-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
proxy-template.php
139 lines (115 loc) · 3.46 KB
/
proxy-template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
declare(strict_types=1);
namespace Brick\Geo\Proxy;
use Brick\Geo\Exception\GeometryIOException;
use Brick\Geo\Exception\CoordinateSystemException;
use Brick\Geo\Exception\InvalidGeometryException;
use Brick\Geo\Exception\UnexpectedGeometryException;
use Brick\Geo\Geometry;
use Brick\Geo\_CLASSNAME_;
/**
* Proxy class for _CLASSNAME_.
*
* @internal This class is not part of the public API and can change at any time.
* Please type-hint against _FQCN_ in your projects.
*/
class _CLASSNAME_Proxy extends _CLASSNAME_ implements ProxyInterface
{
/**
* The WKT or WKB data.
*/
private readonly string $proxyData;
/**
* `true` if WKB, `false` if WKT.
*/
private readonly bool $isProxyBinary;
/**
* The SRID of the underlying geometry.
*/
private readonly int $proxySRID;
/**
* The underlying geometry, or NULL if not yet loaded.
*/
private ?_CLASSNAME_ $proxyGeometry = null;
/**
* @param string $data The WKT or WKB data.
* @param bool $isBinary Whether the data is binary (true) or text (false).
* @param int $srid The SRID of the geometry.
*/
public function __construct(string $data, bool $isBinary, int $srid = 0)
{
$this->proxyData = $data;
$this->isProxyBinary = $isBinary;
$this->proxySRID = $srid;
}
/**
* Loads the underlying geometry.
*
* @throws GeometryIOException If the proxy data is not valid.
* @throws CoordinateSystemException If the resulting geometry contains mixed coordinate systems.
* @throws InvalidGeometryException If the resulting geometry is not valid.
* @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class.
*/
private function load() : void
{
$this->proxyGeometry = $this->isProxyBinary
? _CLASSNAME_::fromBinary($this->proxyData, $this->proxySRID)
: _CLASSNAME_::fromText($this->proxyData, $this->proxySRID);
}
public function isLoaded() : bool
{
return $this->proxyGeometry !== null;
}
public function getGeometry() : Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}
return $this->proxyGeometry;
}
public function isProxyBinary() : bool
{
return $this->isProxyBinary;
}
public static function fromText(string $wkt, int $srid = 0) : Geometry
{
return new self($wkt, false, $srid);
}
public static function fromBinary(string $wkb, int $srid = 0) : Geometry
{
return new self($wkb, true, $srid);
}
public function SRID() : int
{
return $this->proxySRID;
}
public function asText() : string
{
if (! $this->isProxyBinary) {
return $this->proxyData;
}
if ($this->proxyGeometry === null) {
$this->load();
}
return $this->proxyGeometry->asText();
}
public function asBinary() : string
{
if ($this->isProxyBinary) {
return $this->proxyData;
}
if ($this->proxyGeometry === null) {
$this->load();
}
return $this->proxyGeometry->asBinary();
}
// BEGIN METHOD TEMPLATE
function _TEMPLATE_()
{
if ($this->proxyGeometry === null) {
$this->load();
}
return $this->proxyGeometry->_METHOD_();
}
// END METHOD TEMPLATE
}