Author: Florian Eckerstorfer
Inheritance: extends AbstractPipe
示例#1
0
文件: Workflow.php 项目: plumphp/plum
 /**
  * Applies the given converter to the given field in the given item if no filter is given or if the filters returns
  * `true` for the field.
  *
  * @param mixed         $item
  * @param ConverterPipe $pipe
  *
  * @return mixed
  */
 protected function convertItemValue($item, ConverterPipe $pipe)
 {
     $value = Vale::get($item, $pipe->getField());
     $filterValue = $pipe->getFilterField() ? Vale::get($item, $pipe->getFilterField()) : $item;
     if ($pipe->getFilter() === null || $pipe->getFilter()->filter($filterValue) === true) {
         $item = Vale::set($item, $pipe->getField(), $pipe->getConverter()->convert($value));
     }
     return $item;
 }
示例#2
0
 /**
  * @test
  * @covers Plum\Plum\Pipe\ConverterPipe::createConverter()
  * @covers Plum\Plum\Pipe\AbstractPipe::__construct()
  * @covers Plum\Plum\Pipe\AbstractPipe::setPosition()
  * @covers Plum\Plum\Pipe\AbstractPipe::getPosition()
  */
 public function createConverterTakesPositionInArray()
 {
     $converter = Mockery::mock('\\Plum\\Plum\\Converter\\ConverterInterface');
     $pipe = ConverterPipe::createConverter(['converter' => $converter, 'position' => Workflow::PREPEND]);
     $this->assertInstanceOf('Plum\\Plum\\Pipe\\ConverterPipe', $pipe);
     $this->assertEquals(Workflow::PREPEND, $pipe->getPosition());
 }