짧은 대답은 아니오입니다. 너는 너의 것을 굴려야 할 것이다.
요소를 가져 와서 public 배열을 읽어 올바른 배열을 반환 할 수있는 독립적 인 클래스를 만들 수 있습니다. 이것은 실질적으로 FormFactory
의 기능을 취소합니다.
아주 간단한 예를
class FormElementSerializer
{
public function toArray(ElementInterface $element)
{
$spec = $this->getElementSpec($element);
if ($element instanceof FieldsetInterface) {
$spec = $this->getFieldsetSpec($element, $spec);
}
if ($element instanceof Form) {
$spec = $this->getFormSpec($element, $spec);
}
return $spec;
}
protected function getElementSpec(ElementInterface $element)
{
$spec = array(
'type' => $this->getElementType($element),
'name' => $element->getName(),
'options' => $element->getOptions(),
'attributes' => $element->getAttributes(),
);
return $spec;
}
protected function getFieldsetSpec(FieldsetInterface $fieldset, array $spec)
{
foreach($fieldset->getElements() as $element) {
$spec['elements'][] = $this->getElementSpec($element);
}
return $spec;
}
// deals with hydrators, fieldsets etc
protected function getFormSpec(FormInterface $form, array $spec);
// could be as simple as returning the class name
protected function getElementType(ElementInterface $element);
}