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,103 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
use Doctrine\DBAL\Schema\Schema;
use ProxyManager\Configuration;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
use ProxyManager\Proxy\LazyLoadingInterface;
class LazySchemaDiffProvider implements SchemaDiffProviderInterface
{
/** @var LazyLoadingValueHolderFactory */
private $proxyFactory;
/** @var SchemaDiffProviderInterface */
private $originalSchemaManipulator;
public function __construct(LazyLoadingValueHolderFactory $proxyFactory, SchemaDiffProviderInterface $originalSchemaManipulator)
{
$this->proxyFactory = $proxyFactory;
$this->originalSchemaManipulator = $originalSchemaManipulator;
}
public static function fromDefaultProxyFacyoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator)
{
$message = 'Function %s::fromDefaultProxyFacyoryConfiguration() deprecated due to typo.'
. 'Use %s::fromDefaultProxyFactoryConfiguration() instead';
trigger_error(
sprintf($message, self::class),
E_USER_DEPRECATED
);
return self::fromDefaultProxyFactoryConfiguration($originalSchemaManipulator);
}
public static function fromDefaultProxyFactoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator)
{
$proxyConfig = new Configuration();
$proxyConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
$proxyFactory = new LazyLoadingValueHolderFactory($proxyConfig);
return new LazySchemaDiffProvider($proxyFactory, $originalSchemaManipulator);
}
/**
* @return Schema
*/
public function createFromSchema()
{
$originalSchemaManipulator = $this->originalSchemaManipulator;
return $this->proxyFactory->createProxy(
Schema::class,
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator) {
$initializer = null;
$wrappedObject = $originalSchemaManipulator->createFromSchema();
return true;
}
);
}
/**
* @param Schema $fromSchema
* @return Schema
*/
public function createToSchema(Schema $fromSchema)
{
$originalSchemaManipulator = $this->originalSchemaManipulator;
if ($fromSchema instanceof LazyLoadingInterface && ! $fromSchema->isProxyInitialized()) {
return $this->proxyFactory->createProxy(
Schema::class,
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator, $fromSchema) {
$initializer = null;
$wrappedObject = $originalSchemaManipulator->createToSchema($fromSchema);
return true;
}
);
}
return $this->originalSchemaManipulator->createToSchema($fromSchema);
}
/**
* @param Schema $fromSchema
* @param Schema $toSchema
*
* @return string[]
*/
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema)
{
if ($toSchema instanceof LazyLoadingInterface
&& ! $toSchema->isProxyInitialized()) {
return [];
}
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
/**
* A schema provider that uses the doctrine ORM to generate schemas.
*
* @since 1.0.0-alpha3
*/
final class OrmSchemaProvider implements SchemaProviderInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct($em)
{
if ( ! $this->isEntityManager($em)) {
throw new \InvalidArgumentException(sprintf(
'$em is not a valid Doctrine ORM Entity Manager, got "%s"',
is_object($em) ? get_class($em) : gettype($em)
));
}
$this->entityManager = $em;
}
/**
* {@inheritdoc}
*/
public function createSchema()
{
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
throw new \UnexpectedValueException('No mapping information to process');
}
$tool = new SchemaTool($this->entityManager);
return $tool->getSchemaFromMetadata($metadata);
}
/**
* Doctrine's EntityManagerInterface was introduced in version 2.4, since this
* library allows those older version we need to be able to check for those
* old ORM versions. Hence the helper method.
*
* No need to check to see if EntityManagerInterface exists first here, PHP
* doesn't care.
*
* @param mixed $manager Hopefully an entity manager, but it may be anything
* @return boolean
*/
private function isEntityManager($manager)
{
return $manager instanceof EntityManagerInterface || $manager instanceof EntityManager;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
class SchemaDiffProvider implements SchemaDiffProviderInterface
{
/** @var AbstractPlatform */
private $platform;
/** @var AbstractSchemaManager */
private $schemaManager;
public function __construct(AbstractSchemaManager $schemaManager, AbstractPlatform $platform)
{
$this->schemaManager = $schemaManager;
$this->platform = $platform;
}
/**
* @return Schema
*/
public function createFromSchema()
{
return $this->schemaManager->createSchema();
}
/**
* @param Schema $fromSchema
* @return Schema
*/
public function createToSchema(Schema $fromSchema)
{
return clone $fromSchema;
}
/**
* @param Schema $fromSchema
* @param Schema $toSchema
* @return string[]
*/
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema)
{
return $fromSchema->getMigrateToSql($toSchema, $this->platform);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
use Doctrine\DBAL\Schema\Schema;
/**
* Generates `Schema` objects to be passed to the migrations class.
*
* @since 1.3
*/
interface SchemaDiffProviderInterface
{
/**
* Create the schema that represent the current state of the database.
*
* @return Schema
*/
public function createFromSchema();
/**
* Create the schema that will represent the future state of the database
*
* @param Schema $fromSchema
* @return Schema
*/
public function createToSchema(Schema $fromSchema);
/**
* Return an array of sql statement that migrate the database state from the
* fromSchema to the toSchema.
*
* @param Schema $fromSchema
* @param Schema $toSchema
*
* @return string[]
*/
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema);
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
/**
* Generates `Schema` objects for the diff command. A schema provider should
* return the schema to which the database should be migrated.
*
* @since 1.0.0-alpha3
*/
interface SchemaProviderInterface
{
/**
* Create the schema to which the database should be migrated.
*
* @return \Doctrine\DBAL\Schema\Schema
*/
public function createSchema();
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Doctrine\DBAL\Migrations\Provider;
use Doctrine\DBAL\Schema\Schema;
/**
* A schemea provider implementation that just returns the schema its given.
*
* @since 1.0.0-alpha3
*/
final class StubSchemaProvider implements SchemaProviderInterface
{
/**
* @var Schema
*/
private $toSchema;
public function __construct(Schema $schema)
{
$this->toSchema = $schema;
}
/**
* {@inheritdoc}
*/
public function createSchema()
{
return $this->toSchema;
}
}