forked from infostreams/mbtiles-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tileserver.php
748 lines (616 loc) · 20.6 KB
/
tileserver.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
<?php
/**
* A PHP TileMap Server
*
* Serves image tiles, UTFgrid tiles and TileJson definitions
* from MBTiles files (as used by TileMill). (Partly) implements
* the Tile Map Services Specification.
*
* Originally based on https://github.com/Zverik/mbtiles-php,
* but refactored and extended.
*
* @author E. Akerboom ([email protected])
* @version 1.1
* @license LGPL
*/
header('Access-Control-Allow-Origin: *');
$_identifier = '[\w\d_-\s]+';
$_number = '\d+';
$r = new Router();
$r->map("",
array("controller"=>"serverinfo", "action"=>"hello"));
$r->map("root.xml",
array("controller"=>"TileMapService", "action"=>"root"));
$r->map("1.0.0",
array("controller"=>"TileMapService", "action"=>"service"));
$r->map("1.0.0/:layer",
array("controller"=>"TileMapService", "action"=>"resource"), array("layer"=>$_identifier));
$r->map("1.0.0/:layer/:z/:x/:y.:ext",
array("controller"=>"maptile", "action"=>"serveTmsTile"),
array("layer"=>$_identifier, "x"=>$_number, "y"=>$_number, "z"=>$_number,
"ext"=>"(png|jpg|jpeg|json)"));
$r->map(":layer/:z/:x/:y.:ext",
array("controller"=>"maptile", "action"=>"serveTile"),
array("layer"=>$_identifier, "x"=>$_number, "y"=>$_number, "z"=>$_number,
"ext"=>"(png|jpg|jpeg|json)"));
$r->map(":layer/:z/:x/:y.:ext\?:argument=:callback",
array("controller"=>"maptile", "action"=>"serveTile"),
array("layer"=>$_identifier, "x"=>$_number, "y"=>$_number, "z"=>$_number,
"ext"=>"(json|jsonp)", "argument"=>$_identifier, "callback"=>$_identifier));
$r->map(":layer/:z/:x/:y.grid.:ext",
array("controller"=>"maptile", "action"=>"serveTile"),
array("layer"=>$_identifier, "x"=>$_number, "y"=>$_number, "z"=>$_number,
"ext"=>"(json|jsonp)", "argument"=>$_identifier, "callback"=>$_identifier));
$r->map(":layer/:z/:x/:y.grid.:ext\?:argument=:callback",
array("controller"=>"maptile", "action"=>"serveTile"),
array("layer"=>$_identifier, "x"=>$_number, "y"=>$_number, "z"=>$_number,
"ext"=>"(json|jsonp)", "argument"=>$_identifier, "callback"=>$_identifier));
$r->map(":layer.tilejson",
array("controller"=>"maptile", "action"=>"tilejson"), array("layer"=>$_identifier));
$r->map(":layer.tilejsonp\?:argument=:callback",
array("controller"=>"maptile", "action"=>"tilejson"),
array("layer"=>$_identifier, "argument"=>$_identifier, "callback"=>$_identifier));
$r->run();
class BaseClass {
protected $layer;
protected $db;
public function __construct() {
}
protected function getMBTilesName() {
return $this->layer . ".mbtiles";
}
protected function openDB() {
$filename = $this->getMBTilesName();
if (file_exists($filename)) {
$this->db = new PDO('sqlite:' . $filename, '', '');
}
if (!isset($this->db)) {
$this->error(404, "Incorrect tileset name: " . $this->layer);
}
}
protected function closeDB() {
// close the database
$this->db = null;
}
protected function error($nr, $message) {
$http_codes = array(
404=>'Not Found',
500=>'Internal Server Error',
// we don't need the rest anyway ;-)
);
header($_SERVER['SERVER_PROTOCOL'] . " $nr {$http_codes[$nr]}");
echo $message;
exit ;
}
}
class ServerInfoController extends BaseClass {
public function __construct() {
}
public function hello() {
global $r;
$x = new TileMapServiceController();
echo "This is the " . $x->server_name . " version " . $x->server_version;
echo "<br /><br />Try these!";
echo "<ul>";
foreach ($r->routes as $route) {
if (strlen($route->url) > 0 && strpos($route->url, ":layer") === false) {
$url = $route->url;
echo "<li><a href='$url'>$url</a></li>";
}
}
$layers = glob("*.mbtiles");
foreach ($layers as $l) {
$l = str_replace(".mbtiles", "", $l);
$urls = array("$l/2/1/1.png", "$l.tilejson", "$l/2/1/1.json");
foreach ($urls as $u) {
echo "<li><a href='$u'>$u</a></li>";
}
}
echo "</ul>";
echo "<br/><br/>PS: non-exhaustive list, see source for details";
}
}
class MapTileController extends BaseClass {
protected $x;
protected $y;
protected $z;
protected $tileset;
protected $ext;
protected $is_tms;
public function __construct() {
$this->is_tms = false;
}
protected function set($layer, $x, $y, $z, $ext, $callback) {
$this->layer = $layer;
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->ext = $ext;
$this->callback = $callback;
}
public function serveTile($layer, $x, $y, $z, $ext, $callback) {
$this->set($layer, $x, $y, $z, $ext, $callback);
if (!$this->is_tms) {
$this->y = pow(2, $this->z) - 1 - $this->y;
}
switch (strtolower($this->ext)) {
case "json" :
case "jsonp" :
if (is_null($this->callback)) {
$this->jsonTile();
} else {
$this->jsonpTile();
}
break;
case "png" :
case "jpeg" :
case "jpg" :
$this->imageTile();
break;
}
}
public function serveTmsTile($tileset, $x, $y, $z, $ext, $callback) {
$this->is_tms = true;
$this->serveTile($tileset . "-tms", $x, $y, $z, $ext, $callback);
}
protected function jsonTile() {
$etag = $this->etag("json");
$this->checkCache($etag);
$json = $this->getUTFgrid();
// disable ZLIB ouput compression
ini_set('zlib.output_compression', 'Off');
// serve JSON file
header('Content-Type: application/json; charset=utf-8');
header('Content-Length: ' . strlen($json));
$this->cachingHeaders($etag);
echo $json;
}
protected function jsonpTile() {
$etag = $this->etag("jsonp");
$this->checkCache($etag);
$json = $this->getUTFgrid();
$output = $this->callback . "($json)";
// disable ZLIB output compression
ini_set('zlib.output_compression', 'Off');
// serve JSON file
header('Content-Type: application/json; charset=utf-8');
header('Content-Length: ' . strlen($output));
$this->cachingHeaders($etag);
echo $output;
}
protected function etag($type) {
return sha1(sprintf("%s-%s-%s-%s-%s-%s", $this->tileset, $this->x, $this->y, $this->z, $type, filemtime($this->getMBTilesName())));
}
protected function checkCache($etag) {
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
protected function cachingHeaders($etag=null) {
$day = 60*60*24;
$expires = 1 * $day;
// For an explanation on how the expires header and the etag header work together,
// please see http://stackoverflow.com/a/500103/426224
header("Expires: " . gmdate('D, d M Y H:i:s', time()+$expires));
header("Pragma: cache");
header("Cache-Control: max-age=$expires");
if (is_string($etag)) {
header("ETag: {$etag}");
}
}
protected function imageTile() {
$etag = $this->etag("img");
$this->checkCache($etag);
if ($this->is_tms) {
$this->tileset = substr($this->tileset, 0, strlen($this->tileset) - 4);
}
try {
$this->openDB();
$result = $this->db->query('select tile_data as t from tiles where zoom_level=' . $this->z . ' and tile_column=' . $this->x . ' and tile_row=' . $this->y);
$data = $result->fetchColumn();
if (!isset($data) || $data === FALSE) {
// did not find a tile - return an empty (transparent) tile
$png = imagecreatetruecolor(256, 256);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
header('Content-type: image/png');
$this->cachingHeaders($etag);
imagepng($png);
} else {
// Hooray, found a tile!
// - figure out which format (jpeg or png) it is in
$result = $this->db->query('select value from metadata where name="format"');
$resultdata = $result->fetchColumn();
$format = isset($resultdata) && $resultdata !== FALSE ? $resultdata : 'png';
if ($format == 'jpg') {
$format = 'jpeg';
}
// - serve the tile
header('Content-type: image/' . $format);
$this->cachingHeaders($etag);
print $data;
}
// done
$this->closeDB();
}
catch( PDOException $e ) {
$this->closeDB();
$this->error(500, 'Error querying the database: ' . $e->getMessage());
}
}
protected function getUTFgrid() {
$this->openDB();
try {
$flip = true;
if ($this->is_tms) {
$this->tileset = substr($this->tileset, 0, strlen($this->tileset) - 4);
$flip = false;
}
$result = $this->db->query('select grid as g from grids where zoom_level=' . $this->z . ' and tile_column=' . $this->x . ' and tile_row=' . $this->y);
$data = $result->fetchColumn();
if (!isset($data) || $data === FALSE) {
// nothing found - return empty JSON object
return "{}";
} else {
// get the gzipped json from the database
$grid = gzuncompress($data);
// manually add the data for the interactivity layer by means of string manipulation
// to prevent a bunch of costly calls to json_encode & json_decode
//
// first, strip off the last '}' character
$grid = substr(trim($grid),0,-1);
// then, add a new key labelled 'data'
$grid .= ',"data":{';
// stuff that key with the actual data
$result = $this->db->query('select key_name as key, key_json as json from grid_data where zoom_level=' . $this->z . ' and tile_column=' . $this->x . ' and tile_row=' . $this->y);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$grid .= '"' . $row['key'] . '":' . $row['json'] . ',';
}
// finish up
$grid = rtrim($grid,',') . "}}";
// done
return $grid;
}
}
catch( PDOException $e ) {
$this->closeDB();
$this->error(500, 'Error querying the database: ' . $e->getMessage());
}
}
public function tileJson($layer, $callback) {
$this->layer = $layer;
$this->openDB();
try {
$tilejson = array();
$tilejson['tilejson'] = "2.0.0";
$tilejson['scheme'] = "xyz";
$result = $this->db->query('select name, value from metadata');
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$key = trim($row['name']);
$value = $row['value'];
if (in_array($key, array('maxzoom', 'minzoom'))) {
$value = intval($value);
}
$tilejson[$key] = $value;
}
if (array_key_exists('bounds', $tilejson)) {
$tilejson['bounds'] = array_map('floatval', explode(',', $tilejson['bounds']));
}
if (array_key_exists('center', $tilejson)) {
$tilejson['center'] = array_map('floatval', explode(',', $tilejson['center']));
}
// find out the absolute URL to this script
$protocol = empty($_SERVER["HTTPS"])?"http":"https";
$server_url = $protocol . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["REQUEST_URI"]);
$tilejson['tiles'] = array(
$server_url . "/" . urlencode($layer) . "/{z}/{x}/{y}.png"
);
$tilejson['grids'] = array(
$server_url . "/" . urlencode($layer) . "/{z}/{x}/{y}.json"
);
if ($callback !== null) {
$json = "$callback(" . json_encode($tilejson) . ")";
} else {
$json = json_encode($tilejson);
}
ini_set('zlib.output_compression', 'Off');
header('Content-Type: application/json');
header('Content-Length: ' . strlen($json));
$this->cachingHeaders();
echo $json;
}
catch( PDOException $e ) {
$this->closeDB();
$this->error(500, 'Error querying the database: ' . $e->getMessage());
}
}
}
/**
* Implements a TileMapService that returns XML information on the provided
* services.
*
* @see http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification
* @author zverik (https://github.com/Zverik)
* @author E. Akerboom ([email protected])
*/
class TileMapServiceController extends BaseClass {
public function __construct() {
$this->server_name = "PHP TileMap server";
$this->server_version = "1.0.0";
}
public function root() {
$base = $this->getBaseUrl();
header('Content-type: text/xml');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<Services>
<TileMapService title="{$this->server_name}" version="{$this->server_version}" href="${base}{$this->server_version}/" />
</Services>
EOF;
}
public function service() {
$base = $this->getBaseUrl();
header('Content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
echo "\n<TileMapService version=\"1.0.0\" services=\"$base\">";
echo "\n\t<Title>{$this->server_name} v{$this->server_version}</Title>";
echo "\n\t<Abstract />";
echo "\n\t<TileMaps>";
if ($handle = opendir('.')) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/^[\w\d_-]+\.mbtiles$/', $file) && is_file($file)) {
try {
$db = new PDO('sqlite:' . $file);
$params = $this->readparams($db);
$name = htmlspecialchars($params['name']);
$identifier = str_replace('.mbtiles', '', $file);
echo "\n\t\t<TileMap title=\"$name\" srs=\"OSGEO:41001\" profile=\"global-mercator\" href=\"${base}1.0.0/$identifier\" />";
}
catch( PDOException $e ) {
// nothing
}
}
}
}
echo "\n\t</TileMaps>";
echo "\n</TileMapService>";
}
function resource($layer) {
try {
$this->layer = $layer;
$this->openDB();
$params = $this->readparams($this->db);
$title = htmlspecialchars($params['name']);
$description = htmlspecialchars($params['description']);
$format = $params['format'];
switch (strtolower($format)) {
case "jpg" :
case "jpeg" :
$mimetype = "image/jpeg";
break;
default :
case "png" :
$format = "png";
$mimetype = "image/png";
break;
}
$base = $this->getBaseUrl();
header('Content-type: text/xml');
echo <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<TileMap version="1.0.0" tilemapservice="{$base}1.0.0/">
<Title>$title</Title>
<Abstract>$description</Abstract>
<SRS>OSGEO:41001</SRS>
<BoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
<Origin x="0" y="0"/>
<TileFormat width="256" height="256" mime-type="$mimetype" extension="$format"/>
<TileSets profile="global-mercator">
EOF;
foreach ($this->readzooms($this->db) as $zoom) {
$href = $base . "1.0.0/" . $this->layer . "/" . $zoom;
$units_pp = 78271.516 / pow(2, $zoom);
echo "<TileSet href=\"$href\" units-per-pixel=\"$units_pp\" order=\"$zoom\" />";
}
echo <<<EOF
</TileSets>
</TileMap>
EOF;
}
catch( PDOException $e ) {
$this->error(404, "Incorrect tileset name: " . $this->layer);
}
}
function readparams($db) {
$params = array();
$result = $db->query('select name, value from metadata');
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$params[$row['name']] = $row['value'];
}
return $params;
}
function readzooms($db) {
$params = $this->readparams($db);
$minzoom = $params['minzoom'];
$maxzoom = $params['maxzoom'];
return range($minzoom, $maxzoom);
}
function getBaseUrl() {
$protocol = empty($_SERVER["HTTPS"])?"http":"https";
return $protocol . '://' . $_SERVER['HTTP_HOST'] . preg_replace('/\/(1.0.0\/)?[^\/]*$/', '/', $_SERVER['REQUEST_URI']);
}
}
/**
* Rails like routing for PHP
*
* Based on http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/
* but extended in significant ways:
*
* 1. Can now be deployed in a subdirectory, not just the domain root
* 2. Will now call the indicated controller & action. Named arguments are
* converted to similarly method arguments, i.e. if you specify :id in the
* URL mapping, the value of that parameter will be provided to the method's
* '$id' parameter, if present.
* 3. Will now allow URL mappings that contain a '?' - useful for mapping JSONP urls
* 4. Should now correctly deal with spaces (%20) and other stuff in the URL
*
* @version 2.0
* @author Dan Sosedoff <http://twitter.com/dan_sosedoff>
* @author E. Akerboom <[email protected]>
*/
define('ROUTER_DEFAULT_CONTROLLER', 'home');
define('ROUTER_DEFAULT_ACTION', 'index');
class Router extends BaseClass {
public $request_uri;
public $routes;
public $controller, $controller_name;
public $action, $id;
public $params;
public $route_found = false;
public function __construct() {
$request = $this->get_request();
$this->request_uri = $request;
$this->routes = array();
}
public function get_request() {
// find out the absolute path to this script
$here = str_replace("\\", "/", realpath(rtrim(dirname(__FILE__), '/')) . "/");
// find out the absolute path to the document root
$document_root = str_replace("\\", "/", realpath($_SERVER["DOCUMENT_ROOT"]) . "/");
// let's see if we can return a path that is expressed *relative* to the script
// (i.e. if this script is in '/sites/something/router.php', and we are
// requesting /sites/something/here/is/my/path.png, then this function will
// return 'here/is/my/path.png')
if (strpos($here, $document_root) !== false) {
$relative_path = "/" . str_replace($document_root, "", $here);
return urldecode(str_replace($relative_path, "", $_SERVER["REQUEST_URI"]));
}
// nope - we couldn't get the relative path... too bad! Return the absolute path
// instead.
return urldecode($_SERVER["REQUEST_URI"]);
}
public function map($rule, $target = array(), $conditions = array()) {
$this->routes[$rule] = new Route($rule, $this->request_uri, $target, $conditions);
}
public function default_routes() {
$this->map(':controller');
$this->map(':controller/:action');
$this->map(':controller/:action/:id');
}
private function set_route($route) {
$this->route_found = true;
$params = $route->params;
$this->controller = $params['controller']; unset($params['controller']);
$this->action = $params['action']; unset($params['action']);
if (isset($params['id'])) {
$this->id = $params['id'];
}
$this->params = array_merge($params, $_GET);
if (empty($this->controller)) {
$this->controller = ROUTER_DEFAULT_CONTROLLER;
}
if (empty($this->action)) {
$this->action = ROUTER_DEFAULT_ACTION;
}
if (empty($this->id)) {
$this->id = null;
}
// determine controller name
$this->controller_name = implode(array_map('ucfirst', explode('_', $this->controller . "_controller")));
}
public function match_routes() {
foreach ($this->routes as $route) {
if ($route->is_matched) {
$this->set_route($route);
break;
}
}
}
public function run() {
$this->match_routes();
if ($this->route_found) {
// we found a route!
if (class_exists($this->controller_name)) {
// ... the controller exists
$controller = new $this->controller_name();
if (method_exists($controller, $this->action)) {
// ... and the action as well! Now, we have to figure out
// how we need to call this method:
// iterate this method's parameters and compare them with the parameter names
// we defined in the route. Then, reassemble the values from the URL and put
// them in the same order as method's argument list.
$m = new ReflectionMethod($controller, $this->action);
$params = $m->getParameters();
$args = array();
foreach ($params as $i=>$p) {
if (isset($this->params[$p->name])) {
$args[$i] = urldecode($this->params[$p->name]);
} else {
// we couldn't find this parameter in the URL! Set it to 'null' to indicate this.
$args[$i] = null;
}
}
// Finally, we call the function with the resulting list of arguments
call_user_func_array(array($controller, $this->action), $args);
} else {
$this->error(404, "Action " . $this->controller_name . "." . $this->action . "() not found");
}
} else {
$this->error(404, "Controller " . $this->controller_name . " not found");
}
} else {
$this->error(404, "Page not found");
}
}
}
class Route {
public $is_matched = false;
public $params;
public $url;
private $conditions;
function __construct($url, $request_uri, $target, $conditions) {
$this->url = $url;
$this->params = array();
$this->conditions = $conditions;
$p_names = array();
$p_values = array();
// extract pattern names (catches :controller, :action, :id, etc)
preg_match_all('@:([\w]+)@', $url, $p_names, PREG_PATTERN_ORDER);
$p_names = $p_names[0];
// make a version of the request with and without the '?x=y&z=a&...' part
$pos = strpos($request_uri, '?');
if ($pos) {
$request_uri_without = substr($request_uri, 0, $pos);
} else {
$request_uri_without = $request_uri;
}
foreach (array($request_uri, $request_uri_without) as $request) {
$url_regex = preg_replace_callback('@:[\w]+@', array($this, 'regex_url'), $url);
$url_regex .= '/?';
if (preg_match('@^' . $url_regex . '$@', $request, $p_values)) {
array_shift($p_values);
foreach ($p_names as $index=>$value) {
$this->params[substr($value, 1)] = urldecode($p_values[$index]);
}
foreach ($target as $key=>$value) {
$this->params[$key] = $value;
}
$this->is_matched = true;
break;
}
}
unset($p_names);
unset($p_values);
}
function regex_url($matches) {
$key = str_replace(':', '', $matches[0]);
if (array_key_exists($key, $this->conditions)) {
return '(' . $this->conditions[$key] . ')';
} else {
return '([a-zA-Z0-9_\+\-%]+)';
}
}
}
?>