Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
perf(Validator): load base rules from call parent method
Browse files Browse the repository at this point in the history
Use static:: replace self:: in Validator::loadValidatorMetadata() to load
rules which created in Validator::rules()
  • Loading branch information
Rhilip committed Feb 8, 2019
1 parent 58b86ac commit 9d7191b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
5 changes: 1 addition & 4 deletions apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public static function rules()

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$rules = self::rules();
foreach ($rules as $property => $constraints) {
$metadata->addPropertyConstraints($property, $constraints);
}
parent::loadValidatorMetadata($metadata);
$metadata->addConstraint(new Assert\Callback([
'callback' => 'isValidTorrent',
'payload' => ['name' => 'file', 'maxSize' => app()->config->get("torrent.max_file_size"), 'mimeTypes' => 'application/x-bittorrent']
Expand Down
6 changes: 1 addition & 5 deletions apps/models/form/UserLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ public static function rules()

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
// FIXME It will not add the rule in self::rule() when use parent::loadValidatorMetadata()
$rules = self::rules();
foreach ($rules as $property => $constraints) {
$metadata->addPropertyConstraints($property, $constraints);
}
parent::loadValidatorMetadata($metadata);
$metadata->addConstraint(new Assert\Callback('validateCaptcha'));
$metadata->addConstraint(new Assert\Callback('loadUserFromPdo'));
$metadata->addConstraint(new Assert\Callback('isMaxLoginIpReached'));
Expand Down
7 changes: 1 addition & 6 deletions apps/models/form/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ public static function rules()

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
// FIXME It will not add the rule in self::rule() when use parent::loadValidatorMetadata()
$rules = self::rules();
foreach ($rules as $property => $constraints) {
$metadata->addPropertyConstraints($property, $constraints);
}

parent::loadValidatorMetadata($metadata);
$metadata->addConstraint(new Assert\Callback('isRegisterSystemOpen'));
$metadata->addConstraint(new Assert\Callback('isMaxUserReached'));
$metadata->addConstraint(new Assert\Callback('isMaxRegisterIpReached'));
Expand Down
2 changes: 1 addition & 1 deletion framework/Validators/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function rules()

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$rules = self::rules();
$rules = static::rules();
foreach ($rules as $property => $constraints) {
$metadata->addPropertyConstraints($property, $constraints);
}
Expand Down

0 comments on commit 9d7191b

Please sign in to comment.