Example #1
0
 public function testSetWeight()
 {
     $tag = new Tag\Item(array('title' => 'foo', 'weight' => 1));
     $tag->setWeight('10');
     $this->assertEquals(10.0, $tag->getWeight());
     $this->assertTrue(is_float($tag->getWeight()));
 }
Example #2
0
 /**
  * Returns the given amount as a formatted string according to the
  * given currency.
  * IMPORTANT NOTE:
  * The amount must always be the smallest unit passed as a string
  * or int! It is a very bad idea to use float for monetary
  * calculations if you need exact values, therefore
  * this method won't accept float values.
  * Examples:
  *      format (500, 'EUR');      --> '5,00 EUR'
  *      format (4.23, 'EUR');     --> FALSE
  *      format ('872331', 'EUR'); --> '8.723,31 EUR'.
  *
  * @param int|string $amount Amount to be formatted. Must be the smalles unit
  * @param string $currencyKey ISO 3 letter code of the currency
  * @param bool $withSymbol If set the currency symbol will be rendered
  *
  * @return string|bool String representation of the amount including currency
  *      symbol(s) or FALSE if $amount was of the type float
  */
 public static function format($amount, $currencyKey, $withSymbol = true)
 {
     if (is_float($amount)) {
         return false;
     }
     /**
      * Currency repository.
      *
      * @var CurrencyRepository
      */
     $currencyRepository = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Repository\\CurrencyRepository');
     $currency = $currencyRepository->findByIso3($currencyKey);
     if (empty($currency)) {
         return false;
     }
     $formattedAmount = number_format($amount / $currency['cu_sub_divisor'], $currency['cu_decimal_digits'], $currency['cu_decimal_point'], $currency['cu_thousands_point']);
     if ($withSymbol) {
         $wholeString = $formattedAmount;
         if (!empty($currency['cu_symbol_left'])) {
             $wholeString = $currency['cu_symbol_left'] . ' ' . $wholeString;
         }
         if (!empty($currency['cu_symbol_right'])) {
             $wholeString .= ' ' . $currency['cu_symbol_right'];
         }
     } else {
         $wholeString = $formattedAmount;
     }
     return $wholeString;
 }
Example #3
0
 /**
  * converts a value from the standard unit for the dimension to this unit.
  */
 public function fromStandardUnit($value)
 {
     if (!is_float($value)) {
         throw new \Exception('value must be a float');
     }
     return $value * $this->divisor;
 }
 /**
  * Determines the type of a scalar value
  * @param mixed The scalar value
  * @return string The type of the scalar value
  */
 function getScalarTypeFromValue(&$value)
 {
     require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_constants.php';
     if (is_string($value)) {
         return DOM_XMLRPC_TYPE_STRING;
     } else {
         if (is_int($value)) {
             return DOM_XMLRPC_TYPE_INT;
         } else {
             if (is_float($value)) {
                 return DOM_XMLRPC_TYPE_DOUBLE;
             } else {
                 if (is_bool($value)) {
                     return DOM_XMLRPC_TYPE_BOOLEAN;
                 } else {
                     if (is_object($value)) {
                         require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_datetime_iso8601.php';
                         require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_base64.php';
                         if (get_class($value) == 'dom_xmlrpc_datetime_iso8601') {
                             return DOM_XMLRPC_TYPE_DATETIME;
                         } else {
                             if (get_class($value) == 'dom_xmlrpc_base64') {
                                 return DOM_XMLRPC_TYPE_BASE64;
                             }
                         }
                     }
                 }
             }
         }
     }
     return '';
 }
 public static function serializeValue($value)
 {
     if ($value === null) {
         return 'null';
     } elseif ($value === false) {
         return 'false';
     } elseif ($value === true) {
         return 'true';
     } elseif (is_float($value) && (int) $value == $value) {
         return $value . '.0';
     } elseif (is_object($value) || gettype($value) == 'object') {
         return 'Object ' . get_class($value);
     } elseif (is_resource($value)) {
         return 'Resource ' . get_resource_type($value);
     } elseif (is_array($value)) {
         return 'Array of length ' . count($value);
     } elseif (is_integer($value)) {
         return (int) $value;
     } else {
         $value = (string) $value;
         if (function_exists('mb_convert_encoding')) {
             $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
         }
         return $value;
     }
 }
 public function appendValue($value)
 {
     if (is_null($value)) {
         $this->append('null');
     } elseif (is_string($value)) {
         $this->_toPhpSyntax($value);
     } elseif (is_float($value)) {
         $this->append('<');
         $this->append($value);
         $this->append('F>');
     } elseif (is_bool($value)) {
         $this->append('<');
         $this->append($value ? 'true' : 'false');
         $this->append('>');
     } elseif (is_array($value) || $value instanceof \Iterator || $value instanceof \IteratorAggregate) {
         $this->appendValueList('[', ', ', ']', $value);
     } elseif (is_object($value) && !method_exists($value, '__toString')) {
         $this->append('<');
         $this->append(get_class($value));
         $this->append('>');
     } else {
         $this->append('<');
         $this->append($value);
         $this->append('>');
     }
     return $this;
 }
 /**
  * Sets the ouput gamma
  *
  * @param float
  */
 public function setOutputGamma($gamma)
 {
     if (is_float($gamma)) {
         $this->ouput_gamma = (double) $gamma;
         return true;
     }
 }
