コード例 #1
3
ファイル: Handler.php プロジェクト: jakubpas/error-exception
 /**
  * @param \Exception $exception
  * @return string
  * @todo Fix this to get full stack trace
  */
 public static function getExceptionTraceAsString(\Exception $exception)
 {
     $ret = "";
     $count = 0;
     foreach ($exception->getTrace() as $trace) {
         $args = "";
         if (isset($trace['args'])) {
             $args = array();
             foreach ($trace['args'] as $arg) {
                 if (is_string($arg)) {
                     $args[] = "'" . $arg . "'";
                 } elseif (is_array($arg)) {
                     $args[] = "Array";
                 } elseif (is_null($arg)) {
                     $args[] = 'NULL';
                 } elseif (is_bool($arg)) {
                     $args[] = $arg ? "true" : "false";
                 } elseif (is_object($arg)) {
                     $args[] = get_class($arg);
                 } elseif (is_resource($arg)) {
                     $args[] = get_resource_type($arg);
                 } else {
                     $args[] = $arg;
                 }
             }
             $args = join(", ", $args);
         }
         $ret .= sprintf("#%s %s(%s): %s(%s)\n", $count, isset($trace['file']) ? $trace['file'] : 'unknown file', isset($trace['line']) ? $trace['line'] : 'unknown line', isset($trace['class']) ? $trace['class'] . $trace['type'] . $trace['function'] : $trace['function'], $args);
         $count++;
     }
     return $ret;
 }
コード例 #2
2
 /**
  * Class Constructor
  *
  * @param array|string|resource $streamOrUrl Stream or URL to open as a stream
  * @param string|null $mode Mode, only applicable if a URL is given
  * @return void
  * @throws Zend_Log_Exception
  */
 public function __construct($streamOrUrl, $mode = null)
 {
     // Setting the default
     if (null === $mode) {
         $mode = 'a';
     }
     if (is_resource($streamOrUrl)) {
         if (get_resource_type($streamOrUrl) != 'stream') {
             // require_once 'Zend/Log/Exception.php';
             throw new Zend_Log_Exception('Resource is not a stream');
         }
         if ($mode != 'a') {
             // require_once 'Zend/Log/Exception.php';
             throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
         }
         $this->_stream = $streamOrUrl;
     } else {
         if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) {
             $streamOrUrl = $streamOrUrl['stream'];
         }
         if (!($this->_stream = @fopen($streamOrUrl, $mode, false))) {
             // require_once 'Zend/Log/Exception.php';
             $msg = "\"{$streamOrUrl}\" cannot be opened with mode \"{$mode}\"";
             throw new Zend_Log_Exception($msg);
         }
     }
     $this->_formatter = new Zend_Log_Formatter_Simple();
 }
コード例 #3
1
ファイル: String.php プロジェクト: hzh123/my_yaf
 public static function printParams($params, $glue = ',')
 {
     $res = '';
     if (count($params)) {
         foreach ($params as $val) {
             if (is_string($val)) {
                 $val = sprintf('\'%s\'', $val);
             } else {
                 if (is_int($val) || is_float($val)) {
                     null;
                 } else {
                     if (is_bool($val)) {
                         $val = $val ? 'true' : 'false';
                     } else {
                         if (is_array($val)) {
                             $val = sprintf('array:%s', json_encode($val, JSON_UNESCAPED_UNICODE));
                         } else {
                             if (is_object($val)) {
                                 $val = sprintf('[object]%s:%s', get_class($val), json_encode($val, JSON_UNESCAPED_UNICODE));
                             } else {
                                 if (is_resource($val)) {
                                     $val = sprintf('[resource]%s', get_resource_type($val));
                                 } else {
                                     $val = 'other';
                                 }
                             }
                         }
                     }
                 }
             }
             $res .= $glue . ' ' . strval($val);
         }
     }
     return substr($res, 2);
 }
コード例 #4
1
 private function varToString($var)
 {
     if (is_object($var)) {
         return sprintf('Object(%s)', get_class($var));
     }
     if (is_array($var)) {
         $a = array();
         foreach ($var as $k => $v) {
             $a[] = sprintf('%s => %s', $k, $this->varToString($v));
         }
         return sprintf('Array(%s)', implode(', ', $a));
     }
     if (is_resource($var)) {
         return sprintf('Resource(%s)', get_resource_type($var));
     }
     if (null === $var) {
         return 'null';
     }
     if (false === $var) {
         return 'false';
     }
     if (true === $var) {
         return 'true';
     }
     return (string) $var;
 }
コード例 #5
0
ファイル: TbsZip.php プロジェクト: seblangis/DocxMerge
 function Open($ArchFile, $UseIncludePath = false)
 {
     // Open the zip archive
     if (!isset($this->Meth8Ok)) {
         $this->__construct();
     }
     // for PHP 4 compatibility
     $this->Close();
     // close handle and init info
     $this->Error = false;
     $this->ArchIsNew = false;
     $this->ArchIsStream = is_resource($ArchFile) && get_resource_type($ArchFile) == 'stream';
     if ($this->ArchIsStream) {
         $this->ArchFile = 'from_stream.zip';
         $this->ArchHnd = $ArchFile;
     } else {
         // open the file
         $this->ArchFile = $ArchFile;
         $this->ArchHnd = fopen($ArchFile, 'rb', $UseIncludePath);
     }
     $ok = !($this->ArchHnd === false);
     if ($ok) {
         $ok = $this->CentralDirRead();
     }
     return $ok;
 }
コード例 #6
0
 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;
     }
 }
コード例 #7
0
ファイル: Pex.php プロジェクト: chuchiy/phpex
 public function emit($cycle, $r = null)
 {
     $writer = $cycle->writer() ? $cycle->writer() : $cycle();
     if ($r) {
         if (is_callable($r)) {
             $r = $r();
         }
         if (is_resource($r) and get_resource_type($r) == 'stream') {
             //flush header
             $writer();
             $stream = $cycle->response()->getBody()->detach();
             stream_copy_to_stream($r, $stream);
             $cycle->response()->getBody()->attach($stream);
         } elseif (is_array($r) or $r instanceof \Traversable or $r instanceof \Generator) {
             foreach ($r as $part) {
                 $writer($part);
             }
         } else {
             $writer((string) $r);
         }
     } else {
         //flush if not
         $writer();
     }
 }
コード例 #8
0
ファイル: functions.php プロジェクト: bonniebo421/rockhall
function spy($x)
{
    switch (1) {
        case is_string($x):
            return '"' . $x . '"';
        case is_numeric($x):
            return $x;
        case is_null($x):
            return 'NULL';
        case is_bool($x):
            return $x ? 'TRUE' : 'FALSE';
        case is_resource($x):
            return '(' . get_resource_type($x) . ')' . "{$x}";
        case is_object($x):
            return get_class($x);
        case is_array($x):
            break;
        case is_scalar($x):
        default:
            return "{$x}";
    }
    switch (count($x)) {
        case 0:
            return '[]';
        case 1:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_pop($x)) . ']';
        case 2:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
        default:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ..., ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
    }
    trigger_error('Something terrible has happened.');
}
コード例 #9
0
ファイル: Result.php プロジェクト: Nycto/Round-Eights
 /**
  * Constructor...
  *
  * @param Resource $result The SQLite result resource
  */
 public function __construct($result)
 {
     if (!is_resource($result) || get_resource_type($result) != 'sqlite result') {
         throw new \r8\Exception\Argument(0, "Result Resource", "Must be a SQLite Result resource");
     }
     $this->result = $result;
 }
コード例 #10
0
ファイル: Stream.php プロジェクト: crystalplanet/redshift
 /**
  * Creates a new stream.
  *
  * @param stream $stream
  */
 public function __construct($stream)
 {
     if (!is_resource($stream) || get_resource_type($stream) !== 'stream') {
         throw new \RuntimeException(self::class . '::__construct($stream) expects a stream as the first argument!');
     }
     $this->stream = $stream;
 }
