Skip to content

Commit

Permalink
Component: write bootstrap artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Nov 27, 2023
1 parent ef1ab03 commit b5b328a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
!/component/ILIAS

# Generated Files
/artifacts
/ilias.ini.php
/ilias.log
/db_template_writer.php
Expand Down
90 changes: 90 additions & 0 deletions cli/build_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

require_once(__DIR__ . "/../vendor/composer/vendor/autoload.php");

echo <<<INFO
Hello there.
This builds the bootstrap of ILIAS by reading all components and resolving the
dependencies. If you want to use custom directives to resolve ambiguous dependencies,
call this script with a parameter pointing a file defining the resolution.
INFO;

if (isset($argv[1])) {
$resolution_file = $argv[1];
} else {
$resolution_file = realpath(__DIR__ . "/../dependency_resolution.php");
}

if (!file_exists($resolution_file)) {
die("Cannot find resolution file at {$resolution_file}.\n");
}

$reader = new ILIAS\Component\Dependencies\Reader();
$resolver = new ILIAS\Component\Dependencies\Resolver();
$renderer = new ILIAS\Component\Dependencies\Renderer();

$component_info = [];

$vendors = new \DirectoryIterator(realpath(__DIR__ . "/../components"));
echo "Reading Vendors from \"./components\"...\n";
foreach ($vendors as $vendor) {
if (str_starts_with($vendor->getFilename(), ".")) {
continue;
}
if (!$vendor->isDir()) {
echo " unexpected non-directory: {$vendor->getPathName()}\n";
continue;
}
echo " Reading Components from Vendor \"{$vendor->getFilename()}\"...\n";
$components = new \DirectoryIterator($vendor->getPathName());
foreach ($components as $component) {
if (str_starts_with($component->getFilename(), ".")) {
continue;
}
if (!$vendor->isDir()) {
echo " unexpected non-directory: {$component->getPathName()}\n";
continue;
}
if (!file_exists($component->getPathName() . "/Component.php")) {
echo " expected \"Component.php\" in {$component->getPathName()}\n";
continue;
}
require_once($component->getPathName() . "/Component.php");
$component_name = $vendor->getFilename() . "\\" . $component->getFileName();
echo " Reading Component \"$component_name\"...\n";
$component_info[] = $reader->read(new $component_name());
}
}

echo "Resolving Dependency using {$resolution_file}...\n";
$disambiguation = require_once($resolution_file);

$component_info = $resolver->resolveDependencies($disambiguation, ...$component_info);

echo "Writing bootstrap to artifacts/bootstrap.php\n";

$bootstrap = $renderer->render(...$component_info);
if (!is_dir(__DIR__ . "/../artifacts")) {
mkdir(__DIR__ . "/../artifacts", 0755, true);
}
file_put_contents(__DIR__ . "/../artifacts/bootstrap.php", $bootstrap);
1 change: 1 addition & 0 deletions components/ILIAS/App/tests/RootFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class RootFolderTest extends TestCase
'composer.json',
'composer_new.json',
'composer.lock',
'dependency_resolution.php',
'ilias.ini.php',
'ilias_version.php',
'LICENSE',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"scripts": {
"post-autoload-dump": [
"@php cli/build_bootstrap.php",
"@php cli/setup.php build-artifacts --yes"
],
"post-install-cmd": [
Expand Down
16 changes: 16 additions & 0 deletions dependency_resolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// This is the default resolution for ambiguous dependencies of components in
// Standard ILIAS.
//
// The structure is as such: keys are components that use services ("dependant")
// that need disambiguation, the value for each dependant is an array where the key
// is the definition ("dependency") and the value is the implementation
// ("implementation") to be used.
//
// The entry "*" for the dependant will define fallbacks to be used for all components
// that have no explicit disambiguation.

return [
"*" => []
];
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: This might be outdated but should definitely be put in another place.

# Components

Services provide general functionalities used in the modules or in other services,
Expand Down Expand Up @@ -70,4 +72,4 @@ This rules are to be understood according to [RFC2119](https://www.ietf.org/rfc/
14. Libraries SHOULD NOT maintain an implicit internal state. All internal states
SHOULD be made explicit. This means, e.g., that the usage of globals, static
variables and the Singleton-pattern are prohibited.


0 comments on commit b5b328a

Please sign in to comment.