From 2e3be43cdac90fbe6824282071fead506763c59f Mon Sep 17 00:00:00 2001 From: Wojciech Kania Date: Sun, 19 Dec 2021 23:22:15 +0100 Subject: [PATCH] enh(php) add PHP constants --- src/languages/php.js | 12 ++++++++++++ test/markup/php/titles.expect.txt | 22 ++++++++++++++++++++++ test/markup/php/titles.txt | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 test/markup/php/titles.expect.txt create mode 100644 test/markup/php/titles.txt diff --git a/src/languages/php.js b/src/languages/php.js index 51fc8e685a..a23b6543c2 100644 --- a/src/languages/php.js +++ b/src/languages/php.js @@ -380,6 +380,18 @@ export default function(hljs) { }, VARIABLE, FUNCTION_INVOKE, + { + match: [ + /const/, + regex.concat(WHITESPACE, "+"), + IDENT_RE, + regex.concat(WHITESPACE, "*="), + ], + scope: { + 1: "keyword", + 3: "variable", + }, + }, { // swallow composed identifiers to avoid parsing them as keywords match: regex.concat( diff --git a/test/markup/php/titles.expect.txt b/test/markup/php/titles.expect.txt new file mode 100644 index 0000000000..03a9daaf19 --- /dev/null +++ b/test/markup/php/titles.expect.txt @@ -0,0 +1,22 @@ +final class Example { + const FOO='foo'; + + public function __construct( + public readonly string $name = self::FOO + ) {} + + public function getClass(): string { + return DateTimeImmutable::class; + } + + public function getClassFromSelf(): string { + return self::class; + } + + public static function getClassFromStatic(): string { + return static::class; + } +} + +$date = DateTimeImmutable::createFromMutable(new \DateTime()); +echo $date::class; diff --git a/test/markup/php/titles.txt b/test/markup/php/titles.txt new file mode 100644 index 0000000000..ffa405fb72 --- /dev/null +++ b/test/markup/php/titles.txt @@ -0,0 +1,22 @@ +final class Example { + const FOO='foo'; + + public function __construct( + public readonly string $name = self::FOO + ) {} + + public function getClass(): string { + return DateTimeImmutable::class; + } + + public function getClassFromSelf(): string { + return self::class; + } + + public static function getClassFromStatic(): string { + return static::class; + } +} + +$date = DateTimeImmutable::createFromMutable(new \DateTime()); +echo $date::class;