PHPackages                             entrepeneur4lyf/laravel-psl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. entrepeneur4lyf/laravel-psl

ActiveLibrary

entrepeneur4lyf/laravel-psl
===========================

Laravel-first package that makes the PHP Standard Library feel natural inside Laravel applications.

v1.0.0(1mo ago)00MITPHPPHP ^8.4CI passing

Since Mar 19Pushed 1mo agoCompare

[ Source](https://github.com/entrepeneur4lyf/laravel-psl)[ Packagist](https://packagist.org/packages/entrepeneur4lyf/laravel-psl)[ Docs](https://github.com/entrepeneur4lyf/laravel-psl)[ RSS](/packages/entrepeneur4lyf-laravel-psl/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

laravel-psl
===========

[](#laravel-psl)

Laravel-first package that makes the PHP Standard Library (PSL) feel natural inside Laravel applications.

Status
------

[](#status)

Current v1 implementation includes:

- explicit bridge utilities for vec, dict, and Collection conversion
- opt-in list-safe Collection macros
- helper-driven typed coercion built on `Psl\Type`
- Laravel-friendly coercion exception wrapping
- PHPUnit and Testbench coverage

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 13.x
- PSL 6.x

Installation
------------

[](#installation)

```
composer require entrepeneur4lyf/laravel-psl
```

Laravel package discovery registers the service provider automatically.

Configuration
-------------

[](#configuration)

Publish the config if you want to change runtime behavior:

```
php artisan vendor:publish --tag=laravel-psl-config
```

Current config:

```
return [
    'features' => [
        'collection_macros' => true,
    ],
];
```

Bridge Utilities
----------------

[](#bridge-utilities)

Use `LaravelPsl\Support\PslBridge` when you want explicit conversions between Laravel Collections and PSL-style array semantics.

```
use LaravelPsl\Support\PslBridge;

$collection = collect([
    'name' => 'Taylor',
    2 => 'Laravel',
]);

$vec = PslBridge::toVec($collection);
// ['Taylor', 'Laravel']

$dict = PslBridge::toDict($collection);
// ['name' => 'Taylor', 2 => 'Laravel']

$backToCollection = PslBridge::toCollection($dict);
// Collection(['name' => 'Taylor', 2 => 'Laravel'])
```

Bridge semantics:

- `toVec()` intentionally reindexes values.
- `toDict()` intentionally preserves runtime keys.
- Mixed `array-key` dictionaries are supported as PHP represents them at runtime.

Collection Macros
-----------------

[](#collection-macros)

When `features.collection_macros` is enabled, these macros are registered on `Illuminate\Support\Collection`:

- `pmap`
- `pfilter`
- `preduce`
- `pchunk`
- `psort`
- `ptoVec`
- `ptoDict`

Example:

```
$users = collect($payload['users'])
    ->pfilter(fn (array $user): bool => $user['active'] ?? false)
    ->pmap(fn (array $user): array => [
        'email' => strtolower($user['email']),
        'name' => trim($user['name']),
    ]);
```

Macro semantics:

- `pmap`, `pfilter`, `pchunk`, and `psort` are list-safe operations.
- List-safe operations reindex values by design.
- `preduce` is terminal and returns the final accumulator.
- `preduce` always requires an explicit initial value.
- `psort` returns a reindexed Collection sorted by values.
- `ptoVec()` returns a plain list.
- `ptoDict()` returns a plain key-preserving array.

Examples:

```
$sum = collect(['a' => 1, 'b' => 2, 'c' => 3])
    ->preduce(fn (int $carry, int $value): int => $carry + $value, 0);
// 6

$sorted = collect(['c' => 3, 'a' => 1, 'b' => 2])->psort();
// Collection([1, 2, 3])

$vec = collect(['name' => 'Taylor', 2 => 'Laravel'])->ptoVec();
// ['Taylor', 'Laravel']

$dict = collect(['name' => 'Taylor', 2 => 'Laravel'])->ptoDict();
// ['name' => 'Taylor', 2 => 'Laravel']
```

Typed Coercion
--------------

[](#typed-coercion)

Use `LaravelPsl\Type\Coerce` as a thin wrapper around `Psl\Type`.

```
use LaravelPsl\Type\Coerce;
use Psl\Type;

$user = Coerce::value(
    Type\shape([
        'name' => Type\non_empty_string(),
        'roles' => Type\vec(Type\string()),
    ]),
    $payload,
);
```

On failure, the package throws `LaravelPsl\Exceptions\CoercionException` and preserves the original `Psl\Type\Exception\CoercionException` as `previous`.

Usage Examples
--------------

[](#usage-examples)

### Controller

[](#controller)

```
use LaravelPsl\Type\Coerce;
use Psl\Type;

$input = Coerce::value(
    Type\shape([
        'email' => Type\non_empty_string(),
        'roles' => Type\vec(Type\string()),
    ]),
    $request->all(),
    ['source' => 'request', 'field' => 'user'],
);
```

### Service

[](#service)

```
use LaravelPsl\Support\PslBridge;

$emails = PslBridge::toVec($users->pluck('email'));
```

### Job

[](#job)

```
use LaravelPsl\Type\Coerce;
use Psl\Type;

$payload = Coerce::value(
    Type\shape([
        'user_id' => Type\positive_int(),
        'tags' => Type\vec(Type\string()),
    ]),
    $this->payload,
    ['source' => 'job', 'job' => static::class],
);
```

### Command

[](#command)

```
$names = collect($this->argument('names'))
    ->pfilter()
    ->psort()
    ->ptoVec();
```

Disabled-Feature Behavior
-------------------------

[](#disabled-feature-behavior)

If `features.collection_macros` is `false`:

- Collection macros are not registered.
- `PslBridge` remains available.
- `Coerce` remains available.

Out of Scope for V1
-------------------

[](#out-of-scope-for-v1)

- dict-aware transform macros
- Form Request integration for coercion
- string adapters
- runtime-aware concurrency integration

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
```

Auto-discovery smoke test:

```
composer test:discovery:install
composer test:discovery
```

See [prd.md](./prd.md) for the product definition and [implementation-plan.md](./implementation-plan.md) for the execution checklist.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance89

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d0fa86a7e132e8f1d5af8f61074546309323078020baede270e1d0391d7d2df?d=identicon)[stonedoubt](/maintainers/stonedoubt)

---

Top Contributors

[![entrepeneur4lyf](https://avatars.githubusercontent.com/u/7050547?v=4)](https://github.com/entrepeneur4lyf "entrepeneur4lyf (8 commits)")

---

Tags

laravelPSLphp standard library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/entrepeneur4lyf-laravel-psl/health.svg)

```
[![Health](https://phpackages.com/badges/entrepeneur4lyf-laravel-psl/health.svg)](https://phpackages.com/packages/entrepeneur4lyf-laravel-psl)
```

###  Alternatives

[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[glhd/linen

21135.6k](/packages/glhd-linen)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
