Add support for installation using the PEAR Installer (and cleanups)

This commit is contained in:
Sebastian Bergmann 2013-02-09 05:53:35 -05:00
parent 21da888820
commit ff3b279a9c
13 changed files with 218 additions and 75 deletions

5
.gitignore vendored
View File

@ -2,3 +2,8 @@ phpunit.xml
composer.lock
composer.phar
vendor/
cache.properties
build/JeffWelch
build/LICENSE
build/README.md
build/*.tgz

View File

@ -13,10 +13,7 @@ Exporting:
```php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
use JeffWelch\PHP\Exporter;
/*
Exception Object &0000000078de0f0d000000002003a261 (
@ -29,7 +26,8 @@ Exception Object &0000000078de0f0d000000002003a261 (
'previous' => null
)
*/
echo new Exporter(new Exception);
print new Exporter(new Exception);
```
@ -37,10 +35,7 @@ Diffing:
```php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
use JeffWelch\PHP\Exporter;
/*
--- Original
@ -58,8 +53,9 @@ use PHP_Exporter\Exporter;
'previous' => null
)
*/
$exporter = new Exporter(new Exception);
echo $exporter->diff(new Exception);
print $exporter->diff(new Exception);
```
@ -69,47 +65,41 @@ Exporting simple types:
```php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
use JeffWelch\PHP\Exporter;
// 46
echo new Exporter(46);
print new Exporter(46);
// 4.0
echo new Exporter(4.0);
print new Exporter(4.0);
// 'hello, world!'
echo new Exporter('hello, world!');
print new Exporter('hello, world!');
// false
echo new Exporter(false);
print new Exporter(false);
// NAN
echo new Exporter(acos(8));
print new Exporter(acos(8));
// -INF
echo new Exporter(log(0));
print new Exporter(log(0));
// null
echo new Exporter(null);
print new Exporter(null);
// resource(13) of type (stream)
echo new Exporter(fopen('php://stderr', 'w'));
print new Exporter(fopen('php://stderr', 'w'));
// Binary String: 0x000102030405
echo new Exporter(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
print new Exporter(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
```
Exporting complex types:
```php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
use JeffWelch\PHP\Exporter;
/*
Array &0 (
@ -125,7 +115,8 @@ Array &0 (
)
)
*/
echo new Exporter(array(array(1,2,3), array("",0,FALSE)));
print new Exporter(array(array(1,2,3), array("",0,FALSE)));
/*
Array &0 (
@ -134,44 +125,43 @@ Array &0 (
)
)
*/
$array = array();
$array['self'] = &$array;
echo new Exporter($array);
print new Exporter($array);
/*
stdClass Object &0000000003a66dcc0000000025e723e2 (
'self' => stdClass Object &0000000003a66dcc0000000025e723e2
)
*/
$obj = new stdClass();
$obj->self = $obj;
echo new Exporter($obj);
print new Exporter($obj);
```
Compact exports:
```php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use PHP_Exporter\Exporter;
use JeffWelch\PHP\Exporter;
// Array ()
$exporter = new Exporter(array());
echo $exporter->shortenedExport();
print $exporter->shortenedExport();
// Array (...)
$exporter = new Exporter(array(1,2,3,4,5));
echo $exporter->shortenedExport();
print $exporter->shortenedExport();
// stdClass Object ()
$exporter = new Exporter(new stdClass);
echo $exporter->shortenedExport();
print $exporter->shortenedExport();
// Exception Object (...)
$exporter = new Exporter(new Exception);
echo $exporter->shortenedExport();
print $exporter->shortenedExport();
// this\nis\na\nsuper\nlong\nstring\nt...\nspace
$exporter = new Exporter(
@ -195,7 +185,7 @@ of
space
LONG_STRING
);
echo $exporter->shortenedExport();
print $exporter->shortenedExport();
```
## Requirements
@ -234,4 +224,4 @@ thanks goes to the following people for their contributions:
## License
PHP_Exporter is licensed under the [BSD 3-Clause license](LICENSE).
PHP_Exporter is licensed under the [BSD 3-Clause license](LICENSE).

66
build.xml Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="php-exporter" default="build">
<property name="php" value="php"/>
<property name="phpunit" value="phpunit"/>
<target name="build" depends="prepare,lint,phpunit"/>
<target name="clean" description="Cleanup build artifacts">
</target>
<target name="prepare" depends="clean,phpab" description="Prepare for build">
</target>
<target name="phpab" description="Generate autoloader script">
<exec executable="phpab">
<arg value="--output" />
<arg path="src/autoload.php" />
<arg path="src" />
</exec>
</target>
<target name="lint">
<apply executable="${php}" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/src">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit">
<condition property="phpunit_cmd" value="${php} ${phpunit}" else="${phpunit}">
<not>
<equals arg1="${phpunit}" arg2="phpunit" />
</not>
</condition>
<exec executable="${phpunit_cmd}" failonerror="true"/>
</target>
<target name="pear">
<mkdir dir="${basedir}/build/JeffWelch/PHP/Exporter"/>
<copy todir="${basedir}/build/JeffWelch/PHP/Exporter">
<fileset dir="${basedir}/src"/>
</copy>
<copy file="LICENSE" todir="${basedir}/build"/>
<copy file="README.md" todir="${basedir}/build"/>
<exec executable="pear" dir="${basedir}/build">
<arg value="package" />
</exec>
<delete dir="${basedir}/build/JeffWelch"/>
<delete file="${basedir}/build/LICENSE"/>
<delete file="${basedir}/build/README.md"/>
</target>
</project>

59
build/package.xml Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.4.10" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
<name>PHP_Exporter</name>
<channel>pear.phpunit.de</channel>
<summary>A nifty utility for visualizing and diffing PHP variables.</summary>
<description>A nifty utility for visualizing and diffing PHP variables.</description>
<lead>
<name>Jeff Welch</name>
<user>whatthejeff</user>
<email>whatthejeff@gmail.com</email>
<active>yes</active>
</lead>
<date>2013-MM-DD</date>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license>The BSD 3-Clause License</license>
<notes>http://github.com/whatthejeff/php-exporter/tree</notes>
<contents>
<dir name="/">
<dir name="JeffWelch">
<dir name="PHP">
<dir name="Exporter">
<file baseinstalldir="/" name="autoload.php" role="php"/>
<file baseinstalldir="/" name="Context.php" role="php"/>
<file baseinstalldir="/" name="Diff.php" role="php"/>
<file baseinstalldir="/" name="Exception.php" role="php"/>
<file baseinstalldir="/" name="Exporter.php" role="php"/>
</dir>
</dir>
</dir>
<file baseinstalldir="/" name="LICENSE" role="doc"/>
<file baseinstalldir="/" name="README.md" role="doc"/>
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.3.3</min>
</php>
<pearinstaller>
<min>1.9.4</min>
</pearinstaller>
</required>
</dependencies>
<phprelease/>
</package>

View File

@ -33,11 +33,13 @@
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": { "PHP_Exporter": "src/" }
"classmap": [
"src/"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
}

View File

@ -1,24 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="PHP_Exporter Test Suite">
<directory>./tests/PHP_Exporter/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
bootstrap="src/autoload.php">
<testsuites>
<testsuite name="PHP_Exporter">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>./src</directory>
<exclude>
<file>./src/autoload.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -41,7 +41,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
namespace PHP_Exporter;
namespace JeffWelch\PHP\Exporter;
/**
* A context containing previously rendered arrays and objects when recursively
@ -53,7 +53,7 @@ namespace PHP_Exporter;
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.github.com/whatthejeff/php-exporter
*/
class ExporterContext {
class Context {
/**
* Previously seen arrays.
*
@ -112,7 +112,7 @@ class ExporterContext {
return $this->containsObject($value);
}
throw new ExporterException('Only arrays and objects are supported');
throw new Exception('Only arrays and objects are supported');
}
/**

View File

@ -42,7 +42,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
namespace PHP_Exporter;
namespace JeffWelch\PHP\Exporter;
/**
* Diff implementation.

View File

@ -42,7 +42,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
namespace PHP_Exporter;
namespace JeffWelch\PHP\Exporter;
/**
* Exception for PHP_Exporter runtime errors.
@ -53,6 +53,6 @@ namespace PHP_Exporter;
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.github.com/whatthejeff/PHP_Exporter
*/
class ExporterException extends \RuntimeException
class Exception extends \RuntimeException
{
}

View File

@ -41,7 +41,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
namespace PHP_Exporter;
namespace JeffWelch\PHP\Exporter;
/**
* A nifty utility for visualizing and diffing PHP data types.
@ -171,7 +171,7 @@ class Exporter
$whitespace = str_repeat(' ', 4 * $indentation);
if (!$processed) {
$processed = new ExporterContext;
$processed = new Context;
}
if (is_array($value)) {

22
src/autoload.php Normal file
View File

@ -0,0 +1,22 @@
<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
// this is an autogenerated file - do not edit
spl_autoload_register(
function($class) {
static $classes = null;
if ($classes === null) {
$classes = array(
'jeffwelch\\php\\exporter\\context' => '/Context.php',
'jeffwelch\\php\\exporter\\diff' => '/Diff.php',
'jeffwelch\\php\\exporter\\exception' => '/Exception.php',
'jeffwelch\\php\\exporter\\exporter' => '/Exporter.php'
);
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require __DIR__ . $classes[$cn];
}
}
);
// @codeCoverageIgnoreEnd

View File

@ -41,7 +41,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
use PHP_Exporter\Diff;
namespace JeffWelch\PHP\Exporter;
/**
*
@ -52,7 +52,7 @@ use PHP_Exporter\Diff;
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.github.com/whatthejeff/php-exporter
*/
class DiffTest extends PHPUnit_Framework_TestCase
class DiffTest extends \PHPUnit_Framework_TestCase
{
const REMOVED = 2;
const ADDED = 1;

View File

@ -41,7 +41,7 @@
* @link http://www.github.com/whatthejeff/php-exporter
*/
use PHP_Exporter\Exporter;
namespace JeffWelch\PHP\Exporter;
/**
*
@ -52,7 +52,7 @@ use PHP_Exporter\Exporter;
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.github.com/whatthejeff/php-exporter
*/
class ExporterTest extends PHPUnit_Framework_TestCase
class ExporterTest extends \PHPUnit_Framework_TestCase
{
/**
* Removes spaces in front newlines
@ -67,10 +67,10 @@ class ExporterTest extends PHPUnit_Framework_TestCase
public function exportProvider()
{
$obj2 = new stdClass;
$obj2 = new \stdClass;
$obj2->foo = 'bar';
$obj = new stdClass;
$obj = new \stdClass;
//@codingStandardsIgnoreStart
$obj->null = NULL;
//@codingStandardsIgnoreEnd
@ -139,7 +139,7 @@ long
text'
EOF
),
array(new stdClass, 'stdClass Object &%x ()'),
array(new \stdClass, 'stdClass Object &%x ()'),
array($obj,
<<<EOF
stdClass Object &%x (
@ -255,7 +255,7 @@ EOF
public function shortenedExportProvider()
{
$obj = new stdClass;
$obj = new \stdClass;
$obj->foo = 'bar';
$array = array(
@ -271,7 +271,7 @@ EOF
array('1', "'1'"),
// \n\r and \r is converted to \n
array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext", "'this\\nis\\na\\nvery\\nvery\\nvery\\nvery...g\\ntext'"),
array(new stdClass, 'stdClass Object ()'),
array(new \stdClass, 'stdClass Object ()'),
array($obj, 'stdClass Object (...)'),
array(array(), 'Array ()'),
array($array, 'Array (...)'),