Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
- Better documentation for TOutputWriter.
- TStdOutWriter removes flush and sets the _stdout var.
- TWebServerAction corrects Port var, setAll "null" check, and minor tweak to the CLI help text.
  • Loading branch information
belisoful committed Aug 20, 2023
1 parent 196b1aa commit 782e68a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
15 changes: 11 additions & 4 deletions framework/IO/TOutputWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
/**
* TOutputWriter class.
*
* TOutputWriter extends TTextWriter to fwrite the buffer to "Output"
* when {@see flush}ed. This allows for testing of the Shell output.
* TOutputWriter extends TTextWriter to write the buffer to "Output" when {@see flush}ed.
* In a CLI execution, STDOUT is "Output" but this is not true for processing web
* pages. For web pages, "Output" goes to the browser and 'php://stdout' goes to
* the web server's output (either cli or file); while STDOUT is not defined.
*
* Once this class is flushed, PHP's flush need to be called to ensure the "Output"
* is written. If Output Buffering (ob_*) is used, ob_flush (or equivalent) also
* must be called before PHP's flush and after this class flushes.
*
* @author Brad Anderson <belisoful@icloud.com>
* @since 4.2.0
Expand All @@ -27,8 +33,9 @@ class TOutputWriter extends TTextWriter
public const OUTPUT_TYPE = 'Output';

/**
* Flushes the content that has been written.
* @return string the content being flushed
* Flushes the content that has been written. This does not call PHP's ob_flush
* or flush and those must be called to ensure the output is actually sent.
* @return string the content being flushed.
*/
public function flush()
{
Expand Down
5 changes: 2 additions & 3 deletions framework/IO/TStdOutWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TStdOutWriter extends TTextWriter
public const STDOUT_URI = 'php://stdout';

/** @var mixed the Standard Out stream handle */
private mixed $_stdout;
private mixed $_stdout = null;

/**
* Closes the StdOut handle when STDOUT is not defined
Expand All @@ -42,7 +42,7 @@ public function __destruct()

/**
* Flushes the content that has been written.
* @return string the content being flushed
* @return string the content being flushed.
*/
public function flush()
{
Expand All @@ -57,7 +57,6 @@ public function flush()
}

fwrite($this->_stdout, $str);
flush();

return $str;
}
Expand Down
10 changes: 5 additions & 5 deletions framework/Shell/Actions/TWebServerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TWebServerAction extends TShellAction
protected $parameters = [[]];
protected $optional = [['router-filepath']];
protected $description = [
'Provides a PHP Web Server to serve the application.',
'Provides a Test PHP Web Server to serve the application.',
'Runs a PHP Web Server after Initializing the Application.'];

/** @var bool Listen on all network addresses assigned to the computer, when one is not provided. */
Expand Down Expand Up @@ -107,7 +107,7 @@ public function getAll(): bool
*/
public function setAll($value): static
{
if (!$value) {
if ($value === null || $value === '') {
$this->_all = true;
} else {
$this->_all = TPropertyValue::ensureBoolean($value);
Expand Down Expand Up @@ -184,12 +184,12 @@ public function getPort(): int
}

/**
* @param null|int|string $address The port to serve pages, default 8080.
* @param null|int|string $port The port to serve pages, default 8080.
* @return static The current object.
*/
public function setPort($address): static
public function setPort($port): static
{
$this->_port = TPropertyValue::ensureInteger($address);
$this->_port = TPropertyValue::ensureInteger($port);

return $this;
}
Expand Down

0 comments on commit 782e68a

Please sign in to comment.