public function testConstruct()
 {
     $parameterBag = new ParameterBag();
     $request = new Request();
     $event = new PreBuildKernelWebHandlerEvent($parameterBag, $request);
     $this->assertSame($parameterBag, $event->getParameters());
     $this->assertSame($request, $event->getRequest());
 }
Ejemplo n.º 2
0
 /**
  * Maps matched siteaccess to the legacy parameters
  *
  * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelWebHandlerEvent $event
  *
  * @return void
  */
 public function onBuildKernelWebHandler(PreBuildKernelWebHandlerEvent $event)
 {
     $siteAccess = $this->container->get('ezpublish.siteaccess');
     $request = $event->getRequest();
     $uriPart = array();
     // Convert matching type
     switch ($siteAccess->matchingType) {
         case 'default':
             $legacyAccessType = eZSiteAccess::TYPE_DEFAULT;
             break;
         case 'env':
             $legacyAccessType = eZSiteAccess::TYPE_SERVER_VAR;
             break;
         case 'uri:map':
         case 'uri:element':
         case 'uri:text':
         case 'uri:regexp':
             $legacyAccessType = eZSiteAccess::TYPE_URI;
             break;
         case 'host:map':
         case 'host:element':
         case 'host:text':
         case 'host:regexp':
             $legacyAccessType = eZSiteAccess::TYPE_HTTP_HOST;
             break;
         case 'port':
             $legacyAccessType = eZSiteAccess::TYPE_PORT;
             break;
         default:
             $legacyAccessType = eZSiteAccess::TYPE_CUSTOM;
     }
     // uri_part
     $pathinfo = str_replace($request->attributes->get('viewParametersString'), '', $request->getPathInfo());
     $semanticPathinfo = $request->attributes->get('semanticPathinfo', $pathinfo);
     if ($pathinfo != $semanticPathinfo) {
         $aPathinfo = explode('/', substr($pathinfo, 1));
         $aSemanticPathinfo = explode('/', substr($semanticPathinfo, 1));
         $uriPart = array_diff($aPathinfo, $aSemanticPathinfo, $this->getFragmentPathItems());
     }
     $event->getParameters()->set('siteaccess', array('name' => $siteAccess->name, 'type' => $legacyAccessType, 'uri_part' => $uriPart));
 }
Ejemplo n.º 3
0
 /**
  * Performs actions related to security before kernel build (mainly settings injection).
  *
  * @param PreBuildKernelWebHandlerEvent $event
  */
 public function onLegacyKernelWebBuild(PreBuildKernelWebHandlerEvent $event)
 {
     if ($this->configResolver->getParameter('legacy_mode') === true) {
         return;
     }
     $injectedMergeSettings = $event->getParameters()->get('injected-merge-settings', array());
     $accessRules = array('access;disable', 'module;user/login', 'module;user/logout');
     // Merge existing settings with the new ones if needed.
     if (isset($injectedMergeSettings['site.ini/SiteAccessRules/Rules'])) {
         $accessRules = array_merge($injectedMergeSettings['site.ini/SiteAccessRules/Rules'], $accessRules);
     }
     $injectedMergeSettings['site.ini/SiteAccessRules/Rules'] = $accessRules;
     $event->getParameters()->set('injected-merge-settings', $injectedMergeSettings);
 }
Ejemplo n.º 4
0
 /**
  * Maps matched siteaccess to the legacy parameters.
  *
  * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelWebHandlerEvent $event
  */
 public function onBuildKernelWebHandler(PreBuildKernelWebHandlerEvent $event)
 {
     $siteAccess = $this->container->get('ezpublish.siteaccess');
     $request = $event->getRequest();
     $uriPart = array();
     // Convert matching type
     switch ($siteAccess->matchingType) {
         case 'default':
             $legacyAccessType = eZSiteAccess::TYPE_DEFAULT;
             break;
         case 'env':
             $legacyAccessType = eZSiteAccess::TYPE_SERVER_VAR;
             break;
         case 'uri:map':
         case 'uri:element':
         case 'uri:text':
         case 'uri:regexp':
             $legacyAccessType = eZSiteAccess::TYPE_URI;
             break;
         case 'host:map':
         case 'host:element':
         case 'host:text':
         case 'host:regexp':
             $legacyAccessType = eZSiteAccess::TYPE_HTTP_HOST;
             break;
         case 'port':
             $legacyAccessType = eZSiteAccess::TYPE_PORT;
             break;
         default:
             $legacyAccessType = eZSiteAccess::TYPE_CUSTOM;
     }
     // uri_part
     $pathinfo = str_replace($request->attributes->get('viewParametersString'), '', $request->getPathInfo());
     $semanticPathinfo = $request->attributes->get('semanticPathinfo', $pathinfo);
     if ($pathinfo != $semanticPathinfo) {
         $aPathinfo = explode('/', substr(rawurldecode($pathinfo), 1));
         $aSemanticPathinfo = explode('/', substr($semanticPathinfo, 1));
         $uriPart = array_diff($aPathinfo, $aSemanticPathinfo, $this->getFragmentPathItems());
     }
     // Handle host_uri match
     if ($siteAccess->matcher instanceof CompoundInterface) {
         $subMatchers = $siteAccess->matcher->getSubMatchers();
         if (!$subMatchers) {
             throw new \RuntimeException('Compound matcher used but not submatchers found.');
         }
         if (count($subMatchers) == 2 && isset($subMatchers['Map\\Host']) && isset($subMatchers['Map\\URI'])) {
             $legacyAccessType = eZSiteAccess::TYPE_HTTP_HOST_URI;
             $uriPart = array($subMatchers['Map\\URI']->getMapKey());
         }
     }
     $event->getParameters()->set('siteaccess', array('name' => $siteAccess->name, 'type' => $legacyAccessType, 'uri_part' => $uriPart));
 }