Example #8
0
 /** Constructor
  *
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     if (EasyRdf_Utils::is_associative_array($value)) {
         $this->_value = isset($value['value']) ? $value['value'] : null;
         $this->_lang = isset($value['lang']) ? $value['lang'] : null;
         $this->_datatype = isset($value['datatype']) ? $value['datatype'] : null;
     } else {
         $this->_value = $value;
         $this->_lang = $lang ? $lang : null;
         $this->_datatype = $datatype ? $datatype : null;
     }
     // Automatic datatype selection
     if ($this->_datatype == null) {
         if (is_float($this->_value)) {
             $this->_datatype = 'xsd:decimal';
         } else {
             if (is_int($this->_value)) {
                 $this->_datatype = 'xsd:integer';
             } else {
                 if (is_bool($this->_value)) {
                     $this->_datatype = 'xsd:boolean';
                 }
             }
         }
     }
     // Expand shortened URIs (qnames)
     if ($this->_datatype) {
         $this->_datatype = EasyRdf_Namespace::expand($this->_datatype);
     }
 }
 /**
  * Set an Azure property
  *
  * @param string $name  Property name
  * @param mixed  $value Property value
  * @param string $type  Property type (Edm.xxxx)
  * @return DynamicTableEntity
  */
 public function setAzureProperty($name, $value = '', $type = null)
 {
     if (strtolower($name) == 'partitionkey') {
         $this->setPartitionKey($value);
     } elseif (strtolower($name) == 'rowkey') {
         $this->setRowKey($value);
     } elseif (strtolower($name) == 'etag') {
         $this->setEtag($value);
     } else {
         if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
             // Determine type?
             if ($type === null) {
                 $type = 'Edm.String';
                 if (is_int($value)) {
                     $type = 'Edm.Int32';
                 } elseif (is_float($value)) {
                     $type = 'Edm.Double';
                 } elseif (is_bool($value)) {
                     $type = 'Edm.Boolean';
                 }
             }
             // Set dynamic property
             $this->_dynamicProperties[strtolower($name)] = (object) array('Name' => $name, 'Type' => $type, 'Value' => $value);
         }
         $this->_dynamicProperties[strtolower($name)]->Value = $value;
     }
     return $this;
 }
