forked from FriendsOfSymfony/FOSRestBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerDecoderProvider.php
More file actions
64 lines (55 loc) · 1.47 KB
/
Copy pathContainerDecoderProvider.php
File metadata and controls
64 lines (55 loc) · 1.47 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\RestBundle\Decoder;
use Symfony\Component\DependencyInjection\ContainerAware;
use FOS\Rest\Decoder\DecoderProviderInterface;
/**
* Provides encoders through the Symfony2 DIC
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class ContainerDecoderProvider extends ContainerAware implements DecoderProviderInterface
{
/**
* @var array
*/
private $decoders;
/**
* Constructor.
*
* @param array $decoders List of key (format) value (service ids) of decoders
*/
public function __construct(array $decoders)
{
$this->decoders = $decoders;
}
/**
* @param string $format format
*
* @return boolean
*/
public function supports($format)
{
return isset($this->decoders[$format]);
}
/**
* @param string $format format
*
* @throws \InvalidArgumentException
* @return FOS\Rest\Decoder\DecoderInterface
*/
public function getDecoder($format)
{
if (!$this->supports($format)) {
throw new \InvalidArgumentException(sprintf("Format '%s' is not supported by ContainerDecoderProvider.", $format));
}
return $this->container->get($this->decoders[$format]);
}
}