mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG switch to trigger_error()
when a resource is not found (#7468)
* BUG switch to `trigger_error()` when a resource is not found rather than throw an exception * Add unit test for module url failing
This commit is contained in:
parent
8d36d55205
commit
cafa3fc29a
@ -77,7 +77,7 @@ class SimpleResourceURLGenerator implements ResourceURLGenerator
|
||||
$exists = file_exists($absolutePath);
|
||||
}
|
||||
if (!$exists) {
|
||||
throw new InvalidArgumentException("File {$relativePath} does not exist");
|
||||
trigger_error("File {$relativePath} does not exist", E_USER_NOTICE);
|
||||
}
|
||||
|
||||
// Apply url rewrites
|
||||
@ -89,7 +89,7 @@ class SimpleResourceURLGenerator implements ResourceURLGenerator
|
||||
// Apply nonce
|
||||
$nonce = '';
|
||||
// Don't add nonce to directories
|
||||
if ($this->nonceStyle && is_file($absolutePath)) {
|
||||
if ($this->nonceStyle && $exists && is_file($absolutePath)) {
|
||||
$nonce = (strpos($relativePath, '?') === false) ? '?' : '&';
|
||||
|
||||
switch ($this->nonceStyle) {
|
||||
|
@ -106,9 +106,7 @@ class ModuleResourceLoader implements TemplateGlobalProvider
|
||||
throw new InvalidArgumentException("Can't find module '$module'");
|
||||
}
|
||||
$resourceObj = $moduleObj->getResource($resource);
|
||||
if (!$resourceObj->exists()) {
|
||||
throw new InvalidArgumentException("Module '$module' does not have specified resource '$resource'");
|
||||
}
|
||||
|
||||
return $resourceObj;
|
||||
}
|
||||
}
|
||||
|
@ -64,4 +64,12 @@ class SimpleResourceURLGeneratorTest extends SapphireTest
|
||||
$generator->urlForResource($module->getResource('client/style.css'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testURLForResourceFailsGracefully()
|
||||
{
|
||||
/** @var SimpleResourceURLGenerator $generator */
|
||||
$generator = Injector::inst()->get(ResourceURLGenerator::class);
|
||||
$url = @$generator->urlForResource('doesnotexist.jpg');
|
||||
$this->assertEquals('/doesnotexist.jpg', $url);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user