-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworking Log / Event system slightly
* Added traits for EventDispatcherAwareTrait and LoggerAwareTrait for PHP 5.4+ use. * ClosureLogAdapter added * All *LogAdapter classes now allow for a `null` log object * Moved around the event dispatching methods for Workers This commit contains general changes preparing for the daemons.
- Loading branch information
1 parent
c105b62
commit 100e8e2
Showing
9 changed files
with
254 additions
and
39 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Event; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* Provides methods to use with the Symfony EventDispatcher component. | ||
* | ||
* @author Justin Rainbow <justin.rainbow@gmail.com> | ||
*/ | ||
trait EventDispatcherAwareTrait | ||
{ | ||
protected $dispatcher; | ||
|
||
/** | ||
* Sets an instance of the EventDispatcherInterface for this object. | ||
* If the `$dispatcher` is null, the object must remove any | ||
* current EventDispatcherInterface assigned to it. | ||
* | ||
* @param EventDispatcherInterface $dispatcher | ||
*/ | ||
public function setEventDispatcher(EventDispatcherInterface $dispatcher = null) | ||
{ | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
/** | ||
* Checks if there is an EventDispatcher available to the current object. | ||
* | ||
* @return Boolean | ||
*/ | ||
public function hasEventDispatcher() | ||
{ | ||
return null !== $this->dispatcher; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Log; | ||
|
||
/** | ||
* Abstract log adapter for Presque | ||
*/ | ||
class ClosureLogAdapter implements LoggerInterface | ||
{ | ||
protected $log; | ||
|
||
public function __construct(\Closure $log = null) | ||
{ | ||
$this->log = $log; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function emerg($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'emerg', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function alert($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'alert', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function crit($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'crit', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function err($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'err', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function warn($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'warn', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function notice($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'notice', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function info($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'info', $context); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function debug($message, array $context = array()) | ||
{ | ||
if (null !== $this->log) { | ||
call_user_func($this->log, $message, 'debug', $context); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Log; | ||
|
||
trait LoggerAwareTrait | ||
{ | ||
protected $logger; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setLogger(LoggerInterface $logger = null) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function hasLogger() | ||
{ | ||
return null !== $this->logger; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.