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


PHP Di::getShared方法代码示例

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


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

示例1: register

 public static function register(Di $di)
 {
     static::$di = $di;
     static::$config = Config::get('auth');
     $di->setShared('auth', function () {
         $di = static::$di;
         $config = static::$config;
         $class = $config['adapter'];
         $options = $config['options'];
         strpos($class, '\\') === false and $class = 'Phwoolcon\\Auth\\Adapter\\' . $class;
         if ($di->has($class)) {
             $class = $di->getRaw($class);
         }
         if (!class_exists($class)) {
             throw new Exception('Admin auth adapter class should implement ' . AdapterInterface::class);
         }
         /* @var Security $hasher */
         $hasher = static::$di->getShared('security');
         $hasher->setDefaultHash($options['security']['default_hash']);
         $hasher->setWorkFactor($options['security']['work_factor']);
         $adapter = new $class($options, $hasher, $di);
         if (!$adapter instanceof AdapterInterface) {
             throw new Exception('Auth adapter class should implement ' . AdapterInterface::class);
         }
         return $adapter;
     });
     static::addPhwoolconJsOptions();
 }
开发者ID:phwoolcon,项目名称:auth,代码行数:28,代码来源:Auth.php

示例2: run

 /**
  * @param array|Payload $payload
  * @return Payload
  * @throws GeneralException
  */
 public static function run($payload)
 {
     static::$instance === null and static::$instance = static::$di->getShared('payment');
     $payload instanceof Payload or $payload = Payload::create($payload);
     $paymentMethod = static::$instance->getPaymentMethod($payload->getGateway(), $payload->getMethod());
     $payload->setResult($paymentMethod->process($payload));
     return $payload;
 }
开发者ID:phwoolcon,项目名称:payment,代码行数:13,代码来源:Processor.php

