Example #1
0
 /**
  * Create a new instance
  *
  * @param string $val Value of this string
  */
 public function __construct($val)
 {
     parent::__construct($val);
     // Validate...
     if (!is_string($this->val)) {
         return $this->panic();
     }
 }
Example #2
0
 /**
  * Create a new instance
  *
  * @param int|float $val Value of this number
  */
 public function __construct($val)
 {
     parent::__construct($val);
     // Validate...
     if (!(is_integer($this->val) || is_float($this->val))) {
         return $this->panic();
     }
 }
Example #3
0
 function setValue($value)
 {
     if (!is_bool($value)) {
         if (in_array($value, array(1, 'true', 't'))) {
             $value = true;
         } else {
             if (in_array($value, array(0, 'false', 'f'))) {
                 $value = false;
             } else {
                 throw new TypeCastException($this, $value, 'not an Boolean value specified');
             }
         }
     }
     parent::setValue($value);
     return $this;
 }
Example #4
0
 /**
  * @param string $uri       The uri to parse
  * @param bool   $normalize If true, uri will be normalized to a string
  *
  * @return array|string
  */
 public static function parse($uri, $normalize = false)
 {
     //  Don't parse empty uris
     if (empty($uri)) {
         return true;
     }
     //  Let PHP have a whack at it
     $_parts = parse_url($uri);
     //  Unparsable or missing host or path, we bail
     if (false === $_parts || !(isset($_parts['host']) || isset($_parts['path']))) {
         return false;
     }
     $_scheme = IfSet::get($_parts, 'scheme', Scalar::boolVal(IfSet::get($_SERVER, 'HTTPS')) ? 'https' : 'http');
     $_port = IfSet::get($_parts, 'port');
     $_host = IfSet::get($_parts, 'host');
     $_path = IfSet::get($_parts, 'path');
     //  Set ports to defaults for scheme if empty
     if (empty($_port)) {
         $_port = null;
         switch ($_parts['scheme']) {
             case 'http':
                 $_port = 80;
                 break;
             case 'https':
                 $_port = 443;
                 break;
         }
     }
     //  If standard port 80 or 443 and there is no port in uri, clear from parse...
     if (!empty($_port)) {
         if (empty($_host) || ($_port == 80 || $_port == 443) && false === strpos($uri, ':' . $_port)) {
             $_port = null;
         }
     }
     if (!empty($_path) && empty($_host)) {
         //	Special case, handle this generically later
         if ('null' == $_path) {
             return 'null';
         }
         $_host = $_path;
         $_path = null;
     }
     $_uri = ['scheme' => $_scheme, 'host' => $_host, 'port' => $_port];
     return $normalize ? static::normalize($_uri) : $_uri;
 }
Example #5
0
 /**
  * @inheritDoc
  */
 public function compile()
 {
     return parent::compile() . '(' . $this->length . ')';
 }
Example #6
0
 /**
  * @param mixed $value
  *
  * @return bool
  */
 public static function boolval($value)
 {
     return Scalar::boolval($value);
 }
Example #7
0
 /**
  * Определение модуля числа
  *
  * @param Scalar $scalar_a Скаляр
  *
  * @return bool
  */
 public static function abs(Scalar $scalar_a)
 {
     return new Scalar(abs($scalar_a->get_value()));
 }
Example #8
0
 protected function isValidValue($value)
 {
     return parent::isValidValue($value) && is_numeric($value);
 }
Example #9
0
 /**
  * Retrieves a boolean option from the given array. $defaultValue is set and returned if $_key is not 'set'.
  * Optionally will unset option in array.
  *
  * Returns TRUE for "1", "true", "on", "yes" and "y". Returns FALSE otherwise.
  *
  * @param array|\ArrayAccess|object $options
  * @param string                    $key
  * @param boolean                   $defaultValue Defaults to false
  * @param boolean                   $unsetValue
  *
  * @return mixed
  */
 public static function getBool(&$options = array(), $key, $defaultValue = false, $unsetValue = false)
 {
     return Scalar::boolval(static::get($options, $key, $defaultValue, $unsetValue));
 }
Example #10
0
 /**
  * Cleans up a trace array
  *
  * @param array $trace
  * @param int   $skipLines
  * @param null  $basePath
  *
  * @return null|string
  */
 protected static function _cleanTrace(array &$trace, $skipLines = null, $basePath = null)
 {
     $_trace = array();
     $_basePath = $basePath ?: \Kisma::get('app.base_path');
     //	Skip some lines
     if (!empty($skipLines) && count($trace) > $skipLines) {
         $trace = array_slice($trace, $skipLines);
     }
     foreach ($trace as $_index => $_code) {
         $_traceItem = array();
         Scalar::sins($trace[$_index], 'file', 'Unspecified');
         Scalar::sins($trace[$_index], 'line', 0);
         Scalar::sins($trace[$_index], 'function', 'Unspecified');
         $_traceItem['file_name'] = trim(str_replace(array($_basePath, "\t", "\r", "\n", PHP_EOL, 'phar://'), array(null, '    ', null, null, null, null), $trace[$_index]['file']));
         $_args = null;
         if (isset($_code['args']) && !empty($_code['args'])) {
             foreach ($_code['args'] as $_arg) {
                 if (is_object($_arg)) {
                     $_args .= get_class($_arg) . ', ';
                 } else {
                     if (is_array($_arg)) {
                         $_args .= '[array], ';
                     } else {
                         if (is_bool($_arg)) {
                             if ($_arg) {
                                 $_args .= 'true, ';
                             } else {
                                 $_args .= 'false, ';
                             }
                         } else {
                             if (is_numeric($_arg)) {
                                 $_args .= $_arg . ', ';
                             } else {
                                 if (is_scalar($_arg)) {
                                     $_args .= '"' . $_arg . '", ';
                                 } else {
                                     $_args .= '"' . gettype($_arg) . '", ';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $_traceItem['line'] = $trace[$_index]['line'];
         if (isset($_code['type'])) {
             $_traceItem['function'] = (isset($_code['class']) ? $_code['class'] : null) . $_code['type'] . $_code['function'];
         } else {
             $_traceItem['function'] = $_code['function'];
         }
         $_traceItem['function'] .= '(' . ($_args ? ' ' . trim($_args, ', ') . ' ' : null) . ')';
         $_traceItem['index'] = $_index;
         $_trace[] = $_traceItem;
     }
     return $_trace;
 }