houssam-ouatmani/fluent-php

A lightweight PHP fluent helper library for strings, numbers, and arrays.

Maintainers

Package info

github.com/Houssam-OUATMANI/fluent-php

pkg:composer/houssam-ouatmani/fluent-php

Transparency log

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-07-21 19:54 UTC

This package is auto-updated.

Last update: 2026-07-21 20:01:58 UTC


README

A lightweight PHP fluent helper library for working with strings, numbers, and arrays.

Installation

Install via Composer:

composer require houssam-ouatmani/fluent-php

Usage

String helper

use HoussamOuatmani\FluentPhp\Fluent;

$formatted = Fluent::str(' hello world ')
    ->trim()
    ->title()
    ->replace('Hello', 'Hi')
    ->get();

echo $formatted; // Hi World

Supported string methods:

  • make(string $value)
  • length()
  • upper()
  • lower()
  • title()
  • snake()
  • kebab()
  • studly()
  • camel()
  • trim()
  • append(string $suffix)
  • prepend(string $prefix)
  • replace(string $search, string $replace)
  • contains(string $needle)
  • substr(int $start, ?int $length = null)
  • limit(int $limit, string $end = '...')
  • words()
  • wordCount()
  • explode(string $delimiter = ',')
  • startsWith(string $str)
  • endsWith(string $str)
  • get()
  • toString()

Number helper

$value = Fluent::num(10)
    ->add(5)
    ->sub(3)
    ->mul(2)
    ->div(3)
    ->get();

echo $value; // 8

Supported number methods:

  • make(int|float $value)
  • add(int|float $value)
  • sub(int|float $value)
  • mul(int|float $value)
  • div(int|float $value)
  • mod(int|float $value)
  • abs()
  • pow(int|float $exponent)
  • round(int $precision = 0, int $mode = PHP_ROUND_HALF_UP)
  • ceil()
  • floor()
  • negate()
  • isEven()
  • isOdd()
  • between(int|float $lower, int|float $upper, bool $inclusive = true)
  • isPositive()
  • isNegative()
  • get()
  • value()
  • toString()

Array helper

$collection = Fluent::arr([3, 1, 2])
    ->sort()
    ->values();

print_r($collection->get()); // [1, 2, 3]

Supported array methods:

  • make(array $items = [])
  • get()
  • all()
  • count()
  • isEmpty()
  • push(mixed $value)
  • prepend(mixed $value)
  • merge(array $items)
  • map(callable $callback)
  • filter(callable $callback)
  • reduce(callable $callback, mixed $initial = null)
  • each(callable $callback)
  • unique()
  • sort(callable|null $callback = null)
  • sortKeys()
  • diff(array $items)
  • intersect(array $items)
  • reverse()
  • flatten(int $depth = PHP_INT_MAX)
  • keys()
  • values()
  • first(mixed $default = null)
  • last(mixed $default = null)
  • has(string|int $key)
  • getAt(string|int $key, mixed $default = null)
  • slice(int $offset, ?int $length = null)
  • chunk(int $size)
  • pluck(string $key, mixed $default = null)
  • groupBy(callable|string $key)
  • flip()
  • toJson(int $flags = 0)
  • toString(string $separator = ',')

License

MIT

Changelog

See CHANGELOG.md for release notes and version history.