Pimcore\Model\Object\ClassDefinition\Data::getGetterCode PHP Метод

getGetterCode() публичный Метод

Creates getter code which is used for generation of php file for object classes using this data type
public getGetterCode ( $class ) : string
$class
Результат string
    public function getGetterCode($class)
    {
        $key = $this->getName();
        $code = "";
        $code .= '/**' . "\n";
        $code .= '* Get ' . str_replace(["/**", "*/", "//"], "", $this->getName()) . " - " . str_replace(["/**", "*/", "//"], "", $this->getTitle()) . "\n";
        $code .= '* @return ' . $this->getPhpdocType() . "\n";
        $code .= '*/' . "\n";
        $code .= "public function get" . ucfirst($key) . " () {\n";
        // adds a hook preGetValue which can be defined in an extended class
        $code .= "\t" . '$preValue = $this->preGetValue("' . $key . '");' . " \n";
        $code .= "\t" . 'if($preValue !== null && !\\Pimcore::inAdmin()) { ' . "\n";
        $code .= "\t\t" . 'return $preValue;' . "\n";
        $code .= "\t" . '}' . "\n";
        if (method_exists($this, "preGetData")) {
            $code .= "\t" . '$data = $this->getClass()->getFieldDefinition("' . $key . '")->preGetData($this);' . "\n";
        } else {
            $code .= "\t" . '$data = $this->' . $key . ";\n";
        }
        // insert this line if inheritance from parent objects is allowed
        if ($class->getAllowInherit()) {
            $code .= "\t" . 'if(\\Pimcore\\Model\\Object::doGetInheritedValues() && $this->getClass()->getFieldDefinition("' . $key . '")->isEmpty($data)) {' . "\n";
            $code .= "\t\t" . 'return $this->getValueFromParent("' . $key . '");' . "\n";
            $code .= "\t" . '}' . "\n";
        }
        $code .= "\treturn " . '$data' . ";\n";
        $code .= "}\n\n";
        return $code;
    }

Usage Example

Пример #1
0
 /**
  * @param $class
  * @return string
  */
 public function getGetterCode($class)
 {
     $code = "";
     $code .= parent::getGetterCode($class);
     return $code;
 }
All Usage Examples Of Pimcore\Model\Object\ClassDefinition\Data::getGetterCode