Grant evaluation for adding a page on top of the site
@param Site $site The site
@return GrantResult The result
964390
function GrantAddPageToSite(Site $site)
    {
        //Dummy page for evaluation
        $page = new Page();
        $page->SetUserGroup($site->GetUserGroup());
        $siteRights = $site->GetUserGroupRights();
        if ($siteRights)
        {
            $page->SetUserGroupRights($siteRights->GetPageRights());
        }
        return $this->Grant(BackendAction::Create(), $page);
    }
1117603
private function createRootPage(SiteInterface $site): PageInterface
    {
        foreach ($this->router->getRouteCollection()->all() as $name => $route) {
            if ('/' === $route->getPath()) {
                $requirements = $route->getRequirements();
                $name = trim($name);

                return $this->pageManager->create([
                    'routeName' => $name,
                    'name' => $name,
                    'url' => $route->getPath(),
                    'site' => $site,
                    'requestMethod' => $requirements['_method'] ?? 'GET|POST|HEAD|DELETE|PUT',
                    'slug' => '/',
                ]);
            }
        }

        return $this->pageManager->create([
            'routeName' => PageInterface::PAGE_ROUTE_CMS_NAME,
            'name' => 'Homepage',
            'url' => '/',
            'site' => $site,
            'requestMethod' => 'GET|POST|HEAD|DELETE|PUT',
            'slug' => '/',
        ]);
    }
84956
protected function prepareNewSite(Site $newSite)
    {
        $siteId = $newSite->getSiteId();
        if (!empty($siteId)) {
            throw new \Exception(
                "Site ID must be empty to create new site, id {$siteId} given."
            );
        }

        if (empty($newSite->getDomain())) {
            throw new \Exception('Domain is required to create new site.');
        }

        return $this->prepareDefaultValues($newSite);
    }
346618
public function save($site)
    {

        if (is_array($site)) {
            $siteData = $site;
            if ($site['id'] > 0) {
                $site = $this->find($site['id']);
            } else {
                $site = new Site();
            }
            $this->assignArrayToObject($site, $siteData);
        } else if (!($site instanceof Site)) {
            $this->addErrorMessage(self::ERROR_WRONG_OBJECT);
        }

        if (!$this->hasError()) {
            $check = $this->siteManager->save($site);
            if ($check) {
                $this->addSuccessMessage(self::SUCCESS_SAVED);
            }
        }

        return $site;
    }
474280
public function setSite($site = null)
    {
        $this->site = null;

        if (($site = SiteHelper::resolve($site)) === null) {
            $this->site = $this->siteId = null;
        } else {
            $this->siteId = $site->id;
            $this->site = $site;
        }

        return $this;
    }
25906
public function site($site)
    {
        $variables = array('site' => $site);
        $request = $this->get(array('{+base_path}/sites/{site}.json', $variables));
        return new Response\Site($request);
    }
47737
protected function getInitializedIndexService(Site $site)
    {
        $indexService = GeneralUtility::makeInstance(IndexService::class, /** @scrutinizer ignore-type */ $site);
        $indexService->setContextTask($this);
        return $indexService;
    }
652749
public function setSite(\BackBee\Site\Site $site = null)
    {
        $this->_site = $site;

        return $this;
    }
1176972
protected function CanEdit(Site $site)
    {
        return self::Guard()->Allow(BackendAction::Edit(), $site) && 
                self::Guard()->Allow(BackendAction::UseIt(), new SiteForm());
    }
1354922
public function getSiteThemePagesTemplateConfig(Site $site)
    {
        $theme = $site->getTheme();

        $rcmThemesConfig = $this->getThemeConfig($theme);

        if (empty($rcmThemesConfig['pages'])) {
            throw new RuntimeException(
                'No theme config found for site and no default theme found'
            );
        }

        return $rcmThemesConfig['pages'];
    }
496910
protected function getChangeFrequency(ReadNodeInterface $node, ReadSiteInterface $site)
    {
        $sitemapChangefreq = $node->getSitemapChangefreq();

        if (is_null($sitemapChangefreq)) {
            $sitemapChangefreq = $site->getSitemapChangefreq();
        }

        return $sitemapChangefreq;
    }
558565
private function ensureSiteMenus(Site $site)
    {
        $ret = [];

        if ($this->treeManager && $this->allowedMenus) {
            $storage = $this->treeManager->getMenuStorage();

            foreach ($this->allowedMenus as $prefix => $title) {

                $name = $prefix.'-'.$site->getId();

                if (!$storage->exists($name)) {
                    $ret[$name] = $storage->create($name, ['title' => $this->t($title), 'site_id' => $site->getId()]);
                }
            }
        }

        return $ret;
    }
