The short answer is no; you will have to roll your own.
You could create a independent class that can take any element and return the correct array by reading it's public methods; this is effectively reversing the functionality of the FormFactory
.
A very brief example
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);
}