chris-kruining / utilities
Utilities for PHP 7.1 and up
Requires
- php: >=7.4.0
- composer/composer: 2.2.6
- nesbot/carbon: 2.56.0
- psr/container: ^1 || 2.0.2
Requires (Dev)
- phpspec/phpspec: 7.1.0
Provides
- dev-master
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- 0.2.26
- 0.2.25
- 0.2.24
- 0.2.23
- 0.2.22
- 0.2.21
- 0.2.20
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.1
- dev-renovate/nesbot-carbon-2.x
- dev-renovate/composer-composer-2.x
This package is auto-updated.
Last update: 2023-09-27 18:01:26 UTC
README
Utilities
some utilities for php, nothing special, nothing new, just to my taste
Installation
installation is simply done via composer
composer require chris-kruining/utilities
Usage
The main component of the library is the Collection
at the moment. The goal of the Collection
is to provide a object oriented interface for array functions. It also has a couple of extra's like method chaining and linq-esc implementation(NOT DONE YET) so that you may interact with the Collection
as if it was a database table
for example
CPB\Utilities\Collections\Collection::from([ 'these', 'are', null, null, 'some', null, 'test', 'values', null ]) ->filter() ->toString(' ');
would yield
'these are some test values'
which is the same as
join(' ', array_filter([ 'these', 'are', null, null, 'some', null, 'test', 'values', null ]));
I agree, the vannilla way is shorter now but the strength really comes into play when we start adding callbacks and increase the chain length
CPB\Utilities\Collections\Collection::from([ 'these', '', '', 'are', null, 'some', null, 'test', '', 'values', '' ]) ->filter(fn($v) => $v !== null && strlen($v) > 0) ->map(fn($k, $v) => $k . '::' . $v) ->toString('|');
would yield
'0::these|1::are|2::some|3::test|4::values'
which is the same as
$filtered = array_filter( [ 'these', '', '', 'are', null, 'some', null, 'test', '', 'values', '' ], fn($v) => $v !== null && strlen($v) > 0 ); join('|', array_map(fn($k, $v) => $k . '::' . $v, array_keys($filtered), $filtered));
As you can see the collection version maintains readability whereas the vannilla version loses in my opinion it's charm because to achieve a single goal you need to spread it out over multiple variables
Roadmap
- Implement basic features to
Collection
- Bloat
Collection
with features :P - Split of features into an inheritance tree
- Split lazy mode from
Collection
intoLazyCollection
and implement PHP's array functions as generators - Finish inheritance structure
- Implement
LazyCollection
- (Better) implement the
Queryable
interface in a new class so theCollection
doesn't become bloated