PHP code example of mindplay / stockpile
1. Go to this page and download the library: Download mindplay/stockpile 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/ */
mindplay / stockpile example snippets
use mindplay\stockpile\Container;
/**
* @property string $db_username
* @property string $db_password
*
* @property-read PDO $db application-wide database connection
*/
class MyApp extends Container
{
...
}
$container = new MyApp(__DIR__ . '/config');
$container->load('default.php'); // load and execute "config/default.php"
/** @var MyApp $this */
$this->db_username = 'foo';
$this->db_password = 'bar';
$container->register(
'view',
function (FileCache $cache) {
// cache argument injected via $container->cache
return new ViewEngine($cache, ...);
}
);
$container->configure(
function (PDO $db) {
$db->exec("set names utf8");
}
);
$container->db_username = '...';
$container->db_password = '...';
$container->seal(); // prevent further changes (exception if incomplete)
$container->logger = new Logger(...); // eager construction, vs lazy register()
class MyContainer extends Container
{
/**
* @return CacheProvider
*/
protected function getCache()
{
return new FileCache($this->getRootPath() . '/cache');
}
}