default services conflit ?
This commit is contained in:
17
old.vendor/consolidation/site-process/.editorconfig
Normal file
17
old.vendor/consolidation/site-process/.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
# This file is for unifying the coding style for different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[**.php]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[{composer.json,composer.lock}]
|
||||
indent_size = 4
|
31
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/bug_report_or_support_request.md
vendored
Normal file
31
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/bug_report_or_support_request.md
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report or support request
|
||||
about: Report a bug or ask a question about expected behavior.
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug or behavior**
|
||||
A clear and concise description of the behavior you are seeing.
|
||||
|
||||
**To Reproduce**
|
||||
What did you do?
|
||||
|
||||
**Expected behavior**
|
||||
What did you expect would happen?
|
||||
|
||||
**Actual behavior**
|
||||
What happened instead?
|
||||
|
||||
**Workaround**
|
||||
Is there another way to do the desired action?
|
||||
|
||||
### System Configuration
|
||||
| Q | A
|
||||
| --------------- | ---
|
||||
| Drush version? | 9.x/8.x (please be specific, and try latest dev build)
|
||||
| Drupal version? | 7.x/8.x
|
||||
| PHP version | 5.6/7.1
|
||||
| OS? | Mac/Linux/Windows
|
||||
|
||||
**Additional information**
|
||||
Add any other context about the problem here.
|
19
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/documentation_request.md
vendored
Normal file
19
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/documentation_request.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Documentation request
|
||||
about: If you know what the documentation change should be, please consider submitting
|
||||
a pull request instead. If you do know where the documentation you need is, please
|
||||
submit a support request first.
|
||||
|
||||
---
|
||||
|
||||
**Existing document**
|
||||
Please provide a link to the existing document that is unclear or incomplete.
|
||||
|
||||
**What are you attempting to do**
|
||||
Please explain the task you are attempting to accomplish.
|
||||
|
||||
**In what way is the existing documentation unclear or incomplete**
|
||||
Please explain any confusion or ambiguities in the existing documentation.
|
||||
|
||||
**What should the documentation say instead?**
|
||||
To the best of your ability, explain what additional information would allow you to complete your task. If you already know what the documentation should say, please consider submitting a documentation pull request instead.
|
17
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
old.vendor/consolidation/site-process/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
16
old.vendor/consolidation/site-process/.github/pull_request_template.md
vendored
Normal file
16
old.vendor/consolidation/site-process/.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
### Overview
|
||||
This pull request:
|
||||
|
||||
| Q | A
|
||||
| ------------- | ---
|
||||
| Bug fix? | yes/no
|
||||
| New feature? | yes/no <!-- don't forget to update CHANGELOG.md files -->
|
||||
| Has tests? | yes/no
|
||||
| BC breaks? | no
|
||||
| Deprecations? | yes/no
|
||||
|
||||
### Summary
|
||||
Short overview of what changed.
|
||||
|
||||
### Description
|
||||
Any additional information.
|
171
old.vendor/consolidation/site-process/.github/workflows/ci.yml
vendored
Normal file
171
old.vendor/consolidation/site-process/.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
# From https://github.com/sebastianbergmann/phpunit/blob/20ab19d3aed56fccf9569cd33c6cd0baab0ec272/.github/workflows/ci.yml
|
||||
# (With many modifications)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
name: CI
|
||||
|
||||
jobs:
|
||||
coding-guidelines:
|
||||
name: Coding Guidelines
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --no-ansi --no-interaction --no-progress
|
||||
|
||||
- name: Run phpcs
|
||||
run: composer cs
|
||||
|
||||
- name: Run linter
|
||||
run: composer lint
|
||||
|
||||
backward-compatibility:
|
||||
name: Backward Compatibility
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Fetch tags
|
||||
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||
|
||||
- name: Install PHP with extensions
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
coverage: none
|
||||
extensions: intl
|
||||
|
||||
- name: Install roave/backward-compatibility-check
|
||||
run: |
|
||||
mkdir -p tools
|
||||
composer --working-dir=tools require roave/backward-compatibility-check:^5
|
||||
|
||||
- name: Run roave/backward-compatibility-check
|
||||
run: ./tools/vendor/bin/roave-backward-compatibility-check --from=4.1.2
|
||||
|
||||
tests:
|
||||
name: Tests
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
PHP_EXTENSIONS: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
|
||||
php-version:
|
||||
- "7.4"
|
||||
|
||||
php-ini-values:
|
||||
- assert.exception=1, zend.assertions=1
|
||||
|
||||
dependencies:
|
||||
- locked
|
||||
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
php-version: "7.1"
|
||||
dependencies: lowest
|
||||
|
||||
- os: ubuntu-latest
|
||||
php-version: "7.4"
|
||||
dependencies: highest
|
||||
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.0"
|
||||
dependencies: highest
|
||||
php-ini-values: assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit_buffer_size=4096M, opcache.jit=1205
|
||||
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.1"
|
||||
dependencies: highest
|
||||
php-ini-values: assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit_buffer_size=4096M, opcache.jit=1205
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install PHP with extensions
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
coverage: pcov
|
||||
extensions: ${{ env.PHP_EXTENSIONS }}
|
||||
ini-values: ${{ matrix.php-ini-values }}
|
||||
|
||||
- name: Determine composer cache directory on Linux
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
|
||||
|
||||
- name: Determine composer cache directory on Windows
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: Add-Content -Path $ENV:GITHUB_ENV -Value "COMPOSER_CACHE_DIR=~\AppData\Local\Composer"
|
||||
|
||||
- name: Cache dependencies installed with composer
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ env.COMPOSER_CACHE_DIR }}
|
||||
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
|
||||
restore-keys: |
|
||||
php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
|
||||
|
||||
- name: Make sure composer.json is valid before we start modifyig it
|
||||
run: composer validate
|
||||
|
||||
- name: Clear platform php configuration in case we need to update phpunit
|
||||
run: composer config --unset platform.php
|
||||
|
||||
- name: Update phpunit if dependencies are locked in case phpunit version in lock file is not compatible
|
||||
if: matrix.dependencies == 'locked'
|
||||
run: |
|
||||
composer install --no-ansi --no-interaction --no-progress
|
||||
composer update --no-ansi --no-interaction --no-progress phpunit/phpunit --with-all-dependencies
|
||||
|
||||
- name: Install lowest dependencies with composer
|
||||
if: matrix.dependencies == 'lowest'
|
||||
run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest
|
||||
|
||||
- name: Install highest dependencies with composer
|
||||
if: matrix.dependencies == 'highest'
|
||||
run: composer update --no-ansi --no-interaction --no-progress
|
||||
|
||||
# Use "script" hack to give us a tty. See https://github.com/actions/runner/issues/241#issuecomment-745902718
|
||||
- name: Run tests with phpunit
|
||||
if: matrix.os != 'windows-latest'
|
||||
shell: 'script -q -e -c "bash {0}"'
|
||||
run: composer unit
|
||||
|
||||
# Run without "script" on Windows
|
||||
- name: Run tests with phpunit
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: composer unit
|
||||
|
||||
- name: Publish code coverage to Codecov
|
||||
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '8.0'
|
||||
run: bash <(curl -s https://codecov.io/bash)
|
6
old.vendor/consolidation/site-process/.gitignore
vendored
Normal file
6
old.vendor/consolidation/site-process/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.idea/
|
||||
*.phar
|
||||
build
|
||||
tools
|
||||
vendor/
|
||||
.phpunit.result.cache
|
11
old.vendor/consolidation/site-process/.scrutinizer.yml
Normal file
11
old.vendor/consolidation/site-process/.scrutinizer.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
checks:
|
||||
php: true
|
||||
filter:
|
||||
excluded_paths:
|
||||
- customize/*
|
||||
- tests/*
|
||||
tools:
|
||||
php_sim: true
|
||||
php_pdepend: true
|
||||
php_analyzer: true
|
||||
php_cs_fixer: false
|
61
old.vendor/consolidation/site-process/CHANGELOG.md
Normal file
61
old.vendor/consolidation/site-process/CHANGELOG.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Changelog
|
||||
|
||||
### 4.2.0 - 2022/Feb/18
|
||||
|
||||
* Support kubectl transport (#60)
|
||||
|
||||
### 4.1.3 / 4.1.2 - 2022/Jan/18
|
||||
|
||||
* Support symfony/process ^5 via illicit access to a private member (#58)
|
||||
* Avoid verbose output when we have nothing to say in ProcessFailedException. (#54)
|
||||
|
||||
### 4.1.1 - 2022/Jan/3
|
||||
|
||||
* Support PHP 8.1. (n.b. No code changes to library; this release is merely to enable testing on 8.1 and explicitly declare support.)
|
||||
|
||||
### 4.1.0 - 2021/Feb/20
|
||||
|
||||
* Support PHP 8
|
||||
|
||||
### 4.0.0 - 2020/May/27
|
||||
|
||||
* Support symfony/process ^4.4, and other symfony components ^5
|
||||
|
||||
### 2.1.0 - 2019/Sep/10
|
||||
|
||||
* Added environment variables in aliases (#47)
|
||||
|
||||
### 2.0.4 - 2019/Aug/12
|
||||
|
||||
* Bugfix: Better error reporting when json output fails to parse. (#46)
|
||||
|
||||
### 2.0.3 - 2019/Jun/4
|
||||
|
||||
* Bugfix: Use posix_isatty when available. (#43)
|
||||
|
||||
### 2.0.2 - 2019/Apr/5
|
||||
|
||||
* When the transport is Docker, allow setting any docker-compose flags in the alias file Alexandru Szasz (#39)
|
||||
* Added vagrant transport. Alexandru Szasz (#40)
|
||||
* Added Util class to help detect TTY properly. Dane Powell (#41)
|
||||
|
||||
### 2.0.1 - 2019/Apr/2
|
||||
|
||||
* Do not format output in RealTimeOutput
|
||||
|
||||
### 2.0.0 - 2019/Mar/12
|
||||
|
||||
* Add a separaate 'addTransports' method for clients that wish to subclass the process manager (#32)
|
||||
* Rename AliasRecord to SiteAlias; Use SiteAliasWithConfig::create (#31)
|
||||
* Use SiteAliasWithConfig (#30)
|
||||
* Use ConfigAwareInterface/Trait (#26)
|
||||
* Allow configuration to be injected into ProcessManager. (#22)
|
||||
* setWorkingDirectory() controls remote execution dir (#25)
|
||||
|
||||
### 1.1.0 - 1.1.2 - 2019/Feb/13
|
||||
|
||||
* ms-slasher13 improve escaping on Windows (#24)
|
||||
|
||||
### 1.0.0 - 2019/Jan/17
|
||||
|
||||
* Initial release
|
92
old.vendor/consolidation/site-process/CONTRIBUTING.md
Normal file
92
old.vendor/consolidation/site-process/CONTRIBUTING.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# Contributing to SiteProcess
|
||||
|
||||
Thank you for your interest in contributing to SiteProcess! Here are some of the guidelines you should follow to make the most of your efforts:
|
||||
|
||||
## Code Style Guidelines
|
||||
|
||||
This project adheres to the [PSR-2 Coding Style Guide](http://www.php-fig.org/psr/psr-2/) for PHP code. An `.editorconfig` file is included with the repository to help you get up and running quickly. Most modern editors support this standard, but if yours does not or you would like to configure your editor manually, follow the guidelines in the document linked above.
|
||||
|
||||
You can run the PHP Codesniffer on your work using a convenient command provided as a composer script:
|
||||
```
|
||||
composer cs
|
||||
```
|
||||
The above will run the PHP Codesniffer on the project sources. To automatically clean up code style violations, run:
|
||||
```
|
||||
composer cbf
|
||||
```
|
||||
Please ensure all contributions are compliant _before_ submitting a pull request.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
### Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
### Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
### Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
### Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
### Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
### Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
29
old.vendor/consolidation/site-process/LICENSE
Normal file
29
old.vendor/consolidation/site-process/LICENSE
Normal file
@@ -0,0 +1,29 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-2020 Greg Anderson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
DEPENDENCY LICENSES:
|
||||
|
||||
Name Version License
|
||||
consolidation/config 2.0.0 MIT
|
||||
consolidation/site-alias 3.0.1 MIT
|
||||
dflydev/dot-access-data v1.1.0 MIT
|
||||
grasmash/expander 1.0.0 MIT
|
||||
symfony/process v4.4.10 MIT
|
135
old.vendor/consolidation/site-process/README.md
Normal file
135
old.vendor/consolidation/site-process/README.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# Site Process
|
||||
|
||||
A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call.
|
||||
|
||||
[](https://travis-ci.org/consolidation/site-process)
|
||||
[](https://scrutinizer-ci.com/g/consolidation/site-process/?branch=master)
|
||||
[](https://codecov.io/gh/consolidation/site-process)
|
||||
[](LICENSE)
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
Site Process is a thin wrapper around the [Symfony Process Component](https://symfony.com/doc/3.4/components/process) that allows applications to use the [Site Alias library](https://github.com/consolidation/site-alias) to specify the target for a remote call.
|
||||
|
||||
For comparison purposes, the `Process` object may be created to run an application on the local system using the standard Symfony Process Component API like so:
|
||||
```
|
||||
$process = new Process(['ls', '-lsa']);
|
||||
```
|
||||
Similarly, a remote call can be done using the general-purpose `SiteProcess` API, which is accessible via the ProcessManager object:
|
||||
```
|
||||
$processManager = ProcessManager::createDefault();
|
||||
$process = $processManager->siteProcess($site_alias, ['ls', '-lsa', '{root}']);
|
||||
```
|
||||
In this example, if `$site_alias` represents a site on the same system, then the `ls -lsa` command will run locally. If, on the other hand, it represents a remote site, then the `ls -lsa` command will be wrapped in an ssh call to the remote system. In either case, the `{root}` reference will be replaced with the value of the attribute of the site alias named `root`. An exception will be thrown if the named attribute does not exist.
|
||||
|
||||
Options may also be specified as an associative array provided as a third parameter:
|
||||
```
|
||||
$process = $processManager->siteProcess($site_alias, ['git', 'status'], ['untracked-files' => 'no']);
|
||||
```
|
||||
This is equivalent to:
|
||||
```
|
||||
$process = $processManager->siteProcess($site_alias, ['git', '--untracked-files=no', 'status']);
|
||||
```
|
||||
### Transports
|
||||
#### SSH
|
||||
Wraps a command so that it runs on a remote system via the ssh cli.
|
||||
|
||||
Example:
|
||||
```yaml
|
||||
local:
|
||||
host: localhost
|
||||
uri: http://localhost
|
||||
ssh:
|
||||
options: -o PasswordAuthentication=no -i $HOME/.ssh/id_rsa
|
||||
|
||||
```
|
||||
### Vagrant
|
||||
Wraps commands so they run with `vagrant ssh -c`.
|
||||
|
||||
Example:
|
||||
```yaml
|
||||
local:
|
||||
uri: http://localhost
|
||||
vagrant:
|
||||
```
|
||||
|
||||
#### Docker Compose
|
||||
Wraps a command so that it runs on a remote system via docker-compose.
|
||||
|
||||
Example:
|
||||
```yaml
|
||||
local:
|
||||
host: localhost
|
||||
uri: http://localhost
|
||||
docker:
|
||||
service: drupal
|
||||
compose:
|
||||
options: --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir
|
||||
exec:
|
||||
options: --user www-data
|
||||
|
||||
```
|
||||
|
||||
The above would execute commands prefixed with:
|
||||
```
|
||||
docker-compose --project dockerComposeProjectName --file docker-compose.yml --project-directory dockerComposeWorkDir exec --user www-data -T drupal
|
||||
```
|
||||
|
||||
`docker.project` and `compose.options --project` do the same thing, docker.project existed before options.
|
||||
|
||||
`docker.service` is the exact name of the service as it appears in docker-compos.yml
|
||||
|
||||
Check the [docker-compose](https://docs.docker.com/compose/reference/overview/) manual for all available options.
|
||||
|
||||
#### Local
|
||||
Runs the command on the local system.
|
||||
|
||||
## Running the tests
|
||||
|
||||
The test suite may be run locally by way of some simple composer scripts:
|
||||
|
||||
| Test | Command
|
||||
| ---------------- | ---
|
||||
| Run all tests | `composer test`
|
||||
| PHPUnit tests | `composer unit`
|
||||
| PHP linter | `composer lint`
|
||||
| Code style | `composer cs`
|
||||
| Fix style errors | `composer cbf`
|
||||
|
||||
|
||||
## Deployment
|
||||
|
||||
- Run `composer release`
|
||||
|
||||
## Contributing
|
||||
|
||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us.
|
||||
|
||||
## Versioning
|
||||
|
||||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [releases](https://github.com/consolidation/site-process/releases) page.
|
||||
|
||||
| Branch | Symfony Versions | PHP Versions
|
||||
| ------------ | ---------------- | ------------
|
||||
| main (4.x) | ^4 | 7.1+
|
||||
| 2.x | ^2 | ^3 | 5.6+
|
||||
|
||||
Note that all 3.x releases of consolidation/site-process were skipped simply to align the 4.x versions with Symfony 4.x support.
|
||||
|
||||
Note that the API of consolidation/site-process itself is compatible between the 2.x and 4.x versions, so most clients that work with both Symfony 3 and Symfony 4 should be able to require `"consolidation/site-process": "^2 | ^4"` without problems.
|
||||
|
||||
## Authors
|
||||
|
||||
* [Greg Anderson](https://github.com/greg-1-anderson)
|
||||
* [Moshe Weitzman](http://weitzman.github.com)
|
||||
|
||||
See also the list of [contributors](https://github.com/consolidation/site-process/contributors) who participated in this project.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
* Thanks to PurpleBooth for the [example README template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)
|
63
old.vendor/consolidation/site-process/composer.json
Normal file
63
old.vendor/consolidation/site-process/composer.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "consolidation/site-process",
|
||||
"description": "A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call.",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Greg Anderson",
|
||||
"email": "greg.1.anderson@greenknowe.org"
|
||||
},
|
||||
{
|
||||
"name": "Moshe Weitzman",
|
||||
"email": "weitzman@tejasa.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Consolidation\\SiteProcess\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Consolidation\\SiteProcess\\": "tests/src"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
"consolidation/config": "^1.2.1|^2",
|
||||
"consolidation/site-alias": "^3",
|
||||
"symfony/process": "^4.3.4|^5",
|
||||
"symfony/console": "^2.8.52|^3|^4.4|^5"
|
||||
},
|
||||
"require-dev": {
|
||||
"squizlabs/php_codesniffer": "^3",
|
||||
"phpunit/phpunit": "^7.5.20|^8.5.14",
|
||||
"yoast/phpunit-polyfills": "^0.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"cs": "phpcs --standard=PSR2 -n src",
|
||||
"cbf": "phpcbf --standard=PSR2 -n src",
|
||||
"unit": "phpunit --colors=always",
|
||||
"lint": [
|
||||
"find src -name '*.php' -print0 | xargs -0 -n1 php -l",
|
||||
"find tests/src -name '*.php' -print0 | xargs -0 -n1 php -l"
|
||||
],
|
||||
"test": [
|
||||
"@lint",
|
||||
"@unit",
|
||||
"@cs"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true,
|
||||
"platform": {
|
||||
"php": "7.2.28"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "4.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
19
old.vendor/consolidation/site-process/phpunit.xml.dist
Normal file
19
old.vendor/consolidation/site-process/phpunit.xml.dist
Normal file
@@ -0,0 +1,19 @@
|
||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="site-process">
|
||||
<directory prefix="" suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
<!--
|
||||
<log type="coverage-html" target="build/logs/coverage" lowUpperBound="35"
|
||||
highLowerBound="70"/>
|
||||
-->
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
</logging>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Factory;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\DockerComposeTransport;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
|
||||
/**
|
||||
* DockerComposeTransportFactory will create an DockerComposeTransport for
|
||||
* applicable site aliases.
|
||||
*/
|
||||
class DockerComposeTransportFactory implements TransportFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function check(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
// TODO: deprecate and eventually remove 'isContainer()', and move the logic here.
|
||||
return $siteAlias->isContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function create(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return new DockerComposeTransport($siteAlias);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Factory;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\KubectlTransport;
|
||||
|
||||
/**
|
||||
* KubectlTransportFactory will create an KubectlTransport for applicable site aliases.
|
||||
*/
|
||||
class KubectlTransportFactory implements TransportFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function check(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return $siteAlias->has('kubectl');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function create(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return new KubectlTransport($siteAlias);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Factory;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\SshTransport;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
|
||||
/**
|
||||
* SshTransportFactory will create an SshTransport for applicable site aliases.
|
||||
*/
|
||||
class SshTransportFactory implements TransportFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function check(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
// TODO: deprecate and eventually remove 'isRemote()', and move the logic here.
|
||||
return $siteAlias->isRemote();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function create(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return new SshTransport($siteAlias);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Factory;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\TransportInterface;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
|
||||
/**
|
||||
* TransportFactoryInterface defines a transport factory that is responsible
|
||||
* for:
|
||||
*
|
||||
* - Determining whether a provided site alias is applicable to this transport
|
||||
* - Creating an instance of a transport for an applicable site alias.
|
||||
*
|
||||
* There is always a transport for every factory, and visa-versa.
|
||||
* @see Consolidation\SiteProcess\Transport\TransportInterface
|
||||
*/
|
||||
interface TransportFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Check to see if a provided site alias is applicable to this transport type.
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @return bool
|
||||
*/
|
||||
public function check(SiteAliasInterface $siteAlias);
|
||||
|
||||
/**
|
||||
* Create a transport instance for an applicable site alias.
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @return TransportInterface
|
||||
*/
|
||||
public function create(SiteAliasInterface $siteAlias);
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Factory;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\VagrantTransport;
|
||||
|
||||
/**
|
||||
* VagrantTransportFactory will create a VagrantTransport for applicable site aliases.
|
||||
*/
|
||||
class VagrantTransportFactory implements TransportFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function check(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return $siteAlias->has('vagrant');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function create(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return new VagrantTransport($siteAlias);
|
||||
}
|
||||
}
|
235
old.vendor/consolidation/site-process/src/ProcessBase.php
Normal file
235
old.vendor/consolidation/site-process/src/ProcessBase.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Style\OutputStyle;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Consolidation\SiteProcess\Util\RealtimeOutputHandler;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
|
||||
/**
|
||||
* A wrapper around Symfony Process.
|
||||
*
|
||||
* - Supports simulated mode. Typically enabled via a --simulate option.
|
||||
* - Supports verbose mode - logs all runs.
|
||||
* - Can convert output json data into php array (convenience method)
|
||||
* - Provides a "realtime output" helper
|
||||
*/
|
||||
class ProcessBase extends Process
|
||||
{
|
||||
/**
|
||||
* @var OutputStyle
|
||||
*/
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
protected $stderr;
|
||||
|
||||
private $simulated = false;
|
||||
|
||||
private $verbose = false;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* realtimeStdout returns the output stream that realtime output
|
||||
* should be sent to (if applicable)
|
||||
*
|
||||
* @return OutputStyle $output
|
||||
*/
|
||||
public function realtimeStdout()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
protected function realtimeStderr()
|
||||
{
|
||||
if ($this->stderr) {
|
||||
return $this->stderr;
|
||||
}
|
||||
if (method_exists($this->output, 'getErrorStyle')) {
|
||||
return $this->output->getErrorStyle();
|
||||
}
|
||||
|
||||
return $this->realtimeStdout();
|
||||
}
|
||||
|
||||
/**
|
||||
* setRealtimeOutput allows the caller to inject an OutputStyle object
|
||||
* that will be used to stream realtime output if applicable.
|
||||
*
|
||||
* @param OutputStyle $output
|
||||
*/
|
||||
public function setRealtimeOutput(OutputInterface $output, $stderr = null)
|
||||
{
|
||||
$this->output = $output;
|
||||
$this->stderr = $stderr instanceof ConsoleOutputInterface ? $stderr->getErrorOutput() : $stderr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isVerbose()
|
||||
{
|
||||
return $this->verbose;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $verbose
|
||||
*/
|
||||
public function setVerbose($verbose)
|
||||
{
|
||||
$this->verbose = $verbose;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSimulated()
|
||||
{
|
||||
return $this->simulated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $simulated
|
||||
*/
|
||||
public function setSimulated($simulated)
|
||||
{
|
||||
$this->simulated = $simulated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger($logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function start(callable $callback = null, array $env = [])
|
||||
{
|
||||
$cmd = $this->getCommandLine();
|
||||
if ($this->isSimulated()) {
|
||||
$this->getLogger()->notice('Simulating: ' . $cmd);
|
||||
// Run a command that always succeeds (on Linux and Windows).
|
||||
$this->overrideCommandLine('true');
|
||||
} elseif ($this->isVerbose()) {
|
||||
$this->getLogger()->info('Executing: ' . $cmd);
|
||||
}
|
||||
parent::start($callback, $env);
|
||||
// Set command back to original value in case anyone asks.
|
||||
if ($this->isSimulated()) {
|
||||
$this->overrideCommandLine($cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Process output and decode its JSON.
|
||||
*
|
||||
* @return array
|
||||
* An associative array.
|
||||
*/
|
||||
public function getOutputAsJson()
|
||||
{
|
||||
$output = trim($this->getOutput());
|
||||
if (empty($output)) {
|
||||
throw new \InvalidArgumentException('Output is empty.');
|
||||
}
|
||||
if (Escape::isWindows()) {
|
||||
// Doubled double quotes were converted to \\".
|
||||
// Revert to double quote.
|
||||
$output = str_replace('\\"', '"', $output);
|
||||
// Revert of doubled backslashes.
|
||||
$output = preg_replace('#\\\\{2}#', '\\', $output);
|
||||
}
|
||||
$sanitizedOutput = $this->removeNonJsonJunk($output);
|
||||
$json = json_decode($sanitizedOutput, true);
|
||||
if (!isset($json)) {
|
||||
$msg = 'Unable to decode output into JSON: ' . json_last_error_msg();
|
||||
if (json_last_error() == JSON_ERROR_SYNTAX) {
|
||||
$msg .= "\n\n$output";
|
||||
}
|
||||
throw new \InvalidArgumentException($msg);
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow for a certain amount of resiliancy in the output received when
|
||||
* json is expected.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
protected function removeNonJsonJunk($data)
|
||||
{
|
||||
// Exit early if we have no output.
|
||||
$data = trim($data);
|
||||
if (empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
// If the data is a simple quoted string, or an array, then exit.
|
||||
if ((($data[0] == '"') && ($data[strlen($data) - 1] == '"')) ||
|
||||
(($data[0] == "[") && ($data[strlen($data) - 1] == "]"))
|
||||
) {
|
||||
return $data;
|
||||
}
|
||||
// If the json is not a simple string or a simple array, then is must
|
||||
// be an associative array. We will remove non-json garbage characters
|
||||
// before and after the enclosing curley-braces.
|
||||
$start = strpos($data, '{');
|
||||
$end = strrpos($data, '}') + 1;
|
||||
$data = substr($data, $start, $end - $start);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a realTime output object.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function showRealtime()
|
||||
{
|
||||
$realTimeOutput = new RealtimeOutputHandler($this->realtimeStdout(), $this->realtimeStderr());
|
||||
$realTimeOutput->configure($this);
|
||||
return $realTimeOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the command line to be executed.
|
||||
*
|
||||
* @param string|array $commandline The command to execute
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @todo refactor library so this hack to get around changes in
|
||||
* symfony/process 5 is unnecessary.
|
||||
*/
|
||||
private function overrideCommandLine($commandline)
|
||||
{
|
||||
$commandlineSetter = function ($commandline) {
|
||||
$this->commandline = $commandline;
|
||||
};
|
||||
$commandlineSetter->bindTo($this, Process::class)($commandline);
|
||||
return $this;
|
||||
}
|
||||
}
|
178
old.vendor/consolidation/site-process/src/ProcessManager.php
Normal file
178
old.vendor/consolidation/site-process/src/ProcessManager.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteProcess\Factory\KubectlTransportFactory;
|
||||
use Consolidation\SiteProcess\Factory\VagrantTransportFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Factory\SshTransportFactory;
|
||||
use Consolidation\SiteProcess\Factory\DockerComposeTransportFactory;
|
||||
use Consolidation\SiteProcess\Factory\TransportFactoryInterface;
|
||||
use Consolidation\SiteProcess\Transport\LocalTransport;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Consolidation\Config\Config;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
use Consolidation\Config\ConfigAwareInterface;
|
||||
use Consolidation\Config\ConfigAwareTrait;
|
||||
use Consolidation\SiteAlias\SiteAliasWithConfig;
|
||||
|
||||
/**
|
||||
* ProcessManager will create a SiteProcess to run a command on a given
|
||||
* site as indicated by a SiteAlias.
|
||||
*
|
||||
* ProcessManager also manages a collection of transport factories, and
|
||||
* will produce transport instances as needed for provided site aliases.
|
||||
*/
|
||||
class ProcessManager implements ConfigAwareInterface
|
||||
{
|
||||
use ConfigAwareTrait;
|
||||
|
||||
/** @var ConfigInterface */
|
||||
protected $configRuntime;
|
||||
|
||||
protected $transportFactories = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = new Config();
|
||||
$this->configRuntime = new Config();
|
||||
}
|
||||
|
||||
/**
|
||||
* setConfigRuntime sets the config object that holds runtime config
|
||||
* items, i.e. config set from the commandline rather than a config file.
|
||||
* Configuration priority (highest to lowest) is:
|
||||
* - config runtime
|
||||
* - site alias
|
||||
* - config files
|
||||
*/
|
||||
public function setConfigRuntime(ConfigInterface $configRuntime)
|
||||
{
|
||||
$this->configRuntime = $configRuntime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* createDefault creates a Transport manager and add the default transports to it.
|
||||
*/
|
||||
public static function createDefault()
|
||||
{
|
||||
$processManager = new self();
|
||||
return static::addTransports($processManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* addTransports adds the avaiable transports to the
|
||||
* provided process manager.
|
||||
*/
|
||||
public static function addTransports(ProcessManager $processManager)
|
||||
{
|
||||
$processManager->add(new SshTransportFactory());
|
||||
$processManager->add(new KubectlTransportFactory());
|
||||
$processManager->add(new DockerComposeTransportFactory());
|
||||
$processManager->add(new VagrantTransportFactory());
|
||||
|
||||
return $processManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a site process configured with an appropriate transport
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias Target for command
|
||||
* @param array $args Command arguments
|
||||
* @param array $options Associative array of command options
|
||||
* @param array $optionsPassedAsArgs Associtive array of options to be passed as arguments (after double-dash)
|
||||
* @return Process
|
||||
*/
|
||||
public function siteProcess(SiteAliasInterface $siteAlias, $args = [], $options = [], $optionsPassedAsArgs = [])
|
||||
{
|
||||
$transport = $this->getTransport($siteAlias);
|
||||
$process = new SiteProcess($siteAlias, $transport, $args, $options, $optionsPassedAsArgs);
|
||||
return $process;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Process instance from a commandline string.
|
||||
* @param array $command The command to run and its arguments listed as separate entries
|
||||
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
|
||||
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
|
||||
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
|
||||
* @param int|float|null $timeout The timeout in seconds or null to disable
|
||||
* @return Process
|
||||
*/
|
||||
public function process($command, $cwd = null, array $env = null, $input = null, $timeout = 60)
|
||||
{
|
||||
return new ProcessBase($command, $cwd, $env, $input, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Process instance from a commandline string.
|
||||
* @param string $command The commandline string to run
|
||||
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
|
||||
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
|
||||
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
|
||||
* @param int|float|null $timeout The timeout in seconds or null to disable
|
||||
* @return Process
|
||||
*/
|
||||
public function shell($command, $cwd = null, array $env = null, $input = null, $timeout = 60)
|
||||
{
|
||||
return ProcessBase::fromShellCommandline($command, $cwd, $env, $input, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a transport factory to our factory list
|
||||
* @param TransportFactoryInterface $factory
|
||||
*/
|
||||
public function add(TransportFactoryInterface $factory)
|
||||
{
|
||||
$this->transportFactories[] = $factory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasTransport determines if there is a transport that handles the
|
||||
* provided site alias.
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasTransport(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return $this->getTransportFactory($siteAlias) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransport returns a transport that is applicable to the provided site alias.
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @return TransportInterface
|
||||
*/
|
||||
public function getTransport(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
$factory = $this->getTransportFactory($siteAlias);
|
||||
|
||||
$siteAliasWithConfig = SiteAliasWithConfig::create($siteAlias, $this->config, $this->configRuntime);
|
||||
|
||||
if ($factory) {
|
||||
return $factory->create($siteAliasWithConfig);
|
||||
}
|
||||
return new LocalTransport();
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransportFactory returns a factory for the provided site alias.
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @return TransportFactoryInterface
|
||||
*/
|
||||
protected function getTransportFactory(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
foreach ($this->transportFactories as $factory) {
|
||||
if ($factory->check($siteAlias)) {
|
||||
return $factory;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
/**
|
||||
* Inflection interface for the site alias manager.
|
||||
*/
|
||||
interface ProcessManagerAwareInterface
|
||||
{
|
||||
/**
|
||||
* @param ProcessManager $processManager
|
||||
*/
|
||||
public function setProcessManager(ProcessManager $processManager);
|
||||
|
||||
/**
|
||||
* @return ProcessManager
|
||||
*/
|
||||
public function processManager();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasProcessManager();
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
/**
|
||||
* Inflection trait for the site alias manager.
|
||||
*/
|
||||
trait ProcessManagerAwareTrait
|
||||
{
|
||||
protected $processManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setProcessManager(ProcessManager $processManager)
|
||||
{
|
||||
$this->processManager = $processManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ProcessManager
|
||||
*/
|
||||
public function processManager()
|
||||
{
|
||||
return $this->processManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function hasProcessManager()
|
||||
{
|
||||
return isset($this->processManager);
|
||||
}
|
||||
}
|
278
old.vendor/consolidation/site-process/src/SiteProcess.php
Normal file
278
old.vendor/consolidation/site-process/src/SiteProcess.php
Normal file
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Transport\DockerComposeTransport;
|
||||
use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
||||
use Consolidation\SiteProcess\Transport\LocalTransport;
|
||||
use Consolidation\SiteProcess\Transport\SshTransport;
|
||||
use Consolidation\SiteProcess\Transport\TransportInterface;
|
||||
use Consolidation\Config\Util\Interpolator;
|
||||
use Consolidation\SiteProcess\Util\Shell;
|
||||
use Consolidation\SiteProcess\Util\ShellOperatorInterface;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* A wrapper around Symfony Process that uses site aliases
|
||||
* (https://github.com/consolidation/site-alias)
|
||||
*
|
||||
* - Interpolate arguments using values from the alias
|
||||
* e.g. `$process = new SiteProcess($alias, ['git', '-C', '{{root}}']);`
|
||||
* - Make remote calls via ssh as if they were local.
|
||||
*/
|
||||
class SiteProcess extends ProcessBase
|
||||
{
|
||||
/** @var SiteAliasInterface */
|
||||
protected $siteAlias;
|
||||
/** @var string[] */
|
||||
protected $args;
|
||||
/** @var string[] */
|
||||
protected $options;
|
||||
/** @var string[] */
|
||||
protected $optionsPassedAsArgs;
|
||||
/** @var string */
|
||||
protected $cd_remote;
|
||||
/** @var TransportInterface */
|
||||
protected $transport;
|
||||
|
||||
/**
|
||||
* Process arguments and options per the site alias and build the
|
||||
* actual command to run.
|
||||
*/
|
||||
public function __construct(SiteAliasInterface $siteAlias, TransportInterface $transport, $args, $options = [], $optionsPassedAsArgs = [])
|
||||
{
|
||||
$this->siteAlias = $siteAlias;
|
||||
$this->transport = $transport;
|
||||
$this->args = $args;
|
||||
$this->options = $options;
|
||||
$this->optionsPassedAsArgs = $optionsPassedAsArgs;
|
||||
|
||||
parent::__construct([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a starting directory for the remote process.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWorkingDirectory()
|
||||
{
|
||||
return $this->cd_remote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a starting directory for the remote process.
|
||||
*
|
||||
* @param string $cd_remote
|
||||
*
|
||||
* @return \Consolidation\SiteProcess\SiteProcess
|
||||
*/
|
||||
public function setWorkingDirectory($cd_remote)
|
||||
{
|
||||
$this->cd_remote = $cd_remote;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a starting directory for the initial/local process.
|
||||
*
|
||||
* @param string $cd
|
||||
*
|
||||
* @return \Consolidation\SiteProcess\SiteProcess
|
||||
*/
|
||||
public function setWorkingDirectoryLocal($cd)
|
||||
{
|
||||
// Symfony 4 REQUIRES that there be a directory set, and defaults
|
||||
// it to the cwd if it is not set. We will maintain that pattern here.
|
||||
if (!$cd) {
|
||||
$cd = getcwd();
|
||||
}
|
||||
return parent::setWorkingDirectory($cd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the starting directory for the initial/local process.
|
||||
*
|
||||
* @return string|null;
|
||||
*/
|
||||
public function getWorkingDirectoryLocal()
|
||||
{
|
||||
return parent::getWorkingDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bool $shouldUseSiteRoot
|
||||
* @return $this|\Symfony\Component\Process\Process
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function chdirToSiteRoot($shouldUseSiteRoot = true)
|
||||
{
|
||||
if (!$shouldUseSiteRoot || !$this->siteAlias->hasRoot()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->setWorkingDirectory($this->siteAlias->root());
|
||||
}
|
||||
|
||||
/**
|
||||
* Take all of our individual arguments and process them for use.
|
||||
*/
|
||||
protected function processArgs()
|
||||
{
|
||||
$transport = $this->getTransport($this->siteAlias);
|
||||
$transport->configure($this);
|
||||
|
||||
$processor = new ArgumentProcessor();
|
||||
$selectedArgs = $processor->selectArgs(
|
||||
$this->siteAlias,
|
||||
$this->args,
|
||||
$this->options,
|
||||
$this->optionsPassedAsArgs
|
||||
);
|
||||
|
||||
// Set environment variables if needed.
|
||||
if ($this->siteAlias->has('env-vars')) {
|
||||
$selectedArgs = $this->addEnvVars($this->siteAlias->get('env-vars'), $selectedArgs);
|
||||
}
|
||||
|
||||
// Ask the transport to drop in a 'cd' if needed.
|
||||
if ($this->getWorkingDirectory()) {
|
||||
$selectedArgs = $transport->addChdir($this->getWorkingDirectory(), $selectedArgs);
|
||||
}
|
||||
|
||||
// Do any necessary interpolation on the selected arguments.
|
||||
$processedArgs = $this->interpolate($selectedArgs);
|
||||
|
||||
// Wrap the command with 'ssh' or some other transport if this is
|
||||
// a remote command; otherwise, leave it as-is.
|
||||
return $transport->wrap($processedArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the command/args in an env call.
|
||||
* @todo Check if this needs to depend on linux/win.
|
||||
* @todo Check if this needs to be delegated to transport.
|
||||
*/
|
||||
public function addEnvVars($envVars, $args)
|
||||
{
|
||||
$envArgs = ['env'];
|
||||
foreach ($envVars as $key => $value) {
|
||||
$envArgs[] = Escape::forSite($this->siteAlias, $key) . '='
|
||||
. Escape::forSite($this->siteAlias, $value);
|
||||
}
|
||||
return array_merge($envArgs, $args);
|
||||
}
|
||||
|
||||
public function setTransport($transport)
|
||||
{
|
||||
$this->transport = $transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the transport manager for the correct transport for the
|
||||
* provided alias.
|
||||
*/
|
||||
protected function getTransport(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
return $this->transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCommandLine()
|
||||
{
|
||||
$commandLine = parent::getCommandLine();
|
||||
if (empty($commandLine)) {
|
||||
$processedArgs = $this->processArgs();
|
||||
$commandLine = Escape::argsForSite($this->siteAlias, $processedArgs);
|
||||
$commandLine = implode(' ', $commandLine);
|
||||
$this->overrideCommandLine($commandLine);
|
||||
}
|
||||
return $commandLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function start(callable $callback = null, array $env = [])
|
||||
{
|
||||
$cmd = $this->getCommandLine();
|
||||
parent::start($callback, $env);
|
||||
}
|
||||
|
||||
public function mustRun(callable $callback = null, array $env = []): \Symfony\Component\Process\Process
|
||||
{
|
||||
if (0 !== $this->run($callback, $env)) {
|
||||
// Be less verbose when there is nothing in stdout or stderr.
|
||||
if (empty($this->getOutput()) && empty($this->getErrorOutput())) {
|
||||
$this->disableOutput();
|
||||
}
|
||||
throw new ProcessFailedException($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function wait(callable $callback = null)
|
||||
{
|
||||
$return = parent::wait($callback);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* interpolate examines each of the arguments in the provided argument list
|
||||
* and replaces any token found therein with the value for that key as
|
||||
* pulled from the given site alias.
|
||||
*
|
||||
* Example: "git -C {{root}} status"
|
||||
*
|
||||
* The token "{{root}}" will be converted to a value via $siteAlias->get('root').
|
||||
* The result will replace the token.
|
||||
*
|
||||
* It is possible to use dot notation in the keys to access nested elements
|
||||
* within the site alias record.
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias
|
||||
* @param type $args
|
||||
* @return type
|
||||
*/
|
||||
protected function interpolate($args)
|
||||
{
|
||||
$interpolator = new Interpolator();
|
||||
return array_map(
|
||||
function ($arg) use ($interpolator) {
|
||||
if ($arg instanceof ShellOperatorInterface) {
|
||||
return $arg;
|
||||
}
|
||||
return $interpolator->interpolate($this->siteAlias, $arg, false);
|
||||
},
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the command line to be executed.
|
||||
*
|
||||
* @param string|array $commandline The command to execute
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @todo refactor library so this hack to get around changes in
|
||||
* symfony/process 5 is unnecessary.
|
||||
*/
|
||||
private function overrideCommandLine($commandline)
|
||||
{
|
||||
$commandlineSetter = function ($commandline) {
|
||||
$this->commandline = $commandline;
|
||||
};
|
||||
$commandlineSetter->bindTo($this, Process::class)($commandline);
|
||||
return $this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Util\Shell;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
|
||||
/**
|
||||
* DockerComposeTransport knows how to wrap a command such that it executes
|
||||
* on a Docker Compose service.
|
||||
*/
|
||||
class DockerComposeTransport implements TransportInterface
|
||||
{
|
||||
protected $tty;
|
||||
protected $siteAlias;
|
||||
protected $cd_remote;
|
||||
|
||||
public function __construct(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
$this->siteAlias = $siteAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function configure(SiteProcess $process)
|
||||
{
|
||||
$this->tty = $process->isTty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function wrap($args)
|
||||
{
|
||||
$transport = $this->getTransport();
|
||||
$transportOptions = $this->getTransportOptions();
|
||||
$commandToExecute = $this->getCommandToExecute($args);
|
||||
|
||||
return array_merge(
|
||||
$transport,
|
||||
$transportOptions,
|
||||
$commandToExecute
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addChdir($cd, $args)
|
||||
{
|
||||
$this->cd_remote = $cd;
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransport returns the transport along with the docker-compose
|
||||
* project in case it is defined.
|
||||
*/
|
||||
protected function getTransport()
|
||||
{
|
||||
$transport = ['docker-compose'];
|
||||
$project = $this->siteAlias->get('docker.project', '');
|
||||
$options = $this->siteAlias->get('docker.compose.options', '');
|
||||
if ($project && (strpos($options, '-p') === false || strpos($options, '--project') === false)) {
|
||||
$transport = array_merge($transport, ['-p', $project]);
|
||||
}
|
||||
if ($options) {
|
||||
$transport[] = Shell::preEscaped($options);
|
||||
}
|
||||
return array_merge($transport, ['exec']);
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransportOptions returns the transport options for the tranport
|
||||
* mechanism itself
|
||||
*/
|
||||
protected function getTransportOptions()
|
||||
{
|
||||
$transportOptions = [
|
||||
$this->siteAlias->get('docker.service', ''),
|
||||
];
|
||||
if ($options = $this->siteAlias->get('docker.exec.options', '')) {
|
||||
array_unshift($transportOptions, Shell::preEscaped($options));
|
||||
}
|
||||
if (!$this->tty) {
|
||||
array_unshift($transportOptions, '-T');
|
||||
}
|
||||
if ($this->cd_remote) {
|
||||
$transportOptions = array_merge(['--workdir', $this->cd_remote], $transportOptions);
|
||||
}
|
||||
return array_filter($transportOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* getCommandToExecute processes the arguments for the command to
|
||||
* be executed such that they are appropriate for the transport mechanism.
|
||||
*
|
||||
* Nothing to do for this transport.
|
||||
*/
|
||||
protected function getCommandToExecute($args)
|
||||
{
|
||||
return $args;
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Util\Shell;
|
||||
|
||||
/**
|
||||
* KubectlTransport knows how to wrap a command such that it runs in a container
|
||||
* on Kubernetes via kubectl.
|
||||
*/
|
||||
class KubectlTransport implements TransportInterface
|
||||
{
|
||||
/** @var bool */
|
||||
protected $tty;
|
||||
|
||||
/** @var \Consolidation\SiteAlias\SiteAliasInterface */
|
||||
protected $siteAlias;
|
||||
|
||||
public function __construct(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
$this->siteAlias = $siteAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function configure(SiteProcess $process)
|
||||
{
|
||||
$this->tty = $process->isTty();
|
||||
}
|
||||
|
||||
/**
|
||||
* inheritdoc
|
||||
*/
|
||||
public function wrap($args)
|
||||
{
|
||||
# TODO: How/where do we complain if a required argument is not available?
|
||||
$namespace = $this->siteAlias->get('kubectl.namespace');
|
||||
$tty = $this->tty && $this->siteAlias->get('kubectl.tty', false) ? "true" : "false";
|
||||
$interactive = $this->tty && $this->siteAlias->get('kubectl.interactive', false) ? "true" : "false";
|
||||
$resource = $this->siteAlias->get('kubectl.resource');
|
||||
$container = $this->siteAlias->get('kubectl.container');
|
||||
|
||||
$transport = [
|
||||
'kubectl',
|
||||
"--namespace=$namespace",
|
||||
'exec',
|
||||
"--tty=$tty",
|
||||
"--stdin=$interactive",
|
||||
$resource,
|
||||
];
|
||||
if ($container) {
|
||||
$transport[] = "--container=$container";
|
||||
}
|
||||
$transport[] = "--";
|
||||
|
||||
return array_merge($transport, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addChdir($cd_remote, $args)
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'cd',
|
||||
$cd_remote,
|
||||
Shell::op('&&'),
|
||||
],
|
||||
$args
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
|
||||
/**
|
||||
* LocalTransport just runs the command on the local system.
|
||||
*/
|
||||
class LocalTransport implements TransportInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function configure(SiteProcess $process)
|
||||
{
|
||||
$process->setWorkingDirectoryLocal($process->getWorkingDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function wrap($args)
|
||||
{
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addChdir($cd, $args)
|
||||
{
|
||||
return $args;
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Util\Shell;
|
||||
use Consolidation\Config\ConfigInterface;
|
||||
|
||||
/**
|
||||
* SshTransport knows how to wrap a command such that it runs on a remote
|
||||
* system via the ssh cli.
|
||||
*/
|
||||
class SshTransport implements TransportInterface
|
||||
{
|
||||
protected $tty;
|
||||
protected $siteAlias;
|
||||
|
||||
public function __construct(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
$this->siteAlias = $siteAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function configure(SiteProcess $process)
|
||||
{
|
||||
$this->tty = $process->isTty();
|
||||
}
|
||||
|
||||
/**
|
||||
* inheritdoc
|
||||
*/
|
||||
public function wrap($args)
|
||||
{
|
||||
$transport = ['ssh'];
|
||||
$transportOptions = $this->getTransportOptions();
|
||||
$commandToExecute = $this->getCommandToExecute($args);
|
||||
|
||||
return array_merge(
|
||||
$transport,
|
||||
$transportOptions,
|
||||
$commandToExecute
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addChdir($cd_remote, $args)
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'cd',
|
||||
$cd_remote,
|
||||
Shell::op('&&'),
|
||||
],
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransportOptions returns the transport options for the tranport
|
||||
* mechanism itself
|
||||
*/
|
||||
protected function getTransportOptions()
|
||||
{
|
||||
$transportOptions = [
|
||||
Shell::preEscaped($this->siteAlias->get('ssh.options', '-o PasswordAuthentication=no')),
|
||||
$this->siteAlias->remoteHostWithUser(),
|
||||
];
|
||||
if ($this->tty) {
|
||||
array_unshift($transportOptions, '-t');
|
||||
}
|
||||
return $transportOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCommandToExecute processes the arguments for the command to
|
||||
* be executed such that they are appropriate for the transport mechanism.
|
||||
*/
|
||||
protected function getCommandToExecute($args)
|
||||
{
|
||||
// Escape each argument for the target system and then join
|
||||
$args = Escape::argsForSite($this->siteAlias, $args);
|
||||
$commandToExecute = implode(' ', $args);
|
||||
|
||||
return [$commandToExecute];
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
|
||||
/**
|
||||
* Transports know how to wrap a command such that it runs on a remote system
|
||||
* via some other command.
|
||||
*
|
||||
* There is always a transport for every factory, and visa-versa.
|
||||
*
|
||||
* @see Consolidation\SiteProcess\Factory\TransportFactoryInterface
|
||||
*/
|
||||
interface TransportInterface
|
||||
{
|
||||
/**
|
||||
* Configure ourselves based on the settings of the process object
|
||||
* (e.g. isTty()).
|
||||
*
|
||||
* @param \Consolidation\SiteProcess\SiteProcess $process
|
||||
*/
|
||||
public function configure(SiteProcess $process);
|
||||
|
||||
/**
|
||||
* wrapWithTransport examines the provided site alias; if it is a local
|
||||
* alias, then the provided arguments are returned unmodified. If the
|
||||
* alias points at a remote system, though, then the arguments are
|
||||
* escaped and wrapped in an appropriate ssh command.
|
||||
*
|
||||
* @param array $args arguments provided by caller.
|
||||
* @return array command and arguments to execute.
|
||||
*/
|
||||
public function wrap($args);
|
||||
|
||||
/**
|
||||
* addChdir adds an appropriate 'chdir' / 'cd' command for the transport.
|
||||
*/
|
||||
public function addChdir($cd, $args);
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess\Transport;
|
||||
|
||||
use Consolidation\SiteProcess\SiteProcess;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Consolidation\SiteProcess\Util\Shell;
|
||||
|
||||
/**
|
||||
* VagrantTransport knows how to wrap a command such that it runs on a remote
|
||||
* system via the vagrant cli.
|
||||
*/
|
||||
class VagrantTransport implements TransportInterface
|
||||
{
|
||||
protected $tty;
|
||||
protected $siteAlias;
|
||||
|
||||
public function __construct(SiteAliasInterface $siteAlias)
|
||||
{
|
||||
$this->siteAlias = $siteAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function configure(SiteProcess $process)
|
||||
{
|
||||
$this->tty = $process->isTty();
|
||||
}
|
||||
|
||||
/**
|
||||
* inheritdoc
|
||||
*/
|
||||
public function wrap($args)
|
||||
{
|
||||
$transport = ['vagrant', 'ssh'];
|
||||
$transportOptions = $this->getTransportOptions();
|
||||
$commandToExecute = $this->getCommandToExecute($args);
|
||||
|
||||
return array_merge(
|
||||
$transport,
|
||||
$transportOptions,
|
||||
['-c'],
|
||||
$commandToExecute
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addChdir($cd_remote, $args)
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'cd',
|
||||
$cd_remote,
|
||||
Shell::op('&&'),
|
||||
],
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransportOptions returns the transport options for the tranport
|
||||
* mechanism itself
|
||||
*/
|
||||
protected function getTransportOptions()
|
||||
{
|
||||
return $this->tty ? ['-t'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* getCommandToExecute processes the arguments for the command to
|
||||
* be executed such that they are appropriate for the transport mechanism.
|
||||
*/
|
||||
protected function getCommandToExecute($args)
|
||||
{
|
||||
// Escape each argument for the target system and then join
|
||||
$args = Escape::argsForSite($this->siteAlias, $args);
|
||||
$commandToExecute = implode(' ', $args);
|
||||
|
||||
return [$commandToExecute];
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Consolidation\SiteProcess\Transport\TransportInterface;
|
||||
|
||||
/**
|
||||
* ArgumentProcessor takes a set of arguments and options from the caller
|
||||
* and processes them with the provided site alias to produce a final
|
||||
* executable command that will run either locally or on a remote system,
|
||||
* as applicable.
|
||||
*/
|
||||
class ArgumentProcessor
|
||||
{
|
||||
/**
|
||||
* selectArgs selects the appropriate set of arguments for the command
|
||||
* to be executed and orders them as needed.
|
||||
*
|
||||
* @param SiteAliasInterface $siteAlias Description of
|
||||
* @param array $args Command and arguments to execute (source)
|
||||
* @param array $options key / value pair of option and value in include
|
||||
* in final arguments
|
||||
* @param array $optionsPassedAsArgs key / value pair of option and value
|
||||
* to include in final arguments after the '--' argument.
|
||||
* @return array Command and arguments to execute
|
||||
*/
|
||||
public function selectArgs(SiteAliasInterface $siteAlias, $args, $options = [], $optionsPassedAsArgs = [])
|
||||
{
|
||||
// Split args into three arrays separated by the `--`
|
||||
list($leadingArgs, $dashDash, $remaingingArgs) = $this->findArgSeparator($args);
|
||||
$convertedOptions = $this->convertOptions($options);
|
||||
$convertedOptionsPassedAsArgs = $this->convertOptions($optionsPassedAsArgs);
|
||||
|
||||
// If the caller provided options that should be passed as args, then we
|
||||
// always need a `--`, whether or not one existed to begin with in $args
|
||||
if (!empty($convertedOptionsPassedAsArgs)) {
|
||||
$dashDash = ['--'];
|
||||
}
|
||||
|
||||
// Combine our separated args in the correct order. $dashDash will
|
||||
// always be `['--']` if $optionsPassedAsArgs or $remaingingArgs are
|
||||
// not empty, and otherwise will usually be empty.
|
||||
return array_merge(
|
||||
$leadingArgs,
|
||||
$convertedOptions,
|
||||
$dashDash,
|
||||
$convertedOptionsPassedAsArgs,
|
||||
$remaingingArgs
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* findArgSeparator finds the "--" argument in the provided arguments list,
|
||||
* if present, and returns the arguments in three sets.
|
||||
*
|
||||
* @return array of three arrays, leading, "--" and trailing
|
||||
*/
|
||||
protected function findArgSeparator($args)
|
||||
{
|
||||
$pos = array_search('--', $args);
|
||||
if ($pos === false) {
|
||||
return [$args, [], []];
|
||||
}
|
||||
|
||||
return [
|
||||
array_slice($args, 0, $pos),
|
||||
['--'],
|
||||
array_slice($args, $pos + 1),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* convertOptions takes an associative array of options (key / value) and
|
||||
* converts it to an array of strings in the form --key=value.
|
||||
*
|
||||
* @param array $options in key => value form
|
||||
* @return array options in --option=value form
|
||||
*/
|
||||
protected function convertOptions($options)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($options as $option => $value) {
|
||||
if ($value === true || $value === null) {
|
||||
$result[] = "--$option";
|
||||
} elseif ($value === false) {
|
||||
// Ignore this option.
|
||||
} else {
|
||||
$result[] = "--{$option}={$value}";
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
145
old.vendor/consolidation/site-process/src/Util/Escape.php
Normal file
145
old.vendor/consolidation/site-process/src/Util/Escape.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
use Consolidation\SiteAlias\SiteAliasInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Consolidation\Config\Util\Interpolator;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Consolidation\SiteProcess\Util\ShellOperatorInterface;
|
||||
|
||||
/**
|
||||
* Escape will shell-escape commandline arguments for different platforms.
|
||||
*/
|
||||
class Escape
|
||||
{
|
||||
/**
|
||||
* argsForSite escapes each argument in an array for the given site.
|
||||
*/
|
||||
public static function argsForSite(SiteAliasInterface $siteAlias, $args)
|
||||
{
|
||||
return array_map(
|
||||
function ($arg) use ($siteAlias) {
|
||||
return Escape::forSite($siteAlias, $arg);
|
||||
},
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* forSite escapes the provided argument for the specified alias record.
|
||||
*/
|
||||
public static function forSite(SiteAliasInterface $siteAlias, $arg)
|
||||
{
|
||||
return static::shellArg($arg, $siteAlias->os());
|
||||
}
|
||||
|
||||
/**
|
||||
* shellArg escapes the provided argument for the specified OS
|
||||
*
|
||||
* @param string|ShellOperatorInterface $arg The argument to escape
|
||||
* @param string|null $os The OS to escape for. Optional; defaults to LINUX
|
||||
*
|
||||
* @return string The escaped string
|
||||
*/
|
||||
public static function shellArg($arg, $os = null)
|
||||
{
|
||||
// Short-circuit escaping for simple params (keep stuff readable);
|
||||
// also skip escaping for shell operators (e.g. &&), which must not
|
||||
// be escaped.
|
||||
if (($arg instanceof ShellOperatorInterface) || preg_match('|^[a-zA-Z0-9@=.:/_-]*$|', $arg)) {
|
||||
return (string) $arg;
|
||||
}
|
||||
|
||||
if (static::isWindows($os)) {
|
||||
return static::windowsArg($arg);
|
||||
}
|
||||
return static::linuxArg($arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* isWindows determines whether the provided OS is Windows.
|
||||
*
|
||||
* @param string|null $os The OS to escape for.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isWindows($os = null)
|
||||
{
|
||||
// In most cases, $os will be NULL and PHP_OS will be returned. However,
|
||||
// if an OS is specified in $os, return that instead.
|
||||
$os = $os ?: PHP_OS;
|
||||
return strtoupper(substr($os, 0, 3)) === 'WIN';
|
||||
}
|
||||
|
||||
/**
|
||||
* linuxArg is the Linux version of escapeshellarg().
|
||||
*
|
||||
* This is intended to work the same way that escapeshellarg() does on
|
||||
* Linux. If we need to escape a string that will be used remotely on
|
||||
* a Linux system, then we need our own implementation of escapeshellarg,
|
||||
* because the Windows version behaves differently.
|
||||
*
|
||||
* Note that we behave somewhat differently than the built-in escapeshellarg()
|
||||
* with respect to whitespace replacement in order
|
||||
*
|
||||
* @param string $arg The argument to escape
|
||||
*
|
||||
* @return string The escaped string
|
||||
*/
|
||||
public static function linuxArg($arg)
|
||||
{
|
||||
// For single quotes existing in the string, we will "exit"
|
||||
// single-quote mode, add a \' and then "re-enter"
|
||||
// single-quote mode. The result of this is that
|
||||
// 'quote' becomes '\''quote'\''
|
||||
$arg = preg_replace('/\'/', '\'\\\'\'', $arg);
|
||||
|
||||
// Replace "\t", "\n", "\r", "\0", "\x0B" with a whitespace.
|
||||
// Note that this replacement makes Drush's escapeshellarg work differently
|
||||
// than the built-in escapeshellarg in PHP on Linux, as these characters
|
||||
// usually are NOT replaced. However, this was done deliberately to be more
|
||||
// conservative when running _drush_escapeshellarg_linux on Windows
|
||||
// (this can happen when generating a command to run on a remote Linux server.)
|
||||
//
|
||||
// TODO: Perhaps we should only do this if the local system is Windows?
|
||||
// n.b. that would be a little more complicated to test.
|
||||
$arg = str_replace(["\t", "\n", "\r", "\0", "\x0B"], ' ', $arg);
|
||||
|
||||
// Add surrounding quotes.
|
||||
$arg = "'" . $arg . "'";
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* windowsArg is the Windows version of escapeshellarg().
|
||||
*
|
||||
* @param string $arg The argument to escape
|
||||
*
|
||||
* @return string The escaped string
|
||||
*/
|
||||
public static function windowsArg($arg)
|
||||
{
|
||||
if ('' === $arg || null === $arg) {
|
||||
return '""';
|
||||
}
|
||||
if (false !== strpos($arg, "\0")) {
|
||||
$arg = str_replace("\0", '?', $arg);
|
||||
}
|
||||
if (!preg_match('/[\/()%!^"<>&|\s]/', $arg)) {
|
||||
return $arg;
|
||||
}
|
||||
// Double up existing backslashes
|
||||
$arg = preg_replace('/(\\\\+)$/', '$1$1', $arg);
|
||||
|
||||
// Replacing whitespace for good measure (see comment above).
|
||||
$arg = str_replace(["\t", "\n", "\r", "\0", "\x0B"], ' ', $arg);
|
||||
|
||||
$arg = str_replace(['"', '^', '%', '!'], ['""', '"^^"', '"^%"', '"^!"'], $arg);
|
||||
|
||||
// Add surrounding quotes.
|
||||
$arg = '"' . $arg . '"';
|
||||
|
||||
return $arg;
|
||||
}
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Consolidation\Config\Util\Interpolator;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
||||
/**
|
||||
* RealtimeOutput can be provided to a process object when you want
|
||||
* to display the output of the running command as it is being produced.
|
||||
*/
|
||||
class RealtimeOutputHandler
|
||||
{
|
||||
protected $stdout;
|
||||
protected $stderr;
|
||||
protected $stdoutMarker = '';
|
||||
protected $stderrMarker = '';
|
||||
|
||||
/**
|
||||
* Provide the output streams to use for stdout and stderr
|
||||
*/
|
||||
const MARKER_ERR = '> ';
|
||||
|
||||
public function __construct(OutputInterface $stdout, OutputInterface $stderr)
|
||||
{
|
||||
$this->stdout = $stdout;
|
||||
$this->stderr = $stderr;
|
||||
|
||||
$this->stdoutMarker = '';
|
||||
$this->stderrMarker = self::MARKER_ERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gives us an opportunity to adapt to the settings of the
|
||||
* process object (e.g. do we need to do anything differently if
|
||||
* it is in tty mode, etc.)
|
||||
*/
|
||||
public function configure(Process $process)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setStderrMarker defines the string that should be added at
|
||||
* the beginning of every line of stderr that is printed.
|
||||
*/
|
||||
public function setStderrMarker($marker)
|
||||
{
|
||||
$this->stderrMarker = $marker;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setStdoutMarker defines the string that should be added at
|
||||
* the beginning of every line of stdout that is printed.
|
||||
*/
|
||||
public function setStdoutMarker($marker)
|
||||
{
|
||||
$this->stdoutMarker = $marker;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* hideStdout overrides whatever was formerly stored in $this->stdout
|
||||
* with a null output buffer so that none of the standard output data
|
||||
* is visible.
|
||||
*/
|
||||
public function hideStdout()
|
||||
{
|
||||
$this->stdout = new NullOutput();
|
||||
$this->stdoutMarker = '';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* hideStderr serves the same function as hideStdout, but for the
|
||||
* standard error stream. Note that it is not useful to unconditionally
|
||||
* call both hideStdout and hideStderr; if no output is desired, then
|
||||
* the RealtimeOutputHandler should not be used.
|
||||
*/
|
||||
public function hideStderr()
|
||||
{
|
||||
$this->stderr = new NullOutput();
|
||||
$this->stderrMarker = '';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this object is used as a callable, then run 'handleOutput'.
|
||||
*/
|
||||
public function __invoke($type, $buffer)
|
||||
{
|
||||
$this->handleOutput($type, $buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method when you want real-time output from a Process call.
|
||||
* @param string $type
|
||||
* @param string $buffer
|
||||
*/
|
||||
public function handleOutput($type, $buffer)
|
||||
{
|
||||
if (Process::ERR === $type) {
|
||||
$this->stderr->write($this->addMarker($buffer, $this->stderrMarker), false, OutputInterface::OUTPUT_RAW);
|
||||
} else {
|
||||
$this->stdout->write($this->addMarker($buffer, $this->stdoutMarker), false, OutputInterface::OUTPUT_RAW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that every line in $buffer begins with a MARKER_ERR.
|
||||
*/
|
||||
protected function addMarker($buffer, $marker)
|
||||
{
|
||||
// Exit early if there is no marker to add
|
||||
if (empty($marker)) {
|
||||
return $buffer;
|
||||
}
|
||||
// Add a marker on the beginning of every line.
|
||||
return $marker . rtrim(implode("\n" . $marker, explode("\n", $buffer)), $marker);
|
||||
}
|
||||
}
|
52
old.vendor/consolidation/site-process/src/Util/Shell.php
Normal file
52
old.vendor/consolidation/site-process/src/Util/Shell.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
/**
|
||||
* Shell::op is a static factory that will create shell operators for use
|
||||
* in command line arguments list. Shell operators are characters that have
|
||||
* special meaning to the shell, such as "output redirection". When a shell
|
||||
* operator object is used, it indicates that this element is intended to
|
||||
* be used as an operator, and is not simply some other parameter to be escaped.
|
||||
*/
|
||||
class Shell implements ShellOperatorInterface
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public static function op($operator)
|
||||
{
|
||||
static::validateOp($operator);
|
||||
return new self($operator);
|
||||
}
|
||||
|
||||
public static function preEscaped($value)
|
||||
{
|
||||
return new self($value);
|
||||
}
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
protected static function validateOp($operator)
|
||||
{
|
||||
$valid = [
|
||||
'&&',
|
||||
'||',
|
||||
'|',
|
||||
'<',
|
||||
'>',
|
||||
'>>',
|
||||
';',
|
||||
];
|
||||
|
||||
if (!in_array($operator, $valid)) {
|
||||
throw new \Exception($operator . ' is not a valid shell operator.');
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
/**
|
||||
* ShellOperatorInterface is a marker interface indicating that the object
|
||||
* represents a shell operator.
|
||||
*/
|
||||
interface ShellOperatorInterface
|
||||
{
|
||||
}
|
27
old.vendor/consolidation/site-process/src/Util/Tty.php
Normal file
27
old.vendor/consolidation/site-process/src/Util/Tty.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Consolidation\SiteProcess\Util;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Wrapper for universal support of TTY-related functionality across versions of
|
||||
* Symfony Process.
|
||||
*/
|
||||
class Tty
|
||||
{
|
||||
/**
|
||||
* In Symfony Process 4+, this is simply a wrapper for Process::isTtySupported().
|
||||
* In lower versions, it mimics the same functionality.
|
||||
*/
|
||||
public static function isTtySupported()
|
||||
{
|
||||
// Start off by checking STDIN with `posix_isatty`, as that appears to be more reliable
|
||||
if (function_exists('posix_isatty')) {
|
||||
return posix_isatty(STDIN);
|
||||
}
|
||||
if (method_exists('\Symfony\Component\Process\Process', 'isTtySupported')) {
|
||||
return Process::isTtySupported();
|
||||
}
|
||||
return (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
|
||||
class ArgumentProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testArgumentProcessor.
|
||||
*/
|
||||
public function argumentProcessorTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'["ls", "-al"]',
|
||||
[],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
],
|
||||
|
||||
[
|
||||
'["drush", "status", "--fields=root,uri"]',
|
||||
[],
|
||||
['drush', 'status'],
|
||||
['fields' => 'root,uri'],
|
||||
[],
|
||||
],
|
||||
|
||||
[
|
||||
'["drush", "rsync", "a", "b", "--", "--exclude=vendor"]',
|
||||
[],
|
||||
['drush', 'rsync', 'a', 'b',],
|
||||
[],
|
||||
['exclude' => 'vendor'],
|
||||
],
|
||||
|
||||
[
|
||||
'["drush", "rsync", "a", "b", "--", "--exclude=vendor", "--include=vendor/autoload.php"]',
|
||||
[],
|
||||
['drush', 'rsync', 'a', 'b', '--', '--include=vendor/autoload.php'],
|
||||
[],
|
||||
['exclude' => 'vendor'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the SiteProcess class.
|
||||
*
|
||||
* @dataProvider argumentProcessorTestValues
|
||||
*/
|
||||
public function testArgumentProcessor(
|
||||
$expected,
|
||||
$siteAliasData,
|
||||
$args,
|
||||
$options,
|
||||
$optionsPassedAsArgs)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$processor = new ArgumentProcessor();
|
||||
|
||||
$actual = $processor->selectArgs($siteAlias, $args, $options, $optionsPassedAsArgs);
|
||||
$actual = '["' . implode('", "', $actual) . '"]';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
173
old.vendor/consolidation/site-process/tests/EscapeTest.php
Normal file
173
old.vendor/consolidation/site-process/tests/EscapeTest.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
|
||||
class EscapeTest extends TestCase
|
||||
{
|
||||
const DEFAULT_SITE_ALIAS = ['host' => 'example.com', ];
|
||||
const LINUX_SITE_ALIAS = ['host' => 'example.com', 'os' => 'Linux'];
|
||||
const WINDOWS_SITE_ALIAS = ['host' => 'example.com', 'os' => 'WIN'];
|
||||
|
||||
/**
|
||||
* Data provider for testIsWindows.
|
||||
*/
|
||||
public function isWindowsTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'Linux',
|
||||
false,
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'Linux',
|
||||
false,
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'WIN',
|
||||
true,
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the isWindows method.
|
||||
*
|
||||
* @dataProvider isWindowsTestValues
|
||||
*/
|
||||
public function testIsWindows(
|
||||
$expected,
|
||||
$expectToBeWindows,
|
||||
$siteAliasData)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$actual = $siteAlias->os();
|
||||
$this->assertEquals($expected, $actual);
|
||||
$actuallyIsWindows = Escape::isWindows($siteAlias->os());
|
||||
$this->assertEquals($expectToBeWindows, $actuallyIsWindows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testEscapeForSite.
|
||||
*/
|
||||
public function escapeForSiteTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'foo',
|
||||
'foo',
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'foo',
|
||||
'foo',
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'foo',
|
||||
'foo',
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'foo bar'",
|
||||
'foo bar',
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'foo bar'",
|
||||
'foo bar',
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'"foo bar"',
|
||||
'foo bar',
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'don'\\''t forget'",
|
||||
"don't forget",
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'don'\\''t forget'",
|
||||
"don't forget",
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'"don\'t forget"',
|
||||
"don't forget",
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'I'\''ll try the \"easy\" fix.'",
|
||||
"I'll try the \"easy\" fix.",
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'I'\''ll try the \"easy\" fix.'",
|
||||
"I'll try the \"easy\" fix.",
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'"I\'ll try the ""easy"" fix."',
|
||||
"I'll try the \"easy\" fix.",
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'a b'",
|
||||
"a\tb",
|
||||
static::DEFAULT_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
"'a b'",
|
||||
"a\tb",
|
||||
static::LINUX_SITE_ALIAS,
|
||||
],
|
||||
|
||||
[
|
||||
'"a b"',
|
||||
"a\tb",
|
||||
static::WINDOWS_SITE_ALIAS,
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the forSite method.
|
||||
*
|
||||
* @dataProvider escapeForSiteTestValues
|
||||
*/
|
||||
public function testEscapeForSite(
|
||||
$expected,
|
||||
$arg,
|
||||
$siteAliasData)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
|
||||
$actual = Escape::forSite($siteAlias, $arg);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
||||
class RealtimeOutputHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testRealtimeOutputHandler.
|
||||
*/
|
||||
public function realtimeOutputHandlerTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'hello, world',
|
||||
'',
|
||||
['echo', 'hello, world'],
|
||||
'LINUX',
|
||||
],
|
||||
|
||||
[
|
||||
'"hello, world"',
|
||||
'',
|
||||
['echo', 'hello, world'],
|
||||
'WIN'
|
||||
],
|
||||
|
||||
[
|
||||
'README.md',
|
||||
'',
|
||||
['ls', 'README.md'],
|
||||
'LINUX',
|
||||
],
|
||||
|
||||
[
|
||||
'',
|
||||
'No such file or directory',
|
||||
['ls', 'no/such/file'],
|
||||
'LINUX',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the RealtimeOutputHandler class.
|
||||
*
|
||||
* @dataProvider realtimeOutputHandlerTestValues
|
||||
*/
|
||||
public function testRealtimeOutputHandler($expectedStdout, $expectedStderr, $args, $os)
|
||||
{
|
||||
if (Escape::isWindows() != Escape::isWindows($os)) {
|
||||
$this->markTestSkipped("OS isn't supported");
|
||||
}
|
||||
$stdin = new ArrayInput([]);
|
||||
$stdout = new BufferedOutput();
|
||||
$stderr = new BufferedOutput();
|
||||
$symfonyStyle = new SymfonyStyle($stdin, $stdout);
|
||||
|
||||
$process = new ProcessBase($args);
|
||||
$process->setRealtimeOutput($symfonyStyle, $stderr);
|
||||
$process->run($process->showRealtime());
|
||||
|
||||
$this->assertEquals($expectedStdout, trim($stdout->fetch()));
|
||||
if (empty($expectedStderr)) {
|
||||
$this->assertEquals('', trim($stderr->fetch()));
|
||||
}
|
||||
else {
|
||||
$this->assertStringContainsString($expectedStderr, trim($stderr->fetch()));
|
||||
}
|
||||
}
|
||||
}
|
307
old.vendor/consolidation/site-process/tests/SiteProcessTest.php
Normal file
307
old.vendor/consolidation/site-process/tests/SiteProcessTest.php
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
||||
use Consolidation\SiteProcess\Util\Escape;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
|
||||
class SiteProcessTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testSiteProcess.
|
||||
*/
|
||||
public function siteProcessTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
"ls -al",
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ls -al",
|
||||
'src',
|
||||
false,
|
||||
[],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ls -al /path1 /path2",
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['ls', '-al', '/path1', '/path2'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -o PasswordAuthentication=no www-admin@server.net 'ls -al'",
|
||||
false,
|
||||
false,
|
||||
['host' => 'server.net', 'user' => 'www-admin'],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -o PasswordAuthentication=no www-admin@server.net 'cd /srv/www/docroot && ls -al'",
|
||||
false,
|
||||
false,
|
||||
['host' => 'server.net', 'user' => 'www-admin', 'root' => '/srv/www/docroot'],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -o PasswordAuthentication=no www-admin@server.net 'cd src && ls -al'",
|
||||
'src',
|
||||
false,
|
||||
['host' => 'server.net', 'user' => 'www-admin'],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -t -o PasswordAuthentication=no www-admin@server.net 'ls -al'",
|
||||
false,
|
||||
true,
|
||||
['host' => 'server.net', 'user' => 'www-admin'],
|
||||
['ls', '-al'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -t -o PasswordAuthentication=no www-admin@server.net 'cd src && ls -al /path1 /path2'",
|
||||
'src',
|
||||
true,
|
||||
['host' => 'server.net', 'user' => 'www-admin'],
|
||||
['ls', '-al', '/path1', '/path2'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"ssh -t -o PasswordAuthentication=no www-admin@server.net 'cd src && ls -al /path1 /path2'",
|
||||
'src',
|
||||
true,
|
||||
['host' => 'server.net', 'user' => 'www-admin'],
|
||||
['ls', '-al', '/path1', '/path2'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"docker-compose exec --workdir src --user root drupal ls -al /path1 /path2",
|
||||
'src',
|
||||
true,
|
||||
['docker' => ['service' => 'drupal', 'exec' => ['options' => '--user root']]],
|
||||
['ls', '-al', '/path1', '/path2'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"docker-compose -p project exec --workdir src --user root drupal ls -al /path1 /path2",
|
||||
'src',
|
||||
true,
|
||||
['docker' => ['service' => 'drupal', 'project' => 'project', 'exec' => ['options' => '--user root']]],
|
||||
['ls', '-al', '/path1', '/path2'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"drush status '--fields=root,uri'",
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['drush', 'status'],
|
||||
['fields' => 'root,uri'],
|
||||
[],
|
||||
'LINUX',
|
||||
],
|
||||
|
||||
[
|
||||
'drush status --fields=root,uri',
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['drush', 'status'],
|
||||
['fields' => 'root,uri'],
|
||||
[],
|
||||
'WIN',
|
||||
],
|
||||
|
||||
[
|
||||
"drush rsync a b -- --exclude=vendor",
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['drush', 'rsync', 'a', 'b',],
|
||||
[],
|
||||
['exclude' => 'vendor'],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"drush rsync a b -- --exclude=vendor --include=vendor/autoload.php",
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
['drush', 'rsync', 'a', 'b', '--', '--include=vendor/autoload.php'],
|
||||
[],
|
||||
['exclude' => 'vendor'],
|
||||
NULL,
|
||||
],
|
||||
|
||||
[
|
||||
"env foo=bar baz=zong drush status",
|
||||
false,
|
||||
false,
|
||||
['env-vars' => ['foo' => 'bar', 'baz' => 'zong']],
|
||||
['drush', 'status'],
|
||||
[],
|
||||
[],
|
||||
NULL,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the SiteProcess class.
|
||||
*
|
||||
* @dataProvider siteProcessTestValues
|
||||
*/
|
||||
public function testSiteProcess(
|
||||
$expected,
|
||||
$cd,
|
||||
$useTty,
|
||||
$siteAliasData,
|
||||
$args,
|
||||
$options,
|
||||
$optionsPassedAsArgs,
|
||||
$os)
|
||||
{
|
||||
if (Escape::isWindows() != Escape::isWindows($os)) {
|
||||
$this->markTestSkipped("OS isn't supported");
|
||||
}
|
||||
if ($useTty && Escape::isWindows($os)) {
|
||||
$this->markTestSkipped('Windows doesn\'t have /dev/tty support');
|
||||
}
|
||||
$processManager = ProcessManager::createDefault();
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$siteProcess = $processManager->siteProcess($siteAlias, $args, $options, $optionsPassedAsArgs);
|
||||
$siteProcess->setTty($useTty);
|
||||
// The transport handles the chdir during processArgs().
|
||||
$fallback = $siteAlias->hasRoot() ? $siteAlias->root() : null;
|
||||
$siteProcess->setWorkingDirectory($cd ?: $fallback);
|
||||
|
||||
$actual = $siteProcess->getCommandLine();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testSiteProcessJson.
|
||||
*/
|
||||
public function siteProcessJsonTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'Output is empty.',
|
||||
'',
|
||||
'LINUX',
|
||||
],
|
||||
[
|
||||
"Unable to decode output into JSON: Syntax error\n\nNo json data here",
|
||||
'No json data here',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'{"foo":"bar"}',
|
||||
'{"foo":"bar"}',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'{"foo":"b\'ar"}',
|
||||
'{"foo":"b\'ar"}',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'{"foo":"bar"}',
|
||||
'Ignored leading data {"foo":"bar"} Ignored trailing data',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'["a","b","c"]',
|
||||
'["a", "b", "c"]',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'"string"',
|
||||
'"string"',
|
||||
NULL,
|
||||
],
|
||||
[
|
||||
'[]',
|
||||
'[]',
|
||||
NULL,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the SiteProcess class.
|
||||
*
|
||||
* @dataProvider siteProcessJsonTestValues
|
||||
*/
|
||||
public function testSiteProcessJson(
|
||||
$expected,
|
||||
$data,
|
||||
$os)
|
||||
{
|
||||
if (Escape::isWindows()) {
|
||||
$this->markTestSkipped("Windows is not working yet. PRs welcome.");
|
||||
}
|
||||
$args = ['echo', $data];
|
||||
$processManager = ProcessManager::createDefault();
|
||||
$siteAlias = new SiteAlias([], '@alias.dev');
|
||||
$siteAlias->set('os', $os);
|
||||
$siteProcess = $processManager->siteProcess($siteAlias, $args);
|
||||
$siteProcess->mustRun();
|
||||
|
||||
try {
|
||||
$actual = $siteProcess->getOutputAsJson();
|
||||
$actual = json_encode($actual, true);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$actual = $e->getMessage();
|
||||
}
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteProcess\Transport\DockerComposeTransport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
|
||||
class DockerComposeTransportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testWrap.
|
||||
*/
|
||||
public function wrapTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'docker-compose --project project --project-directory projectDir --file myCompose.yml exec -T --user root drupal ls',
|
||||
[
|
||||
'docker' => [
|
||||
'service' => 'drupal',
|
||||
'compose' => [
|
||||
'options' => '--project project --project-directory projectDir --file myCompose.yml'
|
||||
],
|
||||
'exec' => ['options' => '--user root']
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'docker-compose exec -T drupal ls',
|
||||
[
|
||||
'docker' => [
|
||||
'service' => 'drupal',
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'docker-compose --project project2 --file myCompose.yml exec -T drupal ls',
|
||||
[
|
||||
'docker' => [
|
||||
'service' => 'drupal',
|
||||
'project' => 'project1',
|
||||
'compose' => [
|
||||
'options' => '--project project2 --file myCompose.yml'
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'docker-compose -p project1 --file myCompose.yml exec -T drupal ls',
|
||||
[
|
||||
'docker' => [
|
||||
'service' => 'drupal',
|
||||
'project' => 'project1',
|
||||
'compose' => [
|
||||
'options' => '--file myCompose.yml'
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider wrapTestValues
|
||||
*/
|
||||
public function testWrap($expected, $siteAliasData)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$dockerTransport = new DockerComposeTransport($siteAlias);
|
||||
$actual = $dockerTransport->wrap(['ls']);
|
||||
$this->assertEquals($expected, implode(' ', $actual));
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteProcess\Transport\KubectlTransport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
|
||||
class KubectlTransportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testWrap.
|
||||
*/
|
||||
public function wrapTestValues()
|
||||
{
|
||||
return [
|
||||
// Everything explicit.
|
||||
[
|
||||
'kubectl --namespace=vv exec --tty=false --stdin=false deploy/drupal --container=drupal -- ls',
|
||||
['ls'],
|
||||
[
|
||||
'kubectl' => [
|
||||
'tty' => false,
|
||||
'interactive' => false,
|
||||
'namespace' => 'vv',
|
||||
'resource' => 'deploy/drupal',
|
||||
'container' => 'drupal',
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
// Minimal. Kubectl will pick a container.
|
||||
[
|
||||
'kubectl --namespace=vv exec --tty=false --stdin=false deploy/drupal -- ls',
|
||||
['ls'],
|
||||
[
|
||||
'kubectl' => [
|
||||
'namespace' => 'vv',
|
||||
'resource' => 'deploy/drupal',
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
// Don't escape arguments after "--"
|
||||
[
|
||||
'kubectl --namespace=vv exec --tty=false --stdin=false deploy/drupal -- asdf "double" \'single\'',
|
||||
['asdf', '"double"', "'single'"],
|
||||
[
|
||||
'kubectl' => [
|
||||
'namespace' => 'vv',
|
||||
'resource' => 'deploy/drupal',
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider wrapTestValues
|
||||
*/
|
||||
public function testWrap($expected, $args, $siteAliasData)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$dockerTransport = new KubectlTransport($siteAlias);
|
||||
$actual = $dockerTransport->wrap($args);
|
||||
$this->assertEquals($expected, implode(' ', $actual));
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Consolidation\SiteProcess\Transport\VagrantTransport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Consolidation\SiteAlias\SiteAlias;
|
||||
|
||||
class VagrantTransportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Data provider for testWrap.
|
||||
*/
|
||||
public function wrapTestValues()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'vagrant ssh -c ls',
|
||||
[
|
||||
'vagrant' => []
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider wrapTestValues
|
||||
*/
|
||||
public function testWrap($expected, $siteAliasData)
|
||||
{
|
||||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
|
||||
$dockerTransport = new VagrantTransport($siteAlias);
|
||||
$actual = $dockerTransport->wrap(['ls']);
|
||||
$this->assertEquals($expected, implode(' ', $actual));
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
interface CommandTesterInterface
|
||||
{
|
||||
const STATUS_OK = 0;
|
||||
const STATUS_ERROR = 1;
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Consolidation\SiteProcess;
|
||||
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
trait CommandTesterTrait
|
||||
{
|
||||
/** @var string */
|
||||
protected $appName;
|
||||
|
||||
/** @var string */
|
||||
protected $appVersion;
|
||||
|
||||
/**
|
||||
* Instantiate a new runner
|
||||
*/
|
||||
public function setupCommandTester($appName, $appVersion)
|
||||
{
|
||||
// Define our invariants for our test
|
||||
$this->appName = $appName;
|
||||
$this->appVersion = $appVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare our $argv array; put the app name in $argv[0] followed by
|
||||
* the command name and all command arguments and options.
|
||||
*
|
||||
* @param array $functionParameters should usually be func_get_args()
|
||||
* @param int $leadingParameterCount the number of function parameters
|
||||
* that are NOT part of argv. Default is 2 (expected content and
|
||||
* expected status code).
|
||||
*/
|
||||
protected function argv($functionParameters, $leadingParameterCount = 2)
|
||||
{
|
||||
$argv = $functionParameters;
|
||||
$argv = array_slice($argv, $leadingParameterCount);
|
||||
array_unshift($argv, $this->appName);
|
||||
|
||||
return $argv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulated front controller
|
||||
*/
|
||||
protected function execute($argv, $commandClasses, $configurationFile = false)
|
||||
{
|
||||
// Define a global output object to capture the test results
|
||||
$output = new BufferedOutput();
|
||||
|
||||
// We can only call `Runner::execute()` once; then we need to tear down.
|
||||
$runner = new \Robo\Runner($commandClasses);
|
||||
if ($configurationFile) {
|
||||
$runner->setConfigurationFilename($configurationFile);
|
||||
}
|
||||
$statusCode = $runner->execute($argv, $this->appName, $this->appVersion, $output);
|
||||
|
||||
// Destroy our container so that we can call $runner->execute() again for the next test.
|
||||
\Robo\Robo::unsetContainer();
|
||||
|
||||
// Return the output and status code.
|
||||
return [trim($output->fetch()), $statusCode];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user