Example #10
0
 /**
  * convert a money amount (represented by a float or string (based on locale) ie.: R$ 5,00) to cents (represented by an int).
  *
  * @param float $amount
  *
  * @throws \UnexpectedValueException
  *
  * @return int
  */
 public static function toCents($amount)
 {
     /*
      * There's probably a better way, but this is what i could come up with
      * to avoid rounding errors
      * todo: search for a better way
      */
     if (!is_float($amount)) {
         $type = gettype($amount);
         throw new \UnexpectedValueException("Needs a float! not {$type}");
     }
     //handle locales
     $locale = localeconv();
     $amount = str_replace($locale['mon_thousands_sep'], '', $amount);
     $amount = str_replace($locale['mon_decimal_point'], '.', $amount);
     $amount = str_replace($locale['decimal_point'], '.', $amount);
     $parts = explode('.', "{$amount}");
     // handle the case where $amount has a .0 fraction part
     if (count($parts) == 1) {
         $parts[] = '00';
     }
     list($whole, $fraction) = $parts;
     /*
      * since the documentation only mentions decimals with a precision of two
      * and doesn't specify any rounding method i'm truncating the number
      *
      * the str_pad is to handle the case where $amount is, for example, 6.9
      */
     $fraction = str_pad(substr($fraction, 0, 2), 2, '0');
     $whole = (int) $whole * 100;
     $fraction = (int) $fraction;
     return $whole + $fraction;
 }
Example #11
0
 /**
  * Constructor.
  *
  * @param array $index Index specification
  */
 public function __construct(array $index)
 {
     if (!isset($index['key'])) {
         throw new InvalidArgumentException('Required "key" document is missing from index specification');
     }
     if (!is_array($index['key']) && !is_object($index['key'])) {
         throw new InvalidArgumentTypeException('"key" option', $index['key'], 'array or object');
     }
     foreach ($index['key'] as $fieldName => $order) {
         if (!is_int($order) && !is_float($order) && !is_string($order)) {
             throw new InvalidArgumentTypeException(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string');
         }
     }
     if (!isset($index['ns'])) {
         throw new InvalidArgumentException('Required "ns" option is missing from index specification');
     }
     if (!is_string($index['ns'])) {
         throw new InvalidArgumentTypeException('"ns" option', $index['ns'], 'string');
     }
     if (!isset($index['name'])) {
         $index['name'] = \MongoDB\generate_index_name($index['key']);
     }
     if (!is_string($index['name'])) {
         throw new InvalidArgumentTypeException('"name" option', $index['name'], 'string');
     }
     $this->index = $index;
 }
Example #12
0
/**
 * This function will return clean variable info
 *
 * @param mixed $var
 * @param string $indent Indent is used when dumping arrays recursivly
 * @param string $indent_close_bracet Indent close bracket param is used
 *   internaly for array output. It is shorter that var indent for 2 spaces
 * @return null
 */
function clean_var_info($var, $indent = '&nbsp;&nbsp;', $indent_close_bracet = '')
{
    if (is_object($var)) {
        return 'Object (class: ' . get_class($var) . ')';
    } elseif (is_resource($var)) {
        return 'Resource (type: ' . get_resource_type($var) . ')';
    } elseif (is_array($var)) {
        $result = 'Array (';
        if (count($var)) {
            foreach ($var as $k => $v) {
                $k_for_display = is_integer($k) ? $k : "'" . clean($k) . "'";
                $result .= "\n" . $indent . '[' . $k_for_display . '] => ' . clean_var_info($v, $indent . '&nbsp;&nbsp;', $indent_close_bracet . $indent);
            }
            // foreach
        }
        // if
        return $result . "\n{$indent_close_bracet})";
    } elseif (is_int($var)) {
        return '(int)' . $var;
    } elseif (is_float($var)) {
        return '(float)' . $var;
    } elseif (is_bool($var)) {
        return $var ? 'true' : 'false';
    } elseif (is_null($var)) {
        return 'NULL';
    } else {
        return "(string) '" . clean($var) . "'";
    }
    // if
}
Example #13
0
 /**
  * @param integer $value The max value for comparison
  */
 public function __construct($value = null)
 {
     if ($value === null || !is_int($value) && !is_float($value)) {
         throw new InvalidArgumentException("invalid value provided for 'value'; " . "expecting an integer or a float");
     }
     $this->max = $value;
 }
 public function __construct($arg1, $arg2 = null)
 {
     if (is_object($arg1) && is_null($arg2)) {
         if (!is_a($arg1, 'midgard_object')) {
             throw new InvalidArgumentException("You can instantiate spots only from MgdSchema objects");
         }
         $this->latitude = $arg1->latitude;
         $this->longitude = $arg1->longitude;
         if (isset($arg1->accuracy)) {
             $this->accuracy = $arg1->accuracy;
         }
         $this->when = $arg1->metadata->created;
     } elseif (is_string($arg1) && is_null($arg2)) {
         $this->text = $arg1;
         $this->accuracy = 80;
     } else {
         if (!is_float($arg1) || !is_float($arg2)) {
             throw new InvalidArgumentException("A pair of WGS-84 coordinates expected");
         }
         $this->latitude = $arg1;
         $this->longitude = $arg2;
     }
     if ($this->latitude > 90 || $this->latitude < -90) {
         throw new InvalidArgumentException("WGS-84 latitude must be between 90 and -90 degrees");
     }
     if ($this->longitude > 180 || $this->longitude < -180) {
         throw new InvalidArgumentException("WGS-84 longitude must be between 180 and -180 degrees");
     }
 }
Example #15
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid integer
  *
  * @param  string|integer $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->error(self::INVALID);
         return false;
     }
     if (is_int($value)) {
         return true;
     }
     $this->setValue($value);
     if ($this->locale === null) {
         $locale = localeconv();
         $valueFiltered = str_replace($locale['decimal_point'], '.', $value);
         $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
         if (strval(intval($valueFiltered)) != $valueFiltered) {
             $this->error(self::NOT_INT);
             return false;
         }
     } else {
         try {
             if (!Zend_Locale_Format::isInteger($value, ['locale' => $this->locale])) {
                 $this->error(self::NOT_INT);
                 return false;
             }
         } catch (Zend_Locale_Exception $e) {
             $this->error(self::NOT_INT);
             return false;
         }
     }
     return true;
 }
