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


PHP Container::share方法代码示例

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


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

示例1: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  */
 public function register(Container $container)
 {
     $model = $this->model;
     // QueryHelper
     $container->share('model.' . $this->name . '.helper.query', function ($container) use($model) {
         if ($model instanceof ListModel) {
             return $model->getQueryHelper();
         } else {
             return new QueryHelper();
         }
     });
     // Filter
     $container->share('model.' . $this->name . '.filter', function ($container) use($model) {
         if ($model instanceof ListModel) {
             return $model->getFilterHelper();
         } else {
             return new FilterHelper();
         }
     })->alias('model.' . $this->name . '.helper.filter', 'model.' . $this->name . '.filter');
     // Search
     $container->share('model.' . $this->name . '.search', function ($container) use($model) {
         if ($model instanceof ListModel) {
             return $model->getSearchHelper();
         } else {
             return new SearchHelper();
         }
     })->alias('model.' . $this->name . '.helper.search', 'model.' . $this->name . '.search');
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:35,代码来源:GridProvider.php

示例2: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  */
 public function register(Container $container)
 {
     // Global Config
     $container->share('joomla.config', array('JFactory', 'getConfig'));
     // Windwalker Config
     $container->share('windwalker.config', array($this, 'loadConfig'));
     // Database
     $this->share($container, 'db', 'JDatabaseDriver', array('JFactory', 'getDbo'));
     // Language
     $this->share($container, 'language', 'JLanguage', array('JFactory', 'getLanguage'));
     // Dispatcher
     $this->share($container, 'event.dispatcher', 'JEventDispatcher', array('JEventDispatcher', 'getInstance'));
     // Date
     $this->set($container, 'date', 'JDate', function () {
         return DateHelper::getDate();
     });
     // Global
     $container->set('SplPriorityQueue', function () {
         return new \SplPriorityQueue();
     });
     // Asset
     $container->share('helper.asset', function () {
         return new \Windwalker\Helper\AssetHelper();
     });
     // Detect deferent environment
     if (defined('WINDWALKER_CONSOLE')) {
         $container->registerServiceProvider(new CliProvider());
     } else {
         $container->registerServiceProvider(new WebProvider());
     }
 }
开发者ID:beingsane,项目名称:quickcontent,代码行数:38,代码来源:SystemProvider.php

示例3: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     // Register the web processor
     $container->share('monolog.processor.web', function () {
         return new WebProcessor();
     });
     // Register the main application handler
     $container->share('monolog.handler.application', function (Container $container) {
         /** @var \Joomla\Registry\Registry $config */
         $config = $container->get('config');
         $level = strtoupper($config->get('log.application', $config->get('log.level', 'error')));
         return new StreamHandler(APPROOT . '/logs/app.log', constant('\\Monolog\\Logger::' . $level));
     });
     // Register the database handler
     $container->share('monolog.handler.database', function (Container $container) {
         /** @var \Joomla\Registry\Registry $config */
         $config = $container->get('config');
         // If database debugging is enabled then force the logger's error level to DEBUG, otherwise use the level defined in the app config
         $level = $config->get('database.debug', false) ? 'DEBUG' : strtoupper($config->get('log.database', $config->get('log.level', 'error')));
         return new StreamHandler(APPROOT . '/logs/database.log', constant('\\Monolog\\Logger::' . $level));
     });
     // Register the main Logger
     $container->alias('monolog', 'Monolog\\Logger')->alias('monolog.logger.application', 'Monolog\\Logger')->alias('Psr\\Log\\LoggerInterface', 'Monolog\\Logger')->share('Monolog\\Logger', function (Container $container) {
         return new Logger('MauticDashboard', [$container->get('monolog.handler.application')], [$container->get('monolog.processor.web')]);
     });
     // Register the database Logger
     $container->share('monolog.logger.database', function (Container $container) {
         return new Logger('MauticDashboard', [$container->get('monolog.handler.database')], [$container->get('monolog.processor.web')]);
     });
 }
开发者ID:phproberto,项目名称:jstats-server,代码行数:39,代码来源:MonologServiceProvider.php

