From 8477cbe90e8b6ed08e9fe6dbbf5de69fd93fa669 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 29 Jul 2020 21:49:49 +0200 Subject: [PATCH] Add invalidation functionality --- Autoloader.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Autoloader.php b/Autoloader.php index f467c0d3a..5dbe733a1 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -112,4 +112,30 @@ final class Autoloader return false; } + + /** + * Invalidate a already loaded file + * + * IMPORTANT: This does not reload an already loaded file + * + * @param string $class Class to invalidate + * + * @return bool + * + * @since 1.0.0 + * @todo Find a way to re-load aready loaded files. This can be important for changed scripts + */ + public static function invalidate(string $class) : bool + { + if (!\extension_loaded('opcache') + || !\opcache_is_script_cached(__DIR__ . '/../../Models/NewsArticleMapper.php') + ) { + return false; + } + + \opcache_invalidate(__DIR__ . '/../../Models/NewsArticleMapper.php'); + \opcache_compile_file(__DIR__ . '/../../Models/NewsArticleMapper.php'); + + return true; + } }