Removed the static interface as suggested by @sebastianbergmann

This commit is contained in:
Jeff Welch 2013-02-06 11:20:47 -05:00
parent 680647d606
commit fba4ca1619
3 changed files with 41 additions and 38 deletions

View File

@ -16,34 +16,34 @@ Exporting simple types:
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
$exporter = new PHP_Exporter\Exporter;
// 46
echo Exporter::export(46);
echo $exporter->export(46);
// 4.0
echo Exporter::export(4.0);
echo $exporter->export(4.0);
// 'hello, world!'
echo Exporter::export('hello, world!');
echo $exporter->export('hello, world!');
// false
echo Exporter::export(false);
echo $exporter->export(false);
// NAN
echo Exporter::export(acos(8));
echo $exporter->export(acos(8));
// -INF
echo Exporter::export(log(0));
echo $exporter->export(log(0));
// null
echo Exporter::export(null);
echo $exporter->export(null);
// resource(13) of type (stream)
echo Exporter::export(fopen('php://stderr', 'w'));
echo $exporter->export(fopen('php://stderr', 'w'));
// Binary String: 0x000102030405
echo Exporter::export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
echo $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
```
Exporting complex types:
@ -53,7 +53,7 @@ Exporting complex types:
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
$exporter = new PHP_Exporter\Exporter;
/*
Array &0 (
@ -69,7 +69,7 @@ Array &0 (
)
)
*/
echo Exporter::export(array(array(1,2,3), array("",0,FALSE)));
echo $exporter->export(array(array(1,2,3), array("",0,FALSE)));
/*
Array &0 (
@ -80,7 +80,7 @@ Array &0 (
*/
$array = array();
$array['self'] = &$array;
echo Exporter::export($array);
echo $exporter->export($array);
/*
stdClass Object &0000000003a66dcc0000000025e723e2 (
@ -89,7 +89,7 @@ stdClass Object &0000000003a66dcc0000000025e723e2 (
*/
$obj = new stdClass();
$obj->self = $obj;
echo Exporter::export($obj);
echo $exporter->export($obj);
```
Compact exports:
@ -99,22 +99,22 @@ Compact exports:
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
$exporter = new PHP_Exporter\Exporter;
// Array ()
echo Exporter::shortenedExport(array());
echo $exporter->shortenedExport(array());
// Array (...)
echo Exporter::shortenedExport(array(1,2,3,4,5));
echo $exporter->shortenedExport(array(1,2,3,4,5));
// stdClass Object ()
echo Exporter::shortenedExport(new stdClass);
echo $exporter->shortenedExport(new stdClass);
// Exception Object (...)
echo Exporter::shortenedExport(new Exception);
echo $exporter->shortenedExport(new Exception);
// this\nis\na\nsuper\nlong\nstring\nt...\nspace
echo Exporter::shortenedExport(
echo $exporter->shortenedExport(
<<<LONG_STRING
this
is

View File

@ -71,9 +71,9 @@ class Exporter
* @param integer $indentation The indentation level of the 2nd+ line
* @return string
*/
public static function export($value, $indentation = 0)
public function export($value, $indentation = 0)
{
return self::recursiveExport($value, $indentation);
return $this->recursiveExport($value, $indentation);
}
/**
@ -88,7 +88,7 @@ class Exporter
* @return string
* @see PHP_Exporter\Exporter::export
*/
protected static function recursiveExport(&$value, $indentation, $processed = null)
protected function recursiveExport(&$value, $indentation, $processed = null)
{
if ($value === NULL) {
return 'null';
@ -141,8 +141,8 @@ class Exporter
$output = "Array &$key (\n";
foreach ($value as $k => $v) {
$ek = self::export($k);
$output .= "$whitespace $ek => ".self::recursiveExport($value[$k], $indentation + 1, $processed)."\n";
$ek = $this->export($k);
$output .= "$whitespace $ek => ".$this->recursiveExport($value[$k], $indentation + 1, $processed)."\n";
}
return "$output$whitespace)";
@ -159,13 +159,13 @@ class Exporter
}
$hash = $processed->add($value);
$array = self::toArray($value);
$array = $this->toArray($value);
if (count($array) > 0) {
$output = "$class Object &$hash (\n";
foreach ($array as $k => $v) {
$k = self::export($k);
$output .= "$whitespace $k => ".self::recursiveExport($v, $indentation + 1, $processed)."\n";
$k = $this->export($k);
$output .= "$whitespace $k => ".$this->recursiveExport($v, $indentation + 1, $processed)."\n";
}
return "$output$whitespace)";
@ -193,17 +193,17 @@ class Exporter
* @return string
* @see PHP_Exporter\Exporter::export
*/
public static function shortenedExport($value)
public function shortenedExport($value)
{
if (is_string($value)) {
return self::shortenedString($value);
return $this->shortenedString($value);
}
if(is_object($value)) {
return sprintf(
"%s Object (%s)",
get_class($value),
count(self::toArray($value)) > 0 ? '...' : ''
count($this->toArray($value)) > 0 ? '...' : ''
);
}
@ -214,7 +214,7 @@ class Exporter
);
}
return self::export($value);
return $this->export($value);
}
/**
@ -224,9 +224,9 @@ class Exporter
* @param integer $max The maximum length for the string
* @return string
*/
public static function shortenedString($string, $maxLength = 40)
public function shortenedString($string, $maxLength = 40)
{
$string = self::export($string);
$string = $this->export($string);
if (strlen($string) > $maxLength) {
$string = substr($string, 0, $maxLength - 10) . '...' . substr($string, -7);
@ -242,7 +242,7 @@ class Exporter
* @param object $object
* @return array
*/
public static function toArray($object)
public function toArray($object)
{
$array = array();

View File

@ -250,7 +250,8 @@ EOF
*/
public function testExport($value, $expected)
{
$this->assertStringMatchesFormat($expected, self::trimnl(Exporter::export($value)));
$exporter = new Exporter;
$this->assertStringMatchesFormat($expected, self::trimnl($exporter->export($value)));
}
public function shortenedExportProvider()
@ -283,7 +284,8 @@ EOF
*/
public function testShortenedExport($value, $expected)
{
$this->assertSame($expected, self::trimnl(Exporter::shortenedExport($value)));
$exporter = new Exporter;
$this->assertSame($expected, self::trimnl($exporter->shortenedExport($value)));
}
public function provideNonBinaryMultibyteStrings()
@ -301,6 +303,7 @@ EOF
*/
public function testNonBinaryStringExport($value, $expectedLength)
{
$this->assertRegExp("~'.{{$expectedLength}}'\$~s", Exporter::export($value));
$exporter = new Exporter;
$this->assertRegExp("~'.{{$expectedLength}}'\$~s", $exporter->export($value));
}
}