Exemplo n.º 1
0
 public function testCompileMethodWithoutRouteName()
 {
     $expectedService = "controller.sample_classwithoutcontaineraware";
     //Setup and run class annotation to ensure global state
     $reflClass = new \ReflectionClass('Sample\\ClassWithoutContainerAware');
     $classAnnotations = [];
     $classAnnotations[] = $classAnnotation = new Annotation\Route();
     $classAnnotation->path = "/foo";
     $this->compiler->compileClass($reflClass, $classAnnotations);
     //Setup method annotations
     $reflMethod = $reflClass->getMethod('fooMethod');
     $annotations = [];
     $annotations[] = $routeAnnotation = new Annotation\Route();
     //No name given, expecting a defualt name
     $routeAnnotation->path = "/baz";
     $routeAnnotation->methods = ["PUT"];
     $this->compiler->compileMethod($reflClass, $reflMethod, $annotations);
     /** @var $controllerCollection \Silex\ControllerCollection */
     $controllerCollection = $this->app['controllers'];
     $routes = $controllerCollection->flush();
     $route = $routes->get("sample_classwithoutcontaineraware_foomethod");
     $this->assertNotNull($route, 'Found route with expected name');
     $this->assertEquals('/foo/baz', $route->getPath(), 'Path includes parent path from controller annotation');
     $this->assertEquals(["PUT"], $route->getMethods(), 'Expected methods set');
     $this->assertEquals('bar', $route->getDefault('foo'), 'Default value inferred from reflection method');
 }
Exemplo n.º 2
0
 public function register(Application $app)
 {
     ////
     // Absolute dependencies
     ////
     $app->register(new ServiceControllerServiceProvider());
     ////
     // User Configured Values
     ////
     $app['orlex.cache.dir'] = null;
     $app['orlex.controller.dirs'] = [];
     $app['orlex.annotation.dirs'] = [];
     ////
     // Internal Services
     ////
     $app['orlex.cache'] = $app->share(function ($app) {
         $cache_dir = $app['orlex.cache.dir'];
         if (!$cache_dir) {
             return false;
         }
         $cache = new Cache\FilesystemCache($cache_dir);
         return $cache;
     });
     $app['orlex.annotation.reader'] = $app->share(function ($app) {
         $reader = new Annotations\AnnotationReader();
         if ($cache = $app['orlex.cache']) {
             $reader = new Annotations\CachedReader($reader, $cache);
         }
         return $reader;
     });
     $app['orlex.directoryloader'] = $app->share(function () {
         return new Loader\DirectoryLoader();
     });
     $app['orlex.annotation.registry'] = $app->share(function ($app) {
         AnnotationRegistry::registerAutoloadNamespace('Orlex\\Annotation', dirname(__DIR__));
         foreach ($app['orlex.annotation.dirs'] as $dir => $namespace) {
             AnnotationRegistry::registerAutoloadNamespace($namespace, $dir);
         }
     });
     $app['orlex.route.compiler'] = $app->share(function ($app) {
         $app['orlex.annotation.registry'];
         $compiler = new Compiler\Route($app['orlex.annotation.reader'], $app['orlex.directoryloader']);
         $compiler->setContainer($app);
         return $compiler;
     });
 }