-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve layout/structure for validators.
- Loading branch information
Showing
28 changed files
with
300 additions
and
311 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
2 changes: 1 addition & 1 deletion
2
app/Json/Validators/Rules/AppErrorCodes.php → app/Json/Validators/AppErrorCodes.php
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,114 @@ | ||
<?php namespace App\Json\Validators; | ||
|
||
use App\Data\Models\Board; | ||
use App\Data\Models\Comment; | ||
use App\Data\Models\Post; | ||
use App\Data\Models\Role; | ||
use App\Data\Models\User; | ||
use App\Json\Schemes\BoardScheme; | ||
use App\Json\Schemes\CommentScheme; | ||
use App\Json\Schemes\PostScheme; | ||
use App\Json\Schemes\RoleScheme; | ||
use App\Json\Schemes\UserScheme; | ||
use Limoncello\Flute\Validation\Rules\ExistInDatabaseTrait; | ||
use Limoncello\Flute\Validation\Rules\RelationshipsTrait; | ||
use Limoncello\Validation\Contracts\Rules\RuleInterface; | ||
use Limoncello\Validation\Rules; | ||
|
||
/** | ||
* @package App | ||
*/ | ||
class BaseRules extends Rules | ||
{ | ||
use RelationshipsTrait, ExistInDatabaseTrait; | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function boardId(): RuleInterface | ||
{ | ||
return self::stringToInt(self::exists(Board::TABLE_NAME, Board::FIELD_ID)); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function boardRelationship(): RuleInterface | ||
{ | ||
return self::toOneRelationship(BoardScheme::TYPE, static::boardId()); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function commentId(): RuleInterface | ||
{ | ||
return self::stringToInt(self::exists(Comment::TABLE_NAME, Comment::FIELD_ID)); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function commentRelationship(): RuleInterface | ||
{ | ||
return self::toOneRelationship(CommentScheme::TYPE, static::commentId()); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function postId(): RuleInterface | ||
{ | ||
return self::stringToInt(self::exists(Post::TABLE_NAME, Post::FIELD_ID)); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function postRelationship(): RuleInterface | ||
{ | ||
return self::toOneRelationship(PostScheme::TYPE, static::postId()); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function roleId(): RuleInterface | ||
{ | ||
return self::isString(self::exists(Role::TABLE_NAME, Role::FIELD_ID)); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function roleRelationship(): RuleInterface | ||
{ | ||
return self::toOneRelationship(RoleScheme::TYPE, static::roleId()); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function userId(): RuleInterface | ||
{ | ||
return self::stringToInt(self::exists(User::TABLE_NAME, User::FIELD_ID)); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function userRelationship(): RuleInterface | ||
{ | ||
return self::toOneRelationship(UserScheme::TYPE, static::userId()); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function usersRelationship(): RuleInterface | ||
{ | ||
$readableAll = static::stringArrayToIntArray(static::existAll(User::TABLE_NAME, User::FIELD_ID)); | ||
|
||
return self::toManyRelationship(UserScheme::TYPE, $readableAll); | ||
} | ||
} |
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,30 @@ | ||
<?php namespace App\Json\Validators\Board; | ||
|
||
use App\Data\Models\Board as Model; | ||
use App\Json\Schemes\BoardScheme as Scheme; | ||
use App\Json\Validators\BaseRules; | ||
use Limoncello\Validation\Contracts\Rules\RuleInterface; | ||
|
||
/** | ||
* @package App | ||
* | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
final class BoardRules extends BaseRules | ||
{ | ||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function boardType(): RuleInterface | ||
{ | ||
return self::equals(Scheme::TYPE); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function title(): RuleInterface | ||
{ | ||
return self::isString(self::stringLengthMax(Model::getAttributeLengths()[Model::FIELD_TITLE])); | ||
} | ||
} |
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,29 @@ | ||
<?php namespace App\Json\Validators\Comment; | ||
|
||
use App\Json\Schemes\CommentScheme as Scheme; | ||
use App\Json\Validators\BaseRules; | ||
use Limoncello\Validation\Contracts\Rules\RuleInterface; | ||
|
||
/** | ||
* @package App | ||
* | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
final class CommentRules extends BaseRules | ||
{ | ||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function commentType(): RuleInterface | ||
{ | ||
return self::equals(Scheme::TYPE); | ||
} | ||
|
||
/** | ||
* @return RuleInterface | ||
*/ | ||
public static function text(): RuleInterface | ||
{ | ||
return self::isString(); | ||
} | ||
} |
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
Oops, something went wrong.