You are here

public function EdgeEntityBase::__construct in Apigee Edge 8

EdgeEntityBase constructor.

Parameters

array $values: An array of values to set, keyed by property name.

null|string $entity_type: Type of the entity.

\Apigee\Edge\Entity\EntityInterface|null $decorated: The SDK entity that this Drupal entity decorates.

Throws

\ReflectionException

Overrides EntityBase::__construct

3 calls to EdgeEntityBase::__construct()
ApiProduct::__construct in src/Entity/ApiProduct.php
ApiProduct constructor.
AttributesAwareFieldableEdgeEntityBase::__construct in src/Entity/AttributesAwareFieldableEdgeEntityBase.php
AttributesAwareFieldableEntityBase constructor.
Developer::__construct in src/Entity/Developer.php
Developer constructor.
3 methods override EdgeEntityBase::__construct()
ApiProduct::__construct in src/Entity/ApiProduct.php
ApiProduct constructor.
AttributesAwareFieldableEdgeEntityBase::__construct in src/Entity/AttributesAwareFieldableEdgeEntityBase.php
AttributesAwareFieldableEntityBase constructor.
Developer::__construct in src/Entity/Developer.php
Developer constructor.

File

src/Entity/EdgeEntityBase.php, line 52

Class

EdgeEntityBase
Base class for Apigee Edge entities in Drupal.

Namespace

Drupal\apigee_edge\Entity

Code

public function __construct(array $values, string $entity_type, ?EntityInterface $decorated = NULL) {
  parent::__construct([], $entity_type);
  if ($decorated) {
    $this->decorated = $decorated;
  }
  else {
    $rc = new \ReflectionClass($this
      ->decoratedClass());
    if (!$rc
      ->implementsInterface(EntityInterface::class)) {
      throw new InvalidArgumentException(sprintf('"%s" interface must be implemented by the decorated class.', $rc
        ->getName()));
    }

    // Get rid of useless but also problematic null values.
    // (SDK entity classes do not like them.)
    $values = array_filter($values, function ($value) {
      return !is_null($value);
    });
    $this->decorated = $rc
      ->newInstance($values);
  }
}