forked from bankiru/doctrine-api-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerApiFactory.php
40 lines (33 loc) · 1.07 KB
/
ContainerApiFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Bankiru\Api;
use Bankiru\Api\Doctrine\ApiFactoryInterface;
use Bankiru\Api\Doctrine\ApiFactoryRegistryInterface;
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
use ScayTrase\Api\Rpc\RpcClientInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class ContainerApiFactory implements ApiFactoryRegistryInterface
{
/** @var ContainerInterface */
private $container;
/**
* ContainerApiFactory constructor.
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/** {@inheritdoc} */
public function create($alias, RpcClientInterface $client, ApiMetadata $metadata)
{
/** @var ApiFactoryInterface $factory */
$factory = $this->container->get($alias);
return $factory->createApi($client, $metadata);
}
/** {@inheritdoc} */
public function has($alias)
{
return $this->container->has($alias) && $this->container->get($alias) instanceof ApiFactoryInterface;
}
}