Esempio n. 1
0
 public function __construct($paths, $yaml)
 {
     parent::__construct($paths);
     $filename = self::$configuration_filepath . DIRECTORY_SEPARATOR . self::$configuration_filename;
     if (!file_exists($filename)) {
         throw new \RuntimeException('The configuration file does not exist at this path: ' . $filename);
     }
     $parsed = $yaml->parse(file_get_contents($filename));
     if ($parsed == false) {
         throw new \RuntimeException('The configuration file does not have valid YAML: ' . $filename);
     }
     $this->classes = $parsed;
 }
Esempio n. 2
0
 public function __construct($paths)
 {
     parent::__construct($paths);
     $filename = self::$configuration_filepath . DIRECTORY_SEPARATOR . self::$configuration_filename;
     if (!file_exists($filename)) {
         throw new \RuntimeException('The configuration file does not exist at this path: ' . $filename);
     }
     $json = json_decode(file_get_contents($filename), true);
     if ($json == null) {
         throw new \RuntimeException('The configuration file does not have valid JSON: ' . $filename);
     }
     $entities = [];
     foreach ($json['resources'] as $resource) {
         $entity = $resource['entity'];
         $entities[$entity] = $resource;
         unset($entities[$entity]['entity']);
     }
     $this->classes = $entities;
 }
Esempio n. 3
0
    public function testNoRepresentationIsAllowed()
    {
        $file_contents = <<<HEREDOC
<?php
\$resources = [];
\$resources['DrestTests\\Entities\\NoAnnotation\\User'] = [
    'representations' => [],
    'routes' => [
        ['name' => 'get_user', 'routePattern' => '/user/:id', 'routeConditions' => ['id' => '\\d+'], 'verbs' => ['GET'], 'action' => 'Action\\Custom'],
        ['name' => 'post_user', 'routePattern' => '/user', 'verbs' => ['POST'], 'expose' => ['username', 'email_address', 'profile' => ['firstname', 'lastname'], 'phone_numbers' => ['number']], 'handle_call' => 'populatePost']
    ]
];
return \$resources;
HEREDOC;
        $tmp = $this->createCustomTmpFile($file_contents);
        $metadataFactory = new MetadataFactory(\Drest\Mapping\Driver\PhpDriver::create([$tmp]));
        $className = 'DrestTests\\Entities\\NoAnnotation\\User';
        $cmd = $metadataFactory->getMetadataForClass($className);
        $this->assertEmpty($cmd->getRepresentations());
    }
Esempio n. 4
0
 /**
  * Registers a custom temporary file
  * @param temporary file $tmp
  */
 public function registerTmpFile($tmp)
 {
     $configuration = new Configuration();
     $configuration->setAttribute('configFilePath', sys_get_temp_dir());
     $configuration->setAttribute('configFileName', basename($tmp));
     PhpDriver::register($configuration);
 }
Esempio n. 5
0
 public function __construct($paths)
 {
     parent::__construct($paths);
 }