Skip to content

Commit

Permalink
Add external manager type
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jan 24, 2019
1 parent 9b86166 commit 18afc83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ResourceManager
const MAP_RESOURCES = 'r';
const MAP_PUBLIC = 'p';
const MAP_COMPONENT = 'c';
const MAP_EXTERNAL = 'e';

protected $_type = self::MAP_RESOURCES;
protected $_mapOptions = [];
Expand Down Expand Up @@ -62,6 +63,11 @@ public static function inline()
return new static(self::MAP_INLINE, []);
}

public static function external()
{
return new static(self::MAP_EXTERNAL, []);
}

public static function component(DispatchableComponent $component)
{
$dispatch = Dispatch::instance();
Expand Down Expand Up @@ -95,7 +101,7 @@ public static function component(DispatchableComponent $component)
*/
public function getResourceUri($relativeFullPath): ?string
{
if($this->isExternalUrl($relativeFullPath))
if($this->_type == self::MAP_EXTERNAL || $this->isExternalUrl($relativeFullPath))
{
return $relativeFullPath;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/ResourceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testComponent()
'c/6/Packaged/Dispatch/Tests/TestComponents/DemoComponent/DemoComponent/a4197ed8/style.css',
$manager->getResourceUri('style.css')
);
Dispatch::instance()->addComponentAlias('\Packaged\Dispatch\Tests\TestComponents','');
Dispatch::instance()->addComponentAlias('\Packaged\Dispatch\Tests\TestComponents', '');
$manager = ResourceManager::component($component);
$this->assertEquals(
'c/3/_/DemoComponent/DemoComponent/a4197ed8/style.css',
Expand Down Expand Up @@ -105,6 +105,11 @@ public function testRequireInlineJs()

public function testIsExternalUrl()
{
$manager = ResourceManager::external();
$this->assertTrue($manager->isExternalUrl('http://www.google.com'));
$this->assertFalse($manager->isExternalUrl('abhttp://www.google.com'));

//Check external still work on other resource types
$manager = ResourceManager::public();
$this->assertTrue($manager->isExternalUrl('http://www.google.com'));
$this->assertFalse($manager->isExternalUrl('abhttp://www.google.com'));
Expand Down

0 comments on commit 18afc83

Please sign in to comment.