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


PHP Di::get方法代码示例

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


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

示例1: setUp

 public function setUp()
 {
     $this->di = $this->getDI();
     $config = $this->di->get('config');
     //        // Load any additional services that mock some methods to prevent database unwanted changes
     //        $this->di->set('modelsManager', new Manager());
     //        $this->di->set('modelsMetadata', new Files(array('metaDataDir' => $config->application->testsMetadataDir)));
     //        $con = $this->getMock('\\Phalcon\\Db\\Adapter\\Pdo\\Mysql', array('getDialect', 'query', 'execute'), array(),'',false);
     //        $this->dialect = $this->getMock('\\Phalcon\\Db\\Dialect\\Mysql', array('select'), array(), '', false);
     //        $results = $this->getMock('\\Phalcon\\Db\\Result\\Pdo', array('numRows', 'setFetchMode', 'fetchall', 'create'), array(), '', false);
     //        $results->expects($this->any())
     //            ->method('numRows')
     //            ->will($this->returnValue(10));
     //
     //        $results->expects($this->any())
     //            ->method('create')
     //            ->willReturn(true);
     //
     //        $results->expects($this->any())
     //            ->method('fetchall')
     //            ->will($this->returnValue(0));
     //
     //        $this->dialect->expects($this->any())
     //            ->method('select');
     //
     //        $con->expects($this->any())
     //            ->method('getDialect')
     //            ->will($this->returnValue($this->dialect));
     //
     //        $con->expects($this->any())
     //            ->method('query')
     //            ->will($this->returnValue($results));
     //
     //        $con->expects($this->any())
     //            ->method('execute');
     //
     //        $this->di->set('db', $con);
     //        parent::setUp($this->di);
     $this->_loaded = true;
 }
开发者ID:sr-hosseini,项目名称:motorbike,代码行数:40,代码来源:UnitTestCase.php

示例2: injectTo

 public static function injectTo(Di $di)
 {
     $di->setShared('logger', function () use($di) {
         $logger = new Multiple();
         $config = $di->get('config')['loggers'];
         foreach ($config as $logConfig) {
             $adapter = $logConfig['adapter'];
             $options = isset($logConfig['options']) ? $logConfig['options'] : null;
             $logger->push(new $adapter($logConfig['name'], $options));
         }
         return $logger;
     });
 }
开发者ID:tobeorla,项目名称:phalcon-skeleton,代码行数:13,代码来源:Logger.php

