Example #1
0
 protected function getTemplateDataForModel($model)
 {
     $data = ['name' => Helper::get()->shortName($model), 'slug' => Helper::get()->slugify($model), 'properties' => []];
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     foreach ($properties as $property) {
         $name = $property->getName();
         $type = null;
         $targetEntity = null;
         $mappedBySlug = null;
         $propertyDefinition = ['name' => $name];
         if (($fieldAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Field')) !== null) {
             $type = $fieldAnnotation->type;
         } elseif (($referenceOneAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceOne')) !== null) {
             $name .= '.id';
             $type = 'reference';
             $targetEntity = Helper::get()->shortName($referenceOneAnnotation->targetDocument);
         } elseif (($referenceManyAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany')) !== null) {
             $type = 'referenced_list';
             $targetEntity = Helper::get()->shortName($referenceManyAnnotation->targetDocument);
             $mappedBySlug = Helper::get()->slugify($referenceManyAnnotation->mappedBy, false);
         } elseif ($reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Id') === null) {
             continue;
         }
         $propertyDefinition['name'] = $name;
         $propertyDefinition['type'] = $type;
         if ($targetEntity) {
             $propertyDefinition[$type] = ['targetEntity' => $targetEntity, 'targetEntitySlug' => Helper::get()->slugify($targetEntity), 'mappedBySlug' => $mappedBySlug];
         }
         $data['properties'][] = $propertyDefinition;
     }
     return $data;
 }
Example #2
0
 public function testCopyRecursiveWithFilter()
 {
     $helper = Helper::get();
     $root = vfsStream::setup('root', null, array('foo' => ['test' => ['test.txt' => 'test', 'test.json' => '[]']], 'bar' => []));
     $helper->copyRecursive($root->getChild('foo')->url(), $root->getChild('bar')->url(), '/\\.(?:json)$/');
     $this->assertEquals(null, $root->getChild('bar')->getChild('test')->getChild('test.txt'));
     $this->assertSame('[]', $root->getChild('bar')->getChild('test')->getChild('test.json')->getContent());
 }