Exemplo n.º 1
0
 /**
  * @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);
     }
 }
Exemplo 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);
 }
Exemplo 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;
 }
Exemplo n.º 10
0
Arquivo: App.php Projeto: 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));
 }
Exemplo 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]);
 }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo n.º 17
0
 /**
  * @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);
 }
Exemplo n.º 22
0
 /**
  * @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]);
 }
Exemplo 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]);
 }
Exemplo n.º 27
0
 /**
  * @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]);
 }
Exemplo n.º 28
0
 /**
  * @param $filter
  * @param IRoute $route
  *
  * @return bool
  */
 public function invoke($filter, IRoute $route)
 {
     return $this->container->call($filter, ['route' => $route]);
 }