narrowspark / exception-inspector
此包已被废弃,不再维护。未建议替代包。
异常堆栈跟踪检查器。
1.0.2
2020-04-22 08:13 UTC
Requires
- php: ^7.3
- thecodingmachine/safe: ^1.1.0
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^9.1.2
- dev-master / 1.0.x-dev
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/json5-2.2.3
- dev-renovate/configure
- dev-dependabot/npm_and_yarn/minimist-1.2.6
- dev-dependabot/npm_and_yarn/node-fetch-2.6.7
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/composer/phpunit/phpunit-tw-9.5.8
- dev-dependabot/npm_and_yarn/textlint-12.0.2
- dev-dependabot/npm_and_yarn/textlint-rule-write-good-2.0.0
- dev-dependabot/npm_and_yarn/textlint-rule-helper-2.2.0
- dev-dependabot/npm_and_yarn/textlint-rule/textlint-rule-no-invalid-control-character-2.0.0
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/dot-build/wikimedia/composer-merge-plugin-tw-2.0.1
- dev-dependabot/npm_and_yarn/write-good-1.0.8
- dev-dependabot/npm_and_yarn/textlint-rule-terminology-2.1.5
- dev-dependabot/npm_and_yarn/ini-1.3.8
- dev-dependabot/npm_and_yarn/textlint-rule-en-capitalization-2.0.3
- dev-dependabot/composer/thecodingmachine/safe-tw-1.3.3
- dev-dependabot/npm_and_yarn/node-fetch-2.6.1
- dev-dependabot/npm_and_yarn/textlint-rule-alex-3.0.0
- dev-dependabot/npm_and_yarn/textlint-rule-no-dead-link-4.7.0
This package is auto-updated.
Last update: 2023-03-05 18:56:31 UTC
README
异常堆栈跟踪检查器。
安装
运行
$ composer require narrowspark/exception-inspector
用法
Inspector
类提供了检查异常实例的方法,特别关注其帧或堆栈跟踪。
<?php declare(strict_types=1); use Narrowspark\ExceptionInspector\Frame; use Narrowspark\ExceptionInspector\FrameCollection; use Narrowspark\ExceptionInspector\Inspector; $exception = new \Exception('This is a error'); $inspector = new Inspector($exception); /** * Returns an iterator instance for all the frames in the stack * trace for the Exception being inspected. * * @var \Narrowspark\ExceptionInspector\FrameIterator $frames */ $frames = $inspector->getFrames(); // Returns the string name of the Exception being inspected // A faster way of doing get_class($inspector->getException()) echo $inspector->getExceptionName(); // Returns the string message for the Exception being inspected // A faster way of doing $inspector->getException()->getMessage() echo $inspector->getExceptionMessage();
FrameCollection
类提供了一个流畅的接口来操作和检查一组 Frame
实例。
// Returns the number of frames in the collection echo $frames->count(); // @see [array_filter](https://php.ac.cn/manual/en/function.array-filter) // Filter the Frames in the collection with a callable. // The callable must accept a Frame object, and return // true to keep it in the collection, or false not to. $filteredFrames = $frames->filter(function(Frame $frame): bool { return true; }); // @see: [array_map](https://php.ac.cn/manual/en/function.array-map.php) // The callable must accept a Frame object, and return // a Frame object, doesn't matter if it's the same or not // - will throw an UnexpectedValueException if something // else is returned. $mapedFrames = $frames->map(function (Frame $frame): Frame { return $frame; });
Frame
类模拟异常堆栈跟踪中的一个单独的帧。您可以使用它来检索有关帧上下文、文件和行号的信息。
您有向帧添加注释的功能。
foreach ($frames as $frame) { // Returns the file path for the file where this frame occurred. $frame->getFile(); // Returns the line number for this frame $frame->getLine(); // Returns the class name for this frame, if it occurred // within a class/instance. $frame->getClass(); // Returns the function name for this frame, if it occurred // within a function/method $frame->getFunction(); // Returns an array of arguments for this frame. Empty if no // arguments were provided. $frame->getArgs(); // Returns the full file contents for the file where this frame // occurred. $frame->getFileContents(); // Returns an array of lines for a file. $frame->getFileLines(); // Optionally scoped to a given range of line numbers. // i.e: Frame::getFileLines(0, 3) returns the first 3 // lines after line 0 (1) $frame->getFileLines(0, 3); }
版本控制
此库遵循语义版本控制,代码规则集的添加在主要版本中执行。
变更日志
请查看 CHANGELOG.md
。
贡献
请查看 CONTRIBUTING.md
。
感谢 whoops 提供的类接口。
行为准则
请查看 CODE_OF_CONDUCT.md
。
许可
此包使用 MIT 许可证进行许可。
请查看 LICENSE.md
。