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


PHP di函数代码示例

本文整理汇总了PHP中di函数的典型用法代码示例。如果您正苦于以下问题:PHP di函数的具体用法?PHP di怎么用?PHP di使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: report

 /**
  * Processes the error, fatal and exceptions
  */
 protected function report()
 {
     # - let monolog handle the logging in the errors,
     # unless you want it to, you can refer to method
     # handleExceptionError()
     MonologErrorHandler::register(di()->get('log'));
     # - register all the the loggers we have
     register_shutdown_function([$this, 'handleFatalError']);
     set_error_handler([$this, 'handleError']);
     set_exception_handler([$this, 'handleExceptionError']);
 }
开发者ID:philippgerard,项目名称:slayer,代码行数:14,代码来源:Handler.php

示例2: __construct

 public function __construct()
 {
     $this->request = di()->get('request');
     $this->session = di()->get('session');
     $this->response = di()->get('response');
     $this->security = di()->get('security');
 }
开发者ID:ps-clarity,项目名称:support,代码行数:7,代码来源:Auth.php

示例3: __get

 public function __get($name)
 {
     if (di()->has($name) === false) {
         throw new InvalidArgumentException("Dependency Injection [{$name}] not found");
     }
     return di()->get($name);
 }
开发者ID:phalconslayer,项目名称:framework,代码行数:7,代码来源:ServiceMagicMethods.php

示例4: boot

 /**
  * Loads all services.
  *
  * return void
  */
 public function boot()
 {
     $providers_loaded = array_map(function ($provider) {
         # check if module function exists
         if (method_exists($provider, 'module')) {
             di('module')->setModule($provider->getAlias(), function ($di) use($provider) {
                 call_user_func_array([$provider, 'module'], [$di]);
             });
         }
         # callRegister should return an empty or an object or array
         # then we could manually update the register
         if ($register = $provider->callRegister()) {
             di()->set($provider->getAlias(), $register, $provider->getShared());
         }
         return $provider;
     }, $this->providers);
     # this happens when some application services relies on other service,
     # iterate the loaded providers and call the boot() function
     foreach ($providers_loaded as $provider) {
         $boot = $provider->boot();
         if ($boot && !di()->has($provider->getAlias())) {
             di()->set($provider->getAlias(), $boot, $provider->getShared());
         }
     }
 }
开发者ID:phalconslayer,项目名称:framework,代码行数:30,代码来源:Container.php

