PHP code example of frdl / context
1. Go to this page and download the library: Download frdl/context 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' );
frdl / context example snippets
$items = [
'selected' => 'member2' ,
'test' => [
'member1' => '${test.member2}' ,
'member2' => 'FooBar' ,
'member2.prop1' => '${selected}.FooBar' ,
],
];
$context = \frdl\Context::create($items);
$content.= '$context->resolve()<pre>' ;
$content.= print_r($context->resolve(), true );
$content.= '</pre>' ;
$content.= '$context->get("test.member2.prop1")<pre>' ;
$content.= print_r($context->resolve('test.member2.prop1' ), true );
$content.= '</pre>' ;
$content.= '$context->resolve()->all()<pre>' ;
$content.= print_r($context->resolve()->all(), true );
$content.= '</pre>' ;
$content.= '$context->all()<pre>' ;
$content.= print_r($context->all(), true );
$content.= '</pre>' ;
$content.= '$context->resolve()->flatten()<pre>' ;
$content.= print_r($context->resolve()->flatten(), true );
$content.= '</pre>' ;
$dataSource = new \Dflydev\PlaceholderResolver\DataSource\ArrayDataSource($context->flatten()) ;
$placeholderResolver = new \Dflydev\PlaceholderResolver\RegexPlaceholderResolver($dataSource
, '${' , '}'
);
$value = $placeholderResolver->resolvePlaceholder('afsasf ${test.member1}' );
$content.= '$value<pre>' ;
$content.= print_r($value, true );
$content.= '</pre>' ;
$content.= 'test.member1<pre>' ;
$content.= print_r( $dataSource->get('test.member1' ), true );
$content.= '</pre>' ;
$servicesLegacyContainer = new \compiled\CompiledContainer();
try {
$configItems = [
];
$context = \frdl\ContextContainer::create($configItems, '${' , '}' );
}catch (\Exception $e){
print_r( $e->getMessage());
}
$acclimator = new ContainerAcclimator;
$items = [
];
$serviceContainer = $acclimator->acclimate($servicesLegacyContainer);
$contextContainer = $acclimator->acclimate($context);
$this ->container = \frdl\ContextContainer::create($items, '${' , '}' );
$this ->container->addContainer($serviceContainer);
$this ->container->addContainer($contextContainer);
$container = \frdlweb\Level2App::getInstance('production' , $projectDir. \DIRECTORY_SEPARATOR)
->getContainer()
;
$env = [];
$context = \frdl\ContextContainer::create($env);
$container->set('context' , $context);
$container->set('env' , $env);
$context->set('context.app.container.doc.title' , 'My TestCase Application' );
echo '<pre>' ;
print_r($env);
echo '</pre>' ;
echo '<pre>' ;
print_r($container->get('context' ));
echo '</pre>' ;
$s=serialize($container);
print_r('$s=serialize($container): <pre>' .gettype($s).'</pre>' );
echo '<pre>' .$s.'</pre>' ;
$c = unserialize($s);
print_r('$c = unserialize($s): <pre>' .gettype($c).'</pre>' );
print_r($c);
print_r($c->get('project' )->title);