本文整理汇总了PHP中Nette\DI\Container::getService方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::getService方法的具体用法?PHP Container::getService怎么用?PHP Container::getService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Container
的用法示例。
在下文中一共展示了Container::getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getWallet
/**
* @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]);
}
示例2: getModel
/**
* 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.");
}
示例3: getWallet
/**
* @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]);
}
示例4: runMigrations
/**
* 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;
}
示例5: getLoginProviderByName
/**
* @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]);
}
示例6: getLoginProviderByName
/**
* @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]);
}
示例7: __construct
public function __construct(Context $context, Container $container, EntityManager $entityManager)
{
$this->context = $context;
$this->container = $container;
$this->em = $entityManager;
$this->cache = $this->container->getService('cacheStorage');
}
示例8: create
/**
* @return CDNLoader
*/
public function create()
{
$compiler = $this->container->getService('cdnloader.compiler');
$httpRequest = $this->container->getService('httpRequest');
$loader = new CDNLoader($compiler, $httpRequest);
return $loader;
}
示例9: getRpcServer
/**
* @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]);
}
示例10: run
/**
* @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;
}
}
示例11: __construct
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');
}
示例12: create
/**
* @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;
}
示例13: initializeListener
/**
* @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]);
}
示例14: create
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)));
}
示例15: getInstance
/**
* {@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];
}