Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ntax committed Jan 23, 2018
2 parents d66945c + 2183de8 commit d181145
Show file tree
Hide file tree
Showing 29 changed files with 731 additions and 78 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Since this library is very much alpha, I haven't had time to add all the [valida
* MaxLength
* MinLength
* Pattern
* Max
* Min
## Usage
Expand All @@ -67,7 +69,7 @@ For reasons that I can't quite imagine, you might only want to just add client s
TextType::class,
[
'parsleys' => [
new \C0ntax\ParsleyBundle\Constraint\MinLength(2, 'You need more than %s chars'),
new \C0ntax\ParsleyBundle\Directive\Field\Constraint\MinLength(2, 'You need more than %s chars'),
],
]
)
Expand Down Expand Up @@ -136,7 +138,7 @@ Let's assume that the Entity in the example above is out of your control. It's c
TextType::class,
[
'parsleys' => [
new \C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage(\C0ntax\ParsleyBundle\Constraint\MinLength::class, 'You need more than %s chars'),
new \C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage(\C0ntax\ParsleyBundle\Directive\Field\Constraint\MinLength::class, 'You need more than %s chars'),
],
]
)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c0ntax/parsley-bundle",
"version": "0.1.1",
"version": "0.2.0",
"type": "symfony-bundle",
"description": "A bridge between Symfony and Parsley.js",
"license": "Apache-2.0",
Expand Down
3 changes: 1 addition & 2 deletions src/C0ntaxParsleyBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle;

Expand All @@ -12,5 +12,4 @@
*/
class C0ntaxParsleyBundle extends Bundle
{

}
6 changes: 3 additions & 3 deletions src/Contracts/ConstraintInterface.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Contracts;

use C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage;
use C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage;

/**
* Interface ConstraintInterface
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
interface ConstraintInterface extends DirectiveInterface
{
Expand Down
62 changes: 62 additions & 0 deletions src/Directive/Field/Constraint/AbstractComparison.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class AbstractComparison
*
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
abstract class AbstractComparison extends AbstractConstraint
{
/** @var int|float|\DateTime */
private $value;

/**
* Min constructor.
*
* @param \DateTime|float|int $min
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct($min, string $errorMessage = null)
{
$this->setValue($min);
$this->setErrorMessageString($errorMessage);
}

/**
* @return array
*/
public function getViewAttr(): array
{
$value = null;
if ($this->getValue() instanceof \DateTime || $this->getValue() instanceof \DateTimeImmutable) {
$value = $this->getValue()->format('Y-m-d H:i:s');
} else {
$value = (string) $this->getValue();
}

return $this->getMergedViewAttr($value);
}

/**
* @return \DateTime|float|int
*/
private function getValue()
{
return $this->value;
}

/**
* @param \DateTime|float|int $min
* @return AbstractComparison
*/
private function setValue($min): AbstractComparison
{
$this->value = $min;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

use C0ntax\ParsleyBundle\Contracts\ConstraintInterface;
use C0ntax\ParsleyBundle\Directive\ConstraintErrorMessage;
use C0ntax\ParsleyBundle\Directive\Field\ConstraintErrorMessage;

/**
* Class AbstractConstraint
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
abstract class AbstractConstraint implements ConstraintInterface
{
Expand All @@ -29,6 +29,7 @@ public function getErrorMessage(): ?ConstraintErrorMessage
/**
* @param string $errorMessage
* @return AbstractConstraint
* @throws \InvalidArgumentException
*/
protected function setErrorMessageString(?string $errorMessage): AbstractConstraint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class AbstractLength
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
abstract class AbstractLength extends AbstractConstraint
{
Expand All @@ -22,6 +22,7 @@ abstract class AbstractLength extends AbstractConstraint
* @param int|null $min
* @param int|null $max
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(int $min = null, int $max = null, string $errorMessage = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class Email
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class Email extends AbstractConstraint
{
/**
* Email constructor.
*
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(string $errorMessage = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class Length
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class Length extends AbstractLength
{
Expand All @@ -16,6 +16,7 @@ class Length extends AbstractLength
* @param int $min
* @param int $max
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(int $min, int $max, string $errorMessage = null)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Directive/Field/Constraint/Max.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class Min
*
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class Max extends AbstractComparison
{
/**
* @return string
*/
public static function getConstraintId(): string
{
return 'max';
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class MaxLength
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class MaxLength extends AbstractLength
{
Expand All @@ -15,6 +15,7 @@ class MaxLength extends AbstractLength
*
* @param int $max
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(int $max, string $errorMessage = null)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Directive/Field/Constraint/Min.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class Min
*
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class Min extends AbstractComparison
{
/**
* @return string
*/
public static function getConstraintId(): string
{
return 'min';
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class MinLength
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class MinLength extends AbstractLength
{
Expand All @@ -15,6 +15,7 @@ class MinLength extends AbstractLength
*
* @param int|null $min
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(int $min, string $errorMessage = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace C0ntax\ParsleyBundle\Constraint;
namespace C0ntax\ParsleyBundle\Directive\Field\Constraint;

/**
* Class Pattern
*
* @package C0ntax\ParsleyBundle\Constraint
* @package C0ntax\ParsleyBundle\Directive\Field\Constraint
*/
class Pattern extends AbstractConstraint
{
Expand All @@ -18,6 +18,7 @@ class Pattern extends AbstractConstraint
*
* @param string $pattern
* @param string|null $errorMessage
* @throws \InvalidArgumentException
*/
public function __construct(string $pattern, string $errorMessage = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace C0ntax\ParsleyBundle\Directive;
namespace C0ntax\ParsleyBundle\Directive\Field;

use C0ntax\ParsleyBundle\Constraint\AbstractConstraint;
use C0ntax\ParsleyBundle\Contracts\ConstraintInterface;
use C0ntax\ParsleyBundle\Contracts\DirectiveInterface;
use C0ntax\ParsleyBundle\Directive\Field\Constraint\AbstractConstraint;

/**
* Class ErrorMessage
Expand Down Expand Up @@ -53,7 +53,9 @@ public function getViewAttr(): array
private function getConstraintIdFromClass(string $class): string
{
if (!class_exists($class)) {
throw new \InvalidArgumentException($class.' is not a class and therefore doesn\'t implement '.ConstraintInterface::class);
throw new \InvalidArgumentException(
$class.' is not a class and therefore doesn\'t implement '.ConstraintInterface::class
);
}

if (array_key_exists(ConstraintInterface::class, class_implements($class))) {
Expand Down
Loading

0 comments on commit d181145

Please sign in to comment.