本文整理汇总了PHP中Symfony\Component\Intl\Globals\IntlGlobals::setError方法的典型用法代码示例。如果您正苦于以下问题:PHP IntlGlobals::setError方法的具体用法?PHP IntlGlobals::setError怎么用?PHP IntlGlobals::setError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Intl\Globals\IntlGlobals
的用法示例。
在下文中一共展示了IntlGlobals::setError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
/**
* Format the date/time value (timestamp) as a string.
*
* @param int|\DateTime $timestamp The timestamp to format. \DateTime objects
* are supported as of PHP 5.3.4.
*
* @return string|bool The formatted value or false if formatting failed.
*
* @see http://www.php.net/manual/en/intldateformatter.format.php
*
* @throws MethodArgumentValueNotImplementedException If one of the formatting characters is not implemented
*/
public function format($timestamp)
{
// intl allows timestamps to be passed as arrays - we don't
if (is_array($timestamp)) {
$message = PHP_VERSION_ID >= 50304 ? 'Only integer Unix timestamps and DateTime objects are supported' : 'Only integer Unix timestamps are supported';
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message);
}
// behave like the intl extension
$argumentError = null;
if (PHP_VERSION_ID < 50304 && !is_int($timestamp)) {
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
} elseif (PHP_VERSION_ID >= 50304 && !is_int($timestamp) && !$timestamp instanceof \DateTime) {
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
if (PHP_VERSION_ID >= 50500 && !is_int($timestamp)) {
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
}
}
if (null !== $argumentError) {
IntlGlobals::setError(IntlGlobals::U_ILLEGAL_ARGUMENT_ERROR, $argumentError);
$this->errorCode = IntlGlobals::getErrorCode();
$this->errorMessage = IntlGlobals::getErrorMessage();
return false;
}
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
if (PHP_VERSION_ID >= 50304 && $timestamp instanceof \DateTime) {
$timestamp = $timestamp->getTimestamp();
}
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
$formatted = $transformer->format($this->createDateTime($timestamp));
// behave like the intl extension
IntlGlobals::setError(IntlGlobals::U_ZERO_ERROR);
$this->errorCode = IntlGlobals::getErrorCode();
$this->errorMessage = IntlGlobals::getErrorMessage();
return $formatted;
}
示例2: calculateUnixTimestamp
/**
* Calculates the Unix timestamp based on the matched values by the reverse matching regular
* expression of parse().
*
* @param \DateTime $dateTime The DateTime object to be used to calculate the timestamp
* @param array $options An array with the matched values to be used to calculate the timestamp
*
* @return bool|int The calculated timestamp or false if matched date is invalid
*/
protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
{
$options = $this->getDefaultValueForOptions($options);
$year = $options['year'];
$month = $options['month'];
$day = $options['day'];
$hour = $options['hour'];
$hourInstance = $options['hourInstance'];
$minute = $options['minute'];
$second = $options['second'];
$marker = $options['marker'];
$timezone = $options['timezone'];
// If month is false, return immediately (intl behavior)
if (false === $month) {
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Date parsing failed');
return false;
}
// Normalize hour
if ($hourInstance instanceof HourTransformer) {
$hour = $hourInstance->normalizeHour($hour, $marker);
}
// Set the timezone if different from the default one
if (null !== $timezone && $timezone !== $this->timezone) {
$dateTime->setTimezone(new \DateTimeZone($timezone));
}
// Normalize yy year
preg_match_all($this->regExp, $this->pattern, $matches);
if (in_array('yy', $matches[0])) {
$dateTime->setTimestamp(time());
$year = $year > $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year;
}
$dateTime->setDate($year, $month, $day);
$dateTime->setTime($hour, $minute, $second);
return $dateTime->getTimestamp();
}
示例3: resetError
/**
* Set the error to the default U_ZERO_ERROR.
*/
protected function resetError()
{
IntlGlobals::setError(IntlGlobals::U_ZERO_ERROR);
$this->errorCode = IntlGlobals::getErrorCode();
$this->errorMessage = IntlGlobals::getErrorMessage();
}