Pimcore\Model\Object\Concrete::__callStatic PHP Method

__callStatic() public static method

public static __callStatic ( $method, $arguments )
$method
$arguments
    public static function __callStatic($method, $arguments)
    {
        // check for custom static getters like Object::getByMyfield()
        $propertyName = lcfirst(preg_replace("/^getBy/i", "", $method));
        $tmpObj = new static();
        // get real fieldname (case sensitive)
        $fieldnames = [];
        foreach ($tmpObj->getClass()->getFieldDefinitions() as $fd) {
            $fieldnames[] = $fd->getName();
        }
        $propertyName = implode("", preg_grep('/^' . preg_quote($propertyName, '/') . '$/i', $fieldnames));
        if (property_exists($tmpObj, $propertyName)) {
            // check if the given fieldtype is valid for this shorthand
            $allowedDataTypes = ["input", "numeric", "checkbox", "country", "date", "datetime", "image", "language", "multihref", "multiselect", "select", "slider", "time", "user", "email", "firstname", "lastname", "localizedfields"];
            $field = $tmpObj->getClass()->getFieldDefinition($propertyName);
            if (!in_array($field->getFieldType(), $allowedDataTypes)) {
                throw new \Exception("Static getter '::getBy" . ucfirst($propertyName) . "' is not allowed for fieldtype '" . $field->getFieldType() . "', it's only allowed for the following fieldtypes: " . implode(",", $allowedDataTypes));
            }
            if ($field instanceof Model\Object\ClassDefinition\Data\Localizedfields) {
                $arguments = array_pad($arguments, 5, 0);
                list($localizedPropertyName, $value, $locale, $limit, $offset) = $arguments;
                $localizedField = $field->getFielddefinition($localizedPropertyName);
                if (!$localizedField instanceof Model\Object\ClassDefinition\Data) {
                    Logger::error("Class: Object\\Concrete => call to undefined static method " . $method);
                    throw new \Exception("Call to undefined static method " . $method . " in class Object\\Concrete");
                }
                if (!in_array($localizedField->getFieldType(), $allowedDataTypes)) {
                    throw new \Exception("Static getter '::getBy" . ucfirst($propertyName) . "' is not allowed for fieldtype '" . $localizedField->getFieldType() . "', it's only allowed for the following fieldtypes: " . implode(",", $allowedDataTypes));
                }
                $defaultCondition = $localizedPropertyName . " = " . \Pimcore\Db::get()->quote($value) . " ";
                $listConfig = ["condition" => $defaultCondition];
                if ($locale) {
                    $listConfig["locale"] = $locale;
                }
            } else {
                $arguments = array_pad($arguments, 3, 0);
                list($value, $limit, $offset) = $arguments;
                $defaultCondition = $propertyName . " = " . \Pimcore\Db::get()->quote($value) . " ";
                $listConfig = ["condition" => $defaultCondition];
            }
            if (!is_array($limit)) {
                if ($limit) {
                    $listConfig["limit"] = $limit;
                }
                if ($offset) {
                    $listConfig["offset"] = $offset;
                }
            } else {
                $listConfig = array_merge($listConfig, $limit);
                $listConfig['condition'] = $defaultCondition . $limit['condition'];
            }
            $list = static::getList($listConfig);
            if (isset($listConfig['limit']) && $listConfig['limit'] == 1) {
                $elements = $list->getObjects();
                return isset($elements[0]) ? $elements[0] : null;
            }
            return $list;
        }
        // there is no property for the called method, so throw an exception
        Logger::error("Class: Object\\Concrete => call to undefined static method " . $method);
        throw new \Exception("Call to undefined static method " . $method . " in class Object\\Concrete");
    }