private static function set_controller_and_action() { # verificando se o config da rota atual é um array com # varias opções, ou apenas a definição básica da rota is_array(static::$routes[static::$current]) ? $route = explode(' ', static::$routes[static::$current]['location']) : ($route = explode(' ', static::$routes[static::$current])); static::$controller = $route[0]; static::$action = @$route[1] ?: 'index'; }
/** * Runs the application and routes the request. * * @param object $app Instantiated application object. */ public static function run($app) { $route = Router::process(new Request()); // Route to 404 if controller and/or method cannot be found if (!class_exists($route['controller']) or !method_exists($route['controller'], "{$route['method']}Action")) { if ($app->environment() == 'development') { throw new Exception("Unable to find controller for '" . Request::pathInfo() . "'"); } else { $route = Router::set404(); } } // Get method parameters $r = new ReflectionMethod("{$route['controller']}::{$route['method']}Action"); $params = []; foreach ($r->getParameters() as $param) { if (isset($route['params'][$param->getName()])) { $params[] = $route['params'][$param->getName()]; } } unset($r, $param); static::$controller = new $route['controller'](); // Run before filters $beforeAll = EventDispatcher::dispatch("before." . $route['controller'] . "::*"); $beforeAction = EventDispatcher::dispatch("before." . $route['controller'] . "::{$route['method']}"); if ($beforeAll instanceof Response || $beforeAction instanceof Response) { static::$controller->executeAction = false; $response = $beforeAll ?: $beforeAction; } // Execute action if (static::$controller->executeAction) { $response = call_user_func_array(array(static::$controller, $route['method'] . 'Action'), $params); } // Run after filters $afterAll = EventDispatcher::dispatch("after." . $route['controller'] . "::*"); $afterAction = EventDispatcher::dispatch("after." . $route['controller'] . "::{$route['method']}"); if ($afterAll instanceof Response || $afterAction instanceof Response) { $response = $afterAll instanceof Response ? $afterAll : $afterAction; } // Send response if (!$response instanceof Response) { throw new Exception("The controller [{$route['controller']}::{$route['method']}] returned an invalid response."); } else { $response->send(); } // Shutdown the controller static::$controller->__shutdown(); }
/** * {@inheritdoc} */ public static function doSetUpBeforeClass() { static::$schemaTool = new SchemaTool(static::$em); static::$schemaTool->dropSchema(static::getTablesMetadata()); static::$schemaTool->createSchema(static::getTablesMetadata()); static::$encoder = static::$container->get('security.encoder_factory'); static::$user = new User(); static::$user->setEmail('*****@*****.**'); static::$user->setPassword(static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt())); static::$user->setUsername('testUser'); $entityPermissionCategory = new PermissionCategory(); $entityPermissionCategory->setName('backend_user'); $entityPermissionCategory->setTechnicalName('backend_user'); static::$em->persist($entityPermissionCategory); $entityPermission = new Permission(); $entityPermission->setRoleName('IS_AUTHENTICATED_FULLY'); $entityPermission->setDescription('IS_AUTHENTICATED_FULLY'); $entityPermission->setName('IS_AUTHENTICATED_FULLY'); $entityPermission->setCategory($entityPermissionCategory); $entityPermission2 = new Permission(); $entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS'); $entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS'); $entityPermission2->setName('ROLE_MANAGE_PERMISSIONS'); $entityPermission2->setCategory($entityPermissionCategory); $entityPermission3 = new Permission(); $entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION'); $entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION'); $entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION'); $entityPermission3->setCategory($entityPermissionCategory); static::$em->persist($entityPermission); static::$em->persist($entityPermission2); static::$em->persist($entityPermission3); static::$em->flush(); $group = new Group(); $group->setRefName('BACKEND-USER'); $group->setName('backend-user'); $group->addPermission($entityPermission); $group->addPermission($entityPermission2); $group->addPermission($entityPermission3); static::$user->addToGroup($group); static::$em->persist($group); static::$em->persist(static::$user); static::$em->flush(); static::$controller = new GroupsController(); static::$controller->setContainer(static::$container); }
/** * Clear some data * * @return void */ protected function clearDataOnStartup() { static::$controller = null; \XLite\Model\CachingFactory::clearCache(); }
/** * Instance controller. * * @return void */ private static function controller() { if(isset(static::$segments[0]) and static::$segments[0] != null) { $controller = static::$controller_path . '/' . Inflector::camelize(static::$segments[0]) . 'Controller.php'; if(is_file($controller)) { require static::$controller_path . '/' . Inflector::camelize(static::$segments[0]) . 'Controller.php'; $controller = 'Controllers\\'. Inflector::camelize(static::$segments[0]) . 'Controller'; static::$controller = new $controller(); } else { throw new ControllerException('Controller ' . static::$segments[0] . ' not found.'); } } else { throw new RouteException('Route not found.'); } }
public static function setController($controller) { static::$controller = $controller; }
protected static function setRoute($route) { $destination = explode('::', $route->destination); $info = ['controller' => $destination[0], 'method' => $destination[1], 'params' => $route->params, 'defaults' => $route->defaults, 'extension' => isset($route->params['extension']) ? $route->params['extension'] : 'html']; // Remove the first dot from the extension if ($info['extension'][0] == '.') { $info['extension'] = substr($info['extension'], 1); } // Allow static use current route info. static::$controller = $info['controller']; static::$method = $info['method']; static::$params = $info['params']; static::$defaults = $info['defaults']; static::$extension = $info['extension']; return static::$currentRoute = $info; }
private static function setRoute($route) { $value = explode('.', $route['value']); $method = explode('/', implode('.', array_slice($value, 1))); $vars = isset($method[1]) ? explode(',', $method[1]) : array(); static::$controller = str_replace('::', '\\', '\\'.$value[0]); static::$method = $method[0]; static::$params = $route['params']; static::$vars = $vars; static::$extension = (isset($route['params']['extension']) ? $route['params']['extension'] : null); }