コード例 #1
0
ファイル: GetOption.php プロジェクト: alexpw/Console
 /**
  * Prepare the pipette.
  *
  * @access  public
  * @param   array                         $options    The option definition.
  * @param   \Hoa\Console\Core\Cli\Parser  $parser     The parser.
  * @return  void
  * @throw   \Hoa\Console\Exception
  */
 public function __construct(array $options, Parser $parser)
 {
     $this->_options = $options;
     $this->_parser = $parser;
     if (empty($options)) {
         $this->_pipette[null] = null;
         return;
     }
     $names = array();
     $_names = array();
     foreach ($options as $i => $option) {
         if (isset($option[self::OPTION_NAME])) {
             $names[$option[self::OPTION_NAME]] = $i;
         }
         if (isset($option[self::OPTION_VAL])) {
             $names[$option[self::OPTION_VAL]] = $i;
         }
     }
     $_names = array_keys($names);
     $switches = $parser->getSwitches();
     foreach ($switches as $name => $value) {
         if (false === in_array($name, $_names)) {
             if (1 === strlen($name)) {
                 $this->_pipette[] = array('__ambiguous', array('solutions' => array(), 'value' => $value, 'option' => $name));
                 continue;
             }
             $haystack = implode(';', $_names);
             $differences = (int) ceil(strlen($name) / 3);
             $searched = \Hoa\String\Search::approximated($haystack, $name, $differences);
             $solutions = array();
             foreach ($searched as $s) {
                 $h = substr($haystack, $s['i'], $s['l']);
                 if (false !== strpos($h, ';') || false !== in_array($h, array_keys($switches)) || false === in_array($h, $_names)) {
                     continue;
                 }
                 $solutions[] = $h;
             }
             if (empty($solutions)) {
                 continue;
             }
             $this->_pipette[] = array('__ambiguous', array('solutions' => $solutions, 'value' => $value, 'option' => $name));
             continue;
         }
         $option = $options[$names[$name]];
         $argument = $option[self::OPTION_HAS_ARG];
         if (self::NO_ARGUMENT === $argument) {
             if (!is_bool($value)) {
                 $parser->transferSwitchToInput($name, $value);
             }
         } elseif (self::REQUIRED_ARGUMENT === $argument && !is_string($value)) {
             throw new Exception('The argument %s requires a value (it is not a switch).', 0, $name);
         }
         $this->_pipette[] = array($option[self::OPTION_VAL], $value);
     }
     $this->_pipette[null] = null;
     reset($this->_pipette);
     return;
 }
コード例 #2
0
ファイル: Search.php プロジェクト: Hywan/String
 public function case_approximated()
 {
     $this->given($x = 'GATAA', $y = 'CAGATAAGAGAA', $k = 1)->when($result = LUT\Search::approximated($y, $x, $k))->then->array($result)->isEqualTo([0 => ['i' => 1, 'j' => 6, 'l' => 5], 1 => ['i' => 2, 'j' => 7, 'l' => 5], 2 => ['i' => 3, 'j' => 8, 'l' => 5], 3 => ['i' => 7, 'j' => 12, 'l' => 5]]);
 }