本文整理汇总了PHP中Route::getAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getAction方法的具体用法?PHP Route::getAction怎么用?PHP Route::getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::getAction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
public function dispatch(Route $route, Request $request, Response $response)
{
$controller = __NAMESPACE__ . '\\Controllers\\' . $route->getController();
$action = $route->getAction();
$foo = new $controller($request, $response);
$foo->{$action}();
$response->send();
}
示例2: __construct
public function __construct()
{
self::$__instance = $this;
set_exception_handler('exceptionHandler');
// setup our loader instance
$this->loader = new Loader();
// load a few helpers
$this->loader->helper('uri', FRAMEWORK_PATH . 'helpers');
// loader the plugins
$this->plugins = $this->loader->manager('plugins');
$this->plugins->loadFrameworkPlugins();
// what shall we load first?
$this->route = $this->loader->manager('route')->find();
// load the controller
$this->controller = $this->loader->controller($this->route->getController());
$this->controller->invokeAction($this->route->getAction());
}
示例3: getContent
protected function getContent(Router $router, Context $context, Route $route)
{
$callback = $route->getAction();
$values = $router->extract($context, $route);
$bindings = $router->bind($values, $route->getBindings());
$arguments = $router->buildArguments($callback, $bindings);
return $callback(...$arguments);
}
示例4: __construct
/**
* __construct()
* check if init() method is declared and runs
*
* @see \ngfw\Route
* @see \ngfw\View
*/
public function __construct()
{
$className = Route::getController();
$method = Route::getAction();
$this->view = new View($className, $method);
if (method_exists($this, 'init')) {
$this->init();
}
}
示例5: dispatch
private function dispatch(Route $route_)
{
$controller = $route_->createController($this->router, $this->request, $this->response, $this->auth);
$action = $route_->getAction() . 'Action';
if (!method_exists($controller, $action)) {
throw new \Exception('Unknow method ' . $action . ' in ' . get_class($controller), 1);
}
echo $controller->{$action}();
return;
}
示例6: testGetSet
/**
* @dataProvider getSetProvider
* @covers Route::getController
* @covers Route::setController
* @covers Route::getAction
* @covers Route::setAction
* @covers Route::getParams
* @covers Route::setParams
*
* @param string $controller
* @param string $action
* @param array $params
*/
public function testGetSet($controller, $action, array $params)
{
$route = new Route('a', 'b', array('c'));
$route->setController($controller);
$this->assertEquals($controller, $route->getController());
$route->setAction($action);
$this->assertEquals($action, $route->getAction());
$route->setParams($params);
$this->assertEquals($params, $route->getParams());
}
示例7: invoke
private function invoke(Route $route)
{
$className = 'AlfredSlack\\Controllers\\' . ucfirst($route->getController()) . 'Controller';
$actionName = $route->getAction() . 'Action';
$controller = new $className();
if (!$controller instanceof \AlfredSlack\Controllers\Controller) {
throw new \Exception("{$className} must inherits from AlfredSlack\\Controllers\\Controller");
}
Utils::log('ACTION: ' . $className . '::' . $actionName . '()');
Utils::log('SIMULATE: php -r \'$query="' . str_replace('"', '\\"', json_encode($route)) . '";include "scripts/index.php";\';');
$interruptAction = $controller->preDispatch($actionName, $route->getParams()) === false;
if (!$interruptAction) {
$actionResult = $controller->dispatch($actionName, $route->getParams());
$controller->postDispatch($actionName, $route->getParams(), $actionResult);
}
}
示例8: loadController
/**
* _loadController()
* Loads application controller
*
* @see \ngfw\Route
* @throws \ngfw\Exception
* @return void
*/
private function loadController()
{
if (!$this->_controllerLoaded) {
$controllerTitle = Route::getController() . "Controller";
if (class_exists($controllerTitle)) {
$this->_controllerObject = new $controllerTitle();
} else {
throw new Exception(sprintf('The requested Controller "%s" does not exist.', $controllerTitle));
}
if ($this->_viewTemplate) {
$this->_controllerObject->setViewObject("template", $this->_viewTemplate);
}
$this->_controllerLoaded = true;
$method = Route::getAction() . "Action";
if (is_callable(array($this->_controllerObject, $method))) {
call_user_func(array($this->_controllerObject, $method));
$this->_controllerObject->startRander();
} else {
throw new Exception(sprintf('The requested method "%s" does not exist in %s.', $method, $controllerTitle));
}
}
}
示例9: checkRoute
/**
* Checking if identified route is valid.
*
* @static
* @access private
* @param Route $oRoute
* @return boolean
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
private static function checkRoute(Route $oRoute)
{
$aRouteDefaults = $oRoute->getDefaults();
// relocation
if (Helper\Arrays::path($aRouteDefaults, 'relocate', FALSE) !== FALSE) {
static::relocate($aRouteDefaults['relocate']);
}
// check controller
static::checkControllerExistance($oRoute->getController(), Helper\Arrays::path($aRouteDefaults, 'package', NULL));
// check action
static::checkActionExistance($oRoute->getAction());
return TRUE;
}
示例10: run
/**
* Run application
*
* @staticvar boolean $is_init
* @staticvar array $routes
* @param $route (optional, ex: 'my/route->action')
* @return void
*/
public function run($route = null)
{
static $is_init = false;
static $routes = [];
// routes stack for current request
if (!$is_init) {
$this->log->trace('Initializing', Logger::CATEGORY_DRONE);
// param default values
$default = [self::KEY_DEBUG => true, self::KEY_ERROR_BACKTRACE => true, self::KEY_ERROR_HANDLER => ['\\Drone\\Core', 'errorHandler'], self::KEY_ERROR_LOG => false, self::KEY_EXT_TEMPLATE => '.tpl', self::KEY_EXT_WEB => '.htm', self::KEY_PATH_CONTROLLER => PATH_ROOT . '_app/mod', self::KEY_PATH_TEMPLATE => PATH_ROOT . '_app/tpl', self::KEY_PATH_TEMPLATE_GLOBAL => PATH_ROOT . '_app/tpl/_global'];
// init param default values
foreach ($default as $k => $v) {
if (!Registry::has($k)) {
Registry::set($k, $v);
}
}
// set default error handler
if (is_array(Registry::get(self::KEY_ERROR_HANDLER))) {
set_error_handler(Registry::get(self::KEY_ERROR_HANDLER));
}
// init paths
$this->__formatDir(Registry::get(self::KEY_PATH_CONTROLLER));
$this->__formatDir(Registry::get(self::KEY_PATH_TEMPLATE));
$this->__formatDir(Registry::get(self::KEY_PATH_TEMPLATE_GLOBAL));
$is_init = true;
}
Registry::set(self::KEY_ROUTE_CONTROLLER, false);
// init controller
if ($route !== null) {
$routes[] = $route;
// cache route
$route = new Route(null, $route);
Registry::set([self::KEY_ROUTE_CONTROLLER => $route->getController(), self::KEY_ROUTE_CLASS => $route->getClass(), self::KEY_ROUTE_TEMPLATE => $route->getController()]);
if ($route->isAction()) {
Registry::set(self::KEY_ROUTE_ACTION, $route->getAction());
}
$this->log->trace('Route set: \'' . Registry::get(self::KEY_ROUTE_CONTROLLER) . '\'', Logger::CATEGORY_DRONE);
} else {
$is_index = false;
$request = $_SERVER['REQUEST_URI'];
$this->log->trace('Process request: \'' . $request . '\'', Logger::CATEGORY_DRONE);
Registry::set(self::KEY_REQUEST, $request);
if (($pos = strpos($request, '?')) !== false) {
$request = substr($request, 0, $pos);
}
unset($pos);
$routes[] = $request;
if (substr($request, -1) != '/') {
// ensure request has web extension
if (substr($request, -strlen(Registry::get(self::KEY_EXT_WEB))) === Registry::get(self::KEY_EXT_WEB)) {
// do not allow direct access to index like '/path/index.htm'
if (basename($request) === 'index' . Registry::get(self::KEY_EXT_WEB)) {
$this->error(self::ERROR_404);
// kick direct index request
return;
}
// rm web extension
$request = substr($request, 0, strlen($request) - strlen(Registry::get(self::KEY_EXT_WEB)));
} else {
$this->error(self::ERROR_404);
// kick request
return;
}
} else {
$is_index = true;
}
$r = null;
foreach ($this->__routes as $r) {
if ($rf = $r->matchFile($request)) {
$this->log->trace('Route file loaded: \'' . $r->getController() . '\'', Logger::CATEGORY_DRONE);
foreach ($rf as $k => $v) {
$r = new Route($k, $v);
if ($r->match($request)) {
break 2;
// match
}
}
} else {
if ($r->match($request)) {
break;
// match
}
}
$r = null;
// no match
}
if ($r) {
$this->log->trace('Route (mapped) detected: \'' . $r->getPath() . '\'', Logger::CATEGORY_DRONE);
Registry::set([self::KEY_ROUTE_CONTROLLER => $r->getController(), self::KEY_ROUTE_CLASS => $r->getClass(), self::KEY_ROUTE_TEMPLATE => $r->getController()]);
if ($r->isAction()) {
Registry::set(self::KEY_ROUTE_ACTION, $r->getAction());
}
$this->view->setRouteParams($r->getParams());
//.........这里部分代码省略.........
示例11: dirname
<?php
// get the absolute path to system
$sys_path = dirname(__FILE__);
// set the include path
set_include_path($sys_path . PATH_SEPARATOR . get_include_path());
// include some required components
require_once 'components/common.php';
require_once 'components/autoload.php';
// get config instance
$config = get_config();
// store the system path in config
$config->set('path.system', $sys_path);
// get route library
$route = new Route();
// get controller, action and request params
$controller = $route->getController();
$action = $route->getAction();
$params = $route->getParams();
// store in config
$config->set('request.controller', $controller);
$config->set('request.action', $action);
$config->set('request.params', $params);
// init the application
$application = new Application($controller, $action);
// EOF
示例12: runController
/**
* Calls an action inside a controller
* (if at least one of them is not present
* nothing happens)
*
* @param Route Route
*/
private function runController(Route $route, array $params)
{
$controller = $route->getController();
$action = $route->getAction();
Router::$currentController = $controller . '#' . $action;
ControllerBase::runController($controller, $action, $params);
}
示例13: testSetAction
public function testSetAction()
{
$this->object->setAction('someAction');
$this->assertEquals('someAction', $this->object->getAction());
}