Skip to content

Commit 156f86b

Browse files
author
Aleksandr Daniloff
committed
Update:
- reamde - improve codestyle
1 parent 0870019 commit 156f86b

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

DependencyInjection/Configuration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public function getConfigTreeBuilder()
2525
$rootNode = $treeBuilder->root('leoo_team_cache_cleaner');
2626
$rootNode
2727
->children()
28-
->variableNode('commands')->end();
29-
// ->end();
28+
->variableNode('commands')
29+
->end();
3030

3131
return $treeBuilder;
3232
}

Event/CommandListener.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
class CommandListener
1818
{
19-
const FILE_PATH = __DIR__ . '/../Resources/config/versions.yml';
19+
const FILE_PATH = __DIR__ . '/../Resources/config';
20+
const FILE_NAME = 'versions.yml';
2021

2122
/** @var array $allowedCommands */
2223
private $allowedCommands;
@@ -31,8 +32,6 @@ public function __construct($allowedCommands)
3132
}
3233

3334
/**
34-
* @todo: add input parameters ?
35-
* @todo: check if directories and file exists
3635
* @param ConsoleCommandEvent $event
3736
*/
3837
public function run(ConsoleCommandEvent $event)
@@ -41,13 +40,25 @@ public function run(ConsoleCommandEvent $event)
4140
$command = $event->getCommand();
4241

4342
if (in_array($command->getName(), $this->allowedCommands)) {
44-
$config = @Yaml::parse(file_get_contents(self::FILE_PATH));
45-
$oldVersion = (int)@$config['framework']['assets']['version']++;
43+
$filename = self::FILE_PATH . '/' . self::FILE_NAME;
4644

45+
if (file_exists($filename)) {
46+
$config = Yaml::parse(file_get_contents($filename));
47+
}
48+
49+
if (
50+
!isset($config['framework'])
51+
or !isset($config['framework']['assets'])
52+
or !isset($config['framework']['assets']['version'])
53+
) {
54+
$config = array('framework' => array('assets' => array('version' => 0)));
55+
}
56+
$oldVersion = $config['framework']['assets']['version']++;
57+
4758
$output->writeln("Updating asset_version from <info>$oldVersion</info>"
4859
. " to <info>{$config['framework']['assets']['version']}</info>");
4960

50-
file_put_contents(self::FILE_PATH, Yaml::dump($config));
61+
file_put_contents($filename, Yaml::dump($config));
5162
}
5263
}
5364
}

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
This project is still under conceptualization / development. There is a lot of things to do and improve. Any contirbution (pull-request, issues...) will be much appreciated.
55

66
### What is this repository for? ###
7-
87
This Repository let you change the framework_assets_version to force client to reload assets.
98
You can either define specific commands (like assets:install or assetic:dump) that will be overloaded or use the new commands to do so manually.
109

1110
### Installation ###
12-
1311
@todo: explain how to install package
1412

1513
Add the bundle to your AppKernel.php file:
1614
```
1715
$bundles = array(
18-
1916
...
20-
2117
new LeooTeam\CacheCleanerBundle\LeooTeamCacheCleanerBundle(),
22-
2318
);
2419
```
2520

2621
### Requirements ###
27-
2822
This bundle requires Symfony >= 2.8
2923

3024
### Configuration ###
31-
Optionnal : add the commands that will trigger the event.
25+
Required : add the commands that will trigger the event.
3226
```
3327
#app/config/config.yml
28+
imports:
29+
- { resource: "@LeooTeamCacheCleanerBundle/Resources/config/versions.yml", ignore_errors: true }
30+
```
31+
32+
Optionnal : add the commands that will trigger the event.
33+
```
3434
leoo_team_cache_cleaner:
3535
commands: ['cache:clear', 'assets:install', 'assetic:dump']
3636
```

0 commit comments

Comments
 (0)