Example #16
0
 function mypercentile($X, $percentile)
 {
     if (0 < $percentile && $percentile < 1) {
         $p = $percentile;
     } else {
         if (1 < $percentile && $percentile <= 100) {
             $p = $percentile * 0.01;
         } else {
             return "";
         }
     }
     $count = count($X);
     $allindex = ($count - 1) * $p;
     $intvalindex = intval($allindex);
     $floatval = $allindex - $intvalindex;
     sort($X);
     if (!is_float($floatval)) {
         $result = $X[$intvalindex];
     } else {
         if ($count > $intvalindex + 1) {
             $result = $floatval * ($X[$intvalindex + 1] - $X[$intvalindex]) + $X[$intvalindex];
         } else {
             $result = $X[$intvalindex];
         }
     }
     return $result;
 }
    public $optional_fields = array();
    /**
	* course_module ID associated
	* @var int $instanceid
	*/
    public $taskid;
    /**
	* Assessor ID associated
	* @var int $assessorid
	*/
    public $assessorid;
    /**
	* Student ID associated
	* @var int $studentid
	*/
    public $studentid;
    /**
	* Grade
	* @var int $grade
	*/
    public $grade;
    /**
     * The last time this evalcomix_assessment was modified.
     * @var int $timemodified
     */
    public $timemodified;
    /**
	* Constructor
	*
	* @param int $id ID
	* @param int $instanceid //foreign key of table 'block_evalcomix_tasks'
	* @param int $assessorid //foreign key of table 'user'
Example #18
0
 /**
  * (non-PHPdoc)
  * @see IValidator::isValid()
  */
 public function isValid($val)
 {
     $this->val = $val;
     $ereg = '/^' . $this->type . '$/i';
     if (preg_match($ereg, 'int') || preg_match($ereg, 'integer')) {
         $state = is_int($val);
     } else {
         if (preg_match($ereg, 'float')) {
             $state = is_float($val);
         } else {
             if (preg_match($ereg, 'string')) {
                 $state = is_string($val);
             } else {
                 if (preg_match($ereg, 'array')) {
                     $state = is_array($val);
                 } else {
                     if (preg_match($ereg, 'bool')) {
                         $state = is_bool($val);
                     } else {
                         if (preg_match($ereg, 'null')) {
                             $state = is_null($val);
                         }
                     }
                 }
             }
         }
     }
     if ($state === false) {
         throw new TypeException($this->val, $this->type);
         return false;
     }
     return true;
 }
