1. Go to this page and download the library: Download pyrsmk/chernozem 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/ */
pyrsmk / chernozem example snippets
$chernozem = new Chernozem\Container();
// Set a value
$chernozem['foo'] = 72;
// Get a value
echo $chernozem['foo'];
// Test a value
if(isset($chernozem['foo'])) {
// 'foo' value exists
}
// Remove a value
unset($chernozem['foo']);
// Set a value
$chernozem->set('foo', 72);
// Get a value
echo $chernozem->get('foo');
// Test a value
if($chernozem->has('foo')) {
// 'foo' value exists
}
// Remove a value
$chernozem->remove('foo');
// Set a value
$chernozem->setFoo(72);
// Get a value
echo $chernozem->getFoo();
$chernozem['some_service'] = $chernozem->factory(function($chernozem) {
return new Some_Service();
});
$chernozem['some_service'] = $chernozem->service(function($chernozem) {
return new Some_Service();
});
class MyService implements Chernozem\ServiceProviderInterface {
public function register(Interop\Container\ContainerInterface $container) {
$container['some_service1'] = new Some_Service();
$container['some_service2'] = new Another_Service();
$container['an_option'] = '[email protected]';
}
}
$chernozem->register(new MyService());
// Set a list of fruits
$chernozem['fruits'] = ['apple', 'banana', 'pear'];
// Set type hinting
$chernozem->hint('fruits', 'array');
// Oops! Wrong type!
$chernozem['fruits'] = 72;
// Set a 'mailer' service
$chernozem['mailer'] = $chernozem->service(function($chernozem) {
return new Mailer();
});
// Mark as read onyl
$chernozem->readonly('mailer');
$chernozem->setter('foo_service', function($service) {
throw new Exception("'foo_service' is already set!");
return $service; // Never run, it's only for the example
});
$chernozem->getter('foo_service', function($service) {
$service->executeSomeAction();
$service->executeAnotherAction();
return $service;
});
$delegate_container = new SomeVendor\Container();
// ... some stuff ...
$chernozem->delegate($delegate_container);
$chernozem['some_service'] = $chernozem->service(function($delegate_container) {
$some_service = new Some_Service();
// Load an option that is registered in the delegate container
$some_service->setOption('some_option', $delegate_container->get('some_option'));
return $some_service;
});
// Instantiate containers
$container1 = new SomeVendor\Container();
$container2 = new AnotherVendor\Container();
// ... some stuff ...
// Add containers to the composite container
$composite = new Chernozem\Composite();
$composite->add($container1);
$composite->add($container2);
echo $composite['foo'];
if(isset($composite['foo'])){
// the 'foo' key exists
}
echo count($chernozem);
foreach($chernozem as $id => $value) {
var_dump($value);
}
$chernozem['service'] = $chernozem->service(function() {
// First service
});
unset($chernozem['service']);
$chernozem['service'] = $chernozem->service(function() {
// New service
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.