I do not want to derail #2005716: Remove entity dependency on plugins, promote EntityType to a domain object but there is something deeply disturbing in that patch that really needs these two to agree on something. Namely:
<?php
class AnnotationReader {
protected function reader() {
if (!isset($this->reader)) {
$this->reader = new DoctrineAnnotationReader();
}
return $this->reader;
}
public function setReader($reader) {
$this->reader = $reader;
}
}
?>
I know how this would look in a Crell patch:
<?php
class AnnotationReader {
protected $reader;
function __construct(ReaderInterface $reader) {
$this->reader = $reader;
}
?>
and then inject @reader into the annotationreader service in DIC.
With the DIC approach, the pluggability is consistent, it's crystal clear who sets the dependency, why does it set and where and what can you expect (nothing just the interface).
The other approach is simpler because, let's face it, most of the time you don't need to override either the dependency or the class (are you going to write a Reader or AnnotationReader that looks like Doctrine's but it's not quite??). It's equally clear that the reader() will return just the interface but I feel -- but I am just this old PHP4 curmudgeon -- that the temptation to rely on the default is much, much bigger. It's also confusing because it's not clear at all who where and why would or should call setReader if at all.