コード例 #11
0
ファイル: base2.php プロジェクト: sjw-github/lib
 public function setTimeout($timeout)
 {
     $this->options['timeout'] = $timeout;
     if ($this->socket && get_resource_type($this->socket) === 'stream') {
         stream_set_timeout($this->socket, $timeout);
     }
 }
コード例 #12
0
ファイル: CasterStub.php プロジェクト: vomasmic/symfony
 public function __construct($value, $class = '')
 {
     $this->class = $class;
     $this->value = $value;
     switch (gettype($value)) {
         case 'object':
             $this->type = self::TYPE_OBJECT;
             $this->class = get_class($value);
             $this->cut = -1;
             break;
         case 'array':
             $this->type = self::TYPE_ARRAY;
             $this->class = self::ARRAY_ASSOC;
             $this->cut = $this->value = count($value);
             break;
         case 'resource':
         case 'unknown type':
             $this->type = self::TYPE_RESOURCE;
             $this->class = @get_resource_type($value);
             $this->cut = -1;
             break;
         case 'string':
             if ('' === $class) {
                 $this->type = self::TYPE_STRING;
                 $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
                 $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
                 $this->value = '';
             }
             break;
     }
 }
コード例 #13
0
 /**
  * The constructor
  * @param resource $socket a valid socket resource
  * @throws \InvalidArgumentException
  */
 public function __construct($socket)
 {
     if (!is_resource($socket) && strtolower(@get_resource_type($socket)) != 'socket') {
         throw new \InvalidArgumentException('Socket resource is required!');
     }
     $this->socket = $socket;
 }
コード例 #14
0
ファイル: DB_MySQL.php プロジェクト: acdha/impphp
 function __construct()
 {
     /**
      * The constructor can either be called with an existing database handle
      * or a set of four parameters to use with mysqli_[p]connect():
      *
      * $db = new DB_MySQL($my_existing_mysqli_link_handle);
      *
      * or
      *
      * $db = new DB_MySQL("localhost", "my_db", "db_user", "db_password");
      *
      */
     switch (func_num_args()) {
         case 1:
             $h = func_get_arg(0);
             // Make sure what we got really is a mysql link
             assert(is_resource($h));
             $t = get_resource_type($h);
             if ($t == "mysql link") {
                 $this->isPersistent = false;
             } elseif ($t == "mysql link persistent") {
                 $this->isPersistent = true;
             } else {
                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() Passed handle isn't a mysql connection - it's a {$t} resource!", E_USER_ERROR);
             }
             $this->Handle = $t;
             return;
         case 4:
             list($this->Server, $this->Database, $this->Username, $this->Password) = func_get_args();
             break;
         default:
             trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() called with " . func_num_args() . " arguments - it should be called with either 1 (a mysql connection handle) or 4 (the server, db_name, user, and password to connect with)", E_USER_ERROR);
     }
 }
コード例 #15
0
ファイル: XLib.php プロジェクト: xpence/portfolio
 public static function is_ref(&$arg1, &$arg2)
 {
     if (!self::is_same($arg1, $arg2)) {
         return false;
     }
     $same = false;
     if (is_array($arg1)) {
         do {
             $key = uniqid("is_ref_", true);
         } while (array_key_exists($key, $arg1));
         if (array_key_exists($key, $arg2)) {
             return false;
         }
         $data = uniqid('is_ref_data_', true);
         $arg1[$key] =& $data;
         if (array_key_exists($key, $arg2)) {
             if ($arg2[$key] === $data) {
                 $same = true;
             }
         }
         unset($arg1[$key]);
     } elseif (is_object($arg1)) {
         if (get_class($arg1) !== get_class($arg2)) {
             return false;
         }
         $obj1 = array_keys(get_object_vars($arg1));
         $obj2 = array_keys(get_object_vars($arg2));
         do {
             $key = uniqid('is_ref_', true);
         } while (in_array($key, $obj1));
         if (in_array($key, $obj2)) {
             return false;
         }
         $data = uniqid('is_ref_data_', true);
         $arg1->{$key} =& $data;
         if (isset($arg2->{$key})) {
             if ($arg2->{$key} === $data) {
                 $same = true;
             }
         }
         unset($arg1->{$key});
     } elseif (is_resource($arg1)) {
         if (get_resource_type($arg1) !== get_resource_type($arg2)) {
             return false;
         }
         return (string) $arg1 === (string) $arg2;
     } else {
         if ($arg1 !== $arg2) {
             return false;
         }
         do {
             $key = uniqid('is_ref_', true);
         } while ($key === $arg1);
         $tmp = $arg1;
         $arg1 = $key;
         $same = $arg1 === $arg2;
         $arg1 = $tmp;
     }
     return $same;
 }
