-
Notifications
You must be signed in to change notification settings - Fork 13
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 #26 from foaly-nr1/patch-cacheable
Cache metadata
- Loading branch information
Showing
6 changed files
with
128 additions
and
76 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Snowcap\ImBundle\Doctrine\Driver; | ||
|
||
use Metadata\Driver\DriverInterface; | ||
use Metadata\MergeableClassMetadata; | ||
use Doctrine\Common\Annotations\Reader; | ||
use Snowcap\ImBundle\Doctrine\Metadata\MogrifyMetadata; | ||
|
||
class MogrifyDriver implements DriverInterface | ||
{ | ||
const MOGRIFY = 'Snowcap\ImBundle\Doctrine\Mapping\Mogrify'; | ||
|
||
private $reader; | ||
|
||
public function __construct(Reader $reader) | ||
{ | ||
$this->reader = $reader; | ||
} | ||
|
||
public function loadMetadataForClass(\ReflectionClass $class) | ||
{ | ||
$classMetadata = new MergeableClassMetadata($class->getName()); | ||
|
||
foreach ($class->getProperties() as $property) { | ||
$field = $this->reader->getPropertyAnnotation($property, self::MOGRIFY); | ||
|
||
if(!is_null($field)) { | ||
$propertyMetadata = new MogrifyMetadata($class->getName(), $property->getName()); | ||
$propertyMetadata->params = $field->params; | ||
|
||
$classMetadata->addPropertyMetadata($propertyMetadata); | ||
} | ||
} | ||
|
||
return $classMetadata; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Snowcap\ImBundle\Doctrine\Metadata; | ||
|
||
use Metadata\PropertyMetadata as BasePropertyMetadata; | ||
|
||
class MogrifyMetadata extends BasePropertyMetadata | ||
{ | ||
/** | ||
* @var string|array<string> | ||
*/ | ||
public $params; | ||
|
||
public function serialize() | ||
{ | ||
return serialize(array( | ||
$this->class, | ||
$this->name, | ||
$this->params, | ||
)); | ||
} | ||
|
||
public function unserialize($str) | ||
{ | ||
list($this->class, $this->name, $this->params) = unserialize($str); | ||
|
||
$this->reflection = new \ReflectionProperty($this->class, $this->name); | ||
$this->reflection->setAccessible(true); | ||
} | ||
} |
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