示例3: testResolvingService

 /**
  * Tests resolving service
  *
  * @author Serghei Iakovlev <serghei@phalconphp.com>
  * @since  2016-01-29
  */
 public function testResolvingService()
 {
     $this->specify("Di does not resolves service correctly", function () {
         $di = new Di();
         $di->set('resolved', function () {
             return new \SomeService();
         });
         $di->set('notResolved', function () {
             return new \SomeService();
         });
         expect($di->getService('resolved')->isResolved())->false();
         expect($di->getService('notResolved')->isResolved())->false();
         $di->get('resolved');
         expect($di->getService('resolved')->isResolved())->true();
         expect($di->getService('notResolved')->isResolved())->false();
     });
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:23,代码来源:ServiceTest.php

示例4: getTimezoneOffset

 /**
  * @param Di $di
  * @return int
  */
 public static function getTimezoneOffset(Di $di)
 {
     /**
      * @var \Phalcon\Http\Request $request
      */
     $request = $di->get('request');
     $timezoneOffset = $request->getHeader('TimezoneOffset');
     return (int) $timezoneOffset;
 }
开发者ID:sergeytkachenko,项目名称:phalcon-rest-jpa,代码行数:13,代码来源:Params.php

示例5: getDI

 /**
  * Get the Phalcon dependency injection instance.
  *
  * @param  string $name service name
  * @return \Phalcon\Di|mixed
  */
 public function getDI($name = null)
 {
     $name = $name;
     return null === $name ? $this->di : $this->di->get($name);
 }
开发者ID:broklyngagah,项目名称:orbit,代码行数:11,代码来源:Command.php

示例6: testConfigFileLoaded

 public function testConfigFileLoaded()
 {
     $b = $this->getBootstrap()->run();
     $this->assertEquals('bar', static::$di->get('config')->foo);
 }
开发者ID:logikostech,项目名称:core,代码行数:5,代码来源:BootstrapTest.php

示例7: injectTo

 public static function injectTo(Di $di)
 {
     $di->setShared('logger', $di->get('config')['logger']);
 }
开发者ID:mamuz,项目名称:phalcon-skeleton,代码行数:4,代码来源:Logger.php

示例8: initEventsManager

 protected function initEventsManager(Di $di)
 {
     if (!$di->has('eventsManager') || $di->getService('eventsManager')->getDefinition() == 'Phalcon\\Events\\Manager') {
         $di->setShared('eventsManager', $this->getEventsManager());
     }
     $this->setEventsManager($di->get('eventsManager'));
 }
开发者ID:logikostech,项目名称:core,代码行数:7,代码来源:Bootstrap.php

示例9: getSession

 /**
  * getSession
  * @return SessionAdapter
  */
 public function getSession()
 {
     return $this->_di->get('session');
 }
开发者ID:remk-wadriga,项目名称:phalcon-base-application-project,代码行数:8,代码来源:UserService.php

示例10: get

 public function get($name, $parameters = null)
 {
     return parent::get($name, $parameters);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Di.php

示例11: getAssetManager

 /**
  * getAssetManager
  * @return \interfaces\AssetManagerInterface
  */
 public function getAssetManager()
 {
     return $this->_di->get('assetManager');
 }
开发者ID:remk-wadriga,项目名称:phalcon-base-application-project,代码行数:8,代码来源:WidgetManager.php

示例12: services

 private function services()
 {
     $di = new Di();
     // Store the api messages
     $di->set('messages', function ($input = null) {
         return $input;
     });
     $di->set('view', function () {
         $view = new View();
         // $view->setViewsDir('../apps/views/');
         return $view;
     });
     $di->set('dispatcher', function () use($di) {
         $eventsManager = new Manager();
         $eventsManager->attach('dispatch:afterExecuteRoute', function ($event, $dispatcher) use($di) {
             // dd($event->getSource()->getActiveController()->getMessages());
             // dd(get_class_methods($event->getSource()->getActiveController()));
             // dd(get_class_methods($event->getSource()));
             // dd($event->getData());
             // dd($event->getSource());
             $source = $event->getSource();
             $returned = $source->getReturnedValue();
             if (is_object($returned)) {
                 if (!method_exists($returned, 'toArray')) {
                     throw new ApiException('The returned value can not be parsed, try it manual.');
                 }
                 $returned = $returned->toArray();
             }
             $configs = $di->get('config');
             $response = new Response();
             if ($configs->api->cors->enabled) {
                 $response->setHeader('Access-Control-Allow-Origin', $configs->api->cors->hosts);
             }
             foreach ($configs->api->headers as $name => $value) {
                 $response->setHeader($name, $value);
             }
             $json_options = 0;
             if ($configs->debug) {
                 $json_options = JSON_PRETTY_PRINT;
             }
             foreach ($configs->json->options as $option) {
                 $json_options |= $option;
             }
             $activeController = $source->getActiveController();
             $status = $activeController->getStatus();
             $errors = $activeController->getErrors();
             $messages = $activeController->getMessages();
             $status_code = $activeController->getCode();
             $data = ['status' => $status, 'status_code' => $status_code, 'errors' => $errors, 'messages' => $messages, 'data' => $returned];
             $response->setJsonContent($data, $json_options);
             $event->getSource()->setReturnedValue($response);
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('App\\Controllers\\');
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     ///////!!!!!!!!!!!!!!!!
     $di->set('modelsMetadata', function () {
         return new \Phalcon\Mvc\Model\Metadata\Memory();
     });
     $di->set('modelsManager', function () {
         return new \Phalcon\Mvc\Model\Manager();
     });
     $this->setDi($di);
 }
开发者ID:ivyhjk,项目名称:phalcon-app,代码行数:66,代码来源:app.php


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