1 | <?php |
||
24 | class Factory |
||
25 | { |
||
26 | |||
27 | use AutoLoggerTrait; |
||
28 | |||
29 | /** |
||
30 | * This is the default time, in seconds, that objects are cached for. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | public $defaultDuration = 432000; |
||
35 | |||
36 | /** |
||
37 | * The default driver |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | public $defaultDriver = 'file'; |
||
42 | |||
43 | /** |
||
44 | * Registered cache drivers |
||
45 | * |
||
46 | * @var DriverInterface[] |
||
47 | */ |
||
48 | protected $registeredDrivers = []; |
||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | * |
||
53 | * @param LoggerInterface $logger |
||
54 | */ |
||
55 | public function __construct(LoggerInterface $logger) |
||
62 | |||
63 | /******************************************* |
||
64 | * CREATE |
||
65 | *******************************************/ |
||
66 | |||
67 | /** |
||
68 | * Create a new cache pool |
||
69 | * |
||
70 | * @param array $config |
||
71 | * @return PoolInterface |
||
72 | * @throws InvalidDriverException |
||
73 | */ |
||
74 | public function create($config = []): PoolInterface |
||
109 | |||
110 | /** |
||
111 | * Get a cache driver. If the driver is not found, return the default. |
||
112 | * |
||
113 | * @param $identifier |
||
114 | * @return DriverInterface |
||
115 | * @throws InvalidDriverException |
||
116 | */ |
||
117 | public function autoGetDriver($identifier): DriverInterface |
||
136 | |||
137 | /** |
||
138 | * Get a cache driver |
||
139 | * |
||
140 | * @param $identifier |
||
141 | * @return DriverInterface |
||
142 | * @throws InvalidDriverException |
||
143 | */ |
||
144 | public function getDriver($identifier): DriverInterface |
||
154 | |||
155 | /** |
||
156 | * Register a cache driver for use |
||
157 | * |
||
158 | * @param $identifier |
||
159 | * @param DriverInterface $driver |
||
160 | * @throws InvalidDriverException |
||
161 | */ |
||
162 | public function registerDriver($identifier, DriverInterface $driver) |
||
182 | |||
183 | /** |
||
184 | * Register an array of drivers |
||
185 | * |
||
186 | * @param DriverInterface[] $drivers |
||
187 | * @throws InvalidDriverException |
||
188 | */ |
||
189 | public function registerDrivers(array $drivers) |
||
195 | |||
196 | /** |
||
197 | * Get an array of registered cache drivers |
||
198 | * |
||
199 | * @return DriverInterface[] |
||
200 | */ |
||
201 | public function getDrivers(): array |
||
205 | } |
||
206 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: