当前位置: 首页>>代码示例>>PHP>>正文


PHP IntlGlobals::setError方法代码示例

本文整理汇总了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;
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:47,代码来源:IntlDateFormatter.php

示例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();
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:44,代码来源:FullTransformer.php

示例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();
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:9,代码来源:NumberFormatter.php


注:本文中的Symfony\Component\Intl\Globals\IntlGlobals::setError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。