示例3: register

 /**
  * Fix over clever di service resolver in phalcon 2.1.x:
  * let definition = \Closure::bind(definition, dependencyInjector)
  * which leads to php warning "Cannot bind an instance to a static closure"
  *
  * @param Di $di
  * @codeCoverageIgnore
  */
 public static function register(Di $di)
 {
     if ($_SERVER['PHWOOLCON_PHALCON_VERSION'] > '2010000') {
         $di->setInternalEventsManager($di->getShared('eventsManager'));
         Events::attach('di:beforeServiceResolve', function (Event $event) {
             /* @var Di $di */
             $di = $event->getSource();
             $data = $event->getData();
             $name = $data['name'];
             $parameters = $data['parameters'];
             if (!isset($di->_services[$name])) {
                 return false;
             }
             /* @var Di\Service $service */
             $service = $di->_services[$name];
             if (!$service->isShared()) {
                 return false;
             }
             if (!($definition = $service->getDefinition()) instanceof Closure) {
                 return false;
             }
             return $parameters ? call_user_func_array($definition, $parameters) : call_user_func($definition);
         });
     }
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:33,代码来源:DiFix.php

示例4: injectTo

 public static function injectTo(Di $di)
 {
     /** @var Dispatcher $dispatcher */
     $dispatcher = $di->getShared('dispatcher');
     $dispatcher->getEventsManager()->attach('dispatch:beforeException', function (Event $event, Dispatcher $dispatcher, \Exception $e) {
         /** @var \Phalcon\Logger\AdapterInterface $logger */
         $logger = $dispatcher->getDI()->get('logger');
         $logger->error($e->getMessage());
         if ($dispatcher instanceof Mvc\Dispatcher) {
             if ($e instanceof Mvc\Dispatcher\Exception) {
                 $action = 'notFound';
             } else {
                 $action = 'fatal';
                 if ($dispatcher->getDI()->has('response')) {
                     /** @var \Phalcon\Http\Response $response */
                     $response = $dispatcher->getDI()->get('response');
                     $response->setStatusCode(500, "Internal Server Error");
                 }
             }
             $dispatcher->setNamespaceName($dispatcher->getDefaultNamespace());
             $dispatcher->forward(['controller' => 'error', 'action' => $action]);
         }
         return false;
     });
 }
开发者ID:tobeorla,项目名称:phalcon-skeleton,代码行数:25,代码来源:ErrorHandler.php

示例5: injectTo

 public static function injectTo(Di $di)
 {
     /** @var Dispatcher $dispatcher */
     $dispatcher = $di->getShared('dispatcher');
     $dispatcher->getEventsManager()->attach('dispatch:beforeException', function (Event $event, Dispatcher $dispatcher, \Throwable $e) {
         if ($dispatcher instanceof Mvc\Dispatcher) {
             $dispatcher->setNamespaceName($dispatcher->getDefaultNamespace());
             $dispatcher->forward(['controller' => 'error', 'action' => 'index', 'params' => ['exception' => $e]]);
             return false;
         }
     });
 }
开发者ID:mamuz,项目名称:phalcon-skeleton,代码行数:12,代码来源:ErrorHandler.php

示例6: profileReceive

 /**
  * @param SwooleServer $server
  * @param              $fd
  * @param              $fromId
  * @param              $data
  * @codeCoverageIgnore
  */
 public function profileReceive(SwooleServer $server, $fd, $fromId, $data)
 {
     xhprof_enable(0, ['ignored_functions' => ['call_user_func', 'call_user_func_array']]);
     $this->onReceive($server, $fd, $fromId, $data);
     $microTime = explode(' ', microtime());
     /* @var Router $router */
     $router = static::$di->getShared('router');
     $pathInfo = strtr($router->getRewriteUri(), ['/' => '|']);
     $reportFile = $microTime[1] . '-' . substr($microTime[0], 2) . '-' . $_SERVER['REQUEST_METHOD'] . $pathInfo;
     $this->profiler or $this->profiler = new XHProfRuns_Default($this->profilerDir);
     $this->profiler->save_run(xhprof_disable(), 'service', $reportFile);
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:19,代码来源:Service.php

示例7: reconnect

 public static function reconnect($name = null)
 {
     static::$instance === null and static::$instance = static::$di->getShared('dbManager');
     $db = static::$instance;
     $db->disconnect($name = $name ?: $db->config['default']);
     if (isset($db->connections[$name])) {
         $db->connections[$name]->connect();
         return $db->connections[$name];
     }
     // @codeCoverageIgnoreStart
     return static::connection($name);
     // @codeCoverageIgnoreEnd
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:13,代码来源:Db.php

示例8: register

 public static function register(Di $di)
 {
     static::$di = $di;
     $di->set('Phalcon\\Http\\Cookie', 'Phwoolcon\\Http\\Cookie');
     static::$cookies = static::$di->getShared('cookies');
     static::$cookies->reset();
     static::$options = $options = Config::get('cookies');
     static::$cookies->useEncryption($encrypt = $options['encrypt']);
     $encrypt and static::$di->getShared('crypt')->setKey($options['encrypt_key'])->setPadding(Crypt::PADDING_ZERO);
     /* @var \Phalcon\Http\Response $response */
     if ($response = $di->getShared('response')) {
         $response->setCookies(static::$cookies);
     }
     Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
         $options = $event->getData() ?: [];
         $options['cookies'] = ['domain' => static::$options['domain'], 'path' => static::$options['path']];
         $event->setData($options);
         return $options;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:20,代码来源:Cookies.php

示例9: staticReset

 public static function staticReset()
 {
     static::$router === null and static::$router = static::$di->getShared('router');
     static::$router->reset();
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:5,代码来源:Router.php

示例10: useMultiLocale

 public static function useMultiLocale($flag = null)
 {
     static::$instance or static::$instance = static::$di->getShared('i18n');
     $flag === null or static::$instance->multiLocale = (bool) $flag;
     return static::$instance->multiLocale;
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:6,代码来源:I18n.php

示例11: __callStatic

 public static function __callStatic($name, $arguments)
 {
     static::$session or static::$session = static::$di->getShared('session');
     return call_user_func_array([static::$session, $name], $arguments);
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:5,代码来源:Session.php

示例12: noHeader

 public static function noHeader($flag = null)
 {
     static::$instance or static::$instance = static::$di->getShared('view');
     $flag === null or static::$instance->_options['no_header'] = (bool) $flag;
     return !empty(static::$instance->_options['no_header']);
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:6,代码来源:View.php

示例13: fire

 public static function fire($eventType, $source, $data = null, $cancelable = true)
 {
     static::$event or static::$event = static::$di->getShared('eventsManager');
     return static::$event->fire($eventType, $source, $data, $cancelable);
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:5,代码来源:Events.php

示例14: function

$di->set('response', 'Phalcon\\Http\\Response');
//Registering the view component
$di->set('view', function () {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../apps/views/');
    return $view;
});
$di->set('db', function () {
    return new Database(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
});
//Registering the Models-Metadata
$di->set('modelsMetadata', 'Phalcon\\Mvc\\Model\\Metadata\\Memory');
//Registering the Models Manager
$di->set('modelsManager', 'Phalcon\\Mvc\\Model\\Manager');
try {
    $router = $di->getShared('router');
    $router->handle();
    $view = $di->getShared('view');
    $dispatcher = $di->getShared('dispatcher');
    $dispatcher->setControllerName($router->getControllerName());
    $dispatcher->setActionName($router->getActionName());
    $dispatcher->setParams($router->getParams());
    //Start the view
    $view->start();
    //Dispatch the request
    $dispatcher->dispatch();
    $view->render($dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams());
    $view->finish();
    $response = $di->getShared('response');
    //Pass the output of the view to the response
    $response->setContent($view->getContent());
开发者ID:boiler256,项目名称:mvc,代码行数:31,代码来源:index.php

示例15: getShared

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


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