### Configure pre-deploy and post-deploy hooks in phploy.ini Source: https://github.com/banago/phploy/blob/master/readme.md Execute commands before and after deployment using pre-deploy[] and post-deploy[] keys in phploy.ini. Example uses wget to call a script on the server. ```ini ; To execute before deployment pre-deploy[] = "wget http://staging-example.com/pre-deploy/test.php --spider --quiet" ; To execute after deployment post-deploy[] = "wget http://staging-example.com/post-deploy/test.php --spider --quiet" ``` -------------------------------- ### List changed files with phploy -l Source: https://github.com/banago/phploy/blob/master/readme.md Shows which files will be uploaded or deleted before deploying. Use the short flag -l. ```bash phploy -l ``` -------------------------------- ### Minimal phploy.ini example Source: https://github.com/banago/phploy/blob/master/readme.md A minimal configuration file for PHPloy, specifying the production server with FTP credentials and path. The file should be in the project root and is never uploaded. ```ini [production] quickmode = ftp://user:pass@example.com:21/path/to/installation ``` -------------------------------- ### Manual fresh upload with phploy --fresh Source: https://github.com/banago/phploy/blob/master/readme.md Forces a fresh upload even if a previous deployment exists. ```bash phploy --fresh ``` -------------------------------- ### Install PHPloy globally via Phar archive Source: https://github.com/banago/phploy/blob/master/readme.md Move the downloaded phploy.phar to /usr/local/bin and make it executable for global use. ```bash sudo mv phploy.phar /usr/local/bin/phploy sudo chmod +x /usr/local/bin/phploy ``` -------------------------------- ### Create deployment directory with phploy --force Source: https://github.com/banago/phploy/blob/master/readme.md Instructs PHPloy to create the deployment directory if it does not exist. ```bash phploy --force ``` -------------------------------- ### Install PHPloy globally via Composer Source: https://github.com/banago/phploy/blob/master/readme.md Use this command to install PHPloy globally with Composer. Ensure the Composer bin directory is in your PATH. ```bash composer global require "banago/phploy" ``` -------------------------------- ### Export environment variables for phploy Source: https://github.com/banago/phploy/blob/master/readme.md Example of exporting environment variables so the script automatically uses them, then running phploy with a server name. ```bash $ export PHPLOY_PORT="21" $ export PHPLOY_HOST="myftphost.com" $ export PHPLOY_USER="ftp" $ export PHPLOY_PASS="ftp-password" $ export PHPLOY_PATH="/home/user/public_html/example.com" $ export PHPLOY_PRIVKEY="path/to/or/contents/of/privatekey" $ phploy -s servername ``` -------------------------------- ### Usage examples for dir_tree, human_filesize, pattern_match Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/utils.md Shows practical usage of three helpers: expanding an include directory, formatting a deployed size, and matching an exclude pattern. ```php // Expanding an include directory to its files (FileFilter internals) $files = dir_tree('/path/to/repo/vendor', true, false, true); // => ['/path/to/repo/vendor/lib.php', ...] (recursive, files only, skips .git etc.) // Formatting a deployed size echo human_filesize(1572864, 2); // "1.50M" // Matching an exclude pattern if (pattern_match('src/*.scss', 'src/style.scss')) { // 1 => excluded } ``` -------------------------------- ### Deploy to a single server with --server Source: https://github.com/banago/phploy/blob/master/readme.md Alternative to -s for deploying to a specific server. The 'servername' must match a server entry in the phploy.ini file. ```bash phploy --server servername ``` -------------------------------- ### Deploy to all servers with --all Source: https://github.com/banago/phploy/blob/master/readme.md Deploys to all configured servers, overriding the default server if one is set. Use when you want to push to every server in the configuration. ```bash phploy --all ``` -------------------------------- ### Interactive rollback with --rollback Source: https://github.com/banago/phploy/blob/master/readme.md Starts an interactive rollback that lets you pick a commit from an arrow-key list of recent commits. Note: the --rollback option does not currently update submodules correctly. ```bash phploy --rollback ``` -------------------------------- ### List changed files with phploy --list Source: https://github.com/banago/phploy/blob/master/readme.md Long-form alternative to -l for listing files to be uploaded or deleted. ```bash phploy --list ``` -------------------------------- ### Run the full test suite Source: https://github.com/banago/phploy/blob/master/contributing.md Starts Docker containers, runs tests, and stops Docker. Requires Docker Engine and Docker Compose. ```bash # Run full test suite (starts Docker, runs tests, stops Docker) composer test ``` -------------------------------- ### Set environment variables inline for phploy Source: https://github.com/banago/phploy/blob/master/readme.md Example of setting environment variables inline before running phploy with a server name. ```bash $ PHPLOY_PORT="21" PHPLOY_HOST="myftphost.com" PHPLOY_USER="ftp" PHPLOY_PASS="ftp-password" PHPLOY_PATH="/home/user/public_html/example.com" phploy -s servername ``` -------------------------------- ### Example Pest test structure Source: https://github.com/banago/phploy/blob/master/contributing.md Example test structure for writing tests with Pest PHP. Demonstrates setup, execution, and assertion steps. ```php test('creates revision file on first deployment', function () { // 1. Setup test repository and config $testDir = '/tmp/phploy-test-' . uniqid(); mkdir($testDir); chdir($testDir); // 2. Run PHPloy $output = shell_exec('php /app/bin/phploy --fresh 2>&1'); // 3. Assert results expect($ftpConnection->has('.revision'))->toBeTrue(); // Cleanup shell_exec('rm -rf ' . $testDir); }); ``` -------------------------------- ### Run test services separately for development Source: https://github.com/banago/phploy/blob/master/contributing.md Start Docker containers, run tests, and stop Docker containers individually for development. ```bash composer test:up # Start Docker containers composer test:exec # Run tests composer test:down # Stop Docker containers ``` -------------------------------- ### Instantiate PHPloy to run CLI end-to-end Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md Creates a new PHPloy instance, which parses arguments, loads configuration, validates the repository, and starts deployment. No arguments are required. ```php use Banago\PHPloy\PHPloy; $phploy = new PHPloy(); // runs the CLI end-to-end ``` -------------------------------- ### Run PHPloy locally via Phar archive Source: https://github.com/banago/phploy/blob/master/readme.md Use this command to run PHPloy from your project directory using the phar archive. ```bash php phploy.phar ``` -------------------------------- ### Shared configuration with '*' section Source: https://github.com/banago/phploy/blob/master/readme.md Defines a special '*' section in phploy.ini whose options are shared with all other server configurations. The example shows exclude[] and include[] defaults applied to shard1 and shard2. ```ini ; The special '*' configuration is shared between all other configurations (think include) [*] exclude[] = 'src/*' include[] = "dist/app.css" ; As a result both shard1 and shard2 will have the same exclude[] and include[] "default" values [shard1] quickmode = ftp://example:password@shard1-example.com:21/path/to/installation [shard2] quickmode = ftp://example:password@shard2-example.com:21/path/to/installation ``` -------------------------------- ### Enable logging in phploy.ini Source: https://github.com/banago/phploy/blob/master/readme.md Turn on activity logging by setting logger = on in the [production] section of phploy.ini. Logs are saved to phploy.log in the project. ```ini [production] logger = on ``` -------------------------------- ### Configure purge-before directories in phploy.ini Source: https://github.com/banago/phploy/blob/master/readme.md Specify directories to purge before deployment using the purge-before[] key in phploy.ini. Paths are relative to the deployment path. ```ini ; relative to the deployment path purge-before[] = "dist/" ``` -------------------------------- ### Environment variables for PHPloy Source: https://github.com/banago/phploy/blob/master/readme.md List of environment variables that PHPloy uses if not present in phploy.ini, allowing deployment without storing credentials in a file. ```bash PHPLOY_HOST PHPLOY_PORT PHPLOY_PASS PHPLOY_PATH PHPLOY_USER PHPLOY_PRIVKEY ``` -------------------------------- ### Deploy with submodule scanning using --submodules Source: https://github.com/banago/phploy/blob/master/readme.md Add the --submodules parameter to the phploy command to enable submodule scanning during deployment. Submodule support is deprecated and off by default; Composer is recommended instead. ```bash phploy --submodules ``` -------------------------------- ### Install dependencies with Composer Source: https://github.com/banago/phploy/blob/master/contributing.md Install project dependencies. Requires PHP 8.0 or higher. ```bash composer install ``` -------------------------------- ### Configure purge directories in phploy.ini Source: https://github.com/banago/phploy/blob/master/readme.md Specify directories to purge after deployment using the purge[] key in phploy.ini. Paths are relative to the deployment path. ```ini ; relative to the deployment path purge[] = "cache/" ``` -------------------------------- ### Deploy to a single server with -s Source: https://github.com/banago/phploy/blob/master/readme.md Deploys to the server named 'servername' in the phploy.ini configuration file. Use when you want to target one specific server instead of all configured servers. ```bash phploy -s servername ``` -------------------------------- ### new PHPloy() Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md Instantiates the PHPloy class, which runs the entire CLI deployment process. It parses arguments, loads configuration, validates the repository, and starts deployment. ```APIDOC ## Constructor: `new PHPloy()` ### Description Creates a new PHPloy instance and executes the full CLI deployment workflow. ### Method Constructor ### Endpoint `new Banago\PHPloy\PHPloy()` ### Parameters None ### Request Example ```php use Banago\PHPloy\PHPloy; $phploy = new PHPloy(); // runs the CLI end-to-end ``` ### Response #### Success Response No return value; the constructor has side effects and executes the deployment. #### Error Response Throws `\Exception` when the current working directory is not a Git repository. #### Response Example ```php try { new Banago\PHPloy\PHPloy(); } catch (Exception $e) { // e.g. "'/some/path' is not a Git repository." fwrite(STDERR, "Deploy failed: " . $e->getMessage() . PHP_EOL); exit(1); } ``` ``` -------------------------------- ### Sync remote revision with phploy --sync Source: https://github.com/banago/phploy/blob/master/readme.md Updates the .revision file on the server to match the current local revision. ```bash phploy --sync ``` -------------------------------- ### Store credentials in .phploy file Source: https://github.com/banago/phploy/blob/master/readme.md Alternative configuration to store user and password in a separate .phploy file, useful for sharing phploy.ini via Git while hiding passwords. ```ini [staging] user="theUser" pass="thePassword" [production] user="theUser" pass="thePassword" ``` -------------------------------- ### Sync to a specific revision with phploy --sync Source: https://github.com/banago/phploy/blob/master/readme.md Sets the remote .revision file to a previous commit revision by specifying the revision hash. ```bash phploy --sync your-revision-hash-here ``` -------------------------------- ### Rollback to a specific commit Source: https://github.com/banago/phploy/blob/master/readme.md Rolls back to the commit with the given hash. The working copy files temporarily revert to that version during deployment, then restore afterward. There is no short version of --rollback. ```bash phploy --rollback commit-hash-goes-here ``` -------------------------------- ### Check deployment status with phploy --status Source: https://github.com/banago/phploy/blob/master/readme.md Reports remote revision, commits behind, and files to upload/delete without deploying. If never deployed, revision shows as '(none - not yet deployed)'. ```bash phploy --status ``` -------------------------------- ### Remote path mapping with FileFilter::removeBasePath Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/FileFilter.md Shows how to remove the base path from a remote file path. The example outputs 'index.php' for input 'src/index.php' when base is 'src/'. ```php use Banago\PHPloy\FileFilter; $filter = new FileFilter($cli, ['base' => 'src/'], '/repo'); echo $filter->removeBasePath('src/index.php'); // "index.php" ``` -------------------------------- ### getArgument method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Gets an argument value. Returns the argument's value (string for value arguments, or the configured default when the flag was not provided). Backed by CLImate::arguments->get($name). ```php /** * Get an argument value. * * @return mixed */ public function getArgument(string $name) ``` -------------------------------- ### Instantiate and run Deployment with Cli, Git, Config Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md Shows how to construct the Deployment object with Cli, Git, and Config instances, then call run() to execute the deployment workflow. The constructor reads CLI arguments such as --fresh, --force, --list, --remote-list, --status, --submodules, --sync, and --from into state, and sets the repository to the current working directory. ```php use Banago\PHPloy\Cli; use Banago\PHPloy\Config; use Banago\PHPloy\Deployment; use Banago\PHPloy\Git; $deployment = new Deployment($cli, $git, $config); $deployment->run(); ``` -------------------------------- ### Error handling when CWD is not a Git repository Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md Construction throws when the current working directory is not a Git repository. This example catches the exception and writes a failure message to STDERR, then exits with code 1. ```php // Run from a directory without .git: try { new Banago\PHPloy\PHPloy(); } catch (Exception $e) { // e.g. "'/some/path' is not a Git repository." fwrite(STDERR, "Deploy failed: " . $e->getMessage() . PHP_EOL); exit(1); } ``` -------------------------------- ### run() Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md Executes the deployment workflow for every target server, including connecting, computing diffs, filtering files, pushing/deleting, writing remote revisions, and running hooks/purge/copy steps. ```APIDOC ## run() ### Description Runs the deployment workflow for every target server. ### Method run ### Signature ```php public function run() ``` ### Parameters None ### Return void ``` -------------------------------- ### Interactive selection and deployment logging with pickFromList and logDeployment Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Demonstrates interactive server selection using pickFromList, which returns the selected key (e.g., 'prod' or 'stage') or null when cancelled. Also shows logDeployment, which writes deployment details to phploy.log; the boolean parameter likely indicates success or failure. ```php use Banago\PHPloy\Cli; $cli = new Cli(); $chosen = $cli->pickFromList('Pick a server:', [ 'prod' => 'Production', 'stage' => 'Staging', ]); // $chosen === 'prod' or 'stage' when selected, null when cancelled $cli->logDeployment('abc123', 'prod', 'main', 12, 0, true); // also writes phploy.log ``` -------------------------------- ### Instantiate and use FileFilter Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/FileFilter.md Creates a FileFilter instance with the CLI wrapper, server config, and repository path, then applies filters to a file list from Deployment::compare(). ```php use Banago\PHPloy\Cli; use Banago\PHPloy\FileFilter; $filter = new FileFilter($cli, $serverConfig, '/path/to/repo'); $filtered = $filter->filter($files); ``` -------------------------------- ### Deployment constructor signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md The constructor accepts Cli, Git, and Config instances. It reads CLI arguments into state properties and sets the repository to the current working directory. Throws \Exception from resolveFromIndex() for a non-positive --from value and from resolveRevision() when the interactive rollback has no commits or no selection. ```php /** * Constructor. */ public function __construct(Cli $cli, Git $git, Config $config) ``` -------------------------------- ### Read configuration programmatically with Config::getServers and getServer Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Shows how to instantiate Config with a Cli instance and retrieve server sections. getServers() returns all sections, while getServer('production') returns an array or null. The returned array includes keys like 'scheme', 'host', and 'path'. ```php use Banago\PHPloy\Cli; use Banago\PHPloy\Config; $cli = new Cli(); $config = new Config($cli); $servers = $config->getServers(); // all sections $prod = $config->getServer('production'); // ?array // e.g. ['scheme' => 'ftp', 'host' => 'example.com', 'path' => '/', ...] ``` -------------------------------- ### Create a new Connection instance Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Instantiate a Connection object with a server configuration array. Requires a 'scheme' key; throws an exception if missing or unknown. ```php use Banago\PHPloy\Connection; $conn = new Connection([ 'scheme' => 'ftp', 'host' => 'example.com', 'user' => 'ftp', 'pass' => 'secret', 'path' => '/public_html', ]); ``` -------------------------------- ### Create sample config file with Config::createSampleConfig Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Creates a sample phploy.ini file in the current directory from the repository template. Requires a Cli instance and writes the file to ./phploy.ini. ```php use Banago\PHPloy\Cli; use Banago\PHPloy\Config; $cli = new Cli(); Config::createSampleConfig($cli); // writes ./phploy.ini from the repo template ``` -------------------------------- ### Instantiate Cli Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Creates a new Cli instance, which immediately registers and parses CLI arguments from $_SERVER['argv']. ```php use Banago\PHPloy\Cli; $cli = new Cli(); // registers and parses CLI arguments immediately ``` -------------------------------- ### new Connection($server) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Creates a new Connection instance wrapping a Flysystem filesystem. The constructor accepts a server configuration array and throws an exception if the scheme is missing or unsupported. ```APIDOC ## Constructor ### Description Creates a new Connection instance wrapping a Flysystem filesystem. ### Method Constructor ### Signature `public function __construct($server)` ### Parameters - **$server** (array) - Required - Server configuration array. Must include a `scheme` key. ### Return Returns the constructed Connection instance. ### Throws - `\Exception` - If `scheme` is missing: "Please provide a connection protocol such as 'ftp' or 'sftp'." - `\Exception` - If `scheme` is unknown: "Please provide a known connection protocol such as 'ftp' or 'sftp'." - `\Exception` - If connection fails: underlying adapter exception (message echoed with `Oh Snap:` prefix before rethrowing). ### Example ```php use Banago\PHPloy\Connection; $conn = new Connection([ 'scheme' => 'ftp', 'host' => 'example.com', 'user' => 'ftp', 'pass' => 'secret', 'path' => '/public_html', ]); ``` ``` -------------------------------- ### Basic FTP connect and read/write operations Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Shows the pattern used by integration tests: create a Connection with FTP scheme, check for a .revision file, read it, put a file, delete a file, and list contents recursively. The listContents call returns an array of path/type items. ```php use Banago\PHPloy\Connection; $ftp = new Connection([ 'scheme' => 'ftp', 'host' => 'ftp-server', 'user' => 'testuser', 'pass' => 'testpass', 'path' => '/some/remote/path', 'timeout' => 30, ]); if ($ftp->has('.revision')) { $revision = $ftp->read('.revision'); } $ftp->put('hello.txt', "world\n"); $ok = $ftp->delete('old.txt'); $list = $ftp->listContents('', true); // [['path' => ..., 'type' => 'file'], ...] ``` -------------------------------- ### Git constructor signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Constructor accepts an optional repository path; when null, the shell's current directory is used. Throws `\Exception` with message `"Failed to initialize Git: {message}"` if either `rev-parse` command fails. ```php /** * Git constructor. * * @param string|null $repo * @throws \Exception */ public function __construct($repo = null) ``` -------------------------------- ### getServer Method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Returns the normalized configuration array for a specific server by name, or null if the server does not exist. ```php /** * Get specific server configuration */ public function getServer(string $name): ?array ``` -------------------------------- ### Resume interrupted deploy with phploy --from 599 Source: https://github.com/banago/phploy/blob/master/readme.md Skips re-uploading files that already landed after an interrupted deploy. Pass the 1-based index from the error message to --from; it re-uploads that file (in case of partial transfer) and continues. ```bash phploy --from 599 ``` -------------------------------- ### deploy method signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md Shows the LIST-mode message when --list is present, then runs $this->deployment->run(). ```php protected function deploy(): void ``` -------------------------------- ### new Git($repo = null) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Constructs a Git wrapper instance. Resolves the current branch and revision at construction time. ```APIDOC ## Constructor: `new Git($repo = null)` ### Description Creates a new Git wrapper instance. Resolves the current branch and revision at construction time. ### Parameters - **$repo** (string|null) - Optional - Repository path. When null, the shell's current directory is used. ### Return void. Sets `$this->branch` and `$this->revision`. ### Throws - `\Exception` - `"Failed to initialize Git: {message}"` when either `rev-parse` command fails. ``` -------------------------------- ### Error handling for non-repository paths Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Shows how to catch exceptions when constructing a Git object with an invalid path or when calling command() with a missing path. The constructor throws 'Failed to initialize Git: ...' and command() throws 'Repository path does not exist: /missing/path'. ```php use Banago\PHPloy\Git; try { $git = new Git('/not/a/repo'); } catch (Exception $e) { // "Failed to initialize Git: ..." from the constructor } // command() validates the path up-front: try { $git->command('status', '/missing/path'); } catch (Exception $e) { // "Repository path does not exist: /missing/path" } ``` -------------------------------- ### Instantiate Git wrapper with repository path Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Creates a new Git instance for the given repository path. The constructor resolves the current branch and revision using `git rev-parse`. ```php use Banago\PHPloy\Git; $git = new Git('/path/to/repo'); ``` -------------------------------- ### pickFromList method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Presents an arrow-key selectable list and returns the chosen option's key. Returns the selected value or null if none was chosen. Backed by CLImate::radio($prompt, $options)->prompt(). ```php /** * Present an arrow-key selectable list and return the chosen option's key. * * @param array $options Map of value => label. * @return string|null The selected value, or null if none was chosen. */ public function pickFromList(string $prompt, array $options): ?string ``` -------------------------------- ### createSampleConfig(Cli $cli): void (static) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Creates a sample phploy.ini file in the current working directory by copying the repository's template. Does nothing if the file already exists, and prints an error if the template cannot be read. ```APIDOC ## createSampleConfig(Cli $cli): void (static) ### Description Creates a sample phploy.ini file in the current working directory by copying the repository's template. Does nothing if the file already exists, and prints an error if the template cannot be read. ### Method Static Method ### Signature `public static function createSampleConfig(Cli $cli): void` ### Parameters - `$cli` (Cli) - Required - CLI wrapper used for informational output. ### Return void. Copies the repo's phploy.ini template (resolved as `dirname(__DIR__) . '/phploy.ini'`) into `getcwd()/phploy.ini`. Does nothing (prints "already exists") when the file already exists; prints an error when the template cannot be read. ``` -------------------------------- ### createSampleConfig Static Method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Copies the repository's phploy.ini template to the current working directory. Does nothing and prints 'already exists' if the file exists; prints an error if the template cannot be read. ```php /** * Create sample config file */ public static function createSampleConfig(Cli $cli): void ``` -------------------------------- ### Cli::pickFromList Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Presents an interactive selection list to the user and returns the selected key. Returns null if the user cancels. ```APIDOC ## Cli::pickFromList ### Description Presents an interactive selection list to the user and returns the selected key. ### Method pickFromList ### Parameters - **prompt** (string) - Required - The prompt to display. - **options** (array) - Required - An associative array of options (key => label). ### Return Value - **string|null** - The selected key, or null if cancelled. ### Example ```php $chosen = $cli->pickFromList('Pick a server:', [ 'prod' => 'Production', 'stage' => 'Staging', ]); ``` ``` -------------------------------- ### Instantiate Config with Cli Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Creates a Config instance using a Cli object. The constructor throws an exception if phploy.ini is missing or invalid. ```php use Banago\PHPloy\Cli; use Banago\PHPloy\Config; $cli = new Cli(); $config = new Config($cli); // throws if phploy.ini is missing/invalid ``` -------------------------------- ### new Cli() Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Instantiates the CLI interaction layer, registering and parsing command-line arguments immediately. ```APIDOC ## Constructor ### Description Creates a new Cli instance, which initializes CLImate and parses arguments from $_SERVER['argv']. ### Method Constructor ### Endpoint `new Cli()` ### Parameters None. ### Request Example ```php use Banago\PHPloy\Cli; $cli = new Cli(); ``` ### Response #### Success Response - **Return** (void) - No return value. ``` -------------------------------- ### Connection constructor Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Creates a new Connection instance for FTP or SFTP. Accepts an array of connection options including scheme, host, user, pass, path, timeout, and privkey. ```APIDOC ## Connection constructor ### Description Creates a new Connection instance for FTP or SFTP. Accepts an array of connection options including scheme, host, user, pass, path, timeout, and privkey. ### Method __construct ### Parameters - **$config** (array) - Required - Connection configuration array. - **scheme** (string) - Required - Connection protocol (e.g., 'ftp', 'sftp'). - **host** (string) - Required - Remote server hostname. - **user** (string) - Required - Username for authentication. - **pass** (string) - Required - Password for authentication. - **path** (string) - Required - Remote path to connect to. - **timeout** (int) - Optional - Connection timeout in seconds. - **privkey** (string) - Optional - Private key path for SFTP (empty for password auth). ### Usage Example ```php $ftp = new Connection([ 'scheme' => 'ftp', 'host' => 'ftp-server', 'user' => 'testuser', 'pass' => 'testpass', 'path' => '/some/remote/path', 'timeout' => 30, ]); ``` ``` -------------------------------- ### pickFromList(string $prompt, array $options): ?string Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Presents an arrow-key selectable list and returns the chosen option's key. ```APIDOC ## pickFromList(string $prompt, array $options): ?string ### Description Presents an interactive radio list to the user and returns the selected option's key. Returns null if no string was selected. ### Method pickFromList ### Endpoint `pickFromList(string $prompt, array $options): ?string` ### Parameters #### Path Parameters - **$prompt** (string) - Required - Prompt shown above the radio list. - **$options** (array) - Required - Map of returned value → display label. ### Request Example ```php $selected = $cli->pickFromList('Choose a server:', ['prod' => 'Production', 'dev' => 'Development']); ``` ### Response #### Success Response - **Return** (?string) - The selected option's key, or `null` if none was chosen. ``` -------------------------------- ### command method signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Runs a git sub-command (without the leading `git`) and returns output lines. Throws `\Exception` if the repository path does not exist or is not a git repository. ```php /** * Runs a git command and returns the output (as an array). * * @param string $command "git [your-command-here]" * @param string|null $repoPath Defaults to $this->repo * * @return array Lines of the output * @throws \Exception */ public function command($command, $repoPath = null) ``` -------------------------------- ### FileFilter constructor signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/FileFilter.md Constructor accepts a Cli instance, the server's normalized config array, and the repository root path. Returns void. ```php /** * @param array $server The current server's config array from Config. */ public function __construct(Cli $cli, array $server, string $repo) ``` -------------------------------- ### Run static analysis Source: https://github.com/banago/phploy/blob/master/contributing.md Run static analysis on the codebase. ```bash composer analyze ``` -------------------------------- ### Programmatic Deployment Run with Deployment Class Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md Shows how to run a deployment programmatically, mirroring PHPloy's internal flow. Requires Cli, Config, Git, and Deployment instances; the run() method executes the deployment. ```php use Banago\PHPloy\Cli; use Banago\PHPloy\Config; use Banago\PHPloy\Deployment; use Banago\PHPloy\Git; $cli = new Cli(); $config = new Config($cli); $git = new Git(getcwd()); $deployment = new Deployment($cli, $git, $config); $deployment->run(); ``` -------------------------------- ### createDir($path): bool Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Creates a remote directory. Returns true on success, false on failure. ```APIDOC ## createDir($path): bool ### Description Creates a directory. ### Method createDir ### Parameters #### Path Parameters - `$path` (string) - Required - Remote directory path. ### Return - **bool** - `true` on success, `false` when creation fails (`UnableToCreateDirectory`). ``` -------------------------------- ### Reading and checking CLI arguments with hasArgument, getArgument, argumentProvided Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Shows how to instantiate the Cli class and check if an argument was explicitly provided. Use hasArgument to test presence, getArgument to retrieve the value (string|null), and argumentProvided to distinguish between a flag with no value (e.g., --rollback) and one with a value (e.g., --rollback ). The interactive picker path is used when the argument is present but no value was supplied. ```php use Banago\PHPloy\Cli; $cli = new Cli(); if ($cli->hasArgument('server')) { $server = $cli->getArgument('server'); // string|null } // --rollback with no value vs. --rollback if ($cli->hasArgument('rollback')) { if ($cli->argumentProvided('rollback')) { $target = (string) $cli->getArgument('rollback'); } else { // interactive picker path } } ``` -------------------------------- ### getServer(string $name): ?array Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Returns the normalized configuration array for a specific server by name. Returns null if the server does not exist. ```APIDOC ## getServer(string $name): ?array ### Description Returns the normalized configuration array for a specific server by name. Returns null if the server does not exist. ### Method Method ### Signature `public function getServer(string $name): ?array` ### Parameters - `$name` (string) - Required - Server section name. ### Return The normalized config array for that server, or `null` when it does not exist. ``` -------------------------------- ### new FileFilter(Cli $cli, array $server, string $repo) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/FileFilter.md Creates a new FileFilter instance for a given server configuration. The constructor stores the CLI wrapper, server config, and repository root path for later filtering operations. ```APIDOC ## Constructor ### Description Creates a new FileFilter instance for a given server configuration. The constructor stores the CLI wrapper, server config, and repository root path for later filtering operations. ### Method Constructor ### Signature ```php public function __construct(Cli $cli, array $server, string $repo) ``` ### Parameters - **$cli** (Cli) - Required - CLI wrapper (used for informational output). - **$server** (array) - Required - The current server's normalized config array (`exclude`/`include`/`base` keys are used). - **$repo** (string) - Required - Repository root path. ### Return void ``` -------------------------------- ### command($command, $repoPath = null): array Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Runs a git command and returns the output lines. Builds the git command with `-c core.quotepath=false` and explicit `--git-dir`/`--work-tree`. ```APIDOC ## Method: `command($command, $repoPath = null): array` ### Description Runs a git command and returns the output as an array of lines. The command is built as `git -c core.quotepath=false --git-dir="{repoPath}/.git" --work-tree="{repoPath}" {command}`. ### Parameters - **$command** (string) - Required - Git sub-command, e.g. `'rev-parse HEAD'` (without the leading `git`). - **$repoPath** (string|null) - Optional - Repository path; defaults to `$this->repo`. ### Return array of output lines. ### Throws - `\Exception` - `"Repository path does not exist: {repoPath}"` when the path is not a directory. - `\Exception` - `"Not a git repository: {repoPath}"` when the path has neither a `.git` directory nor a `.git` file (submodule gitdir pointer). ``` -------------------------------- ### handleEarlyExitCommands method signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md Returns true and stops construction when one of the following arguments is present: help, version, init, or dryrun. Each triggers a corresponding CLI action. ```php protected function handleEarlyExitCommands(): bool ``` -------------------------------- ### Resume Interrupted Deployment with --from Flag Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md Illustrates the resume behavior after an interrupted upload. The error message includes the stopping index, and re-running with '--from 599' resumes from that file without advancing .revision. ```php // from an interrupted upload the error says "Re-run with --from 599 to resume." // The user re-invokes: phploy --from 599 // uploadFile re-uploads file 599 and continues; .revision is not advanced by the // interrupted run, so a plain re-run also resumes correctly. ``` -------------------------------- ### new Config(Cli $cli) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Constructor for the Config class. Loads and normalizes server configuration from phploy.ini, environment variables, and an optional .phploy credentials file. Throws an exception if phploy.ini is missing or invalid. ```APIDOC ## Constructor ### Description Creates a new Config instance, loading and normalizing server configuration from phploy.ini, environment variables, and an optional .phploy credentials file. Throws an exception if phploy.ini is missing or invalid. ### Method Constructor ### Signature `public function __construct(Cli $cli)` ### Parameters - `$cli` (Cli) - Required - CLI wrapper (used by DebugTrait). ### Return void. Calls loadConfig(), which throws when phploy.ini is absent or invalid. ### Throws \Exception - see errors.md. ``` -------------------------------- ### Error-tolerant SFTP connection and exec Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Creates an SFTP Connection with an empty privkey to force password authentication, catching connection errors. Then, only for SFTP connections, runs a remote command via exec() and prints output, catching errors like "exec() is only supported for SFTP connections." or "Remote command failed: ...". ```php use Banago\PHPloy\Connection; try { $conn = new Connection([ 'scheme' => 'sftp', 'host' => 'example.com', 'user' => 'deploy', 'pass' => 'secret', 'path' => '/var/www', 'privkey' => '', // empty => password auth ]); } catch (Exception $e) { // "Please provide a connection protocol..." / adapter connect failure } // SFTP-only remote commands: if ($conn->isSftp()) { try { $out = $conn->exec('cd /var/www && composer install --no-dev'); echo $out; } catch (Exception $e) { // "exec() is only supported for SFTP connections." or "Remote command failed: ..." } } ``` -------------------------------- ### new Deployment($cli, $git, $config) Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Deployment.md Constructor for the Deployment class. It initializes the deployment workflow orchestrator with CLI, Git, and Config instances, and reads CLI arguments into internal state. ```APIDOC ## Constructor ### Description Creates a new Deployment instance that orchestrates the deployment workflow for target servers. ### Method Constructor ### Signature ```php public function __construct(Cli $cli, Git $git, Config $config) ``` ### Parameters - **$cli** (Cli) - Required - CLI wrapper (arguments + output). - **$git** (Git) - Required - Git wrapper. - **$config** (Config) - Required - Server configuration. ### Return void. Reads the following CLI arguments into state: | Property | Source | |---|---| | `$fresh` | `--fresh` | | `$force` | `--force` | | `$listFiles` | `--list` | | `$remoteList` | `--remote-list` | | `$status` | `--status` | | `$scanSubmodules` | `--submodules` | | `$sync` | `--sync` value (or `false`) | | `$revision` | `resolveRevision($cli)` | | `$from` | `resolveFromIndex($cli)` | Also sets `$this->repo = getcwd()`, `$this->mainRepo = $this->repo`, and enables debug via `setDebug($cli->hasArgument('debug'))`. ### Throws - `\Exception` from `resolveFromIndex()` for a non-positive `--from` value. - `\Exception` from `resolveRevision()` when the interactive rollback has no commits or no selection. ``` -------------------------------- ### getServers Method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Returns an associative array of all server configurations from phploy.ini. The shared '*' section is merged into each server and not returned as a server itself. ```php /** * Get all servers configuration */ public function getServers(): array ``` -------------------------------- ### exec($command): string Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Executes a remote command via SFTP. Only supported for SFTP connections; throws an exception otherwise. ```APIDOC ## exec($command): string ### Description Executes a remote command via SFTP. Only supported for SFTP connections; throws an exception otherwise. ### Method exec ### Parameters - **$command** (string) - Required - Command to execute on the remote server. ### Return string - Command output. ### Exceptions - Throws Exception if not SFTP or if command fails. ### Usage Example ```php $out = $conn->exec('cd /var/www && composer install --no-dev'); echo $out; ``` ``` -------------------------------- ### getServers(): array Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Config.md Returns an associative array of all server configurations from phploy.ini. The shared '*' section is merged into each server but not returned as a server itself. ```APIDOC ## getServers(): array ### Description Returns an associative array of all server configurations from phploy.ini. The shared '*' section is merged into each server but not returned as a server itself. ### Method Method ### Signature `public function getServers(): array` ### Parameters None ### Return Associative array of `name => serverConfigArray` for every section in phploy.ini (the `*` shared section is merged in, not returned as a server). ``` -------------------------------- ### Connection constructor signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Constructor for the Connection class. Accepts a server configuration array and returns a Connection instance. Throws exceptions for missing or unknown schemes. ```php /** * Connection constructor. * * @param array $server * * @throws \Exception * * @return Connection */ public function __construct($server) ``` -------------------------------- ### Command construction for git invocation Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Builds the git command with `-c core.quotepath=false` and explicit `--git-dir`/`--work-tree` to handle special characters in filenames. ```text git -c core.quotepath=false --git-dir="{repoPath}/.git" --work-tree="{repoPath}" {command} ``` -------------------------------- ### listContents method signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Connection.md Declares the public listContents method that returns an array of ['path' => string, 'type' => 'file'|'dir'] items, normalizing Flysystem FileAttributes/DirectoryAttributes. The $recursive parameter defaults to false. ```php /** * List directory contents * * @param string $path * @param bool $recursive * @return array */ public function listContents($path, $recursive = false) ``` -------------------------------- ### exec($command, $onErrorStopExecution = false): array Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Executes an arbitrary shell command and returns the output lines. Optionally stops execution on error. ```APIDOC ## Method: `exec($command, $onErrorStopExecution = false): array` ### Description Executes a console command and returns the output as an array of lines. When `$onErrorStopExecution` is true, a non-zero exit code throws an exception. ### Parameters - **$command** (string) - Required - Arbitrary shell command (stdout and stderr are merged via `2>&1`). - **$onErrorStopExecution** (boolean) - Optional - When `true`, a non-zero exit code throws. ### Return array of output lines. ### Throws - `\Exception` - `"Command [{command}] failed with exit code {code}"` when `$onErrorStopExecution` is true and the exit code is non-zero. ``` -------------------------------- ### rel_path($el): string Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/utils.md Strips the absolute path prefix from a given path. Returns the path with the current working directory prefix removed. ```APIDOC ## rel_path($el): string ### Description Strips the absolute path prefix from a given path. Returns the path with the current working directory prefix removed. ### Function Signature ```php function rel_path($el): string ``` ### Parameters - **$el** (string) - Required - Path to relativize. ### Return Value - **string** - The path with the `getcwd() . '/'` prefix stripped. ``` -------------------------------- ### argumentProvided method Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Returns true only when the value was explicitly given on the command line, not when it fell back to its defaultValue. Used by Deployment::resolveRevision() to distinguish --rollback from bare --rollback. ```php /** * Whether a value was explicitly provided on the command line for an * argument (as opposed to falling back to its default value). */ public function argumentProvided(string $name): bool ``` -------------------------------- ### Cli Constructor Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Constructor for the Cli class. Instantiates CLImate and calls registerArguments(), which parses $_SERVER['argv']. ```php /** * Constructor. */ public function __construct() ``` -------------------------------- ### Cli::logDeployment Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Cli.md Logs a deployment event and writes to phploy.log. Used to record deployment details. ```APIDOC ## Cli::logDeployment ### Description Logs a deployment event and writes to phploy.log. ### Method logDeployment ### Parameters - **revision** (string) - Required - The revision identifier. - **server** (string) - Required - The server name. - **branch** (string) - Required - The branch name. - **filesUploaded** (int) - Required - Number of files uploaded. - **filesDeleted** (int) - Required - Number of files deleted. - **success** (bool) - Required - Whether the deployment succeeded. ### Return Value - **void** - No return value. ### Example ```php $cli->logDeployment('abc123', 'prod', 'main', 12, 0, true); ``` ``` -------------------------------- ### exec method signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/Git.md Executes an arbitrary shell command and returns output lines. When `$onErrorStopExecution` is true, a non-zero exit code throws `\Exception` with message `"Command [{command}] failed with exit code {code}"`. ```php /** * Executes a console command and returns the output (as an array). * * @param string $command Command to execute * @param boolean $onErrorStopExecution If there is a problem, stop execution of the code * * @return array of all lines that were output to the console during the command (STDOUT) * * @throws \Exception */ public function exec($command, $onErrorStopExecution = false) ``` -------------------------------- ### PHPloy constructor signature Source: https://github.com/banago/phploy/blob/master/_autodocs/api-reference/PHPloy.md The constructor takes no arguments and throws \Exception when the current working directory is not a Git repository. It has side effects and executes the entire CLI run. ```php /** * Constructor. * * @throws \Exception */ public function __construct() ```