Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     if (is_null($this->classes)) {
         $this->classes = Yaml::load($this->file);
     }
     // TODO validation
     if (isset($this->classes[$metadata->getClassName()])) {
         $yaml = $this->classes[$metadata->getClassName()];
         if (isset($yaml['constraints'])) {
             foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
                 $metadata->addConstraint($constraint);
             }
         }
         if (isset($yaml['properties'])) {
             foreach ($yaml['properties'] as $property => $constraints) {
                 foreach ($this->parseNodes($constraints) as $constraint) {
                     $metadata->addPropertyConstraint($property, $constraint);
                 }
             }
         }
         if (isset($yaml['getters'])) {
             foreach ($yaml['getters'] as $getter => $constraints) {
                 foreach ($this->parseNodes($constraints) as $constraint) {
                     $metadata->addGetterConstraint($getter, $constraint);
                 }
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Load configuration from file or array
  *
  * @param string|array $config
  */
 public function loadConfig($filename)
 {
     if (is_array($filename)) {
         $this->config = $filename;
     } else {
         $this->config = \Symfony\Components\Yaml\Yaml::load($filename);
     }
 }
 /**
  * Get an array of ClassMetadataInfo instances from the passed
  * Doctrine 1 schema
  *
  * @return array $metadatas  An array of ClassMetadataInfo instances
  */
 public function getMetadata()
 {
     $schema = array();
     foreach ($this->_from as $path) {
         if (is_dir($path)) {
             $files = glob($path . '/*.yml');
             foreach ($files as $file) {
                 $schema = array_merge($schema, (array) \Symfony\Components\Yaml\Yaml::load($file));
             }
         } else {
             $schema = array_merge($schema, (array) \Symfony\Components\Yaml\Yaml::load($path));
         }
     }
     $metadatas = array();
     foreach ($schema as $className => $mappingInformation) {
         $metadatas[] = $this->_convertToClassMetadataInfo($className, $mappingInformation);
     }
     return $metadatas;
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 protected function _load($file)
 {
     $array = Yaml::load($file);
     if (isset($array['table_name'])) {
         $this->setMigrationTableName($array['table_name']);
     }
     if (isset($array['new_migrations_directory'])) {
         $this->setNewMigrationsDirectory($array['new_migrations_directory']);
     }
     if (isset($array['directories']) && is_array($array['directories'])) {
         foreach ($array['directories'] as $directory) {
             $this->registerMigrationsFromDirectory($directory);
         }
     }
     if (isset($array['migrations']) && is_array($array['migrations'])) {
         foreach ($array['migrations'] as $migration) {
             $this->registerMigration($migration['version'], $migration['class']);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  */
 protected function _load($file)
 {
     $array = Yaml::load($file);
     if (isset($array['name'])) {
         $this->setName($array['name']);
     }
     if (isset($array['table_name'])) {
         $this->setMigrationsTableName($array['table_name']);
     }
     if (isset($array['migrations_namespace'])) {
         $this->setMigrationsNamespace($array['migrations_namespace']);
     }
     if (isset($array['migrations_directory'])) {
         $migrationsDirectory = $this->_getDirectoryRelativeToFile($file, $array['migrations_directory']);
         $this->setMigrationsDirectory($migrationsDirectory);
         $this->registerMigrationsFromDirectory($migrationsDirectory);
     }
     if (isset($array['migrations']) && is_array($array['migrations'])) {
         foreach ($array['migrations'] as $migration) {
             $this->registerMigration($migration['version'], $migration['class']);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 protected function _loadMappingFile($file)
 {
     return \Symfony\Components\Yaml\Yaml::load($file);
 }
Ejemplo n.º 7
0
 /**
  * Converts a single ClassMetadata instance to the exported format
  * and returns it
  *
  * TODO: Should this code be pulled out in to a toArray() method in ClassMetadata
  *
  * @param ClassMetadataInfo $metadata 
  * @return mixed $exported
  */
 public function exportClassMetadata(ClassMetadataInfo $metadata)
 {
     $array = array();
     if ($metadata->isMappedSuperclass) {
         $array['type'] = 'mappedSuperclass';
     } else {
         $array['type'] = 'entity';
     }
     $array['table'] = $metadata->table['name'];
     if (isset($metadata->table['schema'])) {
         $array['schema'] = $metadata->table['schema'];
     }
     $inheritanceType = $metadata->inheritanceType;
     if ($inheritanceType !== ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
         $array['inheritanceType'] = $this->_getInheritanceTypeString($inheritanceType);
     }
     if ($column = $metadata->discriminatorColumn) {
         $array['discriminatorColumn'] = $column;
     }
     if ($map = $metadata->discriminatorMap) {
         $array['discriminatorMap'] = $map;
     }
     if ($metadata->changeTrackingPolicy !== ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT) {
         $array['changeTrackingPolicy'] = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy);
     }
     if (isset($metadata->table['indexes'])) {
         $array['indexes'] = $metadata->table['indexes'];
     }
     if (isset($metadata->table['uniqueConstraints'])) {
         $array['uniqueConstraints'] = $metadata->table['uniqueConstraints'];
     }
     $fieldMappings = $metadata->fieldMappings;
     $ids = array();
     foreach ($fieldMappings as $name => $fieldMapping) {
         if (isset($fieldMapping['length'])) {
             $fieldMapping['type'] = $fieldMapping['type'] . '(' . $fieldMapping['length'] . ')';
             unset($fieldMapping['length']);
         }
         $fieldMapping['column'] = $fieldMapping['columnName'];
         unset($fieldMapping['columnName'], $fieldMapping['fieldName']);
         if ($fieldMapping['column'] == $name) {
             unset($fieldMapping['column']);
         }
         if (isset($fieldMapping['id']) && $fieldMapping['id']) {
             $ids[$name] = $fieldMapping;
             unset($fieldMappings[$name]);
             continue;
         }
         $fieldMappings[$name] = $fieldMapping;
     }
     if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
         $ids[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $this->_getIdGeneratorTypeString($metadata->generatorType);
     }
     if ($ids) {
         $array['fields'] = $ids;
     }
     if ($fieldMappings) {
         if (!isset($array['fields'])) {
             $array['fields'] = array();
         }
         $array['fields'] = array_merge($array['fields'], $fieldMappings);
     }
     $associations = array();
     foreach ($metadata->associationMappings as $name => $associationMapping) {
         $cascade = array();
         if ($associationMapping->isCascadeRemove) {
             $cascade[] = 'remove';
         }
         if ($associationMapping->isCascadePersist) {
             $cascade[] = 'persist';
         }
         if ($associationMapping->isCascadeRefresh) {
             $cascade[] = 'refresh';
         }
         if ($associationMapping->isCascadeMerge) {
             $cascade[] = 'merge';
         }
         if ($associationMapping->isCascadeDetach) {
             $cascade[] = 'detach';
         }
         $associationMappingArray = array('targetEntity' => $associationMapping->targetEntityName, 'cascade' => $cascade);
         if ($associationMapping instanceof OneToOneMapping) {
             $joinColumns = $associationMapping->joinColumns;
             $newJoinColumns = array();
             foreach ($joinColumns as $joinColumn) {
                 $newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName'];
                 if (isset($joinColumn['onDelete'])) {
                     $newJoinColumns[$joinColumn['name']]['onDelete'] = $joinColumn['onDelete'];
                 }
                 if (isset($joinColumn['onUpdate'])) {
                     $newJoinColumns[$joinColumn['name']]['onUpdate'] = $joinColumn['onUpdate'];
                 }
             }
             $oneToOneMappingArray = array('mappedBy' => $associationMapping->mappedBy, 'inversedBy' => $associationMapping->inversedBy, 'joinColumns' => $newJoinColumns, 'orphanRemoval' => $associationMapping->orphanRemoval);
             $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray);
             $array['oneToOne'][$name] = $associationMappingArray;
         } else {
             if ($associationMapping instanceof OneToManyMapping) {
                 $oneToManyMappingArray = array('mappedBy' => $associationMapping->mappedBy, 'inversedBy' => $associationMapping->inversedBy, 'orphanRemoval' => $associationMapping->orphanRemoval, 'orderBy' => $associationMapping->orderBy);
                 $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
                 $array['oneToMany'][$name] = $associationMappingArray;
             } else {
                 if ($associationMapping instanceof ManyToManyMapping) {
                     $manyToManyMappingArray = array('mappedBy' => $associationMapping->mappedBy, 'inversedBy' => $associationMapping->inversedBy, 'joinTable' => $associationMapping->joinTable, 'orderBy' => $associationMapping->orderBy);
                     $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);
                     $array['manyToMany'][$name] = $associationMappingArray;
                 }
             }
         }
     }
     if (isset($metadata->lifecycleCallbacks)) {
         $array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks;
     }
     return \Symfony\Components\Yaml\Yaml::dump(array($metadata->name => $array), 10);
 }
Ejemplo n.º 8
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Yaml\Yaml;
use Symfony\Components\Yaml\Inline;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(124);
// ::load()
$t->diag('::load()');
$testsForLoad = array('' => '', 'null' => null, 'false' => false, 'true' => true, '12' => 12, '"quoted string"' => 'quoted string', "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '0x4D2' => 0x4d2, '02333' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '123456789123456789' => '123456789123456789', '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), '[  foo  ,   bar , false  ,  null     ,  12  ]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo  : bar, bar : foo,  false  :   false,  null  :   null,  integer :  12  }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\'\'\': \'bar\', "bar\\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')), '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')), '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')), '[  foo, [  bar, foo  ]  ]' => array('foo', array('bar', 'foo')), '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))));
foreach ($testsForLoad as $yaml => $value) {
    $t->is(Inline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
}
$testsForDump = array('null' => null, 'false' => false, 'true' => true, '12' => 12, "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '1234' => 0x4d2, '1243' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')), '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')), '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))));
// ::dump()
$t->diag('::dump()');
foreach ($testsForDump as $yaml => $value) {
    $t->is(Inline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
}
foreach ($testsForLoad as $yaml => $value) {
    if ($value == 1230) {
        continue;
    }
    $t->is(Inline::load(Inline::dump($value)), $value, 'check consistency');
Ejemplo n.º 9
0
 public static function setUpBeforeClass()
 {
     Yaml::setSpecVersion('1.1');
 }
Ejemplo n.º 10
0
 protected function addParameters()
 {
     if (!$this->container->getParameters()) {
         return '';
     }
     return Yaml::dump(array('parameters' => $this->prepareParameters($this->container->getParameters())), 2);
 }
Ejemplo n.º 11
0
 protected function loadFile($file)
 {
     return $this->validate(Yaml::load($file), $file);
 }
Ejemplo n.º 12
0
 public function loadFile($file)
 {
     Debug::checkArgs(0, 1, 'string', $file, 1, 'nonempty', $file);
     if (!is_file($file) || !is_readable($file)) {
         throw new FtpException("{$file} is not readable or doesn’t exists.");
     }
     try {
         return ScYaml::load($file);
     } catch (\Symfony\Components\Yaml\ParserException $e) {
         throw new ParserException($e->getMessage());
     } catch (\InvalidArgumentException $e) {
         throw new ParserException($e->getMessage());
     }
 }
Ejemplo n.º 13
0
 protected function loadFile($file)
 {
     return Yaml::load($file);
 }
Ejemplo n.º 14
0
 protected function addParameters()
 {
     if (!$this->container->getParameterBag()->all()) {
         return '';
     }
     if ($this->container->isFrozen()) {
         $parameters = $this->prepareParameters($this->container->getParameterBag()->all());
     } else {
         $parameters = $this->container->getParameterBag()->all();
     }
     return Yaml::dump(array('parameters' => $parameters), 2);
 }