Pimcore\Model\Object\Objectbrick\Definition::createContainerClasses PHP Méthode

createContainerClasses() private méthode

    private function createContainerClasses()
    {
        $containerDefinition = [];
        if (!empty($this->classDefinitions)) {
            foreach ($this->classDefinitions as $cl) {
                $containerDefinition[$cl['classname']][$cl['fieldname']][] = $this->key;
                $class = Object\ClassDefinition::getById($cl['classname']);
                $fd = $class->getFieldDefinition($cl['fieldname']);
                if (!$fd) {
                    throw new \Exception("Could not resolve field definition for " . $cl['fieldname']);
                }
                $allowedTypes = $fd->getAllowedTypes();
                if (!in_array($this->key, $allowedTypes)) {
                    $allowedTypes[] = $this->key;
                }
                $fd->setAllowedTypes($allowedTypes);
                $class->save();
            }
        }
        $list = new Object\Objectbrick\Definition\Listing();
        $list = $list->load();
        foreach ($list as $def) {
            if ($this->key != $def->getKey()) {
                $classDefinitions = $def->getClassDefinitions();
                if (!empty($classDefinitions)) {
                    foreach ($classDefinitions as $cl) {
                        $containerDefinition[$cl['classname']][$cl['fieldname']][] = $def->getKey();
                    }
                }
            }
        }
        foreach ($containerDefinition as $classId => $cd) {
            $class = Object\ClassDefinition::getById($classId);
            if (!$class) {
                continue;
            }
            foreach ($cd as $fieldname => $brickKeys) {
                $className = $this->getContainerClassName($class->getName(), $fieldname);
                $namespace = $this->getContainerNamespace($class->getName(), $fieldname);
                $cd = '<?php ';
                $cd .= "\n\n";
                $cd .= "namespace " . $namespace . ";";
                $cd .= "\n\n";
                $cd .= "class " . $className . " extends \\Pimcore\\Model\\Object\\Objectbrick {";
                $cd .= "\n\n";
                $cd .= "\n\n";
                $cd .= 'protected $brickGetters = array(' . "'" . implode("','", $brickKeys) . "');\n";
                $cd .= "\n\n";
                foreach ($brickKeys as $brickKey) {
                    $cd .= 'public $' . $brickKey . " = null;\n\n";
                    $cd .= '/**' . "\n";
                    $cd .= '* @return \\Pimcore\\Model\\Object\\Objectbrick\\Data\\' . $brickKey . "\n";
                    $cd .= '*/' . "\n";
                    $cd .= "public function get" . ucfirst($brickKey) . "() { \n";
                    if ($class->getAllowInherit()) {
                        $cd .= "\t" . 'if(!$this->' . $brickKey . ' && \\Pimcore\\Model\\Object\\AbstractObject::doGetInheritedValues($this->getObject())) { ' . "\n";
                        $cd .= "\t\t" . '$brick = $this->getObject()->getValueFromParent("' . $fieldname . '");' . "\n";
                        $cd .= "\t\t" . 'if(!empty($brick)) {' . "\n";
                        $cd .= "\t\t\t" . 'return $this->getObject()->getValueFromParent("' . $fieldname . '")->get' . ucfirst($brickKey) . "(); \n";
                        $cd .= "\t\t" . "}\n";
                        $cd .= "\t" . "}\n";
                    }
                    $cd .= '   return $this->' . $brickKey . "; \n";
                    $cd .= "}\n\n";
                    $cd .= '/**' . "\n";
                    $cd .= '* @param \\Pimcore\\Model\\Object\\Objectbrick\\Data\\' . $brickKey . ' $' . $brickKey . "\n";
                    $cd .= "* @return void\n";
                    $cd .= '*/' . "\n";
                    $cd .= "public function set" . ucfirst($brickKey) . " (" . '$' . $brickKey . ") {\n";
                    $cd .= "\t" . '$this->' . $brickKey . " = " . '$' . $brickKey . ";\n";
                    $cd .= "\t" . 'return $this;' . ";\n";
                    $cd .= "}\n\n";
                }
                $cd .= "}\n";
                $cd .= "\n";
                $folder = $this->getContainerClassFolder($class->getName());
                if (!is_dir($folder)) {
                    File::mkdir($folder);
                }
                $file = $folder . "/" . ucfirst($fieldname) . ".php";
                File::put($file, $cd);
            }
        }
    }