forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
374 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
components/ILIAS/Component/src/Dependencies/ResolutionDirective.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
53 changes: 53 additions & 0 deletions
53
components/ILIAS/Component/src/Dependencies/ResolutionDirective/ForXUseY.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
components/ILIAS/Component/src/Dependencies/ResolutionDirective/InComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
components/ILIAS/Component/src/Dependencies/ResolutionDirective/WhenPulling.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.