-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Conversation
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
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.
2005-2013 :D
Changing the default format for Zend\Form should be done within a seperate PR and btw. removing the In my opinion the name should be |
Where are the tests? ;) |
* | ||
* @var string | ||
*/ | ||
protected $format = self::DATETIME_FORMAT; | ||
protected $format = PhpDateTime::W3C; |
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.
This is a BC Break
@Maks3w tests attached |
/** | ||
* Sets filter options | ||
* | ||
* @param string|array|\Zend\Config\Config $options |
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.
* @param array|Traversable $options
@weierophinney What do you thing about this? |
namespace Zend\Filter; | ||
|
||
use DateTime; | ||
use Exception; |
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.
Can you please use an exception that is part of the Zend\Filter component? If no suitable exception exists you could create it, and have it extend the appropriate SPL exception.
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 second the recommendation from @Freeaqingme
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.
Hi both, I am "using" \Exception to catch the Exception thrown by DateTime (http://www.php.net/manual/en/datetime.construct.php) which is just \Exception. Are you saying I should create an Exception in Filter\Exception that Extends \Exception?
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.
In this case, I'd remove the import, and use FQCN when catching:
catch (\Exception $e)
This will make it more clear that you actually intend to catch a global exception -- which is a rare occurrence in the framework.
This looks good. @davidwindell - Make the changes requested, remove the "[WIP]" notation, and I'll do final review for merge. |
Thanks @weierophinney, I've made the requested changes. |
$result = $this->normalizeDateTime($value); | ||
} catch (\Exception $ex) { | ||
// DateTime threw an exception, an invalid date string was provided | ||
return $value; |
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.
The filter should throw the exception else it returns not normalized dates
$filter->filter('now'); // 2013-03-13 10:00
$filter->filter('2013-03-13 10:00'); // 2013-03-13 10:00
$filter->filter('abcdefg'); // abcdefg ? -> please throw an Exception
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.
@marc-mabe this is not the behaviour of other filters, see https://github.com/zendframework/zf2/blob/master/library/Zend/Filter/UriNormalize.php#L105
Filters should not throw exceptions or they will cause problems with InputFilters
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.
Thats interesting because other filters throw exceptions - see https://github.com/zendframework/zf2/blob/master/library/Zend/Filter/HtmlEntities.php
@weierophinney What's the right way to go here? For me a filter should throw exceptions on failures else it's impossible to detect such failures (see my example above). Only implementations of Zend\Validator\ValidatorInterface::isValid
shouldn't throw exceptions but the filters should do that.
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'm now re throwing the blanket DateTime \Exception as a InvalidArgumentException
$result = $this->normalizeDateTime($value); | ||
} catch (\Exception $ex) { | ||
// DateTime threw an exception, an invalid date string was provided | ||
throw new Exception\InvalidArgumentException($ex); |
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.
This should be throw new Exception\InvalidArgumentException("Invalid input date '{$value}'", 0, $ex);
to throw the exception of DateTime
as previous exception
New DateTimeFormatter Filter (#3617)
- Incorporate feedback from @marc-mabe - Also: use $e as exception (for consistency)
Merged. |
…-unaware-of-datetime-formatter Add service definition for DateTimeFormatter (related to #3632)
…/zf3617 New DateTimeFormatter Filter (zendframework/zendframework#3617)
- Incorporate feedback from @marc-mabe - Also: use $e as exception (for consistency)
…otfix/filter-plugin-manager-unaware-of-datetime-formatter Add service definition for DateTimeFormatter (related to zendframework/zendframework#3632)
This PR introduces a simple
DateTimeFormatter
Filter class that will attempt to format a provided string using the specified date() style format.The main advantage of this is to allow pre-formatting of a provided datetime value on a
Zend\Form\Element\DateTime
where the HTML5 spec and different browsers may pass values with or without seconds which can cause the validator to fail.See #3617