-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from w3c/inverse
Allow monitoring inverse side of relationships
- Loading branch information
Showing
16 changed files
with
2,220 additions
and
121 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ class Update | |
* @var bool | ||
*/ | ||
public $monitor_collections = true; | ||
|
||
public $monitor_owning = false; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace W3C\LifecycleEventsBundle\Services; | ||
|
||
use Doctrine\Common\Annotations\Reader; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
|
||
/** | ||
* Convenient class to get lifecycle annotations more easily | ||
* | ||
* @author Jean-Guilhem Rouel <jean-gui@w3.org> | ||
*/ | ||
class AnnotationGetter | ||
{ | ||
/** | ||
* @var Reader | ||
*/ | ||
private $reader; | ||
|
||
public function __construct(Reader $reader) | ||
{ | ||
$this->reader = $reader; | ||
} | ||
|
||
/** | ||
* Get a class-level annotation | ||
* | ||
* @param string $class Class to get annotation of | ||
* @param string $annotationClass Class of the annotation to get | ||
* | ||
* @return object|null object of same class as $annotationClass or null if no annotation is found | ||
*/ | ||
public function getAnnotation($class, $annotationClass) | ||
{ | ||
$annotation = $this->reader->getClassAnnotation( | ||
new \ReflectionClass($class), | ||
$annotationClass | ||
); | ||
return $annotation; | ||
} | ||
|
||
/** | ||
* Get a field-level annotation | ||
* | ||
* @param ClassMetadata $classMetadata Metadata of the class to get annotation of | ||
* @param string $field Name of the field to get annotation of | ||
* @param string $annotationClass Class of the annotation to get | ||
* | ||
* @return object|null object of same class as $annotationClass or null if no annotation is found | ||
* @throws \ReflectionException if the field does not exist | ||
*/ | ||
public function getPropertyAnnotation(ClassMetadata $classMetadata, $field, $annotationClass) | ||
{ | ||
$reflProperty = $classMetadata->getReflectionProperty($field); | ||
|
||
if ($reflProperty) { | ||
return $this->reader->getPropertyAnnotation($reflProperty, $annotationClass); | ||
} | ||
|
||
throw new \ReflectionException( | ||
$classMetadata->getName() . '.' . $field . ' not found. Could this be a private field of a parent class?' | ||
); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace W3C\LifecycleEventsBundle\Tests\Annotation\Fixtures; | ||
|
||
use W3C\LifecycleEventsBundle\Annotation as On; | ||
|
||
/** | ||
* @On\Update(monitor_owning=true) | ||
* | ||
* @author Jean-Guilhem Rouel <jean-gui@w3.org> | ||
*/ | ||
class Person | ||
{ | ||
public $name; | ||
|
||
/** | ||
* @ ORM\ManyToMany(targetEntity="Person", inversedBy="friendOf") | ||
*/ | ||
public $friends; | ||
|
||
/** | ||
* @ ORM\ManyToMany(targetEntity="Person", mappedBy="friends") | ||
* @On\Change(monitor_owning=true) | ||
*/ | ||
public $friendOf; | ||
|
||
/** | ||
* @ ORM\ManyToOne(targetEntity="Person", inversedBy="sons") | ||
*/ | ||
public $father; | ||
|
||
/** | ||
* @ ORM\OneToMany(targetEntity="Person", mappedBy="father") | ||
* @On\Change(monitor_owning=true) | ||
*/ | ||
public $sons; | ||
|
||
/** | ||
* @ ORM\OneToOne(targetEntity="Person", inversedBy="mentoring") | ||
*/ | ||
public $mentor; | ||
|
||
/** | ||
* @ ORM\OneToOne(targetEntity="Person", mappedBy="mentor") | ||
* @On\Change(monitor_owning=true) | ||
*/ | ||
public $mentoring; | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace W3C\LifecycleEventsBundle\Tests\Annotation\Fixtures; | ||
|
||
use W3C\LifecycleEventsBundle\Annotation as On; | ||
|
||
/** | ||
* @On\Update() | ||
* | ||
* @author Jean-Guilhem Rouel <jean-gui@w3.org> | ||
*/ | ||
class PersonNoMonitor | ||
{ | ||
public $name; | ||
|
||
/** | ||
* @ ORM\ManyToMany(targetEntity="Person", inversedBy="friendOf") | ||
*/ | ||
public $friends; | ||
|
||
/** | ||
* @ ORM\ManyToMany(targetEntity="Person", mappedBy="friends") | ||
*/ | ||
public $friendOf; | ||
|
||
/** | ||
* @ ORM\ManyToOne(targetEntity="Person", inversedBy="sons") | ||
* @On\Change() | ||
*/ | ||
public $father; | ||
|
||
/** | ||
* @ ORM\OneToMany(targetEntity="Person", mappedBy="father") | ||
*/ | ||
public $sons; | ||
|
||
/** | ||
* @ ORM\OneToOne(targetEntity="Person", inversedBy="mentoring") | ||
*/ | ||
public $mentor; | ||
|
||
/** | ||
* @ ORM\OneToOne(targetEntity="Person", mappedBy="mentor") | ||
*/ | ||
public $mentoring; | ||
} |
Oops, something went wrong.