Skip to content

Commit

Permalink
Ugly, but faster
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jul 7, 2023
1 parent b8fd17c commit 8b72f2f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/CoordinateReferenceSystem/CoordinateReferenceSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,30 @@ public function getBoundingArea(): BoundingArea
public static function fromSRID(string $srid): Compound|Geocentric|Geographic2D|Geographic3D|Projected|Vertical
{
if (!isset(self::$cachedObjects[$srid])) {
if (isset(Projected::getSupportedSRIDs()[$srid])) {
try {
self::$cachedObjects[$srid] = Projected::fromSRID($srid);
} elseif (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
} elseif (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
} elseif (isset(Geocentric::getSupportedSRIDs()[$srid])) {
self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
} elseif (isset(Vertical::getSupportedSRIDs()[$srid])) {
self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
} elseif (isset(Compound::getSupportedSRIDs()[$srid])) {
self::$cachedObjects[$srid] = Compound::fromSRID($srid);
} else {
throw new UnknownCoordinateReferenceSystemException($srid);
} catch (UnknownCoordinateReferenceSystemException) {
try {
self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
} catch (UnknownCoordinateReferenceSystemException) {
try {
self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
} catch (UnknownCoordinateReferenceSystemException) {
try {
self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
} catch (UnknownCoordinateReferenceSystemException) {
try {
self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
} catch (UnknownCoordinateReferenceSystemException) {
try {
self::$cachedObjects[$srid] = Compound::fromSRID($srid);
} catch (UnknownCoordinateReferenceSystemException) {
throw new UnknownCoordinateReferenceSystemException($srid);
}
}
}
}
}
}
}

Expand Down

0 comments on commit 8b72f2f

Please sign in to comment.