diff --git a/cli/entry_point.php b/cli/entry_point.php new file mode 100644 index 000000000000..b38d55b4e5c2 --- /dev/null +++ b/cli/entry_point.php @@ -0,0 +1,39 @@ + + new Component\Activities\StaticRepository( + $seek[Component\Activities\Activity::class] + ); + $contribute[Component\EntryPoint::class] = static fn() => new Component\EntryPoint\HelloWorld("Component/HelloWorld"); + $contribute[Component\EntryPoint::class] = static fn() => + new Component\Activities\ListActivitiesEntryPoint( + $use[Component\Activities\Repository::class] + ); $contribute[\ILIAS\Setup\Agent::class] = static fn() => new \ilComponentsSetupAgent( diff --git a/components/ILIAS/Component/src/Activities/Activity.php b/components/ILIAS/Component/src/Activities/Activity.php new file mode 100644 index 000000000000..4c054ee0b2e3 --- /dev/null +++ b/components/ILIAS/Component/src/Activities/Activity.php @@ -0,0 +1,74 @@ +repository->getActivitiesByName("/.*/")))); + echo "\n"; + return 0; + } +} diff --git a/components/ILIAS/Component/src/Activities/Query.php b/components/ILIAS/Component/src/Activities/Query.php new file mode 100644 index 000000000000..2585fa7a715d --- /dev/null +++ b/components/ILIAS/Component/src/Activities/Query.php @@ -0,0 +1,33 @@ + where keys are the name + */ + public function getActivitiesByName(string $name_matcher, ?ActivityType $type = null, ?Range $range = null): \Iterator; +} diff --git a/components/ILIAS/Component/src/Activities/StaticRepository.php b/components/ILIAS/Component/src/Activities/StaticRepository.php new file mode 100644 index 000000000000..4e094fc7798f --- /dev/null +++ b/components/ILIAS/Component/src/Activities/StaticRepository.php @@ -0,0 +1,51 @@ + $ativities + */ + public function __construct( + array $activities + ) { + foreach ($activities as $activity) { + if (!($activity instanceof Activity)) { + throw new \InvalidArgumentException( + "Expected `Activity`, got: " . get_class($activity) + ); + } + $this->activities[(string) $activity->getName()] = $activity; + } + } + + public function getActivitiesByName(string $name_matcher, ?ActivityType $type = null, ?Range $range = null): \Iterator + { + foreach ($this->activities as $name => $activity) { + if (preg_match($name_matcher, $name)) { + yield $name => $activity; + } + } + } +} diff --git a/components/ILIAS/Component/tests/Activities/StaticRepositoryTest.php b/components/ILIAS/Component/tests/Activities/StaticRepositoryTest.php new file mode 100644 index 000000000000..3bb1560176f3 --- /dev/null +++ b/components/ILIAS/Component/tests/Activities/StaticRepositoryTest.php @@ -0,0 +1,84 @@ +assertEquals([], iterator_to_array($repository->getActivitiesByName("%.*%"))); + } + + public function testKeyIsName(): void + { + $name = "\\ILIAS\\Component\\Tests\\SomeActivity"; + + $activity = $this->createMock(Activity::class); + $activity + ->method("getName") + ->willReturn(new Name($name)); + + $repository = new StaticRepository([$activity]); + + $activities = iterator_to_array($repository->getActivitiesByName("%.*%")); + + $this->assertEquals($activity, $activities[$name]); + } + + public function testGetActivitiesByNameNoMatch(): void + { + $name = "\\ILIAS\\Component\\Tests\\SomeActivity"; + + $activity = $this->createMock(Activity::class); + $activity + ->method("getName") + ->willReturn(new Name($name)); + + $repository = new StaticRepository([$activity]); + + $activities = iterator_to_array($repository->getActivitiesByName("%Foo%")); + + $this->assertEquals([], $activities); + } + + public function testGetActivitiesByNameMatch(): void + { + $name = "\\ILIAS\\Component\\Tests\\SomeActivity"; + + $activity = $this->createMock(Activity::class); + $activity + ->method("getName") + ->willReturn(new Name($name)); + + $repository = new StaticRepository([$activity]); + + $activities = iterator_to_array($repository->getActivitiesByName("%.*Some.*%")); + + $this->assertEquals($activity, $activities[$name]); + } +} diff --git a/components/ILIAS/Setup/Setup.php b/components/ILIAS/Setup/Setup.php index a9f43efbbddf..7588849e00b3 100644 --- a/components/ILIAS/Setup/Setup.php +++ b/components/ILIAS/Setup/Setup.php @@ -50,6 +50,9 @@ public function init( $pull[\ILIAS\Data\Factory::class] ); + $contribute[\ILIAS\Component\Activities\Activity::class] = static fn() => + new \ILIAS\Setup\Activities\GetStatus(); + $internal["command.install"] = static fn() => new \ILIAS\Setup\CLI\InstallCommand( $internal["agent_finder"], diff --git a/components/ILIAS/Setup/src/Activities/GetStatus.php b/components/ILIAS/Setup/src/Activities/GetStatus.php new file mode 100644 index 000000000000..14b99e0285f5 --- /dev/null +++ b/components/ILIAS/Setup/src/Activities/GetStatus.php @@ -0,0 +1,48 @@ +