Skip to content

Commit

Permalink
Merge 31c2564 into 9cfd645
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Jul 7, 2020
2 parents 9cfd645 + 31c2564 commit 9bdb468
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/PreloaderLister.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ class PreloaderLister
*/
public function build() : array
{
// Exclude "$PRELOAD$" phantom file
$scripts = $this->excludePreloadVariable($this->list);

// Exclude the files set by the developer
$scripts = $this->exclude($this->list);
$scripts = $this->exclude($scripts);

// Sort the scripts by hit ratio
$scripts = $this->sortScripts($scripts);
Expand All @@ -64,6 +67,19 @@ public function build() : array
return array_unique($scripts);
}

/**
* Excludes de `$PRELOAD$` file key from the list.
*
* @param array $list
* @return array
*/
protected function excludePreloadVariable(array $list)
{
unset($list['$PRELOAD$']);

return $list;
}

/**
* Retrieve a sorted scripts list used by Opcache.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/PreloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,28 @@ public function test_uses_require_instead_of_compile()
$this->assertStringContainsString('require_once $file', $contents);
}

public function test_excludes_phantom_preload_variable()
{
$this->list['$PRELOAD$'] = [
'full_path' => '$PRELOAD$',
'hits' => 0,
'memory_consumption' => 560,
'last_used' => 'Thu Jan 1 01:00:00 1970',
'last_used_timestamp' => 0,
'timestamp' => 0
];

$this->mockOpcache();

$preloader = new Preloader(new PreloaderCompiler, new PreloaderLister, $this->opcache);

$preloader->writeTo($this->preloaderPath);

$contents = file_get_contents($this->preloaderPath);

$this->assertStringNotContainsString('$PRELOAD$', $contents);
}

public function test_exception_when_autoload_doesnt_exists()
{
$this->expectException(LogicException::class);
Expand Down

0 comments on commit 9bdb468

Please sign in to comment.