1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Twig; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Rule; |
6
|
|
|
use Obblm\Core\Entity\Team; |
7
|
|
|
use Obblm\Core\Helper\AssetPackager; |
8
|
|
|
use Obblm\Core\Helper\ImageHelper; |
9
|
|
|
use Twig\Extension\AbstractExtension; |
10
|
|
|
use Twig\TwigFunction; |
11
|
|
|
|
12
|
|
|
class AssetsExtension extends AbstractExtension |
13
|
|
|
{ |
14
|
|
|
protected $imageHelper; |
15
|
|
|
protected $packager; |
16
|
|
|
|
17
|
|
|
public function __construct(AssetPackager $packager, ImageHelper $imageHelper) |
18
|
|
|
{ |
19
|
|
|
$this->packager = $packager; |
20
|
|
|
$this->imageHelper = $imageHelper; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getFunctions() |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
new TwigFunction('roster_image', [$this, 'getRosterImageUrl']), |
27
|
|
|
new TwigFunction('team_logo', [$this, 'getTeamLogo']), |
28
|
|
|
new TwigFunction('team_cover', [$this, 'getTeamCover']), |
29
|
|
|
new TwigFunction('obblm_css', [$this, 'getObblmCss']), |
30
|
|
|
new TwigFunction('obblm_js', [$this, 'getObblmJs']), |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getObblmCss(string $entrypoint, $bundle = 'core') |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
return $this->packager->getCssEntry($entrypoint); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getObblmJs(string $entrypoint, $bundle = 'core') |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return $this->packager->getJsEntry($entrypoint); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getRosterImageUrl(Rule $rule, string $roster, int $width = null, int $height = 150) |
45
|
|
|
{ |
46
|
|
|
return $this->imageHelper->getRosterImage($rule, $roster, $width, $height); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getTeamLogo(Team $team, int $width = 200, int $height = null) |
50
|
|
|
{ |
51
|
|
|
return $this->imageHelper->getTeamLogo($team, $width, $height); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getTeamCover(Team $team, int $width = null, int $height = null) |
55
|
|
|
{ |
56
|
|
|
return $this->imageHelper->getTeamCover($team, $width, $height); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.