From c8dd8f02eb618d6c0ca4a22316ca3bbd830e15a1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 2 Jul 2014 23:11:39 +0200 Subject: [PATCH] Finished #1555 todo list --- src/spl/AttachableLogger.php | 40 ++++++++++++++++ src/spl/AttachableThreadedLogger.php | 70 ++++++++++++++++++++++++++++ src/spl/LoggerAttachment.php | 34 ++++++++++++++ src/spl/ThreadedLogger.php | 46 ------------------ src/spl/ThreadedLoggerAttachment.php | 7 +-- 5 files changed, 145 insertions(+), 52 deletions(-) create mode 100644 src/spl/AttachableLogger.php create mode 100644 src/spl/AttachableThreadedLogger.php create mode 100644 src/spl/LoggerAttachment.php diff --git a/src/spl/AttachableLogger.php b/src/spl/AttachableLogger.php new file mode 100644 index 0000000000..dfe76830f5 --- /dev/null +++ b/src/spl/AttachableLogger.php @@ -0,0 +1,40 @@ +attachment instanceof \ThreadedLoggerAttachment){ + $this->attachment->addAttachment($attachment); + }else{ + $this->attachment = $attachment; + } + } + + /** + * @param ThreadedLoggerAttachment $attachment + */ + public function removeAttachment(\ThreadedLoggerAttachment $attachment){ + if($this->attachment instanceof \ThreadedLoggerAttachment){ + if($this->attachment === $attachment){ + $this->attachment = null; + foreach($attachment->getAttachments() as $attachment){ + $this->addAttachment($attachment); + } + } + } + } + + public function removeAttachments(){ + if($this->attachment instanceof \ThreadedLoggerAttachment){ + $this->attachment->removeAttachments(); + $this->attachment = null; + } + } + + /** + * @return \ThreadedLoggerAttachment[] + */ + public function getAttachments(){ + $attachments = []; + if($this->attachment instanceof \ThreadedLoggerAttachment){ + $attachments[] = $this->attachment; + $attachments += $this->attachment->getAttachments(); + } + return $attachments; + } +} \ No newline at end of file diff --git a/src/spl/LoggerAttachment.php b/src/spl/LoggerAttachment.php new file mode 100644 index 0000000000..9128087540 --- /dev/null +++ b/src/spl/LoggerAttachment.php @@ -0,0 +1,34 @@ +attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->addAttachment($attachment); - }else{ - $this->attachment = $attachment; - } - } - - /** - * @param ThreadedLoggerAttachment $attachment - */ - public function removeAttachment(\ThreadedLoggerAttachment $attachment){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - if($this->attachment === $attachment){ - $this->attachment = null; - foreach($attachment->getAttachments() as $attachment){ - $this->addAttachment($attachment); - } - } - } - } - - public function removeAttachments(){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->removeAttachments(); - $this->attachment = null; - } - } - - /** - * @return \ThreadedLoggerAttachment[] - */ - public function getAttachments(){ - $attachments = []; - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $attachments[] = $this->attachment; - $attachments += $this->attachment->getAttachments(); - } - return $attachments; - } } \ No newline at end of file diff --git a/src/spl/ThreadedLoggerAttachment.php b/src/spl/ThreadedLoggerAttachment.php index a5f21f7135..f66df2b7f4 100644 --- a/src/spl/ThreadedLoggerAttachment.php +++ b/src/spl/ThreadedLoggerAttachment.php @@ -19,16 +19,11 @@ * */ -abstract class ThreadedLoggerAttachment extends \Threaded{ +abstract class ThreadedLoggerAttachment extends \Threaded implements \LoggerAttachment{ /** @var \ThreadedLoggerAttachment */ protected $attachment = null; - /** - * @param string $message - */ - protected abstract function log($message); - /** * @param string $message */