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

Validator result interface proposal #24

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/ResultInterface.php
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();
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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 and getField($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 :)

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 :)

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if - else

Copy link
Member Author

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.


/**
* Returns the list of error violations in a machine readable format.
*
* @return array
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can constraint this to integer or string types

*/
public function getErrorCodes();

/**
* Get the error messages associated with the validation result
*
* @return Translator\TranslatableMessageInterface[]
*/
public function getMessages();
}
48 changes: 48 additions & 0 deletions src/Translator/TranslatableMessageInterface.php
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name may return two types of message.

  • Messages with placeholders
  • Messages without placeholders.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Member Author

Choose a reason for hiding this comment

The 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();
}