Example #1
0
 public function __construct(Application $app, $path, $controller = null, $idVariable = 'id')
 {
     if (is_object($controller)) {
         $controllerClass = static::underscoreDot(get_class($controller));
         $app[$controllerClass] = $app->factory(function () use($controller) {
             return $controller;
         });
         $controller = $controllerClass;
     }
     $this->app = $app;
     $this->path = $path;
     $this->idVariable = $idVariable;
     $this->routes = array();
     $this->prefix = substr($path, 1);
     $this->prefix = str_replace('/{' . $idVariable . '}', '', $this->prefix);
     $this->prefix = str_replace('/', '_', $this->prefix);
     if ($controller !== null) {
         $this->cget(sprintf('%s:%s', $controller, $app['rest.methods.cget']));
         $this->post(sprintf('%s:%s', $controller, $app['rest.methods.post']));
         $this->get(sprintf('%s:%s', $controller, $app['rest.methods.get']));
         $this->put(sprintf('%s:%s', $controller, $app['rest.methods.put']));
         $this->patch(sprintf('%s:%s', $controller, $app['rest.methods.patch']));
         $this->delete(sprintf('%s:%s', $controller, $app['rest.methods.delete']));
     }
 }
Example #2
0
 public function testOverriddenRoutesFactory()
 {
     $app = new Application();
     $app['routes_factory'] = $app->factory(function () {
         return new RouteCollectionSubClass();
     });
     $this->assertInstanceOf('Silex\\Tests\\RouteCollectionSubClass', $app['routes']);
 }
 public function testAddResourceAlternate()
 {
     $app = new Application();
     $app['locale'] = 'fr';
     $app->register(new ValidatorServiceProvider());
     $app->register(new TranslationServiceProvider());
     $app->factory($app->extend('translator.resources', function ($resources, $app) {
         $resources = array_merge($resources, array(array('array', array('This value should not be blank.' => 'Pas vide'), 'fr', 'validators')));
         return $resources;
     }));
     $app['validator'];
     $this->assertEquals('Pas vide', $app['translator']->trans('This value should not be blank.', array(), 'validators', 'fr'));
 }
 public function testRoutesFactoryInConstructor()
 {
     $app = new Application();
     $app['routes_factory'] = $app->factory(function () {
         return new RouteCollectionSubClass2();
     });
     $controllers = new ControllerCollection(new Route(), $app['routes_factory']);
     $routes = $controllers->flush();
     $this->assertInstanceOf('Silex\\Tests\\RouteCollectionSubClass2', $routes);
 }