get() public method

Returns an entry of the container by its name.
public get ( string $name ) : mixed
$name string Entry name or a class name.
return mixed
Exemplo n.º 1
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);
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 public function offsetGet($id)
 {
     if (parent::offsetExists($id)) {
         return parent::offsetGet($id);
     }
     return $this->phpdi->get($id);
 }
Exemplo n.º 4
0
 /**
  * クライアントの準備
  * @return void
  */
 protected function boot()
 {
     $this->container->set('config', $this->config);
     $this->container->set('api', $this->container->get(QiitaAPIInterface::class));
     Model::setFactory($this->container);
     Model::setApi($this->container->get('api'));
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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();
 }
 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;
 }
 /**
  * @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;
 }
Exemplo n.º 9
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;
         }
     }
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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)];
     }
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
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]);
 }
Exemplo n.º 14
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];
 }
Exemplo n.º 15
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']);
     });
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
0
 public function resolve(ServerRequestInterface $request, Container $container) : Command
 {
     if (!$this->isResolvable($request)) {
         throw new UnresolvableCommandException();
     }
     return $container->get($this->commandClassName);
 }
Exemplo n.º 18
0
 /**
  * Отправить ответ.
  *
  * @param Response $response
  */
 protected function sendResponse(Response $response)
 {
     /** @var Request $request */
     $request = $this->container->get(Request::class);
     $response->prepare($request);
     $response->send();
 }
Exemplo n.º 19
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);
     }
 }
Exemplo n.º 20
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());
     }
 }
Exemplo n.º 21
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.");
     }
 }
Exemplo n.º 22
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();
 }
Exemplo n.º 23
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;
 }
Exemplo n.º 24
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}();
 }
Exemplo n.º 25
0
 public function fetch(Filter $filter) : array
 {
     $result = [];
     $scripts = Chain::create($this->bundlesService->getBundles())->filter(function (Bundle $bundle) {
         return $bundle instanceof FrontlineBundleInjectable;
     })->map(function (FrontlineBundleInjectable $bundle) {
         return $bundle->getFrontlineScripts();
     })->reduce(function (array $carry, array $scripts) {
         return array_merge($carry, $scripts);
     }, []);
     $scripts = array_map(function (string $script) {
         return $this->container->get($script);
     }, $scripts);
     foreach ($filter->filter($scripts) as $script) {
         if ($script instanceof FrontlineScript) {
             $result = array_merge_recursive($result, $script());
         } else {
             throw new \Exception();
         }
     }
     return $result;
 }
Exemplo n.º 26
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;
 }
Exemplo n.º 27
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);
     }
 }
Exemplo n.º 28
0
 /**
  * @param string $name
  * @return mixed
  * @throws \DI\NotFoundException
  */
 public function get($name)
 {
     $obj = parent::get($name);
     if ($obj instanceof LoggerAwareInterface) {
         $obj->setLogger($this->get(LoggerInterface::class));
     }
     if ($obj instanceof EventDispatcherAwareInterface) {
         $obj->setEventDispatcher($this->get(EventDispatcherInterface::class));
     }
     if ($obj instanceof ContainerAwareInterface) {
         $obj->setContainer($this);
     }
     return $obj;
 }
Exemplo n.º 29
0
 /**
  * Widget constructor.
  *
  * @param string $widgetClassNameOrAlias
  * @param Container $container
  */
 public function __construct($widgetClassNameOrAlias, Container $container)
 {
     $instance = $container->make($widgetClassNameOrAlias, ['wpWidget' => $this]);
     if (!in_array(WidgetInterface::class, class_implements($instance))) {
         throw new RuntimeException("Incorrect widget class name or widget does not implement WidgetInterface");
     }
     /**
      * Check if instance have listeners for wordpress
      * events which should be registered while
      * widget registering.
      */
     if ($instance instanceof ActionInterface || $instance instanceof DataFilterInterface) {
         $container->get('EventManager')->attachListeners($instance);
     }
     $this->getInstance = function () use($instance) {
         return $instance;
     };
     $params = $instance->getParams();
     $controlOption = [];
     if ($params instanceof ControlableInterface) {
         $controlOption = $params->getControlOptions();
     }
     parent::__construct($params->getId(), $params->getName(), $params->getOptions(), $controlOption);
 }
Exemplo n.º 30
0
 public function __invoke(Container $container) : EntityRepository
 {
     $em = $container->get(EntityManager::class);
     /** @var EntityManager $em */
     return $em->getRepository($this->entityClassName);
 }