Example #19
0
 /**
  * Returns true if and only if $value is a valid integer
  *
  * @param  string|int $value
  * @return bool
  * @throws Exception\InvalidArgumentException
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->error(self::INVALID);
         return false;
     }
     if (is_int($value)) {
         return true;
     }
     $this->setValue($value);
     $locale = $this->getLocale();
     $format = new NumberFormatter($locale, NumberFormatter::DECIMAL);
     if (intl_is_failure($format->getErrorCode())) {
         throw new Exception\InvalidArgumentException("Invalid locale string given");
     }
     $parsedInt = $format->parse($value, NumberFormatter::TYPE_INT64);
     if (intl_is_failure($format->getErrorCode())) {
         $this->error(self::NOT_INT);
         return false;
     }
     $decimalSep = $format->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $groupingSep = $format->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
     $valueFiltered = str_replace($groupingSep, '', $value);
     $valueFiltered = str_replace($decimalSep, '.', $valueFiltered);
     if (strval($parsedInt) !== $valueFiltered) {
         $this->error(self::NOT_INT);
         return false;
     }
     return true;
 }
Example #20
0
 function _formatVar(&$value)
 {
     if (is_null($value)) {
         return Artx_Log_Formatter::_formatNull($value);
     }
     if (is_bool($value)) {
         return Artx_Log_Formatter::_formatBool($value);
     }
     if (is_int($value) || is_float($value)) {
         return $value;
     }
     if (is_object($value)) {
         return Artx_Log_Formatter::_formatObject($value);
     }
     // is_callable should be placed before is_string and is_array:
     if (is_callable($value)) {
         return Artx_Log_Formatter::_formatCallback($value);
     }
     if (is_string($value)) {
         return Artx_Log_Formatter::_formatString($value);
     }
     if (is_array($value)) {
         return Artx_Log_Formatter::_formatArray($value);
     }
     return gettype($value) . ' { ... }';
 }
Example #21
0
 private function formatValue($value)
 {
     if (is_string($value)) {
         if (strlen($value) > 20) {
             $this->remaining[] = $value;
             return '?';
         } else {
             return $this->connection->quote($value);
         }
     } elseif (is_int($value)) {
         return (string) $value;
     } elseif (is_float($value)) {
         return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
     } elseif (is_bool($value)) {
         return $this->driver->formatBool($value);
     } elseif ($value === NULL) {
         return 'NULL';
     } elseif ($value instanceof Table\ActiveRow) {
         return $value->getPrimary();
     } elseif (is_array($value) || $value instanceof \Traversable) {
         $vx = $kx = array();
         if ($value instanceof \Traversable) {
             $value = iterator_to_array($value);
         }
         if (isset($value[0])) {
             // non-associative; value, value, value
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'values') {
             // (key, key, ...) VALUES (value, value, ...)
             $this->arrayMode = 'multi';
             foreach ($value as $k => $v) {
                 $kx[] = $this->driver->delimite($k);
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
         } elseif ($this->arrayMode === 'assoc') {
             // key=value, key=value, ...
             foreach ($value as $k => $v) {
                 $vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'multi') {
             // multiple insert (value, value, ...), ...
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $vx) . ')';
         }
     } elseif ($value instanceof \DateTime) {
         return $this->driver->formatDateTime($value);
     } elseif ($value instanceof SqlLiteral) {
         return $value->__toString();
     } else {
         $this->remaining[] = $value;
         return '?';
     }
 }
Example #22
0
 /**
  * @param mixed $value
  * @return Node\Expr
  */
 public static function parserNodeFromValue($value)
 {
     if (is_array($value)) {
         $items = array();
         foreach ($value as $k => $v) {
             $items[] = new Node\Expr\ArrayItem(static::parserNodeFromValue($v), static::parserNodeFromValue($k));
         }
         return new Node\Expr\Array_($items);
     } else {
         if (is_string($value)) {
             return new Node\Scalar\String_($value);
         } else {
             if (is_int($value)) {
                 return new Node\Scalar\LNumber($value);
             } else {
                 if (is_float($value)) {
                     return new Node\Scalar\DNumber($value);
                 } else {
                     if (is_null($value)) {
                         return new Node\Expr\ConstFetch(new Node\Name('null'));
                     } else {
                         if (is_bool($value)) {
                             return new Node\Expr\ConstFetch(new Node\Name($value ? 'true' : 'false'));
                         } else {
                             throw new Exception\DomainException('Unsupported value: ' . Utils::varInfo($value));
                         }
                     }
                 }
             }
         }
     }
 }
