作者:adrianeava
项目:manager.i
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
public function registerServices()
{
$di = new FactoryDefault();
$loader = new Loader();
$namespaces = [];
$map = (require_once __DIR__ . '/../autoload_namespaces.php');
foreach ($map as $k => $values) {
$k = trim($k, '\\');
if (!isset($namespaces[$k])) {
$dir = '/' . str_replace('\\', '/', $k) . '/';
$namespaces[$k] = implode($dir . ';', $values) . $dir;
}
}
$loader->registerNamespaces($namespaces);
$loader->register();
/**
* Register a router
*/
$di->set('router', function () {
$router = new Router();
$router->setDefaultModule('frontend');
//set frontend routes
$router->mount(new FrontendRoutes());
//
return $router;
});
$this->setDI($di);
}
作者:nicklos1
项目:littlemal
function setDi()
{
$di = new FactoryDefault();
$di['router'] = function () use($di) {
$router = new Router();
$router->setDefaultModule('mobimall');
return $router;
};
$di['url'] = function () {
$url = new UrlResolver();
$url->setBaseUri('/');
return $url;
};
$di['session'] = function () {
$session = new SessionAdapter();
// $session->start();
return $session;
};
$loader = new Loader();
$loader->registerNamespaces(array('Mall\\Mdu' => __DIR__ . '/../apps/mdu'));
$sysConfig = (include __DIR__ . '/../config/sysconfig.php');
$di['sysconfig'] = function () use($sysConfig) {
return $sysConfig;
};
$loader->register();
return $di;
}
作者:phalco
项目:cphalco
public function modulesClosure(IntegrationTester $I)
{
$I->wantTo('handle request and get content by using single modules strategy (closure)');
Di::reset();
$_GET['_url'] = '/login';
$di = new FactoryDefault();
$di->set('router', function () {
$router = new Router(false);
$router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
$router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
return $router;
});
$application = new Application();
$view = new View();
$application->registerModules(['frontend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
return $view;
});
}, 'backend' => function ($di) use($view) {
/** @var \Phalcon\DiInterface $di */
$di->set('view', function () use($view) {
$view->setViewsDir(PATH_DATA . 'modules/backend/views/');
return $view;
});
}]);
$application->setDI($di);
$I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
}
作者:adrianeava
项目:manager.i
protected function initRouter()
{
$this->getDI()->set('router', function () {
$router = new Router();
$router->setDefaultModule('hrm');
return $router;
});
}
作者:serus2
项目:phalcon
private function mvcRouter()
{
//Register routing
$router = new Router();
$router->clear();
foreach ($this->config('route') as $url => $route) {
$router->add($url, $route->toArray());
}
return $router;
}
作者:mamu
项目:phalcon-applicatio
/**
* @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;
}
作者:bullhor
项目:fast-res
public function addRoutes(Router $router)
{
$router->add('/' . $this->getApiRootUrl() . '(\\/?)', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 'Index', 'action' => 'index'));
$router->addGet('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'show', 'params' => 2));
$router->addGet('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'index'));
$router->addPost('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'create'));
$router->addOptions('/' . $this->getApiRootUrl() . '/:controller', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'options'));
$router->addOptions('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'options'));
$router->addDelete('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'delete', 'params' => 2));
$router->addPut('/' . $this->getApiRootUrl() . '/:controller/:params', array('namespace' => $this->getApiControllerRootNamespace(), 'controller' => 1, 'action' => 'update', 'params' => 2));
}
作者:silverwolfx1
项目:tcc-uhealt
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
protected function registerServices()
{
$di = new FactoryDefault();
require '../../../autoloader.php';
$loader = new Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
$router = new Router();
$router->setDefaultModule("frontend");
//Registering a router
$di->set('router', function () use($router) {
return $router;
});
$this->setDI($di);
}
作者:kimthangat
项目:zcm
/**
* Load frontend router
*
* @param \Phalcon\Mvc\Router $router
* @return \Phalcon\Mvc\Router
*/
function zcms_load_frontend_router($router)
{
//Get frontend module
$frontendModule = get_child_folder(APP_DIR . '/frontend/');
$frontendModule = array_reverse($frontendModule);
foreach ($frontendModule as $module) {
$routerClass = 'Router' . ucfirst($module);
$fileRoute = APP_DIR . "/frontend/{$module}/{$routerClass}.php";
if (file_exists($fileRoute)) {
require_once $fileRoute;
if (class_exists($routerClass)) {
$router->mount(new $routerClass());
}
}
}
return $router;
}
作者:tmquang680
项目:phale
public function __construct(DiInterface $di)
{
parent::__construct(false);
$this->clear();
$this->removeExtraSlashes(true);
$this->setUriSource(PhalconRouter::URI_SOURCE_SERVER_REQUEST_URI);
$this->setDefaultAction('index');
$this->setDefaultController('index');
$this->setDI($di);
$this->notFound(['controller' => 'error', 'action' => 'not-found']);
}
作者:theDisc
项目:phalcon-expressiv
/**
* @param Router\Route $route
* @return array
*/
private function collectParams(Router\Route $route)
{
$matches = $this->router->getMatches();
$params = [];
foreach ($route->getPaths() as $name => $position) {
if (isset($matches[$position])) {
$params[$name] = $matches[$position];
}
}
return $params;
}
作者:lison
项目:cphalco
/**
* Sets the environment
*/
public function setUp()
{
parent::setUp();
$this->di->set('router', function () {
$router = new PhRouter(false);
$router->add('/admin/:controller/p/:action', array('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}', array('section' => 2, 'article' => 3))->setName('news');
$router->add('/([a-z]{2})/([a-zA-Z0-9_-]+)(/|)', array('lang' => 1, 'module' => 'main', 'controller' => 2, 'action' => 'index'))->setName('lang-controller');
return $router;
});
}
作者:rcmonito
项目:abboom_phalcon_code_exampl
/**
* registers module according to uri given
*
* @return bool true if module successfully loaded; <br />
* false otherwise;
*/
public function handle()
{
$boolReturn = false;
$oLogger = $this->di->getFileLogger();
$oPreRouter = new Router();
$oPreRouter->add('/api(.*)', array('module' => 'api'));
$oPreRouter->add('/regular(.*)', array('module' => 'regular'));
$oPreRouter->add('/blind(.*)', array('module' => 'blind'));
$oPreRouter->handle();
$strModuleName = $oPreRouter->getModuleName();
/**
* @type Request $oRequest
*/
$oRequest = $this->di->getRequest();
if (array_key_exists($strModuleName, $this->knownModules)) {
$this->app->registerModules(array($strModuleName => $this->knownModules[$strModuleName]));
$this->app->setDefaultModule($strModuleName);
$boolReturn = true;
$oLogger->debug(__CLASS__ . ': ' . $oRequest->getURI() . ' leads to module: ' . $strModuleName);
} else {
if (!U::isLegacy()) {
$strMsg = 'failed to load phalcon module';
} else {
$strMsg = 'loading old backend';
}
$oLogger->debug(__CLASS__ . ': ' . $strMsg . ' for "' . $oRequest->getUri() . '"');
}
return $boolReturn;
}
作者:nexi
项目:nest-cor
public function routing(Router $router)
{
$this->setModuleName($router->getModuleName());
$this->setNamespaceName($router->getNamespaceName());
$this->setControllerName($router->getControllerName());
$this->setActionName($router->getActionName());
$this->setParams($router->getParams());
}
作者:alevikz
项目:phres
/**
* @return $this
*/
public function createDependencies()
{
$dependency = new FactoryDefault();
$dependency->set('db', function () {
return $this->getDatabase();
});
$dependency->set('router', function () {
$router = new Router(false);
$routes = Routes::get();
foreach ($routes as $group => $controllers) {
foreach ($controllers as $controller) {
$router->add($controller['route'], ['namespace' => "App\\Controllers\\{$group}", 'controller' => $controller['class'], 'action' => 'run'], $controller['method']);
}
}
$router->notFound(['namespace' => 'PhRest\\Controllers', 'controller' => 'Missing', 'action' => 'run']);
return $router;
});
$dependency->set('view', function () {
return new View();
}, true);
$this->setDI($dependency);
return $this;
}
作者:ant-hil
项目:phalcon-kernel-modul
public function testAnnotations()
{
$di = new Di();
$di['request'] = new \Phalcon\Http\Request();
$router = new Router(false);
$router->setDI($di);
$loader = new ArrayRouteLoader($router);
$loader->load(include __DIR__ . '/Fixtures/routes.php');
$router->handle();
$this->assertCount(3, $router->getRoutes());
$routes = [['uri' => '/test4', 'method' => 'GET', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test4', 'method' => 'POST', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test5', 'method' => 'POST', 'controller' => 'test5', 'action' => 'test5'], ['uri' => '/test6', 'method' => 'GET', 'controller' => 'test6', 'action' => 'test6']];
foreach ($routes as $route) {
$_SERVER['REQUEST_METHOD'] = $route['method'];
$router->handle($route['uri']);
$this->assertEquals($router->getControllerName(), $route['controller']);
$this->assertEquals($router->getActionName(), $route['action']);
$this->assertEquals($router->isExactControllerName(), true);
}
}
作者:skulla
项目:thunderhaw
public function add($pattern, $paths = null, $httpMethods = null)
{
$_route = $pattern;
$name = null;
if ($_route instanceof \Phalcon\Mvc\Router\Route) {
$pattern = $_route->getPattern();
$paths = $_route->getPaths();
$httpMethods = $_route->getHttpMethods();
$name = $_route->getName();
}
if ($httpMethods != null && $name != null) {
return parent::add($pattern, $paths)->via($httpMethods)->setName($name);
} elseif ($httpMethods != null) {
return parent::add($pattern, $paths)->via($httpMethods);
} elseif ($name != null) {
return parent::add($pattern, $paths)->setName($name);
} else {
return parent::add($pattern, $paths);
}
}
作者:boiler25
项目:mv
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
protected function registerServices()
{
$di = new FactoryDefault();
$loader = new Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
//Registering a router
$di->set('router', function () {
$router = new Router();
$router->setDefaultModule("frontend");
$router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
$router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
$router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
$router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
return $router;
});
$this->setDI($di);
}
作者:vlad608
项目:projectstorag
<?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();
作者:nakane
项目:phalcon_security_tes
<?php
use Phalcon\Mvc\Router;
$router = new Router();
$router->add('/', ['controller' => 'index', 'action' => 'index']);
$router->add('/tokencheck', ['controller' => 'index', 'action' => 'tokencheck']);
$router->handle();