Classes implementing this interface will help you get settings for a specific scope. In eZ Publish context, this is useful to get a setting for a specific siteaccess for example. The idea is to check the different scopes available for a given namespace to find the appropriate parameter. To work, the dynamic setting must comply internally to the following name format : "..parameter.name".
 public function setUp()
 {
     $this->ioServiceMock = $this->getMock('eZ\\Publish\\Core\\IO\\IOServiceInterface');
     $this->configResolverMock = $this->getMock('eZ\\Publish\\Core\\MVC\\ConfigResolverInterface');
     $this->configResolverMock->expects($this->any())->method('getParameter')->with('io.url_prefix')->will($this->returnValue($this->ioUriPrefix));
     $this->eventListener = new StreamFileListener($this->ioServiceMock, $this->configResolverMock);
 }
Ejemplo n.º 2
0
 /**
  * @param \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface $matcherFactory
  * @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver
  * @param \eZ\Publish\API\Repository\ContentService $contentService
  * @param ProviderInterface[] Comments providers, indexed by their label.
  * @param string|null $defaultProvider Label of provider to use by default. If not provided, the first entry in $providers will be used.
  */
 public function __construct(MatcherFactoryInterface $matcherFactory, ConfigResolverInterface $configResolver, ContentService $contentService, array $providers = array(), $defaultProvider = null)
 {
     $this->matcherFactory = $matcherFactory;
     $this->providers = $providers;
     $this->setDefaultProviderLabel($defaultProvider ?: $configResolver->getParameter('default_provider', 'ez_comments'));
     $this->contentService = $contentService;
 }
Ejemplo n.º 3
0
 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'));
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * @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);
 }
Ejemplo n.º 6
0
 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;
 }
 /**
  * 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;
     }
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 public function getParameter($parameterName, $defaultValue = null)
 {
     if ($this->configResolver->hasParameter($parameterName)) {
         return $this->configResolver->getParameter($parameterName);
     }
     return $defaultValue;
 }
Ejemplo n.º 10
0
 /**
  * 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();
     }
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
Ejemplo n.º 13
0
 public function setUp()
 {
     $this->configResolver = $this->getMockBuilder('\\eZ\\Publish\\Core\\MVC\\ConfigResolverInterface')->getMock();
     $this->configResolver->method('getParameter')->willReturn('Tests/fixtures/template_module.js');
     $this->templating = $this->getMockBuilder('\\Symfony\\Component\\Templating\\EngineInterface')->getMock();
     $this->templating->method('render')->willReturn('template');
     $this->comboLoader = new ComboLoader($this->configResolver, $this->templating, '/yui/', 'Tests/fixtures');
 }
 /**
  * Builds the page service.
  *
  * @param string $serviceClass the class of the page service
  * @param ConfigResolverInterface $resolver
  * @param \eZ\Publish\Core\FieldType\Page\PageStorage\Gateway $storageGateway
  * @param \eZ\Publish\API\Repository\ContentService $contentService
  *
  * @return \eZ\Publish\Core\FieldType\Page\PageService
  */
 public function buildService($serviceClass, ConfigResolverInterface $resolver, PageGateway $storageGateway, ContentService $contentService)
 {
     $pageSettings = $resolver->getParameter('ezpage');
     /** @var $pageService \eZ\Publish\Core\FieldType\Page\PageService */
     $pageService = new $serviceClass($contentService, $pageSettings['layouts'], $pageSettings['blocks']);
     $pageService->setStorageGateway($storageGateway);
     return $pageService;
 }
 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);
 }
 public function __construct(\Closure $kernelClosure, ConfigResolverInterface $configResolver, URIHelper $uriHelper, LegacyResponseManager $legacyResponseManager, LegacyHelper $legacyHelper, RouterInterface $router)
 {
     $this->kernelClosure = $kernelClosure;
     $this->legacyLayout = $configResolver->getParameter('module_default_layout', 'ezpublish_legacy');
     $this->configResolver = $configResolver;
     $this->uriHelper = $uriHelper;
     $this->legacyResponseManager = $legacyResponseManager;
     $this->legacyHelper = $legacyHelper;
     $this->router = $router;
 }
Ejemplo n.º 18
0
 public function testMatchRequestRegularPathinfo()
 {
     $matchedParameters = array('_controller' => 'AcmeBundle:myAction');
     $pathinfo = '/siteaccess/foo/bar';
     $request = Request::create($pathinfo);
     $this->configResolver->expects($this->never())->method('getParameter');
     /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultRouter $router */
     $router = $this->generateRouter(array('match'));
     $router->expects($this->once())->method('match')->with($pathinfo)->will($this->returnValue($matchedParameters));
     $this->assertSame($matchedParameters, $router->matchRequest($request));
 }
 /**
  * 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)));
 }
Ejemplo n.º 20
0
 /**
  * @dataProvider onKernelRequestProvider
  */
 public function testOnKernelRequest(array $configuredLanguages, array $convertedLocalesValueMap, $expectedLocale)
 {
     $this->configResolver->expects($this->once())->method('getParameter')->with('languages')->will($this->returnValue($configuredLanguages));
     $this->localeConverter->expects($this->atLeastOnce())->method('convertToPOSIX')->will($this->returnValueMap($convertedLocalesValueMap));
     $defaultLocale = 'en';
     $localeListener = new LocaleListener($defaultLocale);
     $localeListener->setConfigResolver($this->configResolver);
     $localeListener->setLocaleConverter($this->localeConverter);
     $request = new Request();
     $localeListener->onKernelRequest(new GetResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST));
     $this->assertSame($expectedLocale, $request->attributes->get('_locale'));
 }
Ejemplo n.º 21
0
 /**
  * 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;
 }
 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'))));
 }
    /**
     * 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" )
        );
    }
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * 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());
 }
 /**
  * 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)));
 }
 /**
  * @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];
 }
Ejemplo n.º 28
0
 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);
 }
 /**
  * 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);
 }
Ejemplo n.º 30
0
 /**
  * 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);
     }
 }