Author: Florian Eckerstorfer
Inheritance: extends AbstractPipe
Esempio n. 1
0
 /**
  * Writes the given item to the given writer if the no filter is given or the filter returns `true`.
  *
  * @param mixed      $item
  * @param WriterPipe $pipe
  *
  * @return bool `true` if the item has been written, `false` if not.
  */
 protected function writeItem($item, WriterPipe $pipe)
 {
     if ($pipe->getFilter() === null || $pipe->getFilter()->filter($item) === true) {
         $pipe->getWriter()->writeItem($item);
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @test
  * @covers Plum\Plum\Pipe\WriterPipe::createWriter()
  * @covers Plum\Plum\Pipe\WriterPipe::__construct()
  * @covers Plum\Plum\Pipe\WriterPipe::getFilter()
  */
 public function createWriterTakesCallbackFilter()
 {
     /** @var \Plum\Plum\Writer\WriterInterface $writer */
     $writer = Mockery::mock('\\Plum\\Plum\\Writer\\WriterInterface');
     $filter = function ($v) {
         return true;
     };
     $pipe = WriterPipe::createWriter(['writer' => $writer, 'filter' => $filter]);
     $this->assertInstanceOf('\\Plum\\Plum\\Pipe\\WriterPipe', $pipe);
     $this->assertInstanceOf('\\Plum\\Plum\\Filter\\FilterInterface', $pipe->getFilter());
 }