This commit is contained in:
Juan Pablo Vial
2023-07-24 20:41:38 -04:00
parent 6ab24c8961
commit be33305cf1
612 changed files with 11436 additions and 107 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace Proyect\Root;
class Root
{
/**
* gives base path for your proyect.
* eg. <code>$proyect_name/public/index.php</code> calls for <code>$proyect_name/bootstrap/autoload.php</code>,
* you just need to
*
* <code>include root() . '/bootstrap/autoload.php'</code>
*
* @param string $proyect_name
* @return string
*/
public static function root(string $proyect_name = '')
{
$dir = realpath(__DIR__);
if ($proyect_name == '') {
return self::findComposerFile($dir);
} else {
$ini = strpos($dir, $proyect_name) + strlen($proyect_name);
}
$path = substr($dir, $ini);
$cnt = substr_count($path, DIRECTORY_SEPARATOR);
$root = DIRECTORY_SEPARATOR;
for ($i = 0; $i < $cnt; $i ++) {
$root .= '..' . DIRECTORY_SEPARATOR;
}
return realpath($dir . $root);
}
protected static function findComposerFile($dir)
{
if (file_exists($dir . '/vendor/')) {
return $dir;
}
$root = realpath('/');
if (realpath($dir) == $root) {
return null;
}
$dir = dirname($dir);
return self::findComposerFile($dir);
}
}
?>