Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loilo/traceback
🐾 Get the file or directory calling your code
https://github.com/loilo/traceback
Last synced: 5 days ago
JSON representation
🐾 Get the file or directory calling your code
- Host: GitHub
- URL: https://github.com/loilo/traceback
- Owner: loilo
- License: mit
- Created: 2019-07-16T15:55:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-23T23:03:53.000Z (almost 4 years ago)
- Last Synced: 2024-08-13T14:34:14.484Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Traceback
[![Tests](https://badgen.net/github/checks/loilo/traceback/master)](https://github.com/loilo/traceback/actions)
[![Version on packagist.org](https://badgen.net/packagist/v/loilo/traceback)](https://packagist.org/packages/loilo/traceback)Get the file or directory calling your code.
## Installation
```bash
composer require loilo/traceback
```## Usage
`/var/www/foo.php`
```php
require_once __DIR__ . '/vendor/autoload.php';use Loilo\Traceback\Traceback;
function foo()
{
var_dump(
// File path calling foo()
Traceback::file(),// Directory of file calling foo()
Traceback::dir(),// File path calling foo() but skipping
// the first file in the chain
Traceback::file(1),// Directory of file calling foo() with skipping
Traceback::dir(1)
);
}
````/var/www/bar.php`
```php
require_once __DIR__ . '/foo.php';foo();
````/var/www/baz/qux.php`
```php
require_once __DIR__ . '/../bar.php';
```Running `qux.php` will output:
```
string(16) "/var/www/bar.php"
string(8) "/var/www"
string(20) "/var/www/baz/qux.php"
string(12) "/var/www/baz"
```