|
|
@@ -17,13 +17,20 @@ use Doctrine\Common\Annotations\AnnotationRegistry;
|
|
|
use Doctrine\Common\Annotations\AnnotationReader as Render;
|
|
|
use FormBuilder\Contract\AnnotationInterface;
|
|
|
use FormBuilder\FormHandle;
|
|
|
+use FormBuilder\Util;
|
|
|
|
|
|
class AnnotationReader
|
|
|
{
|
|
|
protected static $isInit = false;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var Render
|
|
|
+ */
|
|
|
protected $annotationReader;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var FormHandle
|
|
|
+ */
|
|
|
protected $handle;
|
|
|
|
|
|
public function __construct(FormHandle $handle)
|
|
|
@@ -43,10 +50,40 @@ class AnnotationReader
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @return array
|
|
|
+ * @throws \ReflectionException
|
|
|
+ */
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
+ $reflectionClass = new \ReflectionClass($this->handle);
|
|
|
+ $methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
|
|
|
+ $rule = [];
|
|
|
+ $except = $this->handle->getExcept();
|
|
|
+ foreach ($methods as $method) {
|
|
|
+ $field = preg_replace('/^(.+)(Field|_field)$/', '$1', $method->name);
|
|
|
+ $value = null;
|
|
|
+ if ($field != $method->name && !in_array($field, $except)) {
|
|
|
+ $params = $method->getParameters();
|
|
|
+ if (isset($params[0]) && ($dep = $params[0]->getClass())) {
|
|
|
+ if (in_array('FormBuilder\\Contract\\FormComponentInterface', $dep->getInterfaceNames())) {
|
|
|
+ $componentClass = $dep->getName();
|
|
|
+ $value = $method->invokeArgs($this->handle, [new $componentClass($field, $this->handle->getFieldTitle($field))]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (is_null($value)) $value = $method->invoke($this->handle);
|
|
|
+ if (!is_null($value) && (($isArray = is_array($value)) || Util::isComponent($value))) {
|
|
|
+ $rule[] = compact('value', 'method', 'isArray');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $this->parse($rule);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @param $rules
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function parse($rules)
|
|
|
+ protected function parse($rules)
|
|
|
{
|
|
|
$formRule = [];
|
|
|
$groupList = [];
|