loilo/

获取调用您代码的文件或目录

1.0.0 2019-07-16 15:54 UTC

This package is auto-updated.

Last update: 2024-09-24 07:12:01 UTC


README

Traceback logo: two dog footprints next to each other

Traceback

Tests Version on packagist.org

获取调用您代码的文件或目录。

安装

composer require loilo/traceback

使用

/var/www/foo.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

require_once __DIR__ . '/foo.php';

foo();

/var/www/baz/qux.php

require_once __DIR__ . '/../bar.php';

运行 qux.php 将输出

string(16) "/var/www/bar.php"
string(8) "/var/www"
string(20) "/var/www/baz/qux.php"
string(12) "/var/www/baz"