Skip to content

Commit

Permalink
Performance optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
rawsrc committed Apr 6, 2020
1 parent 5183b68 commit 0e26e81
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions PhpEcho.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function setCode(string $code)
public function __invoke(string $helper, ...$args)
{
if ($helper !== '') {
if ( ! self::isHelper($helper)) {
if ( ! empty(self::$helpers_file_to_inject)) {
self::injectHelpers();
}
if (self::isHelper($helper)) {
Expand Down Expand Up @@ -260,6 +260,10 @@ public function __toString()
* @var array [helper's name => [type]]
*/
private static $helpers_types = [];
/**
* @var array [helpers filepath to inject]
*/
private static $helpers_file_to_inject = [];

/**
* @param string $name
Expand Down Expand Up @@ -306,7 +310,8 @@ public static function addPathToHelperFile(string ...$path)
{
foreach ($path as $p) {
if ( ! isset(self::$helpers_file_path[$p])) {
self::$helpers_file_path[$p] = true;
self::$helpers_file_path[$p] = true;
self::$helpers_file_to_inject[] = $p;
}
}
}
Expand All @@ -316,12 +321,12 @@ public static function addPathToHelperFile(string ...$path)
*/
public static function injectHelpers()
{
foreach (self::$helpers_file_path as $path => &$to_inject) {
if ($to_inject && is_file($path)) {
foreach (self::$helpers_file_to_inject as $path) {
if (is_file($path)) {
self::addHelpers(include $path);
$to_inject = false;
}
}
self::$helpers_file_to_inject = [];
}

/**
Expand Down

0 comments on commit 0e26e81

Please sign in to comment.