Commit d1c6cacb authored by Tino Goratsch's avatar Tino Goratsch

added a static class "Filesystem"

parent a8f9b045
...@@ -53,8 +53,7 @@ class Cache ...@@ -53,8 +53,7 @@ class Cache
return @unlink($dir); return @unlink($dir);
} }
$files = array_diff(scandir($dir), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']); foreach (Filesystem::scandir($dir) as $file) {
foreach ($files as $file) {
$path = "$dir/$file"; $path = "$dir/$file";
if (is_dir($path)) { if (is_dir($path)) {
......
<?php
namespace ACP3\Core;
/**
* Class Filesystem
* @package ACP3\Core
*/
class Filesystem
{
/**
* @var array
*/
protected static $excluded = ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd'];
/**
* @param $directory
* @param array $excluded
*
* @return array
*/
public static function scandir($directory, array $excluded = [])
{
return array_diff(
scandir($directory),
array_merge(static::$excluded, $excluded)
);
}
}
\ No newline at end of file
...@@ -173,9 +173,8 @@ class Modules ...@@ -173,9 +173,8 @@ class Modules
public function getAllModules() public function getAllModules()
{ {
if (empty($this->allModules)) { if (empty($this->allModules)) {
foreach ($this->vendors->getVendors() as $namespace) { foreach ($this->vendors->getVendors() as $vendor) {
$modules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']); foreach (Filesystem::scandir(MODULES_DIR . $vendor . '/') as $module) {
foreach ($modules as $module) {
$info = $this->getModuleInfo($module); $info = $this->getModuleInfo($module);
if (!empty($info)) { if (!empty($info)) {
$this->allModules[$info['name']] = $info; $this->allModules[$info['name']] = $info;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace ACP3\Core\Modules; namespace ACP3\Core\Modules;
use ACP3\Core\Cache; use ACP3\Core\Cache;
use ACP3\Core\Filesystem;
use ACP3\Core\Lang; use ACP3\Core\Lang;
use ACP3\Core\XML; use ACP3\Core\XML;
use ACP3\Modules\ACP3\System\Model; use ACP3\Modules\ACP3\System\Model;
...@@ -101,7 +102,7 @@ class ModuleInfoCache ...@@ -101,7 +102,7 @@ class ModuleInfoCache
{ {
$infos = []; $infos = [];
$modules = array_diff(scandir(MODULES_DIR . $vendor . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']); $modules = Filesystem::scandir(MODULES_DIR . $vendor . '/');
if (!empty($modules)) { if (!empty($modules)) {
foreach ($modules as $module) { foreach ($modules as $module) {
...@@ -177,7 +178,7 @@ class ModuleInfoCache ...@@ -177,7 +178,7 @@ class ModuleInfoCache
*/ */
protected function getModuleName(array $moduleInfo, $moduleName) protected function getModuleName(array $moduleInfo, $moduleName)
{ {
if (isset($moduleInfo['name']['lang']) && $moduleInfo['name']['lang'] == 'true') { if (isset($moduleInfo['name']['lang']) && $moduleInfo['name']['lang'] === 'true') {
return $this->lang->t($moduleName, $moduleName); return $this->lang->t($moduleName, $moduleName);
} }
......
<?php <?php
namespace ACP3\Core\Modules; namespace ACP3\Core\Modules;
use ACP3\Core\Filesystem;
/** /**
* Class Vendors * Class Vendors
...@@ -20,7 +21,7 @@ class Vendors ...@@ -20,7 +21,7 @@ class Vendors
if ($this->vendors === []) { if ($this->vendors === []) {
$this->vendors = array_merge( $this->vendors = array_merge(
['ACP3'], ['ACP3'],
array_diff(scandir(MODULES_DIR), ['.', '..', 'ACP3', 'Custom']), Filesystem::scandir(MODULES_DIR, ['ACP3', 'Custom']),
['Custom'] ['Custom']
); );
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace ACP3\Installer\Modules\Update\Controller; namespace ACP3\Installer\Modules\Update\Controller;
use ACP3\Core\Cache; use ACP3\Core\Cache;
use ACP3\Core\Filesystem;
use ACP3\Core\Modules; use ACP3\Core\Modules;
use ACP3\Installer\Core; use ACP3\Installer\Core;
...@@ -64,8 +65,7 @@ class Index extends Core\Modules\Controller ...@@ -64,8 +65,7 @@ class Index extends Core\Modules\Controller
// ...danach die Restlichen // ...danach die Restlichen
foreach ($this->vendors->getVendors() as $vendor) { foreach ($this->vendors->getVendors() as $vendor) {
$modules = array_diff(scandir(MODULES_DIR . $vendor . '/'), ['.', '..', '.gitignore', '.svn', '.htaccess', '.htpasswd']); foreach (Filesystem::scandir(MODULES_DIR . $vendor . '/') as $module) {
foreach ($modules as $module) {
if (in_array(strtolower($module), $coreModules) === false) { if (in_array(strtolower($module), $coreModules) === false) {
$results[$module] = $this->_returnModuleUpdateResult($module); $results[$module] = $this->_returnModuleUpdateResult($module);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment