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

refactor: minor fixes and improvements

parent a72ecab5
No related branches found
No related tags found
2 merge requests!3improve into wp-hook and some additional unfinished things,!21.x
...@@ -4,9 +4,7 @@ declare( strict_types=1 ); ...@@ -4,9 +4,7 @@ declare( strict_types=1 );
namespace WPDesk\Init\Binding\Loader; namespace WPDesk\Init\Binding\Loader;
use WPDesk\Init\Binding\DefinitionFactory; use WPDesk\Init\Binding\DefinitionFactory;
use WPDesk\Init\Plugin\Plugin;
use WPDesk\Init\Util\Path; use WPDesk\Init\Util\Path;
use WPDesk\Init\Configuration\ReadableConfig;
use WPDesk\Init\Loader\PhpFileLoader; use WPDesk\Init\Loader\PhpFileLoader;
class DirectoryBasedLoader implements BindingDefinitions { class DirectoryBasedLoader implements BindingDefinitions {
...@@ -20,10 +18,10 @@ class DirectoryBasedLoader implements BindingDefinitions { ...@@ -20,10 +18,10 @@ class DirectoryBasedLoader implements BindingDefinitions {
/** @var DefinitionFactory */ /** @var DefinitionFactory */
private $def_factory; private $def_factory;
public function __construct( $path, PhpFileLoader $loader, DefinitionFactory $def_factory ) { public function __construct( $path, ?PhpFileLoader $loader = null, ?DefinitionFactory $def_factory = null ) {
$this->path = new Path( (string) $path ); $this->path = new Path( (string) $path );
$this->loader = $loader; $this->loader = $loader ?? new PhpFileLoader();
$this->def_factory = $def_factory; $this->def_factory = $def_factory ?? new DefinitionFactory();
} }
public function load(): iterable { public function load(): iterable {
...@@ -47,6 +45,6 @@ class DirectoryBasedLoader implements BindingDefinitions { ...@@ -47,6 +45,6 @@ class DirectoryBasedLoader implements BindingDefinitions {
$hooks = [ $filename->get_filename_without_extension() => $hooks ]; $hooks = [ $filename->get_filename_without_extension() => $hooks ];
} }
yield from (new ArrayBindingLoader( $hooks, $this->def_factory ))->load(); yield from (new ArrayBindingLoader( $hooks ) )->load();
} }
} }
...@@ -8,7 +8,7 @@ use WPDesk\Init\Binding\Loader\BindingDefinitions; ...@@ -8,7 +8,7 @@ use WPDesk\Init\Binding\Loader\BindingDefinitions;
class GenericDriver implements HookDriver { class GenericDriver implements HookDriver {
/** @var BindingDefinitionLoader */ /** @var BindingDefinitions */
private $definitions; private $definitions;
/** @var Binder */ /** @var Binder */
......
...@@ -11,7 +11,6 @@ class PhpFileLoader { ...@@ -11,7 +11,6 @@ class PhpFileLoader {
* @return mixed * @return mixed
*/ */
public function load( $resource ) { public function load( $resource ) {
// TODO: add file locator
return ( static function () use ( $resource ) { return ( static function () use ( $resource ) {
if ( ! is_readable( (string) $resource ) ) { if ( ! is_readable( (string) $resource ) ) {
throw new \RuntimeException( "Could not load $resource" ); throw new \RuntimeException( "Could not load $resource" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment