/** * @expectedException \BadMethodCallException */ public function testRouteMethodDoesNotExist() { $route = new MyRoute(); $controller = new Controller($route); $controller->bar(); }
/** * @param string $serviceid * @param \Silex\Controller $controller * @param \Silex\Application $app * @param \ReflectionClass $class * @param \ReflectionMethod $method * @return mixed */ public function modify($serviceid, Controller $controller, Application $app, \ReflectionClass $class, \ReflectionMethod $method) { echo "<pre>In " . __METHOD__ . " (annotation modification for {$class->getName()}::{$method->getName()}...</pre>"; $controller->before(function () { echo "<pre>In Callback Induced From @Test Annotation...</pre>"; }); }
public function testConflictingRouteNames() { $controllers = new ControllerCollection(new Route()); $mountedRootController = $controllers->match('/', function () { }); $mainRootController = new Controller(new Route('/')); $mainRootController->bind($mainRootController->generateRouteName('main_')); $controllers->flush(); $this->assertNotEquals($mainRootController->getRouteName(), $mountedRootController->getRouteName()); }
/** * @param string $serviceid * @param \Silex\Controller $controller * @param \Silex\Application $app * @param \ReflectionClass $class * @param \ReflectionMethod $method * @return mixed|void */ public function modify($serviceid, Controller $controller, Application $app, \ReflectionClass $class, \ReflectionMethod $method) { $callback = $this->callback; if (!is_callable($callback)) { if ($class->hasMethod($callback)) { $callback = [$app[$serviceid], $callback]; } } $controller->after($callback); }
public function testConflictingRouteNames() { $controllers = new ControllerCollection(); $mountedRootController = new Controller(new Route('/')); $controllers->add($mountedRootController); $mainRootController = new Controller(new Route('/')); $mainRootController->bindDefaultRouteName('main_'); $controllers->flush(); $this->assertNotEquals($mainRootController->getRouteName(), $mountedRootController->getRouteName()); }
private function configureController(Controller $controller, $route_name = null, $before = null, $after = null) { if ($route_name) { $controller->bind($route_name); } if ($before) { $controller->before($this->callback_prefix . ":" . $before); } if ($after) { $controller->after($this->callback_prefix . ":" . $after); } }
public function testControllerFreezing() { $routes = new RouteCollection(); $controllers = new ControllerCollection($routes); $fooController = new Controller(new Route('/foo')); $fooController->bind('foo'); $controllers->add($fooController); $barController = new Controller(new Route('/bar')); $barController->bind('bar'); $controllers->add($barController); $controllers->flush(); try { $fooController->bind('foo2'); $this->fail(); } catch (ControllerFrozenException $e) { } try { $barController->bind('bar2'); $this->fail(); } catch (ControllerFrozenException $e) { } }
/** * @param \Silex\Controller $controller * * @return void */ private function addJsonParsing(Controller $controller) { $controller->before(function (Request $request) { $isJson = strpos($request->headers->get('Content-Type'), 'application/json') === 0; if ($isJson) { $data = json_decode($request->getContent(), true); $request->request->replace(is_array($data) ? $data : []); } }); }
/** * @dataProvider provideRouteAndExpectedRouteName */ public function testDefaultRouteNameGeneration(Route $route, $expectedRouteName) { $controller = new Controller($route); $controller->bindDefaultRouteName(''); $this->assertEquals($expectedRouteName, $controller->getRouteName()); }
public static function buildRoute(Controller $route, $value, $ctrlPrefix, $actionName) { $route->bind(self::forUsage($value, $ctrlPrefix, $actionName)); }
public static function buildRoute(Controller $route, $value) { $route->method(self::forUsage($value)); }