-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Implementation of annotation getters for the ClassField joinpoint (#387) #388
Merged
lisachenko
merged 3 commits into
goaop:master
from
RunOpenCode:feature/annotated-class-property-access
Jan 22, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/* | ||
* Go! AOP framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\Aop\Support; | ||
|
||
use Doctrine\Common\Annotations\Reader; | ||
use Go\Core\AspectKernel; | ||
use ReflectionProperty; | ||
|
||
/** | ||
* Extended version of ReflectionProperty with annotation support | ||
*/ | ||
class AnnotatedReflectionProperty extends ReflectionProperty implements AnnotationAccess | ||
{ | ||
/** | ||
* Annotation reader | ||
* | ||
* @var Reader | ||
*/ | ||
private static $annotationReader; | ||
|
||
/** | ||
* Gets property annotation. | ||
* | ||
* @param string $annotationName The name of the annotation. | ||
* @return mixed The Annotation or NULL, if the requested annotation does not exist. | ||
*/ | ||
public function getAnnotation(string $annotationName) | ||
{ | ||
return self::getReader()->getPropertyAnnotation($this, $annotationName); | ||
} | ||
|
||
/** | ||
* Gets the annotations applied to a property. | ||
*/ | ||
public function getAnnotations(): array | ||
{ | ||
return self::getReader()->getPropertyAnnotations($this); | ||
} | ||
|
||
/** | ||
* Returns an annotation reader | ||
*/ | ||
private static function getReader(): Reader | ||
{ | ||
if (!self::$annotationReader) { | ||
self::$annotationReader = AspectKernel::getInstance()->getContainer()->get('aspect.annotation.reader'); | ||
} | ||
|
||
return self::$annotationReader; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
/* | ||
* Go! AOP framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\Aop\Support; | ||
|
||
/** | ||
* Provides access to annotations from reflection class/property/method. | ||
*/ | ||
interface AnnotationAccess | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for interface extraction refactoring |
||
{ | ||
/** | ||
* Gets annotation. | ||
* | ||
* @param string $annotationName The name of the annotation. | ||
* @return mixed The Annotation or NULL, if the requested annotation does not exist. | ||
*/ | ||
public function getAnnotation(string $annotationName); | ||
|
||
/** | ||
* Gets the annotations. | ||
*/ | ||
public function getAnnotations(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Go\Aop\Framework; | ||
|
||
use Go\Aop\Support\AnnotationAccess; | ||
|
||
class ClassFieldAccessTest extends \PHPUnit_Framework_TestCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for the test case |
||
{ | ||
/** | ||
* @var ClassFieldAccess | ||
*/ | ||
protected $classField; | ||
|
||
public function setUp() | ||
{ | ||
$this->classField = new ClassFieldAccess(__CLASS__, 'classField', []); | ||
} | ||
|
||
public function testClassFiledReturnsProperty() | ||
{ | ||
$this->assertEquals(__CLASS__, $this->classField->getField()->class); | ||
$this->assertEquals('classField', $this->classField->getField()->name); | ||
} | ||
|
||
public function testStaticPartEqualsToReflectionMethod() | ||
{ | ||
$this->assertInstanceOf('ReflectionProperty', $this->classField->getStaticPart()); | ||
} | ||
|
||
public function testProvidesAccessToAnnotations() | ||
{ | ||
$this->assertInstanceOf(AnnotationAccess::class, $this->classField->getField()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Year isn't correct :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did copy/paste of docBlock.
Different classes have different years, I checked.
To be honest - I am ok for having author and/or copyright annotation, but year in docblock does not have any particular value, we could just remove it - it poses only unnecessary maintenance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. Accepted, will do this for the master branch.