Skip to content

Loading…

Interfaces #3

Merged
merged 2 commits into from

3 participants

@stof

This adds some missing functions in the HandlerInterface

@lsmith77 lsmith77 commented on an outdated diff
src/Monolog/Handler/HandlerInterface.php
@@ -18,7 +20,46 @@ namespace Monolog\Handler;
*/
interface HandlerInterface
{
- public function isHandling($record);
+ /**
+ * Checks whether the handler handles the record.
+ *
+ * @return Boolean
+ */
+ public function isHandling(array $record);
+
+ /**
+ * Handles a record.
+ *
+ * @param array $record The record to handle
+ * @return Boolean Whether the handler stops the propagation in the stack or not.
+ */
+ public function handle(array $record);

its custom (well at least in Symfony2 and in the rest of the file) to not have "public" in interfaces

@stof
stof added a note

This comes from Seldaek implementation :)

But you're right, I will remove it. I did not take care of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Seldaek Seldaek merged commit 7a912a4 into Seldaek:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
9 src/Monolog/Handler/AbstractHandler.php
@@ -12,6 +12,7 @@
namespace Monolog\Handler;
use Monolog\Logger;
+use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/**
@@ -35,12 +36,12 @@ public function __construct($level = Logger::DEBUG, $bubble = false)
$this->bubble = $bubble;
}
- public function isHandling($record)
+ public function isHandling(array $record)
{
return $record['level'] >= $this->level;
}
- public function handle($record)
+ public function handle(array $record)
{
if ($record['level'] < $this->level) {
return false;
@@ -61,7 +62,7 @@ public function handle($record)
return false === $this->bubble;
}
- abstract public function write($record);
+ abstract public function write(array $record);
public function close()
{
@@ -77,7 +78,7 @@ public function popProcessor()
return array_shift($this->processors);
}
- public function setFormatter($formatter)
+ public function setFormatter(FormatterInterface $formatter)
{
$this->formatter = $formatter;
}
View
8 src/Monolog/Handler/FingersCrossedHandler.php
@@ -53,7 +53,7 @@ public function __construct($handler, $actionLevel = Logger::WARNING, $bufferSiz
* @param array $record Records
* @return Boolean Whether the record was handled
*/
- public function handle($record)
+ public function handle(array $record)
{
if ($this->buffering) {
$this->buffer[] = $record;
@@ -85,10 +85,10 @@ public function reset()
}
/**
- * Implemented to comply with the AbstractHandler rqeuirements. Can not be called.
+ * Implemented to comply with the AbstractHandler requirements. Can not be called.
*/
- public function write($record)
+ public function write(array $record)
{
- throw new \LogicException('This method should not be called directly on the FingersCrossedHandler.');
+ throw new \BadMethodCallException('This method should not be called directly on the FingersCrossedHandler.');
}
}
View
45 src/Monolog/Handler/HandlerInterface.php
@@ -11,6 +11,8 @@
namespace Monolog\Handler;
+use Monolog\Formatter\FormatterInterface;
+
/**
* Interface that all Monolog Handlers must implement
*
@@ -18,7 +20,46 @@
*/
interface HandlerInterface
{
- public function isHandling($record);
+ /**
+ * Checks whether the handler handles the record.
+ *
+ * @return Boolean
+ */
+ function isHandling(array $record);
+
+ /**
+ * Handles a record.
+ *
+ * @param array $record The record to handle
+ * @return Boolean Whether the handler stops the propagation in the stack or not.
+ */
+ function handle(array $record);
+
+ /**
+ * Adds a processor in the stack.
+ *
+ * @param callable $callback
+ */
+ function pushProcessor($callback);
+
+ /**
+ * Removes the processor on top of the stack and returns it.
+ *
+ * @return callable
+ */
+ function popProcessor();
+
+ /**
+ * Sets the formatter.
+ *
+ * @param FormatterInterface $formatter
+ */
+ function setFormatter(FormatterInterface $formatter);
- public function handle($record);
+ /**
+ * Gets the formatter.
+ *
+ * @return FormatterInterface
+ */
+ function getFormatter();
}
View
4 src/Monolog/Handler/NullHandler.php
@@ -23,7 +23,7 @@
*/
class NullHandler extends AbstractHandler
{
- public function handle($record)
+ public function handle(array $record)
{
if ($record['level'] < $this->level) {
return false;
@@ -31,7 +31,7 @@ public function handle($record)
return false === $this->bubble;
}
- public function write($record)
+ public function write(array $record)
{
}
}
View
2 src/Monolog/Handler/StreamHandler.php
@@ -36,7 +36,7 @@ public function __construct($stream, $level = Logger::DEBUG, $bubble = true)
}
}
- public function write($record)
+ public function write(array $record)
{
if (null === $this->stream) {
if (!$this->url) {
View
2 src/Monolog/Handler/TestHandler.php
@@ -85,7 +85,7 @@ protected function hasRecord($record, $level = null)
return false;
}
- public function write($record)
+ public function write(array $record)
{
$this->recordsByLevel[$record['level']][] = $record;
$this->records[] = $record;
Something went wrong with that request. Please try again.