1
0
mirror of https://github.com/flarum/core.git synced 2025-08-02 14:37:49 +02:00

Extract a class to hold / determine paths

This commit is contained in:
Franz Liedke
2020-05-01 14:23:44 +02:00
parent d31a747631
commit d0ae2839f0
5 changed files with 160 additions and 33 deletions

44
src/Foundation/Paths.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation;
use InvalidArgumentException;
/**
* @property-read string base
* @property-read string public
* @property-read string storage
* @property-read string vendor
*/
class Paths
{
private $paths;
public function __construct(array $paths)
{
if (! isset($paths['base'], $paths['public'], $paths['storage'])) {
throw new InvalidArgumentException(
'Paths array requires keys base, public and storage'
);
}
$this->paths = array_map(function ($path) {
return rtrim($path, '\/');
}, $paths);
// Assume a standard Composer directory structure unless specified
$this->paths['vendor'] = $this->vendor ?? $this->base.DIRECTORY_SEPARATOR.'vendor';
}
public function __get($name): ?string
{
return $this->paths[$name] ?? null;
}
}