Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator's "allowEmpty" list cannot handle Objects #13549

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

someson
Copy link

@someson someson commented Oct 22, 2018

Hello!

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:
Objects should be listable in Validator's allowEmpty as a possible "empty" value, i.e.

  • new \Phalcon\Db\RawValue('NULL'), __toString() can be used for comparing values

As a temporary workaround I'm using currently smth. like this:

namespace Your\Namespace;

use Phalcon\Db\RawValue;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Numericality as BaseNumericality;

class Numericality extends BaseNumericality
{
    public function isAllowEmpty(Validation $validation, string $fieldName): bool
    {
        $value = $validation->getValue($fieldName);
        if ($value instanceof RawValue) {
            $value = $value->getValue();
        }
        return ! $value || $value === 'NULL';
    }
}

Thanks

tests updated for phalcon#12519
see phalcon#12519#issuecomment-431848960
@niden niden merged commit 40b345b into phalcon:3.4.x Nov 1, 2018
@niden
Copy link
Member

niden commented Nov 1, 2018

Thank you!

@sergeyklay
Copy link
Contributor

Why this PR has been merged?
The tests was failed: https://travis-ci.org/phalcon/cphalcon/builds/444850239

@sergeyklay
Copy link
Contributor

Fixed in the #13575

@someson
Copy link
Author

someson commented Nov 3, 2018

Why this PR has been merged?
The tests was failed: https://travis-ci.org/phalcon/cphalcon/builds/444850239

Because PR contains just the new test condition, that will fail without that new feature you still have to implement :)

@niden niden added documentation Documentation required and removed documentation Documentation required labels Apr 9, 2019
@niden niden added the 4.0 label Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants