-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] Extracted validation logic of form. Fields can now contain mul…
…tiple validators
- Loading branch information
Bernhard Schussek
committed
Mar 20, 2011
1 parent
2d0096f
commit b620dc6
Showing
9 changed files
with
75 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Validator; | ||
|
||
use Symfony\Component\Form\FieldInterface; | ||
use Symfony\Component\Form\FieldError; | ||
|
||
class FormValidator implements FieldValidatorInterface | ||
{ | ||
public function validate(FieldInterface $form) | ||
{ | ||
if (count($form->getExtraData()) > 0) { | ||
$form->addError(new FieldError('This form should not contain extra fields')); | ||
} | ||
|
||
if ($form->isRoot() && isset($_SERVER['CONTENT_LENGTH'])) { | ||
$length = (int) $_SERVER['CONTENT_LENGTH']; | ||
$max = trim(ini_get('post_max_size')); | ||
|
||
switch (strtolower(substr($max, -1))) { | ||
// The 'G' modifier is available since PHP 5.1.0 | ||
case 'g': | ||
$max *= 1024; | ||
case 'm': | ||
$max *= 1024; | ||
case 'k': | ||
$max *= 1024; | ||
} | ||
|
||
if ($length > $max) { | ||
$form->addError(new FieldError('The uploaded file was too large. Please try to upload a smaller file')); | ||
} | ||
} | ||
} | ||
} |