This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add FixedPrefix, ApplyOnArrayValueByKey and more structure
- Loading branch information
1 parent
5ea62cf
commit 8b76049
Showing
12 changed files
with
98 additions
and
18 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,44 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace CoStack\Reversible\Applicable; | ||
|
||
use Closure; | ||
use CoStack\Reversible\AbstractReversible; | ||
use CoStack\Reversible\Reversible; | ||
|
||
class ApplyOnArrayValueByKey extends AbstractReversible | ||
{ | ||
private $reversible; | ||
private $keys; | ||
|
||
public function __construct(Reversible $reversible, array $keys) | ||
{ | ||
$this->reversible = $reversible; | ||
$this->keys = $keys; | ||
} | ||
|
||
public function getExecutionClosure(): Closure | ||
{ | ||
return function(array $value): array { | ||
foreach ($this->keys as $key) { | ||
if (!empty($value[$key])) { | ||
$value[$key] = $this->reversible->execute($value[$key]); | ||
} | ||
} | ||
return $value; | ||
}; | ||
} | ||
|
||
public function getReversionClosure(): Closure | ||
{ | ||
return function(array $value): array { | ||
foreach ($this->keys as $key) { | ||
if (!empty($value[$key])) { | ||
$value[$key] = $this->reversible->reverse($value[$key]); | ||
} | ||
} | ||
return $value; | ||
}; | ||
} | ||
|
||
} |
6 changes: 4 additions & 2 deletions
6
src/RecursiveReversible.php → ...plicable/ApplyOnArrayValueRecursively.php
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
2 changes: 1 addition & 1 deletion
2
src/Encoding/Base64Encoding.php → src/Operation/Encoding/Base64Encoding.php
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
2 changes: 1 addition & 1 deletion
2
src/Encoding/JsonEncoding.php → src/Operation/Encoding/JsonEncoding.php
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
2 changes: 1 addition & 1 deletion
2
src/Encoding/RawUrlEncode.php → src/Operation/Encoding/RawUrlEncode.php
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
2 changes: 1 addition & 1 deletion
2
src/Encoding/SerializationEncoding.php → ...ration/Encoding/SerializationEncoding.php
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
2 changes: 1 addition & 1 deletion
2
src/Encoding/UrlEncode.php → src/Operation/Encoding/UrlEncode.php
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,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace CoStack\Reversible\Operation\Fixed; | ||
|
||
use Closure; | ||
use CoStack\Reversible\AbstractReversible; | ||
use function strlen; | ||
use function substr; | ||
|
||
class FixedPrefix extends AbstractReversible | ||
{ | ||
private $prefix; | ||
|
||
public function __construct(string $prefix) | ||
{ | ||
$this->prefix = $prefix; | ||
} | ||
|
||
public function getExecutionClosure(): Closure | ||
{ | ||
return function(string $value): string { | ||
return $this->prefix . $value; | ||
}; | ||
} | ||
|
||
public function getReversionClosure(): Closure | ||
{ | ||
return function(string $value): string { | ||
return substr($value, strlen($this->prefix)); | ||
}; | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
src/Transform/ImplodeTransform.php → src/Operation/Transform/ImplodeTransform.php
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