13
13
14
14
use Psr \Cache \CacheItemPoolInterface ;
15
15
use Symfony \Component \Validator \Exception \NoSuchMetadataException ;
16
- use Symfony \Component \Validator \Mapping \Cache \CacheInterface ;
17
16
use Symfony \Component \Validator \Mapping \ClassMetadata ;
18
17
use Symfony \Component \Validator \Mapping \Loader \LoaderInterface ;
19
18
@@ -49,20 +48,8 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
49
48
*/
50
49
protected $ loadedClasses = [];
51
50
52
- /**
53
- * Creates a new metadata factory.
54
- *
55
- * @param CacheItemPoolInterface|null $cache The cache for persisting metadata
56
- * between multiple PHP requests
57
- */
58
- public function __construct (LoaderInterface $ loader = null , $ cache = null )
51
+ public function __construct (LoaderInterface $ loader = null , CacheItemPoolInterface $ cache = null )
59
52
{
60
- if ($ cache instanceof CacheInterface) {
61
- @trigger_error (sprintf ('Passing a "%s" to "%s" is deprecated in Symfony 4.4 and will trigger a TypeError in 5.0. Please pass an implementation of "%s" instead. ' , \get_class ($ cache ), __METHOD__ , CacheItemPoolInterface::class), E_USER_DEPRECATED );
62
- } elseif (!$ cache instanceof CacheItemPoolInterface && null !== $ cache ) {
63
- throw new \TypeError (sprintf ('Expected an instance of %s, got %s. ' , CacheItemPoolInterface::class, \is_object ($ cache ) ? \get_class ($ cache ) : \gettype ($ cache )));
64
- }
65
-
66
53
$ this ->loader = $ loader ;
67
54
$ this ->cache = $ cache ;
68
55
}
@@ -98,24 +85,14 @@ public function getMetadataFor($value)
98
85
throw new NoSuchMetadataException (sprintf ('The class or interface "%s" does not exist. ' , $ class ));
99
86
}
100
87
101
- $ cacheItem = null ;
102
- if ($ this ->cache instanceof CacheInterface) {
103
- if ($ metadata = $ this ->cache ->read ($ class )) {
104
- // Include constraints from the parent class
105
- $ this ->mergeConstraints ($ metadata );
106
-
107
- return $ this ->loadedClasses [$ class ] = $ metadata ;
108
- }
109
- } elseif (null !== $ this ->cache ) {
110
- $ cacheItem = $ this ->cache ->getItem ($ this ->escapeClassName ($ class ));
111
- if ($ cacheItem ->isHit ()) {
112
- $ metadata = $ cacheItem ->get ();
88
+ $ cacheItem = null === $ this ->cache ? null : $ this ->cache ->getItem ($ this ->escapeClassName ($ class ));
89
+ if ($ cacheItem && $ cacheItem ->isHit ()) {
90
+ $ metadata = $ cacheItem ->get ();
113
91
114
- // Include constraints from the parent class
115
- $ this ->mergeConstraints ($ metadata );
92
+ // Include constraints from the parent class
93
+ $ this ->mergeConstraints ($ metadata );
116
94
117
- return $ this ->loadedClasses [$ class ] = $ metadata ;
118
- }
95
+ return $ this ->loadedClasses [$ class ] = $ metadata ;
119
96
}
120
97
121
98
$ metadata = new ClassMetadata ($ class );
@@ -124,9 +101,7 @@ public function getMetadataFor($value)
124
101
$ this ->loader ->loadClassMetadata ($ metadata );
125
102
}
126
103
127
- if ($ this ->cache instanceof CacheInterface) {
128
- $ this ->cache ->write ($ metadata );
129
- } elseif (null !== $ cacheItem ) {
104
+ if (null !== $ cacheItem ) {
130
105
$ this ->cache ->save ($ cacheItem ->set ($ metadata ));
131
106
}
132
107
0 commit comments