コード例 #1
0
ファイル: debug.php プロジェクト: Nycto/Round-Eights
/**
 * Returns a string containing information about this value
 *
 * @param mixed $value The value to return information about
 * @return String A shoft string describing the input
 */
function getDump($value)
{
    if (is_bool($value)) {
        return "bool(" . ($value ? "TRUE" : "FALSE") . ")";
    } else {
        if (is_null($value)) {
            return "null()";
        } else {
            if (is_int($value)) {
                return "int(" . $value . ")";
            } else {
                if (is_float($value)) {
                    return "float(" . $value . ")";
                } else {
                    if (is_string($value)) {
                        return "string('" . str_replace(array("\n", "\r", "\t"), array('\\n', '\\r', '\\t'), \r8\str\truncate(addslashes($value), 50, "'...'")) . "')";
                    } else {
                        if (is_array($value)) {
                            if (count($value) == 0) {
                                return "array(0)";
                            }
                            $output = array();
                            $i = 0;
                            foreach ($value as $key => $val) {
                                $i++;
                                $output[] = getDump($key) . " => " . (is_array($val) ? "array(" . count($val) . ")" : getDump($val));
                                if ($i == 2) {
                                    break;
                                }
                            }
                            return "array(" . count($value) . ")(" . implode(", ", $output) . (count($value) > 2 ? ",..." : "") . ")";
                        } else {
                            if (is_object($value)) {
                                return "object(" . get_class($value) . ")";
                            } else {
                                if (is_resource($value)) {
                                    return "resource(" . get_resource_type($value) . ")";
                                } else {
                                    return "unknown(" . gettype($value) . ")";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // @codeCoverageIgnoreEnd
}
コード例 #2
0
ファイル: strings.php プロジェクト: Nycto/Round-Eights
 public function testTruncate()
 {
     $this->assertEquals("Not long enough", \r8\str\truncate("Not long enough", 30));
     $this->assertEquals("too long ...own good", \r8\str\truncate("too long for it's own good", 20));
     $this->assertEquals("too long -- own good", \r8\str\truncate("too long for it's own good", 20, "--"));
 }