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

feat: improve detection of dev mode


Now, dev mode doesn't have to be explicitly set, only for WordPress,
which has production type defined.

Additionally, allow to build container without using cache, when server
does not support it (i.e. cannot write to the disk).

Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent e4b6d594
No related branches found
No related tags found
1 merge request!5feat: remove compilation command
Pipeline #445898 failed
...@@ -92,10 +92,10 @@ final class Kernel { ...@@ -92,10 +92,10 @@ final class Kernel {
return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), '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, bool $useCache = true ): Container {
$original_builder = new DiBuilder(); $original_builder = new DiBuilder();
if ( $this->config->get( 'debug', false ) === false ) { if ( $this->is_prod() && $useCache ) {
$original_builder->enableCompilation( $original_builder->enableCompilation(
$this->get_cache_path(), $this->get_cache_path(),
$this->get_container_name( $plugin ) $this->get_container_name( $plugin )
...@@ -112,7 +112,11 @@ final class Kernel { ...@@ -112,7 +112,11 @@ final class Kernel {
$extension->build( $builder, $plugin, $this->config ); $extension->build( $builder, $plugin, $this->config );
} }
try {
return $builder->build(); return $builder->build();
} catch ( \Exception $e ) {
return $this->initialize_container( $plugin, false );
}
} }
private function prepare_driver( ContainerInterface $container ): HookDriver { private function prepare_driver( ContainerInterface $container ): HookDriver {
...@@ -125,7 +129,7 @@ final class Kernel { ...@@ -125,7 +129,7 @@ final class Kernel {
new ClusteredLoader( $loader ) new ClusteredLoader( $loader )
); );
if ( $this->config->get( 'debug', false ) ) { if ( $this->is_dev() ) {
$loader = new DebugBindingLoader( $loader ); $loader = new DebugBindingLoader( $loader );
} }
...@@ -146,4 +150,12 @@ final class Kernel { ...@@ -146,4 +150,12 @@ final class Kernel {
return $driver; return $driver;
} }
private function is_dev(): bool {
return $this->config->get( 'debug', false ) || wp_get_environment_type() !== 'development';
}
private function is_prod(): bool {
return $this->is_dev() === false;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment