Files
InvoiceShelf/app/Platform/Operations/Installation/Application/FilePermissionChecker.php
T
Darko Gjorgjijoski 7db2a8d094 feat(operations): fresh platform-operations implementation
Full rewrite of the installer (incl. the finish step), self-update pipeline,
settings store, cron webhook, dashboard/bootstrap surface, environment
manager, wizard login, config endpoint and shared helpers. Byte-compatible
public interfaces and observable behavior, including documented legacy
quirks; verified by the pilot behavioral suite and the full test suite.
2026-08-20 18:30:12 +02:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Platform\Operations\Installation\Application;
/**
* Reports whether the writable directories the application relies on are at
* least as permissive as the installer requires.
*/
class FilePermissionChecker
{
protected array $results = [];
public function __construct()
{
$this->results = [
'permissions' => [],
'errors' => null,
];
}
/**
* Walk a map of relative folder path => required octal mode. Entries are
* reported in the order given; "errors" stays null until something fails.
*/
public function check(array $folders): array
{
foreach ($folders as $folder => $required) {
$granted = $this->modeOf($folder) >= $required;
$this->results['permissions'][] = [
'folder' => $folder,
'permission' => $required,
'isSet' => $granted,
];
if (! $granted) {
$this->results['errors'] = true;
}
}
return $this->results;
}
/**
* The last four octal digits of the folder's mode, e.g. "0775". Both this
* and the requirement are numeric strings, so the caller's comparison is
* made on their numeric value.
*/
private function modeOf(string $folder): string
{
return substr(sprintf('%o', fileperms(base_path($folder))), -4);
}
}