From 14b10eea22c8b6427de7f1d851c1f61f5dd27dc1 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Tue, 10 Feb 2026 14:24:19 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20json=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 4 +++- src/File.php | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 124d4e5..7bf752d 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -479,7 +479,9 @@ class Component * @param array $shim */ function addRequireJsPath($name, $path, $shim = null): void { - $this->site->addRequireJsPath($name, $path, $shim); + if ($this->site) { + $this->site->addRequireJsPath($name, $path, $shim); + } } /** diff --git a/src/File.php b/src/File.php index 8ee2eae..5898a83 100644 --- a/src/File.php +++ b/src/File.php @@ -6,14 +6,34 @@ use Exception; class File { /** * @param string $filename - * @return string * @throws Exception */ - static function getContents($filename) { + static function getContents(string $filename): string { $buffer = @file_get_contents($filename); if ($buffer !== false) { return $buffer; } throw new Exception("Unable to read file: " . $filename); } + + + /** + * @param string $filename + * @throws Exception + */ + static function getJson(string $filename, bool|null $associative = null): mixed { + if (!file_exists($filename)) { + return throw new \Exception("File not exist: " . $filename); + } + $json = @file_get_contents($filename); + if ($json === false) { + throw new \Exception("Unable to read file: " . $filename); + } + $file = json_decode($json, $associative); + + if (is_null($file)) { + throw new \Exception("Unable decoding json file: " . $filename); + } + return $file; + } }