generated from chevere/package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
improves
Showing
5 changed files
with
148 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Chevere. | ||
* | ||
* (c) Rodolfo Berrios <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chevere\Parameter\Attributes; | ||
|
||
use Attribute; | ||
use Chevere\Parameter\Interfaces\ParameterAttributeInterface; | ||
use Chevere\Parameter\Interfaces\ParameterInterface; | ||
use LogicException; | ||
use function Chevere\Parameter\object; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_FUNCTION)] | ||
class CallableAttr implements ParameterAttributeInterface | ||
{ | ||
public readonly ParameterInterface $parameter; | ||
|
||
public function __construct(callable $callable) | ||
{ | ||
$return = $callable(); | ||
object(ParameterInterface::class)($return); | ||
Check warning on line 30 in src/Attributes/CallableAttr.php GitHub Actions / PHP 8.1 test on ubuntu-latest
Check warning on line 30 in src/Attributes/CallableAttr.php GitHub Actions / PHP 8.2 test on ubuntu-latest
Check warning on line 30 in src/Attributes/CallableAttr.php GitHub Actions / PHP 8.3 test on ubuntu-latest
|
||
// if (!is_object($return)) { | ||
// throw new LogicException('DynamicAttr must return an object'); | ||
// } | ||
// if (! $return instanceof ParameterInterface) { | ||
// throw new LogicException('DynamicAttr must return an object implementing ParameterInterface'); | ||
// } | ||
$this->parameter = $return; | ||
} | ||
|
||
public function __invoke(mixed $mixed): mixed | ||
{ | ||
return $this->parameter->__invoke($mixed); | ||
} | ||
|
||
public function parameter(): ParameterInterface | ||
{ | ||
return $this->parameter; | ||
} | ||
} |
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 | ||
|
||
/* | ||
* This file is part of Chevere. | ||
* | ||
* (c) Rodolfo Berrios <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chevere\Parameter\Attributes; | ||
|
||
use Attribute; | ||
use Chevere\Parameter\Interfaces\NullParameterInterface; | ||
use Chevere\Parameter\Interfaces\ParameterAttributeInterface; | ||
use Chevere\Parameter\Interfaces\ParameterInterface; | ||
use function Chevere\Parameter\null; | ||
|
||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER | Attribute::TARGET_CLASS_CONSTANT)] | ||
class NullAttr implements ParameterAttributeInterface | ||
{ | ||
public readonly NullParameterInterface $parameter; | ||
|
||
public function __construct( | ||
string $description = '', | ||
) { | ||
$this->parameter = null( | ||
description: $description, | ||
); | ||
} | ||
|
||
public function __invoke(mixed $null): mixed | ||
{ | ||
return $this->parameter->__invoke($null); | ||
} | ||
|
||
public function parameter(): ParameterInterface | ||
{ | ||
return $this->parameter; | ||
} | ||
} |
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