xref: /dokuwiki/inc/Remote/OpenApiDoc/DocBlockClass.php (revision 8ddd9b69189e5c591f86c9f4314a06ec13778622)
1*8ddd9b69SAndreas Gohr<?php
2*8ddd9b69SAndreas Gohr
3*8ddd9b69SAndreas Gohrnamespace dokuwiki\Remote\OpenApiDoc;
4*8ddd9b69SAndreas Gohr
5*8ddd9b69SAndreas Gohruse ReflectionClass;
6*8ddd9b69SAndreas Gohr
7*8ddd9b69SAndreas Gohrclass DocBlockClass extends DocBlock
8*8ddd9b69SAndreas Gohr{
9*8ddd9b69SAndreas Gohr    /** @var DocBlockMethod[] */
10*8ddd9b69SAndreas Gohr    protected $methods = [];
11*8ddd9b69SAndreas Gohr
12*8ddd9b69SAndreas Gohr    /** @var DocBlockProperty[] */
13*8ddd9b69SAndreas Gohr    protected $properties = [];
14*8ddd9b69SAndreas Gohr
15*8ddd9b69SAndreas Gohr    /**
16*8ddd9b69SAndreas Gohr     * Parse the given docblock
17*8ddd9b69SAndreas Gohr     *
18*8ddd9b69SAndreas Gohr     * The docblock can be of a method, class or property.
19*8ddd9b69SAndreas Gohr     *
20*8ddd9b69SAndreas Gohr     * @param ReflectionClass $reflector
21*8ddd9b69SAndreas Gohr     */
22*8ddd9b69SAndreas Gohr    public function __construct(ReflectionClass $reflector)
23*8ddd9b69SAndreas Gohr    {
24*8ddd9b69SAndreas Gohr        parent::__construct($reflector);
25*8ddd9b69SAndreas Gohr    }
26*8ddd9b69SAndreas Gohr
27*8ddd9b69SAndreas Gohr    /** @inheritdoc */
28*8ddd9b69SAndreas Gohr    protected function getContext()
29*8ddd9b69SAndreas Gohr    {
30*8ddd9b69SAndreas Gohr        return $this->reflector->getName();
31*8ddd9b69SAndreas Gohr    }
32*8ddd9b69SAndreas Gohr
33*8ddd9b69SAndreas Gohr    /**
34*8ddd9b69SAndreas Gohr     * Get the public methods of this class
35*8ddd9b69SAndreas Gohr     *
36*8ddd9b69SAndreas Gohr     * @return DocBlockMethod[]
37*8ddd9b69SAndreas Gohr     */
38*8ddd9b69SAndreas Gohr    public function getMethodDocs()
39*8ddd9b69SAndreas Gohr    {
40*8ddd9b69SAndreas Gohr        if ($this->methods) return $this->methods;
41*8ddd9b69SAndreas Gohr
42*8ddd9b69SAndreas Gohr        foreach ($this->reflector->getMethods() as $method) {
43*8ddd9b69SAndreas Gohr            /** @var \ReflectionMethod $method */
44*8ddd9b69SAndreas Gohr            if ($method->isConstructor()) continue;
45*8ddd9b69SAndreas Gohr            if ($method->isDestructor()) continue;
46*8ddd9b69SAndreas Gohr            if (!$method->isPublic()) continue;
47*8ddd9b69SAndreas Gohr            $this->methods[$method->getName()] = new DocBlockMethod($method);
48*8ddd9b69SAndreas Gohr        }
49*8ddd9b69SAndreas Gohr
50*8ddd9b69SAndreas Gohr        return $this->methods;
51*8ddd9b69SAndreas Gohr    }
52*8ddd9b69SAndreas Gohr
53*8ddd9b69SAndreas Gohr    /**
54*8ddd9b69SAndreas Gohr     * Get the public properties of this class
55*8ddd9b69SAndreas Gohr     *
56*8ddd9b69SAndreas Gohr     * @return DocBlockProperty[]
57*8ddd9b69SAndreas Gohr     */
58*8ddd9b69SAndreas Gohr    public function getPropertyDocs()
59*8ddd9b69SAndreas Gohr    {
60*8ddd9b69SAndreas Gohr        if ($this->properties) return $this->properties;
61*8ddd9b69SAndreas Gohr
62*8ddd9b69SAndreas Gohr        foreach ($this->reflector->getProperties() as $property) {
63*8ddd9b69SAndreas Gohr            /** @var \ReflectionProperty $property */
64*8ddd9b69SAndreas Gohr            if (!$property->isPublic()) continue;
65*8ddd9b69SAndreas Gohr            $this->properties[$property->getName()] = new DocBlockProperty($property);
66*8ddd9b69SAndreas Gohr        }
67*8ddd9b69SAndreas Gohr
68*8ddd9b69SAndreas Gohr        return $this->properties;
69*8ddd9b69SAndreas Gohr    }
70*8ddd9b69SAndreas Gohr
71*8ddd9b69SAndreas Gohr}
72