Example #23
0
function StatsdPostResult(&$test, $testPath)
{
    require_once 'page_data.inc';
    $runs = $test['runs'];
    if (array_key_exists('discard', $test) && $test['discard'] > 0 && $test['discard'] <= $runs) {
        $runs -= $test['discard'];
    }
    if ($runs) {
        $pageData = loadAllPageData($testPath);
        $medians = array(GetMedianRun($pageData, 0), GetMedianRun($pageData, 1));
        if (isset($pageData) && is_array($pageData)) {
            foreach ($pageData as $run => &$pageRun) {
                foreach ($pageRun as $cached => &$testData) {
                    if (GetSetting('statsdPattern') && !preg_match('/' . GetSetting('statsdPattern') . '/', $test['label'])) {
                        continue;
                    }
                    if (GetSetting('statsdMedianOnly') && !($medians[$cached] == $run)) {
                        continue;
                    }
                    $graphData = array();
                    foreach ($testData as $metric => $value) {
                        if (is_float($value)) {
                            $value = intval($value);
                        }
                        if (is_int($value) && $metric != 'result') {
                            $graphData[$metric] = $value;
                        }
                    }
                    StatsdPost($test['location'], $test['browser'], $test['label'], $cached, $graphData);
                }
            }
        }
    }
}
function display($op, $p1, $p2 = null)
{
    global $calc;
    $search = ['Chippyash\\Type\\Number\\Rational\\', 'Chippyash\\Type\\Number\\Complex\\', 'Chippyash\\Type\\Number\\'];
    $replace = ['', '', ''];
    if (is_int($p1)) {
        $tA = 'PHP-Int';
    } elseif (is_float($p1)) {
        $tA = 'PHP-Float';
    } else {
        $tA = str_replace($search, $replace, get_class($p1));
    }
    if (!is_null($p2)) {
        if (is_int($p2)) {
            $tB = 'PHP-Int';
        } elseif (is_float($p2)) {
            $tB = 'PHP-Float';
        } else {
            $tB = str_replace($search, $replace, get_class($p2));
        }
    }
    try {
        $res = $calc->{$op}($p1, $p2);
        $tR = str_replace($search, $replace, get_class($res));
        if (!is_null($p2)) {
            echo "{$tA}({$p1}) {$op} {$tB}({$p2}) = {$tR}({$res})" . PHP_EOL;
        } else {
            echo "{$op}({$tA}({$p1})) = {$tR}({$res})" . PHP_EOL;
        }
    } catch (InvalidTypeException $e) {
        $msg = $e->getMessage();
        echo "{$tA}({$p1}) {$op} {$tB}({$p2}) is invalid: {$msg}" . PHP_EOL;
    }
}
 function json_encode($data)
 {
     if (is_array($data)) {
         $ret = array();
         // OBJECT
         if (array_keys($data) !== range(0, count($data) - 1)) {
             foreach ($data as $key => $val) {
                 $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
             }
             return "{" . implode(",", $ret) . "}";
             // ARRAY
         } else {
             foreach ($data as $val) {
                 $ret[] = json_encode($val);
             }
             return "[" . implode(",", $ret) . "]";
         }
         // BOOLEAN OR NULL
     } elseif (is_bool($data) || $data === null) {
         return $data === null ? "null" : ($data ? "true" : "false");
     } elseif (is_float($data)) {
         return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
     } elseif (is_int($data)) {
         return $data;
     }
     // STRING
     return kcfinder_json_string_encode($data);
 }
