Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| includeasset | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| compile | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
1 | |||
| get_setters_name | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\template\twig\node; |
| 15 | |
| 16 | abstract class includeasset extends \Twig\Node\Node |
| 17 | { |
| 18 | public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) |
| 19 | { |
| 20 | parent::__construct(array('expr' => $expr), array(), $lineno, $tag); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Compiles the node to PHP. |
| 25 | * |
| 26 | * @param \Twig\Compiler A Twig\Compiler instance |
| 27 | */ |
| 28 | public function compile(\Twig\Compiler $compiler) |
| 29 | { |
| 30 | $compiler->addDebugInfo($this); |
| 31 | |
| 32 | $compiler |
| 33 | ->write("\$asset_file = ") |
| 34 | ->subcompile($this->getNode('expr')) |
| 35 | ->raw(";\n") |
| 36 | ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->env->get_path_helper(), \$this->env->get_filesystem());\n") |
| 37 | ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") |
| 38 | ->indent() |
| 39 | ->write("\$asset_path = \$asset->get_path();") |
| 40 | ->write("\$local_file = \$this->env->get_phpbb_root_path() . \$asset_path;\n") |
| 41 | ->write("if (!file_exists(\$local_file)) {\n") |
| 42 | ->indent() |
| 43 | ->write("\$local_file = \$this->env->findTemplate(\$asset_path);\n") |
| 44 | ->write("\$asset->set_path(\$local_file, true);\n") |
| 45 | ->outdent() |
| 46 | ->write("}\n") |
| 47 | ->outdent() |
| 48 | ->write("}\n") |
| 49 | ->write("\n") |
| 50 | ->write("if (\$asset->is_relative()) {\n") |
| 51 | ->indent() |
| 52 | ->write("\$asset->add_assets_version(\$this->env->get_phpbb_config()['assets_version']);\n") |
| 53 | ->outdent() |
| 54 | ->write("}\n") |
| 55 | ->write("\$this->env->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);") |
| 56 | ; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get the name of the assets bag setter |
| 61 | * |
| 62 | * @return string (e.g. 'script') |
| 63 | */ |
| 64 | abstract public function get_setters_name(); |
| 65 | } |