Skip to content

Commit

Permalink
Support excluding priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Dec 18, 2019
1 parent 1320b02 commit f8fb987
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ResourceStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResourceStore
// [type][priority][uri] = options
protected $_store = [];

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

foreach($this->getResources($for) as $uri => $options)
foreach($this->getResources($for, $priority, $excludePriority) as $uri => $options)
{
if(strlen($uri) == 32 && !stristr($uri, '/'))
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public function generateHtmlIncludes($for = self::TYPE_CSS)
return $return;
}

public function getResources($type, int $priority = null)
public function getResources($type, int $priority = null, array $excludePriority = [])
{
if(isset($this->_store[$type][$priority]))
{
Expand All @@ -93,11 +93,14 @@ public function getResources($type, int $priority = null)
$return = [];
//Sort based on store priority
ksort($this->_store[$type]);
foreach($this->_store[$type] as $resources)
foreach($this->_store[$type] as $currentPriority => $resources)
{
foreach($resources as $uri => $options)
if(!in_array($currentPriority, $excludePriority))
{
$return[$uri] = $options;
foreach($resources as $uri => $options)
{
$return[$uri] = $options;
}
}
}
return $return;
Expand Down
8 changes: 8 additions & 0 deletions tests/ResourceStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function testPriority()
$store->getResources(ResourceStore::TYPE_CSS)
);

$this->assertEquals(
[
'css/high.css' => null,
'css/test.css' => null,
],
$store->getResources(ResourceStore::TYPE_CSS, null, [ResourceStore::PRIORITY_LOW])
);

$this->assertEquals(
['css/high.css' => null],
$store->getResources(ResourceStore::TYPE_CSS, ResourceStore::PRIORITY_HIGH)
Expand Down

0 comments on commit f8fb987

Please sign in to comment.