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


PHP Application::setComponents方法代码示例

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


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

示例1: getEventManager

 /**
  * finds and creates app event manager from its settings
  * @param Application $app yii app
  * @return EventManager app event manager component
  * @throws Exception Define event manager
  */
 public static function getEventManager($app)
 {
     if (self::$_eventManager) {
         return self::$_eventManager;
     }
     foreach ($app->components as $name => $config) {
         $class = is_string($config) ? $config : @$config['class'];
         if ($class == str_replace('Bootstrap', 'Manager', get_called_class())) {
             return self::$_eventManager = $app->{$name};
         }
     }
     $eventFile = \Yii::getAlias('@app/config/_events.php');
     $app->setComponents(['eventManager' => ['class' => 'bariew\\eventManager\\EventManager', 'events' => file_exists($eventFile) && is_file($eventFile) ? include $eventFile : []]]);
     return self::$_eventManager = $app->eventManager;
 }
开发者ID:bariew,项目名称:yii2-event-component,代码行数:21,代码来源:EventBootstrap.php

示例2: getEventManager

 /**
  * finds and creates app event manager from its settings
  * @param Application $app yii app
  * @return EventManager app event manager component
  * @throws Exception Define event manager
  */
 public static function getEventManager($app)
 {
     if (self::$_eventManager) {
         return self::$_eventManager;
     }
     foreach ($app->components as $name => $config) {
         $class = is_string($config) ? $config : @$config['class'];
         // if eventManager component in config
         if ($class == str_replace('Bootstrap', 'Manager', get_called_class())) {
             self::$_eventManager = $app->{$name}->events;
         }
         // this class. set $appId from config
         if ($class == str_replace('Manager', 'Bootstrap', get_called_class())) {
             if ($app->{$name}->appId) {
                 self::$appId = $app->{$name}->appId;
             }
         }
     }
     $events = ModelEvent::eventList(self::$appId);
     // merge config events with plugins
     self::$_eventManager = array_merge_recursive($events, self::$_eventManager);
     $app->setComponents(['eventManager' => ['class' => 'esoftslimited\\plugins\\components\\EventManager', 'events' => self::$_eventManager]]);
     return self::$_eventManager = $app->eventManager;
 }
开发者ID:EsoftsLimited,项目名称:yii2-plugins-manager,代码行数:30,代码来源:EventBootstrap.php


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