Skip to content

Commit

Permalink
Merge pull request #8 from wmde/psr4
Browse files Browse the repository at this point in the history
Make Diff PSR-4 compliant
  • Loading branch information
thiemowmde committed Apr 9, 2014
2 parents 197f322 + 6ea2838 commit 02f52fa
Show file tree
Hide file tree
Showing 43 changed files with 412 additions and 270 deletions.
106 changes: 106 additions & 0 deletions Aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

// This is a IDE helper to understand class aliasing.
// It should not be included anywhere.
// Actual aliasing happens in the entry point using class_alias.

namespace { throw new Exception( 'This code is not meant to be executed' ); }

namespace Diff {

/**
* @deprecated since 1.0, use the base class instead.
*/
class CallbackListDiffer extends Differ\CallbackListDiffer {}

/**
* @deprecated since 1.0, use the base interface instead.
*/
interface Differ extends Differ\Differ {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class ListDiffer extends Differ\ListDiffer {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class MapDiffer extends Differ\MapDiffer {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class OrderedListDiffer extends Differ\OrderedListDiffer {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class ListPatcher extends Patcher\ListPatcher {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class MapPatcher extends Patcher\MapPatcher {}

/**
* @deprecated since 1.0, use the base interface instead.
*/
interface Patcher extends Patcher\Patcher {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class PatcherException extends Patcher\PatcherException {}

/**
* @deprecated since 1.0, use the base interface instead.
*/
interface PreviewablePatcher extends Patcher\PreviewablePatcher {}

/**
* @deprecated since 1.0, use the base class instead.
*/
abstract class ThrowingPatcher extends Patcher\ThrowingPatcher {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class Diff extends DiffOp\Diff\Diff {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class ListDiff extends DiffOp\Diff\ListDiff {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class MapDiff extends DiffOp\Diff\MapDiff {}

/**
* @deprecated since 1.0, use the base class instead.
*/
abstract class AtomicDiffOp extends DiffOp\AtomicDiffOp {}

/**
* @deprecated since 1.0, use the base interface instead.
*/
interface DiffOp extends DiffOp\DiffOp {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class DiffOpAdd extends DiffOp\DiffOpAdd {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class DiffOpChange extends DiffOp\DiffOpChange {}

/**
* @deprecated since 1.0, use the base class instead.
*/
class DiffOpRemove extends DiffOp\DiffOpRemove {}

}
29 changes: 28 additions & 1 deletion Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,31 @@
call_user_func( function() {
require_once __DIR__ . '/Diff.mw.php';
} );
}
}

// Aliasing of classes that got renamed.
// For more details, see Aliases.php.

// Aliases introduced in 1.0
class_alias( 'Diff\Differ\CallbackListDiffer', 'Diff\CallbackListDiffer' );
class_alias( 'Diff\Differ\Differ', 'Diff\Differ' );
class_alias( 'Diff\Differ\ListDiffer', 'Diff\ListDiffer' );
class_alias( 'Diff\Differ\MapDiffer', 'Diff\MapDiffer' );
class_alias( 'Diff\Differ\OrderedListDiffer', 'Diff\OrderedListDiffer' );

class_alias( 'Diff\Patcher\ListPatcher', 'Diff\ListPatcher' );
class_alias( 'Diff\Patcher\MapPatcher', 'Diff\MapPatcher' );
class_alias( 'Diff\Patcher\Patcher', 'Diff\Patcher' );
class_alias( 'Diff\Patcher\PatcherException', 'Diff\PatcherException' );
class_alias( 'Diff\Patcher\PreviewablePatcher', 'Diff\PreviewablePatcher' );
class_alias( 'Diff\Patcher\ThrowingPatcher', 'Diff\ThrowingPatcher' );

class_alias( 'Diff\DiffOp\Diff\Diff', 'Diff\Diff' );
class_alias( 'Diff\DiffOp\Diff\ListDiff', 'Diff\ListDiff' );
class_alias( 'Diff\DiffOp\Diff\MapDiff', 'Diff\MapDiff' );

class_alias( 'Diff\DiffOp\AtomicDiffOp', 'Diff\AtomicDiffOp' );
class_alias( 'Diff\DiffOp\DiffOp', 'Diff\DiffOp' );
class_alias( 'Diff\DiffOp\DiffOpAdd', 'Diff\DiffOpAdd' );
class_alias( 'Diff\DiffOp\DiffOpChange', 'Diff\DiffOpChange' );
class_alias( 'Diff\DiffOp\DiffOpRemove', 'Diff\DiffOpRemove' );
13 changes: 13 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ Latest release:

## Version 1.0 (dev)

#### Improvements

* Diff is now PSR-4 compliant

#### Compatibility breaks

* Removed the Diff\IDiff interface (deprecated since 0.5)
* Removed the Diff\IDiffOp interface (deprecated since 0.4)
* Replaced custom autoloader with PSR-4 based loading via Composer

#### Deprecations

* The classes that got moved into other namespace now have their old names as deprecated aliases:
* All Differ classes that resided directly in the Diff namespace are now in Diff\Differ.
* All DiffOp classes that resided directly in the Diff namespace are now in Diff\DiffOp.
* All Patcher classes that resided directly in the Diff namespace are now in Diff\Patcher.

## Version 0.9 (2013-10-04)

#### Additions
Expand Down
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
],
"psr-4": {
"Diff\\": "src/"
},
"classmap": [
"src/differ/",
"src/diffop/",
"src/patcher/",
"tests/phpunit/diffop/DiffOpTest.php",
"tests/phpunit/DiffTestCase.php"
]
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp;

/**
* Base class for diff operations. A diff operation
Expand Down
16 changes: 7 additions & 9 deletions src/diffop/diff/Diff.php → src/DiffOp/Diff/Diff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

namespace Diff;
namespace Diff\DiffOp\Diff;

use Diff\DiffOp\DiffOp;
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use InvalidArgumentException;

/**
Expand All @@ -14,7 +18,7 @@
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler
*/
class Diff extends \ArrayObject implements IDiff {
class Diff extends \ArrayObject implements DiffOp {

/**
* @since 0.4
Expand Down Expand Up @@ -47,8 +51,6 @@ class Diff extends \ArrayObject implements IDiff {
protected $indexOffset = 0;

/**
* @see Diff::__construct
*
* @since 0.1
*
* @param DiffOp[] $operations
Expand Down Expand Up @@ -82,7 +84,7 @@ public function __construct( array $operations = array(), $isAssociative = null
* @return string
*/
private function getObjectType() {
return '\Diff\DiffOp';
return '\Diff\DiffOp\DiffOp';
}

/**
Expand Down Expand Up @@ -194,8 +196,6 @@ public function unserialize( $serialization ) {
}

/**
* Returns the add operations.
*
* @since 0.1
*
* @return DiffOpAdd[]
Expand All @@ -205,8 +205,6 @@ public function getAdditions() {
}

/**
* Returns the remove operations.
*
* @since 0.1
*
* @return DiffOpRemove[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp\Diff;

/**
* Class representing the diff between to (non-associative) arrays.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp\Diff;

/**
* Class representing the diff between to (associative) arrays.
Expand Down
9 changes: 1 addition & 8 deletions src/diffop/DiffOp.php → src/DiffOp/DiffOp.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

namespace Diff;
namespace Diff\DiffOp;

/**
* Interface for diff operations. A diff operation
* represents a change to a single element.
* In case the elements are maps or diffs, the resulting operation
* can be a MapDiff or ListDiff, which contain their own list of DiffOp objects.
*
* Softly deprecated (since 0.4), use Diff instead.
*
* @since 0.1
*
* @licence GNU GPL v2+
Expand Down Expand Up @@ -59,8 +57,3 @@ public function isAtomic();
public function toArray( $valueConverter = null );

}

/**
* @deprecated since 0.4
*/
interface IDiffOp extends DiffOp {}
2 changes: 1 addition & 1 deletion src/diffop/DiffOpAdd.php → src/DiffOp/DiffOpAdd.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp;

/**
* Represents an addition.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp;

/**
* Represents a change.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Diff;
namespace Diff\DiffOp;

/**
* Represents a removal.
Expand Down
5 changes: 1 addition & 4 deletions src/DiffOpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use InvalidArgumentException;

/**
* Factory for constructing DiffOp objects.
*
* @since 0.5
*
* @licence GNU GPL v2+
Expand Down Expand Up @@ -35,7 +33,7 @@ public function __construct( $valueConverter = null ) {
/**
* Returns an instance of DiffOp constructed from the provided array.
*
* This roundtripes with @see DiffOp::toArray.
* This roundtrips with @see DiffOp::toArray.
*
* @since 0.5
*
Expand Down Expand Up @@ -95,7 +93,6 @@ protected function assertHasKey( $key, array $diffOp ) {
}
}


/**
* Converts an array structure to an object using the value converter callback function
* provided to the constructor, if any.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace Diff;
namespace Diff\Differ;

use Diff\ArrayComparer\StrategicArrayComparer;
use Diff\Comparer\CallbackComparer;
use Diff\DiffOp\DiffOp;

/**
* Differ that only looks at the values of the arrays (and thus ignores key differences).
Expand Down
4 changes: 3 additions & 1 deletion src/differ/Differ.php → src/Differ/Differ.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Diff;
namespace Diff\Differ;

use Diff\DiffOp\DiffOp;

/**
* Interface for objects that can diff two arrays to an array of DiffOp.
Expand Down
5 changes: 4 additions & 1 deletion src/differ/ListDiffer.php → src/Differ/ListDiffer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace Diff;
namespace Diff\Differ;

use Diff\ArrayComparer\ArrayComparer;
use Diff\ArrayComparer\NativeArrayComparer;
use Diff\ArrayComparer\StrictArrayComparer;
use Diff\DiffOp\DiffOp;
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpRemove;
use InvalidArgumentException;

/**
Expand Down
7 changes: 6 additions & 1 deletion src/differ/MapDiffer.php → src/Differ/MapDiffer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php

namespace Diff;
namespace Diff\Differ;

use Diff\DiffOp\Diff\Diff;
use Diff\DiffOp\DiffOp;
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use Exception;
use LogicException;

Expand Down
Loading

0 comments on commit 02f52fa

Please sign in to comment.