Skip to content

Commit c790bdd

Browse files
committed
Update docs
1 parent 0949008 commit c790bdd

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

README.md

+25-20
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ with some decorating added around the printing.
1212
## Usage
1313

1414
```php
15-
use PhpSchool\PSX\ColorsAdapter;
16-
use PhpSchool\PSX\SyntaxHighlighterConfig;
17-
use Colors\Color;
15+
use PhpSchool\PSX\Factory;
1816

19-
$prettyPrinter = new \PhpSchool\PSX\SyntaxHighlighter(
20-
new SyntaxHighlighterConfig,
21-
new ColorsAdapter(new Color)
22-
);
17+
$highlighterFactory = new Factory;
18+
$highlighter = $highlighterFactory->__invoke();
2319

24-
echo $prettyPrinter->prettyPrint($stmts);
20+
echo $highlighter->highlight($phpCode);
2521
```
2622

2723
The colouring by default uses [kevinlebrun/colors.php](https://github.com/kevinlebrun/colors.php). You can use any library you want
@@ -30,21 +26,29 @@ by building an adapter class which implements `\PhpSchool\PSX\ColourAdapterInter
3026
## Customising Colours
3127

3228
```php
33-
use PhpSchool\PSX\ColorsAdapter;
34-
use PhpSchool\PSX\SyntaxHighlighterConfig;
29+
use PhpParser\ParserFactory;
3530
use Colors\Color;
36-
use PhpSchool\PSX\Colours;
37-
38-
$prettyPrinter = new \PhpSchool\PSX\SyntaxHighlighter(
39-
new SyntaxHighlighterConfig([
40-
SyntaxHighlighterConfig::TYPE_KEYWORD => Colours::GREEN,
41-
SyntaxHighlighterConfig::TYPE_RETURN => Colours::BLACK,
42-
]),
43-
new ColorsAdapter(new Color)
31+
use PhpSchool\PSX\SyntaxHighlighter;
32+
use PhpSchool\PSX\SyntaxHighlightPrinter;
33+
use PhpSchool\PSX\SyntaxHighlighterConfig;
34+
use PhpSchool\PSX\ColorsAdapter;
35+
36+
$parserFactory = new ParserFactory;
37+
$color = new Color;
38+
$color->setForceStyle(true);
39+
$highlighter = new SyntaxHighlighter(
40+
$parserFactory->create(ParserFactory::PREFER_PHP7),
41+
new SyntaxHighlightPrinter(
42+
new SyntaxHighlighterConfig([
43+
SyntaxHighlighterConfig::TYPE_KEYWORD => Colours::GREEN,
44+
SyntaxHighlighterConfig::TYPE_RETURN_NEW => Colours::BLACK,
45+
]),
46+
new ColorsAdapter($color)
47+
)
4448
);
4549
```
4650

47-
This will set any keywords as green and return statements as black.
51+
This will set any keywords as green and return & new statements as black.
4852

4953
## Types
5054

@@ -83,9 +87,10 @@ Every keyword inside each type will be coloured by that colour.
8387

8488
* `echo`
8589

86-
#### TYPE_RETURN
90+
#### TYPE_RETURN_NEW
8791

8892
* `return`
93+
* `new`
8994

9095
#### TYPE_VAR_DEREF
9196

0 commit comments

Comments
 (0)