8000 [Validator] Moved constraints Optional and Required to the Constraints\ namespace by webmozart · Pull Request #7701 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Moved constraints Optional and Required to the Constraints\ namespace #7701

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

Merged
merged 1 commit into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,37 @@ UPGRADE FROM 2.x to 3.0
```
Yaml::parse(file_get_contents($fileName));
```

### Validator

* The constraints `Optional` and `Required` were moved to the
`Symfony\Component\Validator\Constraints\` namespace. You should adapt
the path wherever you used them.

Before:

```
use Symfony\Component\Validator\Constraints as Assert;

/**
* @Assert\Collection({
* "foo" = @Assert\Collection\Required(),
* "bar" = @Assert\Collection\Optional(),
* })
*/
private $property;
```

After:

```
use Symfony\Component\Validator\Constraints as Assert;

/**
* @Assert\Collection({
* "foo" = @Assert\Required(),
* "bar" = @Assert\Optional(),
* })
*/
private $property;
```
7 changes: 7 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

2.3.0
-----

* copied the constraints `Optional` and `Required` to the
`Symfony\Component\Validator\Constraints\` namespace and deprecated the original
classes.

2.2.0
-----

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class All extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Blank.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Blank extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Callback extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Choice extends Constraint
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Collection\Required;
use Symfony\Component\Validator\Constraints\Collection\Optional;
use Symfony\Component\Validator\Constraints\Required;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;

/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Collection extends Constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@

namespace Symfony\Component\Validator\Constraints\Collection;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Optional as BaseOptional;

/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use
* {@link \Symfony\Component\Validator\Constraints\Optional} instead.
*/
class Optional extends Constraint
class Optional extends BaseOptional
{
public $constraints = array();

public function getDefaultOption()
{
return 'constraints';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@

namespace Symfony\Component\Validator\Constraints\Collection;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Required as BaseRequired;

/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use
* {@link \Symfony\Component\Validator\Constraints\Required} instead.
*/
class Required extends Constraint
class Required extends BaseRequired
{
public $constraints = array();

public function getDefaultOption()
{
return 'constraints';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Constraints\Collection\Optional;
use Symfony\Component\Validator\Constraints\Optional;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Count extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Country extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Date extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class DateTime extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Email extends Constraint
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Existence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Constraint;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class Existence extends Constraint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the goal of this abstract class you are introducing ? This looks weird as you are not even uisng it for the instanceof checks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced because Optional and Required are two constraints of a kind that will probably always have identical functionality (I discovered that when trying to fix #4453 but didn't have time to complete this fix).

{
public $constraints = array();

public function getDefaultOption()
{
return 'constraints';
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/False.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class False extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class File extends Constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Annotation for group sequences
*
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/Constraints/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Validates that a value is a valid IP address
*
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Joseph Bielawski <stloyd@gmail.com>
*
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Language extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Length extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Locale extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/NotBlank.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class NotBlank extends Constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Symfony\Component\Validator\ConstraintValidator;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/NotNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class NotNull extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Null.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Null extends Constraint
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Optional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Constraints;

/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class Optional extends Existence
{
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Range extends Constraint
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class Regex extends Constraint
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Required.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Constraints;

/**
* @Annotation
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class Required extends Existence
{
}
Loading
0