Author: Matthieu Napoli (matthieu@mnapoli.fr)
Inheritance: implements Interop\Container\ContainerInterface, implements di\FactoryInterface, implements DI\InvokerInterface
Esempio n. 1
0
 /**
  * @param Container $container
  * @throws \DI\NotFoundException
  */
 public function __construct(Container $container)
 {
     /** @var \GeoVisualizer\Collector\Twitter\ApiFactory $apiFactory */
     $apiFactory = $container->get('\\GeoVisualizer\\Collector\\Twitter\\ApiFactory');
     /** @var \TwitterOAuth\Api $api */
     $this->api = $apiFactory->create($container);
 }
Esempio n. 2
0
 /**
  * @param Container $container
  * @throws \DI\NotFoundException
  */
 public function __construct(Container $container)
 {
     /** @var Configuration $configuration */
     $configuration = $container->get('\\GeoVisualizer\\Visualizer\\GoogleMaps\\Configuration');
     $array = $configuration->parseConfiguration();
     $this->apiKey = $array[Configuration::API_KEY];
 }
Esempio n. 3
0
 protected function readyApiMock()
 {
     $this->apiMock = \Mockery::mock(QiitaAPIInterface::class);
     $this->container->set('api', $this->apiMock);
     $this->container->set(QiitaAPIInterface::class, $this->apiMock);
     Model::setApi($this->apiMock);
 }
Esempio n. 4
0
 /**
  * @param InvokeAction $message
  * @param mixed        $actionResult
  *
  * @return void
  */
 private function respond(InvokeAction $message, $actionResult)
 {
     if ($message->action->getResponder() === null) {
         return;
     }
     $this->container->call($message->action->getResponder(), $actionResult ? ['data' => $actionResult] : []);
 }
Esempio n. 5
0
 public function createFeatureFromClassName(string $featureClassName) : Feature
 {
     if (!in_array($featureClassName, $this->listFeatures())) {
         throw new UnknownFeatureException(sprintf('Unknown feature class `%s`', $featureClassName));
     }
     return $this->container->get($featureClassName);
 }
 public function resolve(ServerRequestInterface $request, Container $container) : Command
 {
     if (!$this->isResolvable($request)) {
         throw new UnresolvableCommandException();
     }
     return $container->get($this->commandClassName);
 }
Esempio n. 7
0
 /**
  * @param Container $container
  * @return Api
  * @throws \DI\NotFoundException
  */
 public function create(Container $container)
 {
     /** @var Configuration $configuration */
     $configuration = $container->get('\\GeoVisualizer\\Collector\\Twitter\\Configuration');
     $array = $configuration->parseConfiguration();
     return new Api($array[Configuration::CONSUMER_KEY], $array[Configuration::CONSUMER_SECRET], $array[Configuration::OAUTH_TOKEN], $array[Configuration::OAUTH_TOKEN_SECRET]);
 }
Esempio n. 8
0
 public function run()
 {
     $this->db = $this->container->get('db');
     $this->db['last_run'] = date('Y-m-d H:i:s');
     \Util::debug('Connecting to Skype');
     $this->core->initSkypeConnection();
     \Util::debug('Initializing plugins');
     $this->container->get('Bot\\Plugins\\Infrastructure\\Broker')->initPlugins();
     /** @var LoopInterface $loop */
     $loop = $this->container->get('loop');
     /** @var EventEmitter $ev */
     $ev = $this->container->get('event');
     if (isset($this->db['restart']) && $this->db['restart']) {
         list($chatName, $restartTime) = $this->db['restart'];
         $this->core->send($chatName, 'Я сделяль!');
         unset($this->db['restart']);
     }
     $loop->addPeriodicTimer(0.0001, function () use($ev, $loop) {
         $this->core->poll();
         //                $this->webCore->poll();
         $ev->emit('tick', [microtime(true)]);
     });
     \Util::debug('Running main loop');
     $loop->run();
 }
 /**
  * Create a collector registry, then add each collector
  * @todo Refactor so it does not use the DI container like a service locator
  * @param Container $container
  * @return Registry
  */
 public function create(Container $container)
 {
     $registry = new Registry();
     $collector = $container->get('\\GeoVisualizer\\Collector\\Twitter\\Collector');
     $registry->addCollector($collector);
     return $registry;
 }
Esempio n. 10
0
 /**
  * @param string $configName
  * @return array|null
  * @throws \DI\NotFoundException
  * @throws ParseException
  * @throws \InvalidArgumentException
  * @throws DependencyException
  */
 private function loadPluginConfig($configName)
 {
     $configPath = $this->container->get('config.path') . DS . 'plugins' . DS . $configName . '.yml';
     if (!file_exists($configPath)) {
         return null;
     }
     return Yaml::parse($configPath);
 }
 protected function createContainer()
 {
     $container = new Container();
     $container->set('array_iterator', new \ArrayIterator(range(1, 5)));
     $container->set('error', function () {
         throw new \RuntimeException();
     });
     return new PHPDIContainerAdapter($container);
 }
 public function create(Container $c)
 {
     $host = $c->get("parameters")['database']['host'];
     $dbName = $c->get("parameters")['database']['dbName'];
     $user = $c->get("parameters")['database']['user'];
     $password = $c->get("parameters")['database']['password'];
     $pdo = new \PDO("mysql:host={$host};dbname={$dbName}", $user, $password);
     return $pdo;
 }
