/**
  * @param IContainer $container
  */
 public function initialize(IContainer $container)
 {
     $container->set([ISwiftMailerManager::class, SwiftMailerManager::class], SwiftMailerManager::class)->singleton();
     $container->set([SwiftMailer::class, Swift_Mailer::class], function (SwiftMailerManager $swiftMailerManager) {
         return $swiftMailerManager->getMailer();
     });
 }
 function it_initializes(IHttpApp $httpApp, IErrorHandler $errorHandler, IContainer $container)
 {
     $httpApp->getDebug()->willReturn(true);
     $errorHandler->addErrorHandler(Argument::any())->shouldBeCalled();
     $errorHandler->addExceptionHandler(Argument::any())->shouldBeCalled();
     $container->set(JsonErrorHandler::class, Argument::type(JsonErrorHandler::class))->shouldBeCalled();
     $this->initialize($httpApp, $errorHandler, $container);
 }
 /**
  * @param IContainer $container
  * @param IMonologErrorHandlerConfig $monologConfig
  * @param IErrorHandler $errorHandler
  * @param IMonologChannelManager $channelManager
  */
 public function initialize(IContainer $container, IMonologErrorHandlerConfig $monologConfig, IErrorHandler $errorHandler, IMonologChannelManager $channelManager)
 {
     $logger = $channelManager->getLogger($monologConfig->getErrorChannelName());
     $monologErrorHandler = new MonologErrorHandler($logger, $errorHandler);
     $monologErrorHandler->enableErrorHandling();
     $monologErrorHandler->enableExceptionHandling();
     $container->set(MonologErrorHandler::class, $monologErrorHandler);
 }
 /**
  * @param IRoute $route
  * @param IContainer $container
  *
  * @return mixed
  */
 public function invoke(IRoute $route, IContainer $container)
 {
     list($controller, $method) = $this->extractControllerAndMethod($route->getAction());
     $this->ensureClassExists($controller);
     $instance = $container->get($controller);
     $this->ensureMethodExists($instance, $method);
     return $container->callMethod($instance, $method, $route->getParameters());
 }
 /**
  * @param IBlackHoleErrorHandlerConfig $config
  * @param IErrorHandler $errorHandler
  * @param IContainer $container
  */
 public function initialize(IBlackHoleErrorHandlerConfig $config, IErrorHandler $errorHandler, IContainer $container)
 {
     if ($config->getEnabled()) {
         $errorHandler = new BlackHoleErrorHandler($errorHandler);
         $errorHandler->enable();
         $container->set(BlackHoleErrorHandler::class, $errorHandler);
     }
 }
 /**
  * @param IContainer $container
  * @param ErrorHandler $errorHandler
  *
  * @throws \Weew\ErrorHandler\Exceptions\InvalidHandlerType
  */
 public function initialize(IContainer $container, ErrorHandler $errorHandler)
 {
     $container->set([ErrorHandler::class, IErrorHandler::class], $errorHandler);
     $errorHandler->enableErrorHandling();
     $errorHandler->enableExceptionHandling();
     $errorHandler->addErrorHandler([$this, 'handleError']);
     $errorHandler->addExceptionHandler([$this, 'handleException']);
 }
 /**
  * @param IApp $app
  * @param IErrorHandler $errorHandler
  * @param IContainer $container
  */
 public function initialize(IApp $app, IErrorHandler $errorHandler, IContainer $container)
 {
     if ($app instanceof IHttpApp && $app->getDebug()) {
         $jsonErrorHandler = new JsonErrorHandler($app, $errorHandler);
         $jsonErrorHandler->enableErrorHandling();
         $jsonErrorHandler->enableExceptionHandling();
         $container->set(JsonErrorHandler::class, $jsonErrorHandler);
     }
 }
Esempio n. 8
0
 function it_shares_an_instance_of_the_default_logger_in_the_container()
 {
     $channelManager = $this->createChannelManager();
     expect($this->container->has(LoggerInterface::class))->shouldBe(false);
     $this->initialize($this->container, $channelManager);
     expect($this->container->has(LoggerInterface::class))->shouldBe(true);
     expect($this->container->has(Logger::class))->shouldBe(true);
     $logger = $this->container->get(LoggerInterface::class);
     $defaultLogger = $channelManager->getLogger();
     expect($logger)->shouldBe($defaultLogger);
 }
Esempio n. 9
0
 /**
  * @param $abstract
  * @param array $args
  *
  * @return mixed
  */
 protected function resolveAbstract($abstract, array $args)
 {
     if (is_callable($abstract)) {
         return $this->container->call($abstract, $args);
     } else {
         if (is_object($abstract)) {
             return $abstract;
         } else {
             if (class_exists($abstract)) {
                 return $this->getClass(new ClassDefinition($abstract, null), $args);
             }
         }
     }
     return null;
 }
Esempio n. 10
0
File: App.php Progetto: weew/app
 /**
  * Start App.
  */
 public function start()
 {
     if ($this->started) {
         return;
     }
     $this->started = true;
     $this->getConfigLoader()->setEnvironment($this->getEnvironment());
     $this->config = $this->getConfigLoader()->load();
     $this->container->set([Config::class, IConfig::class], $this->config);
     $this->config->set('env', $this->getEnvironment());
     $this->config->set('debug', $this->getDebug());
     $this->eventer->dispatch(new ConfigLoadedEvent($this->config));
     $this->kernel->initialize();
     $this->eventer->dispatch(new KernelInitializedEvent($this->kernel));
     $this->kernel->boot();
     $this->eventer->dispatch(new KernelBootedEvent($this->kernel));
     $this->eventer->dispatch(new AppStartedEvent($this));
 }