示例4: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   4.0
  */
 public function register(Container $container)
 {
     $container->share('JApplicationAdministrator', function (Container $container) {
         $app = new \JApplicationAdministrator(null, null, null, $container);
         // The session service provider needs JFactory::$application, set it if still null
         if (JFactory::$application === null) {
             JFactory::$application = $app;
         }
         $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface'));
         $app->setLogger(JLog::createDelegatedLogger());
         $app->setSession($container->get('Joomla\\Session\\SessionInterface'));
         return $app;
     }, true);
     $container->share('JApplicationSite', function (Container $container) {
         $app = new \JApplicationSite(null, null, null, $container);
         // The session service provider needs JFactory::$application, set it if still null
         if (JFactory::$application === null) {
             JFactory::$application = $app;
         }
         $app->setDispatcher($container->get('Joomla\\Event\\DispatcherInterface'));
         $app->setLogger(JLog::createDelegatedLogger());
         $app->setSession($container->get('Joomla\\Session\\SessionInterface'));
         return $app;
     }, true);
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:34,代码来源:Application.php

示例5: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->alias('Stats\\Application', 'Joomla\\Application\\AbstractApplication')->alias('Joomla\\Application\\AbstractWebApplication', 'Joomla\\Application\\AbstractApplication')->share('Joomla\\Application\\AbstractApplication', function (Container $container) {
         $application = new Application($container->get('Joomla\\Input\\Input'), $container->get('config'));
         // Inject extra services
         $application->setRouter($container->get('Stats\\Router'));
         return $application;
     }, true);
     $container->share('Joomla\\Input\\Input', function () {
         return new Input($_REQUEST);
     }, true);
     $container->share('Stats\\Router', function (Container $container) {
         $router = (new Router($container->get('Joomla\\Input\\Input')))->setContainer($container)->setControllerPrefix('Stats\\Controllers\\')->setDefaultController('DisplayController')->addMap('/submit', 'SubmitController')->addMap('/:source', 'DisplayController');
         return $router;
     }, true);
     $container->share('Stats\\Controllers\\DisplayControllerGet', function (Container $container) {
         $controller = new DisplayControllerGet($container->get('Stats\\Views\\Stats\\StatsJsonView'));
         $controller->setApplication($container->get('Joomla\\Application\\AbstractApplication'));
         $controller->setInput($container->get('Joomla\\Input\\Input'));
         return $controller;
     }, true);
     $container->share('Stats\\Controllers\\SubmitControllerCreate', function (Container $container) {
         $controller = new SubmitControllerCreate($container->get('Stats\\Models\\StatsModel'));
         $controller->setApplication($container->get('Joomla\\Application\\AbstractApplication'));
         $controller->setInput($container->get('Joomla\\Input\\Input'));
         return $controller;
     }, true);
     $container->share('Stats\\Models\\StatsModel', function (Container $container) {
         return new StatsModel($container->get('Joomla\\Database\\DatabaseDriver'));
     }, true);
     $container->share('Stats\\Views\\Stats\\StatsJsonView', function (Container $container) {
         return new StatsJsonView($container->get('Stats\\Models\\StatsModel'));
     }, true);
 }
开发者ID:alikon,项目名称:jstats-server,代码行数:43,代码来源:ApplicationServiceProvider.php

示例6: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  */
 public function register(Container $container)
 {
     // QueryHelper
     $container->share('model.' . $this->name . '.helper.query', function ($container) {
         return new QueryHelper();
     });
     // Filter
     $container->share('model.' . $this->name . '.filter', function ($container) {
         return new FilterHelper();
     })->alias('model.' . $this->name . '.helper.filter', 'model.' . $this->name . '.filter');
     // Search
     $container->share('model.' . $this->name . '.search', function ($container) {
         return new SearchHelper();
     })->alias('model.' . $this->name . '.helper.search', 'model.' . $this->name . '.search');
 }
开发者ID:beingsane,项目名称:quickcontent,代码行数:22,代码来源:GridProvider.php

示例7: register

 /**
  * Registers the service provider within a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.2
  */
 public function register(Container $container)
 {
     $that = $this;
     $container->share('logger', function (Container $c) use($that) {
         return $that->getLogger($c);
     }, true);
 }
开发者ID:simonfork,项目名称:tagaliser,代码行数:16,代码来源:LoggerServiceProvider.php

示例8: register

 /**
  * {@inheritdoc}
  */
 public function register(Container $container)
 {
     $config = $this->config;
     $container->share('config', function () use($config) {
         return $config;
     });
 }
