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,77 @@
<?php
namespace Gedmo\ReferenceIntegrity\Mapping\Driver;
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\ReferenceIntegrity\Mapping\Validator;
/**
* This is an annotation mapping driver for ReferenceIntegrity
* behavioral extension. Used for extraction of extended
* metadata from Annotations specifically for ReferenceIntegrity
* extension.
*
* @author Evert Harmeling <evert.harmeling@freshheads.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Annotation extends AbstractAnnotationDriver
{
/**
* Annotation to identify the fields which manages the reference integrity
*/
const REFERENCE_INTEGRITY = 'Gedmo\\Mapping\\Annotation\\ReferenceIntegrity';
/**
* ReferenceIntegrityAction extension annotation
*/
const ACTION = 'Gedmo\\Mapping\\Annotation\\ReferenceIntegrityAction';
/**
* {@inheritDoc}
*/
public function readExtendedMetadata($meta, array &$config)
{
$validator = new Validator();
$reflClass = $this->getMetaReflectionClass($meta);
foreach ($reflClass->getProperties() as $reflProperty) {
if ($referenceIntegrity = $this->reader->getPropertyAnnotation($reflProperty, self::REFERENCE_INTEGRITY)) {
$property = $reflProperty->getName();
if (!$meta->hasField($property)) {
throw new InvalidMappingException(
sprintf(
"Unable to find reference integrity [%s] as mapped property in entity - %s",
$property,
$meta->name
)
);
}
$fieldMapping = $meta->getFieldMapping($property);
if (!isset($fieldMapping['mappedBy'])) {
throw new InvalidMappingException(
sprintf(
"'mappedBy' should be set on '%s' in '%s'",
$property,
$meta->name
)
);
}
if (!in_array($referenceIntegrity->value, $validator->getIntegrityActions())) {
throw new InvalidMappingException(
sprintf(
"Field - [%s] does not have a valid integrity option, [%s] in class - %s",
$property,
implode($validator->getIntegrityActions(), ', '),
$meta->name
)
);
}
$config['referenceIntegrity'][$property] = $referenceIntegrity->value;
}
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Gedmo\ReferenceIntegrity\Mapping\Driver;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\Mapping\Driver\File;
use Gedmo\Mapping\Driver;
use Gedmo\ReferenceIntegrity\Mapping\Validator;
/**
* This is a yaml mapping driver for ReferenceIntegrity
* extension. Used for extraction of extended
* metadata from yaml specifically for ReferenceIntegrity
* extension.
*
* @author Evert Harmeling <evert.harmeling@freshheads.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Yaml extends File implements Driver
{
/**
* File extension
* @var string
*/
protected $_extension = '.dcm.yml';
/**
* {@inheritDoc}
*/
public function readExtendedMetadata($meta, array &$config)
{
$mapping = $this->_getMapping($meta->name);
$validator = new Validator();
if (isset($mapping['fields'])) {
foreach ($mapping['fields'] as $property => $fieldMapping) {
if (isset($fieldMapping['gedmo']['referenceIntegrity'])) {
if (!$meta->hasField($property)) {
throw new InvalidMappingException(
sprintf(
"Unable to find reference integrity [%s] as mapped property in entity - %s",
$property,
$meta->name
)
);
}
if (empty($mapping['fields'][$property]['mappedBy'])) {
throw new InvalidMappingException(
sprintf(
"'mappedBy' should be set on '%s' in '%s'",
$property,
$meta->name
)
);
}
if (!in_array($fieldMapping['gedmo']['referenceIntegrity'], $validator->getIntegrityActions())) {
throw new InvalidMappingException(
sprintf(
"Field - [%s] does not have a valid integrity option, [%s] in class - %s",
$property,
implode($validator->getIntegrityActions(), ', '),
$meta->name
)
);
}
$config['referenceIntegrity'][$property][$mapping['fields'][$property]['mappedBy']] =
$fieldMapping['gedmo']['referenceIntegrity'];
}
}
}
}
/**
* {@inheritDoc}
*/
protected function _loadMappingFile($file)
{
return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
}
}