Skip to content
Snippets Groups Projects
Verified Commit fee1879b authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

feat: allow to compile cache in working environment

parent 57f2cb77
No related branches found
No related tags found
2 merge requests!5feat: remove compilation command,!4feat: remove compilation command
......@@ -22,6 +22,7 @@ use WPDesk\Init\HookDriver\CompositeDriver;
use WPDesk\Init\HookDriver\GenericDriver;
use WPDesk\Init\HookDriver\HookDriver;
use WPDesk\Init\HookDriver\LegacyDriver;
use WPDesk\Init\Util\PhpFileDumper;
use WPDesk\Init\Util\PhpFileLoader;
use WPDesk\Init\Plugin\Header;
use WPDesk\Init\Util\Path;
......@@ -46,6 +47,8 @@ final class Kernel {
/** @var ExtensionsSet */
private $extensions;
private PhpFileDumper $dumper;
public function __construct(
string $filename,
Configuration $config,
......@@ -56,6 +59,7 @@ final class Kernel {
$this->extensions = $extensions;
$this->loader = new PhpFileLoader();
$this->parser = new DefaultHeaderParser();
$this->dumper = new PhpFileDumper();
}
public function boot(): void {
......@@ -63,11 +67,16 @@ final class Kernel {
try {
$plugin_data = $this->loader->load( $cache_path );
} catch ( \Exception $e ) {
// If cache not found, load data from memory.
// Avoid writing files on host environment.
// Generate cache with command instead.
try {
$this->dumper->dump(
$this->parser->parse( $this->filename ),
$cache_path
);
$plugin_data = $this->loader->load( $cache_path );
} catch ( \Exception $e ) {
$plugin_data = $this->parser->parse( $this->filename );
}
}
$plugin = new Plugin( $this->filename, new Header( $plugin_data ) );
......@@ -93,12 +102,13 @@ final class Kernel {
// If there's a cache file, use it as we are in production environment.
// Otherwise, build the container from scratch and use live version, without compilation.
if ( file_exists( $this->get_cache_path( $this->get_container_name( $plugin ) . '.php' ) ) ) {
//
// On failure, restart container compilation, without cache.
if ( $this->config->get( 'debug', false ) === false ) {
$original_builder->enableCompilation(
$this->get_cache_path(),
$this->get_container_name( $plugin )
);
return $original_builder->build();
}
$builder = new ContainerBuilder( $original_builder );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment