PHPackages                             telesto/utils - 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. telesto/utils

ActiveLibrary

telesto/utils
=============

General-purpose library for php.

07PHP

Since May 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/mdopt/TelestoUtils)[ Packagist](https://packagist.org/packages/telesto/utils)[ RSS](/packages/telesto-utils/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (0)

\###General-purpose library for php.

The following examples use shorter array syntax from php 5.4+ for brevity, but the library works also for older versions (5.3.2+ to be precise).

\####Strings:

```
use Telesto\Utils\StringUtil;
```

`StringUtil::explode` (standard explode with escaping delimiter feature)

```
StringUtil::explode('.', 'first\.dont_explode_this.second', null, ['escapeChar'=> '\\']);
// ['first.dont_explode_this', 'second']
```

`StringUtil::implode` (standard implode with escaping delimiter feature)

```
StringUtil::implode('.', ['first.escape_this_dot', 'second'], ['escapeChar'=> '\\']);
// 'first\.escape_this_dot.second'
```

`StringUtil::strposAll` (works like strpos but returns all positions)

```
StringUtil::strposAll(' @ @@ @', '@');
// [1, 3, 4, 6]
```

`StringUtil::substrConsecutiveCounts`

```
StringUtil::substrConsecutiveCounts(' @ @@@ @@', '@');
// [1, 3, 2]
```

`StringUtil::substrMaxConsecutiveCount`

```
StringUtil::substrMaxConsecutiveCount(' @ @@@ @@', '@');
// 3
```

\####Arrays:

```
use Telesto\Utils\ArrayUtil;
```

Set of array functions that also work for objects implementing ArrayAccess interface.

`ArrayUtil::getKeys` (works like array\_keys, but also supports iterators)

```
ArrayUtil::getKeys(new \ArrayObject(['x' => 10, 'y' => 20]));
// ['x', 'y']
```

`ArrayUtil::getElementByKeyPath`

```
ArrayUtil::getElementByKeyPath(
    [
        'points'    => [
            [
                'x' => 10,
                'y' => 20
            ],
            [
                'x' => 100,
                'y' => 200
            ]
        ]
    ],
    'points.1.y'
);
// 200
```

`ArrayUtil::hasElementAtKeyPath`

```
ArrayUtil::hasElementAtKeyPath(
    [
        'point' => [
            'x' => 10,
            'y' => 20
        ]
    ],
    'point.x'
);
// true

ArrayUtil::hasElementAtKeyPath(
    [
        'point' => [
            'x' => 10,
            'y' => 20
        ]
    ],
    'point.z'
);
// false
```

`ArrayUtil::setElementByKeyPath`

```
$array = [
    'point' => [
        'x' => 10,
        'y' => 20
    ]
];

ArrayUtil::setElementByKeyPath($array, 'point.z', 30);

/* $array is now [
    'point' => [
        'x' => 10,
        'y' => 20,
        'z' => 30
    ]
]
*/
```

`ArrayUtil::unsetElementByKeyPath`

```
$array = [
    'point' => [
        'x' => 10,
        'y' => 20
    ]
];

ArrayUtil::unsetElementByKeyPath($array, 'point.y');

/* $array is now [
    'point' => [
        'x' => 10
    ]
]
*/
```

\####Array Operations

`Telesto\Utils\Arrays` component provides interface for generic operations on arrays and objects implementing ArrayObject interface(some operations have additional requirements).

There are 2 types of operations:

- transformations (they produce output given the input)
- overwrites (they are given 2 arguments and use the first to overwrite the second)

Every transformation can be done by creating a new array and overwriting it(and that's the way it's implemented).

Every transformer is an instance of `Telesto\Utils\Arrays\Transformation\Transformer` interface. Every overwriter is an instance of `Telesto\Utils\Arrays\Overwriting\Overwriter` interface.

You can create these instances by yourself. The following example shows how to create and use transformer to perform 'copy by key path map' operation.

```
use Telesto\Utils\Arrays\Overwriting\Copy\KeyPathMap\BasicOverwriter as KeyPathMapOverwriter;
use Telesto\Utils\Arrays\Transformation\CreateAndOverwriteTransformer;

$transformer = new CreateAndOverwriteTransformer(
    new KeyPathMapOverwriter([
        'points.0.x'    => 'p.x',
        'points.0.y'    => 'p.y'
    ])
);

$output = $transformer->transform([
    'points'    => [
        [
            'x' => 10,
            'y' => 20
        ]
    ]
]);

/*
$output is [
    'p' => [
        'x' => 10,
        'y' => 20
    ]
]
*/
```

But this is requires a lot of boilerplate code. Here's a shorter version that uses OperationFacade:

```
use Telesto\Utils\Arrays\OperationFacade;

$transformer = OperationFacade::createTransformer('copy.byKeyPathMap', [
    'points.0.x'    => 'p.x',
    'points.0.y'    => 'p.y'
]);

$output = $transformer->transform([
    'points'    => [
        [
            'x' => 10,
            'y' => 20
        ]
    ]
]);
```

or, if you only need to perform one operation and never use the transformer again:

```
use Telesto\Utils\Arrays\OperationFacade;

$output = OperationFacade::transform(
    [
        'points'    => [
            [
                'x' => 10,
                'y' => 20
            ]
        ]
    ],
    'copy.byKeyPathMap',
    [
        'points.0.x'    => 'p.x',
        'points.0.y'    => 'p.y'
    ]
);
```

License: MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fcd5ed334ff89e048108793eb1117460219fab88051a2ab9dac7c83c51de82f?d=identicon)[mdopt](/maintainers/mdopt)

---

Top Contributors

[![mdopt](https://avatars.githubusercontent.com/u/148892?v=4)](https://github.com/mdopt "mdopt (36 commits)")

### Embed Badge

![Health badge](/badges/telesto-utils/health.svg)

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

PHPackages © 2026

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