Returns value for $paramName, in $namespace.
public getParameter ( string $paramName, string $namespace = null, string $scope = null ) : mixed | ||
$paramName | string | The parameter name, without $prefix and the current scope (i.e. siteaccess name). |
$namespace | string | Namespace for the parameter name. If null, the default namespace should be used. |
$scope | string | The scope you need $paramName value for. |
return | mixed |
/** * Returns the parameter value from config resolver. * * @param string $parameterName * @param string $namespace * @param mixed $defaultValue * * @return mixed */ protected function getParameter($parameterName, $namespace, $defaultValue = null) { if ($this->configResolver->hasParameter($parameterName, $namespace)) { return $this->configResolver->getParameter($parameterName, $namespace); } return $defaultValue; }
/** * If user is logged-in in legacy_mode (e.g. legacy admin interface), * will inject currently logged-in user in the repository. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */ $request = $event->getRequest(); $session = $request->getSession(); if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST || !$this->configResolver->getParameter('legacy_mode') || !($session->isStarted() && $session->has('eZUserLoggedInID'))) { return; } try { $apiUser = $this->repository->getUserService()->loadUser($session->get('eZUserLoggedInID')); $this->repository->setCurrentUser($apiUser); $token = $this->tokenStorage->getToken(); if ($token instanceof TokenInterface) { $token->setUser(new User($apiUser)); // Don't embed if we already have a LegacyToken, to avoid nested session storage. if (!$token instanceof LegacyToken) { $this->tokenStorage->setToken(new LegacyToken($token)); } } } catch (NotFoundException $e) { // Invalid user ID, the user may have been removed => invalidate the token and the session. $this->tokenStorage->setToken(null); $session->invalidate(); } }
public function onSiteAccessMatch(PostSiteAccessMatchEvent $event) { $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id'); $this->urlAliasRouter->setRootLocationId($rootLocationId); $this->urlAliasGenerator->setRootLocationId($rootLocationId); $this->urlAliasGenerator->setExcludedUriPrefixes($this->configResolver->getParameter('content.tree_root.excluded_uri_prefixes')); }
/** * @param Location $location * @return mixed */ public function getContentDecorator(Location $location) { $mappingEntities = $this->configResolver->getParameter('class_mapping', 'ezcontentdecorator'); $contentTypeIdentifier = $this->repository->getContentTypeService()->loadContentType($location->contentInfo->contentTypeId)->identifier; $className = array_key_exists($contentTypeIdentifier, $mappingEntities) ? $mappingEntities[$contentTypeIdentifier] : $this->defaultClassName; return new $className($this->container, $location, $contentTypeIdentifier); }
public function getParameter($parameterName, $defaultValue = null) { if ($this->configResolver->hasParameter($parameterName)) { return $this->configResolver->getParameter($parameterName); } return $defaultValue; }
/** * Tries to match a request with a set of routes. * * If the matcher can not find information, it must throw one of the exceptions documented * below. * * @param \Symfony\Component\HttpFoundation\Request $request The request to match * * @return array An array of parameters * * @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException If no matching resource could be found */ public function matchRequest(Request $request) { if ($this->configResolver->getParameter('routing.enable_tag_router', 'eztags') === false) { throw new ResourceNotFoundException('Config says to bypass TagRouter'); } $requestedPath = rawurldecode($request->attributes->get('semanticPathinfo', $request->getPathInfo())); $pathPrefix = $this->generator->getPathPrefix(); if (mb_stripos($requestedPath, $pathPrefix) !== 0) { throw new ResourceNotFoundException(); } $requestedPath = $this->removePathPrefix($requestedPath, $pathPrefix); $requestedPath = trim($requestedPath, '/'); if (empty($requestedPath)) { throw new ResourceNotFoundException(); } $languages = $this->configResolver->getParameter('languages'); $tag = $this->tagsService->sudo(function (TagsService $tagsService) use($requestedPath, $languages) { return $tagsService->loadTagByUrl($requestedPath, $languages); }); // We specifically pass tag ID so tag view builder will reload the tag and check for permissions // Unfortunately, since at this point user is still anonymous (why!?), this is the best we can do $params = array('_route' => self::TAG_URL_ROUTE_NAME, '_controller' => static::TAG_VIEW_ACTION_CONTROLLER, 'tagId' => $tag->id); $request->attributes->set('tagId', $tag->id); if ($this->logger !== null) { $this->logger->info("TagRouter matched tag #{$tag->id}. Forwarding to tag view controller"); } return $params; }
public function __construct(EngineInterface $templateEngine, ConfigResolverInterface $configResolver, RequestStack $requestStack) { $this->templateEngine = $templateEngine; $this->legacyLayout = $configResolver->getParameter('module_default_layout', 'ezpublish_legacy'); $this->legacyMode = $configResolver->getParameter('legacy_mode'); $this->requestStack = $requestStack; }
public function handle(GetResponseEvent $event) { // In legacy_mode, "remember me" must be delegated to legacy kernel. if ($this->configResolver->getParameter('legacy_mode')) { return; } parent::handle($event); }
/** * Builds the main repository, heart of eZ Publish API * * This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method * directly to make sure you get an instance wrapped inside Signal / Cache / * functionality. * * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler * * @return \eZ\Publish\API\Repository\Repository */ public function buildRepository(PersistenceHandler $persistenceHandler) { $repository = new $this->repositoryClass($persistenceHandler, array('fieldType' => $this->fieldTypeCollectionFactory->getFieldTypes(), 'role' => array('limitationTypes' => $this->roleLimitations), 'languages' => $this->configResolver->getParameter('languages'))); /** @var \eZ\Publish\API\Repository\Repository $repository */ $anonymousUser = $repository->getUserService()->loadUser($this->configResolver->getParameter("anonymous_user_id")); $repository->setCurrentUser($anonymousUser); return $repository; }
protected function getForwardRequest(Location $location, Content $content, SiteAccess $previewSiteAccess) { $request = parent::getForwardRequest($location, $content, $previewSiteAccess); // If the preview siteaccess is configured in legacy_mode, we forward to the LegacyKernelController. if ($this->configResolver->getParameter('legacy_mode', 'ezsettings', $previewSiteAccess->name)) { $request->attributes->set('_controller', 'ezpublish_legacy.controller:indexAction'); } return $request; }
public function onSiteAccessMatch(PostSiteAccessMatchEvent $event) { if (!($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && isset($this->session) && !$this->session->isStarted() && $this->sessionStorage instanceof NativeSessionStorage)) { return; } $sessionOptions = (array) $this->configResolver->getParameter('session'); $sessionName = isset($sessionOptions['name']) ? $sessionOptions['name'] : $this->session->getName(); $sessionOptions['name'] = $this->getSessionName($sessionName, $event->getSiteAccess()); $this->sessionStorage->setOptions($sessionOptions); }
/** * Renders share buttons bar template based on user settings. * * @param \Twig_Environment $twigEnvironment * @param array $options * @param string[] $providers * * @return string */ public function showShareButtons(Twig_Environment $twigEnvironment, array $options = array(), array $providers = array()) { $this->shareButtonsRenderer->setTemplateEngine($twigEnvironment); if (isset($providers)) { $options['providers'] = $providers; } if (!isset($options['template'])) { $options['template'] = $this->configResolver->getParameter('template', 'ez_share_buttons'); } return $twigEnvironment->render(sprintf('EzSystemsShareButtonsBundle::%s.html.twig', $options['template']), array('shareButtons' => $this->shareButtonsRenderer->render($options))); }
public function loginAction() { $session = $this->request->getSession(); if ($this->request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { $error = $this->request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR); } else { $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR); } $csrfToken = isset($this->csrfProvider) ? $this->csrfProvider->generateCsrfToken('authenticate') : null; return new Response($this->templateEngine->render($this->configResolver->getParameter('security.login_template'), array('last_username' => $session->get(SecurityContextInterface::LAST_USERNAME), 'error' => $error, 'csrf_token' => $csrfToken, 'layout' => $this->configResolver->getParameter('security.base_layout')))); }
/** * Displays the gallery. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function displayGalleryAction(ContentView $view, Request $request) { $languages = $this->configResolver->getParameter('languages'); $location = $view->getLocation(); $query = new Query(); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->searchService)); $pager->setMaxPerPage($this->galleryImagesLimit); $pager->setCurrentPage($request->get('page', 1)); $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'images' => $pager]); return $view; }
/** * Returns the YUI loader configuration. * * @param string $configObject * * @return string */ public function yuiConfigLoaderFunction($configObject = '') { $modules = array_fill_keys($this->configResolver->getParameter('yui.modules', 'ez_platformui'), true); $yui = ['filter' => $this->configResolver->getParameter('yui.filter', 'ez_platformui'), 'modules' => []]; $combine = $this->configResolver->getParameter('yui.combine', 'ez_platformui'); if ($combine === true) { $yui['combine'] = true; $yui['root'] = ''; $yui['comboBase'] = $this->router->generate('yui_combo_loader') . '?'; } foreach (array_keys($modules) as $module) { if (!isset($yui['modules'][$module]['requires'])) { $yui['modules'][$module]['requires'] = []; } // Module dependencies if ($this->configResolver->hasParameter("yui.modules.{$module}.requires", 'ez_platformui')) { $yui['modules'][$module]['requires'] = array_merge($yui['modules'][$module]['requires'], $this->configResolver->getParameter("yui.modules.{$module}.requires", 'ez_platformui')); } // Reverse dependencies if ($this->configResolver->hasParameter("yui.modules.{$module}.dependencyOf", 'ez_platformui')) { foreach ($this->configResolver->getParameter("yui.modules.{$module}.dependencyOf", 'ez_platformui') as $dep) { // Add reverse dependency only if referred module is declared in the modules list. if (!isset($modules[$dep])) { if ($this->logger) { $this->logger->error("'{$module}' is declared to be a dependency of undeclared module '{$dep}'. Ignoring."); } continue; } $yui['modules'][$dep]['requires'][] = $module; } } if ($combine === true) { $yui['modules'][$module]['combine'] = true; } if ($this->configResolver->getParameter("yui.modules.{$module}.type", 'ez_platformui') === 'template') { $yui['modules'][$module]['requires'][] = 'template'; $yui['modules'][$module]['requires'][] = 'handlebars'; $yui['modules'][$module]['fullpath'] = $this->router->generate('template_yui_module', ['module' => $module]); } else { $yui['modules'][$module]['fullpath'] = $this->asset($this->configResolver->getParameter("yui.modules.{$module}.path", 'ez_platformui')); } } // Now ensure that all requirements are unique foreach ($yui['modules'] as &$moduleConfig) { $moduleConfig['requires'] = array_unique($moduleConfig['requires']); } $res = ''; if ($configObject != '') { $res = $configObject . ' = '; } return $res . (defined('JSON_UNESCAPED_SLASHES') ? json_encode($yui, JSON_UNESCAPED_SLASHES) : json_encode($yui)) . ';'; }
/** * Adds settings to the parameters that will be injected into the legacy kernel * * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent $event */ public function onBuildKernel( PreBuildKernelEvent $event ) { if( !$this->enabled ) { return; } $settings = array(); $settings["owpagenda.ini/AgendaSettings/FolderNodeId"] = $this->configResolver->getParameter( "open_wide_publish_agenda.agenda_folder.location_id" ); $event->getParameters()->set( "injected-settings", $settings + (array) $event->getParameters()->get( "injected-settings" ) ); }
/** * Renders top menu with child items. * * @param string $template * * @return \Symfony\Component\HttpFoundation\Response */ public function getChildNodesAction($template) { $query = new LocationQuery(); $query->query = $this->menuCriteria->generateChildCriterion($this->locationService->loadLocation($this->topMenuLocationId), $this->configResolver->getParameter('languages')); $query->sortClauses = [new SortClause\Location\Priority(LocationQuery::SORT_ASC)]; $query->performCount = false; $content = $this->searchService->findLocations($query); $menuItems = []; foreach ($content->searchHits as $hit) { $menuItems[] = $hit->valueObject; } return $this->templating->renderResponse($template, ['menuItems' => $menuItems], new Response()); }
/** * Checks if the IndexPage is configured and which page must be shown. * * @param GetResponseEvent $event */ public function onKernelRequestIndex(GetResponseEvent $event) { $request = $event->getRequest(); $semanticPathinfo = $request->attributes->get('semanticPathinfo') ?: '/'; if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && $semanticPathinfo === '/') { $indexPage = $this->configResolver->getParameter('index_page'); if ($indexPage !== null) { $indexPage = '/' . ltrim($indexPage, '/'); $request->attributes->set('semanticPathinfo', $indexPage); $request->attributes->set('needsForward', true); } } }
/** * @return array * * @throws \eZ\Bundle\EzPublishCoreBundle\ApiLoader\Exception\InvalidRepositoryException */ public function getRepositoryConfig() { // Takes configured repository as the reference, if it exists. // If not, the first configured repository is considered instead. $repositoryAlias = $this->configResolver->getParameter('repository'); if ($repositoryAlias === null) { $aliases = array_keys($this->repositories); $repositoryAlias = array_shift($aliases); } if (empty($repositoryAlias) || !isset($this->repositories[$repositoryAlias])) { throw new InvalidRepositoryException("Undefined repository '{$repositoryAlias}'. Did you forget to configure it in ezpublish_*.yml?"); } return array('alias' => $repositoryAlias) + $this->repositories[$repositoryAlias]; }
/** * Renders share buttons bar template based on user settings. * * @param \Twig_Environment $twigEnvironment * @param array $options * @param string[] $providers * @return string * * @throws \InvalidArgumentException if template was not found */ public function showShareButtons(Twig_Environment $twigEnvironment, array $options = array(), array $providers = array()) { $this->shareButtonsRenderer->setTemplateEngine($twigEnvironment); if (isset($providers)) { $options['providers'] = $providers; } if (!isset($options['template'])) { $options['template'] = $this->configResolver->getParameter('template', 'ez_share_buttons'); } if (!file_exists(sprintf('%s/../../Resources/views/%s.html.twig', __DIR__, $options['template']))) { throw new InvalidArgumentException(sprintf('Template with name `%s.html.twig` was not found in views directory of EzSystemsShareButtonBundle.', $options['template'])); } return $twigEnvironment->render(sprintf('@EzSystemsShareButtonsBundle/Resources/views/%s.html.twig', $options['template']), array('shareButtons' => $this->shareButtonsRenderer->render($options))); }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->attributes->has('_locale')) { foreach ($this->configResolver->getParameter('languages') as $locale) { $convertedLocale = $this->localeConverter->convertToPOSIX($locale); if ($convertedLocale !== null) { // Setting the converted locale to the _locale request attribute, so that it can be properly processed by parent listener. $request->attributes->set('_locale', $convertedLocale); break; } } } parent::onKernelRequest($event); }
/** * If user is logged-in in legacy_mode (e.g. legacy admin interface), * will inject currently logged-in user in the repository. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */ $request = $event->getRequest(); if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST || !$this->configResolver->getParameter('legacy_mode') || !$request->getSession()->has('eZUserLoggedInID')) { return; } $apiUser = $this->repository->getUserService()->loadUser($request->getSession()->get('eZUserLoggedInID')); $this->repository->setCurrentUser($apiUser); $token = $this->securityContext->getToken(); if ($token instanceof TokenInterface) { $token->setUser(new User($apiUser)); $token->setAuthenticated(true); } }
/** * Builds the proxy client, taking dynamically defined servers into account. * * @param array $servers * @param string $baseUrl * * @return \FOS\HttpCache\ProxyClient\Varnish */ public function buildProxyClient(array $servers, $baseUrl) { $allServers = array(); foreach ($servers as $server) { if (!$this->dynamicSettingParser->isDynamicSetting($server)) { $allServers[] = $server; continue; } $settings = $this->dynamicSettingParser->parseDynamicSetting($server); $configuredServers = $this->configResolver->getParameter($settings['param'], $settings['namespace'], $settings['scope']); $allServers = array_merge($allServers, (array) $configuredServers); } $class = $this->proxyClientClass; return new $class($allServers, $baseUrl); }
/** * Adds dynamic settings notation support: $<paramName>[;<namespace>[;<scope>]]$. * * {@inheritdoc} */ protected function parseInput($input, array $options = array()) { if ($this->dynamicSettingParser->isDynamicSetting($input)) { $parsedSettings = $this->dynamicSettingParser->parseDynamicSetting($input); $input = $this->configResolver->getParameter($parsedSettings['param'], $parsedSettings['namespace'], $parsedSettings['scope']); if (is_array($input)) { $collection = $this->createAssetCollection(array(), $options); foreach ($input as $file) { $collection->add(parent::parseInput($file, $options)); } return $collection; } } return parent::parseInput($input, $options); }
/** * Returns configured template reference for the given embed parameters. * * @param $resourceType * @param $isInline * @param $isDenied * * @return null|string */ protected function getEmbedTemplateName($resourceType, $isInline, $isDenied) { $configurationReference = $this->embedConfigurationNamespace; if ($resourceType === static::RESOURCE_TYPE_CONTENT) { $configurationReference .= '.content'; } else { $configurationReference .= '.location'; } if ($isInline) { $configurationReference .= '_inline'; } if ($isDenied) { $configurationReference .= '_denied'; } if ($this->configResolver->hasParameter($configurationReference)) { $configuration = $this->configResolver->getParameter($configurationReference); return $configuration['template']; } if (isset($this->logger)) { $this->logger->warning("Embed tag configuration '{$configurationReference}' was not found"); } $configurationReference = $this->embedConfigurationNamespace; $configurationReference .= '.default'; if ($isInline) { $configurationReference .= '_inline'; } if ($this->configResolver->hasParameter($configurationReference)) { $configuration = $this->configResolver->getParameter($configurationReference); return $configuration['template']; } if (isset($this->logger)) { $this->logger->warning("Embed tag default configuration '{$configurationReference}' was not found"); } return null; }
/** * Returns if the provided siteaccess is running in legacy mode. * * @param string $siteAccessName * * @return bool */ protected function isLegacyModeSiteAccess($siteAccessName) { if (!$this->configResolver->hasParameter('legacy_mode', 'ezsettings', $siteAccessName)) { return false; } return $this->configResolver->getParameter('legacy_mode', 'ezsettings', $siteAccessName); }
/** * Returns a valid Location object for $contentId. * Will either load mainLocationId (if available) or build a virtual Location object. * * @param mixed $contentId * * @return \eZ\Publish\API\Repository\Values\Content\Location|null Null when content does not have location */ public function getPreviewLocation( $contentId ) { // contentInfo must be reloaded as content is not published yet (e.g. no mainLocationId) $contentInfo = $this->contentService->loadContentInfo( $contentId ); // mainLocationId already exists, content has been published at least once. if ( $contentInfo->mainLocationId ) { $location = $this->locationService->loadLocation( $contentInfo->mainLocationId ); } // New Content, never published, create a virtual location object. else { // @todo In future releases this will be a full draft location when this feature // is implemented. Or it might return null when content does not have location, // but for now we can't detect that so we return a virtual draft location $location = new Location( array( // Faking using root locationId 'id' => $this->configResolver->getParameter( 'content.tree_root.location_id' ), 'contentInfo' => $contentInfo, 'status' => Location::STATUS_DRAFT ) ); } return $location; }
/** * Tries to retrieve a valid eZ user if authenticated user doesn't come from the repository (foreign user provider). * Will dispatch an event allowing listeners to return a valid eZ user for current authenticated user. * Will by default let the repository load the anonymous user. * * @param \Symfony\Component\Security\Http\Event\InteractiveLoginEvent $event */ public function onInteractiveLogin(BaseInteractiveLoginEvent $event) { $token = $event->getAuthenticationToken(); $originalUser = $token->getUser(); if ($originalUser instanceof eZUser || !$originalUser instanceof UserInterface) { return; } /* * 1. Send the event. * 2. If no eZ user is returned, load Anonymous user. * 3. Inject eZ user in repository. * 4. Create the UserWrapped user object (implementing eZ UserInterface) with loaded eZ user. * 5. Create new token with UserWrapped user * 6. Inject the new token in security context */ $subLoginEvent = new InteractiveLoginEvent($event->getRequest(), $token); $this->eventDispatcher->dispatch(MVCEvents::INTERACTIVE_LOGIN, $subLoginEvent); if ($subLoginEvent->hasAPIUser()) { $apiUser = $subLoginEvent->getAPIUser(); } else { $apiUser = $this->repository->getUserService()->loadUser($this->configResolver->getParameter('anonymous_user_id')); } $this->repository->setCurrentUser($apiUser); $providerKey = method_exists($token, 'getProviderKey') ? $token->getProviderKey() : __CLASS__; $interactiveToken = new InteractiveLoginToken($this->getUser($originalUser, $apiUser), get_class($token), $token->getCredentials(), $providerKey, $token->getRoles()); $interactiveToken->setAttributes($token->getAttributes()); $this->tokenStorage->setToken($interactiveToken); }
/** * Injects the ConfigResolver to potentially override default_target_path for redirections after authentication success. * * @param ConfigResolverInterface $configResolver */ public function setConfigResolver(ConfigResolverInterface $configResolver) { $defaultPage = $configResolver->getParameter('default_page'); if ($defaultPage !== null) { $this->options['default_target_path'] = $defaultPage; } }
/** * Returns array of child content objects from given $locationId. * * @param int $locationId * @param int $limit * * @return array */ private function fetchItems($locationId, $limit) { $languages = $this->configResolver->getParameter('languages'); $query = new Query(); $location = $this->locationService->loadLocation($locationId); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $query->performCount = false; $query->limit = $limit; $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)]; $results = $this->searchService->findContent($query); $items = []; foreach ($results->searchHits as $item) { $items[] = $item->valueObject; } return $items; }