Skip to content

Commit

Permalink
Added clear-config-cache utility
Browse files Browse the repository at this point in the history
Per conversation on zendframework#54, we want to make production settings the
default, which means enabling the configuration cache. However, we also
need to make it easy for developers to clear the configuration cache.

This patch adds a script, `bin/clear-config-cache.php`, which can be
used to remove the configured configuration cache file, if defined. It
is aliased in `composer.json` as `clear-config-cache`, allowing usage as
`composer clear-config-cache`.
  • Loading branch information
weierophinney committed Jan 11, 2017
1 parent d973761 commit 4440dfd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bin/clear-config-cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Script for clearing the configuration cache.
*
* Can also be invoked as `composer clear-config-cache`.
*
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License
*/

chdir(__DIR__ . '/../');

require 'vendor/autoload.php';

$config = include 'config/config.php';

if (! isset($config['config_cache_path'])) {
echo "No configuration cache path found" . PHP_EOL;
exit(0);
}

if (! file_exists($config['config_cache_path'])) {
printf(
"Configured config cache file '%s' not found%s",
$config['config_cache_path'],
PHP_EOL
);
exit(0);
}

if (false === unlink($config['config_cache_path'])) {
printf(
"Error removing config cache file '%s'%s",
$config['config_cache_path'],
PHP_EOL
);
exit(1);
}

printf(
"Removed configured config cache file '%s'%s",
$config['config_cache_path'],
PHP_EOL
);
exit(0);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@cs-check",
"@test"
],
"clear-config-cache": "php bin/clear-config-cache.php",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public public/index.php",
Expand Down

0 comments on commit 4440dfd

Please sign in to comment.