3 * Contains the factory class that handles the creation of geometric objects
6 declare(strict_types
=1);
8 namespace PhpMyAdmin\Gis
;
10 use function mb_strpos
;
11 use function mb_substr
;
12 use function strtoupper
;
15 * Factory class that handles the creation of geometric objects.
20 * Returns the singleton instance of geometric class of the given type.
22 * @param string $type type of the geometric object
24 * @return GisGeometry|null the singleton instance of geometric class of the given type
26 public static function fromType(string $type): GisGeometry|
null
28 return match (strtoupper($type)) {
29 'MULTIPOLYGON' => GisMultiPolygon
::singleton(),
30 'POLYGON' => GisPolygon
::singleton(),
31 'MULTIPOINT' => GisMultiPoint
::singleton(),
32 'POINT' => GisPoint
::singleton(),
33 'MULTILINESTRING' => GisMultiLineString
::singleton(),
34 'LINESTRING' => GisLineString
::singleton(),
35 'GEOMETRYCOLLECTION' => GisGeometryCollection
::singleton(),
41 * Returns the singleton instance of geometric class of the given wkt type.
43 public static function fromWkt(string $wkt): GisGeometry|
null
45 $typePos = mb_strpos($wkt, '(');
46 if ($typePos === false) {
50 $type = mb_substr($wkt, 0, $typePos);
52 return self
::fromType($type);