PHPackages                             dflydev/placeholder-resolver - 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. dflydev/placeholder-resolver

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

dflydev/placeholder-resolver
============================

Given a data source representing key =&gt; value pairs, resolve placeholders like ${foo.bar} to the value associated with the 'foo.bar' key in the data source.

v1.0.3(4y ago)14414.6M↓21.5%5[1 issues](https://github.com/dflydev/dflydev-placeholder-resolver/issues)3MITPHPPHP &gt;=5.3.2

Since Jul 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dflydev/dflydev-placeholder-resolver)[ Packagist](https://packagist.org/packages/dflydev/placeholder-resolver)[ Docs](https://github.com/dflydev/dflydev-placeholder-resolver)[ RSS](/packages/dflydev-placeholder-resolver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (3)

Placeholder Resolver
====================

[](#placeholder-resolver)

Given a data source representing key =&gt; value pairs, resolve placeholders like `${foo.bar}` to the value associated with the `foo.bar` key in the data source.

Placeholder Resolver is intended to be used at a relatively low level. For example, a configuration library could use Placeholder Resolver behind the scenes to allow for configuration values to reference other configuration values.

Example
-------

[](#example)

```
conn.driver: mysql
conn.db_name: example
conn.hostname: 127.0.0.1
conn.username: root
conn.password: pa$$word
```

Given the appropriate `DataSourceInterface` implementation to provide the above data as a set of key =&gt; value pairs, the Placeholder Resolver would resolve the value of `$dsnPattern` to `mysql:dbname=example;host=127.0.0.1`.

```
$dsnPattern = '${conn.driver}:dbname=${conn.db_name};host=${conn.hostname}';
$dsn = $placeholderResolver->resolveValue($dsnPattern);
// mysql:dbname=example;host=127.0.0.1
```

Requirements
------------

[](#requirements)

- PHP 5.3+

Usage
-----

[](#usage)

```
use Dflydev\PlaceholderResolver\RegexPlaceholderResolver;

// YourDataSource implements Dflydev\PlaceholderResolver\DataSource\DataSourceInterface
$dataSource = new YourDataSource;

// Create the placeholder resolver
$placeholderResolver = new RegexPlaceholderResolver($dataSource);

// Start resolving placeholders
$value = $placeholderResolver->resolvePlaceholder('${foo}');
```

The `RegexPlaceholderResolver` constructor accepts two additional arguments, a placeholder prefix and a placeholder suffix. The default placeholder prefix is `${` and the default placeholder suffix is `}`.

To handle placeholders that look like `` instead of `${foo.bar}`, one would instantiate the class like this:

```
$placeholderResolver = new RegexPlaceholderResolver($dataSource, '');
```

Placeholders can recursively resolve placeholders. For example, given a data source with the following:

```
array(
    'foo' => 'FOO',
    'bar' => 'BAR',
    'FOO.BAR' => 'BAZ!',
);
```

The placeholder `${${foo}.${bar}}` would internally be resolved to `${FOO.BAR}` before being further resolved to `BAZ!`.

Resolved placeholders are cached using the `CacheInterface`. The default `Cache` implementation is used unless it is explicitly set on the Placeholder Resolver.

```
// YourCache implements Dflydev\PlaceholderResolver\Cache\CacheInterface
$cache = new YourCache;

$placeholderResolver->setCache($cache);
```

License
-------

[](#license)

This library is licensed under the New BSD License - see the LICENSE file for details.

Community
---------

[](#community)

If you have questions or want to help out, join us in the #dflydev channel on irc.freenode.net.

Not Invented Here
-----------------

[](#not-invented-here)

Much of the ideas behind this library came from Spring's Property Placeholder Configurer implementation.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity58

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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.

###  Release Activity

Cadence

Every ~1142 days

Total

4

Last Release

1627d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d6029bd16a0e8a9b97358a75b54affa6baadc1d9b0ca7eab2b6dd6c681ad7a8?d=identicon)[simensen](/maintainers/simensen)

---

Top Contributors

[![simensen](https://avatars.githubusercontent.com/u/191200?v=4)](https://github.com/simensen "simensen (21 commits)")[![ArnaudLigny](https://avatars.githubusercontent.com/u/80580?v=4)](https://github.com/ArnaudLigny "ArnaudLigny (1 commits)")[![aurmil](https://avatars.githubusercontent.com/u/1309545?v=4)](https://github.com/aurmil "aurmil (1 commits)")[![beryllium](https://avatars.githubusercontent.com/u/602491?v=4)](https://github.com/beryllium "beryllium (1 commits)")

---

Tags

resolverplaceholder

### Embed Badge

![Health badge](/badges/dflydev-placeholder-resolver/health.svg)

```
[![Health](https://phpackages.com/badges/dflydev-placeholder-resolver/health.svg)](https://phpackages.com/packages/dflydev-placeholder-resolver)
```

###  Alternatives

[rybakit/arguments-resolver

ArgumentsResolver allows you to determine the arguments to pass to a function or method.

26107.7k7](/packages/rybakit-arguments-resolver)[emanueleminotto/faker-placehold-it-provider

placehold.it provider for Faker

1423.5k1](/packages/emanueleminotto-faker-placehold-it-provider)[sroze/argument-resolver

A lightweight utility to resolve method arguments based on types and names

1041.4k1](/packages/sroze-argument-resolver)

PHPackages © 2026

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