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,79 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AuditManager implements AuditManagerInterface
{
/**
* @var array
*/
protected $classes = [];
/**
* @var array
*/
protected $readers = [];
/**
* @var ContainerInterface
*/
protected $container;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function setReader($serviceId, array $classes)
{
$this->readers[$serviceId] = $classes;
}
/**
* {@inheritdoc}
*/
public function hasReader($class)
{
foreach ($this->readers as $classes) {
if (in_array($class, $classes)) {
return true;
}
}
return false;
}
/**
* {@inheritdoc}
*/
public function getReader($class)
{
foreach ($this->readers as $readerId => $classes) {
if (in_array($class, $classes)) {
return $this->container->get($readerId);
}
}
throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
interface AuditManagerInterface
{
/**
* Set AuditReaderInterface service id for array of $classes.
*
* @param string $serviceId
* @param array $classes
*/
public function setReader($serviceId, array $classes);
/**
* Returns true if $class has AuditReaderInterface.
*
* @param string $class
*
* @return bool
*/
public function hasReader($class);
/**
* Get AuditReaderInterface service for $class.
*
* @param string $class
*
* @return AuditReaderInterface
*
* @throws \RuntimeException
*/
public function getReader($class);
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
interface AuditReaderInterface
{
/**
* @param string $className
* @param string $id
* @param string $revision
*/
public function find($className, $id, $revision);
/**
* @param string $className
* @param int $limit
* @param int $offset
*/
public function findRevisionHistory($className, $limit = 20, $offset = 0);
/**
* @param string $classname
* @param string $revision
*/
public function findRevision($classname, $revision);
/**
* @param string $className
* @param string $id
*/
public function findRevisions($className, $id);
/**
* @param string $className
* @param int $id
* @param int $oldRevision
* @param int $newRevision
*/
public function diff($className, $id, $oldRevision, $newRevision);
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
use Sonata\AdminBundle\Exception\LockException;
/**
* @author Emmanuel Vella <vella.emmanuel@gmail.com>
*/
interface LockInterface
{
/**
* @param object $object
*
* @return mixed|null
*/
public function getLockVersion($object);
/**
* @param object $object
* @param mixed $expectedVersion
*
* @throws LockException
*/
public function lock($object, $expectedVersion);
}

View File

@@ -0,0 +1,275 @@
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Exception\ModelManagerException;
/**
* A model manager is a bridge between the model classes and the admin
* functionality.
*/
interface ModelManagerInterface
{
/**
* Returns a new FieldDescription.
*
* @param string $class
* @param string $name
* @param array $options
*
* @return FieldDescriptionInterface
*/
public function getNewFieldDescriptionInstance($class, $name, array $options = []);
/**
* @param mixed $object
*
* @throws ModelManagerException
*/
public function create($object);
/**
* @param mixed $object
*
* @throws ModelManagerException
*/
public function update($object);
/**
* @param mixed $object
*
* @throws ModelManagerException
*/
public function delete($object);
/**
* @param string $class
* @param array $criteria
*
* @return array all objects matching the criteria
*/
public function findBy($class, array $criteria = []);
/**
* @param string $class
* @param array $criteria
*
* @return object an object matching the criteria or null if none match
*/
public function findOneBy($class, array $criteria = []);
/**
* @param string $class
* @param mixed $id
*
* @return object the object with id or null if not found
*/
public function find($class, $id);
/**
* @param string $class
* @param ProxyQueryInterface $queryProxy
*
* @throws ModelManagerException
*/
public function batchDelete($class, ProxyQueryInterface $queryProxy);
/**
* @param array $parentAssociationMapping
* @param string $class
*/
public function getParentFieldDescription($parentAssociationMapping, $class);
/**
* @param string $class
* @param string $alias
*
* @return ProxyQueryInterface
*/
public function createQuery($class, $alias = 'o');
/**
* Get the identifier for the model type of this class.
*
* @param string $class fully qualified class name
*
* @return string
*/
public function getModelIdentifier($class);
/**
* Get the identifiers of this model class.
*
* This returns an array to handle cases like a primary key that is
* composed of multiple columns. If you need a string representation,
* use getNormalizedIdentifier resp. getUrlsafeIdentifier
*
* @param object $model
*
* @return array list of all identifiers of this model
*/
public function getIdentifierValues($model);
/**
* Get a list of the field names models of the specified class use to store
* the identifier.
*
* @param string $class fully qualified class name
*
* @return array
*/
public function getIdentifierFieldNames($class);
/**
* Get the identifiers for this model class as a string.
*
* @param object $model
*
* @return string a string representation of the identifiers for this
* instance
*/
public function getNormalizedIdentifier($model);
/**
* Get the identifiers as a string that is safe to use in a url.
*
* This is similar to getNormalizedIdentifier but guarantees an id that can
* be used in a URL.
*
* @param object $model
*
* @return string string representation of the id that is safe to use in a url
*/
public function getUrlsafeIdentifier($model);
/**
* Create a new instance of the model of the specified class.
*
* @param string $class
*
* @return mixed
*/
public function getModelInstance($class);
/**
* @param string $class
*
* @return array
*/
public function getModelCollectionInstance($class);
/**
* Removes an element from the collection.
*
* @param mixed $collection
* @param mixed $element
*/
public function collectionRemoveElement(&$collection, &$element);
/**
* Add an element from the collection.
*
* @param mixed $collection
* @param mixed $element
*
* @return mixed
*/
public function collectionAddElement(&$collection, &$element);
/**
* Check if the element exists in the collection.
*
* @param mixed $collection
* @param mixed $element
*
* @return bool
*/
public function collectionHasElement(&$collection, &$element);
/**
* Clear the collection.
*
* @param mixed $collection
*
* @return mixed
*/
public function collectionClear(&$collection);
/**
* Returns the parameters used in the columns header.
*
* @param FieldDescriptionInterface $fieldDescription
* @param DatagridInterface $datagrid
*
* @return array
*/
public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid);
/**
* @param string $class
*
* @return array
*/
public function getDefaultSortValues($class);
/**
* @param string $class
* @param array $array
*/
public function modelReverseTransform($class, array $array = []);
/**
* @param string $class
* @param object $instance
*/
public function modelTransform($class, $instance);
/**
* @param mixed $query
*/
public function executeQuery($query);
/**
* @param DatagridInterface $datagrid
* @param array $fields
* @param null $firstResult
* @param null $maxResult
*
* @return \Exporter\Source\SourceIteratorInterface
*/
public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null);
/**
* @param string $class
*
* @return array
*/
public function getExportFields($class);
/**
* @param DatagridInterface $datagrid
* @param int $page
*
* @return mixed
*/
public function getPaginationParameters(DatagridInterface $datagrid, $page);
/**
* @param string $class
* @param ProxyQueryInterface $query
* @param array $idx
*/
public function addIdentifiersToQuery($class, ProxyQueryInterface $query, array $idx);
}