private function processUri($uri)
 {
     $hasBodyParams = false;
     $queryString = null;
     $queryStringHasParams = false;
     // get rid of any leading /
     if ($uri[0] == '/') {
         $uri = substr($uri, 1);
     }
     // do we have any query string params?
     $hasQueryString = strripos($uri, '?');
     if ($hasQueryString !== false) {
         $queryString = substr($uri, $hasQueryString + 1);
         $queryStringHasParams = strpos($queryString, '{') === false ? false : true;
         $queryString = explode('&', $queryString);
         $uri = substr($uri, 0, $hasQueryString);
         $this->key = '?';
     }
     // cleanup and prepare:
     // do we end with a /
     $uri = strripos($uri, '/') == strlen($uri) - 1 ? substr($uri, 0, -1) : $uri;
     $hasBodyParams = strpos($uri, '{') === false ? false : true;
     $segments = explode('/', $uri);
     // parse the main URI body
     if ($hasBodyParams) {
         $this->processArray($segments);
     } else {
         $this->parts = $segments;
         $this->key .= implode("", $segments);
     }
     if (is_array($queryString)) {
         $this->processArray($queryString, true);
     }
     $this->hash = AMServiceManager::generateKey($this->key, $this->parameter_count);
 }
Esempio n. 2
0
 public function get_Details($name)
 {
     if (empty($name)) {
         AMServiceManager::not_found();
     }
     echo "get_Details: " . $name;
 }
Esempio n. 3
0
 *
 *    LICENSE:
 *
 *    Licensed under the Apache License, Version 2.0 (the "License"); you may not
 *    use this file except in compliance with the License.  You may obtain a copy
 *    of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 *    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 *    PURPOSE. See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package samples
 *    @subpackage services
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2010 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/* 
	requires path appropriate .htaccess redirection to this script
*/
require '../../axismundi/services/AMServiceManager.php';
require 'Bookmarks.php';
$manager = new AMServiceManager();
$manager->bindContract(new Bookmarks());
$manager->start();
 public function start()
 {
     $endpoints = null;
     $method = strtoupper($_SERVER['REQUEST_METHOD']);
     $termination = strripos($_SERVER['REQUEST_URI'], '?');
     $path = substr($_SERVER['REQUEST_URI'], 0, $termination === false ? strlen($_SERVER['REQUEST_URI']) : $termination);
     if ($path[0] == '/') {
         $path = substr($path, 1);
     }
     if ($path[strlen($path) - 1] == '/') {
         $path = substr($path, 0, strlen($path) - 1);
     }
     $segments = explode("/", $path);
     if ($_SERVER['QUERY_STRING']) {
         $queryString = explode('&', $_SERVER['QUERY_STRING']);
         foreach ($queryString as $part) {
             list($argName, $argValue) = explode('=', $part);
             $segments[] = $argName;
             $segments[] = $argValue;
         }
     }
     $segmentsLength = count($segments);
     $branch = $this->contract->endpoints[$method];
     $endpoints = array();
     foreach ($branch as $service) {
         $match = array_intersect($segments, $service->parts);
         $params = $segmentsLength - count($match);
         if ($params == $service->parameter_count && count(array_diff($service->parts, $match)) == 0) {
             $input = strlen($_SERVER['QUERY_STRING']) ? '?' . implode("", $match) : implode("", $match);
             $key = AMServiceManager::generateKey($input, $params);
             if (array_key_exists($key, $branch)) {
                 $args = array_diff($segments, $service->parts);
                 // we apply some weighting.  matching path arguments hold more importance that parameter arguments
                 // so if we have an endnpoint defined as /{arg} vs /users
                 // /users will be given a higher priority than /{arg}
                 $score = $params + count($match) * 2;
                 $endpoints[] = array('score' => $score, 'arguments' => $args, 'service' => $service);
             }
         }
     }
     $choices = count($endpoints);
     if ($choices) {
         if ($choices > 1) {
             $this->execute($endpoints[0]['service'], $endpoints[0]['arguments']);
         } else {
             usort($endpoints, array($this, "sort_endpoints_score"));
             $selection = array_pop($endpoints);
             $this->execute($selection['service'], $selection['arguments']);
         }
     } else {
         AMServiceManager::not_found();
     }
 }