开发者ID:KBO-Techo-Dev,项目名称:MagazinePro-jfw,代码行数:10,代码来源:ConfigServiceProvider.php

示例9: register

 /**
  * Registers the service provider within a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.1
  */
 public function register(Container $container)
 {
     $that = $this;
     $container->share('github', function (Container $c) use($that) {
         return $that->getGithub($c);
     }, true);
 }
开发者ID:simonfork,项目名称:tagaliser,代码行数:16,代码来源:GithubServiceProvider.php

示例10: register

 /**
  * Registers the service provider within a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.2
  */
 public function register(Container $container)
 {
     $that = $this;
     $container->share('config', function ($c) use($that) {
         return $that->getConfig($c);
     }, true);
 }
开发者ID:simonfork,项目名称:tagaliser,代码行数:16,代码来源:ConfigServiceProvider.php

示例11: testGetNewInstance

 /**
  * @testdox getNewInstance() will always return a new instance, even if the resource was set to be shared
  */
 public function testGetNewInstance()
 {
     $container = new Container();
     $container->share('foo', function () {
         return new \stdClass();
     });
     $this->assertNotSame($container->getNewInstance('foo'), $container->getNewInstance('foo'));
 }
开发者ID:nibra,项目名称:joomla-pythagoras,代码行数:11,代码来源:ContainerAccessTest.php

示例12: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->share('cck', function ($container) {
         return new CCKEngine($container->get('app'), $container->get('event.dispatcher'), $container);
     });
     \JForm::addFieldPath(__DIR__ . '/Fields');
     \JForm::addFormPath(__DIR__ . '/Resource/Form');
 }
开发者ID:ForAEdesWeb,项目名称:AEW3,代码行数:17,代码来源:CCKProvider.php

示例13: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns the container to support chaining.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function register(Container $container)
 {
     $container->share('JTracker\\Github\\Github', function () use($container) {
         // Call the Github factory's getInstance method and inject the application; it handles the rest of the configuration
         return GithubFactory::getInstance($container->get('app'));
     }, true);
     // Alias the object
     $container->alias('gitHub', 'JTracker\\Github\\Github');
 }
开发者ID:dextercowley,项目名称:jissues,代码行数:19,代码来源:GitHubProvider.php

示例14: testShareProtected

 /**
  * Tests the protected method when passing the shared arg..
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testShareProtected()
 {
     $this->fixture->share('foo', function () {
         return new \stdClass();
     }, true);
     $dataStore = $this->readAttribute($this->fixture, 'dataStore');
     $this->assertTrue($dataStore['foo']['protected'], 'The shared method does set protected when passed true as third arg.');
     $this->assertTrue($dataStore['foo']['shared'], 'The share convenience method sets items as shared.');
 }
开发者ID:ZerGabriel,项目名称:joomla-framework,代码行数:16,代码来源:ContainerTest.php

示例15: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  */
 public function register(Container $container)
 {
     // Global Config
     $container->share('joomla.config', array('JFactory', 'getConfig'));
     // Windwalker Config
     $container->share('windwalker.config', array($this, 'loadConfig'));
     // Database
     $this->share($container, 'db', 'JDatabaseDriver', array('JFactory', 'getDbo'));
     // Session
     // Global Config
     $container->share('session', function () {
         return \JFactory::getSession();
     });
     // Language
     $this->share($container, 'language', 'JLanguage', array('JFactory', 'getLanguage'));
     // Dispatcher
     $this->share($container, 'event.dispatcher', 'JEventDispatcher', array('JEventDispatcher', 'getInstance'));
     // Mailer
     $this->share($container, 'mailer', 'JMail', array('JFactory', 'getMailer'));
     // Date
     $this->set($container, 'date', 'JDate', function () {
         return DateHelper::getDate();
     });
     // Global
     $container->set('SplPriorityQueue', function () {
         return new \SplPriorityQueue();
     });
     // Asset
     $container->share('helper.asset', function () {
         return \Windwalker\Asset\AssetManager::getInstance();
     });
     // Relation
     $container->share('relation.container', function () {
         return new RelationContainer();
     });
     // Detect deferent environment
     if ($this->isConsole) {
         $container->registerServiceProvider(new CliProvider());
     } else {
         $container->registerServiceProvider(new WebProvider());
     }
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:49,代码来源:SystemProvider.php


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