Ejemplo n.º 1
0
 /**
  * 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');
 }
Ejemplo n.º 2
0
 /**
  * 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());
     }
 }
 /**
  * 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')]);
     });
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * 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');
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $container)
 {
     $config = $this->config;
     $container->share('config', function () use($config) {
         return $config;
     });
 }
Ejemplo n.º 9
0
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * 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);
 }
Ejemplo n.º 11
0
 /**
  * @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'));
 }
Ejemplo n.º 12
0
 /**
  * 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');
 }
Ejemplo n.º 13
0
 /**
  * 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');
 }
Ejemplo n.º 14
0
 /**
  * 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.');
 }
Ejemplo n.º 15
0
 /**
  * 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());
     }
 }
 /**
  * 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(Application::class, JoomlaApplication\AbstractApplication::class)->alias(JoomlaApplication\AbstractWebApplication::class, JoomlaApplication\AbstractApplication::class)->share(JoomlaApplication\AbstractApplication::class, function (Container $container) {
         $application = new Application($container->get(Input::class), $container->get('config'));
         // Inject extra services
         $application->setLogger($container->get('monolog.logger.application'));
         $application->setRouter($container->get(Router::class));
         return $application;
     }, true);
     $container->share(Input::class, function () {
         return new Input($_REQUEST);
     }, true);
     $container->share(Router::class, 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(DisplayControllerGet::class, function (Container $container) {
         $controller = new DisplayControllerGet($container->get(StatsJsonView::class));
         $controller->setApplication($container->get('Joomla\\Application\\AbstractApplication'));
         $controller->setInput($container->get('Joomla\\Input\\Input'));
         return $controller;
     }, true);
     $container->share(SubmitControllerCreate::class, function (Container $container) {
         $controller = new SubmitControllerCreate($container->get('Stats\\Models\\StatsModel'));
         $controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
         $controller->setInput($container->get(Input::class));
         return $controller;
     }, true);
     $container->share(SubmitControllerGet::class, function (Container $container) {
         $controller = new SubmitControllerGet();
         $controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
         $controller->setInput($container->get(Input::class));
         return $controller;
     }, true);
     $container->share(StatsModel::class, function (Container $container) {
         return new StatsModel($container->get(DatabaseDriver::class));
     }, true);
     $container->share(StatsJsonView::class, function (Container $container) {
         return new StatsJsonView($container->get(StatsModel::class));
     }, true);
 }
 /**
  * @testdox An extended resource replaces the original resource
  */
 public function testExtend()
 {
     $container = new Container();
     $container->share('foo', function () {
         return new \stdClass();
     });
     $value = 42;
     $container->extend('foo', function ($shared) use($value) {
         $shared->value = $value;
         return $shared;
     });
     $one = $container->get('foo');
     $this->assertEquals($value, $one->value);
     $two = $container->get('foo');
     $this->assertEquals($value, $two->value);
     $this->assertSame($one, $two);
 }
 /**
  * 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)
 {
     $name = $this->name;
     // Component
     $container->alias('component', ucfirst($name) . 'Component')->share(ucfirst($name) . 'Component', $this->component);
     // ControllerResolver
     $resolverClass = '\\Windwalker\\Controller\\Resolver\\ControllerResolver';
     $container->alias('controller.resolver', $resolverClass)->share($resolverClass, function ($container) use($resolverClass) {
         return new $resolverClass($container->get('app'), $container);
     });
     // Asset Helper
     $container->share('helper.asset', function ($container) use($name) {
         $asset = AssetManager::getInstance('com_' . strtolower($name));
         $asset->setContainer($container);
         return $asset;
     });
 }
 /**
  * Registers the query bus service provider.
  *
  * @param   Container  $container  A dependency injection container.
  *
  * @return  void
  * 
  * @since   __DEPLOY__
  */
 public function register(Container $container)
 {
     $container->share('querybus', function (Container $container) {
         $handlerMiddleware = new CommandHandlerMiddleware(new ClassNameExtractor(), new CallableLocator(function ($queryName) use($container) {
             // Break apart the fully-qualified class name.
             // We do this so that the namespace path is not modified.
             $parts = explode('\\', $queryName);
             // Determine the handler class name from the query class name.
             $handlerName = str_replace('Query', 'QueryHandler', array_pop($parts));
             // Construct the fully-qualified class name of the handler.
             $serviceName = implode('\\', $parts) . '\\' . $handlerName;
             return new $serviceName($container);
         }), new HandleInflector());
         $middleware = array($handlerMiddleware);
         return new QueryBusBase($middleware);
     }, true);
 }
 /**
  * Registers the command bus service provider.
  *
  * @param   Container  $container  A dependency injection container.
  *
  * @return  void
  * 
  * @since   __DEPLOY__
  */
 public function register(Container $container)
 {
     $container->share('commandbus', function (Container $container) {
         $handlerMiddleware = new CommandHandlerMiddleware(new ClassNameExtractor(), new CallableLocator(function ($commandName) use($container) {
             // Break apart the fully-qualified class name.
             // We do this so that the namespace path is not modified.
             $parts = explode('\\', $commandName);
             // Determine the handler class name from the command class name.
             $handlerName = str_replace('Command', 'CommandHandler', array_pop($parts));
             // Construct the fully-qualified class name of the handler.
             $serviceName = implode('\\', $parts) . '\\' . $handlerName;
             return new $serviceName($container);
         }), new HandleInflector());
         // Note: LockingMiddleware prevents one command from being executed while another is already running.
         $middleware = array(new LockingMiddleware(), new DomainEventMiddleware($container, $container->get('dispatcher')), $handlerMiddleware);
         return new CommandBusBase($middleware);
     }, true);
 }
