@@ -5037,10 +5037,12 @@ public function ping(ServerRequestInterface $request): ResponseInterface
5037
5037
class ColumnConverter
5038
5038
{
5039
5039
private $ driver ;
5040
+ private $ geometrySrid ;
5040
5041
5041
- public function __construct (string $ driver )
5042
+ public function __construct (string $ driver, int $ geometrySrid )
5042
5043
{
5043
5044
$ this ->driver = $ driver ;
5045
+ $ this ->geometrySrid = $ geometrySrid ;
5044
5046
}
5045
5047
5046
5048
public function convertColumnValue (ReflectedColumn $ column ): string
@@ -5066,12 +5068,13 @@ public function convertColumnValue(ReflectedColumn $column): string
5066
5068
}
5067
5069
}
5068
5070
if ($ column ->isGeometry ()) {
5071
+ $ srid = $ this ->geometrySrid ;
5069
5072
switch ($ this ->driver ) {
5070
5073
case 'mysql ' :
5071
5074
case 'pgsql ' :
5072
- return "ST_GeomFromText(?) " ;
5075
+ return "ST_GeomFromText(?, $ srid ) " ;
5073
5076
case 'sqlsrv ' :
5074
- return "geometry::STGeomFromText(?,0 ) " ;
5077
+ return "geometry::STGeomFromText(?, $ srid ) " ;
5075
5078
}
5076
5079
}
5077
5080
return '? ' ;
@@ -5114,10 +5117,10 @@ class ColumnsBuilder
5114
5117
private $ driver ;
5115
5118
private $ converter ;
5116
5119
5117
- public function __construct (string $ driver )
5120
+ public function __construct (string $ driver, int $ geometrySrid )
5118
5121
{
5119
5122
$ this ->driver = $ driver ;
5120
- $ this ->converter = new ColumnConverter ($ driver );
5123
+ $ this ->converter = new ColumnConverter ($ driver, $ geometrySrid );
5121
5124
}
5122
5125
5123
5126
public function getOffsetLimit (int $ offset , int $ limit ): string
@@ -5238,10 +5241,12 @@ public function getIncrement(ReflectedTable $table, array $columnValues): string
5238
5241
class ConditionsBuilder
5239
5242
{
5240
5243
private $ driver ;
5244
+ private $ geometrySrid ;
5241
5245
5242
- public function __construct (string $ driver )
5246
+ public function __construct (string $ driver, int $ geometrySrid )
5243
5247
{
5244
5248
$ this ->driver = $ driver ;
5249
+ $ this ->geometrySrid = $ geometrySrid ;
5245
5250
}
5246
5251
5247
5252
private function getConditionSql (Condition $ condition , array &$ arguments ): string
@@ -5402,14 +5407,15 @@ private function hasSpatialArgument(string $operator): bool
5402
5407
5403
5408
private function getSpatialFunctionCall (string $ functionName , string $ column , bool $ hasArgument ): string
5404
5409
{
5410
+ $ srid = $ this ->geometrySrid ;
5405
5411
switch ($ this ->driver ) {
5406
5412
case 'mysql ' :
5407
5413
case 'pgsql ' :
5408
- $ argument = $ hasArgument ? ' ST_GeomFromText(?) ' : '' ;
5414
+ $ argument = $ hasArgument ? " ST_GeomFromText(?, $ srid ) " : '' ;
5409
5415
return "$ functionName( $ column, $ argument)=TRUE " ;
5410
5416
case 'sqlsrv ' :
5411
5417
$ functionName = str_replace ('ST_ ' , 'ST ' , $ functionName );
5412
- $ argument = $ hasArgument ? ' geometry::STGeomFromText(?,0) ' : '' ;
5418
+ $ argument = $ hasArgument ? " geometry::STGeomFromText(?, $ srid ) " : '' ;
5413
5419
return "$ column. $ functionName( $ argument)=1 " ;
5414
5420
case 'sqlite ' :
5415
5421
$ argument = $ hasArgument ? '? ' : '0 ' ;
@@ -5572,6 +5578,7 @@ class GenericDB
5572
5578
private $ conditions ;
5573
5579
private $ columns ;
5574
5580
private $ converter ;
5581
+ private $ geometrySrid ;
5575
5582
5576
5583
private function getDsn (): string
5577
5584
{
@@ -5655,13 +5662,13 @@ private function initPdo(): bool
5655
5662
$ this ->mapper = new RealNameMapper ($ this ->mapping );
5656
5663
$ this ->reflection = new GenericReflection ($ this ->pdo , $ this ->driver , $ this ->database , $ this ->tables , $ this ->mapper );
5657
5664
$ this ->definition = new GenericDefinition ($ this ->pdo , $ this ->driver , $ this ->database , $ this ->tables , $ this ->mapper );
5658
- $ this ->conditions = new ConditionsBuilder ($ this ->driver );
5659
- $ this ->columns = new ColumnsBuilder ($ this ->driver );
5665
+ $ this ->conditions = new ConditionsBuilder ($ this ->driver , $ this -> geometrySrid );
5666
+ $ this ->columns = new ColumnsBuilder ($ this ->driver , $ this -> geometrySrid );
5660
5667
$ this ->converter = new DataConverter ($ this ->driver );
5661
5668
return $ result ;
5662
5669
}
5663
5670
5664
- public function __construct (string $ driver , string $ address , int $ port , string $ database , string $ command , array $ tables , array $ mapping , string $ username , string $ password )
5671
+ public function __construct (string $ driver , string $ address , int $ port , string $ database , string $ command , array $ tables , array $ mapping , string $ username , string $ password, int $ geometrySrid )
5665
5672
{
5666
5673
$ this ->driver = $ driver ;
5667
5674
$ this ->address = $ address ;
@@ -5672,10 +5679,11 @@ public function __construct(string $driver, string $address, int $port, string $
5672
5679
$ this ->mapping = $ mapping ;
5673
5680
$ this ->username = $ username ;
5674
5681
$ this ->password = $ password ;
5682
+ $ this ->geometrySrid = $ geometrySrid ;
5675
5683
$ this ->initPdo ();
5676
5684
}
5677
5685
5678
- public function reconstruct (string $ driver , string $ address , int $ port , string $ database , string $ command , array $ tables , array $ mapping , string $ username , string $ password ): bool
5686
+ public function reconstruct (string $ driver , string $ address , int $ port , string $ database , string $ command , array $ tables , array $ mapping , string $ username , string $ password, int $ geometrySrid ): bool
5679
5687
{
5680
5688
if ($ driver ) {
5681
5689
$ this ->driver = $ driver ;
@@ -5704,6 +5712,9 @@ public function reconstruct(string $driver, string $address, int $port, string $
5704
5712
if ($ password ) {
5705
5713
$ this ->password = $ password ;
5706
5714
}
5715
+ if ($ geometrySrid ) {
5716
+ $ this ->geometrySrid = $ geometrySrid ;
5717
+ }
5707
5718
return $ this ->initPdo ();
5708
5719
}
5709
5720
@@ -8817,13 +8828,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8817
8828
8818
8829
class ReconnectMiddleware extends Middleware
8819
8830
{
8820
- private $ reflection ;
8831
+ private $ config ;
8821
8832
private $ db ;
8822
8833
8823
8834
public function __construct (Router $ router , Responder $ responder , Config $ config , string $ middleware , ReflectionService $ reflection , GenericDB $ db )
8824
8835
{
8825
8836
parent ::__construct ($ router , $ responder , $ config , $ middleware );
8826
- $ this ->reflection = $ reflection ;
8837
+ $ this ->config = $ config ;
8827
8838
$ this ->db = $ db ;
8828
8839
}
8829
8840
@@ -8833,7 +8844,7 @@ private function getDriver(): string
8833
8844
if ($ driverHandler ) {
8834
8845
return call_user_func ($ driverHandler );
8835
8846
}
8836
- return '' ;
8847
+ return $ this -> config -> getDriver () ;
8837
8848
}
8838
8849
8839
8850
private function getAddress (): string
@@ -8842,7 +8853,7 @@ private function getAddress(): string
8842
8853
if ($ addressHandler ) {
8843
8854
return call_user_func ($ addressHandler );
8844
8855
}
8845
- return '' ;
8856
+ return $ this -> config -> getAddress () ;
8846
8857
}
8847
8858
8848
8859
private function getPort (): int
@@ -8851,7 +8862,7 @@ private function getPort(): int
8851
8862
if ($ portHandler ) {
8852
8863
return call_user_func ($ portHandler );
8853
8864
}
8854
- return 0 ;
8865
+ return $ this -> config -> getPort () ;
8855
8866
}
8856
8867
8857
8868
private function getDatabase (): string
@@ -8860,7 +8871,7 @@ private function getDatabase(): string
8860
8871
if ($ databaseHandler ) {
8861
8872
return call_user_func ($ databaseHandler );
8862
8873
}
8863
- return '' ;
8874
+ return $ this -> config -> getDatabase () ;
8864
8875
}
8865
8876
8866
8877
private function getCommand (): string
@@ -8869,7 +8880,7 @@ private function getCommand(): string
8869
8880
if ($ commandHandler ) {
8870
8881
return call_user_func ($ commandHandler );
8871
8882
}
8872
- return '' ;
8883
+ return $ this -> config -> getCommand () ;
8873
8884
}
8874
8885
8875
8886
private function getTables (): array
@@ -8878,7 +8889,7 @@ private function getTables(): array
8878
8889
if ($ tablesHandler ) {
8879
8890
return call_user_func ($ tablesHandler );
8880
8891
}
8881
- return [] ;
8892
+ return $ this -> config -> getTables () ;
8882
8893
}
8883
8894
8884
8895
private function getMapping (): array
@@ -8887,7 +8898,7 @@ private function getMapping(): array
8887
8898
if ($ mappingHandler ) {
8888
8899
return call_user_func ($ mappingHandler );
8889
8900
}
8890
- return [] ;
8901
+ return $ this -> config -> getMapping () ;
8891
8902
}
8892
8903
8893
8904
private function getUsername (): string
@@ -8896,7 +8907,7 @@ private function getUsername(): string
8896
8907
if ($ usernameHandler ) {
8897
8908
return call_user_func ($ usernameHandler );
8898
8909
}
8899
- return '' ;
8910
+ return $ this -> config -> getUsername () ;
8900
8911
}
8901
8912
8902
8913
private function getPassword (): string
@@ -8905,7 +8916,16 @@ private function getPassword(): string
8905
8916
if ($ passwordHandler ) {
8906
8917
return call_user_func ($ passwordHandler );
8907
8918
}
8908
- return '' ;
8919
+ return $ this ->config ->getPassword ();
8920
+ }
8921
+
8922
+ private function getGeometrySrid (): int
8923
+ {
8924
+ $ geometrySridHandler = $ this ->getProperty ('geometrySridHandler ' , '' );
8925
+ if ($ geometrySridHandler ) {
8926
+ return call_user_func ($ geometrySridHandler );
8927
+ }
8928
+ return $ this ->config ->getGeometrySrid ();
8909
8929
}
8910
8930
8911
8931
public function process (ServerRequestInterface $ request , RequestHandlerInterface $ next ): ResponseInterface
@@ -8919,9 +8939,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8919
8939
$ mapping = $ this ->getMapping ();
8920
8940
$ username = $ this ->getUsername ();
8921
8941
$ password = $ this ->getPassword ();
8922
- if ($ driver || $ address || $ port || $ database || $ command || $ tables || $ mapping || $ username || $ password ) {
8923
- $ this ->db ->reconstruct ($ driver , $ address , $ port , $ database , $ command , $ tables , $ mapping , $ username , $ password );
8924
- }
8942
+ $ geometrySrid = $ this ->getGeometrySrid ();
8943
+ $ this ->db ->reconstruct ($ driver , $ address , $ port , $ database , $ command , $ tables , $ mapping , $ username , $ password , $ geometrySrid );
8925
8944
return $ next ->handle ($ request );
8926
8945
}
8927
8946
}
@@ -11634,7 +11653,8 @@ public function __construct(Config $config)
11634
11653
$ config ->getTables (),
11635
11654
$ config ->getMapping (),
11636
11655
$ config ->getUsername (),
11637
- $ config ->getPassword ()
11656
+ $ config ->getPassword (),
11657
+ $ config ->getGeometrySrid ()
11638
11658
);
11639
11659
$ prefix = sprintf ('phpcrudapi-%s- ' , substr (md5 (__FILE__ ), 0 , 8 ));
11640
11660
$ cache = CacheFactory::create ($ config ->getCacheType (), $ prefix , $ config ->getCachePath ());
@@ -11833,6 +11853,7 @@ class Config
11833
11853
'debug ' => false ,
11834
11854
'basePath ' => '' ,
11835
11855
'openApiBase ' => '{"info":{"title":"PHP-CRUD-API","version":"1.0.0"}} ' ,
11856
+ 'geometrySrid ' => 4326 ,
11836
11857
];
11837
11858
11838
11859
private function getDefaultDriver (array $ values ): string
@@ -12022,6 +12043,11 @@ public function getOpenApiBase(): array
12022
12043
{
12023
12044
return json_decode ($ this ->values ['openApiBase ' ], true );
12024
12045
}
12046
+
12047
+ public function getGeometrySrid (): int
12048
+ {
12049
+ return $ this ->values ['geometrySrid ' ];
12050
+ }
12025
12051
}
12026
12052
}
12027
12053
0 commit comments