本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::isScopeActive方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::isScopeActive方法的具體用法?PHP ContainerInterface::isScopeActive怎麽用?PHP ContainerInterface::isScopeActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::isScopeActive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLocale
/**
* @return string
*/
public function getLocale()
{
if ($this->container !== null && $this->container->isScopeActive('request')) {
return $this->container->get('request')->getLocale();
}
return $this->locale;
}
示例2: convert
/**
* {@inheritDoc}
*/
public function convert(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $method, $value, array $attributes = [])
{
if (!$this->container->isScopeActive('request') || !$this->container->has('request')) {
throw new ConverterException('Could not convert Request parameter in not active "request" scope.');
}
return $this->container->get('request');
}
示例3: __construct
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct($container)
{
$this->container = $container;
if ($this->container->isScopeActive('request')) {
$this->request = $this->container->get('request');
}
}
示例4: getLocale
public function getLocale()
{
if ($this->container->isScopeActive('request') && $this->container->has('request')) {
return $this->container->get('request')->getSession()->getLang()->getLocale();
}
return $this->locale;
}
示例5: getGlobals
/**
* {@inheritDoc}
*/
public function getGlobals()
{
if (!$this->container->isScopeActive('request')) {
return array();
}
return array('require_js' => array('config' => $this->configurationBuilder->getConfiguration()));
}
示例6: onThreadCreate
/**
* Creates and persists a thread with the specified id.
*
* @param \FOS\CommentBundle\Event\ThreadEvent $event
*/
public function onThreadCreate(ThreadEvent $event)
{
if (!$this->container->isScopeActive('request')) {
return;
}
$thread = $event->getThread();
$thread->setPermalink($this->container->get('request')->getUri());
}
示例7: getLocale
/**
* {@inheritdoc}
*/
public function getLocale()
{
if ($this->container->isScopeActive('request')) {
if ($request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
return $request->getLocale();
}
}
return $this->defaultLocale;
}
示例8: getRequest
/**
* @return null|Request
*/
private function getRequest()
{
if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}
if ($this->container->isScopeActive('request')) {
return $this->container->get('request');
}
return;
}
示例9: getLocale
/**
* Get the locale, either from the parent or from the container if available
* or the default locale if one is set.
*
* @param array $parameters the request parameters
*
* @return string
*/
protected function getLocale($parameters)
{
$locale = parent::getLocale($parameters);
if ($locale) {
return $locale;
}
if (is_null($this->container) || !$this->container->isScopeActive('request') || !($request = $this->container->get('request'))) {
return $this->defaultLocale;
}
return $request->getLocale();
}
示例10: postUpdate
public function postUpdate(LifecycleEventArgs $arg)
{
if (!$this->container->isScopeActive('request')) {
return;
}
if (!$this->container->get('security.context')->getToken()->isAuthenticated()) {
return;
}
if ($arg->getDocument() instanceof Document\Article) {
if ($arg->getDocument()->wereTranslationsModified()) {
$this->notifyModification($arg->getDocument(), $arg->getDocumentManager());
}
}
}
示例11: notify
/**
* @param Notification $notification
* @return void
*/
public function notify(Notification $notification)
{
if (!$this->container->isScopeActive('request')) {
$this->container->enterScope('request');
$this->container->set('request', new Request(), 'request');
}
$ticket = $this->loadTicket($notification);
$changeList = $this->postProcessChangesList($notification);
foreach ($this->watchersService->getWatchers($ticket) as $watcher) {
$userType = $watcher->getUserType();
$user = User::fromString($userType);
$isOroUser = $user->isOroUser();
if ($isOroUser) {
$loadedUser = $this->oroUserManager->findUserBy(['id' => $user->getId()]);
} else {
$loadedUser = $this->diamanteUserRepository->get($user->getId());
}
if (!$isOroUser && $notification->isTagUpdated()) {
continue;
}
$message = $this->message($notification, $ticket, $isOroUser, $loadedUser->getEmail(), $changeList);
$this->mailer->send($message);
$reference = new MessageReference($message->getId(), $ticket, $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH));
$this->messageReferenceRepository->store($reference);
}
}
示例12: isolateEnvironment
/**
* {@inheritdoc}
*/
public function isolateEnvironment(Environment $uninitializedEnvironment, $testSubject = null)
{
if (!$uninitializedEnvironment instanceof UninitializedContextServiceEnvironment) {
throw new EnvironmentIsolationException(sprintf('ContextServiceEnvironmentHandler does not support isolation of `%s` environment.', get_class($uninitializedEnvironment)), $uninitializedEnvironment);
}
if (!$this->container->isScopeActive('scenario')) {
$this->container->enterScope('scenario');
}
$environment = new InitializedContextEnvironment($uninitializedEnvironment->getSuite());
foreach ($uninitializedEnvironment->getContextsServicesIds() as $serviceId) {
/** @var Context $context */
$context = $this->container->get($serviceId);
$environment->registerContext($context);
}
return $environment;
}
示例13: match
/**
* Tries to match a URL with a set of routes.
*
* Returns false if no route matches the URL.
*
* @param string $url URL to be parsed
*
* @return array|false An array of parameters or false if no route matches
*/
public function match($url)
{
$params = $this->getMatcher()->match($url);
if (false === $params) {
throw new ResourceNotFoundException();
}
// No request. What append ?
$currentLocale = null;
if ($this->container->isScopeActive('request')) {
$currentLocale = $this->localeResolver->resolveLocale($this->container->get('request'));
}
// Clean the route name
if (false !== ($pos = strpos($params['_route'], I18nLoader::ROUTING_PREFIX))) {
$params['_route'] = substr($params['_route'], $pos + strlen(I18nLoader::ROUTING_PREFIX));
}
// Retrieve all authorized locales for the given route
$routeLocales = array();
if (isset($params['_locale'])) {
$routeLocales = array($params['_locale']);
} elseif (isset($params['_locales'])) {
$routeLocales = $params['_locales'];
unset($params['_locales']);
}
if (0 === count($routeLocales) || in_array($currentLocale, $routeLocales)) {
$params['_locale'] = $currentLocale;
return $params;
}
throw new ResourceNotFoundException();
}
示例14: __construct
/**
* @param string $path
*/
public function __construct(RackspaceContainer $container, ContainerInterface $serviceContainer)
{
$this->container = $container;
if ($serviceContainer->hasScope('request') && $serviceContainer->isScopeActive('request') && $serviceContainer->has('request')) {
$this->request = $serviceContainer->get('request');
}
}
示例15: __construct
/**
* @param ContainerInterface $container
* @param EntityManager $em
*/
public function __construct(ContainerInterface $container, EntityManager $em)
{
if ($container->isScopeActive('request')) {
$this->em = $em;
$this->siteRequest = $container->get('sudoux.cms.site');
$this->site = $this->siteRequest->getSite();
$this->container = $container;
}
}