This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping\Driver;
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\SoftDeleteable\Mapping\Validator;
/**
* This is an annotation mapping driver for SoftDeleteable
* behavioral extension. Used for extraction of extended
* metadata from Annotations specifically for SoftDeleteable
* extension.
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Annotation extends AbstractAnnotationDriver
{
/**
* Annotation to define that this object is loggable
*/
const SOFT_DELETEABLE = 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
/**
* {@inheritDoc}
*/
public function readExtendedMetadata($meta, array &$config)
{
$class = $this->getMetaReflectionClass($meta);
// class annotations
if ($class !== null && $annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE)) {
$config['softDeleteable'] = true;
Validator::validateField($meta, $annot->fieldName);
$config['fieldName'] = $annot->fieldName;
$config['timeAware'] = false;
if (isset($annot->timeAware)) {
if (!is_bool($annot->timeAware)) {
throw new InvalidMappingException("timeAware must be boolean. ".gettype($annot->timeAware)." provided.");
}
$config['timeAware'] = $annot->timeAware;
}
$config['hardDelete'] = true;
if (isset($annot->hardDelete)) {
if (!is_bool($annot->hardDelete)) {
throw new InvalidMappingException("hardDelete must be boolean. ".gettype($annot->hardDelete)." provided.");
}
$config['hardDelete'] = $annot->hardDelete;
}
}
$this->validateFullMetadata($meta, $config);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping\Driver;
use Gedmo\Mapping\Driver\Xml as BaseXml;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\SoftDeleteable\Mapping\Validator;
/**
* This is a xml mapping driver for SoftDeleteable
* behavioral extension. Used for extraction of extended
* metadata from xml specifically for SoftDeleteable
* extension.
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Xml extends BaseXml
{
/**
* {@inheritDoc}
*/
public function readExtendedMetadata($meta, array &$config)
{
/**
* @var \SimpleXmlElement $xml
*/
$xml = $this->_getMapping($meta->name);
$xmlDoctrine = $xml;
$xml = $xml->children(self::GEDMO_NAMESPACE_URI);
if (in_array($xmlDoctrine->getName(), array('mapped-superclass', 'entity', 'document', 'embedded-document'))) {
if (isset($xml->{'soft-deleteable'})) {
$field = $this->_getAttribute($xml->{'soft-deleteable'}, 'field-name');
if (!$field) {
throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
}
Validator::validateField($meta, $field);
$config['softDeleteable'] = true;
$config['fieldName'] = $field;
$config['timeAware'] = false;
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'time-aware')) {
$config['timeAware'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'time-aware');
}
$config['hardDelete'] = true;
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'hard-delete')) {
$config['hardDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'hard-delete');
}
}
}
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping\Driver;
use Gedmo\Mapping\Driver\File;
use Gedmo\Mapping\Driver;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\SoftDeleteable\Mapping\Validator;
/**
* This is a yaml mapping driver for Timestampable
* behavioral extension. Used for extraction of extended
* metadata from yaml specifically for Timestampable
* extension.
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.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);
if (isset($mapping['gedmo'])) {
$classMapping = $mapping['gedmo'];
if (isset($classMapping['soft_deleteable'])) {
$config['softDeleteable'] = true;
if (!isset($classMapping['soft_deleteable']['field_name'])) {
throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
}
$fieldName = $classMapping['soft_deleteable']['field_name'];
Validator::validateField($meta, $fieldName);
$config['fieldName'] = $fieldName;
$config['timeAware'] = false;
if (isset($classMapping['soft_deleteable']['time_aware'])) {
if (!is_bool($classMapping['soft_deleteable']['time_aware'])) {
throw new InvalidMappingException("timeAware must be boolean. ".gettype($classMapping['soft_deleteable']['time_aware'])." provided.");
}
$config['timeAware'] = $classMapping['soft_deleteable']['time_aware'];
}
$config['hardDelete'] = true;
if (isset($classMapping['soft_deleteable']['hard_delete'])) {
if (!is_bool($classMapping['soft_deleteable']['hard_delete'])) {
throw new InvalidMappingException("hardDelete must be boolean. ".gettype($classMapping['soft_deleteable']['hard_delete'])." provided.");
}
$config['hardDelete'] = $classMapping['soft_deleteable']['hard_delete'];
}
}
}
}
/**
* {@inheritDoc}
*/
protected function _loadMappingFile($file)
{
return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping\Event\Adapter;
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
use Gedmo\SoftDeleteable\Mapping\Event\SoftDeleteableAdapter;
/**
* Doctrine event adapter for ORM adapted
* for SoftDeleteable behavior.
*
* @author David Buchmann <mail@davidbu.ch>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
final class ORM extends BaseAdapterORM implements SoftDeleteableAdapter
{
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping\Event;
use Gedmo\Mapping\Event\AdapterInterface;
/**
* Doctrine event adapter interface
* for SoftDeleteable behavior
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
interface SoftDeleteableAdapter extends AdapterInterface
{
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Gedmo\SoftDeleteable\Mapping;
use Gedmo\Exception\InvalidMappingException;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
/**
* This class is used to validate mapping information
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class Validator
{
/**
* List of types which are valid for timestamp
*
* @var array
*/
public static $validTypes = array(
'date',
'date_immutable',
'time',
'time_immutable',
'datetime',
'datetime_immutable',
'datetimetz',
'datetimetz_immutable',
'timestamp',
'zenddate',
);
public static function validateField(ClassMetadata $meta, $field)
{
if ($meta->isMappedSuperclass) {
return;
}
$fieldMapping = $meta->getFieldMapping($field);
if (!in_array($fieldMapping['type'], self::$validTypes)) {
throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s',
$field,
$fieldMapping['type'],
implode(', ', self::$validTypes),
$meta->name));
}
}
}