コード例 #1
0
 public function acceptSegment(Segment $segment)
 {
     if ($this->getCode() == $segment->getCode() && $this->maxRepeat > count($this->segments)) {
         $this->segments[] = $segment;
         return true;
     } else {
         return false;
     }
 }
コード例 #2
0
ファイル: Populator.php プロジェクト: progrupa/edifact
 protected function fromSegment($object, MessageSegment $segment)
 {
     $classRefl = new \ReflectionClass($object);
     //  Check if proper segment was received
     $this->checkSegmentCode($classRefl, $segment->getCode());
     //  Populate SegmentPiece properties
     $this->fillFromArray($object, $classRefl, array_values($segment->getRawData()));
     //  Check if mandatory fields have values
     $this->checkMandatoryFields($object, $classRefl, $segment->getCode());
 }
コード例 #3
0
ファイル: SegmentPopulator.php プロジェクト: progrupa/edifact
 /**
  * @param $data
  * @return Segment
  * @throws MandatorySegmentPieceMissing
  * @throws UnknownSegmentException
  */
 public function populate(&$data)
 {
     $segmentData = array_shift($data);
     $code = $segmentData[0];
     $segment = new Segment();
     $segment->setCode($code);
     $segment->setRawData($segmentData);
     if (!isset($this->segmentConfig[$code])) {
         return $segment;
         //            throw new UnknownSegmentException(sprintf("Unknown segment found: %s", $code));
     }
     $config = $this->segmentConfig[$code];
     $values = $this->transformValues($config->getDataElements(), $segmentData);
     foreach ($values as $k => $v) {
         $segment->set($k, $v);
     }
     return $segment;
 }
コード例 #4
0
 /**
  * @return mixed
  */
 protected function givenSegmentPopulator()
 {
     $segmentPopulator = \Phake::mock(SegmentPopulator::class);
     \Phake::when($segmentPopulator)->populate(\Phake::anyParameters())->thenReturnCallback(function (&$data) {
         $x = array_shift($data);
         $segment = new Segment($x[0]);
         $segment->setRawData($x);
         return $segment;
     });
     return $segmentPopulator;
 }