-
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.
Merge pull request #7 from ebln/attributes
Add a designated Attribute
- Loading branch information
Showing
34 changed files
with
1,036 additions
and
244 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ebln\Attrib; | ||
|
||
/** | ||
* Marks classes to be instanciated by certain factories | ||
* | ||
* If used together with ForceFactoryInterface | ||
* the configured factories must be congruent! | ||
* This is enforced for PHP 8 and later. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class ForceFactory | ||
{ | ||
/** @var array<int, class-string> */ | ||
private array $allowedFactories; | ||
|
||
/** @param class-string ...$factories */ | ||
public function __construct(string ...$factories) | ||
{ | ||
$allowedFactories = []; | ||
foreach ($factories as $factory) { | ||
$allowedFactories[$factory] = $factory; | ||
} | ||
|
||
$this->allowedFactories = array_values($allowedFactories); | ||
} | ||
|
||
/** @return array<int, class-string> */ | ||
public function getAllowedFactories(): array | ||
{ | ||
return $this->allowedFactories; | ||
} | ||
} |
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
Oops, something went wrong.