@@ -12,16 +12,12 @@ with some decorating added around the printing.
12
12
## Usage
13
13
14
14
``` php
15
- use PhpSchool\PSX\ColorsAdapter;
16
- use PhpSchool\PSX\SyntaxHighlighterConfig;
17
- use Colors\Color;
15
+ use PhpSchool\PSX\Factory;
18
16
19
- $prettyPrinter = new \PhpSchool\PSX\SyntaxHighlighter(
20
- new SyntaxHighlighterConfig,
21
- new ColorsAdapter(new Color)
22
- );
17
+ $highlighterFactory = new Factory;
18
+ $highlighter = $highlighterFactory->__invoke();
23
19
24
- echo $prettyPrinter->prettyPrint($stmts );
20
+ echo $highlighter->highlight($phpCode );
25
21
```
26
22
27
23
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
30
26
## Customising Colours
31
27
32
28
``` php
33
- use PhpSchool\PSX\ColorsAdapter;
34
- use PhpSchool\PSX\SyntaxHighlighterConfig;
29
+ use PhpParser\ParserFactory;
35
30
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
+ )
44
48
);
45
49
```
46
50
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.
48
52
49
53
## Types
50
54
@@ -83,9 +87,10 @@ Every keyword inside each type will be coloured by that colour.
83
87
84
88
* ` echo `
85
89
86
- #### TYPE_RETURN
90
+ #### TYPE_RETURN_NEW
87
91
88
92
* ` return `
93
+ * ` new `
89
94
90
95
#### TYPE_VAR_DEREF
91
96
0 commit comments