1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Fabiang\AsseticBundle; |
6
|
|
|
|
7
|
|
|
use Assetic\Contracts\Filter\FilterInterface; |
8
|
|
|
use Assetic\FilterManager as AsseticFilterManager; |
9
|
|
|
use Fabiang\AsseticBundle\Exception\InvalidArgumentException; |
10
|
|
|
use Psr\Container\ContainerInterface; |
11
|
|
|
|
12
|
|
|
use function gettype; |
13
|
|
|
use function is_object; |
14
|
|
|
use function sprintf; |
15
|
|
|
|
16
|
|
|
class FilterManager extends AsseticFilterManager |
17
|
1 |
|
{ |
18
|
|
|
protected ContainerInterface $container; |
19
|
1 |
|
|
20
|
|
|
public function __construct(ContainerInterface $container) |
21
|
|
|
{ |
22
|
|
|
$this->container = $container; |
23
|
|
|
} |
24
|
|
|
|
25
|
2 |
|
/** |
26
|
|
|
* @param mixed $alias |
27
|
2 |
|
*/ |
28
|
|
|
public function has($alias): bool |
29
|
|
|
{ |
30
|
|
|
return parent::has($alias) ? true : $this->container->has($alias); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed $alias |
35
|
5 |
|
* @return mixed |
36
|
|
|
* @throws InvalidArgumentException When cant retrieve filter from service manager. |
37
|
5 |
|
*/ |
38
|
1 |
|
public function get($alias) |
39
|
|
|
{ |
40
|
|
|
if (parent::has($alias)) { |
41
|
4 |
|
return parent::get($alias); |
42
|
4 |
|
} |
43
|
2 |
|
|
44
|
2 |
|
$service = $this->container; |
45
|
|
|
if (! $service->has($alias)) { |
46
|
|
|
throw new InvalidArgumentException( |
47
|
|
|
sprintf( |
48
|
|
|
'There is no "%s" filter in Laminas service manager.', |
49
|
|
|
$alias |
50
|
|
|
) |
51
|
2 |
|
); |
52
|
2 |
|
} |
53
|
1 |
|
|
54
|
1 |
|
$filter = $service->get($alias); |
55
|
1 |
|
if (! $filter instanceof FilterInterface) { |
56
|
1 |
|
$givenType = is_object($filter) ? FilterInterface::class : gettype($filter); |
57
|
|
|
$message = 'Retrieved filter "%s" is not instanceof ' |
58
|
|
|
. '"Assetic\Filter\FilterInterface", but type was given %s'; |
59
|
1 |
|
$message = sprintf($message, $alias, $givenType); |
60
|
|
|
throw new InvalidArgumentException($message); |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
$this->set($alias, $filter); |
64
|
|
|
|
65
|
|
|
return $filter; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|