You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
phpcommandline/src/CommandLine/Argument/AbstractArgument.php

114 lines
2.6 KiB
PHP

<?php
namespace jrosset\CommandLine\Argument;
/**
* Abstract base for arguments
*/
abstract class AbstractArgument implements IArgument {
/**
* @var string The variable name in parse output
*/
private string $varName;
/**
* @var mixed|null The default value for the argument. Null if none
*/
private $_default;
/**
* @var string The argument name in help
*/
private string $name;
/**
* @var string|null The argument description in help
*/
private ?string $description;
/**
* Create a new argument
*
* By default, the {@see AbstractArgument::$varName variable name} is the same as the {@see AbstractArgument::$name argument in help}
*
* @param string $name The argument name in help
* @param string|null $description The argument description in help
*/
protected function __construct (string $name, ?string $description) {
$this->setVarName($this->getName());
$this->setDefault();
$this->setName($name);
$this->setDescription($description);
}
/**
* @inheritDoc
*/
public function getVarName (): string {
return $this->varName;
}
/**
* Set the variable name in parse output
*
* @param string $varName The variable name
*
* @return $this
*/
public function setVarName (string $varName): self {
$this->varName = $varName;
return $this;
}
/**
* @inheritDoc
*/
public function getDefault () {
return $this->_default;
}
/**
* Set the default value for the argument. Null if none
*
* @param mixed $default The default value
*
* @return $this
*/
public function setDefault ($default = null): self {
$this->_default = $default;
return $this;
}
/**
* @inheritDoc
*/
public function getName (): string {
return $this->name;
}
/**
* Set the argument name in help
*
* @param string $name The argument name in help
*
* @return $this
*/
public function setName (string $name): self {
$this->name = $name;
return $this;
}
/**
* @inheritDoc
*/
public function getDescription (): ?string {
return $this->description;
}
/**
* Set the argument description in help
*
* @param string|null $description The argument description
*
* @return $this
*/
public function setDescription (?string $description): self {
$this->description = $description;
return $this;
}
}