These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
8 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
9 | * @link http://phpdoc.org |
||
10 | */ |
||
11 | |||
12 | namespace Cilex\Provider; |
||
13 | |||
14 | use Cilex\Application; |
||
15 | use Doctrine\Common\Annotations\AnnotationRegistry; |
||
16 | use JMS\Serializer\SerializerBuilder; |
||
17 | use Pimple\Container; |
||
18 | use Pimple\ServiceProviderInterface; |
||
19 | |||
20 | /** |
||
21 | * Cilex Service Provider to provide serialization services. |
||
22 | */ |
||
23 | class JmsSerializerServiceProvider implements ServiceProviderInterface |
||
24 | { |
||
25 | /** |
||
26 | * Registers services on the given app. |
||
27 | * |
||
28 | * @param Container $app An Application instance |
||
29 | */ |
||
30 | public function register(Container $app) |
||
31 | { |
||
32 | $vendorPath = $app['composer.vendor_path'] ?? __DIR__ . '/../../../vendor'; |
||
33 | |||
34 | $serializerPath = $vendorPath . '/jms/serializer/src'; |
||
35 | if (!file_exists($serializerPath)) { |
||
36 | $serializerPath = __DIR__ . '/../../../../../jms/serializer/src'; |
||
37 | } |
||
38 | |||
39 | $app['serializer.annotations'] = [ |
||
40 | ['namespace' => 'JMS\Serializer\Annotation', 'path' => $serializerPath], |
||
41 | ]; |
||
42 | |||
43 | $app['serializer'] = function ($container) { |
||
44 | if (!isset($container['serializer.annotations']) || !is_array($container['serializer.annotations'])) { |
||
45 | throw new \RuntimeException( |
||
46 | 'Expected the container to have an array called "serializer.annotations" that describes which ' |
||
47 | . 'annotations are supported by the Serializer and where it can find them' |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | foreach ($container['serializer.annotations'] as $annotationsDefinition) { |
||
52 | if (!isset($annotationsDefinition['namespace'])) { |
||
53 | throw new \UnexpectedValueException( |
||
54 | 'The annotation definition for the Serializer should have a key "namespace" that tells the ' |
||
55 | . 'serializer what the namespace for the provided annotations are.' |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | if (!isset($annotationsDefinition['path'])) { |
||
60 | throw new \UnexpectedValueException( |
||
61 | 'The annotation definition for the Serializer should have a key "path" that tells the ' |
||
62 | . 'serializer where it can find the provided annotations.' |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | AnnotationRegistry::registerAutoloadNamespace( |
||
0 ignored issues
–
show
|
|||
67 | $annotationsDefinition['namespace'], |
||
68 | $annotationsDefinition['path'] |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | return SerializerBuilder::create()->build(); |
||
73 | }; |
||
74 | } |
||
75 | } |
||
76 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.