Making properties protected.

This commit is contained in:
mark_story 2010-10-10 14:55:15 -04:00
parent 49006b2bbb
commit 8b46645f6a
3 changed files with 47 additions and 39 deletions

View file

@ -26,6 +26,8 @@
*/
class ConsoleInputArgument {
protected $_name, $_help, $_required, $_choices;
/**
* Make a new Input Argument
*
@ -38,13 +40,13 @@ class ConsoleInputArgument {
public function __construct($name, $help = '', $required = false, $choices = array()) {
if (is_array($name) && isset($name['name'])) {
foreach ($name as $key => $value) {
$this->{$key} = $value;
$this->{'_' . $key} = $value;
}
} else {
$this->name = $name;
$this->help = $help;
$this->required = $required;
$this->choices = $choices;
$this->_name = $name;
$this->_help = $help;
$this->_required = $required;
$this->_choices = $choices;
}
}
@ -54,7 +56,7 @@ class ConsoleInputArgument {
* @return string
*/
public function name() {
return $this->name;
return $this->_name;
}
/**
@ -64,7 +66,7 @@ class ConsoleInputArgument {
* @return string
*/
public function help($width = 0) {
$name = $this->name;
$name = $this->_name;
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
@ -72,7 +74,7 @@ class ConsoleInputArgument {
if (!$this->isRequired()) {
$optional = ' <comment>(optional)</comment>';
}
return sprintf('%s%s%s', $name, $this->help, $optional);
return sprintf('%s%s%s', $name, $this->_help, $optional);
}
/**
@ -81,7 +83,7 @@ class ConsoleInputArgument {
* @return string
*/
public function usage() {
$name = $this->name;
$name = $this->_name;
if (!$this->isRequired()) {
$name = '[' . $name . ']';
}
@ -94,6 +96,6 @@ class ConsoleInputArgument {
* @return boolean
*/
public function isRequired() {
return (bool) $this->required;
return (bool) $this->_required;
}
}

View file

@ -27,6 +27,8 @@
*/
class ConsoleInputOption {
protected $_name, $_short, $_help, $_boolean, $_default, $_choices;
/**
* Make a new Input Option
*
@ -41,15 +43,15 @@ class ConsoleInputOption {
public function __construct($name, $short = null, $help = '', $boolean = false, $default = '', $choices = array()) {
if (is_array($name) && isset($name['name'])) {
foreach ($name as $key => $value) {
$this->{$key} = $value;
$this->{'_' . $key} = $value;
}
} else {
$this->name = $name;
$this->short = $short;
$this->help = $help;
$this->boolean = $boolean;
$this->default = $default;
$this->choices = $choices;
$this->_name = $name;
$this->_short = $short;
$this->_help = $help;
$this->_boolean = $boolean;
$this->_default = $default;
$this->_choices = $choices;
}
}
@ -59,7 +61,7 @@ class ConsoleInputOption {
* @return string
*/
public function name() {
return $this->name;
return $this->_name;
}
/**
@ -70,17 +72,17 @@ class ConsoleInputOption {
*/
public function help($width = 0) {
$default = $short = '';
if (!empty($this->default) && $this->default !== true) {
$default = sprintf(__(' <comment>(default: %s)</comment>'), $this->default);
if (!empty($this->_default) && $this->_default !== true) {
$default = sprintf(__(' <comment>(default: %s)</comment>'), $this->_default);
}
if (!empty($this->short)) {
$short = ', -' . $this->short;
if (!empty($this->_short)) {
$short = ', -' . $this->_short;
}
$name = sprintf('--%s%s', $this->name, $short);
$name = sprintf('--%s%s', $this->_name, $short);
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
return sprintf('%s%s%s', $name, $this->help, $default);
return sprintf('%s%s%s', $name, $this->_help, $default);
}
/**
@ -89,10 +91,10 @@ class ConsoleInputOption {
* @return string
*/
public function usage() {
$name = empty($this->short) ? '--' . $this->name : '-' . $this->short;
$name = empty($this->_short) ? '--' . $this->_name : '-' . $this->_short;
$default = '';
if (!empty($this->default) && $this->default !== true) {
$default = ' ' . $this->default;
if (!empty($this->_default) && $this->_default !== true) {
$default = ' ' . $this->_default;
}
return sprintf('[%s%s]', $name, $default);
}
@ -103,7 +105,7 @@ class ConsoleInputOption {
* @return void
*/
public function defaultValue() {
return $this->default;
return $this->_default;
}
/**
@ -112,6 +114,6 @@ class ConsoleInputOption {
* @return boolean
*/
public function isBoolean() {
return (bool) $this->boolean;
return (bool) $this->_boolean;
}
}

View file

@ -27,6 +27,10 @@
*/
class ConsoleInputSubcommand {
protected $_name;
protected $_help;
protected $_parser;
/**
* Make a new Subcommand
*
@ -38,12 +42,12 @@ class ConsoleInputSubcommand {
public function __construct($name, $help = '', $parser = null) {
if (is_array($name) && isset($name['name'])) {
foreach ($name as $key => $value) {
$this->{$key} = $value;
$this->{'_' . $key} = $value;
}
} else {
$this->name = $name;
$this->help = $help;
$this->parser = $parser;
$this->_name = $name;
$this->_help = $help;
$this->_parser = $parser;
}
}
@ -53,7 +57,7 @@ class ConsoleInputSubcommand {
* @return string
*/
public function name() {
return $this->name;
return $this->_name;
}
/**
@ -63,21 +67,21 @@ class ConsoleInputSubcommand {
* @return string
*/
public function help($width = 0) {
$name = $this->name;
$name = $this->_name;
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
return $name . $this->help;
return $name . $this->_help;
}
/**
* Get the usage value for this option
*
* @return string
* @return mixed Either false or a ConsoleOptionParser
*/
public function parser() {
if ($this->parser instanceof ConsoleOptionParser) {
return $this->parser;
if ($this->_parser instanceof ConsoleOptionParser) {
return $this->_parser;
}
return false;
}