Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 protected function prepareAndInjectObject($objectName, FieldsetInterface $fieldset, $method)
 {
     if (!is_string($objectName)) {
         throw new Exception\DomainException(sprintf('%s expects string class name; received "%s"', $method, is_object($objectName) ? get_class($objectName) : gettype($objectName)));
     }
     if (!class_exists($objectName)) {
         throw new Exception\DomainException(sprintf('%s expects string class name to be a valid class name; received "%s"', $method, $objectName));
     }
     $om = null;
     if ($fieldset instanceof ObjectManagerAwareInterface) {
         $om = $fieldset->getObjectManager();
     }
     if (!$om) {
         $om = $this->getObjectManager();
     }
     $object = new $objectName();
     if ($om) {
         /* @var $cm \Doctrine\Common\Persistence\Mapping\ClassMetadata */
         if ($object instanceof ObjectManagerAware && $om->getMetadataFactory()->isTransient($objectName)) {
             $cm = $om->getClassMetadata($objectName);
             $object->injectObjectManager($om, $cm);
         } elseif ($object instanceof ObjectManagerAwareInterface) {
             $object->setObjectManager($om);
         }
     }
     $fieldset->setObject($object);
 }