本文整理汇总了PHP中Phalcon\Mvc\Router::setDI方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::setDI方法的具体用法?PHP Router::setDI怎么用?PHP Router::setDI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Router
的用法示例。
在下文中一共展示了Router::setDI方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param Router|null $router
* @param Url|null $url
*/
public function __construct(Router $router = null, Url $url = null)
{
$di = new DI();
$di->setShared('request', new PhalconRequest());
if ($router instanceof PhalconRouterInterface) {
$this->router = $router;
} elseif ($router === null) {
$this->router = new Router();
$this->router->clear();
} else {
throw new Exception\RuntimeException('Router has to be an instance of RouterInterface');
}
$this->router->setDI($di);
$di->setShared('router', $this->router);
if ($url instanceof UrlInterface) {
$this->url = $url;
} elseif ($url === null) {
$this->url = new Url();
$this->url->setBaseUri('/');
} else {
throw new Exception\RuntimeException('Url has to be an instance of UrlInterface');
}
$this->url->setDI($di);
}
示例2: testAnnotations
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);
}
}
示例3: Router
<?php
/**
* Created by PhpStorm.
* User: rcmonitor
* Date: 07.07.15
* Time: 15:46
*/
use Phalcon\Di;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Router;
use Phalcon\Version;
$di = new Di\FactoryDefault();
$oRouter = new Router(false);
$oRouter->setDI($di);
$oRouter->add('/:controller', array('controller' => 1, 'action' => 'index'));
$oEventManager = new Manager();
$oEventManager->attach('dispatch:beforeDispatch', function () {
return false;
});
$oDispatcher = new Dispatcher();
$oDispatcher->setDI($di);
$oDispatcher->setEventsManager($oEventManager);
$oRouter->handle('/test');
$oDispatcher->setControllerName($oRouter->getControllerName());
$oDispatcher->setActionName($oRouter->getActionName());
$oDispatcher->dispatch();
echo $oDispatcher->getControllerClass() . PHP_EOL;
echo Version::get() . PHP_EOL;
示例4: setDI
public function setDI(DiInterface $dependencyInjector)
{
parent::setDI($dependencyInjector);
}