当前位置: 首页>>代码示例>>PHP>>正文


PHP Dispatcher::setDI方法代码示例

本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::setDI方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::setDI方法的具体用法?PHP Dispatcher::setDI怎么用?PHP Dispatcher::setDI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Mvc\Dispatcher的用法示例。


在下文中一共展示了Dispatcher::setDI方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  *
  */
 public function setUp()
 {
     $di = new DI();
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
     $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
     $request = new Request();
     $request->setDI($di);
     $this->request = $request;
     $response = new Response();
     $response->setDI($di);
     $dispatcher = new Dispatcher();
     $dispatcher->setDI($di);
     $this->dispatcher = $dispatcher;
     $cache = new BackendCache(new FrontendCache());
     $di->set('viewCache', $cache);
     $config = new Config(array('cache' => array('enable' => true)));
     $di->set('config', $config);
     $eventsManager = new Manager();
     $di->set('request', $request, true);
     $di->set('response', $response, true);
     $di->set('dispatcher', $dispatcher, true);
     $di->set('eventsManager', $eventsManager);
     $this->di = $di;
     $application = new Application();
     $application->setDI($di);
     $application->setEventsManager($eventsManager);
     $this->application = $application;
 }
开发者ID:hushibing,项目名称:EvaEngine,代码行数:33,代码来源:DispatchTest.php

示例2: onBoot

 public function onBoot()
 {
     // TODO: Implement onBoot() method.
     $this->getDI()->setShared('dispatcher', function () {
         $di = $this->getDI();
         $em = $di->getEventsManager();
         $em->attach('dispatch', new DispatchListener());
         $dispatcher = new Dispatcher();
         $dispatcher->setDI($di);
         $dispatcher->setEventsManager($em);
         return $dispatcher;
     });
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:13,代码来源:ServiceRegister.php

示例3: testModelBinding

 public function testModelBinding(IntegrationTester $I)
 {
     $dispatcher = new Dispatcher();
     $dispatcher->setModelBinding(true);
     $dispatcher->setDI(Di::getDefault());
     $I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
     $I->haveServiceInDi('dispatcher', $dispatcher);
     // Model to test with
     $model = People::findFirst();
     $dispatcher->setControllerName('test10');
     $dispatcher->setActionName('view');
     $dispatcher->setParams([$model->cedula]);
     $dispatcher->dispatch();
     $I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
     $I->assertEquals($model->cedula, $dispatcher->getReturnedValue()->cedula);
     // Reset dispatcher
     $dispatcher = new Dispatcher();
     $dispatcher->setDI(Di::getDefault());
     $I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
     $I->haveServiceInDi('dispatcher', $dispatcher);
     $dispatcher->setControllerName('test9');
     $dispatcher->setActionName('view');
     $dispatcher->setParams([$model->cedula]);
     try {
         $dispatcher->dispatch();
         $I->assertTrue(false, 'Here must be the exception about passing non model to the controller action');
     } catch (\Exception $e) {
         // PHP 5.x
         $I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
     } catch (\TypeError $e) {
         // PHP 7.x
         $I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
     }
     $dispatcher->setModelBinding(true);
     $dispatcher->dispatch();
     $I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
     $I->assertEquals($dispatcher->getReturnedValue()->cedula, $model->cedula);
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:38,代码来源:ControllersCest.php

示例4: 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;
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:30,代码来源:discussion.php

示例5: testLastController

 public function testLastController()
 {
     $this->specify("Dispatcher doesn't store the last controller", function () {
         $di = new Di();
         $dispatcher = new Dispatcher();
         $dispatcher->setDI($di);
         $di->set("dispatcher", $dispatcher);
         $dispatcher->setControllerName("failure");
         $dispatcher->setActionName("exception");
         $dispatcher->setParams([]);
         try {
             $dispatcher->dispatch();
             expect(false)->true();
         } catch (\Exception $e) {
             expect($e->getMessage())->equals("failure by exception");
             expect($dispatcher->getLastController())->isInstanceOf("FailureController");
         }
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:19,代码来源:DispatcherTest.php


注:本文中的Phalcon\Mvc\Dispatcher::setDI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。