PHPackages                             bolt/common - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bolt/common

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bolt/common
===========

🧰 Common utilities for all Bolt libraries

3.0.7(4y ago)18359.8k↑51.4%6[1 issues](https://github.com/bolt/common/issues)[1 PRs](https://github.com/bolt/common/pulls)8MITPHPPHP &gt;=7.2.5 || ^8.0CI failing

Since Aug 1Pushed 4y ago11 watchersCompare

[ Source](https://github.com/bolt/common)[ Packagist](https://packagist.org/packages/bolt/common)[ RSS](/packages/bolt-common/feed)WikiDiscussions 3.0 Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (36)Used By (8)

Bolt Common
===========

[](#bolt-common)

This library provides utility functions to help simplify menial tasks.

Where possible, this library provides some wrappers around some built-in functions. Our code should always throw exceptions instead of triggering errors/warnings/notices (excluding deprecation warnings).

Table of Contents:

- [Arr](#arr)
- [Assert](#assert)
- [Deprecated](#deprecated)
- [Ini](#ini)
- [Json](#json)
- [Serialization](#serialization)
- [Str](#str)

---

Arr
---

[](#arr)

Functions to deal with arrays.

Assert
------

[](#assert)

Additional assertions built on `Webmozart\Assert`.

### `isArrayAccessible`

[](#isarrayaccessible)

Throws `InvalidArgumentException` if `$value` is not an array or object implementing `ArrayAccess`.

```
isArrayAccessible($value, string $message = ''): void
```

### `isInstanceOfAny`

[](#isinstanceofany)

Throws `InvalidArgumentException` if `$value` is not an instance of one of the given classes/interfaces.

```
isInstanceOfAny($value, string[] $classes, string $message = ''): void
```

### `isIterable`

[](#isiterable)

Throws `InvalidArgumentException` if `$value` is not an *iterable*. Same as `isTraversable()`, just a better name.

```
isIterable($value, string $message = ''): void
```

`Deprecated`
------------

[](#deprecated)

Helper methods for triggering deprecation warnings.

### `warn`

[](#warn)

Shortcut for triggering a deprecation warning for something.

```
warn(string $subject, string|float $since = null, string $suggest = ''): void
```

Examples:

```
// Triggers warning: "Doing foo is deprecated."
Deprecated::warn('Doing foo');

// Triggers warning: "Doing foo is deprecated since 3.3 and will be removed in 4.0."
Deprecated::warn('Doing foo', 3.3);

// Triggers warning: "Doing foo is deprecated since 3.3 and will be removed in 4.0. Do bar instead."
Deprecated::warn('Doing foo', 3.3, 'Do bar instead');
```

### `method`

[](#method)

Shortcut for triggering a deprecation warning for a method.

```
method(string|float $since = null, string $suggest = '', string $method = null): void
```

`$suggest` can be a sentence describing what to use instead. Or it can be a method name or `class::method` which will be converted to a sentence.

`$method` defaults to the method/function it was called from.

- If called from constructor, warning message says the class is deprecated.
- If called from magic method, warning message says the method/property called with is deprecated.

Example:

```
class Foo
{
    public function world()
    {
        // Triggers warning: "Foo::world() is deprecated since 3.3 and will be removed in 4.0. Use hello() instead."
        Deprecated::method(3.3, 'hello');
    }
}
```

### `cls`

[](#cls)

Shortcut for triggering a deprecation warning for a class.

```
cls(string $class, string|float $since = null, string $suggest = null): void
```

`$suggest` can be a sentence describing what to use instead. Or it can be a class name which will be converted to a sentence.

Examples:

```
// Triggers warning: "Foo\Bar is deprecated."
Deprecated::cls('Foo\Bar');

// Triggers warning: "Foo\Bar is deprecated. Use Bar\Baz instead."
Deprecated::cls('Foo\Bar', null, 'Bar\Baz');
```

`Ini`
-----

[](#ini)

Handles setting and retrieving values from PHP's configuration.

### `has`

[](#has)

Checks whether the key exists.

```
has(string $key): bool
```

### `getStr`

[](#getstr)

Get a string value. The default is returned if the key does not exist or the value is empty.

```
getStr(string $key, string $default = null): ?string
```

### `getBool`

[](#getbool)

Get a boolean value. False is returned if the key does not exist or the value is empty.

```
getBool(string $key): bool
```

### `getNumeric`

[](#getnumeric)

Get a numeric value. The default is returned if the key does not exist or the value is empty.

```
getNumeric(string $key, int|float $default = null): int|float|null
```

### `getBytes`

[](#getbytes)

Get a memory size value, such as `memory_limit`, and convert it to an integer. The default is returned if the key does not exist or the value is empty.

```
getBytes(string $key, int $default = null): ?int
```

### `set`

[](#set)

Set a new value for the given key. Throws `RuntimeException` if the key does not exist, it is not editable, or something goes wrong.

```
set(string $key, ?scalar $value): void
```

`Json`
------

[](#json)

Handles JSON parsing/dumping with error handling.

### `parse`

[](#parse)

Parses JSON *string* to *array* or *scalar*. Throws `ParseException` if anything goes wrong.

```
parse(string $json, int $options = 0, int $depth = 512): string
```

We use [`seld/jsonlint`](https://github.com/Seldaek/jsonlint) to determine why the parsing failed and include it in the exception message.

### `dump`

[](#dump)

Dumps *mixed* to JSON *string*. Throws `DumpException` if anything goes wrong.

```
dump(mixed $data, int $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE, int $depth = 512): string
```

If input contains invalid UTF-8 characters we try to convert these for you before failing.

### `test`

[](#test)

Returns whether the string is valid JSON.

```
test(string $json): bool
```

`Serialization`
---------------

[](#serialization)

Handles PHP serialization parsing/dumping with error handling.

### `parse`

[](#parse-1)

Parses PHP serialized *string*.

Throws `ParseException` if a serialized class cannot be found or anything else goes wrong.

```
parse(string $value, array $options = []): mixed
```

Note: `$options` parameter is ignored on PHP 5.

See [`unserialize()`](http://php.net/manual/en/function.unserialize.php) for details.

### `dump`

[](#dump-1)

Dumps anything to a PHP serialized *string*.

Throws `DumpException` if the input is not serializable or anything else goes wrong.

```
dump(mixed $value): string
```

`Str`
-----

[](#str)

Common string methods.

### `replaceFirst`

[](#replacefirst)

Replaces the first occurrence of the $search text on the $subject.

```
replaceFirst(string $subject, string $search, string $replace, bool $caseSensitive = true): string
```

### `replaceLast`

[](#replacelast)

Replaces the last occurrence of the $search text on the $subject.

```
replaceLast(string $subject, string $search, string $replace, bool $caseSensitive = true): string
```

### `removeFirst`

[](#removefirst)

Removes the first occurrence of the $search text on the $subject.

```
removeFirst(string $subject, string $search, bool $caseSensitive = true): string
```

### `removeLast`

[](#removelast)

Removes the last occurrence of the $search text on the $subject.

```
removeLast(string $subject, string $search, bool $caseSensitive = true): string
```

### `splitFirst`

[](#splitfirst)

Splits a $subject on the $delimiter and returns the first part.

```
splitFirst(string $subject, string $delimiter): string
```

### `splitLast`

[](#splitlast)

Splits a $subject on the $delimiter and returns the last part.

```
splitLast(string $subject, string $delimiter): string
```

### `endsWith`

[](#endswith)

Returns whether the subjects ends with the search string.

```
endsWith(string $subject, string $search, bool $caseSensitive = true): bool
```

### `className`

[](#classname)

Returns the class name without the namespace, of a string FQCN, or object.

```
className(string|object $class): string
```

### `humanize`

[](#humanize)

Converts a string from camel case and snake case to a human readable string.

```
humanize(string $text): string
```

### `camelCase`

[](#camelcase)

Converts a string from snake case to camel case.

```
camelCase(string $text, bool $lowercaseFirstChar = false): string
```

### `snakeCase`

[](#snakecase)

Converts a string from camel case to snake case.

```
snakeCase(string $text): string
```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~46 days

Recently: every ~10 days

Total

35

Last Release

1698d ago

Major Versions

1.1.x-dev → v2.0.02018-09-29

2.1.10 → 3.0.02020-11-10

2.1.11 → 3.0.32021-02-04

2.1.12 → 3.0.52021-09-16

2.0.x-dev → 3.0.62021-09-28

PHP version history (4 changes)v1.0.0PHP ^5.5 || ^7.0

v2.0.0PHP ^7.1

3.0.0PHP &gt;=7.2.5

3.0.1PHP &gt;=7.2.5 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a15c90b32e75c27fc63f79357a914b4caa7af5fdb69a2e150341515ddececf95?d=identicon)[Macintosh\_plus](/maintainers/Macintosh_plus)

![](https://avatars.githubusercontent.com/u/1835343?v=4)[Bob van de Vijver](/maintainers/bobvandevijver)[@bobvandevijver](https://github.com/bobvandevijver)

![](https://avatars.githubusercontent.com/u/3901745?v=4)[Tobias Feijten](/maintainers/tobias-93)[@tobias-93](https://github.com/tobias-93)

![](https://avatars.githubusercontent.com/u/1833361?v=4)[Bob den Otter](/maintainers/bobdenotter)[@bobdenotter](https://github.com/bobdenotter)

![](https://avatars.githubusercontent.com/u/5082?v=4)[Ross Riley](/maintainers/rossriley)[@rossriley](https://github.com/rossriley)

---

Top Contributors

[![bobdenotter](https://avatars.githubusercontent.com/u/1833361?v=4)](https://github.com/bobdenotter "bobdenotter (58 commits)")[![CarsonF](https://avatars.githubusercontent.com/u/932566?v=4)](https://github.com/CarsonF "CarsonF (55 commits)")[![GwendolenLynch](https://avatars.githubusercontent.com/u/1427081?v=4)](https://github.com/GwendolenLynch "GwendolenLynch (26 commits)")[![I-Valchev](https://avatars.githubusercontent.com/u/7093518?v=4)](https://github.com/I-Valchev "I-Valchev (11 commits)")[![JarJak](https://avatars.githubusercontent.com/u/4981490?v=4)](https://github.com/JarJak "JarJak (7 commits)")[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (1 commits)")[![mcdennem](https://avatars.githubusercontent.com/u/49211363?v=4)](https://github.com/mcdennem "mcdennem (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

boltphp

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/bolt-common/health.svg)

```
[![Health](https://phpackages.com/badges/bolt-common/health.svg)](https://phpackages.com/packages/bolt-common)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5275.9M121](/packages/symplify-monorepo-builder)[craftcms/feed-me

Import content from XML, RSS, CSV or JSON feeds into entries, categories, Craft Commerce products, and more.

293952.6k33](/packages/craftcms-feed-me)[phpactor/phpactor

PHP refactoring and intellisense tool for text editors

1.9k17.1k1](/packages/phpactor-phpactor)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

3014.6M26](/packages/vaimo-composer-patches)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12525.9M149](/packages/phpdocumentor-reflection)

PHPackages © 2026

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