Replacing realpath with file_exists

This commit is contained in:
Dennis Eichhorn 2016-08-23 21:26:05 +02:00
parent 74e1053271
commit 4b09c7c1ba
8 changed files with 16 additions and 21 deletions

View File

@ -178,7 +178,7 @@ class Dispatcher
private function getController(string $controller)
{
if (!isset($this->controllers[$controller])) {
if (realpath($path = ROOT_PATH . '/' . str_replace('\\', '/', $controller) . '.php') === false) {
if (!file_exists($path = ROOT_PATH . '/' . str_replace('\\', '/', $controller) . '.php')) {
throw new PathException($path);
}

View File

@ -103,13 +103,9 @@ class FileLogger implements LoggerInterface
}
if (is_dir($lpath) || strpos($lpath, '.') === false) {
File::create($path = $lpath . '/' . date('Y-m-d') . '.log');
$path = realpath($path);
File::create($path = $path . '/' . date('Y-m-d') . '.log');
} else {
File::create($lpath);
$path = realpath($lpath);
}
$this->path = $path;

View File

@ -52,6 +52,8 @@ class FinanceFormulas
/**
* Annual Percentage Yield
*
* @latex r = \left(APY + 1\right)^{\frac{1}{n}} \cdot n - 1
*
* @param float $apy Annual percentage yield
* @param int $n Number of times compounded
*
@ -62,7 +64,7 @@ class FinanceFormulas
*/
public static function getStateAnnualInterestRateOfAPY(float $apy, int $n) : float
{
return (pow($apy + 1, 1 / $n) - 1) * $n;
return pow($apy + 1, 1 / $n) * $n - 1;
}
/**

View File

@ -73,11 +73,11 @@ class InfoManager
*/
public function load()
{
if (($path = realpath($this->path)) === false) {
if (!file_exists($this->path)) {
throw new PathException($this->path);
}
$this->info = json_decode(file_get_contents($path), true);
$this->info = json_decode(file_get_contents($this->path), true);
}
/**

View File

@ -124,9 +124,9 @@ abstract class ModuleAbstract
public static function getLocalization(string $language, string $destination) : array
{
$lang = [];
if (($path = realpath($oldPath = __DIR__ . '/../../Modules/' . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) !== false) {
if (file_exists($oldPath = __DIR__ . '/../../Modules/' . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
/** @noinspection PhpIncludeInspection */
$lang = include $path;
$lang = include $oldPath;
}
return $lang;

View File

@ -61,7 +61,7 @@ class Router
*/
public function importFromFile(string $path) : bool
{
if (file_exists($path)) {
if (stream_resolve_include_path($path) !== false) {
/** @noinspection PhpIncludeInspection */
$this->routes += include $path;

View File

@ -194,9 +194,8 @@ class Directory extends FileAbstract implements DirectoryInterface
*/
public static function delete(string $path) : bool
{
$path = realpath($oldPath = $path);
if ($path === false || !is_dir($path) || StringUtils::startsWith($path, ROOT_PATH)) {
throw new PathException($oldPath);
if (!file_exists($path) || !is_dir($path)) {
throw new PathException($path);
}
$files = scandir($path);

View File

@ -205,9 +205,7 @@ abstract class ViewAbstract implements \Serializable
*/
public function serialize()
{
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
if ($path === false) {
if (!file_exists(__DIR__ . '/../..' . $this->template . '.tpl.php')) {
return $this->toArray();
}
@ -247,10 +245,10 @@ abstract class ViewAbstract implements \Serializable
*/
public function render() : string
{
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
$path = __DIR__ . '/../..' . $this->template . '.tpl.php';
if ($path === false) {
throw new PathException($oldPath);
if (!file_exists($path)) {
throw new PathException($path);
}
ob_start();