From fac217530b035b1f98a6f9507db67eaf684b2e6a Mon Sep 17 00:00:00 2001 From: Mougrim Date: Tue, 11 May 2021 18:28:08 +0300 Subject: [PATCH] Add configCacheFileMode option Signed-off-by: Mougrim --- src/Listener/AbstractListener.php | 5 +++-- src/Listener/ConfigListener.php | 3 ++- src/Listener/ListenerOptions.php | 27 +++++++++++++++++++++++++++ test/Listener/ListenerOptionsTest.php | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Listener/AbstractListener.php b/src/Listener/AbstractListener.php index b476d26..281825a 100644 --- a/src/Listener/AbstractListener.php +++ b/src/Listener/AbstractListener.php @@ -61,9 +61,10 @@ public function setOptions(ListenerOptions $options) * * @param string $filePath * @param array $array + * @param int $fileMode * @return AbstractListener */ - protected function writeArrayToFile($filePath, $array) + protected function writeArrayToFile($filePath, $array, $fileMode = 0666) { try { $content = "skipConfig ) { $configFile = $this->getOptions()->getConfigCacheFile(); - $this->writeArrayToFile($configFile, $this->getMergedConfig(false)); + $configFileMode = $this->getOptions()->getConfigCacheFileMode(); + $this->writeArrayToFile($configFile, $this->getMergedConfig(false), $configFileMode); } return $this; diff --git a/src/Listener/ListenerOptions.php b/src/Listener/ListenerOptions.php index cc27fd6..82a4086 100644 --- a/src/Listener/ListenerOptions.php +++ b/src/Listener/ListenerOptions.php @@ -52,6 +52,11 @@ class ListenerOptions extends AbstractOptions */ protected $configCacheKey; + /** + * @var int + */ + protected $configCacheFileMode = 0666; + /** * @var string|null */ @@ -283,6 +288,28 @@ public function getConfigCacheFile() return $this->getCacheDir() . '/module-config-cache.php'; } + /** + * Get permission mode used to create the cache file name + * + * @return int + */ + public function getConfigCacheFileMode() + { + return $this->configCacheFileMode; + } + + /** + * Set permission mode used to create the cache file name + * + * @param int $configCacheFileMode + * @return ListenerOptions + */ + public function setConfigCacheFileMode($configCacheFileMode) + { + $this->configCacheFileMode = $configCacheFileMode; + return $this; + } + /** * Get the path where cache file(s) are stored * diff --git a/test/Listener/ListenerOptionsTest.php b/test/Listener/ListenerOptionsTest.php index c952646..fd16a51 100644 --- a/test/Listener/ListenerOptionsTest.php +++ b/test/Listener/ListenerOptionsTest.php @@ -26,6 +26,7 @@ public function testCanConfigureWithArrayInConstructor() 'cache_dir' => __DIR__, 'config_cache_enabled' => true, 'config_cache_key' => 'foo', + 'config_cache_file_mode' => 0123, 'module_paths' => ['module', 'paths'], 'config_glob_paths' => ['glob', 'paths'], 'config_static_paths' => ['static', 'custom_paths'], @@ -35,6 +36,7 @@ public function testCanConfigureWithArrayInConstructor() self::assertNotNull(strstr($options->getConfigCacheFile(), __DIR__)); self::assertNotNull(strstr($options->getConfigCacheFile(), '.php')); self::assertSame('foo', $options->getConfigCacheKey()); + self::assertSame(0123, $options->getConfigCacheFileMode()); self::assertSame(['module', 'paths'], $options->getModulePaths()); self::assertSame(['glob', 'paths'], $options->getConfigGlobPaths()); self::assertSame(['static', 'custom_paths'], $options->getConfigStaticPaths());