1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\JmsSerializerModule\MetadataReader; |
7
|
|
|
|
8
|
|
|
use Doctrine\Common\Annotations\IndexedReader; |
9
|
|
|
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface; |
10
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
11
|
|
|
use Zend\ServiceManager\FactoryInterface; |
12
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
13
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
14
|
|
|
use Nnx\JmsSerializerModule\Options\ModuleOptions; |
15
|
|
|
use Doctrine\Common\Cache\Cache; |
16
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class DefaultAnnotationReaderFactory |
20
|
|
|
* |
21
|
|
|
* @package Nnx\JmsSerializerModule\MetadataReader |
22
|
|
|
*/ |
23
|
|
|
class DefaultAnnotationReaderFactory implements FactoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
* |
28
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
29
|
|
|
* |
30
|
|
|
* @return mixed |
31
|
|
|
* @throws \Nnx\JmsSerializerModule\MetadataReader\Exception\RuntimeException |
32
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
33
|
|
|
*/ |
34
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
35
|
|
|
{ |
36
|
|
|
$appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator; |
37
|
|
|
|
38
|
|
|
// AnnotationRegistry::registerLoader(function ($class) { |
|
|
|
|
39
|
|
|
// return (bool) class_exists($class); |
40
|
|
|
// }); |
41
|
|
|
$reader = new AnnotationReader(); |
42
|
|
|
$indexedReader = new IndexedReader($reader); |
43
|
|
|
|
44
|
|
|
/** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */ |
45
|
|
|
$moduleOptionsPluginManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class); |
46
|
|
|
|
47
|
|
|
/** @var ModuleOptions $moduleOptions */ |
48
|
|
|
$moduleOptions = $moduleOptionsPluginManager->get(ModuleOptions::class); |
49
|
|
|
|
50
|
|
|
$annotationCacheName = $moduleOptions->getAnnotationCache(); |
51
|
|
|
|
52
|
|
|
$annotationCache = $appServiceLocator->get($annotationCacheName); |
53
|
|
|
|
54
|
|
|
if (!$annotationCache instanceof Cache) { |
55
|
|
|
$errMsg = sprintf( |
56
|
|
|
'Annotation cache of type %s is invalid; must implement %s', |
57
|
|
|
(is_object($annotationCache) ? get_class($annotationCache) : gettype($annotationCache)), |
58
|
|
|
Cache::class |
59
|
|
|
); |
60
|
|
|
throw new Exception\RuntimeException($errMsg); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
return new CachedReader($indexedReader, $annotationCache); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.