當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。