Exemplo n.º 1
0
 /**
  * Creates an HTTP cookie to be sent along with an HTTP response.
  *
  * Internally, the value of a cookie is always stored as a string. If the cookie's value was provided as an array
  * or map, it's encoded into JSON and is stored as a JSON string. Boolean values are stored as "1" for `true` and
  * as "0" for `false`.
  *
  * @param  string $cookieName The cookie's name.
  * @param  mixed $value The cookie's value. This can be a string, a `bool`, an `int`, a `float`, an array, or a
  * map.
  */
 public function __construct($cookieName, $value)
 {
     assert('is_cstring($cookieName) && (is_cstring($value) || is_bool($value) || is_int($value) || ' . 'is_float($value) || is_collection($value))', vs(isset($this), get_defined_vars()));
     $this->m_name = $cookieName;
     if (is_cstring($value)) {
         $this->m_value = $value;
     } else {
         if (is_bool($value)) {
             $this->m_value = CString::fromBool10($value);
         } else {
             if (is_int($value)) {
                 $this->m_value = CString::fromInt($value);
             } else {
                 if (is_float($value)) {
                     $this->m_value = CString::fromFloat($value);
                 } else {
                     $json = new CJson($value);
                     $this->m_value = $json->encode();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Joins the elements of an array into a string.
  *
  * The elements in the source array are not required to be all strings and, in addition to types that know how to
  * become a string, an element can be `int`, `float`, or `bool`. In the resulting string, a boolean value of
  * `true` becomes "1" and `false` becomes "0".
  *
  * As a special case, the array is allowed to be empty.
  *
  * @param  array $array The array containing the elements to be joined.
  * @param  string $binder The string to be put between any two elements in the resulting string, such as ", ".
  * Can be empty.
  *
  * @return string The resulting string.
  */
 public static function join($array, $binder)
 {
     assert('is_carray($array) && is_cstring($binder)', vs(isset($this), get_defined_vars()));
     $array = splarray($array);
     $array = self::makeCopy($array);
     for ($i = 0; $i < $array->getSize(); $i++) {
         if (!is_cstring($array[$i])) {
             if (is_bool($array[$i])) {
                 $array[$i] = CString::fromBool10($array[$i]);
             } else {
                 if (is_int($array[$i])) {
                     $array[$i] = CString::fromInt($array[$i]);
                 } else {
                     if (is_float($array[$i])) {
                         $array[$i] = CString::fromFloat($array[$i]);
                     }
                 }
             }
         }
     }
     return implode($binder, self::toPArray($array));
 }
Exemplo n.º 3
0
 /**
  * Sets the value of a PHP's configuration option to a floating-point value.
  *
  * @param  string $optionName The name of the option.
  * @param  float $optionValue The option's new value.
  *
  * @return void
  */
 public static function setConfigOptionFloat($optionName, $optionValue)
 {
     assert('is_cstring($optionName) && is_float($optionValue)', vs(isset($this), get_defined_vars()));
     self::setConfigOption($optionName, CString::fromFloat($optionValue));
 }
Exemplo n.º 4
0
 protected static function recurseQueryValueBeforeComposingQs($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (!is_collection($value)) {
         if (!is_cstring($value)) {
             if (is_bool($value)) {
                 $value = CString::fromBool10($value);
             } else {
                 if (is_int($value)) {
                     $value = CString::fromInt($value);
                 } else {
                     if (is_float($value)) {
                         $value = CString::fromFloat($value);
                     } else {
                         assert('false', vs(isset($this), get_defined_vars()));
                     }
                 }
             }
         }
         return $value;
     }
     if (is_carray($value)) {
         $value = splarray($value)->toArray();
     } else {
         $value = parray($value);
     }
     foreach ($value as &$mapValue) {
         $mapValue = self::recurseQueryValueBeforeComposingQs($mapValue, $currDepth);
     }
     unset($mapValue);
     return $value;
 }
Exemplo n.º 5
0
 protected static function collectionElementToString($elementValue, &$success)
 {
     if (is_cstring($elementValue)) {
         return $elementValue;
     }
     if (is_bool($elementValue)) {
         return CString::fromBool10($elementValue);
     }
     if (is_int($elementValue)) {
         return CString::fromInt($elementValue);
     }
     if (is_float($elementValue)) {
         return CString::fromFloat($elementValue);
     }
     $success = false;
 }