function rewrite(IWebContext $webContext)
 {
     $request = $webContext->getRequest();
     if (!$request->hasVar($this->name, $this->requestPart)) {
         if ($this->isOptional) {
             $value = $this->defaultValue;
         } else {
             throw new RewriteException("variable {$this->name} is not defined by the request", $this, $webContext);
         }
     } else {
         $value = $request->getVar($this->name, $this->requestPart);
     }
     return array($this->name => $value);
 }
 function rewrite(IWebContext $webContext)
 {
     $pathChunks = explode('/', $webContext->getRequest()->getHttpUrl()->getVirtualPath());
     array_shift($pathChunks);
     reset($pathChunks);
     if (sizeof($this->chunkRewriters) > sizeof($pathChunks)) {
         throw new RewriteException('wrong path chunk count', $this, $webContext);
     }
     $parameters = array();
     foreach ($this->chunkRewriters as $chunkRewriter) {
         $pathChunk = current($pathChunks);
         if ($chunkRewriter->isLast() && $chunkRewriter->isGreedy()) {
             $pathChunk = join('/', array_slice($pathChunks, key($pathChunks)));
             if (empty($pathChunk)) {
                 throw new RewriteException('greedy chunks does not capture empty values', $this, $webContext);
             }
         }
         if ($chunkRewriter->getValueCount() && !in_array($pathChunk, $chunkRewriter->getValues())) {
             throw new RewriteException('path chunks` value should be in set of predefined values', $this, $webContext);
         }
         if ($name = $chunkRewriter->getName()) {
             $parameters[$name] = $pathChunk;
         }
         next($pathChunks);
     }
     return $parameters;
 }