vendor/pimcore/pimcore/models/DataObject/ClassDefinition.php line 276

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Model\DataObject;
  15. use Pimcore\Cache;
  16. use Pimcore\DataObject\ClassBuilder\PHPClassDumperInterface;
  17. use Pimcore\Db;
  18. use Pimcore\Event\DataObjectClassDefinitionEvents;
  19. use Pimcore\Event\Model\DataObject\ClassDefinitionEvent;
  20. use Pimcore\Event\Traits\RecursionBlockingEventDispatchHelperTrait;
  21. use Pimcore\File;
  22. use Pimcore\Logger;
  23. use Pimcore\Model;
  24. use Pimcore\Model\DataObject;
  25. use Pimcore\Model\DataObject\ClassDefinition\Data\FieldDefinitionEnrichmentInterface;
  26. /**
  27.  * @method \Pimcore\Model\DataObject\ClassDefinition\Dao getDao()
  28.  */
  29. final class ClassDefinition extends Model\AbstractModel
  30. {
  31.     use DataObject\ClassDefinition\Helper\VarExport;
  32.     use DataObject\Traits\LocateFileTrait;
  33.     use RecursionBlockingEventDispatchHelperTrait;
  34.     /**
  35.      * @internal
  36.      *
  37.      * @var string|null
  38.      */
  39.     public $id;
  40.     /**
  41.      * @internal
  42.      *
  43.      * @var string|null
  44.      */
  45.     public $name;
  46.     /**
  47.      * @internal
  48.      *
  49.      * @var string
  50.      */
  51.     public $description '';
  52.     /**
  53.      * @internal
  54.      *
  55.      * @var int|null
  56.      */
  57.     public $creationDate;
  58.     /**
  59.      * @internal
  60.      *
  61.      * @var int|null
  62.      */
  63.     public $modificationDate;
  64.     /**
  65.      * @internal
  66.      *
  67.      * @var int|null
  68.      */
  69.     public $userOwner;
  70.     /**
  71.      * @internal
  72.      *
  73.      * @var int|null
  74.      */
  75.     public $userModification;
  76.     /**
  77.      * @internal
  78.      *
  79.      * @var string
  80.      */
  81.     public $parentClass '';
  82.     /**
  83.      * Comma separated list of interfaces
  84.      *
  85.      * @internal
  86.      *
  87.      * @var string|null
  88.      */
  89.     public $implementsInterfaces;
  90.     /**
  91.      * Name of the listing parent class if set
  92.      *
  93.      * @internal
  94.      *
  95.      * @var string
  96.      */
  97.     public $listingParentClass '';
  98.     /**
  99.      * @internal
  100.      *
  101.      * @var string
  102.      */
  103.     public $useTraits '';
  104.     /**
  105.      * @internal
  106.      *
  107.      * @var string
  108.      */
  109.     public $listingUseTraits '';
  110.     /**
  111.      * @internal
  112.      *
  113.      * @var bool
  114.      */
  115.     protected $encryption false;
  116.     /**
  117.      * @internal
  118.      *
  119.      * @var array
  120.      */
  121.     protected $encryptedTables = [];
  122.     /**
  123.      * @internal
  124.      *
  125.      * @var bool
  126.      */
  127.     public $allowInherit false;
  128.     /**
  129.      * @internal
  130.      *
  131.      * @var bool
  132.      */
  133.     public $allowVariants false;
  134.     /**
  135.      * @internal
  136.      *
  137.      * @var bool
  138.      */
  139.     public $showVariants false;
  140.     /**
  141.      * @internal
  142.      *
  143.      * @var DataObject\ClassDefinition\Data[]
  144.      */
  145.     public array $fieldDefinitions = [];
  146.     /**
  147.      * @internal
  148.      *
  149.      * @var DataObject\ClassDefinition\Layout|null
  150.      */
  151.     public $layoutDefinitions;
  152.     /**
  153.      * @internal
  154.      *
  155.      * @var string
  156.      */
  157.     public $icon;
  158.     /**
  159.      * @internal
  160.      *
  161.      * @var string
  162.      */
  163.     public $previewUrl;
  164.     /**
  165.      * @internal
  166.      *
  167.      * @var string
  168.      */
  169.     public $group;
  170.     /**
  171.      * @internal
  172.      *
  173.      * @var bool
  174.      */
  175.     public $showAppLoggerTab false;
  176.     /**
  177.      * @internal
  178.      *
  179.      * @var string
  180.      */
  181.     public $linkGeneratorReference;
  182.     /**
  183.      * @internal
  184.      *
  185.      * @var string|null
  186.      */
  187.     public $previewGeneratorReference;
  188.     /**
  189.      * @internal
  190.      *
  191.      * @var array
  192.      */
  193.     public $compositeIndices = [];
  194.     /**
  195.      * @internal
  196.      *
  197.      * @var bool
  198.      */
  199.     public $generateTypeDeclarations true;
  200.     /**
  201.      * @internal
  202.      *
  203.      * @var bool
  204.      */
  205.     public $showFieldLookup false;
  206.     /**
  207.      * @internal
  208.      *
  209.      * @var array
  210.      */
  211.     public $propertyVisibility = [
  212.         'grid' => [
  213.             'id' => true,
  214.             'path' => true,
  215.             'published' => true,
  216.             'modificationDate' => true,
  217.             'creationDate' => true,
  218.         ],
  219.         'search' => [
  220.             'id' => true,
  221.             'path' => true,
  222.             'published' => true,
  223.             'modificationDate' => true,
  224.             'creationDate' => true,
  225.         ],
  226.     ];
  227.     /**
  228.      * @internal
  229.      *
  230.      * @var bool
  231.      */
  232.     public $enableGridLocking false;
  233.     /**
  234.      * @param string $id
  235.      * @param bool $force
  236.      *
  237.      * @return null|ClassDefinition
  238.      *
  239.      * @throws \Exception
  240.      */
  241.     public static function getById(string $id$force false)
  242.     {
  243.         $cacheKey 'class_' $id;
  244.         try {
  245.             if ($force) {
  246.                 throw new \Exception('Forced load');
  247.             }
  248.             $class \Pimcore\Cache\Runtime::get($cacheKey);
  249.             if (!$class) {
  250.                 throw new \Exception('Class in registry is null');
  251.             }
  252.         } catch (\Exception $e) {
  253.             try {
  254.                 $class = new self();
  255.                 $name $class->getDao()->getNameById($id);
  256.                 $definitionFile $class->getDefinitionFile($name);
  257.                 $class = @include $definitionFile;
  258.                 if (!$class instanceof self) {
  259.                     throw new \Exception('Class definition with name ' $name ' or ID ' $id ' does not exist');
  260.                 }
  261.                 $class->setId($id);
  262.                 \Pimcore\Cache\Runtime::set($cacheKey$class);
  263.             } catch (\Exception $e) {
  264.                 Logger::info($e->getMessage());
  265.                 return null;
  266.             }
  267.         }
  268.         return $class;
  269.     }
  270.     /**
  271.      * @param string $name
  272.      *
  273.      * @return self|null
  274.      *
  275.      * @throws \Exception
  276.      */
  277.     public static function getByName($name)
  278.     {
  279.         try {
  280.             $class = new self();
  281.             $id $class->getDao()->getIdByName($name);
  282.             return self::getById($id);
  283.         } catch (Model\Exception\NotFoundException $e) {
  284.             return null;
  285.         }
  286.     }
  287.     /**
  288.      * @param array $values
  289.      *
  290.      * @return self
  291.      */
  292.     public static function create($values = [])
  293.     {
  294.         $class = new self();
  295.         $class->setValues($values);
  296.         return $class;
  297.     }
  298.     /**
  299.      * @internal
  300.      *
  301.      * @param string $name
  302.      */
  303.     public function rename($name)
  304.     {
  305.         $this->deletePhpClasses();
  306.         $this->getDao()->updateClassNameInObjects($name);
  307.         $this->setName($name);
  308.         $this->save();
  309.     }
  310.     /**
  311.      * @param mixed $data
  312.      *
  313.      * @internal
  314.      */
  315.     public static function cleanupForExport(&$data)
  316.     {
  317.         if (!is_object($data)) {
  318.             return;
  319.         }
  320.         if ($data instanceof DataObject\ClassDefinition\Data\VarExporterInterface) {
  321.             $blockedVars $data->resolveBlockedVars();
  322.             foreach ($blockedVars as $blockedVar) {
  323.                 if (isset($data->{$blockedVar})) {
  324.                     unset($data->{$blockedVar});
  325.                 }
  326.             }
  327.             if (isset($data->blockedVarsForExport)) {
  328.                 unset($data->blockedVarsForExport);
  329.             }
  330.         }
  331.         if (method_exists($data'getChildren')) {
  332.             $children $data->getChildren();
  333.             if (is_array($children)) {
  334.                 foreach ($children as $child) {
  335.                     self::cleanupForExport($child);
  336.                 }
  337.             }
  338.         }
  339.     }
  340.     /**
  341.      * @return bool
  342.      */
  343.     private function exists()
  344.     {
  345.         $name $this->getDao()->getNameById($this->getId());
  346.         return is_string($name);
  347.     }
  348.     /**
  349.      * @param bool $saveDefinitionFile
  350.      *
  351.      * @throws \Exception
  352.      * @throws DataObject\Exception\DefinitionWriteException
  353.      */
  354.     public function save($saveDefinitionFile true)
  355.     {
  356.         if ($saveDefinitionFile && !$this->isWritable()) {
  357.             throw new DataObject\Exception\DefinitionWriteException();
  358.         }
  359.         $fieldDefinitions $this->getFieldDefinitions();
  360.         foreach ($fieldDefinitions as $fd) {
  361.             if ($fd->isForbiddenName()) {
  362.                 throw new \Exception(sprintf('Forbidden name used for field definition: %s'$fd->getName()));
  363.             }
  364.             if ($fd instanceof DataObject\ClassDefinition\Data\DataContainerAwareInterface) {
  365.                 $fd->preSave($this);
  366.             }
  367.         }
  368.         if (!$this->getId()) {
  369.             $db Db::get();
  370.             $maxId $db->fetchOne('SELECT MAX(CAST(id AS SIGNED)) FROM classes;');
  371.             $maxId $maxId $maxId 1;
  372.             $this->setId((string) $maxId);
  373.         }
  374.         if (!preg_match('/[a-zA-Z][a-zA-Z0-9_]+/'$this->getName())) {
  375.             throw new \Exception(sprintf('Invalid name for class definition: %s'$this->getName()));
  376.         }
  377.         if (!preg_match('/[a-zA-Z0-9]([a-zA-Z0-9_]+)?/'$this->getId())) {
  378.             throw new \Exception(sprintf('Invalid ID `%s` for class definition %s'$this->getId(), $this->getName()));
  379.         }
  380.         foreach (['parentClass''listingParentClass''useTraits''listingUseTraits'] as $propertyName) {
  381.             $propertyValue $this->{'get'.ucfirst($propertyName)}();
  382.             if ($propertyValue && !preg_match('/^[a-zA-Z_\x7f-\xff\\\][a-zA-Z0-9_\x7f-\xff\\\ ,]*$/'$propertyValue)) {
  383.                 throw new \Exception(sprintf('Invalid %s value for class definition: %s'$propertyName,
  384.                     $this->getParentClass()));
  385.             }
  386.         }
  387.         $isUpdate $this->exists();
  388.         if (!$isUpdate) {
  389.             $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::PRE_ADD);
  390.         } else {
  391.             $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::PRE_UPDATE);
  392.         }
  393.         $this->setModificationDate(time());
  394.         $this->getDao()->save($isUpdate);
  395.         $this->generateClassFiles($saveDefinitionFile);
  396.         // empty object cache
  397.         try {
  398.             Cache::clearTag('class_'.$this->getId());
  399.         } catch (\Exception $e) {
  400.         }
  401.         foreach ($fieldDefinitions as $fd) {
  402.             if ($fd instanceof DataObject\ClassDefinition\Data\DataContainerAwareInterface) {
  403.                 $fd->postSave($this);
  404.             }
  405.         }
  406.         if ($isUpdate) {
  407.             $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::POST_UPDATE);
  408.         } else {
  409.             $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::POST_ADD);
  410.         }
  411.     }
  412.     /**
  413.      * @param bool $generateDefinitionFile
  414.      *
  415.      * @throws \Exception
  416.      *
  417.      * @internal
  418.      */
  419.     public function generateClassFiles($generateDefinitionFile true)
  420.     {
  421.         \Pimcore::getContainer()->get(PHPClassDumperInterface::class)->dumpPHPClasses($this);
  422.         if ($generateDefinitionFile) {
  423.             // save definition as a php file
  424.             $definitionFile $this->getDefinitionFile();
  425.             if (!is_writable(dirname($definitionFile)) || (is_file($definitionFile) && !is_writable($definitionFile))) {
  426.                 throw new \Exception(
  427.                     'Cannot write definition file in: '.$definitionFile.' please check write permission on this directory.'
  428.                 );
  429.             }
  430.             /** @var self $clone */
  431.             $clone DataObject\Service::cloneDefinition($this);
  432.             $clone->setDao(null);
  433.             $clone->fieldDefinitions = [];
  434.             self::cleanupForExport($clone->layoutDefinitions);
  435.             $exportedClass var_export($clonetrue);
  436.             $data '<?php';
  437.             $data .= "\n\n";
  438.             $data .= "\nreturn ".$exportedClass.";\n";
  439.             \Pimcore\File::putPhpFile($definitionFile$data);
  440.         }
  441.     }
  442.     public function delete()
  443.     {
  444.         $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::PRE_DELETE);
  445.         // delete all objects using this class
  446.         $list = new Listing();
  447.         $list->setCondition('o_classId = ?'$this->getId());
  448.         $list->load();
  449.         foreach ($list->getObjects() as $o) {
  450.             $o->delete();
  451.         }
  452.         $this->deletePhpClasses();
  453.         // empty object cache
  454.         try {
  455.             Cache::clearTag('class_'.$this->getId());
  456.         } catch (\Exception $e) {
  457.         }
  458.         // empty output cache
  459.         try {
  460.             Cache::clearTag('output');
  461.         } catch (\Exception $e) {
  462.         }
  463.         $customLayouts = new ClassDefinition\CustomLayout\Listing();
  464.         $customLayouts->setCondition('classId = ?'$this->getId());
  465.         $customLayouts $customLayouts->load();
  466.         foreach ($customLayouts as $customLayout) {
  467.             $customLayout->delete();
  468.         }
  469.         $brickListing = new DataObject\Objectbrick\Definition\Listing();
  470.         $brickListing $brickListing->load();
  471.         foreach ($brickListing as $brickDefinition) {
  472.             $modified false;
  473.             $classDefinitions $brickDefinition->getClassDefinitions();
  474.             if (is_array($classDefinitions)) {
  475.                 foreach ($classDefinitions as $key => $classDefinition) {
  476.                     if ($classDefinition['classname'] == $this->getId()) {
  477.                         unset($classDefinitions[$key]);
  478.                         $modified true;
  479.                     }
  480.                 }
  481.             }
  482.             if ($modified) {
  483.                 $brickDefinition->setClassDefinitions($classDefinitions);
  484.                 $brickDefinition->save();
  485.             }
  486.         }
  487.         $this->getDao()->delete();
  488.         $this->dispatchEvent(new ClassDefinitionEvent($this), DataObjectClassDefinitionEvents::POST_DELETE);
  489.     }
  490.     private function deletePhpClasses()
  491.     {
  492.         // delete the class files
  493.         @unlink($this->getPhpClassFile());
  494.         @unlink($this->getPhpListingClassFile());
  495.         @rmdir(dirname($this->getPhpListingClassFile()));
  496.         @unlink($this->getDefinitionFile());
  497.     }
  498.     /**
  499.      * @internal
  500.      *
  501.      * @return bool
  502.      */
  503.     public function isWritable(): bool
  504.     {
  505.         if ($_SERVER['PIMCORE_CLASS_DEFINITION_WRITABLE'] ?? false) {
  506.             return true;
  507.         }
  508.         return !str_starts_with($this->getDefinitionFile(), PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY);
  509.     }
  510.     /**
  511.      * @internal
  512.      *
  513.      * @param string|null $name
  514.      *
  515.      * @return string
  516.      */
  517.     public function getDefinitionFile($name null)
  518.     {
  519.         return $this->locateDefinitionFile($name ?? $this->getName(), 'definition_%s.php');
  520.     }
  521.     /**
  522.      * @internal
  523.      */
  524.     public function getPhpClassFile(): string
  525.     {
  526.         return $this->locateFile(ucfirst($this->getName()), 'DataObject/%s.php');
  527.     }
  528.     /**
  529.      * @internal
  530.      */
  531.     public function getPhpListingClassFile(): string
  532.     {
  533.         return $this->locateFile(ucfirst($this->getName()), 'DataObject/%s/Listing.php');
  534.     }
  535.     /**
  536.      * @return string|null
  537.      */
  538.     public function getId()
  539.     {
  540.         return $this->id;
  541.     }
  542.     /**
  543.      * @return string|null
  544.      */
  545.     public function getName()
  546.     {
  547.         return $this->name;
  548.     }
  549.     /**
  550.      * @return int|null
  551.      */
  552.     public function getCreationDate()
  553.     {
  554.         return $this->creationDate;
  555.     }
  556.     /**
  557.      * @return int|null
  558.      */
  559.     public function getModificationDate()
  560.     {
  561.         return $this->modificationDate;
  562.     }
  563.     /**
  564.      * @return int|null
  565.      */
  566.     public function getUserOwner()
  567.     {
  568.         return $this->userOwner;
  569.     }
  570.     /**
  571.      * @return int|null
  572.      */
  573.     public function getUserModification()
  574.     {
  575.         return $this->userModification;
  576.     }
  577.     /**
  578.      * @param string $id
  579.      *
  580.      * @return $this
  581.      */
  582.     public function setId($id)
  583.     {
  584.         $this->id $id;
  585.         return $this;
  586.     }
  587.     /**
  588.      * @param string $name
  589.      *
  590.      * @return $this
  591.      */
  592.     public function setName($name)
  593.     {
  594.         $this->name $name;
  595.         return $this;
  596.     }
  597.     /**
  598.      * @param int $creationDate
  599.      *
  600.      * @return $this
  601.      */
  602.     public function setCreationDate($creationDate)
  603.     {
  604.         $this->creationDate = (int)$creationDate;
  605.         return $this;
  606.     }
  607.     /**
  608.      * @param int $modificationDate
  609.      *
  610.      * @return $this
  611.      */
  612.     public function setModificationDate($modificationDate)
  613.     {
  614.         $this->modificationDate = (int)$modificationDate;
  615.         return $this;
  616.     }
  617.     /**
  618.      * @param int $userOwner
  619.      *
  620.      * @return $this
  621.      */
  622.     public function setUserOwner($userOwner)
  623.     {
  624.         $this->userOwner = (int)$userOwner;
  625.         return $this;
  626.     }
  627.     /**
  628.      * @param int $userModification
  629.      *
  630.      * @return $this
  631.      */
  632.     public function setUserModification($userModification)
  633.     {
  634.         $this->userModification = (int)$userModification;
  635.         return $this;
  636.     }
  637.     /**
  638.      * @param array $context
  639.      *
  640.      * @return DataObject\ClassDefinition\Data[]
  641.      */
  642.     public function getFieldDefinitions($context = [])
  643.     {
  644.         if (!\Pimcore::inAdmin() || (isset($context['suppressEnrichment']) && $context['suppressEnrichment'])) {
  645.             return $this->fieldDefinitions;
  646.         }
  647.         $enrichedFieldDefinitions = [];
  648.         foreach ($this->fieldDefinitions as $key => $fieldDefinition) {
  649.             $fieldDefinition $this->doEnrichFieldDefinition($fieldDefinition$context);
  650.             $enrichedFieldDefinitions[$key] = $fieldDefinition;
  651.         }
  652.         return $enrichedFieldDefinitions;
  653.     }
  654.     /**
  655.      * @internal
  656.      */
  657.     protected function doEnrichFieldDefinition($fieldDefinition$context = [])
  658.     {
  659.         //TODO Pimcore 11: remove method_exists BC layer
  660.         if ($fieldDefinition instanceof FieldDefinitionEnrichmentInterface || method_exists($fieldDefinition'enrichFieldDefinition')) {
  661.             if (!$fieldDefinition instanceof FieldDefinitionEnrichmentInterface) {
  662.                 trigger_deprecation('pimcore/pimcore''10.1',
  663.                     sprintf('Usage of method_exists is deprecated since version 10.1 and will be removed in Pimcore 11.' .
  664.                     'Implement the %s interface instead.'FieldDefinitionEnrichmentInterface::class));
  665.             }
  666.             $context['class'] = $this;
  667.             $fieldDefinition $fieldDefinition->enrichFieldDefinition($context);
  668.         }
  669.         return $fieldDefinition;
  670.     }
  671.     /**
  672.      * @return DataObject\ClassDefinition\Layout|null
  673.      */
  674.     public function getLayoutDefinitions()
  675.     {
  676.         return $this->layoutDefinitions;
  677.     }
  678.     /**
  679.      * @param DataObject\ClassDefinition\Data[] $fieldDefinitions
  680.      *
  681.      * @return $this
  682.      */
  683.     public function setFieldDefinitions(array $fieldDefinitions)
  684.     {
  685.         $this->fieldDefinitions $fieldDefinitions;
  686.         return $this;
  687.     }
  688.     /**
  689.      * @param string $key
  690.      * @param DataObject\ClassDefinition\Data $data
  691.      *
  692.      * @return $this
  693.      */
  694.     public function addFieldDefinition($key$data)
  695.     {
  696.         $this->fieldDefinitions[$key] = $data;
  697.         return $this;
  698.     }
  699.     /**
  700.      * @param string $key
  701.      * @param array $context
  702.      *
  703.      * @return DataObject\ClassDefinition\Data|null
  704.      */
  705.     public function getFieldDefinition($key$context = [])
  706.     {
  707.         if (array_key_exists($key$this->fieldDefinitions)) {
  708.             if (!\Pimcore::inAdmin() || (isset($context['suppressEnrichment']) && $context['suppressEnrichment'])) {
  709.                 return $this->fieldDefinitions[$key];
  710.             }
  711.             $fieldDefinition $this->doEnrichFieldDefinition($this->fieldDefinitions[$key], $context);
  712.             return $fieldDefinition;
  713.         }
  714.         return null;
  715.     }
  716.     /**
  717.      * @param DataObject\ClassDefinition\Layout|null $layoutDefinitions
  718.      *
  719.      * @return $this
  720.      */
  721.     public function setLayoutDefinitions($layoutDefinitions)
  722.     {
  723.         $this->layoutDefinitions $layoutDefinitions;
  724.         $this->fieldDefinitions = [];
  725.         $this->extractDataDefinitions($this->layoutDefinitions);
  726.         return $this;
  727.     }
  728.     /**
  729.      * @param DataObject\ClassDefinition\Layout|DataObject\ClassDefinition\Data $def
  730.      */
  731.     private function extractDataDefinitions($def)
  732.     {
  733.         if ($def instanceof DataObject\ClassDefinition\Layout) {
  734.             if ($def->hasChildren()) {
  735.                 foreach ($def->getChildren() as $child) {
  736.                     $this->extractDataDefinitions($child);
  737.                 }
  738.             }
  739.         }
  740.         if ($def instanceof DataObject\ClassDefinition\Data) {
  741.             $existing $this->getFieldDefinition($def->getName());
  742.             if (!$existing && method_exists($def'addReferencedField') && method_exists($def'setReferencedFields')) {
  743.                 $def->setReferencedFields([]);
  744.             }
  745.             if ($existing && method_exists($existing'addReferencedField')) {
  746.                 // this is especially for localized fields which get aggregated here into one field definition
  747.                 // in the case that there are more than one localized fields in the class definition
  748.                 // see also pimcore.object.edit.addToDataFields();
  749.                 $existing->addReferencedField($def);
  750.             } else {
  751.                 $this->addFieldDefinition($def->getName(), $def);
  752.             }
  753.         }
  754.     }
  755.     /**
  756.      * @return string
  757.      */
  758.     public function getParentClass()
  759.     {
  760.         return $this->parentClass;
  761.     }
  762.     /**
  763.      * @return string
  764.      */
  765.     public function getListingParentClass()
  766.     {
  767.         return $this->listingParentClass;
  768.     }
  769.     /**
  770.      * @return string
  771.      */
  772.     public function getUseTraits()
  773.     {
  774.         return $this->useTraits;
  775.     }
  776.     /**
  777.      * @param string $useTraits
  778.      *
  779.      * @return ClassDefinition
  780.      */
  781.     public function setUseTraits($useTraits)
  782.     {
  783.         $this->useTraits = (string) $useTraits;
  784.         return $this;
  785.     }
  786.     /**
  787.      * @return string
  788.      */
  789.     public function getListingUseTraits()
  790.     {
  791.         return $this->listingUseTraits;
  792.     }
  793.     /**
  794.      * @param string $listingUseTraits
  795.      *
  796.      * @return ClassDefinition
  797.      */
  798.     public function setListingUseTraits($listingUseTraits)
  799.     {
  800.         $this->listingUseTraits = (string) $listingUseTraits;
  801.         return $this;
  802.     }
  803.     /**
  804.      * @return bool
  805.      */
  806.     public function getAllowInherit()
  807.     {
  808.         return $this->allowInherit;
  809.     }
  810.     /**
  811.      * @return bool
  812.      */
  813.     public function getAllowVariants()
  814.     {
  815.         return $this->allowVariants;
  816.     }
  817.     /**
  818.      * @param string $parentClass
  819.      *
  820.      * @return $this
  821.      */
  822.     public function setParentClass($parentClass)
  823.     {
  824.         $this->parentClass $parentClass;
  825.         return $this;
  826.     }
  827.     /**
  828.      * @param string $listingParentClass
  829.      *
  830.      * @return $this
  831.      */
  832.     public function setListingParentClass($listingParentClass)
  833.     {
  834.         $this->listingParentClass = (string) $listingParentClass;
  835.         return $this;
  836.     }
  837.     /**
  838.      * @return bool
  839.      */
  840.     public function getEncryption(): bool
  841.     {
  842.         return $this->encryption;
  843.     }
  844.     /**
  845.      * @param bool $encryption
  846.      *
  847.      * @return $this
  848.      */
  849.     public function setEncryption(bool $encryption)
  850.     {
  851.         $this->encryption $encryption;
  852.         return $this;
  853.     }
  854.     /**
  855.      * @internal
  856.      *
  857.      * @param array $tables
  858.      */
  859.     public function addEncryptedTables(array $tables)
  860.     {
  861.         $this->encryptedTables array_unique(array_merge($this->encryptedTables$tables));
  862.     }
  863.     /**
  864.      * @internal
  865.      *
  866.      * @param array $tables
  867.      */
  868.     public function removeEncryptedTables(array $tables)
  869.     {
  870.         foreach ($tables as $table) {
  871.             if (($key array_search($table$this->encryptedTables)) !== false) {
  872.                 unset($this->encryptedTables[$key]);
  873.             }
  874.         }
  875.     }
  876.     /**
  877.      * @internal
  878.      *
  879.      * @param string $table
  880.      *
  881.      * @return bool
  882.      */
  883.     public function isEncryptedTable(string $table): bool
  884.     {
  885.         return (array_search($table$this->encryptedTables) === false) ? false true;
  886.     }
  887.     /**
  888.      * @return bool
  889.      */
  890.     public function hasEncryptedTables(): bool
  891.     {
  892.         return (bool) count($this->encryptedTables);
  893.     }
  894.     /**
  895.      * @internal
  896.      *
  897.      * @param array $encryptedTables
  898.      *
  899.      * @return $this
  900.      */
  901.     public function setEncryptedTables(array $encryptedTables)
  902.     {
  903.         $this->encryptedTables $encryptedTables;
  904.         return $this;
  905.     }
  906.     /**
  907.      * @param bool $allowInherit
  908.      *
  909.      * @return $this
  910.      */
  911.     public function setAllowInherit($allowInherit)
  912.     {
  913.         $this->allowInherit = (bool)$allowInherit;
  914.         return $this;
  915.     }
  916.     /**
  917.      * @param bool $allowVariants
  918.      *
  919.      * @return $this
  920.      */
  921.     public function setAllowVariants($allowVariants)
  922.     {
  923.         $this->allowVariants = (bool)$allowVariants;
  924.         return $this;
  925.     }
  926.     /**
  927.      * @return string
  928.      */
  929.     public function getIcon()
  930.     {
  931.         return $this->icon;
  932.     }
  933.     /**
  934.      * @param string $icon
  935.      *
  936.      * @return $this
  937.      */
  938.     public function setIcon($icon)
  939.     {
  940.         $this->icon $icon;
  941.         return $this;
  942.     }
  943.     /**
  944.      * @return array
  945.      */
  946.     public function getPropertyVisibility()
  947.     {
  948.         return $this->propertyVisibility;
  949.     }
  950.     /**
  951.      * @param array $propertyVisibility
  952.      *
  953.      * @return $this
  954.      */
  955.     public function setPropertyVisibility($propertyVisibility)
  956.     {
  957.         if (is_array($propertyVisibility)) {
  958.             $this->propertyVisibility $propertyVisibility;
  959.         }
  960.         return $this;
  961.     }
  962.     /**
  963.      * @param string $previewUrl
  964.      *
  965.      * @return $this
  966.      */
  967.     public function setPreviewUrl($previewUrl)
  968.     {
  969.         $this->previewUrl $previewUrl;
  970.         return $this;
  971.     }
  972.     /**
  973.      * @return string
  974.      */
  975.     public function getPreviewUrl()
  976.     {
  977.         return $this->previewUrl;
  978.     }
  979.     /**
  980.      * @return string
  981.      */
  982.     public function getGroup()
  983.     {
  984.         return $this->group;
  985.     }
  986.     /**
  987.      * @param string $group
  988.      *
  989.      * @return $this
  990.      */
  991.     public function setGroup($group)
  992.     {
  993.         $this->group $group;
  994.         return $this;
  995.     }
  996.     /**
  997.      * @param string $description
  998.      *
  999.      * @return $this
  1000.      */
  1001.     public function setDescription($description)
  1002.     {
  1003.         $this->description $description;
  1004.         return $this;
  1005.     }
  1006.     /**
  1007.      * @return string
  1008.      */
  1009.     public function getDescription()
  1010.     {
  1011.         return $this->description;
  1012.     }
  1013.     /**
  1014.      * @param bool $showVariants
  1015.      *
  1016.      * @return $this
  1017.      */
  1018.     public function setShowVariants($showVariants)
  1019.     {
  1020.         $this->showVariants = (bool)$showVariants;
  1021.         return $this;
  1022.     }
  1023.     /**
  1024.      * @return bool
  1025.      */
  1026.     public function getShowVariants()
  1027.     {
  1028.         return $this->showVariants;
  1029.     }
  1030.     /**
  1031.      * @return bool
  1032.      */
  1033.     public function getShowAppLoggerTab()
  1034.     {
  1035.         return $this->showAppLoggerTab;
  1036.     }
  1037.     /**
  1038.      * @param bool $showAppLoggerTab
  1039.      *
  1040.      * @return $this
  1041.      */
  1042.     public function setShowAppLoggerTab($showAppLoggerTab)
  1043.     {
  1044.         $this->showAppLoggerTab = (bool) $showAppLoggerTab;
  1045.         return $this;
  1046.     }
  1047.     /**
  1048.      * @return bool
  1049.      */
  1050.     public function getShowFieldLookup()
  1051.     {
  1052.         return $this->showFieldLookup;
  1053.     }
  1054.     /**
  1055.      * @param bool $showFieldLookup
  1056.      *
  1057.      * @return $this
  1058.      */
  1059.     public function setShowFieldLookup($showFieldLookup)
  1060.     {
  1061.         $this->showFieldLookup = (bool) $showFieldLookup;
  1062.         return $this;
  1063.     }
  1064.     /**
  1065.      * @return string
  1066.      */
  1067.     public function getLinkGeneratorReference()
  1068.     {
  1069.         return $this->linkGeneratorReference;
  1070.     }
  1071.     /**
  1072.      * @param string $linkGeneratorReference
  1073.      *
  1074.      * @return $this
  1075.      */
  1076.     public function setLinkGeneratorReference($linkGeneratorReference)
  1077.     {
  1078.         $this->linkGeneratorReference $linkGeneratorReference;
  1079.         return $this;
  1080.     }
  1081.     /**
  1082.      * @return DataObject\ClassDefinition\LinkGeneratorInterface|null
  1083.      */
  1084.     public function getLinkGenerator()
  1085.     {
  1086.         return DataObject\ClassDefinition\Helper\LinkGeneratorResolver::resolveGenerator($this->getLinkGeneratorReference());
  1087.     }
  1088.     /**
  1089.      * @return string|null
  1090.      */
  1091.     public function getPreviewGeneratorReference(): ?string
  1092.     {
  1093.         return $this->previewGeneratorReference;
  1094.     }
  1095.     /**
  1096.      * @param string|null $previewGeneratorReference
  1097.      */
  1098.     public function setPreviewGeneratorReference(?string $previewGeneratorReference): void
  1099.     {
  1100.         $this->previewGeneratorReference $previewGeneratorReference;
  1101.     }
  1102.     /**
  1103.      * @return DataObject\ClassDefinition\PreviewGeneratorInterface|null
  1104.      */
  1105.     public function getPreviewGenerator()
  1106.     {
  1107.         return DataObject\ClassDefinition\Helper\PreviewGeneratorResolver::resolveGenerator($this->getPreviewGeneratorReference());
  1108.     }
  1109.     /**
  1110.      * @return bool
  1111.      */
  1112.     public function isEnableGridLocking(): bool
  1113.     {
  1114.         return $this->enableGridLocking;
  1115.     }
  1116.     /**
  1117.      * @param bool $enableGridLocking
  1118.      */
  1119.     public function setEnableGridLocking(bool $enableGridLocking): void
  1120.     {
  1121.         $this->enableGridLocking $enableGridLocking;
  1122.     }
  1123.     /**
  1124.      * @return string|null
  1125.      */
  1126.     public function getImplementsInterfaces(): ?string
  1127.     {
  1128.         return $this->implementsInterfaces;
  1129.     }
  1130.     /**
  1131.      * @param string|null $implementsInterfaces
  1132.      *
  1133.      * @return $this
  1134.      */
  1135.     public function setImplementsInterfaces(?string $implementsInterfaces)
  1136.     {
  1137.         $this->implementsInterfaces $implementsInterfaces;
  1138.         return $this;
  1139.     }
  1140.     /**
  1141.      * @return array
  1142.      */
  1143.     public function getCompositeIndices(): array
  1144.     {
  1145.         return $this->compositeIndices;
  1146.     }
  1147.     /**
  1148.      * @param array|null $compositeIndices
  1149.      *
  1150.      * @return $this
  1151.      */
  1152.     public function setCompositeIndices($compositeIndices)
  1153.     {
  1154.         $this->compositeIndices $compositeIndices ?? [];
  1155.         return $this;
  1156.     }
  1157.     /**
  1158.      * @return bool
  1159.      */
  1160.     public function getGenerateTypeDeclarations()
  1161.     {
  1162.         return (bool) $this->generateTypeDeclarations;
  1163.     }
  1164.     /**
  1165.      * @param bool $generateTypeDeclarations
  1166.      *
  1167.      * @return $this
  1168.      */
  1169.     public function setGenerateTypeDeclarations($generateTypeDeclarations)
  1170.     {
  1171.         $this->generateTypeDeclarations = (bool) $generateTypeDeclarations;
  1172.         return $this;
  1173.     }
  1174. }