本文整理汇总了PHP中Phalcon\Mvc\Router::removeExtraSlashes方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::removeExtraSlashes方法的具体用法?PHP Router::removeExtraSlashes怎么用?PHP Router::removeExtraSlashes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Router
的用法示例。
在下文中一共展示了Router::removeExtraSlashes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFrom
/**
* @param array $routes
* @return MvcRouter
*/
public static function createFrom(array $routes) : MvcRouter
{
$router = new MvcRouter(false);
$router->setUriSource(MvcRouter::URI_SOURCE_SERVER_REQUEST_URI);
$router->removeExtraSlashes(true);
foreach ($routes as $route) {
$router->add($route['pattern'], $route['paths'] ?? null, $route['httpMethods'] ?? null, $route['position'] ?? MvcRouter::POSITION_LAST);
}
return $router;
}
示例2: Router
<?php
/**
* Created by PhpStorm.
* User: vlad
* Date: 8/28/15
* Time: 10:34 PM
*/
use Phalcon\Mvc\Router;
$router = new Router();
$router->removeExtraSlashes(true);
$router->add("/", array("controller" => "projects", "action" => "index"));
$router->add("/projects(/?index)?", array("controller" => "static", "action" => "error"));
$router->add("/404", array("controller" => "static", "action" => "error404"));
$router->add("/403", array("controller" => "static", "action" => "error403"));
$router->notFound(array("controller" => "static", "action" => "error404"));
$router->handle();
示例3: initRouter
/**
* Initializes the router
*
* @param array $options
*/
protected function initRouter($options = array())
{
$config = $this->di['config'];
$this->di['router'] = function () use($config) {
// Create the router without default routes (false)
$router = new PhRouter(true);
// 404
$router->notFound(array("controller" => "index", "action" => "notFound"));
$router->removeExtraSlashes(true);
foreach ($config['routes'] as $route => $items) {
$router->add($route, $items->params->toArray())->setName($items->name);
}
return $router;
};
}
示例4: function
<?php
use Phalcon\Mvc\Router;
/* ==================================================
* ลงทะเบียน "เส้นทางเว็บแอพพลิเคชั่น" (Router)
* Registering a router
* ================================================== */
$config = $this->config;
// Read the configuration
$manager->set('router', function () use($config) {
$router = new Router();
$router->setDefaultModule($config->router->moduleDefault);
$router->setDefaultController($config->router->controllerDefault);
$router->setDefaultAction($config->router->actionDefault);
$router->removeExtraSlashes(TRUE);
$addModule = explode(',', $config->module->moduleLists);
foreach ($addModule as $module) {
$pathModule = APPLICATION_PATH . '/modules/' . $module . '/Router.php';
$nameModule = ucfirst($module) . 'Router';
if (file_exists($pathModule)) {
include_once $pathModule;
$router->mount(new $nameModule($config));
}
}
return $router;
});
示例5: diRouter
public function diRouter()
{
$di = $this->getDI();
$cachePrefix = $this->getAppName();
$cacheFile = $this->getConfigPath() . "/_cache.{$cachePrefix}.router.php";
if ($router = $this->readCache($cacheFile, true)) {
return $router;
}
$moduleManager = $di->getModuleManager();
$config = new Config();
$moduleName = '';
if ($moduleManager && ($modulesArray = $moduleManager->getModules())) {
foreach ($modulesArray as $moduleName => $module) {
//NOTICE: EvaEngine Load front-end router at last
$config->merge(new Config($moduleManager->getModuleRoutesFrontend($moduleName)));
$config->merge(new Config($moduleManager->getModuleRoutesBackend($moduleName)));
}
}
//Disable default router
$router = new Router(false);
//Last extra slash
$router->removeExtraSlashes(true);
//Set last module as default module
$router->setDefaultModule($moduleName);
//NOTICE: Set a strange controller here to make router not match default index/index
$router->setDefaultController('EvaEngineDefaultController');
$config = $config->toArray();
foreach ($config as $url => $route) {
if (count($route) !== count($route, COUNT_RECURSIVE)) {
if (isset($route['pattern']) && isset($route['paths'])) {
$method = isset($route['httpMethods']) ? $route['httpMethods'] : null;
$router->add($route['pattern'], $route['paths'], $method);
} else {
throw new Exception\RuntimeException(sprintf('No route pattern and paths found by route %s', $url));
}
} else {
$router->add($url, $route);
}
}
if (!$di->getConfig()->debug) {
$this->writeCache($cacheFile, $router, true);
} else {
//Dump merged routers for debug
$this->writeCache($this->getConfigPath() . "/_debug.{$cachePrefix}.router.php", $router, true);
}
return $router;
}
示例6: initRouter
/**
*
* @param type $options
*/
protected function initRouter($options = [])
{
$this->_di->setShared('router', function () {
$router = new Router();
$router->setDefaultModule('intranet');
$router->setDefaultNamespace('Intranet\\Controllers');
$router->removeExtraSlashes(true);
return $router;
});
}
示例7: setupDI
/**
* Sets the environment
*/
private function setupDI()
{
Di::reset();
$di = new Di();
$di->set('router', function () {
$router = new Router(false);
$router->add('/admin/:controller/p/:action', ['controller' => 1, 'action' => 2])->setName('adminProducts');
$router->add('/api/classes/{class}')->setName('classApi');
$router->add('/{year}/{month}/{title}')->setName('blogPost');
$router->add('/wiki/{article:[a-z]+}')->setName('wikipedia');
$router->add('/news/{country:[a-z]{2}}/([a-z+])/([a-z\\-+])/{page}', ['section' => 2, 'article' => 3])->setName('news');
$router->add('/([a-z]{2})/([a-zA-Z0-9_-]+)(/|)', ['lang' => 1, 'module' => 'main', 'controller' => 2, 'action' => 'index'])->setName('lang-controller');
$router->removeExtraSlashes(true);
return $router;
});
return $di;
}
示例8: initRouter
/**
* Initializes the router
*
* @param array $options
*/
public function initRouter($options = [])
{
$config = $this->di['config'];
$loader = $this->di['loader'];
$this->di->setShared('router', function () use($config, $loader) {
$router = new PhRouter(false);
$router->setDefaultModule('common');
foreach ($config['app_routes'] as $route => $params) {
$router->add($route, (array) $params)->setHostName($config->app_baseUri);
}
if (SUBDOMAIN == 'm') {
$router->setDefaultModule('mobile');
$mobileRoutes = ['/:controller' => ['module' => 'mobile', 'controller' => 1], '/:controller/:action/:params' => ['module' => 'mobile', 'controller' => 1, 'action' => 2, 'params' => 3], '/' => ['module' => 'mobile', 'controller' => 'index', 'action' => 'index']];
foreach ($mobileRoutes as $route => $params) {
$router->add($route, (array) $params)->setHostName('m.' . $config->app_baseUri);
}
}
$router->removeExtraSlashes(true);
return $router;
});
}
示例9: run
//.........这里部分代码省略.........
$formatter = new LoggerFormatter($format);
$logger->setFormatter($formatter);
$di->set('logger', $logger, true);
/**
* ERROR HANDLING
*/
ini_set('display_errors', boolval(K_DEBUG));
error_reporting(E_ALL);
set_error_handler(function ($exception) use($logger) {
if ($exception instanceof \Exception) {
$logger->error($exception->__toString());
} else {
$logger->error(json_encode(debug_backtrace()));
}
});
set_exception_handler(function (\Exception $exception) use($logger) {
$logger->error($exception->getMessage());
});
register_shutdown_function(function () use($logger, $memoryUsage, $currentTime) {
$memoryUsed = number_format((memory_get_usage() - $memoryUsage) / 1024, 3);
$executionTime = number_format(microtime(true) - $currentTime, 4);
if (K_DEBUG) {
$logger->info('Shutdown completed [Memory: ' . $memoryUsed . 'Kb] ' . '[Execution: ' . $executionTime . ']');
}
});
$timezone = $config->get('app_timezone', 'US/Eastern');
date_default_timezone_set($timezone);
/**
* Routes
*/
if (!K_CLI) {
$di->set('router', function () use($config) {
$router = new Router(false);
$router->removeExtraSlashes(true);
$routes = $config->routes->toArray();
foreach ($routes as $pattern => $options) {
$router->add($pattern, $options);
}
return $router;
}, true);
}
/**
* We register the events manager
*/
$di->set('dispatcher', function () use($di) {
$eventsManager = new EventsManager();
/**
* Handle exceptions and not-found exceptions using NotFoundPlugin
*/
$eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Kitsune\\Controllers');
return $dispatcher;
});
/**
* The URL component is used to generate all kind of urls in the application
*/
$di->set('url', function () use($config) {
$url = new UrlProvider();
$url->setBaseUri($config->baseUri);
return $url;
});
$di->set('view', function () use($config) {
$view = new View();
$view->setViewsDir(K_PATH . '/app/views/');
示例10: run
//.........这里部分代码省略.........
$logger = new LoggerFile($name);
$formatter = new LoggerFormatter($format);
$logger->setFormatter($formatter);
$this->diContainer->set('logger', $logger, true);
/**********************************************************************
* ERROR HANDLING
**********************************************************************/
ini_set('display_errors', boolval(K_DEBUG));
error_reporting(E_ALL);
set_error_handler(function ($exception) use($logger) {
if ($exception instanceof \Exception) {
$logger->error($exception->__toString());
} else {
$logger->error(json_encode(debug_backtrace()));
}
});
set_exception_handler(function (\Exception $exception) use($logger) {
$logger->error($exception->getMessage());
});
register_shutdown_function(function () use($logger, $utils, $memoryUsage, $currentTime) {
$memoryUsed = memory_get_usage() - $memoryUsage;
$executionTime = microtime(true) - $currentTime;
if (K_DEBUG) {
$logger->info(sprintf('Shutdown completed [%s]s - [%s]', round($executionTime, 3), $utils->bytesToHuman($memoryUsed)));
}
});
$timezone = $config->get('app_timezone', 'US/Eastern');
date_default_timezone_set($timezone);
/**********************************************************************
* ROUTES
**********************************************************************/
if (false === K_CLI) {
$router = new Router(false);
$router->removeExtraSlashes(true);
$routes = $config->routes->toArray();
foreach ($routes as $pattern => $options) {
$router->add($pattern, $options);
}
$this->diContainer->set('router', $router, true);
}
/**********************************************************************
* DISPATCHER
**********************************************************************/
if (false === K_CLI) {
/**
* We register the events manager
*/
$eventsManager = new EventsManager();
/**
* Handle exceptions and not-found exceptions using NotFoundPlugin
*/
$eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Kitsune\\Controllers');
} else {
$dispatcher = new PhCliDispatcher();
$dispatcher->setDefaultNamespace('Kitsune\\Cli\\Tasks');
}
$this->diContainer->set('dispatcher', $dispatcher);
/**********************************************************************
* URL
**********************************************************************/
/**
* The URL component is used to generate all kind of urls in the application
*/
示例11: initRouter
/**
* Initializes the router
*
* @param array $options
*/
protected function initRouter($options = array())
{
$config = $this->di['config'];
$this->di['router'] = function () use($config) {
$router = new Router(false);
$router->notFound(array('controller' => 'index', 'action' => 'notFound'));
$router->removeExtraSlashes(true);
foreach ($config['routes']->toArray() as $route => $items) {
$route = $router->add($route, $items['params']);
if (isset($items['name'])) {
$route->setName($items['name']);
}
if (isset($items['via'])) {
$route->via($items['via']);
}
if (isset($items['hostname'])) {
$route->setHostname($items['hostname']);
}
}
return $router;
};
}
示例12: removeExtraSlashes
public function removeExtraSlashes($remove)
{
return parent::removeExtraSlashes($remove);
}