Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/Classes/AdminDirScanner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

/*
* This file is part of MMLC - ModifiedModuleLoaderClient.
*
* (c) Robin Wieschendorf <mail@robinwieschendorf.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RobinTheHood\ModifiedModuleLoaderClient;

use RobinTheHood\ModifiedModuleLoaderClient\Helpers\FileHelper;

class AdminDirScanner
{
/**
* @return string[]
*/
public function getAll(string $shopRootPath): array
{
$adminDirPaths = [];
$directoryPaths = FileHelper::scanDir($shopRootPath, FileHelper::DIRS_ONLY, false);
foreach ($directoryPaths as $directoryPath) {
if ($this->isAdminDirPath($directoryPath)) {
$adminDirPaths[] = $directoryPath;
}
}
return $adminDirPaths;
}

private function isAdminDirPath(string $filePath): bool
{
if (!file_exists($filePath)) {
return false;
}

if (!is_dir($filePath)) {
return false;
}

$fileName = basename($filePath);

if (!$this->isAdminDirName($fileName)) {
return false;
}

if (!$this->hasAdminDirFiles($filePath)) {
return false;
}

return true;
}

private function isAdminDirName(string $fileName): bool
{
if ($fileName === 'admin') {
return true;
}

if (strpos(strtolower($fileName), 'admin_') === 0) {
return true;
}

return false;
}

private function hasAdminDirFiles(string $filePath): bool
{
// List of Files, that the admin dire
$files = [
'check_update.php'
];

if (!FileHelper::containsAllFiles($files, $filePath)) {
return false;
}

return true;
}
}
28 changes: 8 additions & 20 deletions src/Classes/ShopInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace RobinTheHood\ModifiedModuleLoaderClient;

use Exception;
use RobinTheHood\ModifiedModuleLoaderClient\App;
use RobinTheHood\ModifiedModuleLoaderClient\Helpers\FileHelper;

Expand Down Expand Up @@ -99,30 +100,17 @@ public static function getAdminDir(): string
*/
public static function scanForAdminDir(): string
{
$resultDirectory = 'admin'; // Set default
$adminDirScanner = new AdminDirScanner();
$adminDirPaths = $adminDirScanner->getAll(App::getShopRoot());

$knownAdminPath = App::getShopRoot() . '/admin';

if (\file_exists($knownAdminPath) && \is_dir($knownAdminPath)) {
return $resultDirectory;
if (count($adminDirPaths) <= 0) {
throw new Exception("No valid admin directory found in " . App::getShopRoot());
}

$directorys = FileHelper::scanDir(App::getShopRoot(), FileHelper::DIRS_ONLY, false);

// List of Files, that the admin dire
$files = [
'check_update.php'
];

foreach ($directorys as $directory) {
if (!FileHelper::containsAllFiles($files, $directory)) {
continue;
}

$resultDirectory = $directory;
break;
if (count($adminDirPaths) >= 2) {
throw new Exception("More than one valid admin directory found in " . App::getShopRoot());
}

return basename($resultDirectory);
return basename($adminDirPaths[0]);
}
}