Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

Commit c6e767e

Browse files
committed
initial commit
0 parents  commit c6e767e

15 files changed

Lines changed: 1044 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea/*

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Orchid-Annotation changelog
2+
3+
The latest version of this file can be found at the master branch of the
4+
Orchid-Annotation repository.
5+
6+
## 1.0.0 (2016-11-30)
7+
- First realisation

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
##### Pull Requests
2+
1. Fork the Orchid-Annotation repository
3+
2. Create a new branch for each feature or improvement
4+
3. Send a pull request
5+
6+
##### Style Guide
7+
All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2011-2018 AEngine.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Orchid Annotation
2+
====
3+
Docblock Annotations parser functional
4+
5+
#### Requirements
6+
* PHP >= 7.0
7+
8+
#### Installation
9+
Run the following command in the root directory of your web project:
10+
11+
> `composer require aengine/orchid-annotation`
12+
13+
#### Contributing
14+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
15+
16+
#### License
17+
The Orchid Framework is licensed under the MIT license. See [License File](LICENSE.md) for more information.
18+
19+
#### Description
20+
TODO

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "aengine/orchid-annotation",
3+
"description": "Annotation parser",
4+
"keywords": [
5+
"php",
6+
"framework",
7+
"AEngine",
8+
"Orchid",
9+
"PHPDoc",
10+
"DocBlock",
11+
"Parser",
12+
"Annotation"
13+
],
14+
"homepage": "https://gitlab.com/AEngine/Orchid/Annotation",
15+
"license": "MIT",
16+
"authors": [
17+
{
18+
"name": "Aleksey Ilyin",
19+
"email": "alksily@icloud.com",
20+
"homepage": "http://aengine.team/",
21+
"role": "Developer"
22+
}
23+
],
24+
"require": {
25+
"php": ">=7.0"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"AEngine\\Orchid\\Annotation\\": "src/"
30+
}
31+
}
32+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
3+
namespace AEngine\Orchid\Annotation\Annotated;
4+
5+
use AEngine\Orchid\Annotation\Annotation;
6+
use AEngine\Orchid\Annotation\AnnotationReader;
7+
use AEngine\Orchid\Annotation\Interfaces\AnnotatedInterface;
8+
use ReflectionClass;
9+
use ReflectionException;
10+
use ReflectionMethod;
11+
use ReflectionProperty;
12+
13+
class AnnotatedReflectionClass extends ReflectionClass implements AnnotatedInterface
14+
{
15+
protected $annotations;
16+
protected $methods;
17+
protected $properties;
18+
19+
/**
20+
* Return element type
21+
*
22+
* @return string
23+
*/
24+
public function getAnnotatedElementType()
25+
{
26+
if ($this->isSubClassOf(Annotation::class)) {
27+
return 'ANNOTATION';
28+
}
29+
30+
return 'CLASS';
31+
}
32+
33+
/**
34+
* Return all annotations
35+
*
36+
* @return array
37+
* @throws ReflectionException
38+
*/
39+
public function getAnnotations()
40+
{
41+
if ($this->annotations == null) {
42+
$this->annotations = AnnotationReader::parse($this);
43+
}
44+
45+
return $this->annotations;
46+
}
47+
48+
/**
49+
* Return annotation by strict name or array of annotations
50+
*
51+
* @param string $name
52+
* @param bool $strict
53+
*
54+
* @return array
55+
* @throws ReflectionException
56+
*/
57+
public function getAnnotation($name, $strict = true)
58+
{
59+
$annotations = $this->getAnnotations();
60+
61+
if ($strict) {
62+
if (isset($annotations[$name])) {
63+
return $annotations[$name];
64+
}
65+
66+
return null;
67+
}
68+
69+
foreach ($annotations as $annotation => $obj) {
70+
if (strpos($annotation, $name) === false) {
71+
unset($annotations[$annotation]);
72+
}
73+
}
74+
75+
return $annotations;
76+
}
77+
78+
/**
79+
* Check has annotations
80+
*
81+
* @param string $annotationClass
82+
*
83+
* @return bool
84+
* @throws ReflectionException
85+
*/
86+
public function hasAnnotation($annotationClass)
87+
{
88+
return !!$this->getAnnotation($annotationClass);
89+
}
90+
91+
/**
92+
* Return class methods
93+
*
94+
* @param null $filter
95+
*
96+
* @return AnnotatedReflectionMethod[]
97+
* @throws ReflectionException
98+
*/
99+
public function getMethods($filter = null)
100+
{
101+
if ($this->methods == null) {
102+
$methods = parent::getMethods();
103+
$this->methods = [];
104+
foreach ($methods as $method) {
105+
$this->methods[$method->getName()] = new AnnotatedReflectionMethod($this->getName(), $method->getName());
106+
}
107+
}
108+
109+
return $this->methods;
110+
}
111+
112+
/**
113+
* Return class method by name
114+
*
115+
* @param string $name
116+
*
117+
* @return null|ReflectionMethod
118+
* @throws ReflectionException
119+
*/
120+
public function getMethod($name)
121+
{
122+
$all = $this->getMethods();
123+
124+
return (isset($all[$name]) ? $all[$name] : null);
125+
}
126+
127+
/**
128+
* Check has method by name
129+
*
130+
* @param string $name
131+
*
132+
* @return bool
133+
* @throws ReflectionException
134+
*/
135+
public function hasMethod($name)
136+
{
137+
return $this->getMethod($name) != null;
138+
}
139+
140+
/**
141+
* Return class properties
142+
*
143+
* @param null $filter
144+
*
145+
* @return AnnotatedReflectionProperty[]
146+
* @throws ReflectionException
147+
*/
148+
public function getProperties($filter = null)
149+
{
150+
if ($this->properties == null) {
151+
$properties = parent::getProperties();
152+
$this->properties = [];
153+
foreach ($properties as $property) {
154+
$this->properties[$property->getName()] = new AnnotatedReflectionProperty($this->getName(), $property->getName());
155+
}
156+
}
157+
158+
return $this->properties;
159+
}
160+
161+
/**
162+
* Return class properties by name
163+
*
164+
* @param string $name
165+
*
166+
* @return null|ReflectionProperty
167+
* @throws ReflectionException
168+
*/
169+
public function getProperty($name)
170+
{
171+
$all = $this->getProperties();
172+
173+
return (isset($all[$name]) ? $all[$name] : null);
174+
}
175+
176+
/**
177+
* Check has property by name
178+
*
179+
* @param string $name
180+
*
181+
* @return bool
182+
* @throws ReflectionException
183+
*/
184+
public function hasProperty($name)
185+
{
186+
return $this->getProperty($name) != null;
187+
}
188+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace AEngine\Orchid\Annotation\Annotated;
4+
5+
use AEngine\Orchid\Annotation\AnnotationReader;
6+
use AEngine\Orchid\Annotation\Interfaces\AnnotatedInterface;
7+
use ReflectionException;
8+
use ReflectionMethod;
9+
10+
class AnnotatedReflectionMethod extends ReflectionMethod implements AnnotatedInterface
11+
{
12+
protected $annotations;
13+
14+
/**
15+
* Return element type
16+
*
17+
* @return string
18+
*/
19+
public function getAnnotatedElementType()
20+
{
21+
if ($this->isConstructor()) {
22+
return 'CONSTRUCTOR';
23+
}
24+
25+
return 'METHOD';
26+
}
27+
28+
/**
29+
* Return all annotations
30+
*
31+
* @return array
32+
* @throws ReflectionException
33+
*/
34+
public function getAnnotations()
35+
{
36+
if ($this->annotations == null) {
37+
$this->annotations = AnnotationReader::parse($this);
38+
}
39+
40+
return $this->annotations;
41+
}
42+
43+
/**
44+
* Return annotation by strict name or array of annotations
45+
*
46+
* @param string $name
47+
* @param bool $strict
48+
*
49+
* @return array
50+
* @throws ReflectionException
51+
*/
52+
public function getAnnotation($name, $strict = true)
53+
{
54+
$annotations = $this->getAnnotations();
55+
56+
if ($strict) {
57+
if (isset($annotations[$name])) {
58+
return $annotations[$name];
59+
}
60+
61+
return null;
62+
}
63+
64+
foreach ($annotations as $annotation => $obj) {
65+
if (strpos($annotation, $name) === false) {
66+
unset($annotations[$annotation]);
67+
}
68+
}
69+
70+
return $annotations;
71+
}
72+
73+
/**
74+
* Check has annotations
75+
*
76+
* @param string $annotationClass
77+
*
78+
* @return bool
79+
* @throws ReflectionException
80+
*/
81+
public function hasAnnotation($annotationClass)
82+
{
83+
return !!$this->getAnnotation($annotationClass);
84+
}
85+
}

0 commit comments

Comments
 (0)