Ejemplo n.º 21
0
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function register(Container $container)
 {
     $container->share('Monolog\\Logger', function () use($container) {
         // Instantiate the object
         $logger = new Logger('JTracker');
         if (LoggerProvider::$fileName) {
             // Log to a file
             $logger->pushHandler(new StreamHandler($container->get('debugger')->getLogPath('root') . '/' . LoggerProvider::$fileName, Logger::INFO));
         } elseif ('1' != LoggerProvider::$quiet) {
             // Log to screen
             $logger->pushHandler(new StreamHandler('php://stdout'));
         } else {
             $logger = new NullLogger();
         }
         return $logger;
     }, true);
     // Alias the object
     $container->alias('logger', 'Monolog\\Logger');
 }
 /**
  * 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->share('Joomla\\Renderer\\RendererInterface', function (Container $container) {
         /* @type  \Joomla\Registry\Registry  $config */
         $config = $container->get('config');
         // Instantiate the renderer object
         $rendererConfig = array_merge((array) $config->get('template'), ['path' => JPATH_TEMPLATES]);
         // If the cache isn't false, then it should be a file path relative to the app root
         $rendererConfig['cache'] = $rendererConfig['cache'] === false ? $rendererConfig['cache'] : JPATH_ROOT . '/' . $rendererConfig['cache'];
         // Instantiate the renderer object
         $renderer = new TwigRenderer($rendererConfig);
         // Add our Twig extension
         $renderer->getRenderer()->addExtension(new TwigExtension($this->app));
         // Add the debug extension if enabled
         if ($config->get('template.debug')) {
             $renderer->getRenderer()->addExtension(new \Twig_Extension_Debug());
         }
         // Set the Lexer object
         $renderer->getRenderer()->setLexer(new \Twig_Lexer($renderer->getRenderer(), ['delimiters' => ['tag_comment' => ['{#', '#}'], 'tag_block' => ['{%', '%}'], 'tag_variable' => ['{{', '}}']]]));
         return $renderer;
     }, true);
     // Alias the renderer
     $container->alias('renderer', 'Joomla\\Renderer\\RendererInterface');
 }
Ejemplo n.º 23
0
 /**
  * Custom initialisation method.
  *
  * Called at the end of the Base::__construct method. This is for developers to inject initialisation code for their application classes.
  *
  * @return  void
  *
  * @codeCoverageIgnore
  * @since   1.0
  */
 protected function initialise()
 {
     // New DI stuff!
     $container = new Container();
     $input = $this->input;
     $container->share('input', function (Container $c) use($input) {
         return $input;
     }, true);
     $container->registerServiceProvider(new Providers\ConfigServiceProvider(TAGALISER_CONFIG));
     $container->registerServiceProvider(new Providers\GithubServiceProvider());
     $container->registerServiceProvider(new Providers\LoggerServiceProvider());
     $container->registerServiceProvider(new Providers\MustacheServiceProvider());
     $this->container = $container;
 }
 /**
  * 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->share('config', function () {
         return $this->config;
     }, true);
 }
 /**
  * Registers the domain event publisher service provider.
  *
  * @param   Container  $container  A dependency injection container.
  *
  * @return  void
  * 
  * @since   __DEPLOY__
  */
 public function register(Container $container)
 {
     $container->share('dispatcher', function (Container $container) {
         return \JEventDispatcher::getInstance();
     }, true);
 }
Ejemplo n.º 26
0
 /**
  * @testdox The convenience method share() sets resources as protected when passed true as third arg
  */
 public function testShareProtected()
 {
     $container = new Container();
     $container->share('foo', function () {
         return new \StdClass();
     }, true);
     $this->assertTrue($container->isShared('foo'));
     $this->assertTrue($container->isProtected('foo'));
 }