blade_engine = null; } protected function get_blade(): ?Blade_Engine { if ( false === $this->is_available() ) { return null; } if ( null === $this->blade_engine ) { $this->blade_engine = new Blade_Engine( $this->get_templates_folder(), $this->get_templates_folder() ); } return $this->blade_engine; } /** * @param array $args * @throws Exception */ protected function render( string $template_name, array $args ): string { $blade = $this->get_blade(); if ( null === $blade ) { return ''; } return $blade->render( $template_name, $args ); } protected function get_extension(): string { return 'blade.php'; } protected function get_cache_file( string $unique_id ): string { $templates_folder = $this->get_templates_folder(); // replication of illuminate/View/Compilers/Compiler.php. $hash = hash( 'xxh128', implode( '', array( 'v2', $templates_folder, '/', $unique_id, '.', $this->get_extension() ) ) ); return $templates_folder . '/' . $hash . '.php'; } public function is_available(): bool { // not loaded if PHP < 8.2. return class_exists( Blade_Engine::class ); } }