コード例 #1
0
ファイル: CliRoute.php プロジェクト: pframework/p
 public function match(SourceInterface $source)
 {
     if (!$source instanceof CliSource) {
         return false;
     }
     if (count($this->specificationParts) == 0) {
         return array();
     }
     $argvParts = $source->getArguments();
     $curArgvPart = array_shift($argvParts);
     $parameters = array();
     foreach ($this->specificationParts as $i => $specPart) {
         switch ($specPart[0]) {
             case self::PART_WORD:
                 if ($specPart[1] != $curArgvPart) {
                     return false;
                 } else {
                     $curArgvPart = array_shift($argvParts);
                     continue;
                 }
                 break;
             case self::PART_PARAMETER:
                 $parameterName = ltrim(rtrim($specPart[1], '?'), ':');
                 $parameters[$parameterName] = null;
                 if ($curArgvPart == '' && substr($specPart[1], -1) != '?') {
                     return false;
                 }
                 $parameters[$parameterName] = $curArgvPart;
                 $curArgvPart = array_shift($argvParts);
                 break;
             case self::PART_OPTION:
                 $optionName = substr($specPart[1], 1);
                 $parameters[$optionName] = array();
                 while ($curArgvPart[0] == '-') {
                     $parameters[$optionName][] = $curArgvPart;
                     $curArgvPart = array_shift($argvParts);
                 }
                 break;
         }
     }
     return $parameters;
 }