Git Product home page Git Product logo

pasvl's Introduction

Hi there ๐Ÿ‘‹

  • ๐Ÿช‘ I am a husband, a father (since 2021), and a developer(since ~2005)
  • ๐Ÿ”ญ Iโ€™m currently working on data integration at Shown.io
  • ๐ŸŒฑ Iโ€™m a forever student, open-minded to new ideas and technologies
  • ๐Ÿ“ง [email protected], CV is always available here
  • ๐Ÿ‡ท๐Ÿ‡บ I live in Russia now and working remotely for many years.
  • โœ๏ธ Ocasionally I write in my blog at lessthan12ms.com

pasvl's People

Contributors

averor avatar jugid avatar lezhnev74 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pasvl's Issues

Validation failed with number

Hi,

I'm facing an issue I don't really understand. I have this pattern :

array(1) {
  'loop' =>
  array(2) {
    'count' =>
    string(26) ":string :regexp("/(\d)*/")" also tried ":number :int"
    'sub' =>
    string(7) ":string"
  }
}

For this array :

array(1) {
  'loop' =>
  array(2) {
    'count' =>
    string(1) "5"
    'sub' =>
    string(13) "create-cookie"
  }
}

PASVL always returns an error and I don't really know why. It's an exception that says : Data value [5] matched no pattern at level [loop]. This is the whole stack trace (only PASVL concern) :

[Error details] Data value [5] matched no pattern at level [loop]
PASVL\Validation\Problems\DataValueMatchedNoPattern: Data value [5] matched no pattern at level [loop] in /AutoMate/vendor/lezhnev74/pasvl/src/Validation/Problems/ArrayFailedValidation.php:14
Stack trace:
#0 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/Problems/DataValueMatchedNoPattern.php(22): PASVL\Validation\Problems\ArrayFailedValidation::make(Array, 'Data value [5] ...')
#1 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(97): PASVL\Validation\Problems\DataValueMatchedNoPattern::fromData('5', Array)
#2 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(55): PASVL\Validation\ArrayValidator->validateArrayLevel(Array, Array)
#3 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(89): PASVL\Validation\ArrayValidator->matchValue(Array, Array)
#4 [internal function]: PASVL\Validation\ArrayValidator->PASVL\Validation\{closure}('loop')
#5 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(95): array_filter(Array, Object(Closure))
#6 AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(55): PASVL\Validation\ArrayValidator->validateArrayLevel(Array, Array)
#7 /AutoMate/vendor/lezhnev74/pasvl/src/Validation/ArrayValidator.php(41): PASVL\Validation\ArrayValidator->matchValue(Array, Array)
#8 /AutoMate/src/Scenario/Transformer/AbstractTransformer.php(80): PASVL\Validation\ArrayValidator->validate(Array)

It seems that the pattern matches the array right... But it doesn't.

Simple regex doesn't match

Hi,

I'm trying to use your library that's really cool and interesting for the project I'm doing. First time using it, I'm facing this issue.

I have this $pattern (comes from a var_dump($pattern)) :

array(1) {
  ["go"]=>
  string(36) ":string :regexp("%^(https?:\/\/)%i")"
}

And this array (as $this->step) :

array(1) {
  ["go"]=>
  string(25) "https://www.wikipedia.org"
}

when I use this code :

private function validate() {
        $pattern = $this->getPattern();
        $builder = ValidatorBuilder::forArray($pattern);
        $validator = $builder->build();
        $value = true;

        try {
            $validator->validate($this->step);
        } catch (ArrayFailedValidation $e) {
            echo "Step [". key($this->step)  ."] is not a valid step. Watch out the syntax pattern.\n";
            echo "[Error details] " . $e->getMessage() . "\n";
            $value = false;
        }

        return $value;
    }

But it returns this lines :

Step [go] is not a valid step. Watch out the syntax pattern.
[Error details] Data value [https://www.wikipedia.org] matched no pattern at root level

I tried using preg_match("%^(https?://)%i", 'https://wikipedia.fr'); and it returns 1 (so, true).
I don't know what's wrong with that. Can you help me ?

Regards,

Error while using more than one parametrized validator

"A pattern can have a single main validator name and any number of sub-validators."

But, in below example

    $pattern = [
        'test' => ':string :min(1) :max(255)'
    ];

    $test = [
        'test' => 'test value'
    ];

two validators are created, string and min, the last having argument of

    1) :max(255

that means erroneous behavior.

Looking into

\PASVL\Pattern\Pattern::parse

method, and regexp used to match validator, mistake can be seen - no matching for closing parenthesis.

A little fix can be changing

$validator_arguments_pattern = "(\((?'arguments'.+,?)+\))?";

to

$validator_arguments_pattern = "(\((?'arguments'[^)]+,?)+\))?";

Still, however, closing parenthesis used as part of argument (ex. for regexp validator) will cause some problems...

object(nullable) with subvalidators fails

Love the library; just started using hit.
However, encountered this issue - have a validator pattern like:
$ref = ":object(nullable) :instance(\My\Class\Name)"
Which will always fail if the object actually is null (it still checks for the instance type, even though object is set to Nullable.

I subclassed ObjectValidator, but looking at the validators, this may be an issue throughout the library?

NullobjectValidator.txt

Matching only a subset

What's the correct/best way to only match a subset of the array's keys and ignore the rest?

For example in the arrray [ 'foo' => 'zoo', 'bar' => 42, 'baz' => true ], I only care about validating the values of foo and bar and don't care about baz or any other entries that may appear later.

Enrich messaging

In case data was marked as invalid by a specific Validator, it should be reported. So client can get a validator name which failed.

Example:

$data = ["name"=>"Alan"];
$pattern = ["name" => ":string :len(10)"];

The report should contain a message that "Length 4 did not match expected 10" or similar.
This also should support multi-language environment.

Null or shape?

First, great library!

Is it possible to specify that a value can be NULL or an array with a particular shape?

In this example, roadInfo can be either NULL or the shape shown below.

'roadInfo'  => array(
  'id'    => ':string',
  'type'  => ':string',
  'title' => ':string',
  'data?' => array(
    '*' => array(
      'language' => ':string',
      'data'     => ':string',
    ),
  ),
),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.