/** * {@inheritdoc} */ public function getMapping($reverse = false, $reload = false) { if (is_null($this->_mapping) || $reload) { $this->_mapping = array(); $this->_primary_keys = array(); $reflector = new \ReflectionClass($this); $reader = new AnnotationReader(); foreach ($reflector->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { $annotations = $reader->getPropertyAnnotations($property); if (isset($annotations->db_ref)) { $db_ref = $annotations->db_ref; $this->_mapping[$property->getName()] = (string) $db_ref; if (isset($annotations->pk)) { $key = (string) $db_ref; $strategy = isset($annotations->strategy) ? (string) $annotations->strategy : 'auto'; if ($strategy != 'auto' && $strategy != 'manual') { throw new InvalidStrategyException(sprintf('The primary key strategy must be auto or manual')); } $this->_primary_keys[] = array('key' => $key, 'strategy' => $strategy); } } } } return $reverse ? array_flip($this->_mapping) : $this->_mapping; }
public static function compile(Application $app) { $class = get_called_class(); $instance = new $class($app); $reflector = new \ReflectionClass($instance); $reader = new Reader(); $container = $app['controllers_factory']; foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { $annotations = $reader->getMethodAnnotations($method); if (isset($annotations->route) && isset($annotations->method)) { $route = $annotations->route; $httpMethod = strtolower($annotations->method); $container->{$httpMethod}($route, $method->getClosure($instance)); } } return $container; }
/** * @depends testInitialize * @param Reader $reader */ public function testGetPropertyAnnotation($reader) { $reflector = new \ReflectionProperty('CustomTestClass', 'name'); $this->assertNotNull($reader->getPropertyAnnotation($reflector, 'var')); }
public function boot(AbstractApplication $app) { # Setting environment options $app['debug'] = $this->environment == self::ENVIRONMENT_DEBUG ? true : false; # Compiling controllers $locator = ControllerLocator::getInstance($app); foreach ($this->controllers_path as $path) { if (is_dir(realpath($path))) { $iterator = new \FilesystemIterator($path); $locator->scanControllers($iterator); } } $this->controllers->addAll($locator->getStack()); $reader = new Reader(); $this->controllers->rewind(); foreach ($this->controllers as $controller) { $baseRoute = $reader->getAnnotation(new \ReflectionClass($controller), 'route'); if (!is_null($baseRoute)) { $app->mount($baseRoute, $controller::compile($app)); } } # Configuring Doctrine DBAL if (isset($this->configuration['doctrine'])) { $app->register(new DoctrineServiceProvider(), array('db.options' => $this->configuration['doctrine'])); } # Configuring cache if (isset($this->configuration['zend_cache'])) { $app->register(new ZendCacheServiceProvider(), array('cache.options' => array('zendcache' => $this->configuration['zend_cache']))); } # Configuring Monolog if (isset($this->configuration['monolog'])) { $app['monolog.factory'] = $app->protect(function ($name, array $options) { $logger = new Logger($name); $handlerClass = 'Monolog\\Handler\\' . $options['handler']; if (!class_exists($handlerClass)) { throw new BootstrapException(sprintf('The handler %s specified does not exists and cannot be loaded', $handlerClass)); } if (class_exists($handlerClass)) { $reflector = new \ReflectionClass($handlerClass); $handler = $reflector->newInstanceArgs($options['options']); } else { throw new BootstrapException(sprintf('Invalid Monolog Handler specified')); } $logger->pushHandler($handler); return $logger; }); # Compiling loggers foreach ($this->configuration['monolog'] as $channel => $options) { $app['monolog.' . $channel] = $app['monolog.factory']($channel, $options); } } # Configuring Twig if (isset($this->configuration['twig'])) { if (!is_array($this->configuration['twig'])) { $this->configuration['twig'] = array(); } $app->register(new TwigServiceProvider(), $this->configuration['twig']); } # Configuring Routing component $app->register(new RoutingServiceProvider()); # Setting configurations $app['config'] = $this->configuration; $this->application = $app; $this->application->boot(); return $this->application; }