1130198
public function update(SiteInterface $site, OutputInterface $output = null, $clean = false)
    {
        $message = sprintf(
            ' > <info>Updating core routes for site</info> : <comment>%s - %s</comment>',
            $site->getName(),
            $site->getUrl()
        );

        $this->writeln($output, [
            str_repeat('=', \strlen($message)),
            '',
            $message,
            '',
            str_repeat('=', \strlen($message)),
        ]);

        $knowRoutes = [];

        $root = $this->pageManager->getPageByUrl($site, '/');

        // no root url for the given website, create one
        if (!$root) {
            $root = $this->createRootPage($site);
            $this->pageManager->save($root);
        }

        // Iterate over declared routes from the routing mechanism
        foreach ($this->router->getRouteCollection()->all() as $name => $route) {
            $name = trim($name);

            $knowRoutes[] = $name;

            $page = $this->pageManager->findOneBy([
                'routeName' => $name,
                'site' => $site->getId(),
            ]);

            $routeHostRegex = $route->compile()->getHostRegex();

            if (
                !$this->decoratorStrategy->isRouteNameDecorable($name)
                || !$this->decoratorStrategy->isRouteUriDecorable($route->getPath())
                || null !== $routeHostRegex
                && !preg_match($routeHostRegex, $site->getHost())
            ) {
                if ($page) {
                    $page->setEnabled(false);

                    $this->writeln($output, sprintf(
                        '  <error>DISABLE</error> <error>% -50s</error> %s',
                        $name,
                        $route->getPath()
                    ));
                } else {
                    continue;
                }
            }

            $update = true;

            if (!$page) {
                $update = false;

                $requirements = $route->getRequirements();

                $page = $this->pageManager->create([
                    'routeName' => $name,
                    'name' => $name,
                    'url' => $route->getPath(),
                    'site' => $site,
                    'requestMethod' => $requirements['_method'] ??
                        'GET|POST|HEAD|DELETE|PUT',
                ]);
            }

            if (!$page->getParent() && $page->getId() !== $root->getId()) {
                $page->setParent($root);
            }

            $page->setSlug($route->getPath());
            $page->setUrl($route->getPath());
            $page->setRequestMethod($requirements['_method'] ??
                'GET|POST|HEAD|DELETE|PUT');

            $this->pageManager->save($page);

            $this->writeln($output, sprintf(
                '  <info>%s</info> % -50s %s',
                $update ? 'UPDATE ' : 'CREATE ',
                $name,
                $route->getPath()
            ));
        }

        // Iterate over error pages
        foreach ($this->exceptionListener->getHttpErrorCodes() as $name) {
            $name = trim((string) $name);

            $knowRoutes[] = $name;

            $page = $this->pageManager->findOneBy([
                'routeName' => $name,
                'site' => $site->getId(),
            ]);

            if (!$page) {
                $params = [
                    'routeName' => $name,
                    'name' => $name,
                    'decorate' => false,
                    'site' => $site,
                ];

                $page = $this->pageManager->create($params);

                $this->writeln($output, sprintf('  <info>%s</info> % -50s %s', 'CREATE ', $name, ''));
            }

            // an internal page or an error page should not have any parent (no direct access)
            $page->setParent(null);
            $this->pageManager->save($page);
        }

        $has = false;

        foreach ($this->pageManager->getHybridPages($site) as $page) {
            if (!$page->isHybrid() || $page->isInternal()) {
                continue;
            }

            if (!\in_array($page->getRouteName(), $knowRoutes, true)) {
                if (!$has) {
                    $has = true;

                    $this->writeln($output, ['', 'Some hybrid pages does not exist anymore', str_repeat('-', 80)]);
                }

                if ($clean) {
                    $this->pageManager->delete($page);

                    $this->writeln($output, sprintf('  <error>REMOVED</error>   %s', $page->getRouteName()));
                } else {
                    $this->writeln($output, sprintf('  <error>ERROR</error>   %s', $page->getRouteName()));
                }
            }
        }

        if ($has && !$clean) {
            $this->writeln($output, <<<'MSG'
<error>
  *WARNING* : Pages has been updated however some pages do not exist anymore.
              You must remove them manually.
</error>
MSG
            );
        }
    }
433542
protected function setBaseUrl($site): self
    {
        $this->baseUrl = sprintf($this->baseUrl, $site, self::VERSION);

        return $this;
    }
842335
static function LoadInstalledToFrontend(Site $site)
    {
        $bundles = InstalledBundle::Schema()->Fetch();
        foreach ($bundles as $bundle)
        {
            $manifest = ClassFinder::Manifest($bundle->GetBundle());
            $manifest->LoadToFrontend($site);
        }
    }
771156
protected function checkSiteAndAbort($site = null)
    {
        $site = $site ? $site : fp_env('ACACHA_FORGE_SITE');
        if (! $this->checkSite($site)) {
            $this->error('Site ' . $site . '  not valid');
            die();
        }
    }
1234392
public function getSite($domain, $useCache = true)
    {
        $site = null;

        if ($useCache) {
            $site = $this->getCache($domain);
        }

        if (!empty($site)) {
            return $site;
        }

        $site = $this->siteRepo->getSiteByDomain($domain);

        if (empty($site)) {
            $site = new Site(
                Tracking::UNKNOWN_USER_ID,
                'Fake site due to site domain not found ' . get_class($this)
            );
        }

        return $site;
    }