bytic /
assets
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Assets\Assets; |
||
| 4 | |||
| 5 | use ByTIC\Assets\Assets\Asset\AssetAttributes; |
||
| 6 | use ByTIC\Assets\Assets\Asset\AssetSource; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class Asset |
||
| 10 | * @package ByTIC\Assets\Assets |
||
| 11 | */ |
||
| 12 | class Asset |
||
| 13 | { |
||
| 14 | use Asset\Traits\CanRenderTrait; |
||
| 15 | use Asset\Traits\HasContentTrait; |
||
| 16 | |||
| 17 | const TYPE_STYLES = 'STYLES'; |
||
| 18 | const TYPE_SCRIPTS = 'SCRIPTS'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $type; |
||
| 24 | |||
| 25 | protected $source = false; |
||
| 26 | protected $attribs = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Asset constructor. |
||
| 30 | * @param string $source |
||
| 31 | * @param string $type |
||
| 32 | */ |
||
| 33 | 9 | public function __construct(string $source = '', $type = '') |
|
| 34 | { |
||
| 35 | 9 | $this->source = AssetSource::check($source, $type); |
|
| 36 | 9 | $this->type = $type; |
|
| 37 | 9 | $this->attribs = AssetAttributes::defaultFor($type); |
|
| 38 | 9 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | 4 | public function getSource(): string |
|
| 44 | { |
||
| 45 | 4 | if ($this->source instanceof \Closure) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 46 | 4 | $this->source = ($this->source)(); |
|
| 47 | } |
||
| 48 | 4 | return $this->source; |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $source |
||
| 53 | */ |
||
| 54 | public function setSource(string $source): void |
||
| 55 | { |
||
| 56 | $this->source = $source; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 4 | public function getType(): string |
|
| 63 | { |
||
| 64 | 4 | return $this->type; |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $type |
||
| 69 | */ |
||
| 70 | public function setType(string $type): void |
||
| 71 | { |
||
| 72 | $this->type = $type; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | 4 | public function getAttribs(): array |
|
| 79 | { |
||
| 80 | 4 | return $this->attribs; |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param array $attribs |
||
| 85 | */ |
||
| 86 | public function setAttribs(array $attribs): void |
||
| 87 | { |
||
| 88 | $this->attribs = $attribs; |
||
| 89 | } |
||
| 90 | } |
||
| 91 |