Skip to content

Импорт пустых строк в PrimitiveString #166

Description

@sryabov

В настоящий момент при импорте пустой строки в любом случае (даже если не задана минимальная длина строки через setMin) не получаем в value пустую строку, а получаем null, хотя это разные значения (в том числе и для БД). Есть предложение изменить на следующий код:

public function import($scope)
{
    if (!BasePrimitive::import($scope))
        return null;

    if (!is_scalar($scope[$this->name]) || is_bool($scope[$this->name]))
        return false;

    $this->value = (string) $scope[$this->name];

    $this->selfFilter();

    if (is_string($this->value)) {
        $length = mb_strlen($this->value);

        if(
            ($this->max === null || $length <= $this->max)
            && ($this->min === null || $length >= $this->min)
            && ($this->pattern === null || preg_match($this->pattern, $this->value))
        )
            return true;
    }

    $this->value = null;

    return false;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions