From b9e3bfab8a2c730a35ca3106ae707f5e1d8f3caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=81ebkowski?= Date: Mon, 3 Jul 2023 10:18:06 +0200 Subject: [PATCH] **WIP** --- build-container.php | 53 +++++++++++++++++++ config/cache/.gitignore | 1 + .../Discovery/ImplementationsDiscovery.php | 1 - src/Aoc/SolutionFactory.php | 12 ++--- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100755 build-container.php create mode 100644 config/cache/.gitignore diff --git a/build-container.php b/build-container.php new file mode 100755 index 0000000..2bf4617 --- /dev/null +++ b/build-container.php @@ -0,0 +1,53 @@ +#!/usr/bin/env php + __DIR__ . '/config/cache/inputParsers.php', + Solution::class => __DIR__ . '/config/cache/solutions.php', +]; + +foreach ($map as $type => $target) { + is_dir($dir = dirname($target)) || mkdir($dir, recursive: true); + $implementations = Collection::fromIterable($implementationsDiscovery->findImplementations($type)) + ->sort( + callback: static fn (ReflectionClass $alpha, ReflectionClass $bravo) => $alpha->getName() <=> $bravo->getName(), + ); + + $uses = $implementations + ->map(static fn (ReflectionClass $class) => sprintf('use %s;', $class->getName())) + ->implode("\n"); + + $contents = $implementations + ->map(static fn (ReflectionClass $class) => sprintf(' %s::class,', $class->getShortName())) + ->implode("\n"); + file_put_contents( + $target, + sprintf( + <<classes ->filter(static fn (ReflectionClass $ref) => $ref->implementsInterface($interface)) - ->map(static fn (ReflectionClass $ref) => $ref->newInstance()) ->all(); } diff --git a/src/Aoc/SolutionFactory.php b/src/Aoc/SolutionFactory.php index 9ad7c45..1092d3c 100644 --- a/src/Aoc/SolutionFactory.php +++ b/src/Aoc/SolutionFactory.php @@ -5,6 +5,7 @@ namespace App\Aoc; use App\Aoc\Discovery\ImplementationsDiscovery; +use loophp\collection\Collection; use RuntimeException; final readonly class SolutionFactory @@ -15,12 +16,11 @@ public function __construct(private ImplementationsDiscovery $implementations) public function make(Challenge $challenge): Solution { - $supports = static fn (Solution $solution) => collect($solution->challenges())->contains( - static fn (Challenge $supports) => $supports->equals($challenge), - ); + $supports = static fn (Solution $solution) => null !== Collection::fromIterable($solution->challenges()) + ->find(callbacks: static fn (Challenge $supports) => $supports->equals($challenge)); return $this->getSolutions() - ->first(static fn (Solution $solution) => $supports($solution)) + ->find(callbacks: static fn (Solution $solution) => $supports($solution)) ?? throw new RuntimeException(sprintf('No solution for %s', $challenge)); } @@ -35,8 +35,8 @@ public function mostRecentChallenge(): Challenge ?? throw new RuntimeException('No implementations yet'); } - public function getSolutions(): \Illuminate\Support\Collection + public function getSolutions(): Collection { - return collect($this->implementations->findImplementations(Solution::class)); + return Collection::fromIterable($this->implementations->findImplementations(Solution::class)); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy