Annotation.php 960 字节
<?php

namespace Lackoxygen\ShowDocGeneration\Annotations;

abstract class Annotation
{
    public function __construct(array $values)
    {
        foreach ($this->getSelfProperties() as $property) {
            if (isset($values[$property->getName()])) {
                $this->{$property->getName()} = $values[$property->getName()];
            }
        }
    }

    /**
     * @return mixed|\ReflectionProperty[]
     */
    protected function getSelfProperties()
    {
        static $properties;

        if (is_null($properties)) {
            $ref = new \ReflectionClass($this);

            $properties = $ref->getProperties();
        }

        return $properties;
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        $array = [];
        foreach ($this->getSelfProperties() as $property) {
            $array[$property->getName()] = $this->{$property->getName()};
        }
        return $array;
    }
}