Skip to content

Commit

Permalink
Setup: begin impl in new component framework
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Jan 19, 2024
1 parent 0da1d1a commit dac9cab
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 183 deletions.
180 changes: 19 additions & 161 deletions cli/setup.php
Original file line number Diff line number Diff line change
@@ -1,162 +1,20 @@
<?php

declare(strict_types=1);

/* Copyright (c) 2019 Richard Klees <[email protected]> Extended GPL, see docs/LICENSE */

$executed_in_directory = getcwd();
chdir(__DIR__ . "/..");

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

require_once(__DIR__ . "/../ilias_version.php");

// according to ./Services/Feeds/classes/class.ilExternalFeed.php:
if (!defined("MAGPIE_DIR")) {
define("MAGPIE_DIR", "./components/ILIAS/Feeds/magpierss/");
}

require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupAgent.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupConfig.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilMakeInstallationAccessibleObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilUseRootConfirmed.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilOwnRiskConfirmedObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilOverwritesExistingInstallationConfirmed.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilIniFilesPopulatedObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilIniFilesLoadedObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilNICKeyRegisteredObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilNICKeyStoredObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupConfigStoredObjective.php");
require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupMetricsCollectedObjective.php");

use ILIAS\UI\Component\Input\Field\Factory as FieldFactory;
use ILIAS\UI\Component\Input\Field\File;
use ILIAS\UI\Component\Input\Field\Tag;
use ILIAS\UI\Component\Input\Field\UploadHandler;

$c = build_container_for_setup($executed_in_directory);
$app = $c["app"];
$app->run();

// ATTENTION: This is a hack to get around the usage of the echo/exit pattern in
// the setup for the command line version of the setup. Do not use this.
function setup_exit($message)
{
if (!defined("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES") || !ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES) {
throw new \ILIAS\Setup\UnachievableException($message);
}
}

function build_container_for_setup(string $executed_in_directory): \Pimple\Container
{
$c = new \Pimple\Container();

$c["app"] = function ($c) {
return new \ILIAS\Setup\CLI\App(
$c["command.install"],
$c["command.update"],
$c["command.build-artifacts"],
$c["command.achieve"],
$c["command.status"],
$c["command.migrate"]
);
};
$c["command.install"] = function ($c) {
return new \ILIAS\Setup\CLI\InstallCommand(
$c["agent_finder"],
$c["config_reader"],
$c["common_preconditions"]
);
};
$c["command.update"] = function ($c) {
return new \ILIAS\Setup\CLI\UpdateCommand(
$c["agent_finder"],
$c["config_reader"],
$c["common_preconditions"]
);
};
$c["command.build-artifacts"] = function ($c) {
return new \ILIAS\Setup\CLI\BuildArtifactsCommand(
$c["agent_finder"]
);
};
$c["command.achieve"] = function ($c) {
return new \ILIAS\Setup\CLI\AchieveCommand(
$c["agent_finder"],
$c["config_reader"],
$c["common_preconditions"],
$c["refinery"]
);
};
$c["command.status"] = function ($c) {
return new \ILIAS\Setup\CLI\StatusCommand(
$c["agent_finder"]
);
};

$c["command.migrate"] = function ($c) {
return new \ILIAS\Setup\CLI\MigrateCommand(
$c["agent_finder"],
$c["common_preconditions"]
);
};

$c["common_preconditions"] = function ($c) {
return [
new \ilOwnRiskConfirmedObjective(),
new \ilUseRootConfirmed()
];
};

$c["common_agent"] = function ($c) {
return new \ilSetupAgent(
$c["refinery"],
$c["data_factory"]
);
};

$c["agent_finder"] = function ($c) {
return new ILIAS\Setup\ImplementationOfAgentFinder(
$c["refinery"],
$c["data_factory"],
$c["lng"],
$c["interface_finder"],
[
"common" => $c["common_agent"]
]
);
};

$c["refinery"] = function ($c) {
return new ILIAS\Refinery\Factory(
$c["data_factory"],
$c["lng"]
);
};

$c["data_factory"] = function ($c) {
return new ILIAS\Data\Factory();
};

$c["lng"] = function ($c) {
return new \ilSetupLanguage("en");
};

$c["config_reader"] = function ($c) use ($executed_in_directory) {
return new \ILIAS\Setup\CLI\ConfigReader(
$c["json.parser"],
$executed_in_directory
);
};

$c["interface_finder"] = function ($c) {
return new \ILIAS\Setup\ImplementationOfInterfaceFinder();
};

$c["json.parser"] = function ($c) {
return new \Seld\JsonLint\JsonParser();
};

return $c;
}
/**
* 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
*
*********************************************************************/

require_once(__DIR__ . "/../artifacts/bootstrap.php");

exit(entry_point("The ILIAS Setup"));
79 changes: 78 additions & 1 deletion components/ILIAS/Setup/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace ILIAS;

use ILIAS\Component\EntryPoint;

class Setup implements Component\Component
{
public function init(
Expand All @@ -32,6 +34,81 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[EntryPoint::class] = fn() =>
new \ILIAS\Setup\CLI\App(
$internal["command.install"],
$internal["command.update"],
$internal["command.build-artifacts"],
$internal["command.achieve"],
$internal["command.status"],
$internal["command.migrate"]
);

$internal["command.install"] = fn() =>
new \ILIAS\Setup\CLI\InstallCommand(
$internal["agent_finder"],
$internal["config_reader"],
$internal["common_preconditions"]
);
$internal["command.update"] = fn() =>
new \ILIAS\Setup\CLI\UpdateCommand(
$internal["agent_finder"],
$internal["config_reader"],
$internal["common_preconditions"]
);
$internal["command.build-artifacts"] = fn() =>
new \ILIAS\Setup\CLI\BuildArtifactsCommand(
$internal["agent_finder"]
);
$internal["command.achieve"] = fn() =>
new \ILIAS\Setup\CLI\AchieveCommand(
$internal["agent_finder"],
$internal["config_reader"],
$internal["common_preconditions"],
$pull[\ILIAS\Refinery\Factory::class],
);
$internal["command.status"] = fn() =>
new \ILIAS\Setup\CLI\StatusCommand(
$internal["agent_finder"]
);
$internal["command.migrate"] = fn() =>
new \ILIAS\Setup\CLI\MigrateCommand(
$internal["agent_finder"],
$internal["common_preconditions"]
);

$internal["common_preconditions"] = fn() =>
[
new \ilOwnRiskConfirmedObjective(),
new \ilUseRootConfirmed()
];

$internal["common_agent"] = fn() =>
new \ilSetupAgent(
$pull[\ILIAS\Refinery\Factory::class],
$pull[\ILIAS\Data\Factory::class]
);

$internal["agent_finder"] = fn() =>
new \ILIAS\Setup\ImplementationOfAgentFinder(
$pull[\ILIAS\Refinery\Factory::class],
$pull[\ILIAS\Data\Factory::class],
$use[\ILIAS\Language\Language::class],
$internal["interface_finder"],
[
"common" => $internal["common_agent"]
]
);

$internal["config_reader"] = fn() =>
new \ILIAS\Setup\CLI\ConfigReader(
$internal["json.parser"]
);

$internal["interface_finder"] = fn() =>
new \ILIAS\Setup\ImplementationOfInterfaceFinder();

$internal["json.parser"] = fn() =>
new \Seld\JsonLint\JsonParser();
}
}
19 changes: 16 additions & 3 deletions components/ILIAS/Setup/src/CLI/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,34 @@

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use ILIAS\Component\Component;
use ILIAS\Component\EntryPoint;

/**
* The ILIAS-setup-console-application.
*
* TODO: Add some metainformation to the app, such as name.
*/
class App extends Application
class App extends Application implements EntryPoint
{
public const NAME = "The ILIAS Setup";

public function __construct(Command ...$commands)
{
public function __construct(
Command ...$commands
) {
parent::__construct(self::NAME);
foreach ($commands as $c) {
$this->add($c);
}
}

public function getName(): string
{
return self::NAME;
}

public function enter(): int
{
return $this->run();
}
}
22 changes: 5 additions & 17 deletions components/ILIAS/Setup/src/ImplementationOfAgentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,16 @@

class ImplementationOfAgentFinder implements AgentFinder
{
protected Refinery $refinery;
protected Data\Factory $data_factory;
protected \ilSetupLanguage $lng;
protected ImplementationOfInterfaceFinder $interface_finder;

protected array $predefined_agents;

/**
* @var array<string, Agent> $predefined_agents
*/
public function __construct(
Refinery $refinery,
Data\Factory $data_factory,
\ilSetupLanguage $lng,
ImplementationOfInterfaceFinder $interface_finder,
array $predefined_agents = []
protected Refinery $refinery,
protected Data\Factory $data_factory,
protected \ILIAS\Language\Language $lng,
protected ImplementationOfInterfaceFinder $interface_finder,
protected array $predefined_agents = []
) {
$this->refinery = $refinery;
$this->data_factory = $data_factory;
$this->lng = $lng;
$this->interface_finder = $interface_finder;
$this->predefined_agents = $predefined_agents;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion dependency_resolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
// that have no explicit disambiguation.

return [
"*" => []
"*" => [
"\\ILIAS\Language\Language" => "ilSetupLanguage"
],
"\\ILIAS\\Refinery" => [
"\\ILIAS\Language\Language" => "myLanguage"
]
];

0 comments on commit dac9cab

Please sign in to comment.