Plugin.php in Drupal 8
File
core/lib/Drupal/Component/Annotation/Plugin.php
View source
<?php
namespace Drupal\Component\Annotation;
use Drupal\Component\Utility\NestedArray;
class Plugin implements AnnotationInterface {
protected $definition;
public function __construct($values) {
$reflection = new \ReflectionClass($this);
$defaults = array_filter($reflection
->getDefaultProperties(), function ($value) {
return $value !== NULL;
});
$parsed_values = $this
->parse($values);
$this->definition = NestedArray::mergeDeepArray([
$defaults,
$parsed_values,
], TRUE);
}
protected function parse(array $values) {
$definitions = [];
foreach ($values as $key => $value) {
if ($value instanceof AnnotationInterface) {
$definitions[$key] = $value
->get();
}
elseif (is_array($value)) {
$definitions[$key] = $this
->parse($value);
}
else {
$definitions[$key] = $value;
}
}
return $definitions;
}
public function get() {
return $this->definition;
}
public function getProvider() {
return isset($this->definition['provider']) ? $this->definition['provider'] : FALSE;
}
public function setProvider($provider) {
$this->definition['provider'] = $provider;
}
public function getId() {
return $this->definition['id'];
}
public function getClass() {
return $this->definition['class'];
}
public function setClass($class) {
$this->definition['class'] = $class;
}
}
Classes
Name |
Description |
Plugin |
Defines a Plugin annotation object. |