Esempio n. 13
0
 /**
  * Handle an incoming request.
  *
  * @param Container $container
  * @param  Closure $next
  * @return mixed
  * @throws \DI\NotFoundException
  */
 public function handle(Container $container, Closure $next)
 {
     $request = $container->get(Request::class);
     if (!$request->ajax()) {
         $view = $container->get(View::class)->render('errors.403');
         return $container->get(Response::class)->forbidden($view);
     }
     return $next();
 }
Esempio n. 14
0
 /**
  * Configure the engine and start it.
  *
  * Compute and register some information such as computed global configuration,
  * input, output etc to the DI container for easier access later to
  * lower level components.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 public function configAndStart(InputInterface $input, OutputInterface $output)
 {
     $startUpMsg = "\n" . "Starting the test run. Version ( " . Application::APP_VERSION . " )\n" . "Type character h for help when prompted for an input value.\n";
     $output->writeln($startUpMsg);
     $config = $this->configFactory->config($input, $output);
     $this->container->set('Box\\TestScribe\\Config\\GlobalComputedConfig', $config);
     App::Init($this->appInstance);
     $this->engine->start();
 }
 public function getController(Request $request)
 {
     $controller = $this->resolver->getController($request);
     if (!$controller instanceof \Closure) {
         $instance = is_array($controller) ? reset($controller) : $controller;
         if (is_object($instance)) {
             $this->container->injectOn($instance);
         }
     }
     return $controller;
 }
Esempio n. 16
0
 /**
  * @param GetResponseEvent $event
  */
 public function handle(GetResponseEvent $event)
 {
     $securityAuthRealm = $this->container->get('security.authRealm');
     $request = $event->getRequest();
     $uri = $request->getRequestUri();
     foreach ($securityAuthRealm as $authRealm => $realmConfig) {
         if (isset($realmConfig['authRoute']) && preg_match('#' . $realmConfig['authRoute'] . '#', $uri)) {
             $event->setResponse($event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true));
             return;
         }
     }
 }
 /**
  * @param $path
  * @return null
  * @throws \DI\NotFoundException
  */
 private function getAuthRealm($path)
 {
     $realm = null;
     foreach ($this->container->get('security.firewall') as $route => $config) {
         $regex = '#' . $route . '#';
         if (preg_match($regex, $path) && isset($config['authRealm'])) {
             $realm = $config['authRealm'];
             break;
         }
     }
     return $realm;
 }
Esempio n. 18
0
 /**
  * Returns the dependency injection container
  *
  * @return \DI\Container
  */
 public function getDiContainer()
 {
     if (!$this->diContainer) {
         $builder = new ContainerBuilder();
         //			$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
         $builder->setDefinitionCache(new FilesystemCache(__DIR__ . '/../../var/Cache/'));
         $builder->addDefinitions(__DIR__ . '/../../Classes/Configuration/dependencyInjectionConfiguration.php');
         $this->diContainer = $builder->build();
         //			$this->diContainer = ContainerBuilder::buildDevContainer();
         $this->diContainer->get('Cundd\\PersistentObjectStore\\Event\\SharedEventEmitter');
     }
     return $this->diContainer;
 }
Esempio n. 19
0
 public function createProcessorsFor(IndexedEntity $entity) : array
 {
     switch ($entityClassName = get_class($entity)) {
         default:
             throw new NoProcessorForEntityException(sprintf('No entity processor available for `%s`', $entityClassName));
         case Profile::class:
             return [$this->container->get(PublicProfilesProcessor::class), $this->container->get(PublicExpertsProcessor::class)];
         case Collection::class:
             return [$this->container->get(PublicCollectionsProcessor::class)];
         case Community::class:
             return [$this->container->get(PublicCommunitiesProcessor::class)];
         case Post::class:
             return [$this->container->get(ProfileProcessor::class), $this->container->get(CollectionProcessor::class), $this->container->get(CommunityProcessor::class), $this->container->get(PublicContentProcessor::class), $this->container->get(PublicDiscussionsProcessor::class)];
     }
 }
Esempio n. 20
0
 /**
  * Run middleware
  *
  * @param $routeParams
  * @return mixed
  * @throws \DI\NotFoundException
  */
 private function handleMiddleware($routeParams)
 {
     $middlewareInstance = $this->container->get($routeParams['middleware']);
     return $middlewareInstance->handle($this->container, function () use($routeParams) {
         return $this->handleController($routeParams['controller']);
     });
 }
Esempio n. 21
0
 /**
  * Отправить ответ.
  *
  * @param Response $response
  */
 protected function sendResponse(Response $response)
 {
     /** @var Request $request */
     $request = $this->container->get(Request::class);
     $response->prepare($request);
     $response->send();
 }
