Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created March 22, 2011 14:14
Show Gist options
  • Save lukemorton/881268 to your computer and use it in GitHub Desktop.
Save lukemorton/881268 to your computer and use it in GitHub Desktop.
Just an example of Pimple DI
<?php
$logger = new Logger_Pimple(array(
'log_remote_endpoint' => 'https://secure.freeola.com',
'log_remote_user' => 'luke',
'log_remote_password' => 'luke',
));
$logger['log']->add(0, 'An error occured');
<?php
include 'Pimple.php';
class Logger_Pimple extends Pimple {
public function __construct(array $config = NULL)
{
if (isset($config))
{
$this->add($config);
}
$this->add(array(
'log' => function ($c)
{
$log = new Log;
return $log
->attach_logger($c['log_database'])
->attach_logger($c['log_remote'])
->attach_logger($c['log_file'])
;
},
'log_database' => function ($c)
{
return new Log_Database;
},
'log_remote' => function ($c)
{
return new Log_Remote(
$c['log_remote_endpoint'],
$c['log_remote_user'],
$c['log_remote_password']
);
},
'log_file' => function ($c)
{
return new Log_File;
},
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment