-
Notifications
You must be signed in to change notification settings - Fork 300
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
Refactoring/listener #21
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e8bbb3b
Add an abstract listener which provides reflection validations
PedroTroller 7933133
Refactor all listeners
PedroTroller 1f132b4
Merge master
PedroTroller 91f7baf
Refactor abstract listener methods returns
PedroTroller dc8d0ea
Add a method to test the removal of the object in the future
PedroTroller a05fcd4
Merge
PedroTroller 3091174
Add the ClassAnalizer listener injection, refactor listeners
PedroTroller 426fcae
Merge master
PedroTroller 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the KnpDoctrineBehaviors package. | ||
* | ||
* (c) KnpLabs <http://knplabs.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Knp\DoctrineBehaviors\ORM; | ||
|
||
use Doctrine\Common\EventSubscriber; | ||
|
||
abstract class AbstractListener implements EventSubscriber | ||
{ | ||
|
||
abstract public function getSubscribedEvents(); | ||
|
||
/** | ||
* Return TRUE if the given entity use the given trait, FALSE if not | ||
* @param ReflectionClass $class | ||
* @param string $traitName | ||
* @param boolean $isRecursive | ||
*/ | ||
protected function isEntityUseTrait(\ReflectionClass $class, $traitName, $isRecursive = false) | ||
{ | ||
if (in_array($traitName, $class->getTraitNames())) { | ||
return true; | ||
} | ||
|
||
$parentClass = $class->getParentClass(); | ||
|
||
if ((false === $isRecursive) || (false === $parentClass)) { | ||
return false; | ||
} | ||
|
||
return $this->isEntityUseTrait($parentClass, $traitName, $isRecursive); | ||
} | ||
|
||
/** | ||
* Return TRUE if the given entity has the given method, FALSE if not | ||
* @param ReflectionClass $class | ||
* @param string $methodName | ||
*/ | ||
protected function isEntityHasMethod(\ReflectionClass $class, $methodName) | ||
{ | ||
return $class->hasMethod($methodName); | ||
} | ||
|
||
/** | ||
* Return TRUE if the given entity has the given property, FALSE if not | ||
* @param ReflectionClass $class | ||
* @param string $propertyName | ||
*/ | ||
protected function isEntityHasProperty(\ReflectionClass $class, $propertyName, $isRecursive = false) | ||
{ | ||
if ($class->hasProperty($propertyName)) { | ||
return true; | ||
} | ||
|
||
$parentClass = $class->getParentClass(); | ||
|
||
if ((false === $isRecursive) || (false === $parentClass)) { | ||
return false; | ||
} | ||
|
||
return $this->isEntityHasProperty($parentClass, $propertyName, $isRecursive); | ||
} | ||
} |
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
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
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
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.
isEntityUsingTrait
makes more sense, doesn't it?Anyway, isn't the goal of this PR to abstract wether this listener applies on Document or Entity?
In this case, this method could be called
isObjectUsingTrait
Last thing, as I believe these 3 methods will be usefull in many other places, you might want to move it to its own class and inject it in the listener (something like
Knp\DoctrineBehaviors\Reflection\ClassAnalyzer
)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.
Hmmmm ok....
About the method name, the goal of DoctrineBehaviors is to add features to Doctrine Entities. Is that a real problem if methods names talk about entities.
The class Analyser is a good idea.