From bb24b576e090d360ae7a7b2f5acf121ac332bbe0 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 19 Feb 2023 08:42:53 +0200 Subject: [PATCH] cs --- application/Espo/ORM/BaseEntity.php | 157 ++++++++++++++-------------- 1 file changed, 76 insertions(+), 81 deletions(-) diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 806057194c..048a397fd4 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -32,21 +32,15 @@ namespace Espo\ORM; use Espo\ORM\Value\ValueAccessorFactory; use Espo\ORM\Value\ValueAccessor; -use const E_USER_DEPRECATED; - use stdClass; use InvalidArgumentException; use RuntimeException; +use JsonException; + +use const E_USER_DEPRECATED; class BaseEntity implements Entity { - /** - * @deprecated As of v7.0. Use `getId`. To be changed to protected. - * @todo Change to protected in v8.0. - * @var ?string - */ - public $id = null; - /** @var string */ protected $entityType; @@ -55,6 +49,16 @@ class BaseEntity implements Entity private bool $isFetched = false; private bool $isBeingSaved = false; + protected ?EntityManager $entityManager; + private ?ValueAccessor $valueAccessor = null; + + /** @var array */ + private array $writtenMap = []; + /** @var array> */ + private array $attributes = []; + /** @var array */ + private array $fetchedValuesContainer = []; + /** * @todo Make private, rename to `attributes` in v8.0. . * @deprecated As of v6.0. Use getAttributeList, getAttributeParam, ORM\Defs. @@ -62,11 +66,6 @@ class BaseEntity implements Entity */ public array $fields = []; - /** - * @var array> - */ - private array $attributes = []; - /** * @todo Make private in v8.0. * @deprecated As of v6.0. Use getRelationList, getRelationParam, ORM\Defs. @@ -75,28 +74,19 @@ class BaseEntity implements Entity protected array $relations = []; /** - * An attribute-value map. - * * @deprecated As of v7.0. `setInContainer`, `hasInContainer`, `getFromContainer`. * @todo Make private in v8.0. * @var array */ protected array $valuesContainer = []; + /** - * An attribute-value map of values fetched from DB (before changed). - * - * @deprecated As of v7.0. `getFromFetchedContainer`, `hasInFetchedContainer`. - * @todo Make private. - * @var array + * @deprecated As of v7.0. Use `getId`. To be changed to protected. + * @todo Change to protected in v8.0. + * @var ?string */ - private array $fetchedValuesContainer = []; - - protected ?EntityManager $entityManager; - private ?ValueAccessor $valueAccessor = null; - - /** @var array */ - private array $writtenMap = []; + public $id = null; /** * @param array{ @@ -112,7 +102,6 @@ class BaseEntity implements Entity ?ValueAccessorFactory $valueAccessorFactory = null ) { $this->entityType = $entityType; - $this->entityManager = $entityManager; $this->attributes = $defs['attributes'] ?? $defs['fields'] ?? $this->attributes; @@ -164,16 +153,7 @@ class BaseEntity implements Entity $this->valuesContainer = []; } - /** - * @deprecated As of v7.0. Use `setInContainer` method. - * - * @param string $attribute - * @param mixed $value - */ - protected function setValue($attribute, $value): void - { - $this->setInContainer($attribute, $value); - } + /** * Set an attribute value or multiple attribute values. @@ -182,7 +162,7 @@ class BaseEntity implements Entity * * `set(string $attribute, mixed $value)` * * `set(array|object $valueMap)` * - * @param string|stdClass|array $attribute + * @param string|stdClass|array $attribute * @param mixed $value */ public function set($attribute, $value = null): void @@ -439,37 +419,7 @@ class BaseEntity implements Entity $this->valueAccessor->set($field, $value); } - /** - * @deprecated As of v7.0. Use set instead. - * @todo Make protected. - * @param array $data - */ - public function populateFromArray(array $data, bool $onlyAccessible = true, bool $reset = false): void - { - if ($reset) { - $this->reset(); - } - foreach ($this->getAttributeList() as $attribute) { - if (!array_key_exists($attribute, $data)) { - continue; - } - - if ($attribute == 'id') { - $this->id = $data[$attribute]; - - continue; - } - - if ($onlyAccessible && $this->getAttributeParam($attribute, 'notAccessible')) { - continue; - } - - $value = $data[$attribute]; - - $this->populateFromArrayItem($attribute, $value); - } - } /** * @param mixed $value @@ -494,7 +444,7 @@ class BaseEntity implements Entity /** * @param mixed $value * @return mixed - * @throws \JsonException + * @throws JsonException */ protected function prepareAttributeValue(string $attribute, $value) { @@ -535,7 +485,7 @@ class BaseEntity implements Entity } /** - * @param MIXED $value + * @param mixed $value * @return mixed[]|null */ private function prepareArrayAttributeValue($value): ?array @@ -559,7 +509,7 @@ class BaseEntity implements Entity /** * @param mixed $value - * @throws \JsonException + * @throws JsonException */ private function prepareObjectAttributeValue($value): ?stdClass { @@ -1085,14 +1035,7 @@ class BaseEntity implements Entity } } - /** - * @deprecated As of v6.0. Access `entityManager` property. - */ - protected function getEntityManager(): EntityManager - { - /** @var EntityManager */ - return $this->entityManager; - } + /** * Clone an array value. @@ -1180,4 +1123,56 @@ class BaseEntity implements Entity return $copy; } + + /** + * @deprecated As of v7.0. Use `set` method instead. + * @todo Make protected. + * @param array $data + */ + public function populateFromArray(array $data, bool $onlyAccessible = true, bool $reset = false): void + { + if ($reset) { + $this->reset(); + } + + foreach ($this->getAttributeList() as $attribute) { + if (!array_key_exists($attribute, $data)) { + continue; + } + + if ($attribute == 'id') { + $this->id = $data[$attribute]; + + continue; + } + + if ($onlyAccessible && $this->getAttributeParam($attribute, 'notAccessible')) { + continue; + } + + $value = $data[$attribute]; + + $this->populateFromArrayItem($attribute, $value); + } + } + + /** + * @deprecated As of v7.0. Use `setInContainer` method. + * + * @param string $attribute + * @param mixed $value + */ + protected function setValue($attribute, $value): void + { + $this->setInContainer($attribute, $value); + } + + /** + * @deprecated As of v6.0. Access `entityManager` property. + */ + protected function getEntityManager(): EntityManager + { + /** @var EntityManager */ + return $this->entityManager; + } }