|
1
|
|
|
<?php |
|
2
|
|
|
namespace Goetas\Twital; |
|
3
|
|
|
|
|
4
|
|
|
use Twig\Loader\ExistsLoaderInterface; |
|
5
|
|
|
use Twig\Loader\LoaderInterface; |
|
6
|
|
|
use Twig\Loader\SourceContextLoaderInterface; |
|
7
|
|
|
use Twig\Source; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BaseTwitalOlderTwigLoader |
|
10
|
|
|
{ |
|
11
|
|
|
use TwitalLoaderTrait; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct($loader = null, Twital $twital = null, $addDefaults = true) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->doConstruct($loader, $twital, $addDefaults); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function getCacheKey($name) |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->loader->getCacheKey($name); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function isFresh($name, $time) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->loader->isFresh($name, $time); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getSourceContext($name) |
|
29
|
|
|
{ |
|
30
|
|
|
$context = $this->doGetSourceContext($name); |
|
31
|
|
|
|
|
32
|
|
|
return new \Twig_Source($context[0], $context[1], $context[2]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function exists($name) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->doExists($name); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (interface_exists(ExistsLoaderInterface::class)) { // Twig 2 |
|
42
|
|
|
abstract class BaseTwitalLoader extends BaseTwitalOlderTwigLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface |
|
43
|
|
|
{ |
|
44
|
48 |
|
public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true) |
|
45
|
|
|
{ |
|
46
|
48 |
|
parent::__construct($loader, $twital, $addDefaults); |
|
47
|
48 |
|
} |
|
48
|
|
|
} |
|
49
|
48 |
|
} elseif (interface_exists(\Twig_ExistsLoaderInterface::class)) { // Twig 1 |
|
50
|
6 |
|
abstract class BaseTwitalLoader extends BaseTwitalOlderTwigLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface |
|
|
|
|
|
|
51
|
6 |
|
{ |
|
52
|
48 |
|
public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true) |
|
53
|
6 |
|
{ |
|
54
|
6 |
|
parent::__construct($loader, $twital, $addDefaults); |
|
55
|
48 |
|
} |
|
56
|
6 |
|
|
|
57
|
6 |
|
/** |
|
58
|
48 |
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
31 |
|
public function getSource($name) |
|
61
|
|
|
{ |
|
62
|
31 |
|
return $this->getSourceContext($name)->getCode(); |
|
63
|
29 |
|
} |
|
64
|
29 |
|
} |
|
65
|
29 |
|
} else { // Twig 3 |
|
66
|
29 |
|
abstract class BaseTwitalLoader implements LoaderInterface |
|
|
|
|
|
|
67
|
2 |
|
{ |
|
68
|
1 |
|
use TwitalLoaderTrait; |
|
69
|
|
|
|
|
70
|
|
|
public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true) |
|
71
|
30 |
|
{ |
|
72
|
28 |
|
$this->doConstruct($loader, $twital, $addDefaults); |
|
73
|
26 |
|
} |
|
74
|
|
|
|
|
75
|
28 |
|
public function getSourceContext(string $name): Source |
|
76
|
|
|
{ |
|
77
|
|
|
$context = $this->doGetSourceContext($name); |
|
78
|
|
|
|
|
79
|
|
|
return new Source($context[0], $context[1], $context[2]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getCacheKey(string $name): string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->loader->getCacheKey($name); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
46 |
|
public function isFresh(string $name, int $time): bool |
|
88
|
|
|
{ |
|
89
|
46 |
|
return $this->loader->isFresh($name, $time); |
|
90
|
|
|
} |
|
91
|
46 |
|
|
|
92
|
|
|
public function exists(string $name) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->doExists($name); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
/** |
|
100
|
|
|
* This is a Twital Loader. |
|
101
|
1 |
|
* Compiles a Twital template into a Twig template. |
|
102
|
|
|
* |
|
103
|
|
|
* @author Asmir Mustafic <[email protected]> |
|
104
|
|
|
*/ |
|
105
|
|
|
class TwitalLoader extends BaseTwitalLoader |
|
106
|
|
|
{ |
|
107
|
|
|
} |
|
108
|
|
|
|
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.