initial release

This commit is contained in:
norb 2022-04-06 15:53:12 +02:00
commit 70755ec953
7 changed files with 2940 additions and 0 deletions

65
src/Instance.php Normal file
View file

@ -0,0 +1,65 @@
<?php
/* {{{ Copyright and License Notice
*
* Copyright © 2022 RaBe Websolutions
*
* This file is part of rabe/Util-Instance.
*
* rabe/Util-Instance is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* rabe/Util-Instance is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with rabe/Util-Instance. If not, see <https://www.gnu.org/licenses/>.
*
*///}}}
declare(strict_types=1);
namespace rabe\Util;
class Instance
{
private SplFileInfo $fileInfo;
public function __construct(SplFileInfo $fileInfo)
{
$this->fileInfo = $fileInfo;
}
public function __get(string $property)
{
switch ($property) {
case 'name':
return $this->fileInfo->getBaseName();
case 'basePath':
return $this->fileInfo->getPathname();
case 'webRoot':
return $this->getWebRoot();
case 'configPath':
return $this->getConfigPath();
}
}
public function getWebRoot()
{
$webRoot = $this->basePath;
if (file_exists("$webRoot/public")) {
$webRoot .= '/public';
}
if (file_exists("$webRoot/httpsdocs")) {
$webRoot .= '/httpsdocs';
}
return $webRoot;
}
public function getConfigPath()
{
return $this->webRoot . '/config';
}
}