-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Validator service #567
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
Closed
Closed
Validator service #567
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f3329e7
Add a validator service
elkuku 2d50d57
Use the validator service
elkuku fa03cab
Remove superfluous doc block entries
elkuku 6c3b5b9
Remove superfluous doc block entries
elkuku 8aafb02
Fix doc blocks
elkuku 852f383
Change method names - based on feedback
elkuku b0cc2d2
Merge remote-tracking branch 'origin/master' into validator-service
elkuku 52e01eb
Update to latest changes
elkuku 31b7332
Fix unit tests
elkuku ed31d33
Add a unit test
elkuku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace AppBundle\Utils; | ||
|
||
class Validator | ||
{ | ||
public function username($username) | ||
{ | ||
if (empty($username)) { | ||
throw new \Exception('The username can not be empty.'); | ||
} | ||
|
||
if (1 !== preg_match('/^[a-z_]+$/', $username)) { | ||
throw new \Exception('The username must contain only lowercase latin characters and underscores.'); | ||
} | ||
|
||
return $username; | ||
} | ||
|
||
public function password($plainPassword) | ||
{ | ||
if (empty($plainPassword)) { | ||
throw new \Exception('The password can not be empty.'); | ||
} | ||
|
||
if (mb_strlen(trim($plainPassword)) < 6) { | ||
throw new \Exception('The password must be at least 6 characters long.'); | ||
} | ||
|
||
return $plainPassword; | ||
} | ||
|
||
public function email($email) | ||
{ | ||
if (empty($email)) { | ||
throw new \Exception('The email can not be empty.'); | ||
} | ||
|
||
if (false === mb_strpos($email, '@')) { | ||
throw new \Exception('The email should look like a real email.'); | ||
} | ||
|
||
return $email; | ||
} | ||
|
||
public function fullName($fullName) | ||
{ | ||
if (empty($fullName)) { | ||
throw new \Exception('The full name can not be empty.'); | ||
} | ||
|
||
return $fullName; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the name could be:
usernameValidation
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateUsername
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding the "right" name has always been the hardest part in software design 😉
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elkuku, You're right, but a method name in most cases should be beginning with a verb. :)