|
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
|
|
|
if (interface_exists(\Twig_ExistsLoaderInterface::class)) { // Twig 1 |
|
10
|
|
|
abstract class BaseTwitalLoader extends TwitalLoaderTwigLt3 implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true) |
|
13
|
|
|
{ |
|
14
|
|
|
parent::__construct($loader, $twital, $addDefaults); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function getSourceContext($name) |
|
18
|
|
|
{ |
|
19
|
|
|
$context = $this->doGetSourceContext($name); |
|
20
|
|
|
|
|
21
|
|
|
return new \Twig_Source($context[0], $context[1], $context[2]); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getSource($name) |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->getSourceContext($name)->getCode(); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
} elseif (interface_exists(ExistsLoaderInterface::class)) { // Twig 2 |
|
33
|
|
|
abstract class BaseTwitalLoader extends TwitalLoaderTwigLt3 implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true) |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct($loader, $twital, $addDefaults); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getSourceContext($name) |
|
41
|
|
|
{ |
|
42
|
|
|
$context = $this->doGetSourceContext($name); |
|
43
|
|
|
|
|
44
|
48 |
|
return new Source($context[0], $context[1], $context[2]); |
|
45
|
|
|
} |
|
46
|
48 |
|
} |
|
47
|
48 |
|
} else { // Twig 3 |
|
48
|
|
|
abstract class BaseTwitalLoader extends TwitalLoaderTwigGte3 |
|
|
|
|
|
|
49
|
48 |
|
{ |
|
50
|
6 |
|
} |
|
51
|
6 |
|
} |
|
52
|
48 |
|
|
|
53
|
6 |
|
/** |
|
54
|
6 |
|
* This is a Twital Loader. |
|
55
|
48 |
|
* Compiles a Twital template into a Twig template. |
|
56
|
6 |
|
* |
|
57
|
6 |
|
* @author Asmir Mustafic <[email protected]> |
|
58
|
48 |
|
*/ |
|
59
|
|
|
class TwitalLoader extends BaseTwitalLoader |
|
60
|
31 |
|
{ |
|
61
|
|
|
} |
|
62
|
|
|
|
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.