for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\application;
use nebula\component\loader\Path;
use nebula\application\config\Config;
use nebula\application\filesystem\FileSystem;
/**
* 资源管理器
*/
class Resource
{
* 资源路径
*
* @var array
protected $resource = [];
* 获取相对的路径
* @param string $source
* @param string $relative
* @return string
public static function getPathByRelativedPath(string $source, string $relative):string
$path = $source;
if (Path::isRelativePath($source)) {
$path = $relative.'/'.$path;
}
return Path::toAbsolutePath($path);
* 添加资源目录
* @param string $path
* @return void
public function addResourcePath(string $path)
$path = Path::toAbsolutePath($path);
if (!\in_array($path, $this->resource)) {
array_unshift($this->resource, $path);
* 获取资源文件路径
* @return string|null
public function getResourcePath(string $path):?string
foreach ($this->resource as $root) {
$target = $root.'/'.$path;
if (FileSystem::exist($target)) {
return $target;
return null;
* 获取配置资源文件路径
public function getConfigResourcePath(string $path):?string
if ( $target = Config::resolve($root.'/'.$path)) {