[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace RESTful; 4 5 class URISpec 6 { 7 public $collection_uri = null, 8 $name, 9 $idNames; 10 11 public function __construct($name, $idNames, $root = null) 12 { 13 $this->name = $name; 14 if (!is_array($idNames)) { 15 $idNames = array($idNames); 16 } 17 $this->idNames = $idNames; 18 if ($root != null) { 19 if ($root == '' || substr($root, -1) == '/') { 20 $this->collection_uri = $root . $name; 21 } else { 22 $this->collection_uri = $root . '/' . $name; 23 } 24 } 25 } 26 27 public function match($uri) 28 { 29 $parts = explode('/', rtrim($uri, "/")); 30 31 // collection 32 if ($parts[count($parts) - 1] == $this->name) { 33 34 return array( 35 'collection' => true, 36 ); 37 } 38 39 // non-member 40 if (count($parts) < count($this->idNames) + 1 || 41 $parts[count($parts) - 1 - count($this->idNames)] != $this->name 42 ) { 43 return null; 44 } 45 46 // member 47 $ids = array_combine( 48 $this->idNames, 49 array_slice($parts, -count($this->idNames)) 50 ); 51 $result = array( 52 'collection' => false, 53 'ids' => $ids, 54 ); 55 56 return $result; 57 } 58 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |