Translated using Weblate (Portuguese (Brazil))
[phpmyadmin.git] / src / Gis / GisFactory.php
blob2362bce40817f676af7d45df0da117361865727a
1 <?php
2 /**
3 * Contains the factory class that handles the creation of geometric objects
4 */
6 declare(strict_types=1);
8 namespace PhpMyAdmin\Gis;
10 use function mb_strpos;
11 use function mb_substr;
12 use function strtoupper;
14 /**
15 * Factory class that handles the creation of geometric objects.
17 class GisFactory
19 /**
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(),
36 default => null,
40 /**
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) {
47 return null;
50 $type = mb_substr($wkt, 0, $typePos);
52 return self::fromType($type);