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

fix: compile container with version-aware name


Thanks to this, whenever client updates the plugin, cached container is
recompiled. Should we miss that, we might end up in a situation, when
definitions from v1 are used in plugin's v2 and lead to fatal error on
any constructor changes in classes included in container.

Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent b30935d1
Branches
Tags
2 merge requests!5feat: remove compilation command,!4feat: remove compilation command
Pipeline #424899 failed
...@@ -90,16 +90,12 @@ final class Kernel { ...@@ -90,16 +90,12 @@ final class Kernel {
} }
private function get_container_name( Plugin $plugin ): string { private function get_container_name( Plugin $plugin ): string {
return str_replace( '-', '_', $plugin->get_slug() ) . '_container'; return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), 'container' ]) );
} }
private function initialize_container( Plugin $plugin ): Container { private function initialize_container( Plugin $plugin ): Container {
$original_builder = new DiBuilder(); $original_builder = new DiBuilder();
// 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.
//
// On failure, restart container compilation, without cache.
if ( $this->config->get( 'debug', false ) === false ) { if ( $this->config->get( 'debug', false ) === false ) {
$original_builder->enableCompilation( $original_builder->enableCompilation(
$this->get_cache_path(), $this->get_cache_path(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment