note 114309 added to class.splpriorityqueue
| From: | lsroudi at gmail dot com | Date: | Wed, 05 Feb 2014 18:38:24 +0000 |
| Subject: | note 114309 added to class.splpriorityqueue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198416@lists.php.net to get a copy of this message | ||
<?php
/**
* Description of PriorityQueue
*
* (c) lsroudi http://lsroudi.com/ <lsroudi@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
interface PriorityLoggerInterface {
public function insert($value, $priority);
}
class PriorityLogger extends SplPriorityQueue implements PriorityLoggerInterface {
}
class Logger {
const ERROR = 3;
const NOTICE = 1;
const WARNING = 2;
private $priorityLogger;
public function __construct(PriorityLoggerInterface $priorityLogger)
{
$this->priorityLogger = $priorityLogger;
}
public function addMessage($value, $priority)
{
$this->priorityLogger->insert($value, $priority);
}
public function getPriorityLogger()
{
return $this->priorityLogger;
}
}
$priorityLogger = new PriorityLogger();
$logger = new Logger($priorityLogger);
$logger->addMessage('Message with notice type', Logger::NOTICE);
$logger->addMessage('Message with warning type', Logger::WARNING);
$logger->addMessage('Message with error type', Logger::ERROR);
$priorityLoggerQueue = $logger->getPriorityLogger();
foreach ($priorityLoggerQueue as $queue){
print $queue . PHP_EOL;
}
//Résultat
//Message with error type
//Message with warning type
//Message with notice type
?>
----
Server IP: 87.124.126.49
Probable Submitter: 78.223.136.204
----
Manual Page -- http://php.net/manual/en/class.splpriorityqueue.php
Edit -- https://master.php.net/note/edit/114309
Del: integrated -- https://master.php.net/note/delete/114309/integrated
Del: useless -- https://master.php.net/note/delete/114309/useless
Del: bad code -- https://master.php.net/note/delete/114309/bad+code
Del: spam -- https://master.php.net/note/delete/114309/spam
Del: non-english -- https://master.php.net/note/delete/114309/non-english
Del: in docs -- https://master.php.net/note/delete/114309/in+docs
Del: other reasons-- https://master.php.net/note/delete/114309
Reject -- https://master.php.net/note/reject/114309
Search -- https://master.php.net/manage/user-notes.php