예제 #1
0
 public function isComparable(AbstractSnapshot $snapshot)
 {
     $refl = new \ReflectionObject($snapshot);
     return $refl->isAnonymous() || parent::isComparable($snapshot);
 }
예제 #2
0
 /**
  * @return string
  */
 private static function _toPhp(&$var, &$list = array(), $level = 0, &$line = 1)
 {
     if (is_float($var)) {
         $var = str_replace(',', '.', "{$var}");
         return strpos($var, '.') === FALSE ? $var . '.0' : $var;
     } elseif (is_bool($var)) {
         return $var ? 'TRUE' : 'FALSE';
     } elseif (is_string($var) && (preg_match('#[^\\x09\\x20-\\x7E\\xA0-\\x{10FFFF}]#u', $var) || preg_last_error())) {
         static $table;
         if ($table === NULL) {
             foreach (array_merge(range("", ""), range("", "ÿ")) as $ch) {
                 $table[$ch] = '\\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT);
             }
             $table['\\'] = '\\\\';
             $table["\r"] = '\\r';
             $table["\n"] = '\\n';
             $table["\t"] = '\\t';
             $table['$'] = '\\$';
             $table['"'] = '\\"';
         }
         return '"' . strtr($var, $table) . '"';
     } elseif (is_array($var)) {
         $space = str_repeat("\t", $level);
         static $marker;
         if ($marker === NULL) {
             $marker = uniqid("", TRUE);
         }
         if (empty($var)) {
             $out = '';
         } elseif ($level > self::$maxDepth || isset($var[$marker])) {
             return '/* Nesting level too deep or recursive dependency */';
         } else {
             $out = "\n{$space}";
             $outShort = '';
             $var[$marker] = TRUE;
             $oldLine = $line;
             $line++;
             $counter = 0;
             foreach ($var as $k => &$v) {
                 if ($k !== $marker) {
                     $item = ($k === $counter ? '' : self::_toPhp($k, $list, $level + 1, $line) . ' => ') . self::_toPhp($v, $list, $level + 1, $line);
                     $counter = is_int($k) ? max($k + 1, $counter) : $counter;
                     $outShort .= ($outShort === '' ? '' : ', ') . $item;
                     $out .= "\t{$item},\n{$space}";
                     $line++;
                 }
             }
             unset($var[$marker]);
             if (strpos($outShort, "\n") === FALSE && strlen($outShort) < self::$maxLength) {
                 $line = $oldLine;
                 $out = $outShort;
             }
         }
         return 'array(' . $out . ')';
     } elseif ($var instanceof \Closure) {
         $rc = new \ReflectionFunction($var);
         return "/* Closure defined in file {$rc->getFileName()} on line {$rc->getStartLine()} */";
     } elseif (is_object($var)) {
         if (PHP_VERSION_ID >= 70000 && ($rc = new \ReflectionObject($var)) && $rc->isAnonymous()) {
             return "/* Anonymous class defined in file {$rc->getFileName()} on line {$rc->getStartLine()} */";
         }
         $arr = (array) $var;
         $space = str_repeat("\t", $level);
         $class = get_class($var);
         $used =& $list[spl_object_hash($var)];
         if (empty($arr)) {
             $out = '';
         } elseif ($used) {
             return "/* {$class} dumped on line {$used} */";
         } elseif ($level > self::$maxDepth) {
             return '/* Nesting level too deep */';
         } else {
             $out = "\n";
             $used = $line;
             $line++;
             foreach ($arr as $k => &$v) {
                 if ($k[0] === "") {
                     $k = substr($k, strrpos($k, "") + 1);
                 }
                 $out .= "{$space}\t" . self::_toPhp($k, $list, $level + 1, $line) . ' => ' . self::_toPhp($v, $list, $level + 1, $line) . ",\n";
                 $line++;
             }
             $out .= $space;
         }
         $hash = self::hash($var);
         return $class === 'stdClass' ? "(object) /* {$hash} */ array({$out})" : "{$class}::__set_state(/* {$hash} */ array({$out}))";
     } elseif (is_resource($var)) {
         return '/* resource ' . get_resource_type($var) . ' */';
     } else {
         $res = var_export($var, TRUE);
         $line += substr_count($res, "\n");
         return $res;
     }
 }