示例#1
0
文件: Route.php 项目: nebiros/yasc
 /**
  *
  * @return array
  */
 protected function _setupParams()
 {
     if (count($this->_matches) < 2) {
         return;
     }
     $params = array();
     array_shift($this->_matches);
     $matchesCount = count($this->_matches);
     $paramValues = array_values((array) $this->_paramsList);
     $namesCount = count($paramValues);
     if ($matchesCount < $namesCount) {
         $tmp = array_fill(0, $namesCount - $matchesCount, null);
         $this->_matches = array_merge($this->_matches, $tmp);
     } else {
         if ($matchesCount > $namesCount) {
             $paramValues = range($namesCount, $matchesCount - 1);
         }
     }
     $combination = array_combine($paramValues, $this->_matches);
     if (true === function_exists("array_replace")) {
         $params = array_replace($params, $combination);
     } else {
         $params = Yasc_Util::arrayReplace($params, $combination);
     }
     $pairs = array();
     foreach ($params as $index => $param) {
         if (false === strpos($param, $this->_request->getUrlDelimiter())) {
             continue;
         }
         $dobleAsteriskParam = $param;
         unset($params[$index]);
         $pairs = array_merge($pairs, explode($this->_request->getUrlDelimiter(), $dobleAsteriskParam));
     }
     // get params by pairs, like zend framework does,
     // param1/value1/param2/value2, param1 will be the key of the param,
     // value1 the value of param1, if the value is not present NULL is his
     // value.
     //
     // Check Zend_Controller_Router_Route_Module#match method and see how
     // this works.
     if (($n = count($pairs)) > 0) {
         for ($i = 0; $i < $n; $i = $i + 2) {
             $key = urldecode($pairs[$i]);
             $val = isset($pairs[$i + 1]) ? urldecode($pairs[$i + 1]) : null;
             $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
         }
     }
     return $params;
 }
示例#2
0
文件: Renderer.php 项目: nebiros/yasc
 /**
  * 
  * @param string $type "json", "js", "xml"
  * @param mixed $message
  * @param Array $options (bool) "set_common_headers", (bool) "echo"
  * @return string
  */
 public function render($type, $message = "", array $options = null)
 {
     if (!isset($options["set_common_headers"])) {
         $options["set_common_headers"] = true;
     }
     if (!isset($options["echo"])) {
         $options["echo"] = true;
     }
     if ((bool) $options["set_common_headers"]) {
         $this->setCommonHeaders();
     }
     $this->setContentTypeHeaderFor($type);
     $return = "";
     switch ($type) {
         case "json":
             $return = json_encode($message, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
             break;
         case "js":
             $return = $message;
             break;
         case "xml":
             if (is_array($message)) {
                 $return = Yasc_Util::arrayToXml($message);
             } else {
                 if (is_string($message)) {
                     $return = $message;
                 }
             }
             break;
         default:
             $return = $message;
             break;
     }
     if ((bool) $options["echo"]) {
         \Yasc_App::view()->layout()->disable();
         \Yasc_App::response()->setBody($return)->sendResponse();
         exit;
     }
     return $return;
 }