2017 © Pedro Peláez
 

library former

Form validate with annotation

image

layliaiyong/former

Form validate with annotation

  • Tuesday, July 17, 2018
  • by Lay
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

former

Form validate with annotation, (*1)

Installation

Package is available on Packagist, you can install it using Composer., (*2)

composer require layliaiyong/former

PHP 5.4+, (*3)

Annotation

Property must be protected. Annotation option value must be json string., (*4)

Annotation Patterns: + Former..., (*5)

End with https://github.com/Respect/Validation validator, (*6)

class TestFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->id = 1;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$data->id = 'abc'; 
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["ID must be integer"]
  • NotFormer...

End with respect/Validation validator, (*7)

class TestFormer extends Former
{
    /**
     * @NotFormerIntVal {"message":"ID must not be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->id = 1;
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["ID must be integer"]
// error
$data->id = 'abc'; 
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
  • Former
class TestFormer extends Former
{
    /**
     * @FormerObjectType {"message":"former must be object"}
     * @Former {"message":"invalid former","former":"\\TestObjectFormer"}
     */
    protected $former;
}
class TestObjectFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$former = new \stdClass();
$validator = new TestFormer();
// pass
$former->id = 1;
$data->former = $former;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$former->id = 'abc'; 
$data->former = $former;
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[former]invalid former","[id]ID must be integer"]
  • Formers
class TestFormer extends Former
{
    /**
     * @FormerObjectType {"message":"formers must be object array"}
     * @Former {"message":"invalid formers","former":"\\TestObjectFormer"}
     */
    protected $formers;
}
class TestObjectFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$former = new \stdClass();
$validator = new TestFormer();
// pass
$former->id = 1;
$data->formers = [$former];
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$former->id = 'abc'; 
$data->formers = [$former];
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[formers]invalid formers","[id]ID must be integer"]
  • CaseFormer
class TestFormer extends Former
{
    /**
     * @CaseFormer [{"message":"invalid case when value is 1","when":"FormerEquals","params":[1],"former":"\\TestCaseFormer"}]
     */
    protected $case;
    protected $case1;
}
class TestCaseFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $case1;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->case = 1;
$data->case1 = 2;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$data->case = 1;
$data->case1 = 'abc';
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[case]invalid case when value is 1","[case1]ID must be integer"]

The Versions

17/07 2018

dev-master

9999999-dev

Form validate with annotation

  Sources   Download

MIT

The Requires

 

The Development Requires

by liaiyong

form validate annotation

17/07 2018

v1.0.0

1.0.0.0

Form validate with annotation

  Sources   Download

MIT

The Requires

 

The Development Requires

by liaiyong

form validate annotation