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;
}