コード例 #1
0
ファイル: DefinitionTest.php プロジェクト: alebon/graviton
 /**
  * Get field by path
  *
  * @param JsonDefinition $definition JSON definition
  * @param string         $path       Path to field
  * @return DefinitionElementInterface
  */
 private function getFieldByPath(JsonDefinition $definition, $path)
 {
     $items = explode('.', $path);
     $field = $definition->getField(array_shift($items));
     foreach ($items as $item) {
         if ($item === '0') {
             if (!$field instanceof JsonDefinitionArray) {
                 throw new \InvalidArgumentException(sprintf('Error path: "%s"', $path));
             }
             $field = $field->getElement();
         } else {
             if (!$field instanceof JsonDefinitionHash) {
                 throw new \InvalidArgumentException(sprintf('Error path: "%s"', $path));
             }
             $field = $field->getJsonDefinition()->getField($item);
         }
     }
     return $field;
 }
コード例 #2
0
 /**
  * Returns the field string as described in the json file
  *
  * @param JsonDefinition $jsonDef The json def
  *
  * @return string CommandLine string for the generator command
  */
 private function getFieldString(JsonDefinition $jsonDef)
 {
     $ret = array();
     foreach ($jsonDef->getFields() as $field) {
         // don't add 'id' field it seems..
         if ($field->getName() != 'id') {
             $ret[] = $field->getName() . ':' . $field->getTypeDoctrine();
         }
     }
     return implode(' ', $ret);
 }
コード例 #3
0
ファイル: ResourceGenerator.php プロジェクト: alebon/graviton
 /**
  * generates fixtures
  *
  * @param array  $parameters twig parameters
  * @param string $dir        base bundle dir
  * @param string $document   document name
  *
  * @return void
  */
 protected function generateFixtures(array $parameters, $dir, $document)
 {
     $parameters['fixtures_json'] = addcslashes(json_encode($this->json->getFixtures()), "'");
     $parameters['fixtureOrder'] = $this->json->getFixtureOrder();
     $this->renderFile('fixtures/LoadFixtures.php.twig', $dir . '/DataFixtures/MongoDB/Load' . $document . 'Data.php', $parameters);
 }
コード例 #4
0
 /**
  * Test JsonDefinitionHash::getJsonDefinition()
  *
  * @return void
  */
 public function testGetJsonDefinition()
 {
     $parent = new JsonDefinition((new Schema\Definition())->setId('Parent')->setTarget((new Schema\Target())->setFields([(new Schema\Field())->setName('hash')->setType('hash')->setDescription('description'), (new Schema\Field())->setName('hash.b')->setType('class:B'), (new Schema\Field())->setName('hash.c')->setType('class:C[]'), (new Schema\Field())->setName('hash.d')->setType(JsonDefinitionHash::TYPE_BOOLEAN)])->setRelations([(new Schema\Relation())->setType(JsonDefinitionHash::REL_TYPE_EMBED)->setLocalProperty('hash.b'), (new Schema\Relation())->setType(JsonDefinitionHash::REL_TYPE_REF)->setLocalProperty('hash.c')])));
     /** @var JsonDefinitionHash $field */
     $field = $parent->getField('hash');
     $this->assertInstanceOf('Graviton\\GeneratorBundle\\Definition\\JsonDefinitionHash', $field);
     $this->assertEquals(new JsonDefinition((new Schema\Definition())->setId('ParentHash')->setDescription('description')->setIsSubDocument(true)->setTarget((new Schema\Target())->setFields([(new Schema\Field())->setName('b')->setType('class:B'), (new Schema\Field())->setName('c')->setType('class:C[]'), (new Schema\Field())->setName('d')->setType(JsonDefinitionHash::TYPE_BOOLEAN)])->setRelations([(new Schema\Relation())->setType(JsonDefinitionHash::REL_TYPE_EMBED)->setLocalProperty('b'), (new Schema\Relation())->setType(JsonDefinitionHash::REL_TYPE_REF)->setLocalProperty('c')]))), $field->getJsonDefinition());
 }