Download the PHP package simp/php-toolkit without Composer
On this page you can find all versions of the php package simp/php-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simp/php-toolkit
More information about simp/php-toolkit
Files in simp/php-toolkit
Package php-toolkit
Short Description Fluent helpers for Strings, Numbers, Arrays/Iterables, Phone numbers, Emails and Countries, backed by real ISO country / dialing-code data.
License MIT
Informations about the package php-toolkit
php-toolkit
Fluent, dependency-free PHP helpers for strings, numbers, arrays/iterables, phone numbers, emails and countries — with Phone and Country backed by real ISO-3166 + international dialing-code data (bundled in resources/countries.json, merged from your two uploaded datasets, 249 countries / 237 with dial codes).
⚠️ One naming note
You asked for new String("..."). PHP doesn't allow that — string (like int, float, bool, array, null, void, object, mixed, never) is a reserved word and PHP raises a fatal error if you try to declare a class called String or Array. So this library calls them Str and Arr instead, but everything else works exactly as you described:
Install
No Composer registry access needed — drop the folder in and require the autoloader:
Or, if you do have Composer/Packagist access, composer.json is already set up with PSR-4 (Toolkit\ → src/), so composer dump-autoload + require 'vendor/autoload.php' works too.
Requires PHP ≥ 8.1 with the mbstring extension (intl optional, used for better transliteration in Str::ascii() if present, with an iconv fallback otherwise).
Run the tests / demo
Str — string manipulation
Every method returns a new Str (immutable, chainable). Cast to string with (string), echo, or ->value().
Grouped by category:
| Category | Methods |
|---|---|
| Case | upper lower ucfirst lcfirst title pascal/studly camel snake kebab slug swapCase |
| Trim/pad | trim ltrim rtrim squish pad padLeft padRight |
| Search/replace | substr limit words reverse repeat replace replaceFirst replaceLast remove append prepend between before beforeLast after afterLast mask wrap unwrap |
| Checks | isEmpty isNotEmpty contains containsAll startsWith endsWith equals is (wildcard) isAscii isAlpha isAlphaNumeric isNumeric isJson isUuid isUrl isEmail |
| Convert | toInt toFloat toBool split chunk toArray jsonDecode stripTags escape unescape ascii |
| Info | length wordCount countOccurrences |
| Static | Str::random(len) Str::uuid4() |
Arr — array manipulation
A fluent, chainable wrapper around PHP arrays (think a dependency-free Laravel Collection). Implements ArrayAccess, Countable, IteratorAggregate and JsonSerializable, so an Arr works with foreach, count(), $arr[0], and json_encode() directly. Transformation methods are immutable — they return a new Arr rather than mutating in place.
Dot-notation for nested data:
Full method list, grouped:
| Category | Methods |
|---|---|
| Access | get set has forget (dot-notation aware) · first last only except pluck |
| Transform | map flatMap mapWithKeys filter reject reduce each keys values flip flatten collapse chunk split combine |
| Combine | merge mergeRecursive union diff diffKeys intersect intersectKeys unique |
| Order | sort sortBy sortByDesc sortKeys sortKeysDesc reverse shuffle random |
| Mutate-ish (return new Arr) | pad prepend push pop shift |
| Group | groupBy countBy partition |
| Aggregate | count sum avg min max isEmpty isNotEmpty contains containsKey search implode |
| Convert | toArray toJson lazy() (→ LazyCollection) |
| Static | Arr::create Arr::of Arr::wrap Arr::range Arr::materialize |
Arr also accepts a Traversable/generator in its constructor and eagerly materializes it — great for arrays and small-to-medium query results. For huge or infinite sequences, use LazyCollection instead.
LazyCollection — memory-safe iterables
A generator-backed pipeline for large, expensive, or literally infinite iterables (file lines, DB cursors, ranges). Nothing runs until you call a terminal method (each, first, reduce, count, toArray, sum) — and operations like take()/takeWhile() let you short-circuit a source that never ends on its own.
Reading a large file lazily, line by line:
| Kind | Methods |
|---|---|
| Lazy (no work until consumed) | map filter reject take takeWhile skip chunk tap keys values |
| Terminal (consumes the pipeline) | each first reduce sum contains count toArray toArr() (→ Arr) |
| Static | LazyCollection::make($arrayOrGeneratorFn) LazyCollection::range($start, $end = null, $step = 1) LazyCollection::repeat($value, $times = null) |
Passing a fn(): iterable factory closure (rather than an already-created Generator) to make() is what lets a LazyCollection be safely iterated more than once — plain arrays work either way.
Num — number manipulation
Full list: format currency percentage ordinal roman toWords humanFileSize add subtract multiply divide abs round ceil floor clamp percentageOf isEven isOdd isPositive isNegative isZero isBetween isPrime, and statics random sum average min max range.
Country — ISO 3166 + dialing data
Resolves by alpha-2, alpha-3, numeric ISO code, or name — whichever you pass in.
Unknown identifiers throw Toolkit\Exceptions\UnknownCountryException; use Country::tryFind() if you'd rather get null.
Phone — phone numbers (powered by Country)
North American numbers format NANP-style automatically:
Honest limitation on isMobile(): the source dataset only has country-level dialing codes, not the detailed number-range tables carriers publish, so true mobile-vs-landline detection isn't reliably derivable from it. isMobile() returns null (unknown) unless you register prefixes yourself:
Invalid/unparseable numbers throw Toolkit\Exceptions\InvalidPhoneNumberException.
Email — validation & formatting
Register more free/disposable domains at runtime:
Email::fromValidated($addr) throws Toolkit\Exceptions\InvalidEmailException if the address is malformed; the plain constructor never throws (call isValid() yourself).
Data & attribution
resources/countries.json was built by merging your two uploaded files:
- ISO 3166 country list (names, alpha-2/3, numeric codes, TLDs, flags)
- Wikipedia's "List of telephone country codes" (dial codes, area-code hints, UTC offsets)
236 of 272 Wikipedia entries matched a real ISO country (the rest are things like satellite services, disputed territories, or sub-national exchanges that have no ISO code, e.g. Kosovo, Taiwan, Transnistria — they're simply not in your countries.json source). 237 of 249 ISO countries ended up with a dial code attached.