Skip to content

Commit 56df8f3

Browse files
committed
+ Add @ignored annotation #14
+ hedron dev dep
1 parent 88402de commit 56df8f3

7 files changed

Lines changed: 183 additions & 5 deletions

File tree

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.php text eol=lf
2+
*.phps text eol=lf
3+
*.md text eol=lf
4+
*.html text eol=lf

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"monolog/monolog" : "Sends your logs to files, sockets, inboxes, databases and various web services"
2222
},
2323
"require-dev": {
24-
"maslosoft/addendumtest": "dev-master"
24+
"maslosoft/addendumtest": "dev-master",
25+
"maslosoft/hedron": "*"
2526
},
2627
"require": {
2728
"php": ">=5.5.0",

composer.lock

Lines changed: 92 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
namespace Maslosoft\Addendum\Annotations;
10+
11+
use Maslosoft\Addendum\Annotation;
12+
13+
/**
14+
* Use this annotation to completely ignore method or property metadata.
15+
* This should be used on components. This can also be used to explicitly mark that entity should be **not** ignored.
16+
* Examples:
17+
* &commat;Ignore() - Ignore field or method
18+
* &commat;Ignore(false) - Explicitly mark method or property as not ignored
19+
* @Target('property', 'method')
20+
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
21+
*/
22+
class IgnoredAnnotation extends Annotation
23+
{
24+
25+
public $value = true;
26+
27+
public function init()
28+
{
29+
30+
}
31+
32+
}

src/Annotations/TargetAnnotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function getTargets()
5757

5858
public function init()
5959
{
60-
60+
6161
}
6262

6363
}

src/Collections/Meta.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedClass;
1111
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
1212
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
13+
use Maslosoft\Addendum\Utilities\IgnoredChecker;
1314
use ReflectionMethod;
1415
use ReflectionProperty;
1516

@@ -118,7 +119,10 @@ protected function __construct(IAnnotated $component = null, MetaOptions $option
118119
{
119120
throw new Exception(sprintf('Could not annotate `%s::%s()`', get_class($component), $method->name));
120121
}
121-
122+
if(IgnoredChecker::check($method))
123+
{
124+
continue;
125+
}
122126
$methodMeta = new $options->methodClass($method);
123127
foreach ($method->getAllAnnotations() as $annotation)
124128
{
@@ -152,7 +156,11 @@ protected function __construct(IAnnotated $component = null, MetaOptions $option
152156
{
153157
throw new Exception(sprintf('Could not annotate `%s::%s`', get_class($component), $property->name));
154158
}
155-
159+
160+
if(IgnoredChecker::check($property))
161+
{
162+
continue;
163+
}
156164
$name = $property->name;
157165
/* @var $property ReflectionAnnotatedProperty */
158166
$field = new $options->propertyClass($property);

src/Utilities/IgnoredChecker.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
namespace Maslosoft\Addendum\Utilities;
10+
11+
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
12+
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
13+
14+
/**
15+
* IgnoredChecker
16+
*
17+
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
18+
*/
19+
class IgnoredChecker
20+
{
21+
22+
/**
23+
* Check if entity is ignored
24+
* @param ReflectionAnnotatedMethod|ReflectionAnnotatedProperty $target
25+
* @return bool
26+
*/
27+
public static function check($target)
28+
{
29+
if (!$target->hasAnnotation('Ignored'))
30+
{
31+
return false;
32+
}
33+
34+
$value = $target->getAnnotation('Ignored')->value;
35+
if (false === $value)
36+
{
37+
return false;
38+
}
39+
return true;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)