"Fossies" - the Fresh Open Source Software Archive 
Member "neos-development-collection-7.0.1/Neos.Neos/Classes/Domain/Repository/SiteRepository.php" (23 Feb 2021, 2910 Bytes) of package /linux/www/neos-development-collection-7.0.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "SiteRepository.php" see the
Fossies "Dox" file reference documentation.
1 <?php
2 namespace Neos\Neos\Domain\Repository;
3
4 /*
5 * This file is part of the Neos.Neos package.
6 *
7 * (c) Contributors of the Neos Project - www.neos.io
8 *
9 * This package is Open Source Software. For the full copyright and license
10 * information, please view the LICENSE file which was distributed with this
11 * source code.
12 */
13
14 use Neos\Flow\Annotations as Flow;
15 use Neos\Flow\Persistence\QueryInterface;
16 use Neos\Flow\Persistence\QueryResultInterface;
17 use Neos\Flow\Persistence\Repository;
18 use Neos\Neos\Domain\Model\Site;
19 use Neos\Neos\Domain\Exception as NeosException;
20
21 /**
22 * The Site Repository
23 *
24 * @Flow\Scope("singleton")
25 * @api
26 */
27 class SiteRepository extends Repository
28 {
29 /**
30 * @var array
31 */
32 protected $defaultOrderings = [
33 'name' => QueryInterface::ORDER_ASCENDING,
34 'nodeName' => QueryInterface::ORDER_ASCENDING
35 ];
36
37 /**
38 * @Flow\InjectConfiguration(package="Neos.Neos", path="defaultSiteNodeName")
39 * @var string
40 */
41 protected $defaultSiteNodeName;
42
43 /**
44 * Finds the first site
45 *
46 * @return Site The first site or NULL if none exists
47 * @api
48 */
49 public function findFirst()
50 {
51 return $this->createQuery()->execute()->getFirst();
52 }
53
54 /**
55 * Find all sites with status "online"
56 *
57 * @return QueryResultInterface
58 */
59 public function findOnline()
60 {
61 return $this->findByState(Site::STATE_ONLINE);
62 }
63
64 /**
65 * Find first site with status "online"
66 *
67 * @return Site
68 */
69 public function findFirstOnline()
70 {
71 return $this->findOnline()->getFirst();
72 }
73
74
75 /**
76 * @param string $nodeName
77 * @return Site|null
78 */
79 public function findOneByNodeName(string $nodeName): ?Site
80 {
81 $query = $this->createQuery();
82 /** @var Site|null $site */
83 $site = $query->matching(
84 $query->equals('nodeName', $nodeName)
85 )
86 ->execute()
87 ->getFirst();
88 return $site;
89 }
90
91 /**
92 * Find the site that was specified in the configuration ``defaultSiteNodeName``
93 *
94 * If the defaultSiteNodeName-setting is null the first active site is returned
95 * If the site is not found or not active an exception is thrown
96 *
97 * @return Site
98 * @throws NeosException
99 */
100 public function findDefault()
101 {
102 if ($this->defaultSiteNodeName === null) {
103 return $this->findOnline()->getFirst();
104 }
105 /**
106 * @var Site $defaultSite
107 */
108 $defaultSite = $this->findOneByNodeName($this->defaultSiteNodeName);
109 if (!$defaultSite instanceof Site || $defaultSite->getState() !== Site::STATE_ONLINE) {
110 throw new NeosException(sprintf('DefaultSiteNode %s not found or not active', $this->defaultSiteNodeName), 1476374818);
111 }
112 return $defaultSite;
113 }
114 }