You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
838 B
29 lines
838 B
<?php
|
|
/** @license MIT
|
|
* Copyright 2021 Dustin Wilson et al.
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
declare(strict_types=1);
|
|
namespace dW\Highlighter\Grammar;
|
|
|
|
class Registry {
|
|
protected static array $grammars = [];
|
|
|
|
public static function add(string $grammarPath): bool {
|
|
if (!file_exists($grammarPath)) {
|
|
throw new \Exception("Path \"$grammarPath\" either does not exist or you do not have permission to view the file.");
|
|
}
|
|
|
|
if (isset(self::$grammars[$grammarPath])) {
|
|
return true;
|
|
}
|
|
|
|
$grammar = json_decode(file_get_contents($grammarPath), true);
|
|
if ($grammar === null) {
|
|
throw new \Exception("\"$grammarPath\" is not a valid grammar file.");
|
|
}
|
|
|
|
self::$grammars[$grammarPath] = $grammar;
|
|
return true;
|
|
}
|
|
}
|