Pimcore\Model\AbstractModel::__call PHP Метод

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

public __call ( $method, $args ) : mixed
$method
$args
Результат mixed
    public function __call($method, $args)
    {
        // protected / private methods shouldn't be delegated to the dao -> this can have dangerous effects
        if (!is_callable([$this, $method])) {
            throw new \Exception("Unable to call private/protected method '" . $method . "' on object " . get_class($this));
        }
        // check if the method is defined in ´dao
        if (method_exists($this->getDao(), $method)) {
            try {
                $r = call_user_func_array([$this->getDao(), $method], $args);
                return $r;
            } catch (\Exception $e) {
                Logger::emergency($e);
                throw $e;
            }
        } else {
            Logger::error("Class: " . get_class($this) . " => call to undefined method " . $method);
            throw new \Exception("Call to undefined method " . $method . " in class " . get_class($this));
        }
    }

Usage Example

Пример #1
0
 /**
  * @param $name
  * @param $arguments
  * @return array|mixed|null|void
  * @throws \Exception
  */
 public function __call($name, $arguments)
 {
     $sub = substr($name, 0, 14);
     if (substr($name, 0, 16) == "getWithGroupName") {
         $key = substr($name, 16, strlen($name) - 16);
         $groupConfig = Object\KeyValue\GroupConfig::getByName($arguments[0]);
         return $this->getProperty($key, $groupConfig->getId());
     } else {
         if (substr($name, 0, 14) == "getWithGroupId") {
             $key = substr($name, 14, strlen($name) - 14);
             $groupConfig = Object\KeyValue\GroupConfig::getById($arguments[0]);
             return $this->getProperty($key, $groupConfig->getId());
         } else {
             if (substr($name, 0, 3) == "get") {
                 $key = substr($name, 3, strlen($name) - 3);
                 return $this->getProperty($key);
             } else {
                 if (substr($name, 0, 3) == "set") {
                     $key = substr($name, 3, strlen($name) - 3);
                     return $this->setProperty($key, $arguments[0]);
                 }
             }
         }
     }
     return parent::__call($name, $arguments);
 }