Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • v0.10
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.10.3
  • 0.10.4
  • 0.10.5
  • 0.10.6
  • 0.9.0
  • 0.9.1
11 results

Target

Select target project
  • wpdesk/wp-init
1 result
Select Git revision
  • main
  • v0.10
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.10.3
  • 0.10.4
  • 0.10.5
  • 0.10.6
  • 0.9.0
  • 0.9.1
11 results
Show changes
Commits on Source (3)
  • Bartek Jaskulski's avatar
    Revert "feat: WordPress 6.7 compatibility change" · 9b6a1708
    Bartek Jaskulski authored
    This reverts commit fa051ae0.
    
    This commit was wrong, as translation files may be registered at
    `plugins_loaded`, it's the i18n functions (e.g. `__`) that should be
    deferred after `init` hook.
    Verified
    9b6a1708
  • Bartek Jaskulski's avatar
    fix: improve the work of stoppable binder · e4b6d594
    Bartek Jaskulski authored
    
    Previously stoppable binder was working for all binders, although it
    only supported to signal stop execution with class-based binders. This
    changes the behavior, as having all binders wrapped in stoppable binder
    resulted in execution of all collection binders, without regard for the
    stop signal.
    
    This is convoluted and gets even worse, so this part of the API should
    be rewritten. The side effect of this change is that any callable based
    binder (e.g. database migrations) will not be stopped, no matter what
    happens. This is a serious quirk, and may be better to remove other
    kinds of binders than hookable or rethink the stoppable binder.
    
    Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
    Verified
    e4b6d594
  • Bartek Jaskulski's avatar
    feat: improve detection of dev mode · c2d6fbc5
    Bartek Jaskulski authored
    
    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>
    Verified
    c2d6fbc5
......@@ -9,7 +9,6 @@ use WPDesk\Init\Binding\ComposableBinder;
use WPDesk\Init\Binding\StoppableBinder as Stop;
use WPDesk\Init\Binding\Definition;
use WPDesk\Init\Binding\Binder as BinderInstance;
use WPDesk\Init\Binding\Definition\HookableDefinition;
class StoppableBinder implements ComposableBinder {
......
......@@ -14,7 +14,11 @@ class I18n implements Hookable {
}
public function hooks(): void {
add_action( 'init', $this );
if ( did_action( 'plugins_loaded' ) ) {
$this->__invoke();
} else {
add_action( 'plugins_loaded', $this );
}
}
public function __invoke(): void {
......
......@@ -7,7 +7,6 @@ use DI\Container;
use DI\ContainerBuilder as DiBuilder;
use Psr\Container\ContainerInterface;
use WPDesk\Init\Binding\Binder\CallableBinder;
use WPDesk\Init\Binding\Binder\CollectionBinder;
use WPDesk\Init\Binding\Binder\CompositeBinder;
use WPDesk\Init\Binding\Binder\HookableBinder;
use WPDesk\Init\Binding\Binder\StoppableBinder;
......@@ -93,10 +92,10 @@ final class Kernel {
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();
if ( $this->config->get( 'debug', false ) === false ) {
if ( $this->is_prod() && $useCache ) {
$original_builder->enableCompilation(
$this->get_cache_path(),
$this->get_container_name( $plugin )
......@@ -113,7 +112,11 @@ final class Kernel {
$extension->build( $builder, $plugin, $this->config );
}
try {
return $builder->build();
} catch ( \Exception $e ) {
return $this->initialize_container( $plugin, false );
}
}
private function prepare_driver( ContainerInterface $container ): HookDriver {
......@@ -126,18 +129,15 @@ final class Kernel {
new ClusteredLoader( $loader )
);
if ( $this->config->get( 'debug', false ) ) {
if ( $this->is_dev() ) {
$loader = new DebugBindingLoader( $loader );
}
$driver = new GenericDriver(
$loader,
new StoppableBinder(
new CompositeBinder(
new HookableBinder( $container ),
new StoppableBinder( new HookableBinder( $container ), $container ),
new CallableBinder( $container )
),
$container
)
);
......@@ -150,4 +150,12 @@ final class Kernel {
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;
}
}