Ejemplo n.º 1
0
 /**
  *
  * @param string $name database name
  * @param string $driver Driver implementation class name
  * @param array $parameters Driver-specific parameters
  * @param array $classMapper Class mapper configuration (optional)
  */
 public function __construct($name, $driver, $parameters, $classMapper = [])
 {
     $this->name = $name;
     if (isset($parameters['prefix'])) {
         $this->prefix = $parameters['prefix'];
         unset($parameters['prefix']);
     }
     // load driver
     if ($driver[0] !== '\\') {
         // class is relative to this namespace
         $driver = "\\selective\\ORM\\Driver\\{$driver}";
     }
     $this->driver = new $driver();
     $this->driver->loadParameters($parameters);
     $this->driver->connect($this);
     // load class mapper
     if (isset($classMapper['class'])) {
         $classMapperClass = $classMapper['class'];
         unset($classMapper['class']);
         if ($classMapperClass[0] !== '\\') {
             // class is relative to this namespace
             $classMapperClass = "\\selective\\ORM\\ClassMapper\\{$classMapperClass}";
         }
     } else {
         $classMapperClass = "\\selective\\ORM\\ClassMapper\\BuiltIn";
     }
     $this->classMapper = new $classMapperClass();
     $this->classMapper->loadParameters($classMapper);
 }
Ejemplo n.º 2
0
 public static function create()
 {
     $classMapper = new ClassMapper();
     $client = new Client($classMapper->toArray());
     return $client;
 }
Ejemplo n.º 3
0
 /** @covers ::search */
 public function testMultipleFiltersWithDeepSearch()
 {
     $map = ['GET' => ['application/json' => ['user/' => ['(?P<id>\\d+)' => 'UserIdGetJsonController']]]];
     $mapper = new ClassMapper($map);
     list($class, $data) = $mapper->filter('GET')->filter('application/json')->search('user/12345');
     $this->assertSame('UserIdGetJsonController', $class, 'The wrong class was returned');
     $this->assertSame(['id' => '12345'], $data, 'The wrong data was returned');
 }
Ejemplo n.º 4
0
 /**
  * Generate and add a class map from directory
  *
  * @param  string $dir
  * @throws Exception
  * @return ClassLoader
  */
 public function addClassMapFromDir($dir)
 {
     if (!file_exists($dir)) {
         throw new Exception('That class map directory does not exist.');
     }
     $map = new ClassMapper($dir);
     $classMap = $map->getClassMap();
     return $this->addClassMap($classMap);
 }