/** * * public function doCompileImage() { * $this->doCompileImage('Image', function ($help) { * extract($help); * * }); * } * * @param Closure $doCompile(Array $help) */ public function doCompileImage($entityName = 'Image', Closure $doCompile = NULL, $tableName = 'images') { extract($help = $this->help()); if (!isset($doCompile)) { $doCompile = function () { }; } return $this->getModelCompiler()->compile($entity($entityName, $extends('Psc\\Doctrine\\Entities\\BasicImage2')), $defaultId(), $property('sourcePath', $type('String')), $property('hash', $type('String'), $unique()), $property('label', $type('String'), $nullable()), $constructor($argument('sourcePath', NULL), $argument('label', NULL), $argument('hash', NULL)), $getGClass()->createMethod('triggerRemoved', array(), array('return parent::triggerRemoved();'))->getDocBlock(TRUE)->addAnnotation(Annotation::createDC('PostRemove')), $doCompile($help)); }
public function createClassMetadata(GClass $gClass) { // da wir gClass mehrmals im Test evalen könnten, erzeugen wir einen unique hash für den classname und übergeben den // der class metadata $className = uniqid($gClass->getClassName()); $gClass->setClassName($className); $gClass->createDocBlock()->addAnnotation(Annotation::createDC('Entity')); $classWriter = new ClassWriter($gClass); $classWriter->setUseStyle('lines'); $classWriter->addImport(new GClass('Doctrine\\ORM\\Mapping'), 'ORM'); // braucht einen AnnotationReader nicht SimpleAnnotationReader $classWriter->write($file = $this->newFile('entity.' . $gClass->getClassName() . '.php')); require $file; $cm = new ClassMetadata($gClass->getFQN()); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService()); $this->annotationDriver->loadMetadataForClass($gClass->getFQN(), $cm); $file->delete(); return $cm; }
/** * @param array $orders dbField => ASC|DESC, dbField2 => ASC|DESC usw */ public function setOrderBy(array $orders) { //@OrderBy({"name" = "ASC"}) $this->orderBy = Annotation::createDC('OrderBy')->setValue($orders); return $this; }
public function testGetAnnotionsFilter() { $this->docBlock->addAnnotation(Annotation::createDC('Id')); $this->docBlock->addAnnotation(Annotation::createDC('Id')); $this->docBlock->addAnnotation(Annotation::createDC('Column')); $this->assertCount(3, $this->docBlock->getAnnotations()); $this->assertCount(1, $this->docBlock->getAnnotations('Doctrine\\ORM\\Mapping\\Column')); $this->assertCount(2, $this->docBlock->getAnnotations('Doctrine\\ORM\\Mapping\\Id')); }
public function createDefaultClassDocBlock() { $entityProperties = array(); if ($this->withRepository) { $entityProperties['repositoryClass'] = $this->getRepositoryGClass()->getFQN(); } $docBlock = $this->class->getDocBlock(TRUE); // autocreate aber get, damit wir vorher schon annotations hinzufügen können $entity = Annotation::createDC('Entity', $entityProperties); if (!$docBlock->hasAnnotation($entity->getAnnotationName())) { $docBlock->addAnnotation($entity); } $table = Annotation::createDC('Table', array('name' => $this->getTableName())); if (!$docBlock->hasAnnotation($table->getAnnotationName())) { $docBlock->addAnnotation($table); } return $this; }
/** * ManyToOne self-referencing: * child(ren)<->parent * * @ORM\ManyToOne(targetEntity="CoMun\Entities\NavigationNode", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL") * protected $parent; */ public function testOneToManySelfReferencing() { $relation = new EntityRelation($this->child, $this->parent, EntityRelation::MANY_TO_ONE, EntityRelation::SELF_REFERENCING, 'source'); $relation->setJoinColumnNullable(true); //$relation->getJoinTable()->setName('game_unlocks'); $relation->addAnnotationsForSource($docBlock = new DocBlock()); $this->assertHasRelationAnnotation('ManyToOne', array('targetEntity' => 'CoMun\\Entities\\NavigationNode', 'inversedBy' => 'children'), $docBlock); $joinColumn = Annotation::createDC('JoinColumn', array('name' => null, 'referencedColumnName' => 'id', 'onDelete' => 'SET NULL')); $this->assertEquals($joinColumn, $this->assertHasDCAnnotation($docBlock, 'JoinColumn')); }
/** * Gibt alle Helpers für DoctrineAnnotations (oder andere) zurück * * Jeder Closure-Helper stellt eine Annotation dar und gibt für diese ein explizites interface: * * - $joinTable($name, $joinColumn(s), $inverseJoinColumn(s)) * für die columns kann ein array angegeben werden, muss aber nicht * * - $joinColumn($name, $referencedColumnName, $onDelete) * * - $manyToMany($targetEntity, $inversedBy($propertyName), Array $cascade, $fetch) * - $manyToMany($targetEntity, $mappedBy($propertyName), Array $cascade, $fetch) * - $oneToMany($targetEntity, $mappedBy($propertyName), Array $cascade, $fetch) * - $ManyToOne($targetEntity, $inversedBy($propertyName), Array $cascade, $fetch) * * - $inversedBy($propertyName) * - $mappedBy($propertyName) * * - $doctrineAnnotation($name) * erzeugt eine Doctrine\ORM\Mapping\$name - Psc\Doctrine\Annotation * * @return Array */ public static function getClosureHelpers() { // constructor $doctrineAnnotation = function ($shortName, array $properties = array()) { return \Psc\Doctrine\Annotation::createDC($shortName)->setProperties($properties); }; // others $joinColumn = function ($name, $referencedColumnName = 'id', $onDelete = NULL) use($doctrineAnnotation) { $properties = compact('name', 'referencedColumnName', 'onDelete'); return $doctrineAnnotation('joinColumn', $properties); }; $joinTable = function ($name, $joinColumns = array(), $inverseJoinColumns = array()) use($doctrineAnnotation) { if (!is_array($joinColumns)) { $joinColumns = array($joinColumns); } if (!is_array($inverseJoinColumns)) { $inverseJoinColumns = array($inverseJoinColumns); } $properties = compact('name', 'joinColumns', 'inverseJoinColumns'); return $doctrineAnnotation('joinTable', $properties); }; // Relations $manyToMany = function ($targetEntity, array $inversedOrMapped = array(), array $cascade = NULL, $fetch = 'LAZY') use($doctrineAnnotation) { $properties = array_merge(compact('targetEntity', 'cascade', 'fetch'), $inversedOrMapped); // inversedOrMapped fügt dann inversedBy oder mappedBy den Properties hinzu return $doctrineAnnotation('ManyToMany', $properties); }; $oneToMany = function ($targetEntity, array $mapped = array(), array $cascade = NULL, $fetch = 'LAZY') use($doctrineAnnotation) { $properties = array_merge(compact('targetEntity', 'cascade', 'fetch'), $mapped); return $doctrineAnnotation('OneToMany', $properties); }; $manyToOne = function ($targetEntity, array $inversed = array(), array $cascade = NULL, $fetch = 'LAZY') use($doctrineAnnotation) { $properties = array_merge(compact('targetEntity', 'cascade', 'fetch'), $inversed); return $doctrineAnnotation('ManyToOne', $properties); }; $oneToOne = function ($targetEntity, array $inversedOrMapped = array(), array $cascade = NULL, $fetch = 'LAZY') use($doctrineAnnotation) { $properties = array_merge(compact('targetEntity', 'cascade', 'fetch'), $inversedOrMapped); return $doctrineAnnotation('OneToOne', $properties); }; // HelpersHelpers $inversedBy = function ($propertyName) { return array('inversedBy' => $propertyName); }; $mappedBy = function ($propertyName) { return array('mappedBy' => $propertyName); }; return compact('inversedBy', 'mappedBy', 'oneToOne', 'manyToMany', 'manyToOne', 'oneToMany', 'joinTable', 'joinColumn'); }
public function testAliasWriting() { $this->assertEquals('@ORM\\Entity', $this->createAliasWriter()->writeAnnotation(\Psc\Doctrine\Annotation::createDC('Entity'))); }
/** * @return EntityBuilder */ public function compile(EntityBuilder $eb) { if ($eb !== $this->entityBuilder) { throw new \Psc\Exception('Eigentlich sollten Parameter1 und $this->eb identisch sein. Wurde $entity() (setEntityBuilder) benutzt?'); } /* in den Parametern können Relations sein mit $relation erstellt, die wir auch noch hinzufügen wollen */ foreach (array_slice(func_get_args(), 1) as $item) { if ($item instanceof EntityRelation) { $this->entityBuilder->buildRelation($item); } } $this->entityBuilder->createDefaultClassDocBlock(); $this->entityBuilder->createGetEntityNameMethod(); if (!($this->flags & self::NO_SET_META_GETTER)) { $this->entityBuilder->buildSetMetaGetter(); } $this->entityBuilder->generateDocBlocks(); //$this->entityBuilder->createMethod('export',array(), array()); $docBlock = $this->entityBuilder->getGClass()->getDocBlock(); $docBlock->removeAnnotation(Annotation::createDC('Entity')->getAnnotationName()); $docBlock->removeAnnotation(Annotation::createDC('Table')->getAnnotationName()); $docBlock->addAnnotation(Annotation::createDC('MappedSuperclass')); $this->entityBuilder->write(NULL, $this->overwrite); return $this->entityBuilder; }