ZeroPHP

Support Utilities

Support Utilities

Zero ships a couple of lightweight helpers that make day-to-day tasks easier. The HTTP client saves you from wrestling with raw cURL handles, and the string helper mirrors Laravel's Str facade for quick transformations.

HTTP Client

Namespace: Zero\Lib\Http\Http

The HTTP client wraps PHP's cURL extension with a fluent API and sensible defaults.

Quick start

use Zero\Lib\Http\Http;

$response = Http::timeout(10)
    ->acceptJson()
    ->get('https://api.example.com/posts', ['page' => 2]);

if ($response->successful()) {
    $payload = $response->json();
}

Common patterns

  • Http::get($url, $query = [])
  • Http::post($url, $data = [])
  • Http::withHeaders([...])->post(...)
  • Http::attach($name, $contents, $filename) for multipart uploads
  • Http::asJson() to send JSON bodies (automatically sets headers)
  • Http::retry($times, $sleepMs) for simple retry policies
  • Use $response->status(), $response->body(), $response->json(), $response->headers() to inspect responses.

By default requests throw no exceptions—check $response->failed() or $response->successful() as needed.

String Helpers

Namespace: Zero\Lib\Support\Str

Str mirrors Laravel's helper with a static API and adds a fluent wrapper for chained transformations.

use Zero\Lib\Support\Str;

Str::studly('make_http_client');    // MakeHttpClient
Str::camel('make_http_client');     // makeHttpClient
Str::snake('MakeHTTPClient');       // make_http_client
Str::slug('Hello World!');          // hello-world
Str::limit('A very long sentence', 10); // A very...
Str::random(32);                    // e.g. 3kt1h9...
Str::after('auth:token', ':');      // token
Str::containsAll('queue:email', ['queue', 'email']); // true

Str::of('users.profile-photo')
    ->replaceLast('.', '/')
    ->slug('/');                    // users/profile-photo

Helper reference

Transformations

MethodPurposeExample
Str::studly('make_http_client')Convert to StudlyCaseMakeHttpClient
Str::camel('make_http_client')Convert to camelCasemakeHttpClient
Str::snake('MakeHTTPClient')Convert to snake_casemake_http_client
Str::kebab('MakeHTTPClient')Convert to kebab-casemake-http-client
Str::slug('Héllø Wørld')URL-friendly slug with ASCII transliterationhello-world
Str::title('make http client')Title case wordsMake Http Client
Str::upper('Zero')Uppercase stringZERO
Str::lower('Zero')Lowercase stringzero
Str::ascii('déjà vu')Transliterate to ASCIIdeja vu

Search helpers

MethodPurposeExample
Str::contains('queue:email', 'email')Check for substringtrue
Str::containsAll('queue:email', ['queue', 'email'])Ensure all needles are presenttrue
Str::containsAny('queue:email', ['http', 'email'])Ensure any needles are presenttrue
Str::startsWith('cache:foo', 'cache:')Check prefixtrue
Str::startsWithAny('cache:foo', ['queue:', 'cache:'])Check multiple prefixestrue
Str::endsWith('image.png', '.png')Check suffixtrue
Str::endsWithAny('image.backup.tar.gz', ['.zip', '.tar.gz'])Check multiple suffixestrue

Extraction helpers

MethodPurposeExample
Str::limit('A very long sentence', 10)Trim by charactersA very...
Str::limitWords('One two three four', 3)Trim by wordsOne two three...
Str::words('One two three four', 2)Take N wordsOne two...
Str::substr('framework', 0, 5)Multibyte-aware substringframe
Str::after('auth:token', ':')Portion after first occurrencetoken
Str::before('auth:token', ':')Portion before first occurrenceauth
Str::between('[42]', '[', ']')Portion between two markers42

Replacement & formatting

MethodPurposeExample
Str::replaceFirst('zero', 'one', 'zero zero')Replace first occurrenceone zero
Str::replaceLast('zero', 'one', 'zero zero')Replace last occurrencezero one
Str::swap(['{name}' => 'Zero'], 'Hello {name}')Replace using a mapHello Zero
Str::ensureSuffix('storage/logs', '/')Append suffix if missingstorage/logs/
Str::padLeft('7', 3, '0')Left pad to length007
Str::padRight('7', 3, '0')Right pad to length700
Str::padBoth('core', 8, '-')Pad evenly on both sides--core--
Str::repeat('-', 5)Repeat string-----

Length & randomness

MethodPurposeExample
Str::length('ありがとう')Multibyte-safe length5
Str::uuid()RFC4122 random UUID (v4)d3b0...
Str::random(16)Random token from base62 alphabetk9Qz...

Fluent chains

MethodPurposeExample
Str::of('users.profile-photo')Start fluent chain with StringableStringable instance

The fluent wrapper keeps string results chainable and lets you tap into non-string returns when needed:

use Zero\Lib\Support\Str;
use Zero\Lib\Support\Stringable as FluentString;

$profilePath = Str::of('users.profile-photo')
    ->replaceLast('.', '/')
    ->slug('/'); // users/profile-photo

$queueName = Str::of('queue')
    ->ensureSuffix(':default')
    ->pipe(fn (FluentString $stringable) => (string) $stringable); // queue:default

These helpers are framework-agnostic and usable in both CLI and HTTP code paths. See Zero\Lib\Support\Stringable for the fluent helper implementation and available chaining behaviour.

Storage

Namespace: Zero\\Lib\\Storage\\Storage

The storage facade provides a thin wrapper around the configured filesystem disks. The default local driver writes to storage/ and can be customised through config/storage.php or .env (STORAGE_DISK, STORAGE_LOCAL_ROOT).

Writing files

use Zero\\Lib\\Storage\\Storage;

$path = Storage::put('reports/latest.txt', "Report generated at " . date('c'));
// $path === 'reports/latest.txt'

// Read it back directly from the disk root
$contents = file_get_contents(storage_path($path));

Pair it with uploaded files:

$avatar = Request::file('avatar');

if ($avatar && $avatar->isValid()) {
    $path = $avatar->store('avatars');
    // $path => avatars/slug-64d2c6b1e5c3.jpg
}

Need a custom name?

$avatar->storeAs('avatars', 'user-' . $user->id . '.jpg');

Additional disks can be registered in config/storage.php; the storage manager will throw if you request a disk that has not been configured.

Create filesystem links with the CLI:

php zero storage:link

The command reads the links array in config/storage.php (defaults to linking public/storage to the public disk) and creates the appropriate symlinks. Ensure the web server user has permission to create the link path or run the command with suitable privileges.