You are here

public function AnnotationObject::__construct in Markdown 8.2

AnnotationObject constructor.

Parameters

array $values: Optional. The initial values to populate the annotation with.

1 call to AnnotationObject::__construct()
InstallableLibrary::__construct in src/Annotation/InstallableLibrary.php
AnnotationObject constructor.
1 method overrides AnnotationObject::__construct()
InstallableLibrary::__construct in src/Annotation/InstallableLibrary.php
AnnotationObject constructor.

File

src/Annotation/AnnotationObject.php, line 80

Class

AnnotationObject
Base annotation class for retrieving the annotation as an object.

Namespace

Drupal\markdown\Annotation

Code

public function __construct(array $values = []) {
  $this
    ->validateIdentifier(Identifier::createFromArray($values));

  // Look for deprecated properties so notices can be trigger when accessing
  // them using \ArrayAccess.
  foreach (array_keys(get_object_vars($this)) as $name) {
    try {
      $ref = new \ReflectionProperty($this, $name);

      // Skip non-public properties.
      if (!$ref
        ->isPublic()) {
        continue;
      }

      // Handle deprecated properties.
      if (($doc = $ref
        ->getDocComment()) && preg_match(static::DEPRECATED_REGEX, $doc, $matches)) {
        $deprecation = array_filter(array_map(function ($line) {
          return preg_replace('/^\\s*\\*?\\s*/', '', $line);
        }, explode("\n", $matches[1])));
        array_unshift($deprecation, static::class . "::\${$name} is deprecated");
        if (!empty($matches[2])) {
          $deprecation[] = 'See ' . $matches[2];
        }
        $this->_deprecatedProperties[$name] = implode(' ', $deprecation);

        // Now, remove the property from the class so it uses magic methods.
        // This allows deprecated properties accessed using object notation
        // (i.e. $definition->deprecatedProperty) to trigger notices.
        unset($this->{$name});
      }
    } catch (\ReflectionException $e) {

      // Intentionally do nothing.
    }
  }

  // Now actually set the annotation values.
  // Note: this will trigger deprecations notices for definitions still using
  // deprecated properties.
  $this
    ->doMerge($values);
}