Skip to content

Commit 4e41355

Browse files
committed
New features: print s(), s(2), many QOL improvements
* `Sage::$outputFile` to write to instead of echo * `print sage();` modifier as shorthand for the above to write to `sage.html` in __DIR__ * `sage(2)` shortcut to print just the files of the backtrace * `sage()` now prints the same info as `microtime()` * Documentation and visual improvements
1 parent 7770ba5 commit 4e41355

File tree

14 files changed

+276
-157
lines changed

14 files changed

+276
-157
lines changed

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ saged($i); // alias for sage();die;
3838
sage(1); // shortcut for dumping trace
3939
```
4040

41-
| Function | Shorthand | |
42-
|-----------|----------------|-------------------|
43-
| `sage` | `s` / `d` | Dump |
44-
| `saged` | `sd` | Dump & die |
45-
| `ssage` | `ss` | Simple dump |
46-
| `ssaged` | `ssd` | Simple dump & die |
47-
| `sage(1)` | `s(1)`/`sd(1)` | Debug backtrace |
41+
| Function | Shorthand | |
42+
|-------------|-----------|--------------------------------------------------|
43+
| `sage` | `s` | Dump (same as `\Sage::dump()`) |
44+
| `saged` | `sd` | Dump & die |
45+
| `ssage` | `ss` | Simple dump |
46+
| `ssaged` | `ssd` | Simple dump & die |
47+
| `sagetrace` | `s(1)` | Debug backtrace (same as `\Sage::trace()`) |
48+
| --- | `s(2)` | Backtrace without the arguments - just the paths |
4849

4950
### Simple dump:
5051

@@ -56,13 +57,20 @@ sage(1); // shortcut for dumping trace
5657

5758
### More cool stuff 🤯
5859

59-
To output plain-text mode (no styling **AT ALL**) prefix with `~`. To return instead of echoing, prefix with `@`:
60+
Sage determines the **passed variable name** and as a side effect can detect all sort of prefixes to the call. Use it
61+
for some common on-the-fly adjustments to the dump output.
62+
63+
Examples:
6064

6165
```php
62-
~s($var); // outputs plain text
63-
$output = @ss(); // returns output
66+
~ss($var); // outputs plain text
67+
$output = @ss($var); // returns output instead of displaying it
68+
print sd($var); // saves output into "sage.html" in the current directory
69+
+sage($var); // ignores depth limit for large objects
6470
```
6571

72+
See [Advanced section](#-advanced-tips--tricks) below for more tricks.
73+
6674
### Verbose versions
6775

6876
If you want to use Sage as part of permanent code (e.g. part of a test helper/logger/exception reporter etc), you can
@@ -295,6 +303,7 @@ ss($GLOBALS, $_SERVER);
295303
// show a trace
296304
Sage::trace();
297305
s(1); // shorthand works too!
306+
s(2); // trace - but just the paths
298307
Sage::dump( debug_backtrace() ); // you can even pass a custom result from debug_trace and it will be recognized
299308

300309
// dump and die debugging
@@ -327,15 +336,16 @@ sd('Get off my lawn!'); // no effect
327336

328337
For customization instructions read the section below.
329338
* If a variable is an object, its classname can be clicked to open the class in your IDE.
330-
* There are a couple of real-time modifiers you can use:
331-
* `~s($var)` this call will output in plain text format.
332-
* `+s($var)` will disregard depth level limits and output everything (careful, this can hang your browser on huge
333-
objects)
334-
* `!s($var)` will show uncollapsed rich output.
335-
* `-s($var)` will attempt to `ob_clean` the previous output - useful when Sage is obscured by already present HTML.
336-
337-
[Here's a little bit](https://stackoverflow.com/a/69890023/179104) on how it works.
338-
339+
* There are several real-time prefix modifiers you can use (combinations possible):
340+
341+
| Prefix | | Example |
342+
|--------|----------------------------------------------|--------------|
343+
| print | Puts output into current DIR as sage.html | print sage() |
344+
| + | Dump ignoring depth limits for large objects | + sage() |
345+
| ~ | Simplifies sage output (rich->html->plain) | ~ sage() |
346+
| - | Clean up any output before dumping | - sage() |
347+
| ! | Expand all nodes (in rich view) | ! sage() |
348+
| @ | Return output instead of displaying it | @ sage() |
339349

340350
* Sage also includes a naïve profiler you may find handy. It's for determining relatively which code blocks take longer
341351
than others:

0 commit comments

Comments
 (0)