當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。