-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
1 parent
14820c7
commit c9a9ac6
Showing
9 changed files
with
94 additions
and
25 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
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
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,69 @@ | ||
<?php | ||
|
||
namespace Apiato\Support; | ||
|
||
|
||
use Illuminate\Support\Traits\ForwardsCalls; | ||
use Illuminate\Support\Traits\Macroable; | ||
use Vinkla\Hashids\HashidsManager; | ||
|
||
/** | ||
* @mixin HashidsManager | ||
*/ | ||
final class HashidsManagerDecorator | ||
{ | ||
use ForwardsCalls, Macroable { | ||
__call as macroCall; | ||
} | ||
|
||
public function __construct( | ||
private readonly HashidsManager $manager, | ||
) { | ||
} | ||
|
||
/** | ||
* Decode a hash id. | ||
*/ | ||
public function tryDecode(string $hash): int|null | ||
{ | ||
$result = $this->manager->decode($hash); | ||
|
||
if ([] !== $result && is_int($result[0])) { | ||
return $result[0]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Decode a hash id. | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function decode(string $hash): int | ||
{ | ||
$result = $this->tryDecode($hash); | ||
|
||
if (is_null($result)) { | ||
throw new \InvalidArgumentException('Invalid hash id.'); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Dynamically pass method calls to the underlying resource. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
if (self::hasMacro($method)) { | ||
return $this->macroCall($method, $parameters); | ||
} | ||
|
||
return $this->forwardDecoratedCallTo($this->manager, $method, $parameters); | ||
} | ||
} |
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