vendor/sulu/sulu/src/Sulu/Component/Content/Repository/Content.php line 397

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Content\Repository;
  11. use Jackalope\Query\Row;
  12. use JMS\Serializer\Annotation\ExclusionPolicy;
  13. use JMS\Serializer\Annotation\Expose;
  14. use JMS\Serializer\Annotation\SerializedName;
  15. use JMS\Serializer\Annotation\VirtualProperty;
  16. use Sulu\Component\Content\Compat\StructureType;
  17. use Sulu\Exception\FeatureNotImplementedException;
  18. /**
  19.  * Container class for content data.
  20.  *
  21.  * @ExclusionPolicy("all")
  22.  */
  23. class Content implements \ArrayAccess
  24. {
  25.     /**
  26.      * @var string
  27.      *
  28.      * @Expose
  29.      */
  30.     private $locale;
  31.     /**
  32.      * @var string
  33.      *
  34.      * @Expose
  35.      */
  36.     private $webspaceKey;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @Expose
  41.      */
  42.     private $id;
  43.     /**
  44.      * @var string
  45.      *
  46.      * @Expose
  47.      */
  48.     private $path;
  49.     /**
  50.      * @var int
  51.      */
  52.     private $workflowStage;
  53.     /**
  54.      * @var int
  55.      */
  56.     private $nodeType;
  57.     /**
  58.      * @var bool
  59.      *
  60.      * @Expose
  61.      */
  62.     private $hasChildren;
  63.     /**
  64.      * @var string
  65.      */
  66.     private $template;
  67.     /**
  68.      * @var bool
  69.      */
  70.     private $brokenTemplate;
  71.     /**
  72.      * @var Content[]
  73.      */
  74.     private $children;
  75.     /**
  76.      * @var array
  77.      */
  78.     private $data;
  79.     /**
  80.      * @var array
  81.      */
  82.     private $permissions;
  83.     /**
  84.      * @var StructureType
  85.      */
  86.     private $localizationType;
  87.     /**
  88.      * @var string
  89.      *
  90.      * @Expose
  91.      */
  92.     private $url;
  93.     /**
  94.      * @var array<string, string|null>
  95.      */
  96.     private $urls;
  97.     /**
  98.      * @var string[]
  99.      *
  100.      * @Expose
  101.      */
  102.     private $contentLocales;
  103.     /**
  104.      * @var Row
  105.      */
  106.     private $row;
  107.     public function __construct(
  108.         $locale,
  109.         $webspaceKey,
  110.         $id,
  111.         $path,
  112.         $workflowStage,
  113.         $nodeType,
  114.         $hasChildren,
  115.         $template,
  116.         array $data,
  117.         array $permissions,
  118.         StructureType $localizationType null
  119.     ) {
  120.         $this->locale $locale;
  121.         $this->webspaceKey $webspaceKey;
  122.         $this->id $id;
  123.         $this->path $path;
  124.         $this->workflowStage $workflowStage;
  125.         $this->nodeType $nodeType;
  126.         $this->hasChildren $hasChildren;
  127.         $this->template $template;
  128.         $this->data $data;
  129.         $this->permissions $permissions;
  130.         $this->localizationType $localizationType;
  131.     }
  132.     /**
  133.      * @return string
  134.      */
  135.     public function getId()
  136.     {
  137.         return $this->id;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getPath()
  143.     {
  144.         return $this->path;
  145.     }
  146.     /**
  147.      * @return array
  148.      */
  149.     public function getData()
  150.     {
  151.         return $this->data;
  152.     }
  153.     /**
  154.      * Returns value for given property or given default.
  155.      *
  156.      * @param string $name
  157.      */
  158.     public function getPropertyWithDefault($name$default null)
  159.     {
  160.         if (!\array_key_exists($name$this->data)) {
  161.             return $default;
  162.         }
  163.         return $this->data[$name];
  164.     }
  165.     /**
  166.      * @param string $propertyName
  167.      */
  168.     public function setDataProperty($propertyName$value)
  169.     {
  170.         $this->data[$propertyName] = $value;
  171.     }
  172.     /**
  173.      * @return int
  174.      */
  175.     public function getWorkflowStage()
  176.     {
  177.         return $this->workflowStage;
  178.     }
  179.     /**
  180.      * @return int
  181.      */
  182.     public function getNodeType()
  183.     {
  184.         return $this->nodeType;
  185.     }
  186.     /**
  187.      * Returns template.
  188.      *
  189.      * @return string
  190.      *
  191.      * @VirtualProperty
  192.      * @SerializedName("template")
  193.      */
  194.     public function getTemplate()
  195.     {
  196.         if ($this->brokenTemplate) {
  197.             return;
  198.         }
  199.         return $this->template;
  200.     }
  201.     /**
  202.      * Returns original-template.
  203.      *
  204.      * @return string
  205.      *
  206.      * @VirtualProperty
  207.      * @SerializedName("originalTemplate")
  208.      */
  209.     public function getOriginalTemplate()
  210.     {
  211.         return $this->template;
  212.     }
  213.     /**
  214.      * Set broken-template flag.
  215.      *
  216.      * @return $this
  217.      */
  218.     public function setBrokenTemplate()
  219.     {
  220.         $this->brokenTemplate true;
  221.         return $this;
  222.     }
  223.     /**
  224.      * @return bool
  225.      */
  226.     public function isBrokenTemplate()
  227.     {
  228.         return $this->brokenTemplate;
  229.     }
  230.     /**
  231.      * @return array
  232.      */
  233.     public function getPermissions()
  234.     {
  235.         return $this->permissions;
  236.     }
  237.     /**
  238.      * @return bool
  239.      */
  240.     public function hasChildren()
  241.     {
  242.         return $this->hasChildren;
  243.     }
  244.     /**
  245.      * @return StructureType
  246.      */
  247.     public function getLocalizationType()
  248.     {
  249.         return $this->localizationType;
  250.     }
  251.     /**
  252.      * @return string
  253.      */
  254.     public function getLocale()
  255.     {
  256.         return $this->locale;
  257.     }
  258.     /**
  259.      * @return string
  260.      */
  261.     public function getWebspaceKey()
  262.     {
  263.         return $this->webspaceKey;
  264.     }
  265.     /**
  266.      * @param Content[] $children
  267.      */
  268.     public function setChildren($children)
  269.     {
  270.         $this->children $children;
  271.     }
  272.     /**
  273.      * @return Content[]
  274.      */
  275.     public function getChildren()
  276.     {
  277.         return $this->children;
  278.     }
  279.     /**
  280.      * @return Row
  281.      */
  282.     public function getRow()
  283.     {
  284.         return $this->row;
  285.     }
  286.     public function setRow(Row $row)
  287.     {
  288.         $this->row $row;
  289.     }
  290.     /**
  291.      * @return string[]
  292.      */
  293.     public function getMapping()
  294.     {
  295.         return \implode(','\array_keys($this->data));
  296.     }
  297.     /**
  298.      * @return array<string, string|null>
  299.      */
  300.     public function getUrls()
  301.     {
  302.         return $this->urls;
  303.     }
  304.     /**
  305.      * @param array<string, string|null> $urls
  306.      */
  307.     public function setUrls(array $urls)
  308.     {
  309.         $this->urls $urls;
  310.     }
  311.     /**
  312.      * @return string
  313.      */
  314.     public function getUrl()
  315.     {
  316.         return $this->url;
  317.     }
  318.     /**
  319.      * @param string $url
  320.      */
  321.     public function setUrl($url)
  322.     {
  323.         $this->url $url;
  324.     }
  325.     /**
  326.      * @return string[]
  327.      */
  328.     public function getContentLocales()
  329.     {
  330.         return $this->contentLocales;
  331.     }
  332.     /**
  333.      * @param string[] $contentLocales
  334.      */
  335.     public function setContentLocales($contentLocales)
  336.     {
  337.         $this->contentLocales $contentLocales;
  338.     }
  339.     #[\ReturnTypeWillChange]
  340.     public function offsetExists($offset)
  341.     {
  342.         return \array_key_exists($offset$this->data);
  343.     }
  344.     public function offsetGet($offset)
  345.     {
  346.         return $this->data[$offset];
  347.     }
  348.     #[\ReturnTypeWillChange]
  349.     public function offsetSet($offset$value)
  350.     {
  351.         throw new FeatureNotImplementedException();
  352.     }
  353.     #[\ReturnTypeWillChange]
  354.     public function offsetUnset($offset)
  355.     {
  356.         throw new FeatureNotImplementedException();
  357.     }
  358.     /**
  359.      * @internal
  360.      *
  361.      * @VirtualProperty
  362.      * @SerializedName("_embedded")
  363.      */
  364.     public function getEmbedded(): array
  365.     {
  366.         return [
  367.             'pages' => $this->getChildren(),
  368.         ];
  369.     }
  370. }