Ejemplo n.º 1
0
Archivo: arr.php Proyecto: tapiau/muyo
 /**
  * Returns [n..$]
  *
  * @param int $n
  *
  * @return callable
  */
 function array_rest_dg($n = 1)
 {
     return function () use($n) {
         $array = func_get_args();
         $array = array_shift($array);
         return array_rest($array, $n);
     };
 }
Ejemplo n.º 2
0
 /**
  * Creates a new \Nethgui\Controller\Request object from
  * current HTTP request.
  *
  * @param array $parameters
  * @return \Nethgui\Controller\Request
  */
 private function createRequestModApache()
 {
     if (ini_get("magic_quotes_gpc")) {
         throw new \LogicException("magic_quotes_gpc directive must be disabled!", 1377176328);
     }
     $isMutation = FALSE;
     $postData = array();
     $getData = $_GET;
     $pathInfo = array();
     $locale = '';
     $localeDefault = $this->getClientLocaleDefault();
     // Split PATH_INFO
     if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '/') {
         $pathInfo = array_rest(explode('/', $_SERVER['PATH_INFO']));
         $pathHead = array_head($pathInfo);
         if (!in_array(substr($pathHead, 0, 2), $this->dc['l10n.available_languages'])) {
             throw new Exception\HttpException('Language not found', 404, 1377519247);
         }
         $locale = $pathHead;
         $pathInfo = array_rest($pathInfo);
         foreach ($pathInfo as $pathPart) {
             if ($pathPart === '.' || $pathPart === '..' || $pathPart === '') {
                 throw new Exception\HttpException('Bad Request', 400, 1322217901);
             }
         }
     }
     // Extract the requested output format (xhtml, json...)
     $format = $this->extractTargetFormat($pathInfo);
     // Transform the splitted PATH_INFO into a nested array, where each
     // PATH_INFO part is the key of a nested level:
     $pathInfoMod = array();
     $cur =& $pathInfoMod;
     foreach ($pathInfo as $pathPart) {
         $cur[$pathPart] = array();
         $cur =& $cur[$pathPart];
     }
     // FIXME:
     // Copy root level scalar GET variables into the current module for backward
     // compatibility:
     $cur = array_merge(array_filter($_GET, 'is_string'), $cur);
     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
         $isMutation = TRUE;
         if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json; charset=UTF-8') {
             // Decode RAW request
             $postData = json_decode($GLOBALS['HTTP_RAW_POST_DATA'], true);
             if (is_null($postData)) {
                 throw new \Nethgui\Exception\HttpException('Bad Request', 400, 1322148404);
             }
         } else {
             // Use PHP global:
             $postData = $_POST;
         }
     }
     $dc = $this->dc;
     $R = array_replace_recursive($pathInfoMod, $getData, $postData);
     $request = new \Nethgui\Controller\Request($R);
     $request->setLog($this->dc['Log'])->setAttribute('isMutation', $isMutation)->setAttribute('format', $format)->setAttribute('locale', $locale)->setAttribute('localeDefault', $localeDefault)->setAttribute('userClosure', function () use($dc) {
         return $dc['User'];
     });
     // Append the language code to the url parts:
     $this->urlParts[] = $request->getLocale() . '/';
     return $request;
 }
Ejemplo n.º 3
0
Archivo: net.php Proyecto: tapiau/muyo
 /**
  * @param string $uri_data
  * @return array
  * @throws Exception
  */
 function uri_data_unpack($uri_data)
 {
     debug_enforce(preg_match('/^data:([^;,]+)?;?([^;,]+)?;?(base64)?,(.+)$/', $uri_data, $matches), 'Malformed data uri: ' . var_dump_human_compact($uri_data));
     return array_rest($matches, 1);
 }