/**
* @param array $properties
*/
public function __construct($properties)
{
if (isset($properties['_context'])) {
$this->_context = $properties['_context'];
unset($properties['_context']);
} elseif (Analyser::$context) {
$this->_context = Analyser::$context;
} else {
$this->_context = Context::detect(1);
}
if ($this->_context->is('annotations') === false) {
$this->_context->annotations = [];
}
$this->_context->annotations[] = $this;
$nestedContext = new Context(['nested' => $this], $this->_context);
foreach ($properties as $property => $value) {
if (property_exists($this, $property)) {
$this->{$property} = $value;
if (is_array($value)) {
foreach ($value as $key => $annotation) {
if (is_object($annotation) && $annotation instanceof AbstractAnnotation) {
$this->{$property}[$key] = $this->nested($annotation, $nestedContext);
}
}
}
} elseif ($property !== 'value') {
$this->{$property} = $value;
} elseif (is_array($value)) {
$annotations = [];
foreach ($value as $annotation) {
if (is_object($annotation) && $annotation instanceof AbstractAnnotation) {
$annotations[] = $annotation;
} else {
Logger::notice('Unexpected field in ' . $this->identity() . ' in ' . $this->_context);
}
}
$this->merge($annotations);
} elseif (is_object($value)) {
$this->merge([$value]);
} else {
Logger::notice('Unexpected parameter in ' . $this->identity());
}
}
}