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

setWindowDefinitionAction() public method

public setWindowDefinitionAction ( FOS\RestBundle\Request\ParamFetcher $paramFetcher ) : boolean
$paramFetcher FOS\RestBundle\Request\ParamFetcher
return boolean
    public function setWindowDefinitionAction(ParamFetcher $paramFetcher)
    {
        $class = $paramFetcher->get('class');
        $list = $paramFetcher->get('list') ?: null;
        $add = $paramFetcher->get('add') ?: null;
        $general = $paramFetcher->get('general') ?: null;
        $methods = $paramFetcher->get('methods') ?: null;
        $fields = $paramFetcher->get('fields') ?: null;
        if (substr($class, 0, 1) != '\\') {
            $class = '\\' . $class;
        }
        $path = $general['file'];
        $sourcecode = "<?php\n\n";
        $lSlash = strrpos($class, '\\');
        $class2Name = $lSlash !== -1 ? substr($class, $lSlash + 1) : $class;
        $parentClass = '\\Jarves\\Controller\\ObjectCrudController';
        $objectDefinition = $this->objects->getDefinition($general['object']);
        if ($objectDefinition->isNested()) {
            $parentClass = '\\Jarves\\Controller\\NestedObjectCrudController';
        }
        $namespace = substr(substr($class, 1), 0, $lSlash);
        if (substr($namespace, -1) == '\\') {
            $namespace = substr($namespace, 0, -1);
        }
        $sourcecode .= "namespace {$namespace};\n \n";
        $sourcecode .= 'class ' . $class2Name . ' extends ' . $parentClass . " {\n\n";
        if (count($fields) > 0) {
            $this->addVar($sourcecode, 'fields', $fields);
        }
        if (is_array($list)) {
            foreach ($list as $listVarName => $listVar) {
                $this->addVar($sourcecode, $listVarName, $listVar);
            }
        }
        if (is_array($add)) {
            foreach ($add as $varName => $var) {
                $this->addVar($sourcecode, $varName, $var);
            }
        }
        $blacklist = array('class', 'file');
        if (is_array($general)) {
            foreach ($general as $varName => $var) {
                if (array_search($varName, $blacklist) !== false) {
                    continue;
                }
                $this->addVar($sourcecode, $varName, $var);
            }
        }
        if (is_array($methods)) {
            foreach ($methods as $name => $source) {
                $this->addMethod($sourcecode, $source);
            }
        }
        $sourcecode .= "\n}\n";
        $sourcecode = str_replace("\r", '', $sourcecode);
        $fs = $this->localFilesystem;
        $result = $fs->write($path, $sourcecode);
        $this->reconfigureJarves();
        return $result;
    }