This example shows how to configure a pipeline from a configuration file using the pipelinebuilder's buildFromConfig method.
This example shows how to configure a pipeline from a configuration file using the pipelinebuilder's buildFromConfig method. This example is available in full on GitHub. To run this example, you will need to create a resource key. The resource key is used as short-hand to store the particular set of properties you are interested in as well as any associated license keys that entitle you to increased request limits and/or paid-for properties. You can create a resource key using the 51Degrees Configurator.
This example uses the 'Country' property, which is pre-populated when creating a key using the link above.
*{
"PipelineOptions": {
"Elements": [
{
"BuilderName": "fiftyone\\pipeline\\cloudrequestengine\\CloudRequestEngine",
"BuildParameters": {
"resourceKey": "!!YOUR_RESOURCE_KEY!!"
}
},
{
"BuilderName": "fiftyone\\pipeline\\geolocation\\GeoLocationCloud"
}
]
}
}
<?php
require(__DIR__ . "/../../vendor/autoload.php");
$builder = new PipelineBuilder();
$configFile = __DIR__ . "/pipeline.json";
if (!file_exists($configFile)) {
echo "Config file not found at " . $configFile;
return;
}
$configFileJSON = json_decode(file_get_contents($configFile), true);
$resourceKey = $configFileJSON["PipelineOptions"]["Elements"][0]["BuildParameters"]["resourceKey"];
if (substr($resourceKey, 0, 2) === "!!") {
echo "You need to create a resource key at " .
"https://configure.51degrees.com/gGc3T5pT?utm_source=code&utm_medium=example&utm_campaign=51degrees-php&utm_content=examples-cloud-configurefromfile.php&utm_term=resource-key-required and paste it into " .
"your config file, replacing !!YOUR_RESOURCE_KEY!!.";
return;
}
$pipeline = $builder->buildFromConfig($configFile);
$flowData = $pipeline->createFlowData();
$latitude = "51.458048";
$longitude = "-0.9822207999999999";
$flowData->evidence->set('query.51D_Pos_latitude', $latitude);
$flowData->evidence->set('query.51D_Pos_longitude', $longitude);
$result = $flowData->process();
$country = $flowData->location->country;
if ($country->hasValue) {
echo "Which country is the location [" . $latitude . "," . $longitude . "] in?";
echo "<br />";
echo $flowData->location->country->value;
} else {
echo $country->noValueMessage;
}