Skip to content

Commit d103ea0

Browse files
committed
Initial commit
0 parents  commit d103ea0

File tree

6 files changed

+837
-0
lines changed

6 files changed

+837
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 DiscordPHP
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# DiscordPHP Collection
2+
3+
A collection library for DiscordPHP. Inspired by Laravel Collections.
4+
5+
## Installation
6+
7+
You can install the library via Composer:
8+
9+
```bash
10+
composer require discord-php-helpers/collection
11+
```
12+
13+
## License
14+
15+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "discord-php-helpers/collection",
3+
"description": "A collection library for DiscordPHP. Inspired by Laravel Collections.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "David Cole",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Valithor Obsidion",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"require": {
17+
"php": ">=8.0"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Discord\\Helpers\\": "src/"
22+
}
23+
}
24+
}

src/Collection.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of the DiscordPHP project.
5+
*
6+
* Copyright (c) 2015-present David Cole <[email protected]>
7+
*
8+
* This file is subject to the MIT license that is bundled
9+
* with this source code in the LICENSE.md file.
10+
*/
11+
12+
namespace Discord\Helpers;
13+
14+
/**
15+
* Collection of items. Inspired by Laravel Collections.
16+
*
17+
* @since 5.0.0 No longer extends Laravel's BaseCollection
18+
* @since 4.0.0
19+
*/
20+
class Collection implements CollectionInterface
21+
{
22+
/**
23+
* The collection discriminator.
24+
*
25+
* @var ?string
26+
*/
27+
protected $discrim;
28+
29+
/**
30+
* The items contained in the collection.
31+
*
32+
* @var array
33+
*/
34+
protected $items;
35+
36+
/**
37+
* Class type allowed into the collection.
38+
*
39+
* @var string
40+
*/
41+
protected $class;
42+
43+
use CollectionTrait;
44+
}

src/CollectionInterface.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of the DiscordPHP project.
5+
*
6+
* Copyright (c) 2015-present David Cole <[email protected]>
7+
*
8+
* This file is subject to the MIT license that is bundled
9+
* with this source code in the LICENSE.md file.
10+
*/
11+
12+
namespace Discord\Helpers;
13+
14+
use ArrayAccess;
15+
use Countable;
16+
use IteratorAggregate;
17+
use JsonSerializable;
18+
use Traversable;
19+
20+
interface CollectionInterface extends ArrayAccess, JsonSerializable, IteratorAggregate, Countable
21+
{
22+
public function get(string $discrim, $key);
23+
public function set($offset, $value);
24+
public function pull($key, $default = null);
25+
public function fill($items): self;
26+
public function push(...$items): self;
27+
public function pushItem($item): self;
28+
public function count(): int;
29+
public function first();
30+
public function last();
31+
public function isset($offset): bool;
32+
public function has(...$keys): bool;
33+
public function filter(callable $callback);
34+
public function find(callable $callback);
35+
public function clear(): void;
36+
public function map(callable $callback);
37+
public function merge($collection): self;
38+
public function toArray();
39+
public function offsetExists($offset): bool;
40+
#[\ReturnTypeWillChange]
41+
public function offsetGet($offset);
42+
public function offsetSet($offset, $value): void;
43+
public function offsetUnset($offset): void;
44+
public function serialize(int $flags = 0, ?int $depth = 512): string;
45+
public function __serialize(): array;
46+
public function unserialize(string $serialized): void;
47+
public function __unserialize($data): void;
48+
public function jsonSerialize(): array;
49+
public function getIterator(): Traversable;
50+
public function __debugInfo(): array;
51+
}

0 commit comments

Comments
 (0)