Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
10 / 12 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| assets_bag | |
83.33% |
10 / 12 |
|
66.67% |
4 / 6 |
8.30 | |
0.00% |
0 / 1 |
| add_stylesheet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| add_script | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_stylesheets | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_scripts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_stylesheets_content | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| get_scripts_content | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 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; |
| 15 | |
| 16 | class assets_bag |
| 17 | { |
| 18 | /** @var asset[] */ |
| 19 | protected $stylesheets = []; |
| 20 | |
| 21 | /** @var asset[] */ |
| 22 | protected $scripts = []; |
| 23 | |
| 24 | /** |
| 25 | * Add a css asset to the bag |
| 26 | * |
| 27 | * @param asset $asset |
| 28 | */ |
| 29 | public function add_stylesheet(asset $asset) |
| 30 | { |
| 31 | $this->stylesheets[] = $asset; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Add a js script asset to the bag |
| 36 | * |
| 37 | * @param asset $asset |
| 38 | */ |
| 39 | public function add_script(asset $asset) |
| 40 | { |
| 41 | $this->scripts[] = $asset; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns all css assets |
| 46 | * |
| 47 | * @return asset[] |
| 48 | */ |
| 49 | public function get_stylesheets() |
| 50 | { |
| 51 | return $this->stylesheets; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns all js assets |
| 56 | * |
| 57 | * @return asset[] |
| 58 | */ |
| 59 | public function get_scripts() |
| 60 | { |
| 61 | return $this->scripts; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the HTML code to include all css assets |
| 66 | * |
| 67 | * @return string |
| 68 | */ |
| 69 | public function get_stylesheets_content(): string |
| 70 | { |
| 71 | $output = ''; |
| 72 | foreach ($this->stylesheets as $stylesheet) |
| 73 | { |
| 74 | $output .= "<link href=\"{$stylesheet->get_url()}\" rel=\"stylesheet\" media=\"screen\">\n"; |
| 75 | } |
| 76 | |
| 77 | return $output; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the HTML code to include all js assets |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | public function get_scripts_content(): string |
| 86 | { |
| 87 | $output = ''; |
| 88 | foreach ($this->scripts as $script) |
| 89 | { |
| 90 | $output .= "<script src=\"{$script->get_url()}\"></script>\n"; |
| 91 | } |
| 92 | |
| 93 | return $output; |
| 94 | } |
| 95 | } |