Skip to content

Commit

Permalink
recursive resolver with directives
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Nov 29, 2023
1 parent 2e31103 commit 0cd1111
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 92 deletions.
5 changes: 5 additions & 0 deletions components/ILIAS/Component/src/Dependencies/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public function getResolvedBy(): array
{
return $this->resolved_by;
}

public function isResolved(): bool
{
return count($this->resolved_by) > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\Dependencies;

/**
* Specifies a certain way to disambiguate or resolve some dependency. Do not
* extend, won't work!
*
* "specificity" is meant to order directives, more specific directives come
* first.
*/
interface ResolutionDirective
{
public function getSpecificity(): int;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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\Dependencies\ResolutionDirective;

use ILIAS\Component\Dependencies\ResolutionDirective;

/**
* Tells the Resolver to use an implementation with a certain class name to
* resolve a certain dependency.
*
* Specifity is 1.
*/
class ForXUseY implements ResolutionDirective
{
public function __construct(
protected string $x,
protected string $y,
) {
}

public function getX(): string
{
return $this->x;
}

public function getY(): string
{
return $this->y;
}

public function getSpecificity(): int
{
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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\Dependencies\ResolutionDirective;

use ILIAS\Component\Dependencies\ResolutionDirective;

/**
* Tells the Resolver to apply that directives only in the given component.
*
* Specifity is one more than the maximum specifity of the included directives.
*/
class InComponent implements ResolutionDirective
{
protected int $specificity;
protected array $directives;

public function __construct(
protected string $component_name,
ResolutionDirective ...$directives
) {
usort($directives, fn($l, $r) => $l->getSpecificity() <=> $r->getSpecificity());
$this->directives = $directives;
$this->specificity = max(array_map(fn($d) => $d->getSpecificity(), $directives)) + 1;
}

public function getComponentName(): string
{
return $this->component_name;
}

public function getDirectives(): array
{
return $this->directives;
}

public function getSpecificity(): int
{
return $this->specificity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\Dependencies\ResolutionDirective;

use ILIAS\Component\Dependencies\ResolutionDirective;

/**
* Tells the Resolver to apply certain directives when some specifc thing is pulled.
*
* Specifity is one more than the maximum specifity of the included directives.
*/
class WhenPulling implements ResolutionDirective
{
protected int $specificity;
protected array $directives;

public function __construct(
protected string $provision,
ResolutionDirective ...$directives
) {
$this->directives = $directives;
$this->specificity = max(array_map(fn($d) => $d->getSpecificity(), $directives)) + 1;
}

public function getSpecificity(): int
{
return $this->specificity;
}
}
Loading

0 comments on commit 0cd1111

Please sign in to comment.