65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
|
|
<?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';
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|