Skip to content

Commit a0d1b09

Browse files
committed
php 8.1 support
1 parent 5a6b1b4 commit a0d1b09

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ echo '<pre>', (new Highlight)
3535
```
3636

3737
![alt tag](https://github.com/Ghostff/php_prettify/blob/master/images/dark.png)
38-
![alt tag](https://github.com/Ghostff/php_prettify/blob/master/images/light.png)

code.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Text;
5-
use PhpPrettify as Php;
4+
namespace DateTime as Date;
65

76
#[AttrCommas('foo'), AttrCommas(2342)]
8-
class Text extends Namespace\TextProcess implements Php
7+
class Text extends Namespace\TextProcess implements RandomInterface
98
{
109
/**
1110
* An array of the types that have been resolved.
1211
*
1312
* @var array
1413
*/
1514
protected $resolved = array();
15+
protected readonly DateTime $date;
1616

1717
public function isShared(#[Attr('foo')] string $abstract, int &$counter): bool
1818
{
@@ -28,7 +28,7 @@ class Text extends Namespace\TextProcess implements Php
2828
$shared = false;
2929
}
3030

31-
#smart function type dictation
31+
#function type dictation
3232
self::hash(hash('sha1', 'foobar'), $this->hash());
3333
return (isset($this->instances[$abstract]) || $shared === true);
3434
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.4"
18+
"php": ">=8.0"
1919
}
2020
}

images/dark.png

3.88 KB
Loading

index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
(new ghostff\Highlight\Highlight())
77
->setTheme('bittr') // Sets code highlight theme.
88
->setStyle('body {margin:0;padding:0}') // Append css to default to style.
9-
->setHighlight(22, ['style' => 'color:red']) // Add html attributes to selected line(tr).
10-
->showLineNumber(1, false) // Show line number starting from line 1 and prevent selection of line number.
9+
// ->setHighlight(22, ['style' => 'color:red']) // Add html attributes to selected line(tr).
10+
// ->showLineNumber(1, false) // Show line number starting from line 1 and prevent selection of line number.
1111
->render('code.txt', true),
1212
'</pre>';
1313

src/Highlight.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Highlight
2828
private string $constant = 'color:#8C4D03';
2929
private string $tag_close = 'color:#F00000';
3030
private string $operators = 'color:#0000FF';
31-
private string $semi_colon = 'color:#000000';
3231
private string $parenthesis = 'color:#038C8C';
3332
private string $return_type = 'color:#E3093F';
3433
private string $php_function = 'color:#6367A7';
@@ -60,15 +59,14 @@ class Highlight
6059
(i(f|mplements|n(clude(_once)?|st(anceof|eadof)|terface)|sset))|
6160
(n(amespace|ew))|
6261
(p(r(i(nt|vate)|otected)|ublic))|
63-
(re(quire(_once)?|turn))|
62+
(re(quire(_once)?|turn|adonly))|
6463
(s(tatic|witch))|
6564
(t(hrow|r(ait|y)))|
6665
(u(nset(?!\s*\))|se))|
6766
(__halt_compiler|break|list|(x)?or|var|while|match))\b/';
6867
private string $operators_ptrn = '/((?<! (style|class))\=|\.|\!|\+|\%|-(?!\w+:)|(?<!https|http)[^a-z+]:|\@|\||\?|&gt;|&lt;|&amp;)/';
69-
private string $semi_colon_ptrn = '/(?<![&lt|&gt|&amp]);/';
7068
private string $parenthesis_ptrn = '/\(|\)/';
71-
private string $return_type_ptrn = '/(?<=\<\/span\>\:|\:\<\/span\>)\s*(?:\<span.*?\>\:<span>)*(string|bool|array|float|int|callable|void)/';
69+
private string $return_type_ptrn = '/(?<=\<\/span\>\:|\:\<\/span\>)\s*(?:\<span.*?\>\:<span>)*(string|bool|array|float|int|callable|void|never)/';
7270
private string $curly_braces_ptrn = '/[\{\}]/';
7371
private string $parameter_type_ptrn = '/(?<!\w)(string|bool|array|float|int|callable)\s*(?=\<span.*?class="(variable|operators)"\>[\$|&amp;])/';
7472
private string $square_bracket_ptrn = '/\[|\]/';
@@ -125,12 +123,11 @@ private function format(string $code, ?string $file_name, bool $cache): string
125123

126124
while ($token !== false)
127125
{
128-
$value = rtrim($token, PHP_EOL);
129-
if ($value == '') {
130-
$value = ' ';
126+
$line = rtrim($token, PHP_EOL);
127+
if ($line == '') {
128+
$line = ' ';
131129
}
132130

133-
$line = preg_replace($this->semi_colon_ptrn, "<span style=\"{$this->semi_colon}\" class=\"semi_colon\">\$0</span>", $value);
134131
$gui_line_number = $this->show_line_number ? "<td" . ($this->line_selectable ? '' : ' unselectable="on"') . ">{$start_number}</td><td>" : '<td>';
135132

136133
if (isset($this->highlight[$start_number]))

0 commit comments

Comments
 (0)