1. Go to this page and download the library: Download caseyamcl/sortable-tasks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
useSortableTasks\SortableTask;
abstractclassSetupStepimplementsSortableTask{
abstractpublicfunction__invoke(): bool;
// Provide default implementations of `dependsOn` and `mustRunBefore` that return empty arrayspublicstaticfunctiondependsOn() : iterable{
return [];
}
publicstaticfunctionmustRunBefore() : iterable{
return [];
}
}
classCheckConfigStepextendsSetupStep{
publicstaticfunctiondependsOn(): iterable{
return []; // depends on nothing; can run anytime in the order of operations
}
publicfunction__invoke(): bool{
// do stuff, then..returntrue;
}
}
classCheckDbConnectionStepextendsSetupStep{
private DbConnector $dbConnector;
publicfunction__construct(DbConnector $dbConnector){
$this->dbConnector = $dbConnector;
}
publicstaticfunctiondependsOn(): iterable{
return [CheckConfigStep::class];
}
publicstaticfunctionmustRunBefore(): iterable{
return [BuildContainerStep::class];
}
publicfunction__invoke(): bool{
// do stuff, then..return$this->dbConnector->checkConnection();
}
}
classBuildContainerStepextendsSetupStep{
private ContainerBuilder $containerBuilder;
publicfunction__construct(ContainerBuilder $containerBuilder){
$this->containerBuilder = $containerBuilder;
}
publicstaticfunctiondependsOn(): iterable{
return [CheckConfigStep::class, CheckDbConnection::class];
}
publicfunction__invoke(): bool{
// do stuff, then..return$this->containerBuilder->buildContainer();
}
}
useSortableTasks\SortableTasksIterator;
$iterator = new SortableTasksIterator();
// Notice that it doesn't matter in what order we add the steps; they will get sorted at runtime
$iterator->add(new BuildContainerStep());
$iterator->add(new CheckDbConnectionStep());
$iterator->add(new CheckConfigStep());
// Tasks are sorted upon calling the iterator// Class names are the keysforeach ($iterator as $setupStepClassName => $setupStep) {
if (! $setupStep()->__invoke()) {
thrownew SetupFailedException('Setup failed on step: ' . $setupStepClassName);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.