setPortals() public method

Sets the portals for this collection.
public setPortals ( Portal[] $portals )
$portals Sulu\Component\Webspace\Portal[]
示例#1
0
 public function build()
 {
     $finder = new Finder();
     $finder->in($this->path)->files()->name('*.xml')->sortByName();
     // Iterate over config files, and add a portal object for each config to the collection
     $collection = new WebspaceCollection();
     // reset arrays
     $this->webspaces = [];
     $this->portals = [];
     $this->portalInformations = [];
     foreach ($finder as $file) {
         // add file resource for cache invalidation
         $collection->addResource(new FileResource($file->getRealPath()));
         /** @var Webspace $webspace */
         $webspace = $this->loader->load($file->getRealPath());
         $this->webspaces[] = $webspace;
         $this->buildPortals($webspace);
     }
     $environments = array_keys($this->portalInformations);
     foreach ($environments as $environment) {
         // sort all portal informations by length
         uksort($this->portalInformations[$environment], function ($a, $b) {
             return strlen($a) < strlen($b);
         });
     }
     $collection->setWebspaces($this->webspaces);
     $collection->setPortals($this->portals);
     $collection->setPortalInformations($this->portalInformations);
     return $collection;
 }
 public function build()
 {
     $finder = new Finder();
     $finder->in($this->path)->files()->name('*.xml')->sortByName();
     // Iterate over config files, and add a portal object for each config to the collection
     $collection = new WebspaceCollection();
     // reset arrays
     $this->webspaces = [];
     $this->portals = [];
     $this->portalInformations = [];
     foreach ($finder as $file) {
         /* @var SplFileInfo $file */
         try {
             // add file resource for cache invalidation
             $collection->addResource(new FileResource($file->getRealPath()));
             /** @var Webspace $webspace */
             $webspace = $this->loader->load($file->getRealPath());
             $this->webspaces[] = $webspace;
             $this->buildPortals($webspace);
         } catch (\InvalidArgumentException $iae) {
             $this->logger->warning('Error in file "' . $file->getRealPath() . '" (' . $iae->getMessage() . '). The file has been skipped');
         } catch (InvalidUrlDefinitionException $iude) {
             $this->logger->warning('Error: "' . $iude->getMessage() . '" in "' . $file->getRealPath() . '". File was skipped');
         }
     }
     if (0 === count($this->webspaces)) {
         throw new NoValidWebspaceException($this->path);
     }
     $environments = array_keys($this->portalInformations);
     foreach ($environments as $environment) {
         // sort all portal informations by length
         uksort($this->portalInformations[$environment], function ($a, $b) {
             return strlen($a) < strlen($b);
         });
     }
     $collection->setWebspaces($this->webspaces);
     $collection->setPortals($this->portals);
     $collection->setPortalInformations($this->portalInformations);
     return $collection;
 }
示例#3
0
 public function setUp()
 {
     $webspaces = [];
     $portals = [];
     $portalInformations = ['prod' => [], 'dev' => []];
     $this->webspaceCollection = new WebspaceCollection();
     // first portal
     $portal = new Portal();
     $portal->setName('Portal1');
     $portal->setKey('portal1');
     $theme = new Theme();
     $theme->setKey('portal1theme');
     $environment = new Environment();
     $url = new Url();
     $url->setUrl('www.portal1.com');
     $url->setLanguage('en');
     $url->setCountry('us');
     $environment->addUrl($url);
     $environment->setType('prod');
     $url = new Url();
     $url->setUrl('portal1.com');
     $url->setRedirect('www.portal1.com');
     $environment->addUrl($url);
     $portal->addEnvironment($environment);
     $localizationEnUs = new Localization();
     $localizationEnUs->setCountry('us');
     $localizationEnUs->setLanguage('en');
     $localizationEnUs->setShadow('auto');
     $localizationEnUs->setDefault(true);
     $localizationEnCa = new Localization();
     $localizationEnCa->setCountry('ca');
     $localizationEnCa->setLanguage('en');
     $localizationEnCa->setDefault(false);
     $localizationEnUs->addChild($localizationEnCa);
     $localizationFrCa = new Localization();
     $localizationFrCa->setCountry('ca');
     $localizationFrCa->setLanguage('fr');
     $localizationFrCa->setDefault(false);
     $portal->addLocalization($localizationEnUs);
     $portal->addLocalization($localizationEnCa);
     $portal->addLocalization($localizationFrCa);
     $portal->setDefaultLocalization($localizationEnUs);
     $portal->setResourceLocatorStrategy('tree');
     $webspace = new Webspace();
     $webspace->addLocalization($localizationEnUs);
     $webspace->addLocalization($localizationFrCa);
     $segmentSummer = new Segment();
     $segmentSummer->setName('Summer');
     $segmentSummer->setKey('s');
     $segmentSummer->setDefault(true);
     $segmentWinter = new Segment();
     $segmentWinter->setName('Winter');
     $segmentWinter->setKey('w');
     $segmentWinter->setDefault(false);
     $webspace->addSegment($segmentSummer);
     $webspace->addSegment($segmentWinter);
     $webspace->setTheme($theme);
     $webspace->addPortal($portal);
     $webspace->setKey('default');
     $webspace->setName('Default');
     $webspace->addPortal($portal);
     $webspace->setNavigation(new Navigation([new NavigationContext('main', [])]));
     $portals[] = $portal;
     $webspaces[] = $webspace;
     $portalInformations['prod']['www.portal1.com'] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_FULL, $webspace, $portal, $localizationEnUs, 'www.portal1.com', $segmentSummer);
     $portalInformations['dev']['portal1.lo'] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_FULL, $webspace, $portal, $localizationEnUs, 'portal1.lo', $segmentSummer);
     $this->webspaceCollection->setWebspaces($webspaces);
     $this->webspaceCollection->setPortals($portals);
     $this->webspaceCollection->setPortalInformations($portalInformations);
 }