-
-
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.
Implement native Nette Container adapter for future compatibility.
- Loading branch information
1 parent
222c25e
commit 31c09b2
Showing
5 changed files
with
93 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\StructuredApi\Middleware; | ||
|
||
|
||
use Baraja\StructuredApi\Endpoint; | ||
use Baraja\StructuredApi\MetaDataManager; | ||
use Nette\DI\Container as NetteContainer; | ||
|
||
final class Container | ||
{ | ||
public function __construct( | ||
private NetteContainer $container, | ||
) { | ||
} | ||
|
||
|
||
public function setContainer(NetteContainer $container): void | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
|
||
/** | ||
* @template T | ||
* @param class-string<T> $type | ||
* @return ?T | ||
*/ | ||
public function getByType(string $type): object | ||
{ | ||
return $this->container->getByType($type); | ||
} | ||
|
||
|
||
/** | ||
* @param class-string $className | ||
*/ | ||
public function getEndpoint(string $className): Endpoint | ||
{ | ||
$endpoint = $this->getByType($className); | ||
if (!$endpoint instanceof Endpoint) { | ||
throw new \LogicException( | ||
sprintf( | ||
'Service "%s" must be instance of "%s", but type "%s" given.', | ||
$className, | ||
Endpoint::class, | ||
$endpoint::class, | ||
), | ||
); | ||
} | ||
MetaDataManager::endpointInjectDependencies($endpoint, $this); | ||
|
||
return $endpoint; | ||
} | ||
|
||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getParameters(): array | ||
{ | ||
return $this->container->getParameters(); | ||
} | ||
} |