mirror of
https://github.com/JBDevLabs/ezmigrationbundle.git
synced 2026-03-24 08:52:16 +01:00
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Kaliop\eZMigrationBundle\Core\DefinitionParser;
|
|
|
|
use Kaliop\eZMigrationBundle\API\DefinitionParserInterface;
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
/**
|
|
* Handles Yaml migration definitions.
|
|
*/
|
|
class YamlDefinitionParser extends AbstractDefinitionParser implements DefinitionParserInterface
|
|
{
|
|
/**
|
|
* Tells whether the given file can be handled by this handler, by checking e.g. the suffix
|
|
*
|
|
* @param string $migrationName typically a filename
|
|
* @return bool
|
|
*/
|
|
public function supports($migrationName)
|
|
{
|
|
$ext = pathinfo($migrationName, PATHINFO_EXTENSION);
|
|
return $ext == 'yml' || $ext == 'yaml';
|
|
}
|
|
|
|
/**
|
|
* Parses a migration definition file, and returns the list of actions to take
|
|
*
|
|
* @param MigrationDefinition $definition
|
|
* @return MigrationDefinition
|
|
*/
|
|
public function parseMigrationDefinition(MigrationDefinition $definition)
|
|
{
|
|
try {
|
|
$data = Yaml::parse($definition->rawDefinition);
|
|
} catch (\Exception $e) {
|
|
return new MigrationDefinition(
|
|
$definition->name,
|
|
$definition->path,
|
|
$definition->rawDefinition,
|
|
MigrationDefinition::STATUS_INVALID,
|
|
array(),
|
|
$e->getMessage()
|
|
);
|
|
}
|
|
|
|
return $this->parseMigrationDefinitionData($data, $definition);
|
|
}
|
|
}
|