示例5: testHandle

 public function testHandle()
 {
     $app = $this->setUp();
     $resolver = di('resolver');
     $resolver->set('dispatch:controller', function () {
         return '\\Engine\\Tests\\Application\\Sample';
     });
     $resolver->set('dispatch:forward', function ($controller, $module) {
         return '\\Engine\\Tests\\Application\\Another';
     });
     $sources = ['/blog/add' => ['action' => 'add', 'response' => 'test'], '/blog/view' => ['action' => 'view', 'exception' => 'Phalcon\\Mvc\\Dispatcher\\Exception'], '/blog/forward' => ['action' => 'forward', 'response' => 'my_action']];
     $router = di('router');
     foreach ($sources as $uri => $source) {
         $router->add($uri, "Blog::Index::{$source['action']}");
         try {
             $app->handle($uri);
             $response = di('dispatcher')->getReturnedValue();
             $this->assertEquals($source['response'], $response);
         } catch (\Exception $e) {
             if (isset($source['exception'])) {
                 $this->assertInstanceOf($source['exception'], $e);
             } else {
                 echo $e->getMessage();
                 dd($e->getTraceAsString());
             }
         }
     }
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:28,代码来源:ApplicationTest.php

示例6: initialize

 public function initialize()
 {
     # - the code below is hard-coded, you can add it by fetching your
     # database table and loop into it and change the 'guest' to something
     # that you've stored.
     di()->get('acl')->addRole(new PhalconRole('guest'));
 }
开发者ID:TheCodemasterZz,项目名称:slayer,代码行数:7,代码来源:Kernel.php

示例7: tearDown

 public function tearDown()
 {
     $compiled_file = 'storage/slayer/compiled.php';
     if (file_exists($compiled_file)) {
         di()->get('flysystem')->delete($compiled_file);
     }
 }
开发者ID:phalconslayer,项目名称:framework,代码行数:7,代码来源:ServerTest.php

示例8: boot

 public function boot()
 {
     $app = di()->get('application');
     $event_manager = new EventsManager();
     $event_manager->attach('application', new ApplicationEventListener());
     $app->setEventsManager($event_manager);
 }
开发者ID:phalconslayer,项目名称:slayer,代码行数:7,代码来源:Application.php

示例9: boot

 public function boot()
 {
     $dispatcher = di()->get('dispatcher');
     $event_manager = new EventsManager();
     $event_manager->attach('dispatch', new DispatcherEventListener());
     $dispatcher->setEventsManager($event_manager);
 }
开发者ID:phalconslayer,项目名称:slayer,代码行数:7,代码来源:Dispatcher.php

示例10: _validateMessage

 /**
  *  validate message
  */
 protected function _validateMessage($message)
 {
     if (!$message) {
         di('log')->record("message not found at " . date('Y-m-d H:i:s'));
         exit;
     }
     // 已處理過的 message 將不再處理
     if ($message->getIsUsed()) {
         di('log')->record("message {$id} is used");
         exit;
     }
     // 回應的 chat_id 必須在白名單之內
     $chatId = $message->getChatId();
     $allowIds = conf('bot.allow_chat_ids');
     if (!in_array($chatId, $allowIds)) {
         di('log')->record("message can not allow send to {$chatId} ({$message->getName()})");
         // debug -> 如果不在予許的名單內, 發送警告訊息
         if (isTraining()) {
             $userId = $message->getUserId();
             $text = '您不在白名單之內 by BOT';
             BotHelper::sendMessage($userId, $text);
         }
         exit;
     }
 }
开发者ID:glennfriend,项目名称:tg-bot,代码行数:28,代码来源:Enter.php

示例11: render

 public function render($path, $params = [])
 {
     $path = str_replace($this->getView()->getViewsDir(), '', $path);
     $path = str_replace('.blade.php', '', $path);
     $blade = new Blade($this->getView()->getViewsDir(), storage_path('views') . '/');
     di()->get('view')->setContent($blade->make($path, $params)->render());
 }
开发者ID:ps-clarity,项目名称:view,代码行数:7,代码来源:BladeAdapter.php

示例12: checkViewPath

 /**
  *
  * @return bool
  */
 public function checkViewPath($path)
 {
     $full_path = di()->get('view')->getViewsDir() . $path;
     $result = glob($full_path . '.*');
     if (!$result) {
         throw new ViewFileNotFoundException('Views file path(' . $full_path . ') not found.');
     }
 }
开发者ID:philippgerard,项目名称:slayer,代码行数:12,代码来源:View.php

示例13: handle

 public function handle($e)
 {
     $content = di()->get('view')->take('errors.whoops', ['e' => $e]);
     $response = di('response');
     $response->setContent($content);
     $response->setStatusCode(self::STATUS_CODE);
     return $response->send();
 }
开发者ID:phalconslayer,项目名称:slayer,代码行数:8,代码来源:FatalHandler.php

示例14: onBoot

 public function onBoot()
 {
     // TODO: Implement onBoot() method.
     $this->getDI()->set(ViewContract::class, View::class);
     $this->getDI()->setShared('view', function () {
         return di(ViewContract::class);
     });
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:8,代码来源:ServiceRegister.php

示例15: register

 /**
  * {@inheridoc}.
  */
 public function register()
 {
     $manager = $this->manager();
     di()->set('flysystem_manager', function () use($manager) {
         return $manager;
     }, true);
     return $manager->getFilesystem(config()->app->flysystem);
 }
开发者ID:phalconslayer,项目名称:framework,代码行数:11,代码来源:Flysystem.php


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