Skip to content

Commit

Permalink
Changed non PSR-0 lib to use class_alias() and removed ::format(), in…
Browse files Browse the repository at this point in the history
…stead use :: directly.
  • Loading branch information
jbroadway committed Jan 12, 2012
1 parent ee4f5b3 commit bd1812a
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 31 deletions.
16 changes: 2 additions & 14 deletions lib/Analog.php
Expand Up @@ -14,21 +14,9 @@
});

/**
* We simply extend the main class so that Analog is
* We simply alias extend the main class so that Analog is
* available as a global class. This saves us adding
* `use \Analog\Analog` at the top of every file,
* or worse, typeing `\Analog\Analog::log()` everywhere.
*/
class Analog extends \Analog\Analog {
/**
* We need to override format() to always write to
* the parent, since the pre-built handlers have to
* assume they're using the PSR-0 class.
*/
public static function format ($format = false) {
if ($format) {
\Analog\Analog::$format = $format;
}
return \Analog\Analog::$format;
}
}
class_alias ('\Analog\Analog', 'Analog');
10 changes: 0 additions & 10 deletions lib/Analog/Analog.php
Expand Up @@ -132,16 +132,6 @@ public static function handler ($handler = false) {
return self::$handler;
}

/**
* Format getter/setter.
*/
public static function format ($format = false) {
if ($format) {
self::$format = $format;
}
return self::$format;
}

/**
* Get the log info as an associative array.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Analog/Handler/Buffer.php
Expand Up @@ -45,7 +45,7 @@ public static function init ($handler) {
self::$destructor = new \Analog\Handler\Buffer\Destructor ();

return function ($info) {
Buffer::$buffer .= vsprintf (\Analog\Analog::format (), $info);
Buffer::$buffer .= vsprintf (\Analog\Analog::$format, $info);
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Analog/Handler/File.php
Expand Up @@ -27,7 +27,7 @@ public static function init ($file) {
throw new \RuntimeException ('Could not lock file');
}

fwrite ($f, vsprintf (\Analog\Analog::format (), $info));
fwrite ($f, vsprintf (\Analog\Analog::$format, $info));
flock ($f, LOCK_UN);
fclose ($f);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/Analog/Handler/LevelBuffer.php
Expand Up @@ -44,7 +44,7 @@ public static function init ($handler, $until_level = 2) {
self::$handler = $handler;

return function ($info) use ($until_level) {
LevelBuffer::$buffer .= vsprintf (\Analog\Analog::format (), $info);
LevelBuffer::$buffer .= vsprintf (\Analog\Analog::$format, $info);
if ($info['level'] <= $until_level) {
// flush and reset the buffer
LevelBuffer::flush ();
Expand Down
2 changes: 1 addition & 1 deletion lib/Analog/Handler/Stderr.php
Expand Up @@ -16,7 +16,7 @@
class Stderr {
public static function init () {
return function ($info) {
file_put_contents ('php://stderr', vsprintf (\Analog\Analog::format (), $info));
file_put_contents ('php://stderr', vsprintf (\Analog\Analog::$format, $info));
};
}
}
2 changes: 1 addition & 1 deletion lib/Analog/Handler/Variable.php
Expand Up @@ -18,7 +18,7 @@
class Variable {
public static function init (&$log) {
return function ($info) use (&$log) {
$log .= vsprintf (\Analog\Analog::format (), $info);
$log .= vsprintf (\Analog\Analog::$format, $info);
};
}
}
4 changes: 2 additions & 2 deletions tests/AnalogTest.php
Expand Up @@ -17,7 +17,7 @@ function test_default () {

function test_format () {
// Test changing the format string and write again
Analog::format ("%s, %s, %d, %s\n");
Analog::$format = "%s, %s, %d, %s\n";
Analog::log ('Foo');
$this->assertEquals (
sprintf ("%s, %s, %d, %s\n", 'localhost', gmdate ('Y-m-d H:i:s'), 3, 'Foo'),
Expand All @@ -29,7 +29,7 @@ function test_format () {
function test_handler () {
// Test logging using a closure
Analog::handler (function ($msg) {
AnalogTest::$log .= vsprintf (Analog::format (), $msg);
AnalogTest::$log .= vsprintf (Analog::$format, $msg);
});

Analog::log ('Testing');
Expand Down

0 comments on commit bd1812a

Please sign in to comment.