vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/Values/Content/ContentProxy.php line 84

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace eZ\Publish\Core\Repository\Values\Content;
  7. use eZ\Publish\API\Repository\Values\Content\Content as APIContent;
  8. use eZ\Publish\API\Repository\Values\ContentType\ContentType;
  9. use eZ\Publish\Core\Repository\Values\GeneratorProxyTrait;
  10. /**
  11.  * This class represents a (lazy loaded) proxy for a content value.
  12.  *
  13.  * @internal Meant for internal use by Repository, type hint against API object instead.
  14.  */
  15. class ContentProxy extends APIContent
  16. {
  17.     use GeneratorProxyTrait;
  18.     /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
  19.     protected $object;
  20.     /** @var ContentContentInfoProxy|null */
  21.     protected $contentInfoProxy;
  22.     public function __get($name)
  23.     {
  24.         if ($name === 'id') {
  25.             return $this->id;
  26.         }
  27.         if ($name === 'contentInfo') {
  28.             return $this->getContentInfo();
  29.         }
  30.         if ($this->object === null) {
  31.             $this->loadObject();
  32.         }
  33.         return $this->object->$name;
  34.     }
  35.     public function __isset($name)
  36.     {
  37.         if ($name === 'id' || $name === 'contentInfo') {
  38.             return true;
  39.         }
  40.         if ($this->object === null) {
  41.             $this->loadObject();
  42.         }
  43.         return isset($this->object->$name);
  44.     }
  45.     /**
  46.      * Return content info, in proxy form if we have not loaded object yet.
  47.      *
  48.      * For usage in among others DomainMapper->buildLocation() to make sure we can lazy load content info retrieval.
  49.      *
  50.      * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
  51.      */
  52.     protected function getContentInfo()
  53.     {
  54.         if ($this->object === null) {
  55.             if ($this->contentInfoProxy === null) {
  56.                 $this->contentInfoProxy = new ContentContentInfoProxy($this$this->id);
  57.             }
  58.             return $this->contentInfoProxy;
  59.         } elseif ($this->contentInfoProxy !== null) {
  60.             // Remove ref when we no longer need the proxy
  61.             $this->contentInfoProxy null;
  62.         }
  63.         return $this->object->getVersionInfo()->getContentInfo();
  64.     }
  65.     public function getVersionInfo()
  66.     {
  67.         if ($this->object === null) {
  68.             $this->loadObject();
  69.         }
  70.         return $this->object->getVersionInfo();
  71.     }
  72.     public function getContentType(): ContentType
  73.     {
  74.         if ($this->object === null) {
  75.             $this->loadObject();
  76.         }
  77.         return $this->object->getContentType();
  78.     }
  79.     public function getFieldValue($fieldDefIdentifier$languageCode null)
  80.     {
  81.         if ($this->object === null) {
  82.             $this->loadObject();
  83.         }
  84.         return $this->object->getFieldValue($fieldDefIdentifier$languageCode);
  85.     }
  86.     public function getFields()
  87.     {
  88.         if ($this->object === null) {
  89.             $this->loadObject();
  90.         }
  91.         return $this->object->getFields();
  92.     }
  93.     public function getFieldsByLanguage($languageCode null)
  94.     {
  95.         if ($this->object === null) {
  96.             $this->loadObject();
  97.         }
  98.         return $this->object->getFieldsByLanguage($languageCode);
  99.     }
  100.     public function getField($fieldDefIdentifier$languageCode null)
  101.     {
  102.         if ($this->object === null) {
  103.             $this->loadObject();
  104.         }
  105.         return $this->object->getField($fieldDefIdentifier$languageCode);
  106.     }
  107. }