Example #26
0
 /**
  * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Datetime with the given value
  * 
  * The provided value can be an int, which will be interpreted as a Unix timestamp, or 
  * a string in iso8601 format, or a "stdclass native value"  
  *
  * @param mixed $nativeValue a timestamp, an iso8601 date or a "stdclass native value" 
  * @see http://www.w3.org/TR/NOTE-datetime
  */
 public function __construct($nativeValue)
 {
     if (!is_int($nativeValue) and !is_float($nativeValue) and !is_string($nativeValue) and !is_object($nativeValue)) {
         throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
     }
     if (is_object($nativeValue) && strtolower(get_class($nativeValue)) == 'stdclass' && isset($nativeValue->xmlrpc_type)) {
         $scalar = $nativeValue->scalar;
         $timestamp = $nativeValue->timestamp;
     } else {
         if (is_int($nativeValue) or is_float($nativeValue)) {
             $scalar = XML_RPC2_Backend_Php_Value_Datetime::_timestampToIso8601($nativeValue);
             $timestamp = (int) $nativeValue;
         } elseif (is_string($nativeValue)) {
             $scalar = $nativeValue;
             $timestamp = (int) XML_RPC2_Backend_Php_Value_Datetime::_iso8601ToTimestamp($nativeValue);
         } else {
             throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
         }
     }
     $tmp = new stdclass();
     $tmp->scalar = $scalar;
     $tmp->timestamp = $timestamp;
     $tmp->xmlrpc_type = 'datetime';
     $this->setNativeValue($tmp);
 }
Example #27
0
 public static function doConvert(array $data, array $parent = array())
 {
     $output = '';
     foreach ($data as $k => $v) {
         $index = str_replace(' ', '-', $k);
         if (is_array($v)) {
             $sec = array_merge((array) $parent, (array) $index);
             $output .= PHP_EOL . '[' . join('.', $sec) . ']' . PHP_EOL;
             $output .= self::doConvert($v, $sec);
         } else {
             $output .= "{$index}=";
             if (is_numeric($v) || is_float($v)) {
                 $output .= "{$v}";
             } elseif (is_bool($v)) {
                 $output .= $v === true ? 1 : 0;
             } elseif (is_string($v)) {
                 $output .= "'" . addcslashes($v, "'") . "'";
             } else {
                 $output .= "{$v}";
             }
             $output .= PHP_EOL;
         }
     }
     return $output;
 }
Example #28
0
 public function timestamp($mapping, $value)
 {
     if ($value instanceof MongoDate) {
         return $value->sec;
     } else {
         if ($value === NULL) {
             return NULL;
         } else {
             if (is_int($value) || is_float($value)) {
                 return (int) $value;
             } else {
                 if ($value instanceof Zend_Date) {
                     return $value->getTimestamp();
                 } else {
                     if (is_array($value) && isset($value['sec'])) {
                         return $value['sec'];
                     } else {
                         if (!strlen($value)) {
                             return NULL;
                         } else {
                             if (ctype_digit($value)) {
                                 return intval($value);
                             } else {
                                 if (($time = strtotime($value)) !== false) {
                                     return $time;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return NULL;
 }
Example #29
0
 /**
  * Returns `true` if value is of the specified type
  *
  * @param string $type
  * @param mixed $value
  * @return bool
  */
 protected function checkType($type, $value)
 {
     switch ($type) {
         case 'array':
             return is_array($value);
         case 'bool':
         case 'boolean':
             return is_bool($value);
         case 'callable':
             return is_callable($value);
         case 'float':
         case 'double':
             return is_float($value);
         case 'int':
         case 'integer':
             return is_int($value);
         case 'null':
             return is_null($value);
         case 'numeric':
             return is_numeric($value);
         case 'object':
             return is_object($value);
         case 'resource':
             return is_resource($value);
         case 'scalar':
             return is_scalar($value);
         case 'string':
             return is_string($value);
         case 'mixed':
             return true;
         default:
             return $value instanceof $type;
     }
 }
Example #30
0
 /**
  * getSum
  * Get the sum for the transaction
  */
 public function getSum()
 {
     if (is_float($this->sum)) {
         return number_format($this->sum, 2, ',', '');
     }
     return str_replace(".", ",", $this->sum);
 }