예제 #1
0
파일: Factory.php 프로젝트: coolms/doctrine
 /**
  * {@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);
 }
예제 #2
0
 /**
  * Bind an object to the form
  *
  * Ensures the object is populated with validated values.
  *
  * @param  object $object
  * @param  int $flags
  * @return mixed|void
  * @throws Exception\InvalidArgumentException
  */
 public function bind($object, $flags = FormInterface::VALUES_NORMALIZED)
 {
     if (!in_array($flags, array(FormInterface::VALUES_NORMALIZED, FormInterface::VALUES_RAW))) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects the $flags argument to be one of "%s" or "%s"; received "%s"', __METHOD__, 'Zend\\Form\\FormInterface::VALUES_NORMALIZED', 'Zend\\Form\\FormInterface::VALUES_RAW', $flags));
     }
     if ($this->baseFieldset !== null) {
         $this->baseFieldset->setObject($object);
     }
     $this->bindAs = $flags;
     $this->setObject($object);
     $this->extract();
 }
예제 #3
0
 /**
  * Prepare and inject an object
  *
  * Takes a string indicating a class name, instantiates the class
  * by that name, and injects the class instance as the bound object.
  *
  * @param  string           $objectName
  * @param  FieldsetInterface $fieldset
  * @param  string           $method
  * @throws Exception\DomainException
  * @return void
  */
 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));
     }
     $fieldset->setObject(new $objectName());
 }