Commando\Option::setValue PHP Method

setValue() public method

public setValue ( mixed $value )
$value mixed for this option (set on the command line)
    public function setValue($value)
    {
        if ($this->isBoolean() && !is_bool($value)) {
            throw new \Exception(sprintf('Boolean option expected for option %s, received %s value instead', $this->name, $value));
        }
        if (!$this->validate($value)) {
            throw new \Exception(sprintf('Invalid value, %s, for option %s', $value, $this->name));
        }
        if ($this->isIncrement()) {
            if (!is_int($value)) {
                throw new \Exception(sprintf('Integer expected as value for %s, received %s instead', $this->name, $value));
            }
            if ($value > $this->max_value && $this->max_value > 0) {
                $value = $this->max_value;
            }
        }
        if ($this->isFile()) {
            $file_path = $this->parseFilePath($value);
            if (empty($file_path)) {
                if ($this->file_require_exists) {
                    throw new \Exception(sprintf('Expected %s to be a valid file', $value, $this->name));
                }
            } else {
                $value = $file_path;
            }
        }
        $this->value = $this->map($value);
    }

Usage Example

Exemplo n.º 1
0
 public function testFileGlob()
 {
     $file = dirname(__FILE__) . '/assets/*.txt';
     $option = new Option(0);
     $option->setFileRequirements(true, true);
     $option->setValue($file);
     $file1 = dirname(__FILE__) . '/assets/example.txt';
     $file2 = dirname(__FILE__) . '/assets/another.txt';
     $values = $option->getValue();
     $this->assertTrue($option->isFile());
     $this->assertCount(2, $values);
     $this->assertTrue(in_array($file1, $values));
     $this->assertTrue(in_array($file2, $values));
 }
All Usage Examples Of Commando\Option::setValue