コード例 #16
0
 /**
  * @since 1.0
  *
  * @param resource $handle
  */
 public function __construct($handle)
 {
     if (get_resource_type($handle) !== 'curl') {
         throw new InvalidArgumentException("Expected a cURL resource type");
     }
     $this->handle = $handle;
 }
コード例 #17
0
ファイル: AbstractFormatter.php プロジェクト: phPoirot/Logger
 /**
  * Normalize all non-scalar data types (except null) in a string value
  *
  * @param mixed $value
  * @return mixed
  */
 protected function flatten($value)
 {
     if (is_scalar($value) || null === $value) {
         return $value;
     }
     // better readable JSON
     static $jsonFlags;
     if ($jsonFlags === null) {
         $jsonFlags = 0;
         $jsonFlags |= defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0;
         $jsonFlags |= defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
     }
     if ($value instanceof \DateTime) {
         $value = $value->format($this->getDateTimeFormat());
     } elseif ($value instanceof \Traversable) {
         $value = json_encode(iterator_to_array($value), $jsonFlags);
     } elseif (is_array($value)) {
         $value = json_encode($value, $jsonFlags);
     } elseif (is_object($value) && !method_exists($value, '__toString')) {
         $value = sprintf('object(%s) %s', get_class($value), json_encode($value));
     } elseif (is_resource($value)) {
         $value = sprintf('resource(%s)', get_resource_type($value));
     } elseif (!is_object($value)) {
         $value = gettype($value);
     }
     return (string) $value;
 }
コード例 #18
0
function is_myresource($o, $onlyres = false)
{
    if (extension_loaded('mysql')) {
        if (!is_resource($o)) {
            return false;
        }
        $cname = get_resource_type($o);
        if ($cname != 'mysql link' && $cname != 'mysql result') {
            return false;
        }
        if ($onlyres && $cname != 'mysql result') {
            return false;
        }
        unset($cname);
        return true;
    }
    if (!is_object($o)) {
        return false;
    }
    $cname = get_class($o);
    if ($cname != 'mysqli' && $cname != 'mysqli_result') {
        return false;
    }
    if ($onlyres && $cname != 'mysqli_result') {
        return false;
    }
    unset($cname);
    return true;
}
コード例 #19
0
ファイル: Statement.php プロジェクト: idwsdta/INIT-frame
 /**
  * Initialize
  *
  * @param  resource $pgsql
  * @return void
  * @throws Exception\RuntimeException for invalid or missing postgresql connection
  */
 public function initialize($pgsql)
 {
     if (!is_resource($pgsql) || get_resource_type($pgsql) !== 'pgsql link') {
         throw new Exception\RuntimeException(sprintf('%s: Invalid or missing postgresql connection; received "%s"', __METHOD__, get_resource_type($pgsql)));
     }
     $this->pgsql = $pgsql;
 }
コード例 #20
0
ファイル: ImageWriter.php プロジェクト: naucon/image
 /**
  * @access      protected
  * @param       resource    image resource
  * @return      bool
  */
 protected function isImageResource($imageResource)
 {
     if (is_resource($imageResource) && get_resource_type($imageResource) == 'gd') {
         return true;
     }
     return false;
 }
コード例 #21
0
 /**
  * Stringifies any provided value.
  *
  * @param mixed $value        	
  * @param boolean $exportObject        	
  *
  * @return string
  */
 public function stringify($value, $exportObject = true)
 {
     if (is_array($value)) {
         if (range(0, count($value) - 1) === array_keys($value)) {
             return '[' . implode(', ', array_map(array($this, __FUNCTION__), $value)) . ']';
         }
         $stringify = array($this, __FUNCTION__);
         return '[' . implode(', ', array_map(function ($item, $key) use($stringify) {
             return (is_integer($key) ? $key : '"' . $key . '"') . ' => ' . call_user_func($stringify, $item);
         }, $value, array_keys($value))) . ']';
     }
     if (is_resource($value)) {
         return get_resource_type($value) . ':' . $value;
     }
     if (is_object($value)) {
         return $exportObject ? ExportUtil::export($value) : sprintf('%s:%s', get_class($value), spl_object_hash($value));
     }
     if (true === $value || false === $value) {
         return $value ? 'true' : 'false';
     }
     if (is_string($value)) {
         $str = sprintf('"%s"', str_replace("\n", '\\n', $value));
         if (50 <= strlen($str)) {
             return substr($str, 0, 50) . '"...';
         }
         return $str;
     }
     if (null === $value) {
         return 'null';
     }
     return (string) $value;
 }
コード例 #22
0
ファイル: SiteExporter.php プロジェクト: claudinec/galan-wiki
 /**
  * @param resource $sink A file handle open for writing
  */
 public function __construct($sink)
 {
     if (!is_resource($sink) || get_resource_type($sink) !== 'stream') {
         throw new InvalidArgumentException('$sink must be a file handle');
     }
     $this->sink = $sink;
 }
コード例 #23
0
ファイル: class_gd.php プロジェクト: Evrika/Vidal
 /** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
  * Returns FALSE on failure. The only one parameter $image can be an instance of this class,
  * a GD resource, an array(width, height) or path to image file.
  * @param mixed $image
  * @return array */
 protected function build_image($image)
 {
     if ($image instanceof gd) {
         $width = $image->get_width();
         $height = $image->get_height();
         $image = $image->get_image();
     } elseif (is_resource($image) && get_resource_type($image) == "gd") {
         $width = @imagesx($image);
         $height = @imagesy($image);
     } elseif (is_array($image)) {
         list($key, $width) = each($image);
         list($key, $height) = each($image);
         $image = imagecreatetruecolor($width, $height);
     } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
         $image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false)))));
         if ($type == IMAGETYPE_PNG) {
             imagealphablending($image, false);
         }
     }
     $return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false;
     if ($return !== false && isset($type)) {
         $this->type = $type;
     }
     return $return;
 }
コード例 #24
0
 function getExceptionTraceAsString(Exception $exception)
 {
     $rtn = "";
     $count = 0;
     foreach ($exception->getTrace() as $frame) {
         $args = "";
         if (isset($frame['args'])) {
             $args = array();
             foreach ($frame['args'] as $arg) {
                 if (is_string($arg)) {
                     $args[] = "'" . $arg . "'";
                 } elseif (is_array($arg)) {
                     $args[] = json_encode($arg);
                 } elseif (is_null($arg)) {
                     $args[] = 'NULL';
                 } elseif (is_bool($arg)) {
                     $args[] = $arg ? "true" : "false";
                 } elseif (is_object($arg)) {
                     $args[] = get_class($arg);
                 } elseif (is_resource($arg)) {
                     $args[] = get_resource_type($arg);
                 } else {
                     $args[] = $arg;
                 }
             }
             $args = join(", ", $args);
         }
         $rtn .= sprintf("#%s %s(%s): %s%s(%s)\n", $count, $frame['file'], $frame['line'], isset($frame['class']) ? $frame['class'] . '->' : '', $frame['function'], $args);
         $count++;
     }
     return $rtn;
 }
