Example #1
0
 public function loadResources($resources, Primate $primate)
 {
     foreach ($resources as $resource) {
         if (!$this->rows[$resource->getId()]) {
             throw new RuntimeException("No such row id: " . $resource->getId());
         }
         $row = $this->rows[$resource->getId()];
         foreach ($row as $key => $value) {
             if ($value[0] == '@') {
                 $part = explode(':', substr($value, 1));
                 $type = $primate->getType($part[0]);
                 $subResource = new Resource($type, $part[1]);
                 $value = $subResource;
             }
             $resource->setProperty($key, $value);
         }
     }
 }
Example #2
0
use Primate\Primate;
use Primate\Resource;
use Primate\Type;
use Primate\Serializer;
use Primate\ArrayRepository;
use Symfony\Component\Yaml\Parser;
require_once __DIR__ . '/../vendor/autoload.php';
if (!isset($argv[1])) {
    echo "Usage: example.php /typeName/id\n";
    exit(1);
}
$url = $argv[1];
echo "Fetching {$url}\n";
$yaml = new Parser();
$data = $yaml->parse(file_get_contents(__DIR__ . '/example.yml'));
$primate = new Primate();
$primate->setBaseUrl('http://primate.example.com/api/v1');
$primate->setProperty('tennant', 'joe');
foreach ($data as $typeName => $rows) {
    $repo = new ArrayRepository($rows);
    $type = new Type($typeName, $repo);
    $primate->registerType($type);
}
$part = parse_url($url);
$path = $part['path'];
$query = $part['query'];
$expands = [];
$parts = explode('&', $query);
foreach ($parts as $part) {
    $kv = explode('=', $part);
    $key = $kv[0];