Пример #1
0
 /**
  * Compiles URL addressing selected script of current application.
  *
  * @param string $scriptName pathname of script relative to application folder
  * @param array $parameters set of parameters to pass in query
  * @param mixed $selector first of multiple optional selectors to include
  * @return string URL of addressed script including optional parameters
  */
 public function scriptURL($scriptName, $parameters = array(), $selector = null)
 {
     if (!is_array($parameters)) {
         throw new \InvalidArgumentException('parameters must be array');
     }
     if (substr($scriptName, -4) == '.php') {
         $scriptName = substr($scriptName, 0, -4);
     }
     $selectors = func_get_args();
     $selectors = array_slice($selectors, 2);
     if (count($selectors) == 1 && is_array($selectors[0])) {
         $selectors = array_shift($selectors);
     }
     $selectors = implode('/', array_map(function ($selector) {
         return rawurlencode($selector);
     }, $selectors));
     switch (txf::getContextMode()) {
         case txf::CTXMODE_NORMAL:
         default:
             $url = path::glue($this->url, $scriptName, $selectors);
             break;
         case txf::CTXMODE_REWRITTEN:
             $proxy = $this->usedProxy === true ? '' : $this->usedProxy;
             if ($this->gotNameFromEnvironment) {
                 $url = path::glue($this->context->url, $proxy, $scriptName, $selectors);
             } else {
                 $url = path::glue($this->context->url, $proxy, $this->name, $scriptName, $selectors);
             }
             break;
     }
     return $url . (count($parameters) ? '?' . http_build_query($parameters) : '');
 }
Пример #2
0
 /**
  * Retrieves part of request URI selecting current application and script.
  *
  * The fetched request URI is provided as array of pathname elements, that is
  * pathname might be derived by joining returned elements with '/'.
  *
  * @note Fetched request URI might include further selectors to be processed
  *       by requested script, e.g.
  *
  *       myapp/myscript/par1-of-script/par2-of-script
  *
  * @param string $detectedProxy name of detected proxy script
  * @return array sequence of filenames contained in requested URI for selecting script
  */
 public function getRequestedScriptUri(&$detectedProxy)
 {
     switch (txf::getContextMode()) {
         case txf::CTXMODE_REWRITTEN:
             assert('$_SERVER[REDIRECT_URL] || $_SERVER[PATH_INFO] || $_SERVER[REQUEST_URI]');
             // get originally requested script (e.g. prior to rewrite)
             if (trim($_SERVER['REQUEST_URI']) !== '') {
                 // use of lighttpd's rewriting detected
                 $query = strtok($_SERVER['REQUEST_URI'], '?');
                 // mark rewrite mode by not selecting any valid used proxy
                 $detectedProxy = true;
             } else {
                 if (trim($_SERVER['REDIRECT_URL']) !== '') {
                     // use of mod_rewrite detected
                     $query = $_SERVER['REDIRECT_URL'];
                     // mark rewrite mode by not selecting any valid used proxy
                     $detectedProxy = true;
                 } else {
                     // request for proxy script (run.php) detected
                     $query = $_SERVER['PATH_INFO'];
                     // remember proxy script used this time, if any
                     $detectedProxy = $this->scriptPathname;
                 }
             }
             // derive list of application and script selectors
             return path::stripCommonPrefix(explode('/', $query), $this->prefixPathname);
             // txf::CTXMODE_NORMAL
         // txf::CTXMODE_NORMAL
         default:
             // expect application and script selectors being part of requested
             // script pathname
             return preg_split('#/+#', $this->applicationScriptPathname);
     }
 }