for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace kalanis\kw_afterload;
/**
* Class Afterload
* @package kalanis\kw_afterload
* Process all prepared files with settings in specified directory
* Because Bootstrap is too static
*
* - list all files in datadir
* - order them by their names
* - process them one-by-one
*/
class Afterload
{
* @param string[] $path
public static function run(array $path): void
$self = new static();
$self->process($path);
}
final public function __construct()
* @throws AfterloadException
public function process(array $path): void
$exception = null;
$files = $this->listFiles($path);
sort($files);
foreach ($files as $file) {
try {
require_once $file;
} catch (AfterloadException $ex) {
$exception = $ex->addPrev($exception);
if (!empty($exception)) {
throw $exception;
* @param string[] $passedPath
* @return array<string> array of paths
protected function listFiles(array $passedPath): array
$path = realpath(implode(DIRECTORY_SEPARATOR, $passedPath));
if (!$path) {
return [];
$available = [];
$files = scandir($path);
if (false !== $files) {
if (
is_file($path . DIRECTORY_SEPARATOR . $file)
&& strpos($file, '.php')
) {
$available[] = $path . DIRECTORY_SEPARATOR . $file;
return $available;