Ejemplo n.º 1
0
 /**
  * Register query profiler info
  *
  * @param array $info
  * @return self
  */
 public function log(array $info)
 {
     foreach ($this->writers->toArray() as $writer) {
         $writer->doDb($info);
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function testMaintainsInsertOrderForDataOfEqualPriority()
 {
     $queue = new SplPriorityQueue();
     $queue->insert('foo', 1000);
     $queue->insert('bar', 1000);
     $queue->insert('baz', 1000);
     $queue->insert('bat', 1000);
     $expected = array('foo', 'bar', 'baz', 'bat');
     $test = array();
     foreach ($queue as $datum) {
         $test[] = $datum;
     }
     $this->assertEquals($expected, $test);
 }
Ejemplo n.º 3
0
 public function testSetWriters()
 {
     $writer1 = $this->logger->writerPlugin('mock');
     $writer2 = $this->logger->writerPlugin('null');
     $writers = new SplPriorityQueue();
     $writers->insert($writer1, 1);
     $writers->insert($writer2, 2);
     $this->logger->setWriters($writers);
     $writers = $this->logger->getWriters();
     $this->assertInstanceOf('Zend\\Stdlib\\SplPriorityQueue', $writers);
     $writer = $writers->extract();
     $this->assertTrue($writer instanceof \Zend\Log\Writer\Null);
     $writer = $writers->extract();
     $this->assertTrue($writer instanceof \Zend\Log\Writer\Mock);
 }
Ejemplo n.º 4
0
 /**
  * Add a message as a log entry
  *
  * @param  int $priority
  * @param  mixed $message
  * @param  array|Traversable $extra
  * @return Logger
  * @throws Exception\InvalidArgumentException if message can't be cast to string
  * @throws Exception\InvalidArgumentException if extra can't be iterated over
  * @throws Exception\RuntimeException if no log writer specified
  */
 public function log($priority, $message, $extra = array())
 {
     if (!is_int($priority) || $priority < 0 || $priority >= count($this->priorities)) {
         throw new Exception\InvalidArgumentException(sprintf('$priority must be an integer > 0 and < %d; received %s', count($this->priorities), var_export($priority, 1)));
     }
     if (is_object($message) && !method_exists($message, '__toString')) {
         throw new Exception\InvalidArgumentException('$message must implement magic __toString() method');
     }
     if (!is_array($extra) && !$extra instanceof Traversable) {
         throw new Exception\InvalidArgumentException('$extra must be an array or implement Traversable');
     } elseif ($extra instanceof Traversable) {
         $extra = ArrayUtils::iteratorToArray($extra);
     }
     if ($this->writers->count() === 0) {
         throw new Exception\RuntimeException('No log writer specified');
     }
     $timestamp = new DateTime();
     if (is_array($message)) {
         $message = var_export($message, true);
     }
     $event = array('timestamp' => $timestamp, 'priority' => (int) $priority, 'priorityName' => $this->priorities[$priority], 'message' => (string) $message, 'extra' => $extra);
     foreach ($this->processors->toArray() as $processor) {
         $event = $processor->process($event);
     }
     foreach ($this->writers->toArray() as $writer) {
         $writer->write($event);
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Insert a value with a given priority
  *
  * Utilizes {@var $serial} to ensure that values of equal priority are
  * emitted in the same order in which they are inserted.
  *
  * @param  mixed $datum
  * @param  mixed $priority
  * @return void
  */
 public function insert($datum, $priority)
 {
     if (!is_array($priority)) {
         $priority = [$priority, $this->serial--];
     }
     parent::insert($datum, $priority);
 }
Ejemplo n.º 6
0
 /**
  * Write a profiler
  *
  * @param string $name
  * @return Profiler
  */
 protected function write($name = 'PI')
 {
     $this->end($name);
     foreach ($this->writers->toArray() as $writer) {
         $writer->doProfiler($this->timers[$name]);
     }
     unset($this->timers[$name]);
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Attach a filter to the chain
  *
  * @param  callback|FilterInterface $callback A Filter implementation or valid PHP callback
  * @param  int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier)
  * @return FilterChain
  */
 public function attach($callback, $priority = self::DEFAULT_PRIORITY)
 {
     if (!is_callable($callback)) {
         if (!$callback instanceof FilterInterface) {
             throw new Exception\InvalidArgumentException(sprintf('Expected a valid PHP callback; received "%s"', is_object($callback) ? get_class($callback) : gettype($callback)));
         }
         $callback = array($callback, 'filter');
     }
     $this->filters->insert($callback, $priority);
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Add a message as a log entry
  *
  * @param  int                   $priority
  * @param  mixed                 $message
  * @param  array|Traversable|int $extra
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException if extra can't be iterated over
  * @return self
  */
 public function log($priority, $message, $extra = array())
 {
     if (!is_int($priority) || !isset($this->priorities[$priority])) {
         throw new \InvalidArgumentException('Invalid priority');
     }
     if (is_object($message) && !method_exists($message, '__toString')) {
         throw new \InvalidArgumentException('$message must implement magic __toString() method');
     }
     if (is_int($extra)) {
         $time = $extra;
         $extra = array();
     } elseif (isset($extra['time'])) {
         $time = $extra['time'];
         unset($extra['time']);
     } else {
         $time = microtime(true);
     }
     if (!is_array($extra) && !$extra instanceof Traversable) {
         throw new \InvalidArgumentException('$extra must be an array or implement Traversable');
     } elseif ($extra instanceof Traversable) {
         $extra = ArrayUtils::iteratorToArray($extra);
     }
     if ($this->writers->count() === 0) {
         throw new \RuntimeException('No log writer specified');
     }
     if ($this->dateTimeFormat) {
         $time = time($time, $this->dateTimeFormat);
     }
     if (is_array($message)) {
         $message = var_export($message, true);
     }
     foreach ($this->writers->toArray() as $writer) {
         $writer->write(array('timestamp' => $time, 'priority' => (int) $priority, 'priorityName' => $this->priorities[$priority], 'message' => (string) $message, 'extra' => $extra));
     }
     return $this;
 }
//   - Faster
//   - Requires little memory (RAM)
//   - No reduction in file size
//
// o PROCESSOR_GHOSTSCRIPT
//   - Slower
//   - Requires lots of memory (RAM)
//   - Reduction in file size
//
// If you have both installed on your system, PROCESSOR_PDFTK is recommended.
$processor = PROCESSOR_PDFTK;
// Number of documents (populated with random strings) to concatenate.
$iterations = 3;
// -----------------------------------------------------------------------------
// Logger to output status messages
$writerQueue = new SplPriorityQueue();
$writerQueue->insert(new Writer('php://stdout'), 1);
$logger = new Logger();
$logger->setWriters($writerQueue);
// -----------------------------------------------------------------------------
// Create temporary directory
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);
if (is_dir($tempDirectory)) {
    recursiveRemoveDirectory($tempDirectory);
}
$logger->log(Logger::INFO, sprintf('Making temporary directory %s.', $tempDirectory));
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
Ejemplo n.º 10
0
 /**
  * @param ListenerInterface $listener
  * @param array $options
  * @param int $priority
  */
 public function addListener(ListenerInterface $listener, array $options, $priority = 0)
 {
     $this->listeners->insert(['listener' => $listener, 'options' => $options], $priority);
 }