Files
ezmigrationbundle/Core/DefinitionParser/YamlDefinitionParser.php
2017-01-26 09:28:13 +01:00

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);
}
}