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,133 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration;
use Doctrine\DBAL\Migrations\MigrationException;
/**
* Abstract Migration Configuration class for loading configuration information
* from a configuration file (xml or yml).
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
abstract class AbstractFileConfiguration extends Configuration
{
/**
* The configuration file used to load configuration information
*
* @var string
*/
private $file;
/**
* Whether or not the configuration file has been loaded yet or not
*
* @var boolean
*/
private $loaded = false;
/**
* @var array of possible configuration properties in migrations configuration.
*/
private $configurationProperties = [
'migrations_namespace' => 'setMigrationsNamespace',
'table_name' => 'setMigrationsTableName',
'column_name' => 'setMigrationsColumnName',
'organize_migrations' => 'setMigrationOrganisation',
'name' => 'setName',
'migrations_directory' => 'loadMigrationsFromDirectory',
'migrations' => 'loadMigrations',
'custom_template' => 'setCustomTemplate',
];
protected function setConfiguration(array $config)
{
foreach ($config as $configurationKey => $configurationValue) {
if ( ! isset($this->configurationProperties[$configurationKey])) {
$msg = sprintf('Migrations configuration key "%s" does not exist.', $configurationKey);
throw MigrationException::configurationNotValid($msg);
}
}
foreach ($this->configurationProperties as $configurationKey => $configurationSetter) {
if (isset($config[$configurationKey])) {
$this->{$configurationSetter}($config[$configurationKey]);
}
}
}
private function loadMigrationsFromDirectory($migrationsDirectory)
{
$this->setMigrationsDirectory($migrationsDirectory);
$this->registerMigrationsFromDirectory($migrationsDirectory);
}
private function loadMigrations($migrations)
{
if (is_array($migrations)) {
foreach ($migrations as $migration) {
$this->registerMigration($migration['version'], $migration['class']);
}
}
}
private function setMigrationOrganisation($migrationOrganisation)
{
if (strcasecmp($migrationOrganisation, static::VERSIONS_ORGANIZATION_BY_YEAR) == 0) {
$this->setMigrationsAreOrganizedByYear();
} elseif (strcasecmp($migrationOrganisation, static::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) == 0) {
$this->setMigrationsAreOrganizedByYearAndMonth();
} else {
$msg = 'Unknown ' . var_export($migrationOrganisation, true) . ' for configuration "organize_migrations".';
throw MigrationException::configurationNotValid($msg);
}
}
/**
* Load the information from the passed configuration file
*
* @param string $file The path to the configuration file
*
* @throws MigrationException Throws exception if configuration file was already loaded
*/
public function load($file)
{
if ($this->loaded) {
throw MigrationException::configurationFileAlreadyLoaded();
}
if (file_exists($path = getcwd() . '/' . $file)) {
$file = $path;
}
$this->file = $file;
if ( ! file_exists($file)) {
throw new \InvalidArgumentException('Given config file does not exist');
}
$this->doLoad($file);
$this->loaded = true;
}
protected function getDirectoryRelativeToFile($file, $input)
{
$path = realpath(dirname($file) . '/' . $input);
return ($path !== false) ? $path : $input;
}
public function getFile()
{
return $this->file;
}
/**
* Abstract method that each file configuration driver must implement to
* load the given configuration file whether it be xml, yaml, etc. or something
* else.
*
* @param string $file The path to a configuration file.
*/
abstract protected function doLoad($file);
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration;
/**
* Load migration configuration information from a PHP configuration file.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author David Havl <contact@davidhavl.com>
*/
class ArrayConfiguration extends AbstractFileConfiguration
{
/**
* @inheritdoc
*/
protected function doLoad($file)
{
$config = require $file;
if (isset($config['migrations_directory'])) {
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, $config['migrations_directory']);
}
$this->setConfiguration($config);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration\Connection;
use Doctrine\DBAL\Connection;
interface ConnectionLoaderInterface
{
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen();
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
class ArrayConnectionConfigurationLoader implements ConnectionLoaderInterface
{
private $filename;
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if (empty($this->filename)) {
return null;
}
if ( ! file_exists($this->filename)) {
return null;
}
$params = include $this->filename;
if ( ! is_array($params)) {
throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
}
return DriverManager::getConnection($params);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
final class ConnectionConfigurationChainLoader implements ConnectionLoaderInterface
{
/** @var ConnectionLoaderInterface[] */
private $loaders;
public function __construct(array $loaders)
{
$this->loaders = $loaders;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
foreach ($this->loaders as $loader) {
if (null !== $confObj = $loader->chosen()) {
return $confObj;
}
}
return null;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
class ConnectionConfigurationLoader implements ConnectionLoaderInterface
{
/** @var Configuration */
private $configuration;
public function __construct(Configuration $configuration = null)
{
if ($configuration !== null) {
$this->configuration = $configuration;
}
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if ($this->configuration) {
return $this->configuration->getConnection();
}
return null;
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Symfony\Component\Console\Helper\HelperSet;
class ConnectionHelperLoader implements ConnectionLoaderInterface
{
/**
* @var string
*/
private $helperName;
/** @var HelperSet */
private $helperSet;
/**
* ConnectionHelperLoader constructor.
* @param HelperSet $helperSet
* @param string $helperName
*/
public function __construct(HelperSet $helperSet = null, $helperName)
{
$this->helperName = $helperName;
if ($helperSet === null) {
$helperSet = new HelperSet();
}
$this->helperSet = $helperSet;
}
/**
* read the input and return a Configuration, returns `false` if the config
* is not supported
* @return Connection|null
*/
public function chosen()
{
if ($this->helperSet->has($this->helperName)) {
$connectionHelper = $this->helperSet->get($this->helperName);
if ($connectionHelper instanceof ConnectionHelper) {
return $connectionHelper->getConnection();
}
}
return null;
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration;
/**
* Load migration configuration information from a PHP configuration file.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author David Havl <contact@davidhavl.com>
*/
class JsonConfiguration extends AbstractFileConfiguration
{
/**
* @inheritdoc
*/
protected function doLoad($file)
{
$config = json_decode(file_get_contents($file), true);
if (isset($config['migrations_directory'])) {
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, $config['migrations_directory']);
}
$this->setConfiguration($config);
}
}

View File

@@ -0,0 +1,40 @@
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://doctrine-project.org/schemas/migrations/configuration"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="doctrine-migrations">
<xs:complexType>
<xs:all minOccurs="0">
<xs:element type="xs:string" name="name" minOccurs="0" maxOccurs="1"/>
<xs:element type="xs:string" name="migrations-namespace" minOccurs="0" maxOccurs="1"/>
<xs:element name="table" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="column"/>
</xs:complexType>
</xs:element>
<xs:element name="organize-migrations" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="((y|Y)(e|E)(a|A)(r|R))|((y|Y)(e|E)(a|A)(r|R)_(a|A)(n|N)(d|D)_(m|M)(o|O)(n|N)(t|T)(h|H))"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element type="xs:string" name="migrations-directory" minOccurs="0" maxOccurs="1"/>
<xs:element name="migrations" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="migration">
<xs:complexType mixed="true">
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="class" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -0,0 +1,57 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration;
use Doctrine\DBAL\Migrations\MigrationException;
/**
* Load migration configuration information from a XML configuration file.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class XmlConfiguration extends AbstractFileConfiguration
{
/**
* @inheritdoc
*/
protected function doLoad($file)
{
libxml_use_internal_errors(true);
$xml = new \DOMDocument();
$xml->load($file);
if ( ! $xml->schemaValidate(__DIR__ . DIRECTORY_SEPARATOR . "XML" . DIRECTORY_SEPARATOR . "configuration.xsd")) {
libxml_clear_errors();
throw MigrationException::configurationNotValid('XML configuration did not pass the validation test.');
}
$xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
$config = [];
if (isset($xml->name)) {
$config['name'] = (string) $xml->name;
}
if (isset($xml->table['name'])) {
$config['table_name'] = (string) $xml->table['name'];
}
if (isset($xml->table['column'])) {
$config['column_name'] = (string) $xml->table['column'];
}
if (isset($xml->{'migrations-namespace'})) {
$config['migrations_namespace'] = (string) $xml->{'migrations-namespace'};
}
if (isset($xml->{'organize-migrations'})) {
$config['organize_migrations'] = $xml->{'organize-migrations'};
}
if (isset($xml->{'migrations-directory'})) {
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'});
}
if (isset($xml->migrations->migration)) {
$config['migrations'] = $xml->migrations->migration;
}
$this->setConfiguration($config);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Doctrine\DBAL\Migrations\Configuration;
use Symfony\Component\Yaml\Yaml;
use Doctrine\DBAL\Migrations\MigrationException;
/**
* Load migration configuration information from a YAML configuration file.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class YamlConfiguration extends AbstractFileConfiguration
{
/**
* @inheritdoc
*/
protected function doLoad($file)
{
if ( ! class_exists(Yaml::class)) {
throw MigrationException::yamlConfigurationNotAvailable();
}
$config = Yaml::parse(file_get_contents($file));
if ( ! is_array($config)) {
throw new \InvalidArgumentException('Not valid configuration.');
}
if (isset($config['migrations_directory'])) {
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, $config['migrations_directory']);
}
$this->setConfiguration($config);
}
}