From 419d1cec140bb861667edcc8a4a22af07ecac223 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 4 May 2025 21:32:34 +0100 Subject: [PATCH] Remove illuminate/collections --- composer.json | 1 - composer.lock | 249 +----------------- .../Collection/AbstractCollection.php | 42 +++ .../Collection/EventCollection.php | 9 + .../Collection/PresentationCollection.php | 34 +++ .../PresentationTwigExtension.php | 14 +- 6 files changed, 89 insertions(+), 260 deletions(-) create mode 100644 src/Presentation/Collection/AbstractCollection.php create mode 100644 src/Presentation/Collection/EventCollection.php create mode 100644 src/Presentation/Collection/PresentationCollection.php diff --git a/composer.json b/composer.json index f90b60042..d7506f891 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,5 @@ { "require": { - "illuminate/collections": "^11.6", "opdavies/sculpin-twig-markdown-bundle": "^0.2.0", "sculpin/sculpin": "^3.2" }, diff --git a/composer.lock b/composer.lock index e90a41f87..534b5ea08 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4811731ac9f6bfcb3d81d35eff8a3b67", + "content-hash": "c72e9dc8c2e53aee1883b80259d8890f", "packages": [ { "name": "dflydev/ant-path-matcher", @@ -562,202 +562,6 @@ }, "time": "2020-11-24T22:02:12+00:00" }, - { - "name": "illuminate/collections", - "version": "v11.42.1", - "source": { - "type": "git", - "url": "https://github.com/illuminate/collections.git", - "reference": "6fd628d32a0989211c4f2829bf0a6a6175b2f3fd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/6fd628d32a0989211c4f2829bf0a6a6175b2f3fd", - "reference": "6fd628d32a0989211c4f2829bf0a6a6175b2f3fd", - "shasum": "" - }, - "require": { - "illuminate/conditionable": "^11.0", - "illuminate/contracts": "^11.0", - "illuminate/macroable": "^11.0", - "php": "^8.2" - }, - "suggest": { - "symfony/var-dumper": "Required to use the dump method (^7.0)." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "11.x-dev" - } - }, - "autoload": { - "files": [ - "functions.php", - "helpers.php" - ], - "psr-4": { - "Illuminate\\Support\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Collections package.", - "homepage": "https://laravel.com", - "support": { - "issues": "https://github.com/laravel/framework/issues", - "source": "https://github.com/laravel/framework" - }, - "time": "2025-02-05T10:23:21+00:00" - }, - { - "name": "illuminate/conditionable", - "version": "v11.42.1", - "source": { - "type": "git", - "url": "https://github.com/illuminate/conditionable.git", - "reference": "911df1bda950a3b799cf80671764e34eede131c6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/conditionable/zipball/911df1bda950a3b799cf80671764e34eede131c6", - "reference": "911df1bda950a3b799cf80671764e34eede131c6", - "shasum": "" - }, - "require": { - "php": "^8.0.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "11.x-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Support\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Conditionable package.", - "homepage": "https://laravel.com", - "support": { - "issues": "https://github.com/laravel/framework/issues", - "source": "https://github.com/laravel/framework" - }, - "time": "2024-11-21T16:28:56+00:00" - }, - { - "name": "illuminate/contracts", - "version": "v11.42.1", - "source": { - "type": "git", - "url": "https://github.com/illuminate/contracts.git", - "reference": "b350a3cd8450846325cb49e1cbc1293598b18898" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/b350a3cd8450846325cb49e1cbc1293598b18898", - "reference": "b350a3cd8450846325cb49e1cbc1293598b18898", - "shasum": "" - }, - "require": { - "php": "^8.2", - "psr/container": "^1.1.1|^2.0.1", - "psr/simple-cache": "^1.0|^2.0|^3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "11.x-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Contracts\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Contracts package.", - "homepage": "https://laravel.com", - "support": { - "issues": "https://github.com/laravel/framework/issues", - "source": "https://github.com/laravel/framework" - }, - "time": "2025-02-10T14:20:57+00:00" - }, - { - "name": "illuminate/macroable", - "version": "v11.42.1", - "source": { - "type": "git", - "url": "https://github.com/illuminate/macroable.git", - "reference": "e1cb9e51b9ed5d3c9bc1ab431d0a52fe42a990ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/macroable/zipball/e1cb9e51b9ed5d3c9bc1ab431d0a52fe42a990ed", - "reference": "e1cb9e51b9ed5d3c9bc1ab431d0a52fe42a990ed", - "shasum": "" - }, - "require": { - "php": "^8.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "11.x-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Support\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Macroable package.", - "homepage": "https://laravel.com", - "support": { - "issues": "https://github.com/laravel/framework/issues", - "source": "https://github.com/laravel/framework" - }, - "time": "2024-06-28T20:10:30+00:00" - }, { "name": "michelf/php-markdown", "version": "1.9.1", @@ -1069,57 +873,6 @@ }, "time": "2021-07-14T16:41:46+00:00" }, - { - "name": "psr/simple-cache", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/simple-cache.git", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", - "shasum": "" - }, - "require": { - "php": ">=8.0.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\SimpleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interfaces for simple caching", - "keywords": [ - "cache", - "caching", - "psr", - "psr-16", - "simple-cache" - ], - "support": { - "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" - }, - "time": "2021-10-29T13:26:27+00:00" - }, { "name": "react/cache", "version": "v1.2.0", diff --git a/src/Presentation/Collection/AbstractCollection.php b/src/Presentation/Collection/AbstractCollection.php new file mode 100644 index 000000000..eba26ba3b --- /dev/null +++ b/src/Presentation/Collection/AbstractCollection.php @@ -0,0 +1,42 @@ +items); + } + + public function filter(callable $callback): self + { + return new static( + array_filter( + array: $this->items, + callback: $callback, + ) + ); + } + + public function getIterator(): Iterator + { + return new ArrayIterator($this->items); + } + + public function toArray(): array + { + return $this->items; + } +} diff --git a/src/Presentation/Collection/EventCollection.php b/src/Presentation/Collection/EventCollection.php new file mode 100644 index 000000000..47bd86b26 --- /dev/null +++ b/src/Presentation/Collection/EventCollection.php @@ -0,0 +1,9 @@ +items, + callback: function (array $events, ProxySourceItem $presentation): array { + $events[] = $presentation->data()->get('events'); + + return $events; + }, + initial: [], + ); + + return new EventCollection(array_merge(...$events)); + } + + public function getPastEvents(): EventCollection + { + $today = new DateTimeImmutable('today'); + + return $this->getAllEvents() + ->filter(fn(array $event) => $event['date'] < $today->getTimestamp()); + } +} diff --git a/src/Presentation/TwigExtension/PresentationTwigExtension.php b/src/Presentation/TwigExtension/PresentationTwigExtension.php index cb312cc5d..e5d047a09 100644 --- a/src/Presentation/TwigExtension/PresentationTwigExtension.php +++ b/src/Presentation/TwigExtension/PresentationTwigExtension.php @@ -2,6 +2,7 @@ namespace App\Presentation\TwigExtension; +use App\Presentation\Collection\PresentationCollection; use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; @@ -22,17 +23,8 @@ class PresentationTwigExtension extends AbstractExtension public function getPresentationCount(array $presentations): int { - $today = (new \DateTime('today'))->getTimestamp(); + $presentationCollection = new PresentationCollection($presentations); - return collect($presentations) - ->flatMap(fn (ProxySourceItem $presentation) => $presentation->data()->get('events')) - ->filter( - function (array $event) use ($today): bool { - assert(array_key_exists(array: $event, key: 'date')); - - return $event['date'] < $today; - } - ) - ->count(); + return $presentationCollection->getPastEvents()->count(); } }