retrorsum/README.md

41 lines
937 B
Markdown
Raw Permalink Normal View History

2017-02-02 17:06:29 -08:00
# Retrorsum
This is a simple thing that will search for a file traversing down from the current directory.
This came about because I was thinking of how I could find the base directory of a project without guessing with `__DIR__."/../../../"` and without forcing an app/ directory or something.
I wanted to find a way to find the base directory of an app from a class.
2017-02-02 17:59:09 -08:00
At the moment it does not work if the path is a symlink.
2017-02-02 17:06:29 -08:00
## Usage
```php
use Sikofitt\Retrorsum\Finder;
2017-02-02 17:59:09 -08:00
$finder = new Finder('autoload.php');
2017-02-02 17:06:29 -08:00
2017-02-02 17:59:09 -08:00
define('BASE_DIR', dirname((string)$finder));
2017-02-02 17:06:29 -08:00
```
or
```php
2017-02-02 18:35:22 -08:00
define('BASE_DIR', dirname((string)(new Finder('autoload.php'))));
2017-02-02 17:06:29 -08:00
```
Although this could set BASE_DIR as an empty string if it found nothing.
```php
2017-02-02 18:35:22 -08:00
$finder = new Finder('autoload.php');
2017-02-02 17:06:29 -08:00
if(true === $finder->isFound())
{
2017-02-02 17:59:09 -08:00
define('BASE_DIR', dirname($finder->getPath()));
2017-02-02 17:06:29 -08:00
} else {
// Whatever your other method would be.
}
```
## License
GPL-3.0