Esempio n. 1
0
 public function execute($httpRequest, $route, $defaults = array())
 {
     $defaults = new Dictionary($defaults);
     $uri = $httpRequest->getUri();
     $tokens = String::set($route)->tokenize('{', '}');
     $uriPattern = $uri;
     foreach ($tokens as $token) {
         $uriPattern = str_replace($token, '@', $uriPattern);
     }
     $uriSegments = String::set($uriPattern)->split('@');
     $counter = 0;
     foreach ($tokens as $idx => $token) {
         if (substr($token, 0, 1) == '{') {
             $tokenName = String::set($token)->get('{', '}');
             $tokens[$idx] = $uriSegments->get($counter);
             if ($tokens[$idx]) {
                 $defaults->set((string) $tokenName, $tokens[$idx]);
             }
             ++$counter;
         }
     }
     if ($uri == trim(join('', $tokens), '/')) {
         $httpRequest->getRouteData()->merge($defaults);
         $httpRequest->getParam()->merge($defaults);
         return $httpRequest->getRouteData();
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Initializes a new instance of that class.
  *
  * @param IEnumerable $grps The sequence of groupings.
  *
  * @throws \System\ArgumentException
  */
 public function __construct($grps)
 {
     $grps = static::asIterator($grps, true);
     $dict = new Dictionary(null, null, null, \sprintf('$x => $x instanceof %s', IGrouping::class));
     while ($grps->valid()) {
         /* @var IGrouping $curGrouping */
         $curGrouping = $grps->current();
         $dict->add($curGrouping->key(), $curGrouping);
         $grps->next();
     }
     parent::__construct($dict);
 }
Esempio n. 3
0
 private function httpFiles()
 {
     $array = array();
     foreach ($_FILES as $name => $file) {
         if (is_array($file['name'])) {
             $count = count($file['name']);
             for ($i = 0; $i < $count; $i++) {
                 if ($file['error'][$i] == UPLOAD_ERR_OK) {
                     $array[$name . $i]['name'] = $file['name'][$i];
                     $array[$name . $i]['type'] = $file['type'][$i];
                     $array[$name . $i]['tmp_name'] = $file['tmp_name'][$i];
                     $array[$name . $i]['size'] = $file['size'][$i];
                 }
             }
         } else {
             if ($file['error'] == UPLOAD_ERR_OK) {
                 $array[$name] = $file;
             }
         }
     }
     $list = new Dictionary();
     foreach ($array as $key => $item) {
         $list->add($key, new HttpFile($item['name'], $item['tmp_name'], $item['type'], $item['size']));
     }
     return $list;
 }