Skip to content

Commit c4f982b

Browse files
committed
Add exception to file not exists
1 parent bcf02dd commit c4f982b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

AssetsBundle/DependencyInjection/DocplannerAssetsExtension.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,4 @@ public function load(array $configs, ContainerBuilder $container)
2626
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2727
$loader->load('services.yml');
2828
}
29-
30-
public function getAlias()
31-
{
32-
return 'docplanner_assets';
33-
}
3429
}

AssetsBundle/Service/AssetsLoader.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class AssetsLoader
1111
*/
1212
public function renderScript($type = 'file')
1313
{
14-
$files = 'file.js';
14+
$files = ['platform/js/rwd-common.js'];
1515

16-
$mask = $type == 'file' ? '<script>%s</script>' : '<script src="%s?%s"></script>';
16+
$mask = $type == 'inline' ? '<script>%s</script>' : '<script src="%s?%s"></script>';
1717

1818
return $this->render($mask, $files, $type);
1919
}
@@ -25,9 +25,9 @@ public function renderScript($type = 'file')
2525
*/
2626
public function renderStyle($type = 'file')
2727
{
28-
$files = 'file.js';
28+
$files = ['platform/css/rwd-common.css'];
2929

30-
$mask = $type == 'file' ? '<style>%s</style>' : '<link rel="stylesheet" type="text/css" href="%s?%s">';
30+
$mask = $type == 'inline' ? '<style>%s</style>' : '<link rel="stylesheet" type="text/css" href="%s?%s">';
3131

3232
return $this->render($mask, $files, $type);
3333
}
@@ -47,13 +47,23 @@ private function render($mask, $files, $type)
4747
{
4848
foreach ($files as $file)
4949
{
50+
if (!file_exists($file))
51+
{
52+
throw new \LogicException(sprintf('File %s not found', $file));
53+
}
54+
5055
$ret .= sprintf($mask, $file, crc32(file_get_contents($file)));
5156
}
5257
}
5358
else
5459
{
5560
foreach ($files as $file)
5661
{
62+
if (!file_exists($file))
63+
{
64+
throw new \LogicException(sprintf('File %s not found', $file));
65+
}
66+
5767
$source = file_get_contents($file);
5868
$ret .= $source;
5969
}

AssetsBundle/Twig/AssetsExtension.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function __construct(AssetsLoader $assetsLoader)
2323
public function getFunctions()
2424
{
2525
return [
26-
new \Twig_SimpleFunction('assets_script', [$this, 'assetsScript']),
27-
new \Twig_SimpleFunction('assets_style', [$this, 'assetsStyle']),
26+
new \Twig_SimpleFunction('assets_script', [$this, 'assetsScript'], ['is_safe' => ['html']]),
27+
new \Twig_SimpleFunction('assets_style', [$this, 'assetsStyle'], ['is_safe' => ['html']]),
2828
];
2929
}
3030

@@ -33,20 +33,19 @@ public function getFunctions()
3333
*
3434
* @return string
3535
*/
36-
protected function assetsScript($type = null)
36+
public function assetsScript($type = 'file')
3737
{
38-
return '';
39-
// return $this->assetsLoader->renderScript($type);
38+
return $this->assetsLoader->renderScript($type);
4039
}
4140

4241
/**
4342
* @param null $type
4443
*
4544
* @return string
4645
*/
47-
protected function assetsStyle($type = null)
46+
public function assetsStyle($type = 'file')
4847
{
49-
return $this->assetsLoader->renderScript($type);
48+
return $this->assetsLoader->renderStyle($type);
5049
}
5150

5251
/**

0 commit comments

Comments
 (0)