Esempio n. 11
0
 /**
  * @param IContainer $container
  * @param ReflectionParameter $parameter
  *
  * @return mixed
  * @throws Exception
  * @throws ValueNotFoundException
  */
 protected function getParameterFromContainer(IContainer $container, ReflectionParameter $parameter)
 {
     try {
         return $container->get($parameter->getClass()->getName());
     } catch (Exception $ex) {
         $ignoreException = $ex instanceof ValueNotFoundException || $ex instanceof ImplementationNotFoundException;
         if (!($ignoreException && $parameter->isDefaultValueAvailable())) {
             throw $ex;
         }
     }
 }
 /**
  * @param callable $subscriber
  * @param IEvent $event
  */
 protected function invokeSubscriber(callable $subscriber, IEvent $event)
 {
     $this->container->call($subscriber, ['event' => $event]);
 }
Esempio n. 13
0
 /**
  * @param IContainer $container
  */
 public function initialize(IContainer $container)
 {
     $container->set(IDoctrineConfig::class, DoctrineConfig::class);
     $container->set([EntityManager::class, ObjectManager::class, EntityManagerInterface::class], [$this, 'createEntityManager'])->singleton();
 }
 /**
  * BugsnagErrorHandlerProvider constructor.
  *
  * @param IContainer $container
  */
 public function __construct(IContainer $container)
 {
     $container->set(IBugsnagErrorHandlerConfig::class, BugsnagErrorHandlerConfig::class);
     $container->set(BugsnagErrorHandler::class, [$this, 'createBugsnagErrorHandler'])->singleton();
 }
 /**
  * Share instances in the container.
  */
 protected function shareInstancesInContainer()
 {
     $this->container->set([Router::class, IRouter::class], $this->router);
     $this->container->set([RequestHandler::class, IRequestHandler::class], $this->requestHandler);
 }
Esempio n. 16
0
 /**
  * @param IContainer $container
  * @param MonologChannelManager $channelManager
  */
 public function initialize(IContainer $container, MonologChannelManager $channelManager)
 {
     $container->set([LoggerInterface::class, Logger::class], $channelManager->getLogger());
     $container->set([IMonologChannelManager::class, MonologChannelManager::class], $channelManager);
 }
 /**
  * @param object $provider
  * @param IDictionary $shared
  */
 public function shutdown($provider, IDictionary $shared)
 {
     $this->container->callMethod($provider, 'shutdown', ['shared' => $shared]);
 }
 /**
  * @param $subscriber
  * @param IEvent $event
  */
 protected function invokeSubscriber($subscriber, IEvent $event)
 {
     $this->container->callMethod($subscriber, 'handle', ['event' => $event]);
 }
 /**
  * @param callable $handler
  * @param $command
  *
  * @return mixed
  */
 protected function invokeHandler(callable $handler, $command)
 {
     return $this->container->call($handler, ['command' => $command, 'task' => $command]);
 }
 /**
  * @return mixed
  */
 public function enable()
 {
     $this->container->set($this->repositoryNameParser->getRepositoryNamePattern(), [$this, 'getRepository'])->singleton();
 }
 function it_enables_error_handling(IBlackHoleErrorHandlerConfig $config, IErrorHandler $errorHandler, IContainer $container)
 {
     $config->getEnabled()->willReturn(true);
     $container->set(BlackHoleErrorHandler::class, Argument::type(BlackHoleErrorHandler::class))->shouldBeCalled();
     $this->initialize($config, $errorHandler, $container);
 }
 /**
  * @param $callable
  * @param IRouter $router
  */
 public function invoke($callable, IRouter $router)
 {
     $this->container->call($callable, ['router' => $router]);
 }
 /**
  * @param IRoute $route
  * @param IContainer $container
  *
  * @return mixed
  */
 public function invoke(IRoute $route, IContainer $container)
 {
     return $container->call($route->getAction(), $route->getParameters());
 }
 /**
  * @param $handler
  * @param $command
  *
  * @return mixed
  */
 protected function invokeHandler($handler, $command)
 {
     return $this->container->callMethod($handler, 'handle', ['command' => $command, 'task' => $command]);
 }
Esempio n. 25
0
 /**
  * @param IContainer $container
  */
 public function initialize(IContainer $container)
 {
     $container->set([TwigLoader::class, Twig_Loader_Filesystem::class], [$this, 'createTwigLoaderFilesystem'])->singleton();
     $container->set([Twig::class, Twig_Environment::class], [$this, 'createTwigEnvironment'])->singleton();
 }
 /**
  * @param $resolver
  * @param $parameter
  *
  * @return mixed
  */
 public function invoke($resolver, $parameter)
 {
     return $this->container->call($resolver, ['parameter' => $parameter]);
 }
 /**
  * @param object $handler
  * @param IInput $input
  * @param IOutput $output
  * @param IConsole $console
  *
  * @return mixed
  */
 public function run($handler, IInput $input, IOutput $output, IConsole $console)
 {
     return $this->container->callMethod($handler, 'run', ['input' => $input, 'in' => $input, 'output' => $output, 'out' => $output, 'console' => $console]);
 }
 /**
  * @param $filter
  * @param IRoute $route
  *
  * @return bool
  */
 public function invoke($filter, IRoute $route)
 {
     return $this->container->call($filter, ['route' => $route]);
 }