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); }
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); }
/** * Add a processor to a logger * * @param string|Processor\ProcessorInterface $processor * @param int $priority * @param array|null $options * @return Logger * @throws Exception\InvalidArgumentException */ public function addProcessor($processor, $priority = 1, array $options = null) { if (is_string($processor)) { $processor = $this->processorPlugin($processor, $options); } elseif (!$processor instanceof Processor\ProcessorInterface) { throw new Exception\InvalidArgumentException(sprintf('Processor must implement Zend\\Log\\ProcessorInterface; received "%s"', is_object($processor) ? get_class($processor) : gettype($processor))); } $this->processors->insert($processor, $priority); return $this; }
/** * Add a writer to a logger * * @param string|Writer\WriterInterface $writer * @param int $priority * @param array|null $options * @return Logger * @throws Exception\InvalidArgumentException */ public function addWriter($writer, $priority = 1, array $options = null) { if (is_string($writer)) { $writer = $this->writerPlugin($writer, $options); } elseif (!$writer instanceof Writer\WriterInterface) { throw new Exception\InvalidArgumentException(sprintf('Writer must implement Zend\\Log\\Writer; received "%s"', is_object($writer) ? get_class($writer) : gettype($writer))); } $this->writers->insert($writer, $priority); return $this; }
/** * 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; }
// - 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(); $mailMerge->setUsername(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_USERNAME)->setPassword(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_PASSWORD)->setService(MailMerge::SERVICE_FREE);
/** * Add a writer to a logger * * @param WriterInterface $writer * @param int $priority * @return self */ public function addWriter(WriterInterface $writer, $priority = 1) { $this->writers->insert($writer, $priority); return $this; }
/** * @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); }