|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\AsseticBundle\DependencyInjection; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\Definition; |
|
|
15 |
use Symfony\Component\DependencyInjection\Reference; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* Encapsulates logic for creating a directory resource. |
|
|
19 |
* |
|
|
20 |
* @author Kris Wallsmith <kris@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class DirectoryResourceDefinition extends Definition |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* Constructor. |
|
|
26 |
* |
|
|
27 |
* @param string $bundle A bundle name or empty string |
|
|
28 |
* @param string $engine The templating engine |
|
|
29 |
* @param array $dirs An array of directories to merge |
|
|
30 |
*/ |
|
|
31 |
public function __construct($bundle, $engine, array $dirs) |
|
|
32 |
{ |
|
|
33 |
if (!count($dirs)) { |
|
|
34 |
throw new \InvalidArgumentException('You must provide at least one directory.'); |
|
|
35 |
} |
|
|
36 |
|
|
|
37 |
parent::__construct(); |
|
|
38 |
|
|
|
39 |
$this |
|
|
40 |
->addTag('assetic.templating.'.$engine) |
|
|
41 |
->addTag('assetic.formula_resource', array('loader' => $engine)); |
|
|
42 |
; |
|
|
43 |
|
|
|
44 |
if (1 == count($dirs)) { |
|
|
45 |
// no need to coalesce |
|
|
46 |
self::configureDefinition($this, $bundle, $engine, reset($dirs)); |
|
|
47 |
return; |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
// gather the wrapped resource definitions |
|
|
51 |
$resources = array(); |
|
|
52 |
foreach ($dirs as $dir) { |
|
|
53 |
$resources[] = $resource = new Definition(); |
|
|
54 |
self::configureDefinition($resource, $bundle, $engine, $dir); |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
$this |
|
|
58 |
->setClass('%assetic.coalescing_directory_resource.class%') |
|
|
59 |
->addArgument($resources) |
|
|
60 |
->setPublic(false) |
|
|
61 |
; |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
static private function configureDefinition(Definition $definition, $bundle, $engine, $dir) |
|
|
65 |
{ |
|
|
66 |
$definition |
|
|
67 |
->setClass('%assetic.directory_resource.class%') |
|
|
68 |
->addArgument(new Reference('templating.loader')) |
|
|
69 |
->addArgument($bundle) |
|
|
70 |
->addArgument($dir) |
|
|
71 |
->addArgument('/^[^.]+\.[^.]+\.'.$engine.'$/') |
|
|
72 |
->setPublic(false) |
|
|
73 |
; |
|
|
74 |
} |
|
|
75 |
} |