by dflydev

Provides a mechanism to resolve placeholders from an arbitrary data source.

130 Stars 3 Forks Last release: Not found MIT License 18 Commits 3 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Placeholder Resolver

Given a data source representing key => value pairs, resolve placeholders like

to the value associated with the
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.


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

Given the appropriate

implementation to provide the above data as a set of key => value pairs, the Placeholder Resolver would resolve the value of
$dsnPattern = '${conn.driver}:dbname=${conn.db_name};host=${conn.hostname}';
$dsn = $placeholderResolver->resolveValue($dsnPattern);
// mysql:dbname=example;host=


  • PHP 5.3+


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}');


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 
, 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:

    'foo' => 'FOO',
    'bar' => 'BAR',
    'FOO.BAR' => 'BAZ!',

The placeholder

would internally be resolved to
before being further resolved to

Resolved placeholders are cached using the

. The default
implementation is used unless it is explicitly set on the Placeholder Resolver.
// YourCache implements Dflydev\PlaceholderResolver\Cache\CacheInterface
$cache = new YourCache;



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


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

Not Invented Here

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.