Passed
Push — master ( 2ccc95...db451c )
by Tim
02:28
created

RequirementsInline::themedJavascript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace DorsetDigital\SilverstripeRequirements;
3
4
use SilverStripe\View\Requirements;
5
use SilverStripe\View\SSViewer;
6
use SilverStripe\View\ThemeResourceLoader;
7
use SilverStripe\Control\Director;
8
9
class RequirementsInline
10
{
11
12
 public static function themedJavascript($file, $uniqueId = null)
13
 {
14
  $path = ThemeResourceLoader::inst()->findThemedJavascript($file, SSViewer::get_themes());
15
  if ($path) {
16
   $script = file_get_contents(Director::baseFolder() . DIRECTORY_SEPARATOR . $path);
17
   Requirements::customScript($script, $uniqueId);
18
  } else {
19
   Requirements::customScript('// ' . $file . ' not found');
20
  }
21
 }
22
23
 public static function themedCSS($file, $uniqueId = null)
24
 {
25
  $path = ThemeResourceLoader::inst()->findThemedCSS($file, SSViewer::get_themes());
26
  if ($path) {
27
   $styles = file_get_contents(Director::baseFolder() . DIRECTORY_SEPARATOR . $path);
28
   Requirements::customCSS($styles, $uniqueId);
29
  } else {
30
   Requirements::customCSS('/* ' . $file . ' not found */');
31
  }  
32
 }
33
}
34