Skip to content

Commit

Permalink
Boot finder only if needed.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Mar 22, 2020
1 parent 6e7c422 commit f680961
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Finder.php
Expand Up @@ -7,6 +7,13 @@

abstract class Finder implements ArrayAccess
{
/**
* Indicates if the finder has "booted".
*
* @var bool
*/
protected $booted = false;

/**
* List of projects.
*
Expand All @@ -31,6 +38,28 @@ final public function register(
return $this;
}

/**
* Boot the finder.
*/
public function boot(): void
{
//
}

/**
* Check if the finder needs to be booted and if so, do it.
*
* @return void
*/
protected function bootIfNotBooted(): void
{
if (! $this->booted) {
$this->boot();
}

$this->booted = true;
}

/**
* Determine if the given offset exists.
*
Expand All @@ -40,6 +69,8 @@ final public function register(
*/
public function offsetExists($offset)
{
$this->bootIfNotBooted();

return isset($this->projects[$offset]);
}

Expand All @@ -52,6 +83,8 @@ public function offsetExists($offset)
*/
public function offsetGet($offset)
{
$this->bootIfNotBooted();

return $this->projects[$offset];
}

Expand Down Expand Up @@ -80,6 +113,8 @@ public function offsetSet($offset, $value)
*/
public function offsetUnset($offset)
{
$this->bootIfNotBooted();

unset($this->projects[$offset]);
}
}

0 comments on commit f680961

Please sign in to comment.