mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
23786784ef
Summary: Adds the Balanced PHP API to externals/. Ref T2787. Test Plan: Used in next diff. Reviewers: btrahan, chad Reviewed By: chad CC: aran, aurelijus Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D5764
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace RESTful;
|
|
|
|
class URISpec
|
|
{
|
|
public $collection_uri = null,
|
|
$name,
|
|
$idNames;
|
|
|
|
public function __construct($name, $idNames, $root = null)
|
|
{
|
|
$this->name = $name;
|
|
if (!is_array($idNames)) {
|
|
$idNames = array($idNames);
|
|
}
|
|
$this->idNames = $idNames;
|
|
if ($root != null) {
|
|
if ($root == '' || substr($root, -1) == '/') {
|
|
$this->collection_uri = $root . $name;
|
|
} else {
|
|
$this->collection_uri = $root . '/' . $name;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function match($uri)
|
|
{
|
|
$parts = explode('/', rtrim($uri, "/"));
|
|
|
|
// collection
|
|
if ($parts[count($parts) - 1] == $this->name) {
|
|
|
|
return array(
|
|
'collection' => true,
|
|
);
|
|
}
|
|
|
|
// non-member
|
|
if (count($parts) < count($this->idNames) + 1 ||
|
|
$parts[count($parts) - 1 - count($this->idNames)] != $this->name
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
// member
|
|
$ids = array_combine(
|
|
$this->idNames,
|
|
array_slice($parts, -count($this->idNames))
|
|
);
|
|
$result = array(
|
|
'collection' => false,
|
|
'ids' => $ids,
|
|
);
|
|
|
|
return $result;
|
|
}
|
|
}
|