recoilphp / dev Goto Github PK
View Code? Open in Web Editor NEWDevelopment and debugging tools for Recoil applications.
License: MIT License
Development and debugging tools for Recoil applications.
License: MIT License
The "synthesized" stack frames produced by Trace
do not yet include these keys:
See http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-returnvalues
phpstan
uses nikic/php-parser
3.x, which conflicts with the use of 2.x by this repo.
Suggestion, for utility functions - I put them in Trace.php. Almost-dropin replacements for PHP debug_backtrace() and debug_print_backtrace(), useful for retrieving backtrace without having to throw a fatal exception. Happy to create as pull request, but quite possible I missed something vital in writing these.
/**
* Replacement for debug_print_backtrace() PHP function. Returns the current stack as a string
*
* Call as `yield Trace::debug_print_backtrace();`
*/
public static function debug_print_backtrace() : \Generator
{
/** @var Trace $trace */
$trace = \class_exists(\Recoil\Dev\Instrumentation\Trace::class) ? yield \Recoil\Dev\Instrumentation\Trace::install() : null;
$e = new Exception();
$trace->updateStackTrace($e);
return $e->getTraceAsString();
}
/**
* Replacement for debug_backtrace() PHP function. Returns the current stack as an array
*
* Call as `$backtrace = yield Trace::debug_backtrace();`
*/
public static function debug_backtrace() : \Generator
{
/** @var Trace $trace */
$trace = \class_exists(\Recoil\Dev\Instrumentation\Trace::class) ? yield \Recoil\Dev\Instrumentation\Trace::install() : null;
$e = new Exception();
$trace->updateStackTrace($e);
return $e->getTrace();
}
I'm trying to use this for a Recoil application I'm debugging. It looks super useful! It's just really hard to see where to start. In particular, the "examples" folder is I think out of date, now that the Autoloader gets automatically loaded.
So from what I can see, I'm getting the instrumentation loaded and run (the Autoloader is being called for each application class that is loaded), but I don't know how to get the instrumented stack trace. I'm still getting the default PHP stack trace on an exception.
Any tips how to use this package? A quickstart in the README would be amazing. Happy to write it once I've worked it out myself!
The setting in this variable should override the setting in composer.json.
Perhaps by making recoil/dev
a composer plugin, using the pre-autoload-dump
event?
Allow disabling of instrumentation via the extra
key in composer.json.
@ezzatron has been promoting Kahlan as an alternative to Peridot due to it's wider adoption and likelyhood that it's capable of being extended to run tests as coroutines in much the same way as Peridot.
This doesn't necessitate porting the recoil/dev
's own test suite to Kahlan, but that might also be desirable.
In development mode, it would be useful if strands had some kind of deadlock protection. Some primitives might be:
Kernel::wait()
I'm trying to write PHPUnit tests for classes that contain coroutines, and I'm having trouble getting the coroutines to return the value of the full method instead of the just nested yielded function. I've tried calling current()
on the results, or just putting it in a foreach
loop, but I'm only getting the value of the yielded line inside the method, not the result of the method itself. Are there any examples of how to run unit tests on coroutines without spinning up the Recoil kernel? If I'm not being clear enough let me know and I can post an example.
It might be possible to get a meaningful stack trace using some combination of PHP 7 assert
, debug_backtrace
and __destruct
. Assert would remove the trace in production code, eliminating the overhead. It's not pretty but it's better than nothing.
Some pseudocode:
function trace()
{
$frame = debug_backtrace()[$this_frame - 1];
$strand = yield Recoil::strand();
return new class ($strand)
{
function __construct($strand, $frame) { $strand->pushTrace($frame); }
function __destruct() { $this->strand->popTrace(); }
}
}
Then, in the coroutines you want to trace:
function someCoroutine() : Generator
{
assert($trace = yield trace());
// do work ....
}
For dependencies, there's no reason to instrument code while auto-loading. It could be done at install time instead. The benefits of caching without having to deal with invalidation.
That is:
use Generator as Coroutine;
function a() : Coroutine
{
yield 1;
}
/**
* This function is annotated as coroutine, but is not actually a generator,
* which is probably tripping up the stack trace generator.
*/
function b() : Coroutine
{
return a();
}
FYI @ezzatron
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.