Prado\Web\THttpRequest::resolveRequest PHP Méthode

resolveRequest() public méthode

This method implements a URL-based service resolution. A URL in the format of /index.php?sp=serviceID.serviceParameter will be resolved with the serviceID and the serviceParameter. You may override this method to provide your own way of service resolution.
See also: constructUrl
public resolveRequest ( $serviceIDs ) : string
Résultat string the currently requested service ID, null if no service ID is found
    public function resolveRequest($serviceIDs)
    {
        Prado::trace("Resolving request from " . $_SERVER['REMOTE_ADDR'], 'Prado\\Web\\THttpRequest');
        $getParams = $this->parseUrl();
        foreach ($getParams as $name => $value) {
            $_GET[$name] = $value;
        }
        $this->_items = array_merge($_GET, $_POST);
        $this->_requestResolved = true;
        foreach ($serviceIDs as $serviceID) {
            if ($this->contains($serviceID)) {
                $this->setServiceID($serviceID);
                $this->setServiceParameter($this->itemAt($serviceID));
                return $serviceID;
            }
        }
        return null;
    }

Usage Example

Exemple #1
0
 public function testRequestWithUrlMapping()
 {
     Prado::Using('System.Web.TUrlMapping');
     $confstr = '<config><url ServiceId="testService" ServiceParameter="testServiceParam" pattern="test/{param}/?" parameters.param="\\w+"/></config>';
     $config = new TXmlDocument('1.0', 'utf8');
     $config->loadFromString($confstr);
     $module = new TUrlMapping();
     self::$app->setModule('friendly-url', $module);
     if (isset($_GET['page'])) {
         unset($_GET['page']);
     }
     // Remove service from a previous test !
     $_SERVER['REQUEST_URI'] = '/index.php/test/value2';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHP_SELF'] = '/index.php/test/value2';
     $_SERVER['QUERY_STRING'] = '';
     $_SERVER['PATH_INFO'] = '/test/value2';
     $request = new THttpRequest();
     $request->setUrlManager('friendly-url');
     $request->setUrlFormat(THttpRequestUrlFormat::Path);
     $request->init(null);
     $module->init($config);
     self::assertEquals('testService', $request->resolveRequest(array('page', 'testService')));
 }