Skip to content

Commit d181145

Browse files
committed
Merge branch 'release/0.2.0'
2 parents d66945c + 2183de8 commit d181145

29 files changed

Lines changed: 731 additions & 78 deletions

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Since this library is very much alpha, I haven't had time to add all the [valida
5151
* MaxLength
5252
* MinLength
5353
* Pattern
54+
* Max
55+
* Min
5456
5557
## Usage
5658
@@ -67,7 +69,7 @@ For reasons that I can't quite imagine, you might only want to just add client s
6769
TextType::class,
6870
[
6971
'parsleys' => [
70-
new \C0ntax\ParsleyBundle\Constraint\MinLength(2, 'You need more than %s chars'),
72+
new \C0ntax\ParsleyBundle\Directive\Field\Constraint\MinLength(2, 'You need more than %s chars'),
7173
],
7274
]
7375
)
@@ -136,7 +138,7 @@ Let's assume that the Entity in the example above is out of your control. It's c
136138
TextType::class,
137139
[
138140
'parsleys' => [
139-
new \C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage(\C0ntax\ParsleyBundle\Constraint\MinLength::class, 'You need more than %s chars'),
141+
new \C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage(\C0ntax\ParsleyBundle\Directive\Field\Constraint\MinLength::class, 'You need more than %s chars'),
140142
],
141143
]
142144
)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "c0ntax/parsley-bundle",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"type": "symfony-bundle",
55
"description": "A bridge between Symfony and Parsley.js",
66
"license": "Apache-2.0",

src/C0ntaxParsleyBundle.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace C0ntax\ParsleyBundle;
55

@@ -12,5 +12,4 @@
1212
*/
1313
class C0ntaxParsleyBundle extends Bundle
1414
{
15-
1615
}

src/Contracts/ConstraintInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace C0ntax\ParsleyBundle\Contracts;
55

6-
use C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage;
6+
use C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage;
77

88
/**
99
* Interface ConstraintInterface
1010
*
11-
* @package C0ntax\ParsleyBundle\Constraint
11+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
1212
*/
1313
interface ConstraintInterface extends DirectiveInterface
1414
{
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
5+
6+
/**
7+
* Class AbstractComparison
8+
*
9+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
10+
*/
11+
abstract class AbstractComparison extends AbstractConstraint
12+
{
13+
/** @var int|float|\DateTime */
14+
private $value;
15+
16+
/**
17+
* Min constructor.
18+
*
19+
* @param \DateTime|float|int $min
20+
* @param string|null $errorMessage
21+
* @throws \InvalidArgumentException
22+
*/
23+
public function __construct($min, string $errorMessage = null)
24+
{
25+
$this->setValue($min);
26+
$this->setErrorMessageString($errorMessage);
27+
}
28+
29+
/**
30+
* @return array
31+
*/
32+
public function getViewAttr(): array
33+
{
34+
$value = null;
35+
if ($this->getValue() instanceof \DateTime || $this->getValue() instanceof \DateTimeImmutable) {
36+
$value = $this->getValue()->format('Y-m-d H:i:s');
37+
} else {
38+
$value = (string) $this->getValue();
39+
}
40+
41+
return $this->getMergedViewAttr($value);
42+
}
43+
44+
/**
45+
* @return \DateTime|float|int
46+
*/
47+
private function getValue()
48+
{
49+
return $this->value;
50+
}
51+
52+
/**
53+
* @param \DateTime|float|int $min
54+
* @return AbstractComparison
55+
*/
56+
private function setValue($min): AbstractComparison
57+
{
58+
$this->value = $min;
59+
60+
return $this;
61+
}
62+
}

src/Constraint/AbstractConstraint.php renamed to src/Directive/Field/Constraint/AbstractConstraint.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

4-
namespace C0ntax\ParsleyBundle\Constraint;
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
55

66
use C0ntax\ParsleyBundle\Contracts\ConstraintInterface;
7-
use C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage;
7+
use C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage;
88

99
/**
1010
* Class AbstractConstraint
1111
*
12-
* @package C0ntax\ParsleyBundle\Constraint
12+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
1313
*/
1414
abstract class AbstractConstraint implements ConstraintInterface
1515
{
@@ -29,6 +29,7 @@ public function getErrorMessage(): ?ConstraintErrorMessage
2929
/**
3030
* @param string $errorMessage
3131
* @return AbstractConstraint
32+
* @throws \InvalidArgumentException
3233
*/
3334
protected function setErrorMessageString(?string $errorMessage): AbstractConstraint
3435
{

src/Constraint/AbstractLength.php renamed to src/Directive/Field/Constraint/AbstractLength.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

4-
namespace C0ntax\ParsleyBundle\Constraint;
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
55

66
/**
77
* Class AbstractLength
88
*
9-
* @package C0ntax\ParsleyBundle\Constraint
9+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
1010
*/
1111
abstract class AbstractLength extends AbstractConstraint
1212
{
@@ -22,6 +22,7 @@ abstract class AbstractLength extends AbstractConstraint
2222
* @param int|null $min
2323
* @param int|null $max
2424
* @param string|null $errorMessage
25+
* @throws \InvalidArgumentException
2526
*/
2627
public function __construct(int $min = null, int $max = null, string $errorMessage = null)
2728
{
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

4-
namespace C0ntax\ParsleyBundle\Constraint;
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
55

66
/**
77
* Class Email
88
*
9-
* @package C0ntax\ParsleyBundle\Constraint
9+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
1010
*/
1111
class Email extends AbstractConstraint
1212
{
1313
/**
1414
* Email constructor.
1515
*
1616
* @param string|null $errorMessage
17+
* @throws \InvalidArgumentException
1718
*/
1819
public function __construct(string $errorMessage = null)
1920
{
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

4-
namespace C0ntax\ParsleyBundle\Constraint;
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
55

66
/**
77
* Class Length
88
*
9-
* @package C0ntax\ParsleyBundle\Constraint
9+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
1010
*/
1111
class Length extends AbstractLength
1212
{
@@ -16,6 +16,7 @@ class Length extends AbstractLength
1616
* @param int $min
1717
* @param int $max
1818
* @param string|null $errorMessage
19+
* @throws \InvalidArgumentException
1920
*/
2021
public function __construct(int $min, int $max, string $errorMessage = null)
2122
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;
5+
6+
/**
7+
* Class Min
8+
*
9+
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
10+
*/
11+
class Max extends AbstractComparison
12+
{
13+
/**
14+
* @return string
15+
*/
16+
public static function getConstraintId(): string
17+
{
18+
return 'max';
19+
}
20+
}

0 commit comments

Comments
 (0)