Esempio n. 22
0
 /**
  * run Application
  */
 public function run()
 {
     $response = $this->container->get(TwigResponse::class);
     $response->setTemplate('error/404');
     try {
         $this->eventDispatcher->addSubscriber($this->routerListener);
         $response = $this->httpKernel->handle($this->request);
     } catch (ResourceNotFoundException $e) {
         $response->setContent(['message' => $e->getMessage()]);
     } catch (\Exception $e) {
         //            $response->setContent(['message' => $e->getMessage()]);
         throw $e;
     } finally {
         $response->send();
         $this->httpKernel->terminate($this->request, $response);
     }
 }
Esempio n. 23
0
 /**
  * Returns an entry of the container by its name.
  *
  * @see \DI\Container::get
  *
  * @param string $name
  *
  * @throws \Slim\Exception\ContainerValueNotFoundException
  *
  * @return mixed
  */
 public function get($name)
 {
     try {
         return parent::get($name);
     } catch (\Exception $exception) {
         throw new ContainerValueNotFoundException($exception->getMessage());
     }
 }
Esempio n. 24
0
 /**
  * @param $class
  * @return ControllerInterface
  * @throws RouterException
  */
 private function constructController($class)
 {
     if (class_exists($class)) {
         $controller = $this->container->get($class);
         return $controller;
     } else {
         throw new RouterException("Controller can not be found.");
     }
 }
Esempio n. 25
0
 /**
  * Executa o watcher determinado para a rota encontrada.
  *
  * @param string $watcher_name
  * @param $controller
  * @param array $params
  * @return
  */
 private function runWatcher($watcher_name, $controller, $params = [])
 {
     $watcher_name = ucfirst($watcher_name) . 'Watcher';
     $full_name_watcher = mountCtrlFullName($watcher_name, [$this->app_root_namespace, 'Watchers']);
     $watcher = $this->di->get($full_name_watcher);
     $watcher->setController($controller);
     $watcher->setUrlParams($params);
     return $watcher->run();
 }
Esempio n. 26
0
 /**
  * Returns an instantiated controller
  *
  * @param string $class A class name
  *
  * @return object
  */
 protected function instantiateController($class)
 {
     $obj = $this->container->get($class);
     if ($obj instanceof LoggerAwareInterface) {
         $obj->setLogger($this->logger);
     }
     if ($obj instanceof ContainerAwareInterface) {
         $obj->setContainer($this->container);
     }
     return $obj;
 }
 protected function registerMocks()
 {
     $parser = new PhpDocReader();
     $class = new ReflectionClass($this);
     $registeredNames = array();
     //Find every member that begins with "mock" or "spy"
     foreach ($class->getProperties() as $property) {
         if (strpos($property->name, 'mock') === 0 || strpos($property->name, 'spy') === 0) {
             if ($property->name == "mockObjects") {
                 //This is inherited from PHPUnit_Framework_TestCase and we can't mock it
                 continue;
             }
             //Use the type as the DI name
             $name = $parser->getPropertyType($property);
             //TODO: Check for duplicates
             //$this->DIContainer->getDefinitionManager()->getDefinition()
             $property->setAccessible(true);
             $this->DIContainer->set($name, $property->getValue($this));
         }
     }
 }
Esempio n. 28
0
 /**
  * start the application
  *
  * Call the module controller and the appropriate method
  *
  * @throws \DI\NotFoundException
  */
 public function run()
 {
     /**
      * @var ControllerInterface $controller
      */
     $controller = $this->moduleDiContainer->get('Controller');
     if ($controller instanceof ControllerInterface) {
         $controller->setDic($this->moduleDiContainer);
     }
     $method = $this->method;
     $controller->{$method}();
 }
Esempio n. 29
0
 /**
  * @inheritdoc
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $route = $request->getAttribute('route');
     /**
      * Controller Class name
      */
     $controllerClass = $this->getFullControllerName($route->attributes['module'], $route->attributes['controller']);
     /**
      * Check class existence
      */
     if ($this->controllerClassExists($controllerClass)) {
         // Instance of controller
         $controller = $this->diContainer->get($controllerClass);
         $action = $this->getFullActionName($route->attributes['action']);
         // Check existence of controller action
         if (!method_exists($controller, $action)) {
             throw new NotFoundHttpException(sprintf('Controller "%s" has no action "%s".', $controllerClass, $action));
         }
         // Call controller action
         return $next($request, $controller->{$action}($request, $response), $next);
     }
 }
Esempio n. 30
0
 /**
  * @param string $controller
  *
  * @return GenericController
  */
 private function getControllerInstance(string $controller)
 {
     if ($this->container && $this->container->has($controller)) {
         $obj = $this->container->get($controller);
     }
     if (!isset($obj)) {
         $obj = new $controller();
         if ($this->container) {
             $this->container->injectOn($obj);
         }
     }
     return $obj;
 }