|
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\Component\Templating\Loader; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Templating\Storage; |
|
|
15 |
use Symfony\Component\Templating\TemplateReferenceInterface; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* ChainLoader is a loader that calls other loaders to load templates. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class ChainLoader extends Loader |
|
|
23 |
{ |
|
|
24 |
protected $loaders; |
|
|
25 |
|
|
|
26 |
/** |
|
|
27 |
* Constructor. |
|
|
28 |
* |
|
|
29 |
* @param Loader[] $loaders An array of loader instances |
|
|
30 |
*/ |
|
|
31 |
public function __construct(array $loaders = array()) |
|
|
32 |
{ |
|
|
33 |
$this->loaders = array(); |
|
|
34 |
foreach ($loaders as $loader) { |
|
|
35 |
$this->addLoader($loader); |
|
|
36 |
} |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
/** |
|
|
40 |
* Adds a loader instance. |
|
|
41 |
* |
|
|
42 |
* @param Loader $loader A Loader instance |
|
|
43 |
*/ |
|
|
44 |
public function addLoader(Loader $loader) |
|
|
45 |
{ |
|
|
46 |
$this->loaders[] = $loader; |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* Loads a template. |
|
|
51 |
* |
|
|
52 |
* @param TemplateReferenceInterface $template A template |
|
|
53 |
* |
|
|
54 |
* @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise |
|
|
55 |
*/ |
|
|
56 |
public function load(TemplateReferenceInterface $template) |
|
|
57 |
{ |
|
|
58 |
foreach ($this->loaders as $loader) { |
|
|
59 |
if (false !== $storage = $loader->load($template)) { |
|
|
60 |
return $storage; |
|
|
61 |
} |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
return false; |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
/** |
|
|
68 |
* Returns true if the template is still fresh. |
|
|
69 |
* |
|
|
70 |
* @param TemplateReferenceInterface $template A template |
|
|
71 |
* @param integer $time The last modification time of the cached template (timestamp) |
|
|
72 |
* |
|
|
73 |
* @return Boolean |
|
|
74 |
*/ |
|
|
75 |
public function isFresh(TemplateReferenceInterface $template, $time) |
|
|
76 |
{ |
|
|
77 |
foreach ($this->loaders as $loader) { |
|
|
78 |
return $loader->isFresh($template); |
|
|
79 |
} |
|
|
80 |
|
|
|
81 |
return false; |
|
|
82 |
} |
|
|
83 |
} |