Remove illuminate/collections
This commit is contained in:
parent
275103e149
commit
419d1cec14
6 changed files with 89 additions and 260 deletions
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"illuminate/collections": "^11.6",
|
|
||||||
"opdavies/sculpin-twig-markdown-bundle": "^0.2.0",
|
"opdavies/sculpin-twig-markdown-bundle": "^0.2.0",
|
||||||
"sculpin/sculpin": "^3.2"
|
"sculpin/sculpin": "^3.2"
|
||||||
},
|
},
|
||||||
|
|
249
composer.lock
generated
249
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4811731ac9f6bfcb3d81d35eff8a3b67",
|
"content-hash": "c72e9dc8c2e53aee1883b80259d8890f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "dflydev/ant-path-matcher",
|
"name": "dflydev/ant-path-matcher",
|
||||||
|
@ -562,202 +562,6 @@
|
||||||
},
|
},
|
||||||
"time": "2020-11-24T22:02:12+00:00"
|
"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",
|
"name": "michelf/php-markdown",
|
||||||
"version": "1.9.1",
|
"version": "1.9.1",
|
||||||
|
@ -1069,57 +873,6 @@
|
||||||
},
|
},
|
||||||
"time": "2021-07-14T16:41:46+00:00"
|
"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",
|
"name": "react/cache",
|
||||||
"version": "v1.2.0",
|
"version": "v1.2.0",
|
||||||
|
|
42
src/Presentation/Collection/AbstractCollection.php
Normal file
42
src/Presentation/Collection/AbstractCollection.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Presentation\Collection;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
use Countable;
|
||||||
|
use Iterator;
|
||||||
|
use IteratorAggregate;
|
||||||
|
|
||||||
|
abstract class AbstractCollection implements Countable, IteratorAggregate
|
||||||
|
{
|
||||||
|
public function __construct(protected array $items = [])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return count($this->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;
|
||||||
|
}
|
||||||
|
}
|
9
src/Presentation/Collection/EventCollection.php
Normal file
9
src/Presentation/Collection/EventCollection.php
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Presentation\Collection;
|
||||||
|
|
||||||
|
final class EventCollection extends AbstractCollection
|
||||||
|
{
|
||||||
|
}
|
34
src/Presentation/Collection/PresentationCollection.php
Normal file
34
src/Presentation/Collection/PresentationCollection.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Presentation\Collection;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||||
|
|
||||||
|
final class PresentationCollection extends AbstractCollection
|
||||||
|
{
|
||||||
|
public function getAllEvents(): EventCollection
|
||||||
|
{
|
||||||
|
$events = array_reduce(
|
||||||
|
array: $this->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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Presentation\TwigExtension;
|
namespace App\Presentation\TwigExtension;
|
||||||
|
|
||||||
|
use App\Presentation\Collection\PresentationCollection;
|
||||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
@ -22,17 +23,8 @@ class PresentationTwigExtension extends AbstractExtension
|
||||||
|
|
||||||
public function getPresentationCount(array $presentations): int
|
public function getPresentationCount(array $presentations): int
|
||||||
{
|
{
|
||||||
$today = (new \DateTime('today'))->getTimestamp();
|
$presentationCollection = new PresentationCollection($presentations);
|
||||||
|
|
||||||
return collect($presentations)
|
return $presentationCollection->getPastEvents()->count();
|
||||||
->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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue