-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
226 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace ScriptFUSION\Mapper; | ||
|
||
interface KeyAware | ||
{ | ||
/** | ||
* Sets the key to the specified value. | ||
* | ||
* @param string|int $key Key. | ||
* | ||
* @return void | ||
*/ | ||
public function setKey($key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
namespace ScriptFUSION\Mapper; | ||
|
||
trait KeyAwareTrait | ||
{ | ||
/** | ||
* @var string|int | ||
*/ | ||
private $key; | ||
|
||
public function setKey($key) | ||
{ | ||
$this->key = $key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace ScriptFUSION\Mapper\Strategy; | ||
|
||
use ScriptFUSION\Mapper\KeyAware; | ||
use ScriptFUSION\Mapper\KeyAwareTrait; | ||
|
||
/** | ||
* Copies the current key. | ||
*/ | ||
class CopyKey implements Strategy, KeyAware | ||
{ | ||
use KeyAwareTrait; | ||
|
||
public function __invoke($data, $context = null) | ||
{ | ||
return $this->key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace ScriptFUSIONTest\Integration\Mapper\Strategy; | ||
|
||
use ScriptFUSION\Mapper\Mapper; | ||
use ScriptFUSION\Mapper\Strategy\Collection; | ||
use ScriptFUSION\Mapper\Strategy\Copy; | ||
use ScriptFUSION\Mapper\Strategy\CopyKey; | ||
|
||
final class CopyKeyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function test() | ||
{ | ||
$mapped = (new Mapper)->map( | ||
[ | ||
'foo' => 'bar', | ||
'baz' => [ | ||
'qux' => 'quux', | ||
'corge' => 123, | ||
], | ||
], | ||
[ | ||
'foo' => new CopyKey, | ||
'bar' => new Collection( | ||
new Copy('baz'), | ||
new CopyKey | ||
), | ||
] | ||
); | ||
|
||
self::assertSame([ | ||
'foo' => null, | ||
'bar' => [ | ||
'qux' => 'qux', | ||
'corge' => 'corge', | ||
], | ||
], $mapped); | ||
} | ||
} |
Oops, something went wrong.