Esempio n. 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;
     }
 }
Esempio n. 2
0
 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());
 }
Esempio n. 3
0
 /**
  * @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;
 }
Esempio n. 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;
 }