本文整理匯總了PHP中Doctrine\DBAL\Migrations\Configuration\Configuration::getMigrationsNamespace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Configuration::getMigrationsNamespace方法的具體用法?PHP Configuration::getMigrationsNamespace怎麽用?PHP Configuration::getMigrationsNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Migrations\Configuration\Configuration
的用法示例。
在下文中一共展示了Configuration::getMigrationsNamespace方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getMigrationsInfos
public function getMigrationsInfos()
{
$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));
$infos = ['Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), 'Database Name' => $this->configuration->getConnection()->getDatabase(), 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', 'Version Table Name' => $this->configuration->getMigrationsTableName(), 'Version Column Name' => $this->configuration->getMigrationsColumnName(), 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), 'Previous Version' => $this->getFormattedVersionAlias('prev'), 'Current Version' => $this->getFormattedVersionAlias('current'), 'Next Version' => $this->getFormattedVersionAlias('next'), 'Latest Version' => $this->getFormattedVersionAlias('latest'), 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
return $infos;
}
示例2: configureMigrations
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
{
if (!$configuration->getMigrationsDirectory()) {
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
} else {
$dir = $configuration->getMigrationsDirectory();
// class Kernel has method getKernelParameters with some of the important path parameters
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
foreach ($pathPlaceholderArray as $pathPlaceholder) {
if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
$dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
}
}
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
}
if (!$configuration->getMigrationsNamespace()) {
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
}
if (!$configuration->getName()) {
$configuration->setName($container->getParameter('doctrine_migrations.name'));
}
// For backward compatibility, need use a table from parameters for overwrite the default configuration
if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}
// Migrations is not register from configuration loader
if (!$configuration instanceof AbstractFileConfiguration) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
}
if ($container->hasParameter('doctrine_migrations.organize_migrations')) {
$organizeMigrations = $container->getParameter('doctrine_migrations.organize_migrations');
switch ($organizeMigrations) {
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR:
$configuration->setMigrationsAreOrganizedByYear(true);
break;
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
$configuration->setMigrationsAreOrganizedByYearAndMonth(true);
break;
case false:
break;
default:
throw new InvalidConfigurationException('Unrecognized option "' . $organizeMigrations . '" under "organize_migrations"');
}
}
self::injectContainerToMigrations($container, $configuration->getMigrations());
}
示例3: getMigrationsInfos
public function getMigrationsInfos()
{
$formattedVersions = [];
foreach (['prev', 'current', 'next', 'latest'] as $alias) {
$version = $this->configuration->resolveVersionAlias($alias);
if ($version === null) {
if ($alias == 'next') {
$formattedVersions[$alias] = 'Already at latest version';
} elseif ($alias == 'prev') {
$formattedVersions[$alias] = 'Already at first version';
}
} elseif ($version === '0') {
$formattedVersions[$alias] = '<comment>0</comment>';
} else {
$formattedVersions[$alias] = $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
}
}
$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));
$infos = ['Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), 'Database Name' => $this->configuration->getConnection()->getDatabase(), 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', 'Version Table Name' => $this->configuration->getMigrationsTableName(), 'Version Column Name' => $this->configuration->getMigrationsColumnName(), 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), 'Previous Version' => $formattedVersions['prev'], 'Current Version' => $formattedVersions['current'], 'Next Version' => $formattedVersions['next'], 'Latest Version' => $formattedVersions['latest'], 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
return $infos;
}
示例4: _generateMigration
protected function _generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
{
$placeHolders = array('<namespace>', '<version>', '<up>', '<down>');
$replacements = array($configuration->getMigrationsNamespace(), $version, $up ? " " . implode("\n ", explode("\n", $up)) : null, $down ? " " . implode("\n ", explode("\n", $down)) : null);
$code = str_replace($placeHolders, $replacements, self::$_template);
$dir = $configuration->getMigrationsDirectory();
$dir = $dir ? $dir : getcwd();
$dir = rtrim($dir, '/');
$path = $dir . '/Version' . $version . '.php';
file_put_contents($path, $code);
if ($editorCmd = $input->getOption('editor-cmd')) {
shell_exec($editorCmd . ' ' . escapeshellarg($path));
}
return $path;
}
示例5: generateMigration
protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
{
$placeHolders = ['<namespace>', '<version>', '<up>', '<down>'];
$replacements = [$configuration->getMigrationsNamespace(), $version, $up ? ' ' . implode("\n ", explode("\n", $up)) : null, $down ? ' ' . implode("\n ", explode("\n", $down)) : null];
$code = str_replace($placeHolders, $replacements, $this->template);
$dir = $configuration->getMigrationsDirectory();
$dir = $dir ? $dir : getcwd();
$dir = rtrim($dir, '/');
$path = $dir . '/Version' . $version . '.php';
if (!file_exists($dir)) {
// @codeCoverageIgnoreStart
throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
// @codeCoverageIgnoreEnd
}
file_put_contents($path, $code);
if ($editorCmd = $input->getOption('editor-cmd')) {
shell_exec($editorCmd . ' ' . escapeshellarg($path));
}
return $path;
}
示例6: configureMigrations
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
{
if (!$configuration->getMigrationsDirectory()) {
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
} else {
$dir = $configuration->getMigrationsDirectory();
// class Kernel has method getKernelParameters with some of the important path parameters
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
foreach ($pathPlaceholderArray as $pathPlaceholder) {
if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
$dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
}
}
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
}
if (!$configuration->getMigrationsNamespace()) {
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
}
if (!$configuration->getName()) {
$configuration->setName($container->getParameter('doctrine_migrations.name'));
}
// For backward compatibility, need use a table from parameters for overwrite the default configuration
if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}
// Migrations is not register from configuration loader
if (!$configuration instanceof AbstractFileConfiguration) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
}
self::injectContainerToMigrations($container, $configuration->getMigrations());
}
示例7: writeMigrationClassToFile
/**
* @param \Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
* @param string $up
* @param string $down
* @return string
* @throws \RuntimeException
*/
protected function writeMigrationClassToFile(\Doctrine\DBAL\Migrations\Configuration\Configuration $configuration, $up, $down)
{
$namespace = $configuration->getMigrationsNamespace();
$className = 'Version' . date('YmdHis');
$up = $up === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $up));
$down = $down === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $down));
$path = \TYPO3\Flow\Utility\Files::concatenatePaths(array($configuration->getMigrationsDirectory(), $className . '.php'));
try {
\TYPO3\Flow\Utility\Files::createDirectoryRecursively(dirname($path));
} catch (\TYPO3\Flow\Utility\Exception $exception) {
throw new \RuntimeException(sprintf('Migration target directory "%s" does not exist.', dirname($path)), 1303298536, $exception);
}
$code = <<<EOT
<?php
namespace {$namespace};
use Doctrine\\DBAL\\Migrations\\AbstractMigration,
\tDoctrine\\DBAL\\Schema\\Schema;
/**
* Auto-generated Migration: Please modify to your need!
*/
class {$className} extends AbstractMigration {
\t/**
\t * @param Schema \$schema
\t * @return void
\t */
\tpublic function up(Schema \$schema) {
\t\t// this up() migration is autogenerated, please modify it to your needs{$up}
\t}
\t/**
\t * @param Schema \$schema
\t * @return void
\t */
\tpublic function down(Schema \$schema) {
\t\t// this down() migration is autogenerated, please modify it to your needs{$down}
\t}
}
EOT;
file_put_contents($path, $code);
return $path;
}
示例8: writeMigrationClassToFile
/**
* @param Configuration $configuration
* @param string $up
* @param string $down
* @return string
* @throws \RuntimeException
*/
protected function writeMigrationClassToFile(Configuration $configuration, $up, $down)
{
$namespace = $configuration->getMigrationsNamespace();
$className = 'Version' . date('YmdHis');
$up = $up === null ? '' : "\n " . implode("\n ", explode("\n", $up));
$down = $down === null ? '' : "\n " . implode("\n ", explode("\n", $down));
$path = Files::concatenatePaths(array($configuration->getMigrationsDirectory(), $className . '.php'));
try {
Files::createDirectoryRecursively(dirname($path));
} catch (Exception $exception) {
throw new \RuntimeException(sprintf('Migration target directory "%s" does not exist.', dirname($path)), 1303298536, $exception);
}
$code = <<<EOT
<?php
namespace {$namespace};
use Doctrine\\DBAL\\Migrations\\AbstractMigration;
use Doctrine\\DBAL\\Schema\\Schema;
/**
* Auto-generated Migration: Please modify to your needs! This block will be used as the migration description if getDescription() is not used.
*/
class {$className} extends AbstractMigration
{
/**
* @return string
*/
public function getDescription() {
return '';
}
/**
* @param Schema \$schema
* @return void
*/
public function up(Schema \$schema)
{
// this up() migration is autogenerated, please modify it to your needs{$up}
}
/**
* @param Schema \$schema
* @return void
*/
public function down(Schema \$schema)
{
// this down() migration is autogenerated, please modify it to your needs{$down}
}
}
EOT;
file_put_contents($path, $code);
return $path;
}
示例9: generateMigration
protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
{
$placeHolders = ['<namespace>', '<version>', '<up>', '<down>'];
$replacements = [$configuration->getMigrationsNamespace(), $version, $up ? " " . implode("\n ", explode("\n", $up)) : null, $down ? " " . implode("\n ", explode("\n", $down)) : null];
$code = str_replace($placeHolders, $replacements, $this->getTemplate());
$code = preg_replace('/^ +$/m', '', $code);
$migrationDirectoryHelper = new MigrationDirectoryHelper($configuration);
$dir = $migrationDirectoryHelper->getMigrationDirectory();
$path = $dir . '/Version' . $version . '.php';
file_put_contents($path, $code);
if ($editorCmd = $input->getOption('editor-cmd')) {
proc_open($editorCmd . ' ' . escapeshellarg($path), [], $pipes);
}
return $path;
}
示例10: generateMigration
protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
{
$placeHolders = ['<namespace>', '<version>', '<up>', '<down>'];
$replacements = [$configuration->getMigrationsNamespace(), $version, $up ? " " . implode("\n ", explode("\n", $up)) : null, $down ? " " . implode("\n ", explode("\n", $down)) : null];
$code = str_replace($placeHolders, $replacements, self::$_template);
$code = preg_replace('/^ +$/m', '', $code);
$dir = $configuration->getMigrationsDirectory();
$dir = $dir ? $dir : getcwd();
$dir = rtrim($dir, '/');
$path = $dir . '/Version' . $version . '.php';
if (!file_exists($dir)) {
throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
}
file_put_contents($path, $code);
if ($editorCmd = $input->getOption('editor-cmd')) {
proc_open($editorCmd . ' ' . escapeshellarg($path), [], $pipes);
}
return $path;
}
示例11: writeMigrationClassToFile
/**
* writes given migrations scripts to migration file
*
* @param Configuration $configuration the doctrine migrations configuration
* @param string $up sql query for up
* @param string $down sql query for down
*
* @return string
*/
protected function writeMigrationClassToFile(\Doctrine\DBAL\Migrations\Configuration\Configuration $configuration, $up, $down)
{
$namespace = $configuration->getMigrationsNamespace();
$className = 'Version' . date('YmdHis');
$up = $up === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $up));
$down = $down === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $down));
$path = $this->getMigrationsDirectory() . DIRECTORY_SEPARATOR . $className . '.php';
$code = <<<EOT
<?php
namespace {$namespace};
use Doctrine\\DBAL\\Migrations\\AbstractMigration;
use Doctrine\\DBAL\\Schema\\Schema;
class {$className} extends AbstractMigration
{
\t/**
\t * up
\t *
\t * @param Schema \$schema the schema
*
\t * @return void
\t */
\tpublic function up(Schema \$schema)
\t{
\t\t{$up}
\t}
\t/**
\t * down
\t *
\t * @param Schema \$schema the schema
\t *
\t * @return void
\t */
\tpublic function down(Schema \$schema)
\t{
\t\t{$down}
\t}
}
EOT;
file_put_contents($path, $code);
return $path;
}