Maslosoft Cli Shared API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/cli-shared
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*/
namespace Maslosoft\Cli\Shared\Helpers;
use Maslosoft\Cli\Shared\ConfigDetector;
class FileIO
{
public static function getRootPath($filename = '')
{
$path = (new ConfigDetector())->getRootPath();
if (!empty($path))
{
return rtrim($path, '/\\') . '/' . $filename;
}
return $filename;
}
public static function read($filename)
{
$path = self::getRootPath($filename);
if (!file_exists($path))
{
return null;
}
return file_get_contents($path);
}
public static function write($filename, $data)
{
$path = self::getRootPath($filename);
$dir = dirname($path);
if (!file_exists($dir))
{
mkdir($dir, 0777, true);
}
return file_put_contents($path, $data);
}
}
API documentation generated by ApiGen