Skip to content

Commit

Permalink
Component: build public resources (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Feb 6, 2024
1 parent cf366c0 commit 2544df9
Show file tree
Hide file tree
Showing 596 changed files with 596 additions and 54,371 deletions.
3 changes: 2 additions & 1 deletion components/ILIAS/Accordion/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJSResource($this, "accordion.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static function addCss(): void
public static function getLocalJavascriptFiles(): array
{
return array(
"./components/ILIAS/Accordion/js/accordion.js",
"./js/accordion.js",
self::$owl_path . self::$owl_js_path
);
}
Expand Down
3 changes: 3 additions & 0 deletions components/ILIAS/Calendar/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ public function init(
new \ilCalendarSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "calendar.php");
}
}
File renamed without changes.
6 changes: 5 additions & 1 deletion components/ILIAS/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public function init(

$contribute[\ILIAS\Setup\Agent::class] = fn() =>
new \ilComponentsSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
$internal[Component\Resource\PublicAssetManager::class],
$seek[Component\Resource\PublicAsset::class]
);

$internal[Component\Resource\PublicAssetManager::class] = fn() =>
new Component\Resource\PublicAssetManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@

use ILIAS\Setup;
use ILIAS\Refinery\Transformation;
use ILIAS\Component\Resource\PublicAssetManager;
use ILIAS\Component\Setup\PublicAssetsBuildObjective;

class ilComponentsSetupAgent implements Setup\Agent
{
use Setup\Agent\HasNoNamedObjective;

public function __construct(
protected PublicAssetManager $public_asset_manager,
protected array $public_assets
) {
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -70,10 +78,18 @@ public function getUpdateObjective(Setup\Config $config = null): Setup\Objective
public function getBuildObjective(): Setup\Objective
{
return new Setup\ObjectiveCollection(
"Artifacts for Services/Component",
"Build Objectives of \\ILIAS\\Component",
false,
new ilComponentBuildComponentInfoObjective(),
new ilComponentBuildPluginInfoObjective()
new Setup\ObjectiveCollection(
"Artifacts for \\ILIAS\\Component",
false,
new ilComponentBuildComponentInfoObjective(),
new ilComponentBuildPluginInfoObjective()
),
new PublicAssetsBuildObjective(
$this->public_asset_manager,
$this->public_assets
)
);
}

Expand Down
29 changes: 16 additions & 13 deletions public/saml.php → ...nent/src/Resource/ComponentJSResource.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -16,18 +18,19 @@
*
*********************************************************************/

declare(strict_types=1);
namespace ILIAS\Component\Resource;

if (!file_exists(getcwd() . '/ilias.ini.php')) {
exit();
/**
* An public asset is a file or folder that should be served via the web.
*/
class ComponentJSResource extends ComponentResource
{
public function __construct(
// the component this belongs to
\ILIAS\Component\Component $component,
// path relative to the components resource directory
string $source,
) {
parent::__construct($component, $source, "assets/js");
}
}

ilContext::init(ilContext::CONTEXT_SAML);

ilInitialisation::initILIAS();

/** @var ILIAS\DI\Container $DIC */
$DIC->ctrl()->setTargetScript('ilias.php');
// @todo: removed deprecated ilCtrl methods, this needs inspection by a maintainer.
// $DIC->ctrl()->setCmd('doSamlAuthentication');
$DIC->ctrl()->callBaseClass(ilStartUpGUI::class);
67 changes: 67 additions & 0 deletions components/ILIAS/Component/src/Resource/ComponentResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

/**
* 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
*
*********************************************************************/

namespace ILIAS\Component\Resource;

/**
* An public asset is a file or folder that should be served via the web.
*/
class ComponentResource implements PublicAsset
{
public const REGEXP_SOURCE = '%^((\w+(/\w+)*\.\w{2,4})|(\.htaccess))$%';
public const REGEXP_TARGET = '%^((\w+(/\w+)*)|[.])$%';

public function __construct(
// the component this belongs to
protected \ILIAS\Component\Component $component,
// path relative to the components resource directory
protected string $source,
// path relative to the ILIAS public directory, filename of resource will be appended
// use one dot for toplevel
protected string $target,
) {
if (!preg_match(self::REGEXP_SOURCE, $this->source)) {
throw new \InvalidArgumentException(
"'{$this->source}' is not a valid source path for a public asset."
);
}
if (!preg_match(self::REGEXP_TARGET, $this->target)) {
throw new \InvalidArgumentException(
"'{$this->target}' is not a valid target path for a public asset."
);
}
}

public function getSource(): string
{
list($vendor, $component) = explode("\\", get_class($this->component));

return "components/$vendor/$component/resources/{$this->source}";
}

public function getTarget(): string
{
$source = explode("/", $this->source);
if ($this->target === ".") {
return array_pop($source);
}
return $this->target . "/" . array_pop($source);
}
}
38 changes: 38 additions & 0 deletions components/ILIAS/Component/src/Resource/Endpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* 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
*
*********************************************************************/

namespace ILIAS\Component\Resource;

/**
* An endpoint is a PHP file that produces output via HTTP. These will be located
* on the toplevel of the public folder. Fall back to ComponentResource if something
* else is needed.
*/
class Endpoint extends ComponentResource
{
public function __construct(
// the component this belongs to
\ILIAS\Component\Component $component,
// path relative to the components resource directory
string $source
) {
parent::__construct($component, $source, ".");
}
}
23 changes: 12 additions & 11 deletions public/confirmReg.php → ...AS/Component/src/Resource/PublicAsset.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -16,16 +18,15 @@
*
*********************************************************************/

declare(strict_types=1);
namespace ILIAS\Component\Resource;

if (!file_exists(getcwd() . '/ilias.ini.php')) {
exit();
/**
* An public asset is a file or folder that should be served via the web.
*/
interface PublicAsset
{
// path of asset relative to the ILIAS base
public function getSource(): string;
// new path of relative to the ILIAS public directory
public function getTarget(): string;
}

ilInitialisation::initILIAS();

/** @var ILIAS\DI\Container $DIC */
// @todo: removed deprecated ilCtrl methods, this needs inspection by a maintainer.
// $DIC->ctrl()->setCmd('confirmRegistration');
$DIC->ctrl()->callBaseClass(ilStartUpGUI::class);
$DIC->http()->close();
Loading

0 comments on commit 2544df9

Please sign in to comment.