public static function getLong(Form $form) { $long = array(); foreach ($form->getPrimitiveList() as $primitive) { if (strlen($primitive->getName()) > 1) { $long[] = $primitive->getName() . self::getValueType($primitive); } } return $long; }
public static function form2object(Form $form, $object, $ignoreNull = true) { Assert::isTrue(is_object($object)); if ($object instanceof Prototyped) { $proto = $object->proto(); $list = $proto->getExpandedPropertyList(); foreach ($form->getPrimitiveList() as $name => $prm) { if (isset($list[$name])) { $proto->exportPrimitive($name, $prm, $object, $ignoreNull); } } } else { $class = new ReflectionClass($object); foreach ($form->getPrimitiveList() as $name => $prm) { $setter = 'set' . ucfirst($name); if ($prm instanceof ListedPrimitive) { $value = $prm->getChoiceValue(); } else { $value = $prm->getValue(); } if ($class->hasMethod($setter) && (!$ignoreNull || $value !== null)) { if ($prm->getName() == 'id' && $value instanceof Identifiable) { $value = $value->getId(); } if ($value === null) { $dropper = 'drop' . ucfirst($name); if ($class->hasMethod($dropper)) { $object->{$dropper}(); continue; } } $object->{$setter}($value); } } } }
/** * @return Form */ public static function removePrefix(Form $form, $prefix) { $newForm = Form::create(); foreach ($form->getPrimitiveList() as $primitive) { $primitive->setName(strtr($primitive->getName(), array($prefix => ''))); $newForm->add($primitive); } return $newForm; }