/** * Returns the Transactional annotation for the controller. * * @param \Brick\App\RouteMatch $routeMatch * * @return Transactional|null The annotation, or NULL if the controller is not transactional. * * @todo add support for annotations on functions when Doctrine will handle them */ private function getTransactionalAnnotation(RouteMatch $routeMatch) { $method = $routeMatch->getControllerReflection(); if ($method instanceof \ReflectionMethod) { $annotations = $this->annotationReader->getMethodAnnotations($method); foreach ($annotations as $annotation) { if ($annotation instanceof Transactional) { return $annotation; } } } return null; }
public function match(Request $request) { if ($request->getPath() === '/a') { return RouteMatch::forFunction(function () { return (new Response())->setBody(new MessageBodyString('Hello')); }); } if ($request->getPath() === '/b') { return RouteMatch::forFunction(function () { return (new Response())->setBody(new MessageBodyString('World')); }); } return null; }
/** * {@inheritdoc} */ public function match(Request $request) { $path = $request->getPath(); if ($path == '') { return null; } if ($path[0] != '/') { return null; } $lastSlashPos = strrpos($path, '/'); $prefix = substr($path, 0, $lastSlashPos + 1); $action = substr($path, $lastSlashPos + 1); if (!isset($this->routes[$prefix])) { return null; } $class = $this->routes[$prefix]; if ($action == 'index') { return null; } elseif ($action == '') { $action = 'index'; } $method = $this->capitalize($action) . 'Action'; return RouteMatch::forMethod($class, $method); }