Created
March 22, 2011 14:14
-
-
Save lukemorton/881268 to your computer and use it in GitHub Desktop.
Just an example of Pimple DI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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