Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<?php
/**
* Contains all annotations for extensions
* NOTE: should be included with require_once
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
foreach (glob(__DIR__ . "/*.php") as $filename) {
if (basename($filename, '.php') === 'All') {
continue;
}
include_once $filename;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Blameable annotation for Blameable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author David Buchmann <mail@davidbu.ch>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Blameable extends Annotation
{
/** @var string */
public $on = 'update';
/** @var string|array */
public $field;
/** @var mixed */
public $value;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* IpTraceable annotation for IpTraceable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Pierre-Charles Bertineau <pc.bertineau@alterphp.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class IpTraceable extends Annotation
{
/** @var string */
public $on = 'update';
/** @var string|array */
public $field;
/** @var mixed */
public $value;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Language annotation for Translatable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Language extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Locale annotation for Translatable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Locale extends Annotation
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Loggable annotation for Loggable behavioral extension
*
* @Annotation
* @Target("CLASS")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Loggable extends Annotation
{
/** @var string */
public $logEntryClass;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Reference annotation for ORM -> ODM references extension
* to be user like "@ReferenceMany(type="entity", class="MyEntity", identifier="entity_id")"
*
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @Annotation
*/
abstract class Reference extends Annotation
{
public $type;
public $class;
public $identifier;
public $mappedBy;
public $inversedBy;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* ReferenceIntegrity annotation for ReferenceIntegrity behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Evert Harmeling <evert.harmeling@freshheads.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class ReferenceIntegrity extends Annotation
{
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Gedmo\Mapping\Annotation;
/**
* Reference annotation for ORM -> ODM references extension
* to be user like "@ReferenceMany(type="entity", class="MyEntity", identifier="entity_id")"
*
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @Annotation
*/
class ReferenceMany extends Reference
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Gedmo\Mapping\Annotation;
/**
* @Annotation
*/
class ReferenceManyEmbed extends Reference
{
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Gedmo\Mapping\Annotation;
/**
* Reference annotation for ORM -> ODM references extension
* to be user like "@ReferenceOne(type="entity", class="MyEntity", identifier="entity_id")"
*
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @Annotation
*/
class ReferenceOne extends Reference
{
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Slug annotation for Sluggable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Slug extends Annotation
{
/** @var array<string> @Required */
public $fields = array();
/** @var boolean */
public $updatable = true;
/** @var string */
public $style = 'default'; // or "camel"
/** @var boolean */
public $unique = true;
/** @var string */
public $unique_base = null;
/** @var string */
public $separator = '-';
/** @var string */
public $prefix = '';
/** @var string */
public $suffix = '';
/** @var array<Gedmo\Mapping\Annotation\SlugHandler> */
public $handlers = array();
/** @var string */
public $dateFormat = 'Y-m-d-H:i';
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* SlugHandler annotation for Sluggable behavioral extension
*
* @Annotation
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class SlugHandler extends Annotation
{
public $class = '';
public $options = array();
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* SlugHandlerOption annotation for Sluggable behavioral extension
*
* @Annotation
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class SlugHandlerOption extends Annotation
{
public $name;
public $value;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Group annotation for SoftDeleteable extension
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* @Annotation
* @Target("CLASS")
*/
final class SoftDeleteable extends Annotation
{
/** @var string */
public $fieldName = 'deletedAt';
/** @var bool */
public $timeAware = false;
/** @var bool */
public $hardDelete = true;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Group annotation for Sortable extension
*
* @author Lukas Botsch <lukas.botsch@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* @Annotation
* @Target("PROPERTY")
*/
final class SortableGroup extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Position annotation for Sortable extension
*
* @author Lukas Botsch <lukas.botsch@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* @Annotation
* @Target("PROPERTY")
*/
final class SortablePosition extends Annotation
{
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Timestampable annotation for Timestampable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Timestampable extends Annotation
{
/** @var string */
public $on = 'update';
/** @var string|array */
public $field;
/** @var mixed */
public $value;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Translatable annotation for Translatable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Translatable extends Annotation
{
/** @var boolean */
public $fallback;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TranslationEntity annotation for Translatable behavioral extension
*
* @Annotation
* @Target("CLASS")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TranslationEntity extends Annotation
{
/** @var string @Required */
public $class;
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Tree annotation for Tree behavioral extension
*
* @Annotation
* @Target("CLASS")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Tree extends Annotation
{
/** @var string */
public $type = 'nested';
/** @var string */
public $activateLocking = false;
/** @var integer */
public $lockingTimeout = 3;
/** @var string $identifierMethod */
public $identifierMethod;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeClosure annotation for Tree behavioral extension
*
* @Annotation
* @Target("CLASS")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeClosure extends Annotation
{
/** @var string @Required */
public $class;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeLeft annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeLeft extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeLevel annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeLevel extends Annotation
{
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeLockTime annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeLockTime extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeParent annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeParent extends Annotation
{
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreePath annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @author <rocco@roccosportal.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreePath extends Annotation
{
public $separator = ',';
public $appendId = null;
public $startsWithSeparator = false;
public $endsWithSeparator = true;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreePath annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author <rocco@roccosportal.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreePathHash extends Annotation
{
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreePath annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreePathSource extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeRight annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeRight extends Annotation
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* TreeRoot annotation for Tree behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class TreeRoot extends Annotation
{
/** @var string $identifierMethod */
public $identifierMethod;
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
use Gedmo\Uploadable\Mapping\Validator;
/**
* Uploadable annotation for Uploadable behavioral extension
*
* @Annotation
* @Target("CLASS")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Uploadable extends Annotation
{
/** @var boolean */
public $allowOverwrite = false;
/** @var boolean */
public $appendNumber = false;
/** @var string */
public $path = '';
/** @var string */
public $pathMethod = '';
/** @var string */
public $callback = '';
/** @var string */
public $filenameGenerator = Validator::FILENAME_GENERATOR_NONE;
/** @var double */
public $maxSize = 0;
/** @var array */
public $allowedTypes = '';
/** @var array */
public $disallowedTypes = '';
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* UploadableFileMimeType Annotation for Uploadable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class UploadableFileMimeType extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* UploadableFileName Annotation for Uploadable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author tiger-seo <tiger.seo@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class UploadableFileName extends Annotation
{
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* UploadableFilePath Annotation for Uploadable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class UploadableFilePath extends Annotation
{
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* UploadableFileSize Annotation for Uploadable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class UploadableFileSize extends Annotation
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Gedmo\Mapping\Annotation;
use Doctrine\Common\Annotations\Annotation;
/**
* Versioned annotation for Loggable behavioral extension
*
* @Annotation
* @Target("PROPERTY")
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class Versioned extends Annotation
{
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Gedmo\Mapping;
/**
* The mapping driver abstract class, defines the
* metadata extraction function common among
* all drivers used on these extensions.
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
interface Driver
{
/**
* Read extended metadata configuration for
* a single mapped class
*
* @param object $meta
* @param array $config
*
* @return void
*/
public function readExtendedMetadata($meta, array &$config);
/**
* Passes in the original driver
*
* @param object $driver
*
* @return void
*/
public function setOriginalDriver($driver);
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Gedmo\Mapping\Driver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
/**
* This is an abstract class to implement common functionality
* for extension annotation mapping drivers.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
abstract class AbstractAnnotationDriver implements AnnotationDriverInterface
{
/**
* Annotation reader instance
*
* @var object
*/
protected $reader;
/**
* Original driver if it is available
*/
protected $_originalDriver = null;
/**
* List of types which are valid for extension
*
* @var array
*/
protected $validTypes = array();
/**
* {@inheritDoc}
*/
public function setAnnotationReader($reader)
{
$this->reader = $reader;
}
/**
* Passes in the mapping read by original driver
*
* @param object $driver
*/
public function setOriginalDriver($driver)
{
$this->_originalDriver = $driver;
}
/**
* @param object $meta
*
* @return \ReflectionClass
*/
public function getMetaReflectionClass($meta)
{
$class = $meta->getReflectionClass();
if (!$class) {
// based on recent doctrine 2.3.0-DEV maybe will be fixed in some way
// this happens when running annotation driver in combination with
// static reflection services. This is not the nicest fix
$class = new \ReflectionClass($meta->name);
}
return $class;
}
/**
* Checks if $field type is valid
*
* @param object $meta
* @param string $field
*
* @return boolean
*/
protected function isValidField($meta, $field)
{
$mapping = $meta->getFieldMapping($field);
return $mapping && in_array($mapping['type'], $this->validTypes);
}
/**
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
* @param array $config
*/
public function validateFullMetadata(ClassMetadata $meta, array $config)
{
}
/**
* Try to find out related class name out of mapping
*
* @param ClassMetadata $metadata - the mapped class metadata
* @param $name - the related object class name
* @return string - related class name or empty string if does not exist
*/
protected function getRelatedClassName($metadata, $name)
{
if (class_exists($name) || interface_exists($name)) {
return $name;
}
$refl = $metadata->getReflectionClass();
$ns = $refl->getNamespaceName();
$className = $ns . '\\' . $name;
return class_exists($className) ? $className : '';
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Gedmo\Mapping\Driver;
use Gedmo\Mapping\Driver;
/**
* Annotation driver interface, provides method
* to set custom annotation reader.
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
interface AnnotationDriverInterface extends Driver
{
/**
* Set annotation reader class
* since older doctrine versions do not provide an interface
* it must provide these methods:
* getClassAnnotations([reflectionClass])
* getClassAnnotation([reflectionClass], [name])
* getPropertyAnnotations([reflectionProperty])
* getPropertyAnnotation([reflectionProperty], [name])
*
* @param object $reader - annotation reader class
*/
public function setAnnotationReader($reader);
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Gedmo\Mapping\Driver;
use Gedmo\Mapping\Driver;
/**
* The chain mapping driver enables chained
* extension mapping driver support
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Chain implements Driver
{
/**
* The default driver
*
* @var Driver|null
*/
private $defaultDriver;
/**
* List of drivers nested
* @var Driver[]
*/
private $_drivers = array();
/**
* Add a nested driver.
*
* @param Driver $nestedDriver
* @param string $namespace
*/
public function addDriver(Driver $nestedDriver, $namespace)
{
$this->_drivers[$namespace] = $nestedDriver;
}
/**
* Get the array of nested drivers.
*
* @return Driver[] $drivers
*/
public function getDrivers()
{
return $this->_drivers;
}
/**
* Get the default driver.
*
* @return Driver|null
*/
public function getDefaultDriver()
{
return $this->defaultDriver;
}
/**
* Set the default driver.
*
* @param Driver $driver
*/
public function setDefaultDriver(Driver $driver)
{
$this->defaultDriver = $driver;
}
/**
* {@inheritDoc}
*/
public function readExtendedMetadata($meta, array &$config)
{
foreach ($this->_drivers as $namespace => $driver) {
if (strpos($meta->name, $namespace) === 0) {
$driver->readExtendedMetadata($meta, $config);
return;
}
}
if (null !== $this->defaultDriver) {
$this->defaultDriver->readExtendedMetadata($meta, $config);
return;
}
// commenting it for customized mapping support, debugging of such cases might get harder
//throw new \Gedmo\Exception\UnexpectedValueException('Class ' . $meta->name . ' is not a valid entity or mapped super class.');
}
/**
* Passes in the mapping read by original driver
*
* @param $driver
* @return void
*/
public function setOriginalDriver($driver)
{
//not needed here
}
}

View File

@@ -0,0 +1,132 @@
<?php
namespace Gedmo\Mapping\Driver;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\Driver\FileLocator;
use Doctrine\ORM\Mapping\Driver\AbstractFileDriver;
use Gedmo\Mapping\Driver;
use Gedmo\Exception\InvalidMappingException;
/**
* The mapping FileDriver abstract class, defines the
* metadata extraction function common among
* all drivers used on these extensions by file based
* drivers.
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
abstract class File implements Driver
{
/**
* @var FileLocator
*/
protected $locator;
/**
* File extension, must be set in child class
* @var string
*/
protected $_extension;
/**
* original driver if it is available
*/
protected $_originalDriver = null;
public function setLocator(FileLocator $locator)
{
$this->locator = $locator;
}
/**
* Set the paths for file lookup
*
* @param array $paths
*
* @return void
*/
public function setPaths($paths)
{
$this->_paths = (array) $paths;
}
/**
* Set the file extension
*
* @param string $extension
*
* @return void
*/
public function setExtension($extension)
{
$this->_extension = $extension;
}
/**
* Loads a mapping file with the given name and returns a map
* from class/entity names to their corresponding elements.
*
* @param string $file The mapping file to load.
*
* @return array
*/
abstract protected function _loadMappingFile($file);
/**
* Tries to get a mapping for a given class
*
* @param string $className
*
* @return null|array|object
*/
protected function _getMapping($className)
{
//try loading mapping from original driver first
$mapping = null;
if (!is_null($this->_originalDriver)) {
if ($this->_originalDriver instanceof FileDriver || $this->_originalDriver instanceof AbstractFileDriver) {
$mapping = $this->_originalDriver->getElement($className);
}
}
//if no mapping found try to load mapping file again
if (is_null($mapping)) {
$yaml = $this->_loadMappingFile($this->locator->findMappingFile($className));
$mapping = $yaml[$className];
}
return $mapping;
}
/**
* Passes in the mapping read by original driver
*
* @param object $driver
*
* @return void
*/
public function setOriginalDriver($driver)
{
$this->_originalDriver = $driver;
}
/**
* Try to find out related class name out of mapping
*
* @param $metadata - the mapped class metadata
* @param $name - the related object class name
* @return string - related class name or empty string if does not exist
*/
protected function getRelatedClassName($metadata, $name)
{
if (class_exists($name) || interface_exists($name)) {
return $name;
}
$refl = $metadata->getReflectionClass();
$ns = $refl->getNamespaceName();
$className = $ns . '\\' . $name;
return class_exists($className) ? $className : '';
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Gedmo\Mapping\Driver;
use Gedmo\Mapping\Driver;
use Gedmo\Exception\InvalidMappingException;
use SimpleXMLElement;
/**
* The mapping XmlDriver abstract class, defines the
* metadata extraction function common among all
* all drivers used on these extensions by file based
* drivers.
*
* @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
abstract class Xml extends File
{
const GEDMO_NAMESPACE_URI = 'http://gediminasm.org/schemas/orm/doctrine-extensions-mapping';
const DOCTRINE_NAMESPACE_URI = 'http://doctrine-project.org/schemas/orm/doctrine-mapping';
/**
* File extension
* @var string
*/
protected $_extension = '.dcm.xml';
/**
* Get attribute value.
* As we are supporting namespaces the only way to get to the attributes under a node is to use attributes function on it
*
* @param SimpleXMLElement $node
* @param string $attributeName
*
* @return string
*/
protected function _getAttribute(SimpleXmlElement $node, $attributeName)
{
$attributes = $node->attributes();
return (string) $attributes[$attributeName];
}
/**
* Get boolean attribute value.
* As we are supporting namespaces the only way to get to the attributes under a node is to use attributes function on it
*
* @param SimpleXMLElement $node
* @param string $attributeName
*
* @return boolean
*/
protected function _getBooleanAttribute(SimpleXmlElement $node, $attributeName)
{
$rawValue = strtolower($this->_getAttribute($node, $attributeName));
if ($rawValue === '1' || $rawValue === 'true') {
return true;
}
if ($rawValue === '0' || $rawValue === 'false') {
return false;
}
throw new InvalidMappingException(sprintf("Attribute %s must have a valid boolean value, '%s' found", $attributeName, $this->_getAttribute($node, $attributeName)));
}
/**
* does attribute exist under a specific node
* As we are supporting namespaces the only way to get to the attributes under a node is to use attributes function on it
*
* @param SimpleXMLElement $node
* @param string $attributeName
*
* @return string
*/
protected function _isAttributeSet(SimpleXmlElement $node, $attributeName)
{
$attributes = $node->attributes();
return isset($attributes[$attributeName]);
}
/**
* {@inheritDoc}
*/
protected function _loadMappingFile($file)
{
$result = array();
$xmlElement = simplexml_load_file($file);
$xmlElement = $xmlElement->children(self::DOCTRINE_NAMESPACE_URI);
if (isset($xmlElement->entity)) {
foreach ($xmlElement->entity as $entityElement) {
$entityName = $this->_getAttribute($entityElement, 'name');
$result[$entityName] = $entityElement;
}
} elseif (isset($xmlElement->{'mapped-superclass'})) {
foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) {
$className = $this->_getAttribute($mappedSuperClass, 'name');
$result[$className] = $mappedSuperClass;
}
}
return $result;
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace Gedmo\Mapping\Event\Adapter;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Exception\RuntimeException;
use Doctrine\Common\EventArgs;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
/**
* Doctrine event adapter for ODM specific
* event arguments
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class ODM implements AdapterInterface
{
/**
* @var \Doctrine\Common\EventArgs
*/
private $args;
/**
* @var \Doctrine\ODM\MongoDB\DocumentManager
*/
private $dm;
/**
* {@inheritdoc}
*/
public function setEventArgs(EventArgs $args)
{
$this->args = $args;
}
/**
* {@inheritdoc}
*/
public function getDomainObjectName()
{
return 'Document';
}
/**
* {@inheritdoc}
*/
public function getManagerName()
{
return 'ODM';
}
/**
* {@inheritdoc}
*/
public function getRootObjectClass($meta)
{
return $meta->rootDocumentName;
}
/**
* Set the document manager
*
* @param \Doctrine\ODM\MongoDB\DocumentManager $dm
*/
public function setDocumentManager(DocumentManager $dm)
{
$this->dm = $dm;
}
/**
* {@inheritdoc}
*/
public function getObjectManager()
{
if (!is_null($this->dm)) {
return $this->dm;
}
return $this->__call('getDocumentManager', array());
}
/**
* {@inheritdoc}
*/
public function getObjectState($uow, $object)
{
return $uow->getDocumentState($object);
}
/**
* {@inheritdoc}
*/
public function __call($method, $args)
{
if (is_null($this->args)) {
throw new RuntimeException("Event args must be set before calling its methods");
}
$method = str_replace('Object', $this->getDomainObjectName(), $method);
return call_user_func_array(array($this->args, $method), $args);
}
/**
* {@inheritdoc}
*/
public function getObjectChangeSet($uow, $object)
{
return $uow->getDocumentChangeSet($object);
}
/**
* {@inheritdoc}
*/
public function getSingleIdentifierFieldName($meta)
{
return $meta->identifier;
}
/**
* {@inheritdoc}
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object)
{
$uow->recomputeSingleDocumentChangeSet($meta, $object);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectUpdates($uow)
{
$updates = $uow->getScheduledDocumentUpdates();
$upserts = $uow->getScheduledDocumentUpserts();
return array_merge($updates, $upserts);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectInsertions($uow)
{
return $uow->getScheduledDocumentInsertions();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectDeletions($uow)
{
return $uow->getScheduledDocumentDeletions();
}
/**
* {@inheritdoc}
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value)
{
$uow->setOriginalDocumentProperty($oid, $property, $value);
}
/**
* {@inheritdoc}
*/
public function clearObjectChangeSet($uow, $oid)
{
$uow->clearDocumentChangeSet($oid);
}
/**
* Creates a ODM specific LifecycleEventArgs.
*
* @param object $document
* @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
*
* @return \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance($document, $documentManager)
{
return new LifecycleEventArgs($document, $documentManager);
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace Gedmo\Mapping\Event\Adapter;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Exception\RuntimeException;
use Doctrine\Common\EventArgs;
use Doctrine\ORM\Event\LifecycleEventArgs;
/**
* Doctrine event adapter for ORM specific
* event arguments
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class ORM implements AdapterInterface
{
/**
* @var \Doctrine\Common\EventArgs
*/
private $args;
/**
* @var \Doctrine\ORM\EntityManagerInterface
*/
private $em;
/**
* {@inheritdoc}
*/
public function setEventArgs(EventArgs $args)
{
$this->args = $args;
}
/**
* {@inheritdoc}
*/
public function getDomainObjectName()
{
return 'Entity';
}
/**
* {@inheritdoc}
*/
public function getManagerName()
{
return 'ORM';
}
/**
* {@inheritdoc}
*/
public function getRootObjectClass($meta)
{
return $meta->rootEntityName;
}
/**
* {@inheritdoc}
*/
public function __call($method, $args)
{
if (is_null($this->args)) {
throw new RuntimeException("Event args must be set before calling its methods");
}
$method = str_replace('Object', $this->getDomainObjectName(), $method);
return call_user_func_array(array($this->args, $method), $args);
}
/**
* Set the entity manager
*
* @param \Doctrine\ORM\EntityManagerInterface $em
*/
public function setEntityManager(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* {@inheritdoc}
*/
public function getObjectManager()
{
if (!is_null($this->em)) {
return $this->em;
}
return $this->__call('getEntityManager', array());
}
/**
* {@inheritdoc}
*/
public function getObjectState($uow, $object)
{
return $uow->getEntityState($object);
}
/**
* {@inheritdoc}
*/
public function getObjectChangeSet($uow, $object)
{
return $uow->getEntityChangeSet($object);
}
/**
* {@inheritdoc}
*/
public function getSingleIdentifierFieldName($meta)
{
return $meta->getSingleIdentifierFieldName();
}
/**
* {@inheritdoc}
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object)
{
$uow->recomputeSingleEntityChangeSet($meta, $object);
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectUpdates($uow)
{
return $uow->getScheduledEntityUpdates();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectInsertions($uow)
{
return $uow->getScheduledEntityInsertions();
}
/**
* {@inheritdoc}
*/
public function getScheduledObjectDeletions($uow)
{
return $uow->getScheduledEntityDeletions();
}
/**
* {@inheritdoc}
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value)
{
$uow->setOriginalEntityProperty($oid, $property, $value);
}
/**
* {@inheritdoc}
*/
public function clearObjectChangeSet($uow, $oid)
{
$uow->clearEntityChangeSet($oid);
}
/**
* Creates a ORM specific LifecycleEventArgs.
*
* @param object $document
* @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
*
* @return \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance($document, $documentManager)
{
return new LifecycleEventArgs($document, $documentManager);
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Gedmo\Mapping\Event;
use Doctrine\Common\EventArgs;
use Doctrine\ORM\UnitOfWork;
/**
* Doctrine event adapter interface is used
* to retrieve common functionality for Doctrine
* events
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
interface AdapterInterface
{
/**
* Set the eventargs
*
* @param \Doctrine\Common\EventArgs $args
*/
public function setEventArgs(EventArgs $args);
/**
* Call specific method on event args
*
* @param string $method
* @param array $args
*
* @return mixed
*/
public function __call($method, $args);
/**
* Get the name of domain object
*
* @return string
*/
public function getDomainObjectName();
/**
* Get the name of used manager for this
* event adapter
*
* @return string
*/
public function getManagerName();
/**
* Get the root object class, handles inheritance
*
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
*
* @return string
*/
public function getRootObjectClass($meta);
/**
* Get used object manager
*
* @return \Doctrine\Common\Persistence\ObjectManager
*/
public function getObjectManager();
/**
* Get object state
*
* @param UnitOfWork $uow
* @param object $object
*
* @return int The document state.
*/
public function getObjectState($uow, $object);
/**
* Get the object changeset from a UnitOfWork
*
* @param UnitOfWork $uow
* @param object $object
*
* @return array
*/
public function getObjectChangeSet($uow, $object);
/**
* Get the single identifier field name
*
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
*
* @return string
*/
public function getSingleIdentifierFieldName($meta);
/**
* Recompute the single object changeset from a UnitOfWork
*
* @param UnitOfWork $uow
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
* @param object $object
*
* @return void
*/
public function recomputeSingleObjectChangeSet($uow, $meta, $object);
/**
* Get the scheduled object updates from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectUpdates($uow);
/**
* Get the scheduled object insertions from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectInsertions($uow);
/**
* Get the scheduled object deletions from a UnitOfWork
*
* @param UnitOfWork $uow
*
* @return array
*/
public function getScheduledObjectDeletions($uow);
/**
* Sets a property value of the original data array of an object
*
* @param UnitOfWork $uow
* @param string $oid
* @param string $property
* @param mixed $value
*
* @return void
*/
public function setOriginalObjectProperty($uow, $oid, $property, $value);
/**
* Clears the property changeset of the object with the given OID.
*
* @param UnitOfWork $uow
* @param string $oid The object's OID.
*/
public function clearObjectChangeSet($uow, $oid);
}

View File

@@ -0,0 +1,180 @@
<?php
namespace Gedmo\Mapping;
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Version as CommonLibVer;
use Gedmo\Mapping\Driver\File as FileDriver;
use Gedmo\Mapping\Driver\AnnotationDriverInterface;
/**
* The extension metadata factory is responsible for extension driver
* initialization and fully reading the extension metadata
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class ExtensionMetadataFactory
{
/**
* Extension driver
* @var \Gedmo\Mapping\Driver
*/
protected $driver;
/**
* Object manager, entity or document
* @var object
*/
protected $objectManager;
/**
* Extension namespace
*
* @var string
*/
protected $extensionNamespace;
/**
* Custom annotation reader
*
* @var object
*/
protected $annotationReader;
/**
* Initializes extension driver
*
* @param ObjectManager $objectManager
* @param string $extensionNamespace
* @param object $annotationReader
*/
public function __construct(ObjectManager $objectManager, $extensionNamespace, $annotationReader)
{
$this->objectManager = $objectManager;
$this->annotationReader = $annotationReader;
$this->extensionNamespace = $extensionNamespace;
$omDriver = $objectManager->getConfiguration()->getMetadataDriverImpl();
$this->driver = $this->getDriver($omDriver);
}
/**
* Reads extension metadata
*
* @param object $meta
* @return array - the metatada configuration
*/
public function getExtensionMetadata($meta)
{
if ($meta->isMappedSuperclass) {
return; // ignore mappedSuperclasses for now
}
$config = array();
$cmf = $this->objectManager->getMetadataFactory();
$useObjectName = $meta->name;
// collect metadata from inherited classes
if (null !== $meta->reflClass) {
foreach (array_reverse(class_parents($meta->name)) as $parentClass) {
// read only inherited mapped classes
if ($cmf->hasMetadataFor($parentClass)) {
$class = $this->objectManager->getClassMetadata($parentClass);
$this->driver->readExtendedMetadata($class, $config);
$isBaseInheritanceLevel = !$class->isInheritanceTypeNone()
&& !$class->parentClasses
&& $config
;
if ($isBaseInheritanceLevel) {
$useObjectName = $class->name;
}
}
}
$this->driver->readExtendedMetadata($meta, $config);
}
if ($config) {
$config['useObjectClass'] = $useObjectName;
}
// cache the metadata (even if it's empty)
// caching empty metadata will prevent re-parsing non-existent annotations
$cacheId = self::getCacheId($meta->name, $this->extensionNamespace);
if ($cacheDriver = $cmf->getCacheDriver()) {
$cacheDriver->save($cacheId, $config, null);
}
return $config;
}
/**
* Get the cache id
*
* @param string $className
* @param string $extensionNamespace
* @return string
*/
public static function getCacheId($className, $extensionNamespace)
{
return $className.'\\$'.strtoupper(str_replace('\\', '_', $extensionNamespace)).'_CLASSMETADATA';
}
/**
* Get the extended driver instance which will
* read the metadata required by extension
*
* @param object $omDriver
* @throws \Gedmo\Exception\RuntimeException if driver was not found in extension
* @return \Gedmo\Mapping\Driver
*/
protected function getDriver($omDriver)
{
$driver = null;
$className = get_class($omDriver);
$driverName = substr($className, strrpos($className, '\\') + 1);
if ($omDriver instanceof MappingDriverChain || $driverName == 'DriverChain') {
$driver = new Driver\Chain();
foreach ($omDriver->getDrivers() as $namespace => $nestedOmDriver) {
$driver->addDriver($this->getDriver($nestedOmDriver), $namespace);
}
if (version_compare(CommonLibVer::VERSION, '2.3.0', '>=') && $omDriver->getDefaultDriver() !== null) {
$driver->setDefaultDriver($this->getDriver($omDriver->getDefaultDriver()));
}
} else {
$driverName = substr($driverName, 0, strpos($driverName, 'Driver'));
$isSimplified = false;
if (substr($driverName, 0, 10) === 'Simplified') {
// support for simplified file drivers
$driverName = substr($driverName, 10);
$isSimplified = true;
}
// create driver instance
$driverClassName = $this->extensionNamespace.'\Mapping\Driver\\'.$driverName;
if (!class_exists($driverClassName)) {
$driverClassName = $this->extensionNamespace.'\Mapping\Driver\Annotation';
if (!class_exists($driverClassName)) {
throw new \Gedmo\Exception\RuntimeException("Failed to fallback to annotation driver: ({$driverClassName}), extension driver was not found.");
}
}
$driver = new $driverClassName();
$driver->setOriginalDriver($omDriver);
if ($driver instanceof FileDriver) {
/** @var $driver FileDriver */
if ($omDriver instanceof MappingDriver) {
$driver->setLocator($omDriver->getLocator());
// BC for Doctrine 2.2
} elseif ($isSimplified) {
$driver->setLocator(new SymfonyFileLocator($omDriver->getNamespacePrefixes(), $omDriver->getFileExtension()));
} else {
$driver->setLocator(new DefaultFileLocator($omDriver->getPaths(), $omDriver->getFileExtension()));
}
}
if ($driver instanceof AnnotationDriverInterface) {
$driver->setAnnotationReader($this->annotationReader);
}
}
return $driver;
}
}

View File

@@ -0,0 +1,283 @@
<?php
namespace Gedmo\Mapping;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\EventArgs;
use Gedmo\Mapping\Event\AdapterInterface;
/**
* This is extension of event subscriber class and is
* used specifically for handling the extension metadata
* mapping for extensions.
*
* It dries up some reusable code which is common for
* all extensions who maps additional metadata through
* extended drivers
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
abstract class MappedEventSubscriber implements EventSubscriber
{
/**
* Static List of cached object configurations
* leaving it static for reasons to look into
* other listener configuration
*
* @var array
*/
protected static $configurations = array();
/**
* Listener name, etc: sluggable
*
* @var string
*/
protected $name;
/**
* ExtensionMetadataFactory used to read the extension
* metadata through the extension drivers
*
* @var ExtensionMetadataFactory
*/
private $extensionMetadataFactory = array();
/**
* List of event adapters used for this listener
*
* @var array
*/
private $adapters = array();
/**
* Custom annotation reader
*
* @var object
*/
private $annotationReader;
/**
* @var \Doctrine\Common\Annotations\AnnotationReader
*/
private static $defaultAnnotationReader;
/**
* Constructor
*/
public function __construct()
{
$parts = explode('\\', $this->getNamespace());
$this->name = end($parts);
}
/**
* Get an event adapter to handle event specific
* methods
*
* @param EventArgs $args
*
* @throws \Gedmo\Exception\InvalidArgumentException - if event is not recognized
*
* @return \Gedmo\Mapping\Event\AdapterInterface
*/
protected function getEventAdapter(EventArgs $args)
{
$class = get_class($args);
if (preg_match('@Doctrine\\\([^\\\]+)@', $class, $m) && in_array($m[1], array('ODM', 'ORM'))) {
if (!isset($this->adapters[$m[1]])) {
$adapterClass = $this->getNamespace().'\\Mapping\\Event\\Adapter\\'.$m[1];
if (!class_exists($adapterClass)) {
$adapterClass = 'Gedmo\\Mapping\\Event\\Adapter\\'.$m[1];
}
$this->adapters[$m[1]] = new $adapterClass();
}
$this->adapters[$m[1]]->setEventArgs($args);
return $this->adapters[$m[1]];
} else {
throw new \Gedmo\Exception\InvalidArgumentException('Event mapper does not support event arg class: '.$class);
}
}
/**
* Get the configuration for specific object class
* if cache driver is present it scans it also
*
* @param ObjectManager $objectManager
* @param string $class
*
* @return array
*/
public function getConfiguration(ObjectManager $objectManager, $class)
{
$config = array();
if (isset(self::$configurations[$this->name][$class])) {
$config = self::$configurations[$this->name][$class];
} else {
$factory = $objectManager->getMetadataFactory();
$cacheDriver = $factory->getCacheDriver();
if ($cacheDriver) {
$cacheId = ExtensionMetadataFactory::getCacheId($class, $this->getNamespace());
if (($cached = $cacheDriver->fetch($cacheId)) !== false) {
self::$configurations[$this->name][$class] = $cached;
$config = $cached;
} else {
// re-generate metadata on cache miss
$this->loadMetadataForObjectClass($objectManager, $factory->getMetadataFor($class));
if (isset(self::$configurations[$this->name][$class])) {
$config = self::$configurations[$this->name][$class];
}
}
$objectClass = isset($config['useObjectClass']) ? $config['useObjectClass'] : $class;
if ($objectClass !== $class) {
$this->getConfiguration($objectManager, $objectClass);
}
}
}
return $config;
}
/**
* Get extended metadata mapping reader
*
* @param ObjectManager $objectManager
*
* @return ExtensionMetadataFactory
*/
public function getExtensionMetadataFactory(ObjectManager $objectManager)
{
$oid = spl_object_hash($objectManager);
if (!isset($this->extensionMetadataFactory[$oid])) {
if (is_null($this->annotationReader)) {
// create default annotation reader for extensions
$this->annotationReader = $this->getDefaultAnnotationReader();
}
$this->extensionMetadataFactory[$oid] = new ExtensionMetadataFactory(
$objectManager,
$this->getNamespace(),
$this->annotationReader
);
}
return $this->extensionMetadataFactory[$oid];
}
/**
* Set annotation reader class
* since older doctrine versions do not provide an interface
* it must provide these methods:
* getClassAnnotations([reflectionClass])
* getClassAnnotation([reflectionClass], [name])
* getPropertyAnnotations([reflectionProperty])
* getPropertyAnnotation([reflectionProperty], [name])
*
* @param Reader $reader - annotation reader class
*/
public function setAnnotationReader($reader)
{
$this->annotationReader = $reader;
}
/**
* Scans the objects for extended annotations
* event subscribers must subscribe to loadClassMetadata event
*
* @param ObjectManager $objectManager
* @param object $metadata
* @return void
*/
public function loadMetadataForObjectClass(ObjectManager $objectManager, $metadata)
{
$factory = $this->getExtensionMetadataFactory($objectManager);
try {
$config = $factory->getExtensionMetadata($metadata);
} catch (\ReflectionException $e) {
// entity\document generator is running
$config = false; // will not store a cached version, to remap later
}
if ($config) {
self::$configurations[$this->name][$metadata->name] = $config;
}
}
/**
* Get the namespace of extension event subscriber.
* used for cache id of extensions also to know where
* to find Mapping drivers and event adapters
*
* @return string
*/
abstract protected function getNamespace();
/**
* Create default annotation reader for extensions
*
* @return \Doctrine\Common\Annotations\AnnotationReader
*/
private function getDefaultAnnotationReader()
{
if (null === self::$defaultAnnotationReader) {
if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
'Gedmo\\Mapping\\Annotation',
__DIR__.'/../../'
);
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
} elseif (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
'Gedmo\\Mapping\\Annotation',
__DIR__.'/../../'
);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
} elseif (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$reader->setIgnoreNotImportedAnnotations(true);
$reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
$reader->setEnableParsePhpImports(false);
$reader->setAutoloadAnnotations(true);
$reader = new \Doctrine\Common\Annotations\CachedReader(
new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
);
} else {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setAutoloadAnnotations(true);
$reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
}
self::$defaultAnnotationReader = $reader;
}
return self::$defaultAnnotationReader;
}
/**
* Sets the value for a mapped field
*
* @param AdapterInterface $adapter
* @param object $object
* @param string $field
* @param mixed $oldValue
* @param mixed $newValue
*/
protected function setFieldValue(AdapterInterface $adapter, $object, $field, $oldValue, $newValue)
{
$manager = $adapter->getObjectManager();
$meta = $manager->getClassMetadata(get_class($object));
$uow = $manager->getUnitOfWork();
$meta->getReflectionProperty($field)->setValue($object, $newValue);
$uow->propertyChanged($object, $field, $oldValue, $newValue);
$adapter->recomputeSingleObjectChangeSet($uow, $meta, $object);
}
}