Skip to content

Commit

Permalink
Add configCacheFileMode option
Browse files Browse the repository at this point in the history
Signed-off-by: Mougrim <[email protected]>
  • Loading branch information
mougrim committed May 11, 2021
1 parent 2068e0b commit fac2175
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Listener/AbstractListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?php\n" . VarExporter::export(
Expand All @@ -74,7 +75,7 @@ protected function writeArrayToFile($filePath, $array)
throw ConfigCannotBeCachedException::fromExporterException($e);
}

FileWriter::writeFile($filePath, $content);
FileWriter::writeFile($filePath, $content, $fileMode);

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Listener/ConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public function onLoadModules(ModuleEvent $e)
&& false === $this->skipConfig
) {
$configFile = $this->getOptions()->getConfigCacheFile();
$this->writeArrayToFile($configFile, $this->getMergedConfig(false));
$configFileMode = $this->getOptions()->getConfigCacheFileMode();
$this->writeArrayToFile($configFile, $this->getMergedConfig(false), $configFileMode);
}

return $this;
Expand Down
27 changes: 27 additions & 0 deletions src/Listener/ListenerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class ListenerOptions extends AbstractOptions
*/
protected $configCacheKey;

/**
* @var int
*/
protected $configCacheFileMode = 0666;

/**
* @var string|null
*/
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions test/Listener/ListenerOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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());
Expand Down

0 comments on commit fac2175

Please sign in to comment.