dbObject::__get PHP Méthode

__get() public méthode

Magic getter function
public __get ( $name ) : mixed
$name Variable name
Résultat mixed
    public function __get($name)
    {
        if (isset($this->data[$name]) && $this->data[$name] instanceof dbObject) {
            return $this->data[$name];
        }
        if (property_exists($this, 'relations') && isset($this->relations[$name])) {
            $relationType = strtolower($this->relations[$name][0]);
            $modelName = $this->relations[$name][1];
            switch ($relationType) {
                case 'hasone':
                    $key = isset($this->relations[$name][2]) ? $this->relations[$name][2] : $name;
                    $obj = new $modelName();
                    $obj->returnType = $this->returnType;
                    return $this->data[$name] = $obj->byId($this->data[$key]);
                    break;
                case 'hasmany':
                    $key = $this->relations[$name][2];
                    $obj = new $modelName();
                    $obj->returnType = $this->returnType;
                    return $this->data[$name] = $obj->where($key, $this->data[$this->primaryKey])->get();
                    break;
                default:
                    break;
            }
        }
        if (isset($this->data[$name])) {
            return $this->data[$name];
        }
        if (property_exists($this->db, $name)) {
            return $this->db->{$name};
        }
    }