Created
October 18, 2011 15:37
-
-
Save nerdsrescueme/1295735 to your computer and use it in GitHub Desktop.
Error
This file contains 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 | |
namespace Atom; | |
class Error { | |
private static $instance; | |
public static function instance(array $config = array()) | |
{ | |
if(static::$instance === null) | |
{ | |
static::$instance = new static($config); | |
} | |
return static::$instance; | |
} | |
private $properties = array(); | |
private $methods = array(); | |
public function __construct(array $config = array()) | |
{ | |
if(count($config) === 0) {} // Load defaul config (per environment?) | |
foreach($config as $key => $value) | |
{ | |
if($value instanceof \Closure) | |
{ | |
$this->methods[$key] = $value; | |
continue; | |
} | |
$this->properties[$key] = $value; | |
} | |
} | |
public function __call($method, $parameters) | |
{ | |
if(isset($this->methods[$method])) | |
{ | |
return call_user_func_array(array($this. $method), $parameters); | |
} | |
throw new \BadMethodCallException('Method ['.$method.'] is not defined in your error configuration.'); | |
} | |
public function __get($property) | |
{ | |
if(isset($this->properties[$property])) | |
{ | |
return $this->properties[$property]; | |
} | |
throw new \InvalidArgumentException('Property ['.$property.'] is not defined in your error configuration.'); | |
} | |
} | |
namespace Atom\Design; | |
class Commander { | |
protected $comandee; | |
public function __construct($commandee) | |
{ | |
$this->comandee = $commandee; | |
} | |
abstract function execute(); | |
public function __invoke() | |
{ | |
$this->execute(); | |
} | |
} | |
namespace Atom; | |
class Log extends \Atom\Design\Commander { | |
public function execute() | |
{ | |
$this->comandee->log(); | |
} | |
} | |
class Debug extends \Atom\Design\Commander { | |
public function execute() | |
{ | |
$this->comandee->debug(); | |
} | |
} | |
namespace Atom\Debug; | |
class Sql extends \Atom\Design\Commander { | |
public function execute() | |
{ | |
$this->comandee->sql(); | |
} | |
} | |
class Print extends \Atom\Design\Commander { | |
public function execute() | |
{ | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment