Download the PHP package efureev/support without Composer
On this page you can find all versions of the php package efureev/support. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package support
PHP Support
The small things you write in every project, written once.
Array and string helpers, collections, a dot-notation store, typed exceptions and a pile of traits — for PHP 8.5, with no runtime dependencies.
Why
Most projects grow their own helpers.php: a dot-notation getter, a slugifier, a bit-mask check.
This package is that file, extracted and hardened — 98% test coverage, PHPStan level 7, and a
strict test run that fails on warnings and deprecations.
- No runtime dependencies. Only
ext-ctype,ext-jsonandext-mbstring, all standard.ext-intlis optional and improves transliteration. - Multibyte-aware throughout. Case conversion, padding, truncation and masking count characters, not bytes, and work in any script.
- One exception hierarchy. Everything thrown implements a single interface, so one
catchcovers the whole package. - Nothing you cannot address. Global helper functions are convenient but shadowable; every one of them is also a static method on a class nothing can intercept.
Install
Installing on an older PHP
| PHP | Version | |------------|--------------------------------------------| | >= 8.5 | `composer require efureev/support "^6.1"` | | 8.4 | `composer require efureev/support "^5.3"` | | 8.1 – 8.3 | `composer require efureev/support "^4.19"` | | 7.4 – 8.0 | `composer require efureev/support "^3.0"` | | 7.2 – 7.4 | `composer require efureev/support "^2.0"` | Upgrading a major? See [UPGRADE.md](./UPGRADE.md).Arrays
Read and write nested data without a pile of isset().
Any separator you like, on every method:
Reshape a result set:
Flatten and unflatten:
Strings
Case conversion that understands more than ASCII:
URL-safe slugs, transliterating through ICU when ext-intl is available:
Trimming, masking, padding — all counting characters, not bytes:
Identifiers:
Collections
ArrayCollection is an ordered map: countable, iterable, ArrayAccess, JSON-serialisable.
Chain and branch without breaking the pipeline:
HashCollection is the string-keyed sibling, which derives a key from the element's class:
Storage
A dot-notation bag, reachable as an object, an array or a loop.
JSON, numbers, bits, base64
Enums
Two traits add the lookups PHP's enums leave out.
Exceptions
Every exception implements one interface, so a single catch covers the package even though the
concrete classes extend different SPL bases.
Traits
HasPrePostActions gives an object named callback groups to run around an operation. A callback
returning exactly false stops the group and makes runActions() return false, which is how a
listener vetoes the work:
All traits
| Trait | What it gives you | |--------------------------|-----------------------------------------------------------------------| | `Maker` | `::make(...)` static constructor | | `Singleton` | `::getInstance()`, protected constructor, unserialize guard | | `Thrower` | `::throw()`, `::throwIf()` on an exception class | | `UseErrorsBox` | collect errors on an object: `addError`, `firstError`, `errorsCount` | | `Metable` | attach metadata: `withMeta`, `metaAttribute`, `setMetaAttribute` | | `UseStorage` | back an object with a `Storage`, reachable as properties | | `UseConfigurableStorage` | `configurable()` plus a storage fallback for unknown keys | | `ConfigurableTrait` | configure an object from an array through setters or properties | | `ReadOnlyProperties` | expose chosen non-public properties for reading | | `HasPrePostActions` | register and run callback groups around an operation | | `Whener` | `when($condition, $callback)` for fluent chains | | `ConsolePrint` | `print()` / `printError()`, working outside the CLI SAPI too | | `TraitBooter` | Eloquent-style `bootXxx()` hooks for traits | | `TraitInitializer` | `initializeXxx()` hooks, run per instance |Conditional handlers
ConditionalHandler pairs a piece of work with the condition that guards it, so the two travel
together and the work is only built when it is actually needed. Both closures receive the same
arguments.
Useful for assembling a menu, a set of API fields or a list of tabs, where each entry knows for itself whether it belongs:
The condition can also be a plain boolean, and the handler is immutable — handleIf() returns a
new instance rather than mutating the old one:
PostgreSQL types
Elements are quoted only when the array literal requires it, and escaping is handled — a value containing a comma stays one element.
Testing helpers
Two traits for your own test suite. AdditionalAssertionsTrait needs phpunit/phpunit, declared
in suggest.
Global functions
The helpers are also available as global functions, and as static methods on Php\Support\Func:
Prefer the class in library code. Every global is declared under function_exists(), so a name
another package claimed first — Laravel defines value(), class_basename() and
class_uses_recursive() — wins silently, which makes behaviour depend on autoload order. Func
cannot be shadowed.
Full API reference
**`Arr`** — accessible, collapse, crossJoin, dataToArray, divide, dot, duplicates, except, exists, fillKeysByValues, first, flatten, fromPostgresArray, fromPostgresArrayWithBraces, fromPostgresPoint, get, has, isAssoc, isList, keyBy, last, map, merge, only, pluck, prepend, random, remove, removeByValue, replaceByTemplate, set, shuffle, sortRecursive, toArray, toIndexedArray, toPostgresArray, toPostgresPoint, undot, where, whereNotNull, wrap **`Str`** — after, before, between, clearCache, contains, endsWith, isRegExp, lcFirst, limit, mask, padBoth, padLeft, padRight, random, removeAccents, removeMultiSpace, replaceByTemplate, replaceStrTo, slugify, slugifyWithFormat, squish, startsWith, title, toCamel, toCamelInitCase, toDelimited, toKebab, toLowerCamel, toScreamingDelimited, toScreamingSnake, toSnake, trimPrefix, trimSuffix, truncate, ucFirst, ulid, uuid, wrap **`Json`** — decode, decodeOrThrow, encode, encodeOrThrow, htmlEncode, isValid, prettyPrint **`Number`** — clamp, format, humanize, isInteger, ordinal, percentage, safeInt, `MAX_SAFE_INTEGER` **`Bit`** — addFlag, checkFlag, decBinPad, flags, grant, hasAll, hasAny, hasFlagIn, removeFlag, toggleFlag **`B64`** — decode, decodeOrThrow, decodeSafe, encode, encodeSafe **`URLify`** — downcode, seemsUTF8 **`ArrayCollection`** — add, all, avg, chunk, clear, clone, collapse, concat, contains, containsKey, count, countBy, current, diff, each, every, exists, filter, findFirst, first, flatten, flip, get, getIterator, getKeys, getValues, groupBy, implode, indexOf, intersect, isEmpty, key, keyBy, last, lazy, map, mapByKey, mapInto, max, median, merge, min, next, partition, pipe, pluck, prepend, push, random, reduce, reject, remove, removeElement, reverse, set, skip, slice, some, sort, sortBy, sortDesc, sortKeys, sum, take, tap, testForAll, toArray, toJson, transform, unique, unless, values, when, whereInstanceOf, zip **`HashCollection`** — add, all, clear, contains, count, each, filter, find, get, getIterator, groupBy, hasKey, implode, isEmpty, keys, map, partition, reduce, remove, set, sortBy, toArray, values Both collections also implement `ArrayAccess` and `JsonSerializable`; those methods are left out of the lists above. **`Storage`** — all, clear, count, countRecursive, except, exist, get, isEmpty, merge, only, remove, set, toArray, plus property access, `ArrayAccess` and `foreach` **`Func`** — attributeToGetterMethod, attributeToSetterMethod, classBasename, classNamespace, classUsesRecursive, dataGet, doesTraitUse, eachValue, findGetterMethod, findSetterMethod, getPropertyValue, instance, isTrue, mapValue, publicPropertyExists, remoteCall, remoteStaticCall, remoteStaticCallOrThrow, traitUsesRecursive, value, when **Exceptions** — ExceptionInterface, plus ConfigException, Exception, InvalidArgumentException, InvalidCallException, InvalidConfigException, InvalidParamException, InvalidValueException, MethodNotAllowedException, MissingClassException, MissingConfigException, MissingMethodException, MissingPropertyException, NotSupportedException, UnknownMethodException, UnknownPropertyException **Enums** — casesToEscapeString, casesToString, fromName, hasName, hasValue, labels, names, random, toKeyValueArray, toValueKeyArray, tryFromName, values **`ConditionalHandler`** — make, handleIf, resolve, `__invoke` **Types** — Point, GeoPoint · **Interfaces** — Arrayable, JsonableGood to know
Install ext-intl if you slugify non-Latin text. Without it the bundled character maps cover
Latin, Cyrillic and Greek, but not the Œ/œ ligature or CJK.
Arr::fromPostgresArray cannot restore a null. The writer emits the NULL keyword correctly,
but the reader returns it as the string 'NULL', so a round trip is not value-preserving for null
elements.
Str caches its case conversions in a bounded, process-wide cache. Call Str::clearCache() in
a long-running worker if you convert unbounded user input.
Contributing
Bug reports and pull requests are welcome — see CONTRIBUTING.md.
License
MIT — see LICENSE.
All versions of support with dependencies
ext-ctype Version *
ext-json Version *
ext-mbstring Version *