This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from tdomy/add-return-type-for-php81
- Loading branch information
Showing
9 changed files
with
86 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace MStaack\LaravelPostgis\Geometries; | ||
|
||
use Countable; | ||
use InvalidArgumentException; | ||
|
||
abstract class LineStringCollection extends Geometry implements Countable | ||
{ | ||
/** | ||
* @var LineString[] | ||
*/ | ||
protected $linestrings = []; | ||
|
||
/** | ||
* @param LineString[] $linestrings | ||
*/ | ||
public function __construct(array $linestrings) | ||
{ | ||
if (count($linestrings) < 1) { | ||
throw new InvalidArgumentException('$linestrings must contain at least one entry'); | ||
} | ||
|
||
$validated = array_filter($linestrings, function ($value) { | ||
return $value instanceof LineString; | ||
}); | ||
|
||
if (count($linestrings) !== count($validated)) { | ||
throw new InvalidArgumentException('$linestrings must be an array of Points'); | ||
} | ||
|
||
$this->linestrings = $linestrings; | ||
} | ||
|
||
public function getLineStrings() | ||
{ | ||
return $this->linestrings; | ||
} | ||
|
||
public function is3d() | ||
{ | ||
if (count($this->linestrings) === 0) return false; | ||
return $this->linestrings[0]->is3d(); | ||
} | ||
|
||
public static function fromString($wktArgument) | ||
{ | ||
$str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); | ||
$linestrings = array_map(function ($data) { | ||
return LineString::fromString($data); | ||
}, $str); | ||
|
||
|
||
return new static($linestrings); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return implode(',', array_map(function (LineString $linestring) { | ||
return sprintf('(%s)', (string)$linestring); | ||
}, $this->getLineStrings())); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return count($this->linestrings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters