Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#973 PHP Web Server Action for built-in app development #988

Merged
merged 9 commits into from
Aug 20, 2023
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENH: Issue #977 - THttpRequest::onResolveRequest for custom service resolution a
ENH: Issue #982 - General Logging update: Profiling, Flushing large logs for long running processes, optional Tracing, tracks PID for multi-threaded logging, TBrowserLogRoute colorizes the time delta, TDbLogRoute adds a new DB field 'prefix' and functions for getting the DB log, DB log count, and deleting DB logs, TDBLogRoute also adds a RetainPeriod for automatically removing old logs, Adds an event TLogger::OnFlushLogs and flushes as a register_shutdown_function, adds the TSysLogRoute, and adds unit tests for logging. (belisoful)
ENH: Issue #984 - TEventSubscription for temporary event handlers. (belisoful)
ENH: Issue #972 - TProcessHelper (isSystemWindows, forking, kill, priority) and TSignalsDispatcher for delegating signals to respective global events, alarm interrupt callbacks at specific times, and per child PIDs callbacks. TEventSubscription can subscribe to a PHP process signal, an integer, as an event "name" (in TSignalsDispatcher). (belisoful)
ENH: Issue #973 - Embedded PHP Development Web Server CLI Action. (belisoful)

## Version 4.2.2 - April 6, 2023

Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ composer create-project pradosoft/prado-app app

The application will be installed in the "app" directory.

## Built-in PHP Test Web Server

The built-in PHP Test Web Server can be used to immediately start developing and testing a web application.
The web server is started with command (assuming the above application in the directory "app")

```sh
cd app/protected
./vendor/bin/prado-cli http
```

The application is then accessible on the machine's browser at `http://127.0.0.1:8080/`. The built-in web server is enabled when the application is in "Debug" mode or is enabled in the application configuration parameters.

#### Add PRADO to an existing application
Just create a composer.json file for your project:

Expand All @@ -51,7 +63,7 @@ Just create a composer.json file for your project:
```

The [asset-packagist](https://asset-packagist.org) repository is used to install javascript dependencies.
Assuming you already installed composer, run
Assuming you already installed composer, run the command

```sh
composer install
Expand Down
11 changes: 8 additions & 3 deletions framework/IO/TOutputWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@
/**
* TOutputWriter class.
*
* TOutputWriter extends TTextWriter to fwrite the buffer to STDOUT
* TOutputWriter extends TTextWriter to fwrite the buffer to "Output"
* when {@see flush}ed. This allows for testing of the Shell output.
*
* @author Brad Anderson <belisoful@icloud.com>
* @since 4.2.0
*/
class TOutputWriter extends TTextWriter
{
/** @const The file path to open a data stream to Output. */
public const OUTPUT_URI = 'php://output';

/** @const The type of stream for Output. */
public const OUTPUT_TYPE = 'Output';

/**
* Flushes the content that has been written.
* @return string the content being flushed
*/
public function flush()
{
$str = parent::flush();
fwrite(STDOUT, $str);
flush();
echo $str;
ctrlaltca marked this conversation as resolved.
Show resolved Hide resolved
return $str;
}
}
64 changes: 64 additions & 0 deletions framework/IO/TStdOutWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* TStdOutWriter class file
*
* @author Brad Anderson <belisoful@icloud.com>
* @link https://github.com/pradosoft/prado
* @license https://github.com/pradosoft/prado/blob/master/LICENSE
*/

namespace Prado\IO;

/**
* TStdOutWriter class.
*
* TStdOutWriter extends TTextWriter to fwrite the buffer to STDOUT when {@see flush}ed.
* This allows for testing of the Shell output.
*
* STDOUT is only defined in the CLI. When processing a PHP web page, this opens
* a new handle to 'php://stdout'.
*
* @author Brad Anderson <belisoful@icloud.com>
* @since 4.2.3
*/
class TStdOutWriter extends TTextWriter
{
/** The file path to open a data stream in memory */
public const STDOUT_URI = 'php://stdout';

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

/**
* Closes the StdOut handle when STDOUT is not defined
*/
public function __destruct()
{
if (!defined('STDOUT') && $this->_stdout) {
fclose($this->_stdout);
}
parent::__destruct();
}

/**
* Flushes the content that has been written.
* @return string the content being flushed
*/
public function flush()
{
$str = parent::flush();

if (!$this->_stdout) {
if (!defined('STDOUT')) {
$this->_stdout = fopen(TStdOutWriter::STDOUT_URI, 'wb');
} else {
$this->_stdout = STDOUT;
}
}

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

return $str;
}
}
6 changes: 3 additions & 3 deletions framework/Shell/Actions/TDbParameterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function setAll($value)

/**
* Properties for the action set by parameter
* @param string $actionID the action being executed
* @param string $methodID the action being executed
* @return array properties for the $actionID
*/
public function options($actionID): array
public function options($methodID): array
{
if ($actionID === 'index') {
if ($methodID === 'index') {
return ['all'];
}
return [];
Expand Down
Loading