1
|
|
|
<?php namespace Rocket\UI\Assets\Assetic; |
2
|
|
|
|
3
|
|
|
use Assetic\Asset\AssetCollection; |
4
|
|
|
use Assetic\Asset\AssetInterface; |
5
|
|
|
use Assetic\Filter\FilterInterface; |
6
|
|
|
use Rocket\UI\Assets\Assetic\Asset\AssetReference; |
7
|
|
|
use Rocket\UI\Assets\Assetic\Asset\WeightedAsset; |
8
|
|
|
|
9
|
|
|
class WeightedAssetCollection extends AssetCollection |
10
|
|
|
{ |
11
|
|
|
protected $orderable = []; |
12
|
|
|
protected $flattened = false; |
13
|
|
|
|
14
|
|
|
public function load(FilterInterface $additionalFilter = null) |
15
|
|
|
{ |
16
|
|
|
$this->flattenAndOrderAssets(); |
17
|
|
|
|
18
|
|
|
parent::load($additionalFilter); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function dump(FilterInterface $additionalFilter = null) |
22
|
|
|
{ |
23
|
|
|
$this->flattenAndOrderAssets(); |
24
|
|
|
|
25
|
|
|
return parent::dump($additionalFilter); |
26
|
|
|
} |
27
|
|
|
|
28
|
9 |
|
public function all() |
29
|
|
|
{ |
30
|
9 |
|
$this->flattenAndOrderAssets(); |
31
|
9 |
|
return parent::all(); |
32
|
|
|
} |
33
|
|
|
|
34
|
9 |
|
public function add(AssetInterface $asset) |
35
|
|
|
{ |
36
|
9 |
|
parent::add($asset); |
37
|
|
|
|
38
|
9 |
|
$this->flattened = false; |
39
|
9 |
|
} |
40
|
|
|
|
41
|
9 |
|
protected function flattenAndOrderAssets() |
42
|
|
|
{ |
43
|
9 |
|
if ($this->flattened) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//recursively get assets |
48
|
9 |
|
$original = parent::all(); |
|
|
|
|
49
|
9 |
|
foreach ($original as $asset) { |
50
|
9 |
|
$this->flatten($asset); |
51
|
9 |
|
$this->removeLeaf($asset); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
//order |
55
|
9 |
|
ksort($this->orderable); |
56
|
|
|
|
57
|
|
|
//flatten |
58
|
9 |
|
foreach ($this->orderable as $weight) { |
59
|
9 |
|
foreach ($weight as $item) { |
60
|
9 |
|
$this->add($item); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
9 |
|
$this->flattened = true; |
65
|
9 |
|
} |
66
|
|
|
|
67
|
9 |
|
protected function flatten($asset) |
68
|
|
|
{ |
69
|
9 |
|
if ($asset instanceof AssetCollection) { |
70
|
|
|
foreach ($asset->all() as $leaf) { |
71
|
|
|
$this->flatten($leaf); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
9 |
|
$weight = 0; |
78
|
9 |
|
if ($asset instanceof WeightedAsset) { |
79
|
6 |
|
$weight = $asset->getWeight(); |
80
|
|
|
} |
81
|
|
|
|
82
|
9 |
|
if ($asset instanceof AssetReference) { |
83
|
6 |
|
$weight = $asset->getAsset()->getWeight(); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
9 |
|
$this->orderable[$weight][] = $asset; |
87
|
9 |
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.