src/ChunkDecoder/EvolutionChunkDecoder.php
private function parseEntitiesChunk($evolution, $chunk, $decoded_taf)
    {
        // For each value we detect, we'll clone the $evolution object, complete the clone,
        // and add it to the corresponding entity of the decoded taf

        $remaining_evo = $chunk;
        $tries = 0;

        // call each decoder in the chain and use results to populate the decoded taf
        foreach ($this->decoder_chain as $chunk_decoder) {
            try {
                // we check for probability in each loop, as it can be anywhere
                $remaining_evo = $this->probabilityChunkDecoder($evolution, $remaining_evo, $decoded_taf);

                // reset cavok
                $this->with_cavok = false;

                // try to parse the chunk with the current chunk decoder
                $decoded = $chunk_decoder->parse($remaining_evo, $this->with_cavok);

                // map the obtained fields (if any) to a original entity in the decoded_taf
                $result = $decoded['result'];
                $entity_name = current(array_keys($result));
                if ($entity_name == 'cavok') {
                    if ($result[$entity_name]) {
                        $this->with_cavok = true;
                    }
                    $entity_name = 'visibility';
                }
                $entity = $result[$entity_name];
                if ($entity == null && $entity_name != 'visibility') {
                    // visibility will be null if cavok is true but we still want to add the evolution
                    throw new ChunkDecoderException(
                        $chunk,
                        $remaining_evo,
                        'Bad format for weather evolution',
                        $this
                    );
                }
                if ($entity_name == 'maxTemperature') {
                    $this->addEvolution($decoded_taf, $evolution, $result, 'maxTemperature');
                    $this->addEvolution($decoded_taf, $evolution, $result, 'minTemperature');
                } else {
                    $this->addEvolution($decoded_taf, $evolution, $result, $entity_name);
                }

                // update remaining evo for the next round
                $remaining_evo = $decoded['remaining_taf'];

            } catch (ChunkDecoderException $e) {
                if (++$tries == count($this->decoder_chain)) {
                    if ($this->strict) {
                        throw new ChunkDecoderException(
                            $chunk,
                            $remaining_evo,
                            'Bad format for evolution information',
                            $this
                        );
                    } else {
                        // we tried all the chunk decoders on the first chunk and none of them got a match,
                        // so we drop it
                        $remaining_evo = preg_replace('#(\S+\s+)#', '', $remaining_evo);
                    }
                }
            }
        }

        return $remaining_evo;
    }
private function parseEntitiesChunk($evolution, $chunk, $decoded_taf)
    {
        // For each value we detect, we'll clone the $evolution object, complete the clone,
        // and add it to the corresponding entity of the decoded taf

        $remaining_evo = $chunk;
        $tries = 0;

        // call each decoder in the chain and use results to populate the decoded taf
        foreach ($this->decoder_chain as $chunk_decoder) {
            try {
                // we check for probability in each loop, as it can be anywhere
                $remaining_evo = $this->probabilityChunkDecoder($evolution, $remaining_evo, $decoded_taf);

                // reset cavok
                $this->with_cavok = false;

                // try to parse the chunk with the current chunk decoder
                $decoded = $chunk_decoder->parse($remaining_evo, $this->with_cavok);

                // map the obtained fields (if any) to a original entity in the decoded_taf
                $result = $decoded['result'];
                $entity_name = current(array_keys($result));
                if ($entity_name == 'cavok') {
                    if ($result[$entity_name]) {
                        $this->with_cavok = true;
                    }
                    $entity_name = 'visibility';
                }
                $entity = $result[$entity_name];
                if ($entity == null && $entity_name != 'visibility') {
                    // visibility will be null if cavok is true but we still want to add the evolution
                    throw new ChunkDecoderException(
                        $chunk,
                        $remaining_evo,
                        'Bad format for weather evolution',
                        $this
                    );
                }
                if ($entity_name == 'maxTemperature') {
                    $this->addEvolution($decoded_taf, $evolution, $result, 'maxTemperature');
                    $this->addEvolution($decoded_taf, $evolution, $result, 'minTemperature');
                } else {
                    $this->addEvolution($decoded_taf, $evolution, $result, $entity_name);
                }

                // update remaining evo for the next round
                $remaining_evo = $decoded['remaining_taf'];

            } catch (ChunkDecoderException $e) {
                if (++$tries == count($this->decoder_chain)) {
                    if ($this->strict) {
                        throw new ChunkDecoderException(
                            $chunk,
                            $remaining_evo,
                            'Bad format for evolution information',
                            $this
                        );
                    } else {
                        // we tried all the chunk decoders on the first chunk and none of them got a match,
                        // so we drop it
                        $remaining_evo = preg_replace('#(\S+\s+)#', '', $remaining_evo);
                    }
                }
            }
        }

        return $remaining_evo;
    }
private function parseEntitiesChunk ( $ evolution , $ chunk , $ decoded_taf ) { // For each value we detect, we'll clone the $evolution object, complete the clone, // and add it to the corresponding entity of the decoded taf $ remaining_evo = $ chunk ; $ tries = 0 ; // call each decoder in the chain and use results to populate the decoded taf foreach ( $ this -> decoder_chain as $ chunk_decoder ) { try { // we check for probability in each loop, as it can be anywhere $ remaining_evo = $ this -> probabilityChunkDecoder ( $ evolution , $ remaining_evo , $ decoded_taf ) ; // reset cavok $ this -> with_cavok = false ; // try to parse the chunk with the current chunk decoder $ decoded = $ chunk_decoder -> parse ( $ remaining_evo , $ this -> with_cavok ) ; // map the obtained fields (if any) to a original entity in the decoded_taf $ result = $ decoded [ 'result' ] ; $ entity_name = current ( array_keys ( $ result ) ) ; if ( $ entity_name == 'cavok' ) { if ( $ result [ $ entity_name ] ) { $ this -> with_cavok = true ; } $ entity_name = 'visibility' ; } $ entity = $ result [ $ entity_name ] ; if ( $ entity == null && $ entity_name != 'visibility' ) { // visibility will be null if cavok is true but we still want to add the evolution throw new ChunkDecoderException ( $ chunk , $ remaining_evo , 'Bad format for weather evolution' , $ this ) ; } if ( $ entity_name == 'maxTemperature' ) { $ this -> addEvolution ( $ decoded_taf , $ evolution , $ result , 'maxTemperature' ) ; $ this -> addEvolution ( $ decoded_taf , $ evolution , $ result , 'minTemperature' ) ; } else { $ this -> addEvolution ( $ decoded_taf , $ evolution , $ result , $ entity_name ) ; } // update remaining evo for the next round $ remaining_evo = $ decoded [ 'remaining_taf' ] ; } catch ( ChunkDecoderException $ e ) { if ( ++ $ tries == count ( $ this -> decoder_chain ) ) { if ( $ this -> strict ) { throw new ChunkDecoderException ( $ chunk , $ remaining_evo , 'Bad format for evolution information' , $ this ) ; } else { // we tried all the chunk decoders on the first chunk and none of them got a match, // so we drop it $ remaining_evo = preg_replace ( '#(\S+\s+)#' , '' , $ remaining_evo ) ; } } } } return $ remaining_evo ; }
Extract the weather elements (surface winds, visibility, etc) between 2 evolution tags (BECMG, TEMPO or FM)

@param Evolution $evolution
@param string $chunk
@param DecodedTaf $decoded_taf
@throws ChunkDecoderException
@return string
Extract the weather elements ( surface winds visibility etc ) between 2 evolution tags ( BECMG TEMPO or FM )