Commando\Option::hasNeeds PHP Method

hasNeeds() public method

Check to see if requirements list for option are met
public hasNeeds ( array $optionsList ) : boolean | array
$optionsList array Set of current options defined
return boolean | array True if requirements met, array if not found
    public function hasNeeds($optionsList)
    {
        $needs = $this->getNeeds();
        $definedOptions = array_keys($optionsList);
        $notFound = array();
        foreach ($needs as $need) {
            if (!in_array($need, $definedOptions)) {
                // The needed option has not been defined as a valid flag.
                $notFound[] = $need;
            } elseif (!$optionsList[$need]->getValue()) {
                // The needed option has been defined as a valid flag, but was
                // not pased in by the user.
                $notFound[] = $need;
            }
        }
        return empty($notFound) ? true : $notFound;
    }

Usage Example

 /**
  * Test that the needed requirements are met
  */
 public function testOptionRequirementsMet()
 {
     $option = new Option('f');
     $option->setNeeds('foo');
     $optionSet = array('foo' => new Option('foo'));
     $this->assertTrue($option->hasNeeds($optionSet));
 }
All Usage Examples Of Commando\Option::hasNeeds