PEAR2_Templates_Savant-0.3.2 › PEAR2_Templates_Savant-0.3.2/php/PEAR2/Templates/Savant/BasicFastCompiler.php
- PEAR2_Templates_Savant-0.3.2/
- doc/
- pear2.php.net/
- PEAR2_Templates_Savant/
- examples/
- baseball/
- examples/
- templates/
- examples/
- examples/
- PEAR2_Templates_Savant/
- pear2.php.net/
- php/
- PEAR2/
- Autoload.php
- Exception.php
- MultiErrors/
- MultiErrors.php
- Templates/
- PEAR2/
- test/
- doc/
- package.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace PEAR2\Templates\Savant;
class BasicFastCompiler implements FastCompilerInterface
{
/**
* Directory where compiled templates will be stored
*
* @var string
*/
protected $compiledtemplatedir;
/**
* Constructor for the BasicFastCompiler
*
* @param string $compiledtemplatedir Where to store compiled templates
*
* @throws UnexpectedValueException
*/
function __construct($compiledtemplatedir)
{
$this->compiledtemplatedir = realpath($compiledtemplatedir);
if (!$this->compiledtemplatedir && !is_writable($this->compiledtemplatedir)) {
throw new UnexpectedValueException('Unable to compile templates into ' .
$compiledtemplatedir . ', directory does not exist ' .
'or is unwritable');
}
$this->compiledtemplatedir .= DIRECTORY_SEPARATOR;
}
/**
* Compile a template.
*
* @param string $name Template to compile
* @param Main $savant Savant main object
*
* @return string Name of the compiled template file.
*/
function compile($name, $savant)
{
$cname = $this->compiledtemplatedir . md5($name);
if (file_exists($cname)) {
if (filemtime($name) == filemtime($cname)) {
return $cname;
}
}
$a = file_get_contents($name);
$a = "<?php return '" . str_replace(array('<?php echo', '?>'), array('\' . ', ' . \''), $a) . "';";
file_put_contents($cname, $a);
touch($cname, filemtime($name));
return $cname;
}
}EOF
