mirror of
https://github.com/jbcr/ezmigrationbundle.git
synced 2026-03-24 08:52:08 +01:00
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Kaliop\eZMigrationBundle\Core\DefinitionParser;
|
|
|
|
use Kaliop\eZMigrationBundle\API\DefinitionParserInterface;
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
|
|
|
|
/**
|
|
* Handles Json migration definitions.
|
|
*/
|
|
class JsonDefinitionParser 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 == 'json';
|
|
}
|
|
|
|
/**
|
|
* 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 = json_decode($definition->rawDefinition, true);
|
|
} catch (\Exception $e) {
|
|
return new MigrationDefinition(
|
|
$definition->name,
|
|
$definition->path,
|
|
$definition->rawDefinition,
|
|
MigrationDefinition::STATUS_INVALID,
|
|
array(),
|
|
$e->getMessage()
|
|
);
|
|
}
|
|
|
|
return $this->parseMigrationDefinitionData($data, $definition, 'Json');
|
|
}
|
|
}
|