Completed
Push — master ( 200886...a4bdfd )
by Jeroen De
10s
created

includes/parsers/ImageOverlayParser.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Maps;
4
5
use DataValues\Geo\Parsers\GeoCoordinateParser;
6
use Maps\Elements\ImageOverlay;
7
use Maps\Elements\WmsOverlay;
8
use ValueParsers\ParseException;
9
use ValueParsers\StringValueParser;
10
11
/**
12
 * @since 3.1
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class ImageOverlayParser extends StringValueParser {
18
19
	/**
20
	 * @since 3.1
21
	 *
22
	 * @param string $value
23
	 *
24
	 * @return WmsOverlay
25
	 * @throws ParseException
26
	 */
27
	protected function stringParse( $value ) {
28
		$parameters = explode( '~', $value );
29
		$imageParameters = explode( ':', $parameters[0], 3 );
30
31
		if ( count( $imageParameters ) === 3 ) {
32
			$boundsNorthEast = $this->stringToLatLongValue( $imageParameters[0] );
33
			$boundsSouthWest = $this->stringToLatLongValue( $imageParameters[1] );
34
			$imageUrl = \MapsMapper::getFileUrl( $imageParameters[2] );
35
36
			return new ImageOverlay( $boundsNorthEast, $boundsSouthWest, $imageUrl );
37
		}
38
39
		throw new ParseException( 'Need 3 parameters for an image overlay' );
40
	}
41
42
	private function stringToLatLongValue( $location ) {
43
		$parser = new GeoCoordinateParser( new \ValueParsers\ParserOptions() );
0 ignored issues
show
Deprecated Code introduced by
The class DataValues\Geo\Parsers\GeoCoordinateParser has been deprecated with message: since 2.0, use the base class instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
44
		return $parser->parse( $location );
45
	}
46
47
}
48