PHP code example of dotink / affinity

1. Go to this page and download the library: Download dotink/affinity library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dotink / affinity example snippets


$engine = new Affinity\Engine(
	new Affinity\NativeDriver('/path/to/configs'),
	new Affinity\NativeDriver('/path/to/actions')
);

$engine->start('production', ['app' => $app, 'di' => $di]);

$engine->start('production, europe', $context);

return Affinity\Config::create([

	'key' => 'value',

	'parent' => [
		'child' => 'value'
	]
]);

$engine->fetch('test', 'key', 'default');

$engine->fetch('test', 'parent.child', 'default');

$engine->fetch('@providers', 'mapping', array());

return Affinity\Config::create(['providers'], [
	'@providers' => [
		'mapping' => [
			'Dotink\Package\UsefulInterface' => 'My\Concrete\ProviderClass'
		]
	]
]);

foreach ($engine->fetch('@providers') as $id) {
	$provider_mapping = $engine->fetch($id, '@providers.mapping', []);
	$provider_params  = $engine->fetch($id, '@providers.params',  []);

	foreach ($provider_mapping as $interface => $provider) {
		$injector->alias($interface, $provider);
	}

	foreach ($provider_params as $provider => $params) {
		$injector->define($provider, $params);
	}
}

return Affinity\Action::create(function($app, $di) {
	//
	// Your bootstrap logic here
	//
});

return Affinity\Action::create(['core'], function($app, $di) {
	//
	// Your bootstrap logic here
	//
});

$engine->start('production', ['app' => $app, 'di' => $di]);