This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/FileSystem.php

56 lines
1.2 KiB
PHP
Raw Normal View History

<?php
/**
* Holds file system interaction stuff.
* @package Sakura
*/
namespace Sakura;
/**
* Used for handling file system interactions.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class FileSystem
{
2016-10-07 18:00:37 +00:00
/**
* Cached copy of the root path.
* @var string
*/
private static $rootPath = null;
2016-10-07 18:00:37 +00:00
/**
* Resolves the root path.
* @return string
*/
2016-12-04 16:33:52 +00:00
public static function getRootPath(): string
{
if (self::$rootPath === null) {
// assuming we're running from the 'app' subdirectory
self::$rootPath = realpath(__DIR__ . '/..');
}
return self::$rootPath;
}
2016-10-07 18:00:37 +00:00
/**
* Fixes a given path to the correct slashes and root.
2016-12-04 16:33:52 +00:00
* @param string $path
2016-10-07 18:00:37 +00:00
* @return string
*/
2016-12-04 16:33:52 +00:00
public static function getPath(string $path): string
{
return self::getRootPath() . DIRECTORY_SEPARATOR . self::fixSlashes($path);
}
2016-10-07 18:00:37 +00:00
/**
* Fixes slashes.
2016-12-04 16:33:52 +00:00
* @param string $path
2016-10-07 18:00:37 +00:00
* @return string
*/
2016-12-04 16:33:52 +00:00
private static function fixSlashes(string $path): string
{
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
}
}