/** * @param string $name * @return Wallet */ public function getWallet($name) { if (!isset($this->serviceMap[$name])) { throw new \Nette\InvalidArgumentException("Unknown wallet {$name}."); } return $this->serviceLocator->getService($this->serviceMap[$name]); }
/** * getter for specified model * * @param string $name name of model * @return BaseModel * @throws \InvalidArgumentException */ public function getModel($name) { if ($this->container->hasService($name)) { return $this->container->getService($name); } throw new \InvalidArgumentException("Model '{$name}' not found."); }
/** * @param string $name * @return \Blocktrail\SDK\Wallet * @throws \Nette\InvalidArgumentException */ public function getWallet($name = self::DEFAULT_NAME) { if (!isset($this->walletsServiceMap[$name])) { throw new \Nette\InvalidArgumentException("Unknown wallet '{$name}'."); } return $this->serviceLocator->getService($this->walletsServiceMap[$name]); }
/** * Vytvoří DB a naplní testovacími daty. */ public function runMigrations() { if (!$this->context->parameters['migrations']['enabled']) { return; } $connection = $this->context->getService('dibiConnection'); $dbNamePrefix = $this->context->parameters['testDbPrefix'] . date('Ymd_His') . '_' . rand(1, 1000) . '_'; $i = 1; do { $dbName = $dbNamePrefix . $i; $i++; } while ($connection->query('SHOW DATABASES WHERE %n', 'Database', ' = %s', $dbName)->count()); $connection->query('CREATE DATABASE %n COLLATE=utf8_czech_ci', $dbName); $connection->query('USE %n', $dbName); $migrationsPath = $this->context->parameters['wwwDir'] . '/' . $this->context->parameters['migrations']['path']; $finder = new Migration\Finders\MultipleDirectories(); $finder->addDirectory($migrationsPath . '/struct'); $finder->addDirectory($migrationsPath . '/data'); $migrations = $this->createRunner($connection); ob_start(); $migrations->run($finder, FALSE, TRUE); $result = ob_get_clean(); if (substr(strip_tags($result), -2) !== 'OK') { throw new \Exception('Migrace neproběhly v pořádku: ' . $result); } $this->context->parameters['testDbName'] = $dbName; }
/** * @param string $name * @return \Venne\Security\ILoginProvider */ public function getLoginProviderByName($name) { if (!isset($this->loginProviders[$name])) { throw new InvalidArgumentException(sprintf('Social login name \'%s\' has not been registered.', $name)); } return $this->context->getService($this->loginProviders[$name]); }
/** * @param $name * @return ILoginProvider * @throws InvalidArgumentException */ public function getLoginProviderByName($name) { if (!isset($this->loginProviders[$name])) { throw new InvalidArgumentException("Social login name '{$name}' has not been registered."); } return $this->content->getService($this->loginProviders[$name]); }
public function __construct(Context $context, Container $container, EntityManager $entityManager) { $this->context = $context; $this->container = $container; $this->em = $entityManager; $this->cache = $this->container->getService('cacheStorage'); }
/** * @return CDNLoader */ public function create() { $compiler = $this->container->getService('cdnloader.compiler'); $httpRequest = $this->container->getService('httpRequest'); $loader = new CDNLoader($compiler, $httpRequest); return $loader; }
/** * @param string $name * @return RpcServer */ public function getRpcServer($name) { if (!isset($this->rpcServers[$name])) { throw new InvalidArgumentException("Unknown RPC server {$name}"); } return $this->serviceLocator->getService($this->rpcServers[$name]); }
/** * @return Nette\Application\IResponse */ public function run(Application\Request $request) { $this->request = $request; $httpRequest = $this->context->getByType('Nette\\Http\\IRequest'); if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $httpRequest->getUrl(); $url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) { return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['callback'])) { throw new Application\BadRequestException("Parameter callback is missing."); } $params['presenter'] = $this; $callback = new Nette\Callback($params['callback']); $response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params)); if (is_string($response)) { $response = array($response, array()); } if (is_array($response)) { if ($response[0] instanceof \SplFileInfo) { $response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]); } else { $response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]); } } if ($response instanceof Nette\Templating\ITemplate) { return new Responses\TextResponse($response); } else { return $response; } }
public function __construct(\Nette\DI\Container $container) { $this->container = $container; $this->connection = $container->getService('leanMapper.connection'); $this->entityFactory = $container->getService('entityFactory'); $this->mapper = $container->getService('standardMapper'); $this->transaction = $container->getService('transaction'); }
/** * @return MapperMatrix */ public function create() { $matrix = new MapperMatrix(); foreach ($this->container->findByTag('echo511.leanmapper.mapper') as $serviceName => $tagAttributes) { $matrix->addMapper($this->container->getService($serviceName)); } return $matrix; }
/** * @param string $eventName */ private function initializeListener($eventName) { foreach ($this->listenerIds[$eventName] as $serviceName) { $subscriber = $this->container->getService($serviceName); /** @var Doctrine\Common\EventSubscriber $subscriber */ $this->addEventSubscriber($subscriber); } unset($this->listenerIds[$eventName]); }
public function create() : Registry { $tagToService = function (array $tags) { return array_map(function (string $serviceName) { return $this->container->getService($serviceName); }, array_keys($tags)); }; return new Registry($tagToService($this->container->findByTag(self::RULE_TAG))); }
/** * {@inheritDoc} */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (!isset($this->validators[$name])) { $this->validators[$name] = new $name(); } elseif (is_string($this->validators[$name])) { $this->validators[$name] = $this->serviceLocator->getService($this->validators[$name]); } return $this->validators[$name]; }
public function create() : Broker { $tagToService = function (array $tags) { return array_map(function (string $serviceName) { return $this->container->getService($serviceName); }, array_keys($tags)); }; $phpClassReflectionExtension = $this->container->getByType(PhpClassReflectionExtension::class); return new Broker(array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::PROPERTIES_CLASS_REFLECTION_EXTENSION_TAG))), array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::METHODS_CLASS_REFLECTION_EXTENSION_TAG))), $tagToService($this->container->findByTag(self::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG)), $this->container->getByType(FunctionReflectionFactory::class)); }
public function dispatchEvent($eventName, $eventArgs = []) { if (isset($this->subscribersMap[$eventName])) { $subscribers = $this->subscribersMap[$eventName]; foreach ($subscribers as list($serviceName, $function)) { $service = $this->container->getService($serviceName); call_user_func_array([$service, $function], $eventArgs); } } }
/** * @param string $eventName */ private function initializeListener($eventName) { foreach ($this->listenerIds[$eventName] as $serviceName) { $listener = $this->container->getService($serviceName); if ($listener instanceof \Closure) { $this->addEventListener($eventName, $listener); } elseif ($listener instanceof EventSubscriber) { $this->addEventSubscriber($listener); } } unset($this->listenerIds[$eventName]); }
public function flush() { $mappers = []; foreach ($this->repositories['names'] as $name) { if ($this->container->isCreated($name)) { $mappers[] = $this->container->getService($name)->getMapper(); } } foreach ($mappers as $mapper) { $mapper->flush(); } }
/** * @return TargetSection[] * @throws \Nette\InvalidStateException */ public function getSections() { $sections = array(); foreach ($this->container->findByTag("Brabijan.seo.targetSectionProvider") as $serviceName => $attributes) { $section = $this->container->getService($serviceName); if (!$section instanceof ITargetSectionProvider) { throw new InvalidStateException('Target provider must be instance of Brabijan\\SeoComponents\\DI\\ITargetSectionProvider'); } $sections[] = $section->getTargetSection(); } return $sections; }
public function create() { $serviceNames = $this->context->findByTag($this->tagName); $jobs = array(); foreach ($serviceNames as $name => $attrs) { $job = $this->context->getService($name); if (!$job instanceof IJob) { throw new \InvalidArgumentException("Service {$name} must implements Cron\\IJob interface!"); } $jobs[] = $job; } return new Cron($jobs); }
protected function execute(InputInterface $input, OutputInterface $output) { if (defined('AMQP_DEBUG') === false) { define('AMQP_DEBUG', (bool) $input->getOption('debug')); } $output->writeln('Setting up the Rabbit MQ fabric'); foreach (array(RabbitMqExtension::TAG_PRODUCER, RabbitMqExtension::TAG_CONSUMER, RabbitMqExtension::TAG_RPC_CLIENT, RabbitMqExtension::TAG_RPC_SERVER) as $tag) { foreach ($this->container->findByTag($tag) as $serviceId => $meta) { /** @var AmqpMember $service */ $service = $this->container->getService($serviceId); $service->setupFabric(); } } }
public static function create(DI\Container $container) { try { $entityManager = $container->getService('entityManager'); } catch (\InvalidArgumentException $e) { $entityManager = null; } $robotLoader = $container->getService('robotLoader'); $cacheStorage = $container->getService('cacheStorage'); $cache = new \Nette\Caching\Cache($cacheStorage, self::$namespace); $eventManager = $container->getService('eventManager'); $moduleManager = new \Tatami\Modules\ModuleManager($robotLoader, $eventManager, $cache, $entityManager); $eventManager->addSubscriber(\Tatami\Events\Event::APPLICATION_STARTUP, $moduleManager); return $moduleManager; }
/** * AssetWriter lazy loading * @return AssetWriter */ public function getAssetWriter() { if ($this->assetWriter === NULL) { $this->assetWriter = $this->container->getService($this->writerServiceName); } return $this->assetWriter; }
public function __construct($containerFactory = NULL, Container $container = NULL) { parent::__construct($containerFactory); /** @var IStorage $storage */ $storage = $container->getService('cacheStorage'); $this->cache = new Cache($storage); }
public static function create(DI\Container $container) { $robotLoader = $container->getService('robotLoader'); //$cacheStorage = $container->getService('cacheStorage'); $shortcutsManager = new \ShortcutsManager($robotLoader); return $shortcutsManager; }
/** * @param \Nette\DI\Container $dic * @throws MemberAccessException * @internal */ public function injectComponentFactories(Nette\DI\Container $dic) { if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) { throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.'); } $this->autowireComponentFactoriesLocator = $dic; $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage'); $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories'); if ($cache->load($presenterClass = get_class($this)) !== NULL) { return; } $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter']; $rc = new ClassType($this); foreach ($rc->getMethods() as $method) { if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) { continue; } foreach ($method->getParameters() as $parameter) { if (!($class = $parameter->getClassName())) { // has object type hint continue; } if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) { throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered."); } } } $files = array_map(function ($class) { return ClassType::from($class)->getFileName(); }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore)); $files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName(); $cache->save($presenterClass, TRUE, [$cache::FILES => $files]); }
private function renderListeners($ids) { static $addIcon; if (empty($addIcon)) { $addIcon = '<img width="18" height="18" src="data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/add.png')) . '" title="Listener" />'; } $registeredClasses = $this->getClassMap(); $h = 'htmlspecialchars'; $shortFilename = function (Nette\Reflection\GlobalFunction $refl) { $title = '.../' . basename($refl->getFileName()) . ':' . $refl->getStartLine(); if ($editor = Tracy\Helpers::editorUri($refl->getFileName(), $refl->getStartLine())) { return sprintf(' defined at <a href="%s">%s</a>', htmlspecialchars($editor), $title); } return ' defined at ' . $title; }; $s = ''; foreach ($ids as $id) { if (is_callable($id)) { $s .= '<tr><td width=18>' . $addIcon . '</td><td><pre class="nette-dump"><span class="nette-dump-object">' . Callback::toString($id) . ($id instanceof \Closure ? $shortFilename(Callback::toReflection($id)) : '') . '</span></span></th></tr>'; continue; } if (!$this->sl->isCreated($id) && ($class = array_search($id, $registeredClasses, TRUE))) { $s .= '<tr><td width=18>' . $addIcon . '</td><td><pre class="nette-dump"><span class="nette-dump-object">' . $h(Nette\Reflection\ClassType::from($class)->getName()) . '</span></span></th></tr>'; } else { try { $s .= '<tr><td width=18>' . $addIcon . '</td><td>' . self::dumpToHtml($this->sl->getService($id)) . '</th></tr>'; } catch (\Exception $e) { $s .= "<tr><td colspan=2>Service {$id} cannot be loaded because of exception<br><br>\n" . (string) $e . '</td></th>'; } } } return $s; }
/** * Registers 'addPaymentButtons' & 'addPaymentButton' methods to form using DI container * * @param Container $container */ public static function registerAddPaymentButtonsUsingDependencyContainer(Container $container) { $binder = $container->getByType(Binder::class); $services = $container->findByType(AbstractPaymentService::class); foreach ($services as $service) { self::registerAddPaymentButtons($binder, $container->getService($service)); } }
/** * {@inheritdoc} */ public function getManagers() { $dms = array(); foreach ($this->managers as $name => $id) { $dms[$name] = $this->container->getService($id); } return $dms; }