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,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;
}
}