vendor/netgen/layouts-core/lib/API/Values/Layout/Layout.php line 27

  1. <?php
  2. declare(strict_types=1);
  3. namespace Netgen\Layouts\API\Values\Layout;
  4. use ArrayAccess;
  5. use Countable;
  6. use DateTimeInterface;
  7. use Doctrine\Common\Collections\Collection;
  8. use IteratorAggregate;
  9. use Netgen\Layouts\API\Values\Value;
  10. use Netgen\Layouts\API\Values\ValueStatusTrait;
  11. use Netgen\Layouts\Exception\API\LayoutException;
  12. use Netgen\Layouts\Exception\RuntimeException;
  13. use Netgen\Layouts\Layout\Type\LayoutTypeInterface;
  14. use Netgen\Layouts\Utils\HydratorTrait;
  15. use Ramsey\Uuid\UuidInterface;
  16. use Traversable;
  17. use function in_array;
  18. /**
  19.  * @implements \IteratorAggregate<string, \Netgen\Layouts\API\Values\Layout\Zone>
  20.  * @implements \ArrayAccess<string, \Netgen\Layouts\API\Values\Layout\Zone>
  21.  */
  22. final class Layout implements ValueArrayAccessIteratorAggregateCountable
  23. {
  24.     use HydratorTrait;
  25.     use ValueStatusTrait;
  26.     private UuidInterface $id;
  27.     private LayoutTypeInterface $layoutType;
  28.     private string $name;
  29.     private string $description;
  30.     private DateTimeInterface $created;
  31.     private DateTimeInterface $modified;
  32.     private bool $shared;
  33.     private string $mainLocale;
  34.     /**
  35.      * @var string[]
  36.      */
  37.     private array $availableLocales;
  38.     /**
  39.      * @var \Doctrine\Common\Collections\Collection<string, \Netgen\Layouts\API\Values\Layout\Zone>
  40.      */
  41.     private Collection $zones;
  42.     public function getId(): UuidInterface
  43.     {
  44.         return $this->id;
  45.     }
  46.     /**
  47.      * Returns the layout type.
  48.      */
  49.     public function getLayoutType(): LayoutTypeInterface
  50.     {
  51.         return $this->layoutType;
  52.     }
  53.     /**
  54.      * Returns human readable name of the layout.
  55.      */
  56.     public function getName(): string
  57.     {
  58.         return $this->name;
  59.     }
  60.     /**
  61.      * Return human readable description of the layout.
  62.      */
  63.     public function getDescription(): string
  64.     {
  65.         return $this->description;
  66.     }
  67.     /**
  68.      * Returns when was the layout first created.
  69.      */
  70.     public function getCreated(): DateTimeInterface
  71.     {
  72.         return $this->created;
  73.     }
  74.     /**
  75.      * Returns when was the layout last updated.
  76.      */
  77.     public function getModified(): DateTimeInterface
  78.     {
  79.         return $this->modified;
  80.     }
  81.     /**
  82.      * Returns if the layout is shared.
  83.      */
  84.     public function isShared(): bool
  85.     {
  86.         return $this->shared;
  87.     }
  88.     /**
  89.      * Returns the main locale of the layout.
  90.      */
  91.     public function getMainLocale(): string
  92.     {
  93.         return $this->mainLocale;
  94.     }
  95.     /**
  96.      * Returns the list of all available locales in the layout.
  97.      *
  98.      * @return string[]
  99.      */
  100.     public function getAvailableLocales(): array
  101.     {
  102.         return $this->availableLocales;
  103.     }
  104.     /**
  105.      * Returns if the layout has the provided locale.
  106.      */
  107.     public function hasLocale(string $locale): bool
  108.     {
  109.         return in_array($locale$this->availableLocalestrue);
  110.     }
  111.     /**
  112.      * Returns all zones from the layout.
  113.      */
  114.     public function getZones(): ZoneList
  115.     {
  116.         return new ZoneList($this->zones->toArray());
  117.     }
  118.     /**
  119.      * Returns the specified zone.
  120.      *
  121.      * @throws \Netgen\Layouts\Exception\API\LayoutException If the zone does not exist
  122.      */
  123.     public function getZone(string $zoneIdentifier): Zone
  124.     {
  125.         $zone $this->zones->get($zoneIdentifier);
  126.         if ($zone === null) {
  127.             throw LayoutException::noZone($zoneIdentifier);
  128.         }
  129.         return $zone;
  130.     }
  131.     /**
  132.      * Returns if layout has a specified zone.
  133.      */
  134.     public function hasZone(string $zoneIdentifier): bool
  135.     {
  136.         return $this->zones->containsKey($zoneIdentifier);
  137.     }
  138.     public function getIterator(): Traversable
  139.     {
  140.         return $this->zones->getIterator();
  141.     }
  142.     public function count(): int
  143.     {
  144.         return $this->zones->count();
  145.     }
  146.     /**
  147.      * @param mixed $offset
  148.      */
  149.     public function offsetExists($offset): bool
  150.     {
  151.         return $this->zones->offsetExists($offset);
  152.     }
  153.     /**
  154.      * @param mixed $offset
  155.      */
  156.     public function offsetGet($offset): ?Zone
  157.     {
  158.         return $this->zones->offsetGet($offset);
  159.     }
  160.     /**
  161.      * @param mixed $offset
  162.      * @param mixed $value
  163.      */
  164.     public function offsetSet($offset$value): void
  165.     {
  166.         throw new RuntimeException('Method call not supported.');
  167.     }
  168.     /**
  169.      * @param mixed $offset
  170.      */
  171.     public function offsetUnset($offset): void
  172.     {
  173.         throw new RuntimeException('Method call not supported.');
  174.     }
  175. }