Jarves\Controller\Admin\BundleManager\EditorController::getWindowDefinitionAction PHP Method

getWindowDefinitionAction() public method

public getWindowDefinitionAction ( FOS\RestBundle\Request\ParamFetcher $paramFetcher ) : array
$paramFetcher FOS\RestBundle\Request\ParamFetcher
return array
    public function getWindowDefinitionAction(ParamFetcher $paramFetcher)
    {
        $class = $paramFetcher->get('class');
        if (substr($class, 0, 1) != '\\') {
            $class = '\\' . $class;
        }
        if (!class_exists($class)) {
            throw new ClassNotFoundException(sprintf('Class %s not found.', $class));
        }
        $reflection = new \ReflectionClass($class);
        $root = realpath($this->jarves->getRootDir() . '/../');
        $path = substr($reflection->getFileName(), strlen($root) + 1);
        $content = explode("\n", file_get_contents($reflection->getFileName()));
        $class2Reflection = new \ReflectionClass($class);
        $actualPath = $class2Reflection->getFileName();
        $res = array('class' => $class, 'file' => $path, 'actualFile' => $actualPath, 'properties' => array('__file__' => $path));
        $properties = $class2Reflection->getDefaultProperties();
        foreach ($properties as $k => $v) {
            $res['properties'][$k] = $v;
        }
        $parent = $reflection->getParentClass();
        $parentClass = $parent->name;
        $methods = $reflection->getMethods();
        foreach ($methods as $method) {
            if ($method->class == $class) {
                $code = '';
                if ($code) {
                    $code = "    {$code}\n";
                }
                for ($i = $method->getStartLine() - 1; $i < $method->getEndLine(); $i++) {
                    $code .= $content[$i] . "\n";
                }
                if ($doc = $method->getDocComment()) {
                    $code = "    {$doc}\n{$code}";
                }
                $res['methods'][$method->name] = str_replace("\r", '', $code);
            }
        }
        if (@$res['properties']['fields']) {
            foreach ($res['properties']['fields'] as $key => &$field) {
                if ($field instanceof Model) {
                    $field = $field->toArray();
                }
                $this->normalizeField($field, $key, $res);
            }
        }
        $this->extractParentClassInformation($parentClass, $res['parentMethods']);
        unset($res['properties']['_fields']);
        return $res;
    }