-
Notifications
You must be signed in to change notification settings - Fork 136
Validator result interface proposal #24
base: develop
Are you sure you want to change the base?
Changes from all commits
156d515
a1db762
2b28ea1
96c9d3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Validator; | ||
|
||
/** | ||
* This interface provide methods for to know the result of a validation and the reasons when the result is not valid | ||
* | ||
* This interface resolve the following questions: | ||
* - Is the result valid or invalid? | ||
* - If not, Why is not valid? | ||
*/ | ||
interface ResultInterface | ||
{ | ||
/** | ||
* Is the validation result valid? | ||
* | ||
* @return bool | ||
*/ | ||
public function isValid(); | ||
|
||
/** | ||
* Is the validation result invalid? | ||
* | ||
* @return bool | ||
*/ | ||
public function isNotValid(); | ||
|
||
/** | ||
* Returns the list of error violations in a machine readable format. | ||
* | ||
* @return array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can constraint this to |
||
*/ | ||
public function getErrorCodes(); | ||
|
||
/** | ||
* Get the error messages associated with the validation result | ||
* | ||
* @return Translator\TranslatableMessageInterface[] | ||
*/ | ||
public function getMessages(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Validator\Translator; | ||
|
||
/** | ||
* This interface provide methods for extract the translatable parts of a message. | ||
* | ||
* The translatable parts of a message are those parts allow to consumption by ICU message formatters. | ||
*/ | ||
interface TranslatableMessageInterface | ||
{ | ||
/** | ||
* Returns the message to translate. | ||
* | ||
* The message may include placeholders for message variable interpolation. | ||
* | ||
* @return string | ||
*/ | ||
public function getMessageTemplate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method name may return two types of message.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this means that sometimes, the messages are directly exploitable with this methods (when no placeholder), and sometimes, I must use another object to translate them? |
||
|
||
/** | ||
* Returns the variables to be replaced in the message template placeholders. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables may should have a cardinal number associated to the value for proper translation of plurals /cc @DASPRiD |
||
* | ||
* @return array | ||
*/ | ||
public function getMessageVariables(); | ||
|
||
/** | ||
* Returns the translation domain namespace. | ||
* | ||
* @return string | ||
*/ | ||
public function getTranslationDomain(); | ||
|
||
/** | ||
* Returns the message template with the placeholders replaced by the variables. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString(); | ||
} |
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.
Why? I'm not sure this is really needed... It adds an additional method for few benefits.
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.
Agreed with @bakura10 - in fact, I just closed another issue that suggested it earlier.
isValid()
is a boolean method; if you want to determine if it returns false, you use the boolean operator (!
). Adding another method is confusing and unnecessary.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.
I think is expressiveness is very useful.
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.
I disagree with it being more expressive. It's one more method to implement and maintain, for a trivial boolean condition. Use the boolean operator; it's expressive enough, and it's its sole, well-known purpose.
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.
I see it close like when you have
getFields
andgetField($name)
with the first method you can do the same operations as the second, but the second is more user friendly.Also the implementation is trivial, the return is just the alternate version of isValid (!isValid)
For me expressiveness is human level of write. (!) not operator is not in the dictionary :)
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.
@ojhaujjwal a reason would be awesome :)
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.
I don't this is really needed
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.
Another reason for to have "isNotX" methods is like a way of complete pairs of methods
set - get
add - remove
has - notHas
is - isNot
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.
if - else
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.
We all know if and while are the most basic statements for control and loops but we all like for() and even more foreach()
Also this may help for all those people wants a whitespace after the not (!) operator.