コード例 #25
0
 /**
  * Set the Stream resource we use to get the email text
  * @return Object MimeMailParser Instance
  * @param $stream Resource
  */
 public function setStream($stream)
 {
     // streams have to be cached to file first
     if (get_resource_type($stream) == 'stream') {
         $tmp_fp = tmpfile();
         if ($tmp_fp) {
             while (!feof($stream)) {
                 fwrite($tmp_fp, fread($stream, 2028));
             }
             fseek($tmp_fp, 0);
             $this->stream =& $tmp_fp;
         } else {
             throw new Exception('Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.');
             return false;
         }
         fclose($stream);
     } else {
         $this->stream = $stream;
     }
     $this->resource = mailparse_msg_create();
     // parses the message incrementally low memory usage but slower
     while (!feof($this->stream)) {
         mailparse_msg_parse($this->resource, fread($this->stream, 2082));
     }
     $this->parse();
     return $this;
 }
コード例 #26
0
 /**
  * Return a string with the information of the value
  * null value: NULL
  * boolean: TRUE, FALSE
  * array: Array
  * scalar: converted-value
  * resource: (type resource #number)
  * object with __toString(): result of __toString()
  * object DateTime: ISO 8601 date
  * object: (className Object)
  * anonymous function: same as object
  *
  * @param mixed $value
  * @return string
  */
 protected function toolValueToString($value)
 {
     // null
     if (is_null($value)) {
         return 'NULL';
     }
     // boolean constants
     if (is_bool($value)) {
         return $value ? 'TRUE' : 'FALSE';
     }
     // array
     if (is_array($value)) {
         return 'Array';
     }
     // scalar types (integer, float, string)
     if (is_scalar($value)) {
         return (string) $value;
     }
     // resource
     if (is_resource($value)) {
         return '(' . get_resource_type($value) . ' resource #' . (int) $value . ')';
     }
     // after this line $value is an object since is not null, scalar, array or resource
     // __toString() is implemented
     if (is_callable([$value, '__toString'])) {
         return (string) $value->__toString();
     }
     // object of type \DateTime
     if ($value instanceof \DateTimeInterface) {
         return $value->format("c");
     }
     // unknown type
     return '(' . get_class($value) . ' Object)';
 }
コード例 #27
0
 /**
  * constructor
  *
  * If no file pointer given it will fall back to STDOUT.
  *
  * @param   resource  $out  optional
  * @throws  InvalidArgumentException
  */
 public function __construct($out = STDOUT)
 {
     if (is_resource($out) === false || get_resource_type($out) !== 'stream') {
         throw new InvalidArgumentException('Given filepointer is not a resource of type stream');
     }
     $this->out = $out;
 }
コード例 #28
0
ファイル: general.php プロジェクト: pnagaraju25/fengoffice
/**
 * 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
}
コード例 #29
0
ファイル: Stream.php プロジェクト: rkeplin/zf2
    /**
     * Class Constructor
     *
     * @param array|string|resource $streamOrUrl Stream or URL to open as a stream
     * @param string|null $mode Mode, only applicable if a URL is given
     * @return void
     * @throws \Zend\Log\Exception\InvalidArgumentException
     * @throws \Zend\Log\Excpeiton\RuntimeException
     */
    public function __construct($streamOrUrl, $mode = null)
    {
        // Setting the default
        if (null === $mode) {
            $mode = 'a';
        }

        if (is_resource($streamOrUrl)) {
            if (get_resource_type($streamOrUrl) != 'stream') {
                throw new Log\Exception\InvalidArgumentException('Resource is not a stream');
            }

            if ($mode != 'a') {
                throw new Log\Exception\InvalidArgumentException('Mode cannot be changed on existing streams');
            }

            $this->_stream = $streamOrUrl;
        } else {
            if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) {
                $streamOrUrl = $streamOrUrl['stream'];
            }

            if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
                $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
                throw new Log\Exception\RuntimeException($msg);
            }
        }

        $this->_formatter = new Log\Formatter\Simple();
    }
コード例 #30
0
ファイル: File.php プロジェクト: robik/cFTP
 /**
  * Creates new cFTP_File object
  * 
  * @param Resource $handle FTP session Handle
  * @param string $name File name
  * @throws cFTP_Exception
  */
 public function __construct($handle, $name) 
 {
     if( get_resource_type($handle) != 'FTP Buffer' )
         throw new InvalidArgumentException( 'Specified argument is not valid resource' );
     
     parent::__construct($handle, $name);
 }