Skip to content

Commit f8fb987

Browse files
committed
Support excluding priorities
1 parent 1320b02 commit f8fb987

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/ResourceStore.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ResourceStore
2525
// [type][priority][uri] = options
2626
protected $_store = [];
2727

28-
public function generateHtmlIncludes($for = self::TYPE_CSS)
28+
public function generateHtmlIncludes($for = self::TYPE_CSS, int $priority = null, array $excludePriority = [])
2929
{
3030
if(!isset($this->_store[$for]) || empty($this->_store[$for]))
3131
{
@@ -43,7 +43,7 @@ public function generateHtmlIncludes($for = self::TYPE_CSS)
4343
}
4444
$return = '';
4545

46-
foreach($this->getResources($for) as $uri => $options)
46+
foreach($this->getResources($for, $priority, $excludePriority) as $uri => $options)
4747
{
4848
if(strlen($uri) == 32 && !stristr($uri, '/'))
4949
{
@@ -81,7 +81,7 @@ public function generateHtmlIncludes($for = self::TYPE_CSS)
8181
return $return;
8282
}
8383

84-
public function getResources($type, int $priority = null)
84+
public function getResources($type, int $priority = null, array $excludePriority = [])
8585
{
8686
if(isset($this->_store[$type][$priority]))
8787
{
@@ -93,11 +93,14 @@ public function getResources($type, int $priority = null)
9393
$return = [];
9494
//Sort based on store priority
9595
ksort($this->_store[$type]);
96-
foreach($this->_store[$type] as $resources)
96+
foreach($this->_store[$type] as $currentPriority => $resources)
9797
{
98-
foreach($resources as $uri => $options)
98+
if(!in_array($currentPriority, $excludePriority))
9999
{
100-
$return[$uri] = $options;
100+
foreach($resources as $uri => $options)
101+
{
102+
$return[$uri] = $options;
103+
}
101104
}
102105
}
103106
return $return;

tests/ResourceStoreTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function testPriority()
4040
$store->getResources(ResourceStore::TYPE_CSS)
4141
);
4242

43+
$this->assertEquals(
44+
[
45+
'css/high.css' => null,
46+
'css/test.css' => null,
47+
],
48+
$store->getResources(ResourceStore::TYPE_CSS, null, [ResourceStore::PRIORITY_LOW])
49+
);
50+
4351
$this->assertEquals(
4452
['css/high.css' => null],
4553
$store->getResources(ResourceStore::TYPE_CSS, ResourceStore::PRIORITY_HIGH)

0 commit comments

Comments
 (0)