Skip to content

Commit

Permalink
fix two instances being created by the container instead of a single …
Browse files Browse the repository at this point in the history
…one when replace_default_engine => true
  • Loading branch information
atanas-dev committed Oct 14, 2018
1 parent 240d47f commit c658efa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $myfilter = new Twig_Filter( 'myfilter', function( $string ) {
return strtoupper( $string );
} );

// WPEmerge::resolve() used for brevity's sake - use a Service Provider instead.
$twig = WPEmerge::resolve( WPEMERGETWIG_VIEW_TWIG_VIEW_ENGINE_KEY );
$twig->environment()->addFilter( $myfilter );
```
Expand Down
4 changes: 3 additions & 1 deletion src/View/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function register( $container ) {
};

if ( $container[ WPEMERGE_CONFIG_KEY ]['twig']['replace_default_engine'] ) {
$container[ WPEMERGE_VIEW_ENGINE_KEY ] = $container->raw( WPEMERGETWIG_VIEW_TWIG_VIEW_ENGINE_KEY );
$container[ WPEMERGE_VIEW_ENGINE_KEY ] = function( $c ) {
return $c[ WPEMERGETWIG_VIEW_TWIG_VIEW_ENGINE_KEY ];
};
}
}

Expand Down

0 comments on commit c658efa

Please sign in to comment.