/** * * @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); }
public static function create() { $classMapper = new ClassMapper(); $client = new Client($classMapper->toArray()); return $client; }
/** @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'); }
/** * 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); }