fedecarg / apify-library

Apify is a small open source library that delivers new levels of developer productivity by simplifying the creation of RESTful architectures. It helps development teams deliver quality web services and applications in reduced amounts of time. If you are familiar with the Zend Framework, then you already know how to use Apify.
http://www.apifydoc.com
Other
265 stars 49 forks source link

Request::getUrlPath returns wrong value #13

Open elvetemedve opened 12 years ago

elvetemedve commented 12 years ago

If you use Request::setUrlKeyword or Request::setUrlSegment without Request::enableRestfulMapping, than Request::getUrlPath will return the full URI strarting from webroot instead of the expected suffix.

<?php
define('ROOT_DIR', realpath(dirname(__FILE__) . '/../'));
define('APP_DIR', ROOT_DIR . '/app');

require_once ROOT_DIR . '/config/config.php';

try {
    $request = new Request();
    $request->setUrlKeyword('api');  // we want the part after the "api" segment 
    $request->enableUrlRewriting();
    $request->addRoutes(include ROOT_DIR.'/config/routes.php');
    $request->dispatch();
} catch (Exception $e) {
    $request->handleException($e);
}

Request:

GET /apify/api/users

Expected result:

Actual result:

mpmf commented 12 years ago

Here is a quick and dirty solution (if using setUrlSegment). Put this in Request.php at the getUrlPath() function:

if (null !== $this->urlSegment) { $i = $this->urlSegment; while ($i>0) { $urlPath=substr($urlPath, strpos($urlPath, '/', 1)); $i--; } }

right before the $this->setUrlPath(urldecode($urlPath));

But remember, this is just a quick solution, not a good one.