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 19, 2024
1 parent b3ee348 commit 9597caa
Show file tree
Hide file tree
Showing 740 changed files with 1,292 additions and 45,632 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\ComponentJS($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
6 changes: 5 additions & 1 deletion components/ILIAS/AuthShibboleth/AuthShibboleth.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "shib_login.php");

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "shib_logout.php");
}
}
2 changes: 1 addition & 1 deletion public/shib_login.php → ...S/AuthShibboleth/resources/shib_login.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
// @todo: removed deprecated ilCtrl methods, this needs inspection by a maintainer.
// $DIC->ctrl()->setCmd('doShibbolethAuthentication');
$DIC->ctrl()->callBaseClass(ilStartUpGUI::class);
}
}
2 changes: 1 addition & 1 deletion public/shib_logout.php → .../AuthShibboleth/resources/shib_logout.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ function unserializesession($serialized_string)
}

return ($variables);
}
}
3 changes: 3 additions & 0 deletions components/ILIAS/Authentication/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ public function init(
new \ilAuthenticationSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "sessioncheck.php");
}
}
20 changes: 10 additions & 10 deletions public/sessioncheck.php → ...Authentication/resources/sessioncheck.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
/** @var ILIAS\DI\Container $DIC */
$DIC->http()->saveResponse(
(
new ilSessionReminderCheck(
$DIC->http(),
$DIC->refinery(),
$DIC->language(),
$DIC->database(),
$DIC['ilClientIniFile'],
$DIC->logger()->auth(),
(new DataFactory())->clock()->utc()
)
new ilSessionReminderCheck(
$DIC->http(),
$DIC->refinery(),
$DIC->language(),
$DIC->database(),
$DIC['ilClientIniFile'],
$DIC->logger()->auth(),
(new DataFactory())->clock()->utc()
)
)->handle()
);
$DIC->http()->sendResponse();
$DIC->http()->close();
$DIC->http()->close();
3 changes: 2 additions & 1 deletion components/ILIAS/Awareness/Awareness.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\ComponentJS($this, "Awareness.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function initJS(): void
{
$ilUser = $this->user;
// init js
$this->main_tpl->addJavaScript("./components/ILIAS/Awareness/js/Awareness.js");
$this->main_tpl->addJavaScript("./assets/js/Awareness.js");
$this->ctrl->setParameter($this, "ref_id", $this->ref_id);
$this->main_tpl->addOnLoadCode("il.Awareness.setBaseUrl('" . $this->ctrl->getLinkTarget(
$this,
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/Block/Block.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\ComponentJS($this, "ilblockcallback.js");
}
}
2 changes: 1 addition & 1 deletion components/ILIAS/Block/classes/class.ilBlockGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function __construct()
$this->ui = $DIC->ui();

ilYuiUtil::initConnection();
$this->main_tpl->addJavaScript("./components/ILIAS/Block/js/ilblockcallback.js");
$this->main_tpl->addJavaScript("./assets/js/ilblockcallback.js");

$this->setLimit((int) $this->user->getPref("hits_per_page"));

Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/COPage/Resources/ResourcesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected function init(\ilPageObject $pg): void
if ($this->output_mode == \ilPageObjectGUI::OFFLINE) {
$this->js_files[] = \iljQueryUtil::getLocaljQueryPath();
$this->js_files[] = \iljQueryUtil::getLocaljQueryUIPath();
$this->js_files[] = './components/ILIAS/JavaScript/js/Basic.js';
$this->js_files[] = 'assets/js/Basic.js';
}

$this->js_files[] = "./components/ILIAS/COPage/js/ilCOPagePres.js";
$this->js_files[] = "assets/js/ilCOPagePres.js";

// for all page components...
$defs = $this->pc_definition->getPCDefinitions();
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
38 changes: 38 additions & 0 deletions components/ILIAS/Component/src/Resource/ComponentCSS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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);

namespace ILIAS\Component\Resource;

/**
* This is a css file provided by some component.
*/
class ComponentCSS extends OfComponent
{
/**
* @param $component this belongs to
* @param $source path relative to the components resource directory
*/
public function __construct(
\ILIAS\Component\Component $component,
string $source,
) {
parent::__construct($component, $source, "assets/css");
}
}
38 changes: 38 additions & 0 deletions components/ILIAS/Component/src/Resource/ComponentJS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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);

namespace ILIAS\Component\Resource;

/**
* This is a js file provided by some component.
*/
class ComponentJS extends ComponentResource
{
/**
* @param $component this belongs to
* @param $source path relative to the components resource directory
*/
public function __construct(
\ILIAS\Component\Component $component,
string $source,
) {
parent::__construct($component, $source, "assets/js");
}
}
42 changes: 42 additions & 0 deletions components/ILIAS/Component/src/Resource/Endpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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);

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
{
/**
* @param $component this belongs to
* @param $source path relative to the components resources directory
* @param $target path relative to the ILIAS public directory, filename of resource will be appended. Use one dot for toplevel. Defaults to ".".
*/
public function __construct(
\ILIAS\Component\Component $component,
string $source,
string $target = "."
) {
parent::__construct($component, $source, $target);
}
}
68 changes: 68 additions & 0 deletions components/ILIAS/Component/src/Resource/OfComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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);

namespace ILIAS\Component\Resource;

/**
* An public asset that is a resource of some component.
*/
class OfComponent implements PublicAsset
{
public const REGEXP_SOURCE = '%^((\w+(/(\w|.)+)*\.\w{2,4})|(\.htaccess))$%';
public const REGEXP_TARGET = '%^((\w+(/(\w|.)+)*)|[.])$%';

/**
* @param $component this belongs to
* @param $source path relative to the components resources directory
* @param $target path relative to the ILIAS public directory, filename of resource will be appended. Use one dot for toplevel.
*/
public function __construct(
protected \ILIAS\Component\Component $component,
protected string $source,
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);
}
}
Loading

0 comments on commit 9597caa

Please sign in to comment.