Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
2
vendor/zendframework/zend-diactoros/.coveralls.yml
vendored
Normal file
2
vendor/zendframework/zend-diactoros/.coveralls.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
coverage_clover: clover.xml
|
||||
json_path: coveralls-upload.json
|
1287
vendor/zendframework/zend-diactoros/CHANGELOG.md
vendored
Normal file
1287
vendor/zendframework/zend-diactoros/CHANGELOG.md
vendored
Normal file
File diff suppressed because it is too large
Load diff
43
vendor/zendframework/zend-diactoros/CONDUCT.md
vendored
Normal file
43
vendor/zendframework/zend-diactoros/CONDUCT.md
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Contributor Code of Conduct
|
||||
|
||||
The Zend Framework project adheres to [The Code Manifesto](http://codemanifesto.com)
|
||||
as its guidelines for contributor interactions.
|
||||
|
||||
## The Code Manifesto
|
||||
|
||||
We want to work in an ecosystem that empowers developers to reach their
|
||||
potential — one that encourages growth and effective collaboration. A space that
|
||||
is safe for all.
|
||||
|
||||
A space such as this benefits everyone that participates in it. It encourages
|
||||
new developers to enter our field. It is through discussion and collaboration
|
||||
that we grow, and through growth that we improve.
|
||||
|
||||
In the effort to create such a place, we hold to these values:
|
||||
|
||||
1. **Discrimination limits us.** This includes discrimination on the basis of
|
||||
race, gender, sexual orientation, gender identity, age, nationality, technology
|
||||
and any other arbitrary exclusion of a group of people.
|
||||
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort
|
||||
levels. Remember that, and if brought to your attention, heed it.
|
||||
3. **We are our biggest assets.** None of us were born masters of our trade.
|
||||
Each of us has been helped along the way. Return that favor, when and where
|
||||
you can.
|
||||
4. **We are resources for the future.** As an extension of #3, share what you
|
||||
know. Make yourself a resource to help those that come after you.
|
||||
5. **Respect defines us.** Treat others as you wish to be treated. Make your
|
||||
discussions, criticisms and debates from a position of respectfulness. Ask
|
||||
yourself, is it true? Is it necessary? Is it constructive? Anything less is
|
||||
unacceptable.
|
||||
6. **Reactions require grace.** Angry responses are valid, but abusive language
|
||||
and vindictive actions are toxic. When something happens that offends you,
|
||||
handle it assertively, but be respectful. Escalate reasonably, and try to
|
||||
allow the offender an opportunity to explain themselves, and possibly correct
|
||||
the issue.
|
||||
7. **Opinions are just that: opinions.** Each and every one of us, due to our
|
||||
background and upbringing, have varying opinions. The fact of the matter, is
|
||||
that is perfectly acceptable. Remember this: if you respect your own
|
||||
opinions, you should respect the opinions of others.
|
||||
8. **To err is human.** You might not intend it, but mistakes do happen and
|
||||
contribute to build experience. Tolerate honest mistakes, and don't hesitate
|
||||
to apologize if you make one yourself.
|
228
vendor/zendframework/zend-diactoros/CONTRIBUTING.md
vendored
Normal file
228
vendor/zendframework/zend-diactoros/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,228 @@
|
|||
# CONTRIBUTING
|
||||
|
||||
## RESOURCES
|
||||
|
||||
If you wish to contribute to Zend Framework, please be sure to
|
||||
read/subscribe to the following resources:
|
||||
|
||||
- [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards)
|
||||
- [Contributor's Guide](http://framework.zend.com/participate/contributor-guide)
|
||||
- ZF Contributor's mailing list:
|
||||
Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html
|
||||
Subscribe: zf-contributors-subscribe@lists.zend.com
|
||||
- ZF Contributor's IRC channel:
|
||||
#zftalk.dev on Freenode.net
|
||||
|
||||
If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-diactoros/issues/new).
|
||||
|
||||
## Reporting Potential Security Issues
|
||||
|
||||
If you have encountered a potential security vulnerability, please **DO NOT** report it on the public
|
||||
issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead.
|
||||
We will work with you to verify the vulnerability and patch it as soon as possible.
|
||||
|
||||
When reporting issues, please provide the following information:
|
||||
|
||||
- Component(s) affected
|
||||
- A description indicating how to reproduce the issue
|
||||
- A summary of the security vulnerability and impact
|
||||
|
||||
We request that you contact us via the email address above and give the project
|
||||
contributors a chance to resolve the vulnerability and issue a new release prior
|
||||
to any public exposure; this helps protect users and provides them with a chance
|
||||
to upgrade and/or update in order to protect their applications.
|
||||
|
||||
For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc).
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is in [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/),
|
||||
and rendered using [bookdown](http://bookdown.io). Please read and follow the [general documentation
|
||||
guidelines](https://github.com/zendframework/documentation/blob/master/CONTRIBUTING.md) when
|
||||
providing documentation.
|
||||
|
||||
All new features **must** include documentation before they may be accepted and merged.
|
||||
|
||||
## RUNNING TESTS
|
||||
|
||||
To run tests:
|
||||
|
||||
- Clone the repository:
|
||||
|
||||
```console
|
||||
$ git clone git@github.com:zendframework/zend-diactoros.git
|
||||
$ cd
|
||||
```
|
||||
|
||||
- Install dependencies via composer:
|
||||
|
||||
```console
|
||||
$ curl -sS https://getcomposer.org/installer | php --
|
||||
$ ./composer.phar install
|
||||
```
|
||||
|
||||
If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/
|
||||
|
||||
- Run the tests via `phpunit` and the provided PHPUnit config, like in this example:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
## Running Coding Standards Checks
|
||||
|
||||
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
|
||||
standards checks, and provides configuration for our selected checks.
|
||||
`phpcs` is installed by default via Composer.
|
||||
|
||||
To run checks only:
|
||||
|
||||
```console
|
||||
$ composer cs-check
|
||||
```
|
||||
|
||||
`phpcs` also installs a tool named `phpcbf` which can attempt to fix problems
|
||||
for you:
|
||||
|
||||
```console
|
||||
$ composer cs-fix
|
||||
```
|
||||
|
||||
If you allow phpcbf to fix CS issues, please re-run the tests to ensure
|
||||
they pass, and make sure you add and commit the changes after verification.
|
||||
|
||||
## Recommended Workflow for Contributions
|
||||
|
||||
Your first step is to establish a public repository from which we can
|
||||
pull your work into the master repository. We recommend using
|
||||
[GitHub](https://github.com), as that is where the component is already hosted.
|
||||
|
||||
1. Setup a [GitHub account](http://github.com/), if you haven't yet
|
||||
2. Fork the repository (http://github.com/zendframework/zend-diactoros)
|
||||
3. Clone the canonical repository locally and enter it.
|
||||
|
||||
```console
|
||||
$ git clone git://github.com/zendframework/zend-diactoros.git
|
||||
$ cd zend-diactoros
|
||||
```
|
||||
|
||||
4. Add a remote to your fork; substitute your GitHub username in the command
|
||||
below.
|
||||
|
||||
```console
|
||||
$ git remote add {username} git@github.com:{username}/zend-diactoros.git
|
||||
$ git fetch {username}
|
||||
```
|
||||
|
||||
### Keeping Up-to-Date
|
||||
|
||||
Periodically, you should update your fork or personal repository to
|
||||
match the canonical repository. Assuming you have setup your local repository
|
||||
per the instructions above, you can do the following:
|
||||
|
||||
|
||||
```console
|
||||
$ git checkout master
|
||||
$ git fetch origin
|
||||
$ git rebase origin/master
|
||||
# OPTIONALLY, to keep your remote up-to-date -
|
||||
$ git push {username} master:master
|
||||
```
|
||||
|
||||
If you're tracking other branches -- for example, the "develop" branch, where
|
||||
new feature development occurs -- you'll want to do the same operations for that
|
||||
branch; simply substitute "develop" for "master".
|
||||
|
||||
### Working on a patch
|
||||
|
||||
We recommend you do each new feature or bugfix in a new branch. This simplifies
|
||||
the task of code review as well as the task of merging your changes into the
|
||||
canonical repository.
|
||||
|
||||
A typical workflow will then consist of the following:
|
||||
|
||||
1. Create a new local branch based off either your master or develop branch.
|
||||
2. Switch to your new local branch. (This step can be combined with the
|
||||
previous step with the use of `git checkout -b`.)
|
||||
3. Do some work, commit, repeat as necessary.
|
||||
4. Push the local branch to your remote repository.
|
||||
5. Send a pull request.
|
||||
|
||||
The mechanics of this process are actually quite trivial. Below, we will
|
||||
create a branch for fixing an issue in the tracker.
|
||||
|
||||
```console
|
||||
$ git checkout -b hotfix/9295
|
||||
Switched to a new branch 'hotfix/9295'
|
||||
```
|
||||
|
||||
... do some work ...
|
||||
|
||||
|
||||
```console
|
||||
$ git commit
|
||||
```
|
||||
|
||||
... write your log message ...
|
||||
|
||||
|
||||
```console
|
||||
$ git push {username} hotfix/9295:hotfix/9295
|
||||
Counting objects: 38, done.
|
||||
Delta compression using up to 2 threads.
|
||||
Compression objects: 100% (18/18), done.
|
||||
Writing objects: 100% (20/20), 8.19KiB, done.
|
||||
Total 20 (delta 12), reused 0 (delta 0)
|
||||
To ssh://git@github.com/{username}/zend-diactoros.git
|
||||
b5583aa..4f51698 HEAD -> master
|
||||
```
|
||||
|
||||
To send a pull request, you have two options.
|
||||
|
||||
If using GitHub, you can do the pull request from there. Navigate to
|
||||
your repository, select the branch you just created, and then select the
|
||||
"Pull Request" button in the upper right. Select the user/organization
|
||||
"zendframework" as the recipient.
|
||||
|
||||
If using your own repository - or even if using GitHub - you can use `git
|
||||
format-patch` to create a patchset for us to apply; in fact, this is
|
||||
**recommended** for security-related patches. If you use `format-patch`, please
|
||||
send the patches as attachments to:
|
||||
|
||||
- zf-devteam@zend.com for patches without security implications
|
||||
- zf-security@zend.com for security patches
|
||||
|
||||
#### What branch to issue the pull request against?
|
||||
|
||||
Which branch should you issue a pull request against?
|
||||
|
||||
- For fixes against the stable release, issue the pull request against the
|
||||
"master" branch.
|
||||
- For new features, or fixes that introduce new elements to the public API (such
|
||||
as new public methods or properties), issue the pull request against the
|
||||
"develop" branch.
|
||||
|
||||
### Branch Cleanup
|
||||
|
||||
As you might imagine, if you are a frequent contributor, you'll start to
|
||||
get a ton of branches both locally and on your remote.
|
||||
|
||||
Once you know that your changes have been accepted to the master
|
||||
repository, we suggest doing some cleanup of these branches.
|
||||
|
||||
- Local branch cleanup
|
||||
|
||||
```console
|
||||
$ git branch -d <branchname>
|
||||
```
|
||||
|
||||
- Remote branch removal
|
||||
|
||||
```console
|
||||
$ git push {username} :<branchname>
|
||||
```
|
||||
|
||||
|
||||
## Conduct
|
||||
|
||||
Please see our [CONDUCT.md](CONDUCT.md) to understand expected behavior when interacting with others in the project.
|
12
vendor/zendframework/zend-diactoros/LICENSE.md
vendored
Normal file
12
vendor/zendframework/zend-diactoros/LICENSE.md
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
Copyright (c) 2015-2016, Zend Technologies USA, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Zend Technologies USA, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
vendor/zendframework/zend-diactoros/README.md
vendored
Normal file
34
vendor/zendframework/zend-diactoros/README.md
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
# zend-diactoros
|
||||
|
||||
Master:
|
||||
[![Build status][Master image]][Master]
|
||||
[![Coverage Status][Master coverage image]][Master coverage]
|
||||
Develop:
|
||||
[![Build status][Develop image]][Develop]
|
||||
[![Coverage Status][Develop coverage image]][Develop coverage]
|
||||
|
||||
> Diactoros (pronunciation: `/dɪʌktɒrɒs/`): an epithet for Hermes, meaning literally, "the messenger."
|
||||
|
||||
This package supercedes and replaces [phly/http](https://github.com/phly/http).
|
||||
|
||||
`zend-diactoros` is a PHP package containing implementations of the [accepted PSR-7 HTTP message interfaces](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md), as well as a "server" implementation similar to [node's http.Server](http://nodejs.org/api/http.html).
|
||||
|
||||
* File issues at https://github.com/zendframework/zend-diactoros/issues
|
||||
* Issue patches to https://github.com/zendframework/zend-diactoros/pulls
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is available at:
|
||||
|
||||
- https://zendframework.github.io/zend-diactoros/
|
||||
|
||||
Source files for documentation are [in the doc/ tree](doc/).
|
||||
|
||||
[Master]: https://travis-ci.org/zendframework/zend-diactoros
|
||||
[Master image]: https://secure.travis-ci.org/zendframework/zend-diactoros.svg?branch=master
|
||||
[Master coverage image]: https://img.shields.io/coveralls/zendframework/zend-diactoros/master.svg
|
||||
[Master coverage]: https://coveralls.io/r/zendframework/zend-diactoros?branch=master
|
||||
[Develop]: https://github.com/zendframework/zend-diactoros/tree/develop
|
||||
[Develop image]: https://secure.travis-ci.org/zendframework/zend-diactoros.svg?branch=develop
|
||||
[Develop coverage image]: https://coveralls.io/repos/zendframework/zend-diactoros/badge.svg?branch=develop
|
||||
[Develop coverage]: https://coveralls.io/r/zendframework/zend-diactoros?branch=develop
|
74
vendor/zendframework/zend-diactoros/composer.json
vendored
Normal file
74
vendor/zendframework/zend-diactoros/composer.json
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "zendframework/zend-diactoros",
|
||||
"description": "PSR HTTP Message implementations",
|
||||
"type": "library",
|
||||
"license": "BSD-2-Clause",
|
||||
"keywords": [
|
||||
"http",
|
||||
"psr",
|
||||
"psr-7"
|
||||
],
|
||||
"homepage": "https://github.com/zendframework/zend-diactoros",
|
||||
"support": {
|
||||
"issues": "https://github.com/zendframework/zend-diactoros/issues",
|
||||
"source": "https://github.com/zendframework/zend-diactoros"
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.8.x-dev",
|
||||
"dev-develop": "1.9.x-dev",
|
||||
"dev-release-2.0": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.6 || ^7.0",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-dom": "*",
|
||||
"ext-libxml": "*",
|
||||
"php-http/psr7-integration-tests": "dev-master",
|
||||
"phpunit/phpunit": "^5.7.16 || ^6.0.8 || ^7.2.7",
|
||||
"zendframework/zend-coding-standard": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions/create_uploaded_file.php",
|
||||
"src/functions/marshal_headers_from_sapi.php",
|
||||
"src/functions/marshal_method_from_sapi.php",
|
||||
"src/functions/marshal_protocol_version_from_sapi.php",
|
||||
"src/functions/marshal_uri_from_sapi.php",
|
||||
"src/functions/normalize_server.php",
|
||||
"src/functions/normalize_uploaded_files.php",
|
||||
"src/functions/parse_cookie_header.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Zend\\Diactoros\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"ZendTest\\Diactoros\\": "test/"
|
||||
},
|
||||
"files": [
|
||||
"test/TestAsset/Functions.php",
|
||||
"test/TestAsset/SapiResponse.php"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"check": [
|
||||
"@cs-check",
|
||||
"@test"
|
||||
],
|
||||
"cs-check": "phpcs",
|
||||
"cs-fix": "phpcbf",
|
||||
"test": "phpunit --colors=always",
|
||||
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
|
||||
}
|
||||
}
|
1695
vendor/zendframework/zend-diactoros/composer.lock
generated
vendored
Normal file
1695
vendor/zendframework/zend-diactoros/composer.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
16
vendor/zendframework/zend-diactoros/mkdocs.yml
vendored
Normal file
16
vendor/zendframework/zend-diactoros/mkdocs.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
docs_dir: doc/book
|
||||
site_dir: doc/html
|
||||
pages:
|
||||
- index.md
|
||||
- Overview: overview.md
|
||||
- Installation: install.md
|
||||
- Usage: usage.md
|
||||
- Reference:
|
||||
- "Custom Responses": custom-responses.md
|
||||
- "Emitting Responses": emitting-responses.md
|
||||
- Serialization: serialization.md
|
||||
- API: api.md
|
||||
site_name: zend-diactoros
|
||||
site_description: 'zend-diactoros: PSR-7 HTTP message implementation'
|
||||
repo_url: 'https://github.com/zendframework/zend-diactoros'
|
||||
copyright: 'Copyright (c) 2016 <a href="http://www.zend.com/">Zend Technologies USA Inc.</a>'
|
160
vendor/zendframework/zend-diactoros/src/AbstractSerializer.php
vendored
Normal file
160
vendor/zendframework/zend-diactoros/src/AbstractSerializer.php
vendored
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_pop;
|
||||
use function implode;
|
||||
use function ltrim;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function ucwords;
|
||||
|
||||
/**
|
||||
* Provides base functionality for request and response de/serialization
|
||||
* strategies, including functionality for retrieving a line at a time from
|
||||
* the message, splitting headers from the body, and serializing headers.
|
||||
*/
|
||||
abstract class AbstractSerializer
|
||||
{
|
||||
const CR = "\r";
|
||||
const EOL = "\r\n";
|
||||
const LF = "\n";
|
||||
|
||||
/**
|
||||
* Retrieve a single line from the stream.
|
||||
*
|
||||
* Retrieves a line from the stream; a line is defined as a sequence of
|
||||
* characters ending in a CRLF sequence.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return string
|
||||
* @throws UnexpectedValueException if the sequence contains a CR or LF in
|
||||
* isolation, or ends in a CR.
|
||||
*/
|
||||
protected static function getLine(StreamInterface $stream)
|
||||
{
|
||||
$line = '';
|
||||
$crFound = false;
|
||||
while (! $stream->eof()) {
|
||||
$char = $stream->read(1);
|
||||
|
||||
if ($crFound && $char === self::LF) {
|
||||
$crFound = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// CR NOT followed by LF
|
||||
if ($crFound && $char !== self::LF) {
|
||||
throw new UnexpectedValueException('Unexpected carriage return detected');
|
||||
}
|
||||
|
||||
// LF in isolation
|
||||
if (! $crFound && $char === self::LF) {
|
||||
throw new UnexpectedValueException('Unexpected line feed detected');
|
||||
}
|
||||
|
||||
// CR found; do not append
|
||||
if ($char === self::CR) {
|
||||
$crFound = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any other character: append
|
||||
$line .= $char;
|
||||
}
|
||||
|
||||
// CR found at end of stream
|
||||
if ($crFound) {
|
||||
throw new UnexpectedValueException("Unexpected end of headers");
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the stream into headers and body content.
|
||||
*
|
||||
* Returns an array containing two elements
|
||||
*
|
||||
* - The first is an array of headers
|
||||
* - The second is a StreamInterface containing the body content
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return array
|
||||
* @throws UnexpectedValueException For invalid headers.
|
||||
*/
|
||||
protected static function splitStream(StreamInterface $stream)
|
||||
{
|
||||
$headers = [];
|
||||
$currentHeader = false;
|
||||
|
||||
while ($line = self::getLine($stream)) {
|
||||
if (preg_match(';^(?P<name>[!#$%&\'*+.^_`\|~0-9a-zA-Z-]+):(?P<value>.*)$;', $line, $matches)) {
|
||||
$currentHeader = $matches['name'];
|
||||
if (! isset($headers[$currentHeader])) {
|
||||
$headers[$currentHeader] = [];
|
||||
}
|
||||
$headers[$currentHeader][] = ltrim($matches['value']);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $currentHeader) {
|
||||
throw new UnexpectedValueException('Invalid header detected');
|
||||
}
|
||||
|
||||
if (! preg_match('#^[ \t]#', $line)) {
|
||||
throw new UnexpectedValueException('Invalid header continuation');
|
||||
}
|
||||
|
||||
// Append continuation to last header value found
|
||||
$value = array_pop($headers[$currentHeader]);
|
||||
$headers[$currentHeader][] = $value . ltrim($line);
|
||||
}
|
||||
|
||||
// use RelativeStream to avoid copying initial stream into memory
|
||||
return [$headers, new RelativeStream($stream, $stream->tell())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize headers to string values.
|
||||
*
|
||||
* @param array $headers
|
||||
* @return string
|
||||
*/
|
||||
protected static function serializeHeaders(array $headers)
|
||||
{
|
||||
$lines = [];
|
||||
foreach ($headers as $header => $values) {
|
||||
$normalized = self::filterHeader($header);
|
||||
foreach ($values as $value) {
|
||||
$lines[] = sprintf('%s: %s', $normalized, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\r\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a header name to wordcase
|
||||
*
|
||||
* @param string $header
|
||||
* @return string
|
||||
*/
|
||||
protected static function filterHeader($header)
|
||||
{
|
||||
$filtered = str_replace('-', ' ', $header);
|
||||
$filtered = ucwords($filtered);
|
||||
return str_replace(' ', '-', $filtered);
|
||||
}
|
||||
}
|
185
vendor/zendframework/zend-diactoros/src/CallbackStream.php
vendored
Normal file
185
vendor/zendframework/zend-diactoros/src/CallbackStream.php
vendored
Normal file
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use RuntimeException;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
use const SEEK_SET;
|
||||
|
||||
/**
|
||||
* Implementation of PSR HTTP streams
|
||||
*/
|
||||
class CallbackStream implements StreamInterface
|
||||
{
|
||||
/**
|
||||
* @var callable|null
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(callable $callback)
|
||||
{
|
||||
$this->attach($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->callback = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
$callback = $this->callback;
|
||||
$this->callback = null;
|
||||
return $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a new callback to the instance.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @throws InvalidArgumentException for callable callback
|
||||
*/
|
||||
public function attach(callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
{
|
||||
throw new RuntimeException('Callback streams cannot tell position');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
{
|
||||
return empty($this->callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSeekable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
throw new RuntimeException('Callback streams cannot seek position');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
throw new RuntimeException('Callback streams cannot rewind position');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($string)
|
||||
{
|
||||
throw new RuntimeException('Callback streams cannot write');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
throw new RuntimeException('Callback streams cannot read');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
$callback = $this->detach();
|
||||
return $callback ? $callback() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
$metadata = [
|
||||
'eof' => $this->eof(),
|
||||
'stream_type' => 'callback',
|
||||
'seekable' => false
|
||||
];
|
||||
|
||||
if (null === $key) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
if (! array_key_exists($key, $metadata)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $metadata[$key];
|
||||
}
|
||||
}
|
19
vendor/zendframework/zend-diactoros/src/Exception/DeprecatedMethodException.php
vendored
Normal file
19
vendor/zendframework/zend-diactoros/src/Exception/DeprecatedMethodException.php
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Exception;
|
||||
|
||||
use BadMethodCallException;
|
||||
|
||||
/**
|
||||
* Exception indicating a deprecated method.
|
||||
*/
|
||||
class DeprecatedMethodException extends BadMethodCallException implements ExceptionInterface
|
||||
{
|
||||
}
|
17
vendor/zendframework/zend-diactoros/src/Exception/ExceptionInterface.php
vendored
Normal file
17
vendor/zendframework/zend-diactoros/src/Exception/ExceptionInterface.php
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Exception;
|
||||
|
||||
/**
|
||||
* Marker interface for package-specific exceptions.
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
177
vendor/zendframework/zend-diactoros/src/HeaderSecurity.php
vendored
Normal file
177
vendor/zendframework/zend-diactoros/src/HeaderSecurity.php
vendored
Normal file
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function in_array;
|
||||
use function is_numeric;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function ord;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* Provide security tools around HTTP headers to prevent common injection vectors.
|
||||
*
|
||||
* Code is largely lifted from the Zend\Http\Header\HeaderValue implementation in
|
||||
* Zend Framework, released with the copyright and license below.
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
final class HeaderSecurity
|
||||
{
|
||||
/**
|
||||
* Private constructor; non-instantiable.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a header value
|
||||
*
|
||||
* Ensures CRLF header injection vectors are filtered.
|
||||
*
|
||||
* Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal
|
||||
* tabs are allowed in values; header continuations MUST consist of
|
||||
* a single CRLF sequence followed by a space or horizontal tab.
|
||||
*
|
||||
* This method filters any values not allowed from the string, and is
|
||||
* lossy.
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/HTTP_response_splitting
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function filter($value)
|
||||
{
|
||||
$value = (string) $value;
|
||||
$length = strlen($value);
|
||||
$string = '';
|
||||
for ($i = 0; $i < $length; $i += 1) {
|
||||
$ascii = ord($value[$i]);
|
||||
|
||||
// Detect continuation sequences
|
||||
if ($ascii === 13) {
|
||||
$lf = ord($value[$i + 1]);
|
||||
$ws = ord($value[$i + 2]);
|
||||
if ($lf === 10 && in_array($ws, [9, 32], true)) {
|
||||
$string .= $value[$i] . $value[$i + 1];
|
||||
$i += 1;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Non-visible, non-whitespace characters
|
||||
// 9 === horizontal tab
|
||||
// 32-126, 128-254 === visible
|
||||
// 127 === DEL
|
||||
// 255 === null byte
|
||||
if (($ascii < 32 && $ascii !== 9)
|
||||
|| $ascii === 127
|
||||
|| $ascii > 254
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$string .= $value[$i];
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a header value.
|
||||
*
|
||||
* Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal
|
||||
* tabs are allowed in values; header continuations MUST consist of
|
||||
* a single CRLF sequence followed by a space or horizontal tab.
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/HTTP_response_splitting
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValid($value)
|
||||
{
|
||||
$value = (string) $value;
|
||||
|
||||
// Look for:
|
||||
// \n not preceded by \r, OR
|
||||
// \r not followed by \n, OR
|
||||
// \r\n not followed by space or horizontal tab; these are all CRLF attacks
|
||||
if (preg_match("#(?:(?:(?<!\r)\n)|(?:\r(?!\n))|(?:\r\n(?![ \t])))#", $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Non-visible, non-whitespace characters
|
||||
// 9 === horizontal tab
|
||||
// 10 === line feed
|
||||
// 13 === carriage return
|
||||
// 32-126, 128-254 === visible
|
||||
// 127 === DEL (disallowed)
|
||||
// 255 === null byte (disallowed)
|
||||
if (preg_match('/[^\x09\x0a\x0d\x20-\x7E\x80-\xFE]/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert a header value is valid.
|
||||
*
|
||||
* @param string $value
|
||||
* @throws InvalidArgumentException for invalid values
|
||||
*/
|
||||
public static function assertValid($value)
|
||||
{
|
||||
if (! is_string($value) && ! is_numeric($value)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid header value type; must be a string or numeric; received %s',
|
||||
(is_object($value) ? get_class($value) : gettype($value))
|
||||
));
|
||||
}
|
||||
if (! self::isValid($value)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'"%s" is not valid header value',
|
||||
$value
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert whether or not a header name is valid.
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc7230#section-3.2
|
||||
* @param mixed $name
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function assertValidName($name)
|
||||
{
|
||||
if (! is_string($name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid header name type; expected string; received %s',
|
||||
(is_object($name) ? get_class($name) : gettype($name))
|
||||
));
|
||||
}
|
||||
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $name)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'"%s" is not valid header name',
|
||||
$name
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
413
vendor/zendframework/zend-diactoros/src/MessageTrait.php
vendored
Normal file
413
vendor/zendframework/zend-diactoros/src/MessageTrait.php
vendored
Normal file
|
@ -0,0 +1,413 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function strtolower;
|
||||
|
||||
/**
|
||||
* Trait implementing the various methods defined in MessageInterface.
|
||||
*
|
||||
* @see https://github.com/php-fig/http-message/tree/master/src/MessageInterface.php
|
||||
*/
|
||||
trait MessageTrait
|
||||
{
|
||||
/**
|
||||
* List of all registered headers, as key => array of values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = [];
|
||||
|
||||
/**
|
||||
* Map of normalized header name to original name used to register header.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headerNames = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $protocol = '1.1';
|
||||
|
||||
/**
|
||||
* @var StreamInterface
|
||||
*/
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* Retrieves the HTTP protocol version as a string.
|
||||
*
|
||||
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
|
||||
*
|
||||
* @return string HTTP protocol version.
|
||||
*/
|
||||
public function getProtocolVersion()
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance with the specified HTTP protocol version.
|
||||
*
|
||||
* The version string MUST contain only the HTTP version number (e.g.,
|
||||
* "1.1", "1.0").
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new protocol version.
|
||||
*
|
||||
* @param string $version HTTP protocol version
|
||||
* @return static
|
||||
*/
|
||||
public function withProtocolVersion($version)
|
||||
{
|
||||
$this->validateProtocolVersion($version);
|
||||
$new = clone $this;
|
||||
$new->protocol = $version;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all message headers.
|
||||
*
|
||||
* The keys represent the header name as it will be sent over the wire, and
|
||||
* each value is an array of strings associated with the header.
|
||||
*
|
||||
* // Represent the headers as a string
|
||||
* foreach ($message->getHeaders() as $name => $values) {
|
||||
* echo $name . ": " . implode(", ", $values);
|
||||
* }
|
||||
*
|
||||
* // Emit headers iteratively:
|
||||
* foreach ($message->getHeaders() as $name => $values) {
|
||||
* foreach ($values as $value) {
|
||||
* header(sprintf('%s: %s', $name, $value), false);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @return array Returns an associative array of the message's headers. Each
|
||||
* key MUST be a header name, and each value MUST be an array of strings.
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a header exists by the given case-insensitive name.
|
||||
*
|
||||
* @param string $header Case-insensitive header name.
|
||||
* @return bool Returns true if any header names match the given header
|
||||
* name using a case-insensitive string comparison. Returns false if
|
||||
* no matching header name is found in the message.
|
||||
*/
|
||||
public function hasHeader($header)
|
||||
{
|
||||
return isset($this->headerNames[strtolower($header)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a message header value by the given case-insensitive name.
|
||||
*
|
||||
* This method returns an array of all the header values of the given
|
||||
* case-insensitive header name.
|
||||
*
|
||||
* If the header does not appear in the message, this method MUST return an
|
||||
* empty array.
|
||||
*
|
||||
* @param string $header Case-insensitive header field name.
|
||||
* @return string[] An array of string values as provided for the given
|
||||
* header. If the header does not appear in the message, this method MUST
|
||||
* return an empty array.
|
||||
*/
|
||||
public function getHeader($header)
|
||||
{
|
||||
if (! $this->hasHeader($header)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$header = $this->headerNames[strtolower($header)];
|
||||
|
||||
return $this->headers[$header];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a comma-separated string of the values for a single header.
|
||||
*
|
||||
* This method returns all of the header values of the given
|
||||
* case-insensitive header name as a string concatenated together using
|
||||
* a comma.
|
||||
*
|
||||
* NOTE: Not all header values may be appropriately represented using
|
||||
* comma concatenation. For such headers, use getHeader() instead
|
||||
* and supply your own delimiter when concatenating.
|
||||
*
|
||||
* If the header does not appear in the message, this method MUST return
|
||||
* an empty string.
|
||||
*
|
||||
* @param string $name Case-insensitive header field name.
|
||||
* @return string A string of values as provided for the given header
|
||||
* concatenated together using a comma. If the header does not appear in
|
||||
* the message, this method MUST return an empty string.
|
||||
*/
|
||||
public function getHeaderLine($name)
|
||||
{
|
||||
$value = $this->getHeader($name);
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode(',', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance with the provided header, replacing any existing
|
||||
* values of any headers with the same case-insensitive name.
|
||||
*
|
||||
* While header names are case-insensitive, the casing of the header will
|
||||
* be preserved by this function, and returned from getHeaders().
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new and/or updated header and value.
|
||||
*
|
||||
* @param string $header Case-insensitive header field name.
|
||||
* @param string|string[] $value Header value(s).
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException for invalid header names or values.
|
||||
*/
|
||||
public function withHeader($header, $value)
|
||||
{
|
||||
$this->assertHeader($header);
|
||||
|
||||
$normalized = strtolower($header);
|
||||
|
||||
$new = clone $this;
|
||||
if ($new->hasHeader($header)) {
|
||||
unset($new->headers[$new->headerNames[$normalized]]);
|
||||
}
|
||||
|
||||
$value = $this->filterHeaderValue($value);
|
||||
|
||||
$new->headerNames[$normalized] = $header;
|
||||
$new->headers[$header] = $value;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance with the specified header appended with the
|
||||
* given value.
|
||||
*
|
||||
* Existing values for the specified header will be maintained. The new
|
||||
* value(s) will be appended to the existing list. If the header did not
|
||||
* exist previously, it will be added.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new header and/or value.
|
||||
*
|
||||
* @param string $header Case-insensitive header field name to add.
|
||||
* @param string|string[] $value Header value(s).
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException for invalid header names or values.
|
||||
*/
|
||||
public function withAddedHeader($header, $value)
|
||||
{
|
||||
$this->assertHeader($header);
|
||||
|
||||
if (! $this->hasHeader($header)) {
|
||||
return $this->withHeader($header, $value);
|
||||
}
|
||||
|
||||
$header = $this->headerNames[strtolower($header)];
|
||||
|
||||
$new = clone $this;
|
||||
$value = $this->filterHeaderValue($value);
|
||||
$new->headers[$header] = array_merge($this->headers[$header], $value);
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance without the specified header.
|
||||
*
|
||||
* Header resolution MUST be done without case-sensitivity.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that removes
|
||||
* the named header.
|
||||
*
|
||||
* @param string $header Case-insensitive header field name to remove.
|
||||
* @return static
|
||||
*/
|
||||
public function withoutHeader($header)
|
||||
{
|
||||
if (! $this->hasHeader($header)) {
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
$normalized = strtolower($header);
|
||||
$original = $this->headerNames[$normalized];
|
||||
|
||||
$new = clone $this;
|
||||
unset($new->headers[$original], $new->headerNames[$normalized]);
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the body of the message.
|
||||
*
|
||||
* @return StreamInterface Returns the body as a stream.
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance with the specified message body.
|
||||
*
|
||||
* The body MUST be a StreamInterface object.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return a new instance that has the
|
||||
* new body stream.
|
||||
*
|
||||
* @param StreamInterface $body Body.
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException When the body is not valid.
|
||||
*/
|
||||
public function withBody(StreamInterface $body)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->stream = $body;
|
||||
return $new;
|
||||
}
|
||||
|
||||
private function getStream($stream, $modeIfNotInstance)
|
||||
{
|
||||
if ($stream instanceof StreamInterface) {
|
||||
return $stream;
|
||||
}
|
||||
|
||||
if (! is_string($stream) && ! is_resource($stream)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Stream must be a string stream resource identifier, '
|
||||
. 'an actual stream resource, '
|
||||
. 'or a Psr\Http\Message\StreamInterface implementation'
|
||||
);
|
||||
}
|
||||
|
||||
return new Stream($stream, $modeIfNotInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a set of headers to ensure they are in the correct internal format.
|
||||
*
|
||||
* Used by message constructors to allow setting all initial headers at once.
|
||||
*
|
||||
* @param array $originalHeaders Headers to filter.
|
||||
*/
|
||||
private function setHeaders(array $originalHeaders)
|
||||
{
|
||||
$headerNames = $headers = [];
|
||||
|
||||
foreach ($originalHeaders as $header => $value) {
|
||||
$value = $this->filterHeaderValue($value);
|
||||
|
||||
$this->assertHeader($header);
|
||||
|
||||
$headerNames[strtolower($header)] = $header;
|
||||
$headers[$header] = $value;
|
||||
}
|
||||
|
||||
$this->headerNames = $headerNames;
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the HTTP protocol version
|
||||
*
|
||||
* @param string $version
|
||||
* @throws InvalidArgumentException on invalid HTTP protocol version
|
||||
*/
|
||||
private function validateProtocolVersion($version)
|
||||
{
|
||||
if (empty($version)) {
|
||||
throw new InvalidArgumentException(
|
||||
'HTTP protocol version can not be empty'
|
||||
);
|
||||
}
|
||||
if (! is_string($version)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported HTTP protocol version; must be a string, received %s',
|
||||
(is_object($version) ? get_class($version) : gettype($version))
|
||||
));
|
||||
}
|
||||
|
||||
// HTTP/1 uses a "<major>.<minor>" numbering scheme to indicate
|
||||
// versions of the protocol, while HTTP/2 does not.
|
||||
if (! preg_match('#^(1\.[01]|2)$#', $version)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported HTTP protocol version "%s" provided',
|
||||
$version
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $values
|
||||
* @return string[]
|
||||
*/
|
||||
private function filterHeaderValue($values)
|
||||
{
|
||||
if (! is_array($values)) {
|
||||
$values = [$values];
|
||||
}
|
||||
|
||||
if ([] === $values) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid header value: must be a string or array of strings; '
|
||||
. 'cannot be an empty array'
|
||||
);
|
||||
}
|
||||
|
||||
return array_map(function ($value) {
|
||||
HeaderSecurity::assertValid($value);
|
||||
|
||||
return (string) $value;
|
||||
}, array_values($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure header name and values are valid.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function assertHeader($name)
|
||||
{
|
||||
HeaderSecurity::assertValidName($name);
|
||||
}
|
||||
}
|
91
vendor/zendframework/zend-diactoros/src/PhpInputStream.php
vendored
Normal file
91
vendor/zendframework/zend-diactoros/src/PhpInputStream.php
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use function stream_get_contents;
|
||||
|
||||
/**
|
||||
* Caching version of php://input
|
||||
*/
|
||||
class PhpInputStream extends Stream
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cache = '';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $reachedEof = false;
|
||||
|
||||
/**
|
||||
* @param string|resource $stream
|
||||
*/
|
||||
public function __construct($stream = 'php://input')
|
||||
{
|
||||
parent::__construct($stream, 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->reachedEof) {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
$this->getContents();
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$content = parent::read($length);
|
||||
if (! $this->reachedEof) {
|
||||
$this->cache .= $content;
|
||||
}
|
||||
|
||||
if ($this->eof()) {
|
||||
$this->reachedEof = true;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents($maxLength = -1)
|
||||
{
|
||||
if ($this->reachedEof) {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
$contents = stream_get_contents($this->resource, $maxLength);
|
||||
$this->cache .= $contents;
|
||||
|
||||
if ($maxLength === -1 || $this->eof()) {
|
||||
$this->reachedEof = true;
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
}
|
180
vendor/zendframework/zend-diactoros/src/RelativeStream.php
vendored
Normal file
180
vendor/zendframework/zend-diactoros/src/RelativeStream.php
vendored
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use RuntimeException;
|
||||
|
||||
use const SEEK_SET;
|
||||
|
||||
/**
|
||||
* Class RelativeStream
|
||||
*
|
||||
* Wrapper for default Stream class, representing subpart (starting from given offset) of initial stream.
|
||||
* It can be used to avoid copying full stream, conserving memory.
|
||||
* @example see Zend\Diactoros\AbstractSerializer::splitStream()
|
||||
*/
|
||||
final class RelativeStream implements StreamInterface
|
||||
{
|
||||
/**
|
||||
* @var StreamInterface
|
||||
*/
|
||||
private $decoratedStream;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $offset;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param StreamInterface $decoratedStream
|
||||
* @param int $offset
|
||||
*/
|
||||
public function __construct(StreamInterface $decoratedStream, $offset)
|
||||
{
|
||||
$this->decoratedStream = $decoratedStream;
|
||||
$this->offset = (int)$offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->isSeekable()) {
|
||||
$this->seek(0);
|
||||
}
|
||||
return $this->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->decoratedStream->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
return $this->decoratedStream->detach();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return $this->decoratedStream->getSize() - $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
{
|
||||
return $this->decoratedStream->tell() - $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
{
|
||||
return $this->decoratedStream->eof();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSeekable()
|
||||
{
|
||||
return $this->decoratedStream->isSeekable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
if ($whence == SEEK_SET) {
|
||||
return $this->decoratedStream->seek($offset + $this->offset, $whence);
|
||||
}
|
||||
return $this->decoratedStream->seek($offset, $whence);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
return $this->seek(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
{
|
||||
return $this->decoratedStream->isWritable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($string)
|
||||
{
|
||||
if ($this->tell() < 0) {
|
||||
throw new RuntimeException('Invalid pointer position');
|
||||
}
|
||||
return $this->decoratedStream->write($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable()
|
||||
{
|
||||
return $this->decoratedStream->isReadable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->tell() < 0) {
|
||||
throw new RuntimeException('Invalid pointer position');
|
||||
}
|
||||
return $this->decoratedStream->read($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
if ($this->tell() < 0) {
|
||||
throw new RuntimeException('Invalid pointer position');
|
||||
}
|
||||
return $this->decoratedStream->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return $this->decoratedStream->getMetadata($key);
|
||||
}
|
||||
}
|
73
vendor/zendframework/zend-diactoros/src/Request.php
vendored
Normal file
73
vendor/zendframework/zend-diactoros/src/Request.php
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
use function strtolower;
|
||||
|
||||
/**
|
||||
* HTTP Request encapsulation
|
||||
*
|
||||
* Requests are considered immutable; all methods that might change state are
|
||||
* implemented such that they retain the internal state of the current
|
||||
* message and return a new instance that contains the changed state.
|
||||
*/
|
||||
class Request implements RequestInterface
|
||||
{
|
||||
use RequestTrait;
|
||||
|
||||
/**
|
||||
* @param null|string|UriInterface $uri URI for the request, if any.
|
||||
* @param null|string $method HTTP method for the request, if any.
|
||||
* @param string|resource|StreamInterface $body Message body, if any.
|
||||
* @param array $headers Headers for the message, if any.
|
||||
* @throws \InvalidArgumentException for any invalid value.
|
||||
*/
|
||||
public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = [])
|
||||
{
|
||||
$this->initialize($uri, $method, $body, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
$headers = $this->headers;
|
||||
if (! $this->hasHeader('host')
|
||||
&& $this->uri->getHost()
|
||||
) {
|
||||
$headers['Host'] = [$this->getHostFromUri()];
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeader($header)
|
||||
{
|
||||
if (! $this->hasHeader($header)) {
|
||||
if (strtolower($header) === 'host'
|
||||
&& $this->uri->getHost()
|
||||
) {
|
||||
return [$this->getHostFromUri()];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$header = $this->headerNames[strtolower($header)];
|
||||
|
||||
return $this->headers[$header];
|
||||
}
|
||||
}
|
87
vendor/zendframework/zend-diactoros/src/Request/ArraySerializer.php
vendored
Normal file
87
vendor/zendframework/zend-diactoros/src/Request/ArraySerializer.php
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Request;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use UnexpectedValueException;
|
||||
use Zend\Diactoros\Request;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Serialize or deserialize request messages to/from arrays.
|
||||
*
|
||||
* This class provides functionality for serializing a RequestInterface instance
|
||||
* to an array, as well as the reverse operation of creating a Request instance
|
||||
* from an array representing a message.
|
||||
*/
|
||||
final class ArraySerializer
|
||||
{
|
||||
/**
|
||||
* Serialize a request message to an array.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray(RequestInterface $request)
|
||||
{
|
||||
return [
|
||||
'method' => $request->getMethod(),
|
||||
'request_target' => $request->getRequestTarget(),
|
||||
'uri' => (string) $request->getUri(),
|
||||
'protocol_version' => $request->getProtocolVersion(),
|
||||
'headers' => $request->getHeaders(),
|
||||
'body' => (string) $request->getBody(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a request array to a request instance.
|
||||
*
|
||||
* @param array $serializedRequest
|
||||
* @return Request
|
||||
* @throws UnexpectedValueException when cannot deserialize response
|
||||
*/
|
||||
public static function fromArray(array $serializedRequest)
|
||||
{
|
||||
try {
|
||||
$uri = self::getValueFromKey($serializedRequest, 'uri');
|
||||
$method = self::getValueFromKey($serializedRequest, 'method');
|
||||
$body = new Stream('php://memory', 'wb+');
|
||||
$body->write(self::getValueFromKey($serializedRequest, 'body'));
|
||||
$headers = self::getValueFromKey($serializedRequest, 'headers');
|
||||
$requestTarget = self::getValueFromKey($serializedRequest, 'request_target');
|
||||
$protocolVersion = self::getValueFromKey($serializedRequest, 'protocol_version');
|
||||
|
||||
return (new Request($uri, $method, $body, $headers))
|
||||
->withRequestTarget($requestTarget)
|
||||
->withProtocolVersion($protocolVersion);
|
||||
} catch (\Exception $exception) {
|
||||
throw new UnexpectedValueException('Cannot deserialize request', null, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $key
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
private static function getValueFromKey(array $data, $key, $message = null)
|
||||
{
|
||||
if (isset($data[$key])) {
|
||||
return $data[$key];
|
||||
}
|
||||
if ($message === null) {
|
||||
$message = sprintf('Missing "%s" key in serialized request', $key);
|
||||
}
|
||||
throw new UnexpectedValueException($message);
|
||||
}
|
||||
}
|
154
vendor/zendframework/zend-diactoros/src/Request/Serializer.php
vendored
Normal file
154
vendor/zendframework/zend-diactoros/src/Request/Serializer.php
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Request;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use UnexpectedValueException;
|
||||
use Zend\Diactoros\AbstractSerializer;
|
||||
use Zend\Diactoros\Request;
|
||||
use Zend\Diactoros\Stream;
|
||||
use Zend\Diactoros\Uri;
|
||||
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Serialize (cast to string) or deserialize (cast string to Request) messages.
|
||||
*
|
||||
* This class provides functionality for serializing a RequestInterface instance
|
||||
* to a string, as well as the reverse operation of creating a Request instance
|
||||
* from a string/stream representing a message.
|
||||
*/
|
||||
final class Serializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* Deserialize a request string to a request instance.
|
||||
*
|
||||
* Internally, casts the message to a stream and invokes fromStream().
|
||||
*
|
||||
* @param string $message
|
||||
* @return Request
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromString($message)
|
||||
{
|
||||
$stream = new Stream('php://temp', 'wb+');
|
||||
$stream->write($message);
|
||||
return self::fromStream($stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a request stream to a request instance.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return Request
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromStream(StreamInterface $stream)
|
||||
{
|
||||
if (! $stream->isReadable() || ! $stream->isSeekable()) {
|
||||
throw new InvalidArgumentException('Message stream must be both readable and seekable');
|
||||
}
|
||||
|
||||
$stream->rewind();
|
||||
|
||||
list($method, $requestTarget, $version) = self::getRequestLine($stream);
|
||||
$uri = self::createUriFromRequestTarget($requestTarget);
|
||||
|
||||
list($headers, $body) = self::splitStream($stream);
|
||||
|
||||
return (new Request($uri, $method, $body, $headers))
|
||||
->withProtocolVersion($version)
|
||||
->withRequestTarget($requestTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a request message to a string.
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @return string
|
||||
*/
|
||||
public static function toString(RequestInterface $request)
|
||||
{
|
||||
$httpMethod = $request->getMethod();
|
||||
if (empty($httpMethod)) {
|
||||
throw new UnexpectedValueException('Object can not be serialized because HTTP method is empty');
|
||||
}
|
||||
$headers = self::serializeHeaders($request->getHeaders());
|
||||
$body = (string) $request->getBody();
|
||||
$format = '%s %s HTTP/%s%s%s';
|
||||
|
||||
if (! empty($headers)) {
|
||||
$headers = "\r\n" . $headers;
|
||||
}
|
||||
if (! empty($body)) {
|
||||
$headers .= "\r\n\r\n";
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
$format,
|
||||
$httpMethod,
|
||||
$request->getRequestTarget(),
|
||||
$request->getProtocolVersion(),
|
||||
$headers,
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the components of the request line.
|
||||
*
|
||||
* Retrieves the first line of the stream and parses it, raising an
|
||||
* exception if it does not follow specifications; if valid, returns a list
|
||||
* with the method, target, and version, in that order.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return array
|
||||
*/
|
||||
private static function getRequestLine(StreamInterface $stream)
|
||||
{
|
||||
$requestLine = self::getLine($stream);
|
||||
|
||||
if (! preg_match(
|
||||
'#^(?P<method>[!\#$%&\'*+.^_`|~a-zA-Z0-9-]+) (?P<target>[^\s]+) HTTP/(?P<version>[1-9]\d*\.\d+)$#',
|
||||
$requestLine,
|
||||
$matches
|
||||
)) {
|
||||
throw new UnexpectedValueException('Invalid request line detected');
|
||||
}
|
||||
|
||||
return [$matches['method'], $matches['target'], $matches['version']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a Uri instance based on the provided request target.
|
||||
*
|
||||
* If the request target is of authority or asterisk form, an empty Uri
|
||||
* instance is returned; otherwise, the value is used to create and return
|
||||
* a new Uri instance.
|
||||
*
|
||||
* @param string $requestTarget
|
||||
* @return Uri
|
||||
*/
|
||||
private static function createUriFromRequestTarget($requestTarget)
|
||||
{
|
||||
if (preg_match('#^https?://#', $requestTarget)) {
|
||||
return new Uri($requestTarget);
|
||||
}
|
||||
|
||||
if (preg_match('#^(\*|[^/])#', $requestTarget)) {
|
||||
return new Uri();
|
||||
}
|
||||
|
||||
return new Uri($requestTarget);
|
||||
}
|
||||
}
|
324
vendor/zendframework/zend-diactoros/src/RequestTrait.php
vendored
Normal file
324
vendor/zendframework/zend-diactoros/src/RequestTrait.php
vendored
Normal file
|
@ -0,0 +1,324 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
use function array_keys;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function strtolower;
|
||||
|
||||
/**
|
||||
* Trait with common request behaviors.
|
||||
*
|
||||
* Server and client-side requests differ slightly in how the Host header is
|
||||
* handled; on client-side, it should be calculated on-the-fly from the
|
||||
* composed URI (if present), while on server-side, it will be calculated from
|
||||
* the environment. As such, this trait exists to provide the common code
|
||||
* between both client-side and server-side requests, and each can then
|
||||
* use the headers functionality required by their implementations.
|
||||
*/
|
||||
trait RequestTrait
|
||||
{
|
||||
use MessageTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $method = '';
|
||||
|
||||
/**
|
||||
* The request-target, if it has been provided or calculated.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
private $requestTarget;
|
||||
|
||||
/**
|
||||
* @var UriInterface
|
||||
*/
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
* Initialize request state.
|
||||
*
|
||||
* Used by constructors.
|
||||
*
|
||||
* @param null|string|UriInterface $uri URI for the request, if any.
|
||||
* @param null|string $method HTTP method for the request, if any.
|
||||
* @param string|resource|StreamInterface $body Message body, if any.
|
||||
* @param array $headers Headers for the message, if any.
|
||||
* @throws InvalidArgumentException for any invalid value.
|
||||
*/
|
||||
private function initialize($uri = null, $method = null, $body = 'php://memory', array $headers = [])
|
||||
{
|
||||
$this->validateMethod($method);
|
||||
|
||||
$this->method = $method ?: '';
|
||||
$this->uri = $this->createUri($uri);
|
||||
$this->stream = $this->getStream($body, 'wb+');
|
||||
|
||||
$this->setHeaders($headers);
|
||||
|
||||
// per PSR-7: attempt to set the Host header from a provided URI if no
|
||||
// Host header is provided
|
||||
if (! $this->hasHeader('Host') && $this->uri->getHost()) {
|
||||
$this->headerNames['host'] = 'Host';
|
||||
$this->headers['Host'] = [$this->getHostFromUri()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a URI instance.
|
||||
*
|
||||
* If `$uri` is a already a `UriInterface` instance, returns it.
|
||||
*
|
||||
* If `$uri` is a string, passes it to the `Uri` constructor to return an
|
||||
* instance.
|
||||
*
|
||||
* If `$uri is null, creates and returns an empty `Uri` instance.
|
||||
*
|
||||
* Otherwise, it raises an exception.
|
||||
*
|
||||
* @param null|string|UriInterface $uri
|
||||
* @return UriInterface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function createUri($uri)
|
||||
{
|
||||
if ($uri instanceof UriInterface) {
|
||||
return $uri;
|
||||
}
|
||||
if (is_string($uri)) {
|
||||
return new Uri($uri);
|
||||
}
|
||||
if ($uri === null) {
|
||||
return new Uri();
|
||||
}
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid URI provided; must be null, a string, or a Psr\Http\Message\UriInterface instance'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the message's request target.
|
||||
*
|
||||
* Retrieves the message's request-target either as it will appear (for
|
||||
* clients), as it appeared at request (for servers), or as it was
|
||||
* specified for the instance (see withRequestTarget()).
|
||||
*
|
||||
* In most cases, this will be the origin-form of the composed URI,
|
||||
* unless a value was provided to the concrete implementation (see
|
||||
* withRequestTarget() below).
|
||||
*
|
||||
* If no URI is available, and no request-target has been specifically
|
||||
* provided, this method MUST return the string "/".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestTarget()
|
||||
{
|
||||
if (null !== $this->requestTarget) {
|
||||
return $this->requestTarget;
|
||||
}
|
||||
|
||||
$target = $this->uri->getPath();
|
||||
if ($this->uri->getQuery()) {
|
||||
$target .= '?' . $this->uri->getQuery();
|
||||
}
|
||||
|
||||
if (empty($target)) {
|
||||
$target = '/';
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with a specific request-target.
|
||||
*
|
||||
* If the request needs a non-origin-form request-target — e.g., for
|
||||
* specifying an absolute-form, authority-form, or asterisk-form —
|
||||
* this method may be used to create an instance with the specified
|
||||
* request-target, verbatim.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return a new instance that has the
|
||||
* changed request target.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various
|
||||
* request-target forms allowed in request messages)
|
||||
* @param mixed $requestTarget
|
||||
* @return static
|
||||
* @throws InvalidArgumentException if the request target is invalid.
|
||||
*/
|
||||
public function withRequestTarget($requestTarget)
|
||||
{
|
||||
if (preg_match('#\s#', $requestTarget)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid request target provided; cannot contain whitespace'
|
||||
);
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->requestTarget = $requestTarget;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the HTTP method of the request.
|
||||
*
|
||||
* @return string Returns the request method.
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance with the provided HTTP method.
|
||||
*
|
||||
* While HTTP method names are typically all uppercase characters, HTTP
|
||||
* method names are case-sensitive and thus implementations SHOULD NOT
|
||||
* modify the given string.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* changed request method.
|
||||
*
|
||||
* @param string $method Case-insensitive method.
|
||||
* @return static
|
||||
* @throws InvalidArgumentException for invalid HTTP methods.
|
||||
*/
|
||||
public function withMethod($method)
|
||||
{
|
||||
$this->validateMethod($method);
|
||||
$new = clone $this;
|
||||
$new->method = $method;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URI instance.
|
||||
*
|
||||
* This method MUST return a UriInterface instance.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3986#section-4.3
|
||||
* @return UriInterface Returns a UriInterface instance
|
||||
* representing the URI of the request, if any.
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance with the provided URI.
|
||||
*
|
||||
* This method will update the Host header of the returned request by
|
||||
* default if the URI contains a host component. If the URI does not
|
||||
* contain a host component, any pre-existing Host header will be carried
|
||||
* over to the returned request.
|
||||
*
|
||||
* You can opt-in to preserving the original state of the Host header by
|
||||
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
|
||||
* `true`, the returned request will not update the Host header of the
|
||||
* returned message -- even if the message contains no Host header. This
|
||||
* means that a call to `getHeader('Host')` on the original request MUST
|
||||
* equal the return value of a call to `getHeader('Host')` on the returned
|
||||
* request.
|
||||
*
|
||||
* This method MUST be implemented in such a way as to retain the
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new UriInterface instance.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3986#section-4.3
|
||||
* @param UriInterface $uri New request URI to use.
|
||||
* @param bool $preserveHost Preserve the original state of the Host header.
|
||||
* @return static
|
||||
*/
|
||||
public function withUri(UriInterface $uri, $preserveHost = false)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->uri = $uri;
|
||||
|
||||
if ($preserveHost && $this->hasHeader('Host')) {
|
||||
return $new;
|
||||
}
|
||||
|
||||
if (! $uri->getHost()) {
|
||||
return $new;
|
||||
}
|
||||
|
||||
$host = $uri->getHost();
|
||||
if ($uri->getPort()) {
|
||||
$host .= ':' . $uri->getPort();
|
||||
}
|
||||
|
||||
$new->headerNames['host'] = 'Host';
|
||||
|
||||
// Remove an existing host header if present, regardless of current
|
||||
// de-normalization of the header name.
|
||||
// @see https://github.com/zendframework/zend-diactoros/issues/91
|
||||
foreach (array_keys($new->headers) as $header) {
|
||||
if (strtolower($header) === 'host') {
|
||||
unset($new->headers[$header]);
|
||||
}
|
||||
}
|
||||
|
||||
$new->headers['Host'] = [$host];
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the HTTP method
|
||||
*
|
||||
* @param null|string $method
|
||||
* @throws InvalidArgumentException on invalid HTTP method.
|
||||
*/
|
||||
private function validateMethod($method)
|
||||
{
|
||||
if (null === $method) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_string($method)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported HTTP method; must be a string, received %s',
|
||||
(is_object($method) ? get_class($method) : gettype($method))
|
||||
));
|
||||
}
|
||||
|
||||
if (! preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported HTTP method "%s" provided',
|
||||
$method
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the host from the URI instance
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHostFromUri()
|
||||
{
|
||||
$host = $this->uri->getHost();
|
||||
$host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : '';
|
||||
return $host;
|
||||
}
|
||||
}
|
198
vendor/zendframework/zend-diactoros/src/Response.php
vendored
Normal file
198
vendor/zendframework/zend-diactoros/src/Response.php
vendored
Normal file
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
use function gettype;
|
||||
use function is_float;
|
||||
use function is_numeric;
|
||||
use function is_scalar;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* HTTP response encapsulation.
|
||||
*
|
||||
* Responses are considered immutable; all methods that might change state are
|
||||
* implemented such that they retain the internal state of the current
|
||||
* message and return a new instance that contains the changed state.
|
||||
*/
|
||||
class Response implements ResponseInterface
|
||||
{
|
||||
use MessageTrait;
|
||||
|
||||
const MIN_STATUS_CODE_VALUE = 100;
|
||||
const MAX_STATUS_CODE_VALUE = 599;
|
||||
|
||||
/**
|
||||
* Map of standard HTTP status code/reason phrases
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $phrases = [
|
||||
// INFORMATIONAL CODES
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
102 => 'Processing',
|
||||
103 => 'Early Hints',
|
||||
// SUCCESS CODES
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
207 => 'Multi-Status',
|
||||
208 => 'Already Reported',
|
||||
226 => 'IM Used',
|
||||
// REDIRECTION CODES
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
306 => 'Switch Proxy', // Deprecated to 306 => '(Unused)'
|
||||
307 => 'Temporary Redirect',
|
||||
308 => 'Permanent Redirect',
|
||||
// CLIENT ERROR
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Payload Too Large',
|
||||
414 => 'URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
418 => 'I\'m a teapot',
|
||||
421 => 'Misdirected Request',
|
||||
422 => 'Unprocessable Entity',
|
||||
423 => 'Locked',
|
||||
424 => 'Failed Dependency',
|
||||
425 => 'Too Early',
|
||||
426 => 'Upgrade Required',
|
||||
428 => 'Precondition Required',
|
||||
429 => 'Too Many Requests',
|
||||
431 => 'Request Header Fields Too Large',
|
||||
444 => 'Connection Closed Without Response',
|
||||
451 => 'Unavailable For Legal Reasons',
|
||||
// SERVER ERROR
|
||||
499 => 'Client Closed Request',
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
506 => 'Variant Also Negotiates',
|
||||
507 => 'Insufficient Storage',
|
||||
508 => 'Loop Detected',
|
||||
510 => 'Not Extended',
|
||||
511 => 'Network Authentication Required',
|
||||
599 => 'Network Connect Timeout Error',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $reasonPhrase;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $statusCode;
|
||||
|
||||
/**
|
||||
* @param string|resource|StreamInterface $body Stream identifier and/or actual stream resource
|
||||
* @param int $status Status code for the response, if any.
|
||||
* @param array $headers Headers for the response, if any.
|
||||
* @throws InvalidArgumentException on any invalid element.
|
||||
*/
|
||||
public function __construct($body = 'php://memory', $status = 200, array $headers = [])
|
||||
{
|
||||
$this->setStatusCode($status);
|
||||
$this->stream = $this->getStream($body, 'wb+');
|
||||
$this->setHeaders($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withStatus($code, $reasonPhrase = '')
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->setStatusCode($code, $reasonPhrase);
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a valid status code.
|
||||
*
|
||||
* @param int $code
|
||||
* @param string $reasonPhrase
|
||||
* @throws InvalidArgumentException on an invalid status code.
|
||||
*/
|
||||
private function setStatusCode($code, $reasonPhrase = '')
|
||||
{
|
||||
if (! is_numeric($code)
|
||||
|| is_float($code)
|
||||
|| $code < static::MIN_STATUS_CODE_VALUE
|
||||
|| $code > static::MAX_STATUS_CODE_VALUE
|
||||
) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
|
||||
is_scalar($code) ? $code : gettype($code),
|
||||
static::MIN_STATUS_CODE_VALUE,
|
||||
static::MAX_STATUS_CODE_VALUE
|
||||
));
|
||||
}
|
||||
|
||||
if (! is_string($reasonPhrase)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported response reason phrase; must be a string, received %s',
|
||||
is_object($reasonPhrase) ? get_class($reasonPhrase) : gettype($reasonPhrase)
|
||||
));
|
||||
}
|
||||
|
||||
if ($reasonPhrase === '' && isset($this->phrases[$code])) {
|
||||
$reasonPhrase = $this->phrases[$code];
|
||||
}
|
||||
|
||||
$this->reasonPhrase = $reasonPhrase;
|
||||
$this->statusCode = (int) $code;
|
||||
}
|
||||
}
|
86
vendor/zendframework/zend-diactoros/src/Response/ArraySerializer.php
vendored
Normal file
86
vendor/zendframework/zend-diactoros/src/Response/ArraySerializer.php
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use UnexpectedValueException;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Serialize or deserialize response messages to/from arrays.
|
||||
*
|
||||
* This class provides functionality for serializing a ResponseInterface instance
|
||||
* to an array, as well as the reverse operation of creating a Response instance
|
||||
* from an array representing a message.
|
||||
*/
|
||||
final class ArraySerializer
|
||||
{
|
||||
/**
|
||||
* Serialize a response message to an array.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray(ResponseInterface $response)
|
||||
{
|
||||
return [
|
||||
'status_code' => $response->getStatusCode(),
|
||||
'reason_phrase' => $response->getReasonPhrase(),
|
||||
'protocol_version' => $response->getProtocolVersion(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'body' => (string) $response->getBody(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a response array to a response instance.
|
||||
*
|
||||
* @param array $serializedResponse
|
||||
* @return Response
|
||||
* @throws UnexpectedValueException when cannot deserialize response
|
||||
*/
|
||||
public static function fromArray(array $serializedResponse)
|
||||
{
|
||||
try {
|
||||
$body = new Stream('php://memory', 'wb+');
|
||||
$body->write(self::getValueFromKey($serializedResponse, 'body'));
|
||||
|
||||
$statusCode = self::getValueFromKey($serializedResponse, 'status_code');
|
||||
$headers = self::getValueFromKey($serializedResponse, 'headers');
|
||||
$protocolVersion = self::getValueFromKey($serializedResponse, 'protocol_version');
|
||||
$reasonPhrase = self::getValueFromKey($serializedResponse, 'reason_phrase');
|
||||
|
||||
return (new Response($body, $statusCode, $headers))
|
||||
->withProtocolVersion($protocolVersion)
|
||||
->withStatus($statusCode, $reasonPhrase);
|
||||
} catch (\Exception $exception) {
|
||||
throw new UnexpectedValueException('Cannot deserialize response', null, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $key
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
private static function getValueFromKey(array $data, $key, $message = null)
|
||||
{
|
||||
if (isset($data[$key])) {
|
||||
return $data[$key];
|
||||
}
|
||||
if ($message === null) {
|
||||
$message = sprintf('Missing "%s" key in serialized request', $key);
|
||||
}
|
||||
throw new UnexpectedValueException($message);
|
||||
}
|
||||
}
|
34
vendor/zendframework/zend-diactoros/src/Response/EmitterInterface.php
vendored
Normal file
34
vendor/zendframework/zend-diactoros/src/Response/EmitterInterface.php
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.8.0. The package zendframework/zend-httphandlerrunner
|
||||
* now provides this functionality.
|
||||
*/
|
||||
interface EmitterInterface
|
||||
{
|
||||
/**
|
||||
* Emit a response.
|
||||
*
|
||||
* Emits a response, including status line, headers, and the message body,
|
||||
* according to the environment.
|
||||
*
|
||||
* Implementations of this method may be written in such a way as to have
|
||||
* side effects, such as usage of header() or pushing output to the
|
||||
* output buffer.
|
||||
*
|
||||
* Implementations MAY raise exceptions if they are unable to emit the
|
||||
* response; e.g., if headers have already been sent.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function emit(ResponseInterface $response);
|
||||
}
|
42
vendor/zendframework/zend-diactoros/src/Response/EmptyResponse.php
vendored
Normal file
42
vendor/zendframework/zend-diactoros/src/Response/EmptyResponse.php
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
/**
|
||||
* A class representing empty HTTP responses.
|
||||
*/
|
||||
class EmptyResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Create an empty response with the given status code.
|
||||
*
|
||||
* @param int $status Status code for the response, if any.
|
||||
* @param array $headers Headers for the response, if any.
|
||||
*/
|
||||
public function __construct($status = 204, array $headers = [])
|
||||
{
|
||||
$body = new Stream('php://temp', 'r');
|
||||
parent::__construct($body, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty response with the given headers.
|
||||
*
|
||||
* @param array $headers Headers for the response.
|
||||
* @return EmptyResponse
|
||||
*/
|
||||
public static function withHeaders(array $headers)
|
||||
{
|
||||
return new static(204, $headers);
|
||||
}
|
||||
}
|
80
vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php
vendored
Normal file
80
vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* HTML response.
|
||||
*
|
||||
* Allows creating a response by passing an HTML string to the constructor;
|
||||
* by default, sets a status code of 200 and sets the Content-Type header to
|
||||
* text/html.
|
||||
*/
|
||||
class HtmlResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Create an HTML response.
|
||||
*
|
||||
* Produces an HTML response with a Content-Type of text/html and a default
|
||||
* status of 200.
|
||||
*
|
||||
* @param string|StreamInterface $html HTML or stream for the message body.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @throws InvalidArgumentException if $html is neither a string or stream.
|
||||
*/
|
||||
public function __construct($html, $status = 200, array $headers = [])
|
||||
{
|
||||
parent::__construct(
|
||||
$this->createBody($html),
|
||||
$status,
|
||||
$this->injectContentType('text/html; charset=utf-8', $headers)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the message body.
|
||||
*
|
||||
* @param string|StreamInterface $html
|
||||
* @return StreamInterface
|
||||
* @throws InvalidArgumentException if $html is neither a string or stream.
|
||||
*/
|
||||
private function createBody($html)
|
||||
{
|
||||
if ($html instanceof StreamInterface) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
if (! is_string($html)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid content (%s) provided to %s',
|
||||
(is_object($html) ? get_class($html) : gettype($html)),
|
||||
__CLASS__
|
||||
));
|
||||
}
|
||||
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($html);
|
||||
$body->rewind();
|
||||
return $body;
|
||||
}
|
||||
}
|
37
vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php
vendored
Normal file
37
vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use function array_keys;
|
||||
use function array_reduce;
|
||||
use function strtolower;
|
||||
|
||||
trait InjectContentTypeTrait
|
||||
{
|
||||
/**
|
||||
* Inject the provided Content-Type, if none is already present.
|
||||
*
|
||||
* @param string $contentType
|
||||
* @param array $headers
|
||||
* @return array Headers with injected Content-Type
|
||||
*/
|
||||
private function injectContentType($contentType, array $headers)
|
||||
{
|
||||
$hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
|
||||
return $carry ?: (strtolower($item) === 'content-type');
|
||||
}, false);
|
||||
|
||||
if (! $hasContentType) {
|
||||
$headers['content-type'] = [$contentType];
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
}
|
198
vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php
vendored
Normal file
198
vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php
vendored
Normal file
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function json_encode;
|
||||
use function json_last_error;
|
||||
use function json_last_error_msg;
|
||||
use function sprintf;
|
||||
|
||||
use const JSON_ERROR_NONE;
|
||||
|
||||
/**
|
||||
* JSON response.
|
||||
*
|
||||
* Allows creating a response by passing data to the constructor; by default,
|
||||
* serializes the data to JSON, sets a status code of 200 and sets the
|
||||
* Content-Type header to application/json.
|
||||
*/
|
||||
class JsonResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Default flags for json_encode; value of:
|
||||
*
|
||||
* <code>
|
||||
* JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES
|
||||
* </code>
|
||||
*
|
||||
* @const int
|
||||
*/
|
||||
const DEFAULT_JSON_FLAGS = 79;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $payload;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $encodingOptions;
|
||||
|
||||
/**
|
||||
* Create a JSON response with the given data.
|
||||
*
|
||||
* Default JSON encoding is performed with the following options, which
|
||||
* produces RFC4627-compliant JSON, capable of embedding into HTML.
|
||||
*
|
||||
* - JSON_HEX_TAG
|
||||
* - JSON_HEX_APOS
|
||||
* - JSON_HEX_AMP
|
||||
* - JSON_HEX_QUOT
|
||||
* - JSON_UNESCAPED_SLASHES
|
||||
*
|
||||
* @param mixed $data Data to convert to JSON.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @param int $encodingOptions JSON encoding options to use.
|
||||
* @throws InvalidArgumentException if unable to encode the $data to JSON.
|
||||
*/
|
||||
public function __construct(
|
||||
$data,
|
||||
$status = 200,
|
||||
array $headers = [],
|
||||
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||
) {
|
||||
$this->setPayload($data);
|
||||
$this->encodingOptions = $encodingOptions;
|
||||
|
||||
$json = $this->jsonEncode($data, $this->encodingOptions);
|
||||
$body = $this->createBodyFromJson($json);
|
||||
|
||||
$headers = $this->injectContentType('application/json', $headers);
|
||||
|
||||
parent::__construct($body, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function withPayload($data)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->setPayload($data);
|
||||
return $this->updateBodyFor($new);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getEncodingOptions()
|
||||
{
|
||||
return $this->encodingOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $encodingOptions
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function withEncodingOptions($encodingOptions)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->encodingOptions = $encodingOptions;
|
||||
return $this->updateBodyFor($new);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $json
|
||||
*
|
||||
* @return Stream
|
||||
*/
|
||||
private function createBodyFromJson($json)
|
||||
{
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($json);
|
||||
$body->rewind();
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the provided data to JSON.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $encodingOptions
|
||||
* @return string
|
||||
* @throws InvalidArgumentException if unable to encode the $data to JSON.
|
||||
*/
|
||||
private function jsonEncode($data, $encodingOptions)
|
||||
{
|
||||
if (is_resource($data)) {
|
||||
throw new InvalidArgumentException('Cannot JSON encode resources');
|
||||
}
|
||||
|
||||
// Clear json_last_error()
|
||||
json_encode(null);
|
||||
|
||||
$json = json_encode($data, $encodingOptions);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unable to encode data to JSON in %s: %s',
|
||||
__CLASS__,
|
||||
json_last_error_msg()
|
||||
));
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*/
|
||||
private function setPayload($data)
|
||||
{
|
||||
if (is_object($data)) {
|
||||
$data = clone $data;
|
||||
}
|
||||
|
||||
$this->payload = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the response body for the given instance.
|
||||
*
|
||||
* @param self $toUpdate Instance to update.
|
||||
* @return JsonResponse Returns a new instance with an updated body.
|
||||
*/
|
||||
private function updateBodyFor(self $toUpdate)
|
||||
{
|
||||
$json = $this->jsonEncode($toUpdate->payload, $toUpdate->encodingOptions);
|
||||
$body = $this->createBodyFromJson($json);
|
||||
return $toUpdate->withBody($body);
|
||||
}
|
||||
}
|
52
vendor/zendframework/zend-diactoros/src/Response/RedirectResponse.php
vendored
Normal file
52
vendor/zendframework/zend-diactoros/src/Response/RedirectResponse.php
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Produce a redirect response.
|
||||
*/
|
||||
class RedirectResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Create a redirect response.
|
||||
*
|
||||
* Produces a redirect response with a Location header and the given status
|
||||
* (302 by default).
|
||||
*
|
||||
* Note: this method overwrites the `location` $headers value.
|
||||
*
|
||||
* @param string|UriInterface $uri URI for the Location header.
|
||||
* @param int $status Integer status code for the redirect; 302 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
*/
|
||||
public function __construct($uri, $status = 302, array $headers = [])
|
||||
{
|
||||
if (! is_string($uri) && ! $uri instanceof UriInterface) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
|
||||
__CLASS__,
|
||||
(is_object($uri) ? get_class($uri) : gettype($uri))
|
||||
));
|
||||
}
|
||||
|
||||
$headers['location'] = [(string) $uri];
|
||||
parent::__construct('php://temp', $status, $headers);
|
||||
}
|
||||
}
|
46
vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php
vendored
Normal file
46
vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.8.0. The package zendframework/zend-httphandlerrunner
|
||||
* now provides this functionality.
|
||||
*/
|
||||
class SapiEmitter implements EmitterInterface
|
||||
{
|
||||
use SapiEmitterTrait;
|
||||
|
||||
/**
|
||||
* Emits a response for a PHP SAPI environment.
|
||||
*
|
||||
* Emits the status line and headers via the header() function, and the
|
||||
* body content via the output buffer.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function emit(ResponseInterface $response)
|
||||
{
|
||||
$this->assertNoPreviousOutput();
|
||||
|
||||
$this->emitHeaders($response);
|
||||
$this->emitStatusLine($response);
|
||||
$this->emitBody($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the message body.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
private function emitBody(ResponseInterface $response)
|
||||
{
|
||||
echo $response->getBody();
|
||||
}
|
||||
}
|
112
vendor/zendframework/zend-diactoros/src/Response/SapiEmitterTrait.php
vendored
Normal file
112
vendor/zendframework/zend-diactoros/src/Response/SapiEmitterTrait.php
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RuntimeException;
|
||||
|
||||
use function ob_get_length;
|
||||
use function ob_get_level;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function ucwords;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.8.0. The package zendframework/zend-httphandlerrunner
|
||||
* now provides this functionality.
|
||||
*/
|
||||
trait SapiEmitterTrait
|
||||
{
|
||||
/**
|
||||
* Checks to see if content has previously been sent.
|
||||
*
|
||||
* If either headers have been sent or the output buffer contains content,
|
||||
* raises an exception.
|
||||
*
|
||||
* @throws RuntimeException if headers have already been sent.
|
||||
* @throws RuntimeException if output is present in the output buffer.
|
||||
*/
|
||||
private function assertNoPreviousOutput()
|
||||
{
|
||||
if (headers_sent()) {
|
||||
throw new RuntimeException('Unable to emit response; headers already sent');
|
||||
}
|
||||
|
||||
if (ob_get_level() > 0 && ob_get_length() > 0) {
|
||||
throw new RuntimeException('Output has been emitted previously; cannot emit response');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the status line.
|
||||
*
|
||||
* Emits the status line using the protocol version and status code from
|
||||
* the response; if a reason phrase is available, it, too, is emitted.
|
||||
*
|
||||
* It is important to mention that this method should be called after
|
||||
* `emitHeaders()` in order to prevent PHP from changing the status code of
|
||||
* the emitted response.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @see \Zend\Diactoros\Response\SapiEmitterTrait::emitHeaders()
|
||||
*/
|
||||
private function emitStatusLine(ResponseInterface $response)
|
||||
{
|
||||
$reasonPhrase = $response->getReasonPhrase();
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
header(sprintf(
|
||||
'HTTP/%s %d%s',
|
||||
$response->getProtocolVersion(),
|
||||
$statusCode,
|
||||
($reasonPhrase ? ' ' . $reasonPhrase : '')
|
||||
), true, $statusCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit response headers.
|
||||
*
|
||||
* Loops through each header, emitting each; if the header value
|
||||
* is an array with multiple values, ensures that each is sent
|
||||
* in such a way as to create aggregate headers (instead of replace
|
||||
* the previous).
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
private function emitHeaders(ResponseInterface $response)
|
||||
{
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
foreach ($response->getHeaders() as $header => $values) {
|
||||
$name = $this->filterHeader($header);
|
||||
$first = $name === 'Set-Cookie' ? false : true;
|
||||
foreach ($values as $value) {
|
||||
header(sprintf(
|
||||
'%s: %s',
|
||||
$name,
|
||||
$value
|
||||
), $first, $statusCode);
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a header name to wordcase
|
||||
*
|
||||
* @param string $header
|
||||
* @return string
|
||||
*/
|
||||
private function filterHeader($header)
|
||||
{
|
||||
$filtered = str_replace('-', ' ', $header);
|
||||
$filtered = ucwords($filtered);
|
||||
return str_replace(' ', '-', $filtered);
|
||||
}
|
||||
}
|
134
vendor/zendframework/zend-diactoros/src/Response/SapiStreamEmitter.php
vendored
Normal file
134
vendor/zendframework/zend-diactoros/src/Response/SapiStreamEmitter.php
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use function is_array;
|
||||
use function preg_match;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.8.0. The package zendframework/zend-httphandlerrunner
|
||||
* now provides this functionality.
|
||||
*/
|
||||
class SapiStreamEmitter implements EmitterInterface
|
||||
{
|
||||
use SapiEmitterTrait;
|
||||
|
||||
/**
|
||||
* Emits a response for a PHP SAPI environment.
|
||||
*
|
||||
* Emits the status line and headers via the header() function, and the
|
||||
* body content via the output buffer.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param int $maxBufferLength Maximum output buffering size for each iteration
|
||||
*/
|
||||
public function emit(ResponseInterface $response, $maxBufferLength = 8192)
|
||||
{
|
||||
$this->assertNoPreviousOutput();
|
||||
$this->emitHeaders($response);
|
||||
$this->emitStatusLine($response);
|
||||
|
||||
$range = $this->parseContentRange($response->getHeaderLine('Content-Range'));
|
||||
|
||||
if (is_array($range) && $range[0] === 'bytes') {
|
||||
$this->emitBodyRange($range, $response, $maxBufferLength);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emitBody($response, $maxBufferLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the message body.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param int $maxBufferLength
|
||||
*/
|
||||
private function emitBody(ResponseInterface $response, $maxBufferLength)
|
||||
{
|
||||
$body = $response->getBody();
|
||||
|
||||
if ($body->isSeekable()) {
|
||||
$body->rewind();
|
||||
}
|
||||
|
||||
if (! $body->isReadable()) {
|
||||
echo $body;
|
||||
return;
|
||||
}
|
||||
|
||||
while (! $body->eof()) {
|
||||
echo $body->read($maxBufferLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a range of the message body.
|
||||
*
|
||||
* @param array $range
|
||||
* @param ResponseInterface $response
|
||||
* @param int $maxBufferLength
|
||||
*/
|
||||
private function emitBodyRange(array $range, ResponseInterface $response, $maxBufferLength)
|
||||
{
|
||||
list($unit, $first, $last, $length) = $range;
|
||||
|
||||
$body = $response->getBody();
|
||||
|
||||
$length = $last - $first + 1;
|
||||
|
||||
if ($body->isSeekable()) {
|
||||
$body->seek($first);
|
||||
|
||||
$first = 0;
|
||||
}
|
||||
|
||||
if (! $body->isReadable()) {
|
||||
echo substr($body->getContents(), $first, $length);
|
||||
return;
|
||||
}
|
||||
|
||||
$remaining = $length;
|
||||
|
||||
while ($remaining >= $maxBufferLength && ! $body->eof()) {
|
||||
$contents = $body->read($maxBufferLength);
|
||||
$remaining -= strlen($contents);
|
||||
|
||||
echo $contents;
|
||||
}
|
||||
|
||||
if ($remaining > 0 && ! $body->eof()) {
|
||||
echo $body->read($remaining);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse content-range header
|
||||
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
|
||||
*
|
||||
* @param string $header
|
||||
* @return false|array [unit, first, last, length]; returns false if no
|
||||
* content range or an invalid content range is provided
|
||||
*/
|
||||
private function parseContentRange($header)
|
||||
{
|
||||
if (preg_match('/(?P<unit>[\w]+)\s+(?P<first>\d+)-(?P<last>\d+)\/(?P<length>\d+|\*)/', $header, $matches)) {
|
||||
return [
|
||||
$matches['unit'],
|
||||
(int) $matches['first'],
|
||||
(int) $matches['last'],
|
||||
$matches['length'] === '*' ? '*' : (int) $matches['length'],
|
||||
];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
111
vendor/zendframework/zend-diactoros/src/Response/Serializer.php
vendored
Normal file
111
vendor/zendframework/zend-diactoros/src/Response/Serializer.php
vendored
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use UnexpectedValueException;
|
||||
use Zend\Diactoros\AbstractSerializer;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
|
||||
final class Serializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* Deserialize a response string to a response instance.
|
||||
*
|
||||
* @param string $message
|
||||
* @return Response
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromString($message)
|
||||
{
|
||||
$stream = new Stream('php://temp', 'wb+');
|
||||
$stream->write($message);
|
||||
return static::fromStream($stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a response from a stream.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return Response
|
||||
* @throws InvalidArgumentException when the stream is not readable.
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromStream(StreamInterface $stream)
|
||||
{
|
||||
if (! $stream->isReadable() || ! $stream->isSeekable()) {
|
||||
throw new InvalidArgumentException('Message stream must be both readable and seekable');
|
||||
}
|
||||
|
||||
$stream->rewind();
|
||||
|
||||
list($version, $status, $reasonPhrase) = self::getStatusLine($stream);
|
||||
list($headers, $body) = self::splitStream($stream);
|
||||
|
||||
return (new Response($body, $status, $headers))
|
||||
->withProtocolVersion($version)
|
||||
->withStatus((int) $status, $reasonPhrase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string representation of a response.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @return string
|
||||
*/
|
||||
public static function toString(ResponseInterface $response)
|
||||
{
|
||||
$reasonPhrase = $response->getReasonPhrase();
|
||||
$headers = self::serializeHeaders($response->getHeaders());
|
||||
$body = (string) $response->getBody();
|
||||
$format = 'HTTP/%s %d%s%s%s';
|
||||
|
||||
if (! empty($headers)) {
|
||||
$headers = "\r\n" . $headers;
|
||||
}
|
||||
|
||||
$headers .= "\r\n\r\n";
|
||||
|
||||
return sprintf(
|
||||
$format,
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
($reasonPhrase ? ' ' . $reasonPhrase : ''),
|
||||
$headers,
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the status line for the message.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return array Array with three elements: 0 => version, 1 => status, 2 => reason
|
||||
* @throws UnexpectedValueException if line is malformed
|
||||
*/
|
||||
private static function getStatusLine(StreamInterface $stream)
|
||||
{
|
||||
$line = self::getLine($stream);
|
||||
|
||||
if (! preg_match(
|
||||
'#^HTTP/(?P<version>[1-9]\d*\.\d) (?P<status>[1-5]\d{2})(\s+(?P<reason>.+))?$#',
|
||||
$line,
|
||||
$matches
|
||||
)) {
|
||||
throw new UnexpectedValueException('No status line detected');
|
||||
}
|
||||
|
||||
return [$matches['version'], $matches['status'], isset($matches['reason']) ? $matches['reason'] : ''];
|
||||
}
|
||||
}
|
80
vendor/zendframework/zend-diactoros/src/Response/TextResponse.php
vendored
Normal file
80
vendor/zendframework/zend-diactoros/src/Response/TextResponse.php
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Plain text response.
|
||||
*
|
||||
* Allows creating a response by passing a string to the constructor;
|
||||
* by default, sets a status code of 200 and sets the Content-Type header to
|
||||
* text/plain.
|
||||
*/
|
||||
class TextResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Create a plain text response.
|
||||
*
|
||||
* Produces a text response with a Content-Type of text/plain and a default
|
||||
* status of 200.
|
||||
*
|
||||
* @param string|StreamInterface $text String or stream for the message body.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @throws InvalidArgumentException if $text is neither a string or stream.
|
||||
*/
|
||||
public function __construct($text, $status = 200, array $headers = [])
|
||||
{
|
||||
parent::__construct(
|
||||
$this->createBody($text),
|
||||
$status,
|
||||
$this->injectContentType('text/plain; charset=utf-8', $headers)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the message body.
|
||||
*
|
||||
* @param string|StreamInterface $text
|
||||
* @return StreamInterface
|
||||
* @throws InvalidArgumentException if $html is neither a string or stream.
|
||||
*/
|
||||
private function createBody($text)
|
||||
{
|
||||
if ($text instanceof StreamInterface) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
if (! is_string($text)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid content (%s) provided to %s',
|
||||
(is_object($text) ? get_class($text) : gettype($text)),
|
||||
__CLASS__
|
||||
));
|
||||
}
|
||||
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($text);
|
||||
$body->rewind();
|
||||
return $body;
|
||||
}
|
||||
}
|
80
vendor/zendframework/zend-diactoros/src/Response/XmlResponse.php
vendored
Normal file
80
vendor/zendframework/zend-diactoros/src/Response/XmlResponse.php
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* XML response.
|
||||
*
|
||||
* Allows creating a response by passing an XML string to the constructor; by default,
|
||||
* sets a status code of 200 and sets the Content-Type header to application/xml.
|
||||
*/
|
||||
class XmlResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Create an XML response.
|
||||
*
|
||||
* Produces an XML response with a Content-Type of application/xml and a default
|
||||
* status of 200.
|
||||
*
|
||||
* @param string|StreamInterface $xml String or stream for the message body.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @throws InvalidArgumentException if $text is neither a string or stream.
|
||||
*/
|
||||
public function __construct(
|
||||
$xml,
|
||||
$status = 200,
|
||||
array $headers = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$this->createBody($xml),
|
||||
$status,
|
||||
$this->injectContentType('application/xml; charset=utf-8', $headers)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the message body.
|
||||
*
|
||||
* @param string|StreamInterface $xml
|
||||
* @return StreamInterface
|
||||
* @throws InvalidArgumentException if $xml is neither a string or stream.
|
||||
*/
|
||||
private function createBody($xml)
|
||||
{
|
||||
if ($xml instanceof StreamInterface) {
|
||||
return $xml;
|
||||
}
|
||||
|
||||
if (! is_string($xml)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid content (%s) provided to %s',
|
||||
(is_object($xml) ? get_class($xml) : gettype($xml)),
|
||||
__CLASS__
|
||||
));
|
||||
}
|
||||
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($xml);
|
||||
$body->rewind();
|
||||
return $body;
|
||||
}
|
||||
}
|
185
vendor/zendframework/zend-diactoros/src/Server.php
vendored
Normal file
185
vendor/zendframework/zend-diactoros/src/Server.php
vendored
Normal file
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use OutOfBoundsException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use function property_exists;
|
||||
|
||||
/**
|
||||
* "Serve" incoming HTTP requests
|
||||
*
|
||||
* Given a callback, takes an incoming request, dispatches it to the
|
||||
* callback, and then sends a response.
|
||||
*
|
||||
* @deprecated since 1.8.0. We recommend using the `RequestHandlerRunner` class
|
||||
* from the zendframework/zend-httphandlerrunner package instead.
|
||||
*/
|
||||
class Server
|
||||
{
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $callback;
|
||||
|
||||
/**
|
||||
* Response emitter to use; by default, uses Response\SapiEmitter.
|
||||
*
|
||||
* @var Response\EmitterInterface
|
||||
*/
|
||||
private $emitter;
|
||||
|
||||
/**
|
||||
* @var ServerRequestInterface
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Given a callback, a request, and a response, we can create a server.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param ServerRequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function __construct(
|
||||
callable $callback,
|
||||
ServerRequestInterface $request,
|
||||
ResponseInterface $response
|
||||
) {
|
||||
$this->callback = $callback;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow retrieving the request, response and callback as properties
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @throws OutOfBoundsException for invalid properties
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (! property_exists($this, $name)) {
|
||||
throw new OutOfBoundsException('Cannot retrieve arbitrary properties from server');
|
||||
}
|
||||
return $this->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alternate response emitter to use.
|
||||
*
|
||||
* @param Response\EmitterInterface $emitter
|
||||
*/
|
||||
public function setEmitter(Response\EmitterInterface $emitter)
|
||||
{
|
||||
$this->emitter = $emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Server instance
|
||||
*
|
||||
* Creates a server instance from the callback and the following
|
||||
* PHP environmental values:
|
||||
*
|
||||
* - server; typically this will be the $_SERVER superglobal
|
||||
* - query; typically this will be the $_GET superglobal
|
||||
* - body; typically this will be the $_POST superglobal
|
||||
* - cookies; typically this will be the $_COOKIE superglobal
|
||||
* - files; typically this will be the $_FILES superglobal
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param array $server
|
||||
* @param array $query
|
||||
* @param array $body
|
||||
* @param array $cookies
|
||||
* @param array $files
|
||||
* @return static
|
||||
*/
|
||||
public static function createServer(
|
||||
callable $callback,
|
||||
array $server,
|
||||
array $query,
|
||||
array $body,
|
||||
array $cookies,
|
||||
array $files
|
||||
) {
|
||||
$request = ServerRequestFactory::fromGlobals($server, $query, $body, $cookies, $files);
|
||||
$response = new Response();
|
||||
return new static($callback, $request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Server instance from an existing request object
|
||||
*
|
||||
* Provided a callback, an existing request object, and optionally an
|
||||
* existing response object, create and return the Server instance.
|
||||
*
|
||||
* If no Response object is provided, one will be created.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param ServerRequestInterface $request
|
||||
* @param null|ResponseInterface $response
|
||||
* @return static
|
||||
*/
|
||||
public static function createServerFromRequest(
|
||||
callable $callback,
|
||||
ServerRequestInterface $request,
|
||||
ResponseInterface $response = null
|
||||
) {
|
||||
if (! $response) {
|
||||
$response = new Response();
|
||||
}
|
||||
return new static($callback, $request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Listen" to an incoming request
|
||||
*
|
||||
* If provided a $finalHandler, that callable will be used for
|
||||
* incomplete requests.
|
||||
*
|
||||
* @param null|callable $finalHandler
|
||||
*/
|
||||
public function listen(callable $finalHandler = null)
|
||||
{
|
||||
$callback = $this->callback;
|
||||
|
||||
$response = $callback($this->request, $this->response, $finalHandler);
|
||||
if (! $response instanceof ResponseInterface) {
|
||||
$response = $this->response;
|
||||
}
|
||||
|
||||
$this->getEmitter()->emit($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current response emitter.
|
||||
*
|
||||
* If none has been registered, lazy-loads a Response\SapiEmitter.
|
||||
*
|
||||
* @return Response\EmitterInterface
|
||||
*/
|
||||
private function getEmitter()
|
||||
{
|
||||
if (! $this->emitter) {
|
||||
$this->emitter = new Response\SapiEmitter();
|
||||
}
|
||||
|
||||
return $this->emitter;
|
||||
}
|
||||
}
|
291
vendor/zendframework/zend-diactoros/src/ServerRequest.php
vendored
Normal file
291
vendor/zendframework/zend-diactoros/src/ServerRequest.php
vendored
Normal file
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Server-side HTTP request
|
||||
*
|
||||
* Extends the Request definition to add methods for accessing incoming data,
|
||||
* specifically server parameters, cookies, matched path parameters, query
|
||||
* string arguments, body parameters, and upload file information.
|
||||
*
|
||||
* "Attributes" are discovered via decomposing the request (and usually
|
||||
* specifically the URI path), and typically will be injected by the application.
|
||||
*
|
||||
* Requests are considered immutable; all methods that might change state are
|
||||
* implemented such that they retain the internal state of the current
|
||||
* message and return a new instance that contains the changed state.
|
||||
*/
|
||||
class ServerRequest implements ServerRequestInterface
|
||||
{
|
||||
use RequestTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $attributes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $cookieParams = [];
|
||||
|
||||
/**
|
||||
* @var null|array|object
|
||||
*/
|
||||
private $parsedBody;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $queryParams = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $serverParams;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $uploadedFiles;
|
||||
|
||||
/**
|
||||
* @param array $serverParams Server parameters, typically from $_SERVER
|
||||
* @param array $uploadedFiles Upload file information, a tree of UploadedFiles
|
||||
* @param null|string|UriInterface $uri URI for the request, if any.
|
||||
* @param null|string $method HTTP method for the request, if any.
|
||||
* @param string|resource|StreamInterface $body Message body, if any.
|
||||
* @param array $headers Headers for the message, if any.
|
||||
* @param array $cookies Cookies for the message, if any.
|
||||
* @param array $queryParams Query params for the message, if any.
|
||||
* @param null|array|object $parsedBody The deserialized body parameters, if any.
|
||||
* @param string $protocol HTTP protocol version.
|
||||
* @throws InvalidArgumentException for any invalid value.
|
||||
*/
|
||||
public function __construct(
|
||||
array $serverParams = [],
|
||||
array $uploadedFiles = [],
|
||||
$uri = null,
|
||||
$method = null,
|
||||
$body = 'php://input',
|
||||
array $headers = [],
|
||||
array $cookies = [],
|
||||
array $queryParams = [],
|
||||
$parsedBody = null,
|
||||
$protocol = '1.1'
|
||||
) {
|
||||
$this->validateUploadedFiles($uploadedFiles);
|
||||
|
||||
if ($body === 'php://input') {
|
||||
$body = new PhpInputStream();
|
||||
}
|
||||
|
||||
$this->initialize($uri, $method, $body, $headers);
|
||||
$this->serverParams = $serverParams;
|
||||
$this->uploadedFiles = $uploadedFiles;
|
||||
$this->cookieParams = $cookies;
|
||||
$this->queryParams = $queryParams;
|
||||
$this->parsedBody = $parsedBody;
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getServerParams()
|
||||
{
|
||||
return $this->serverParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUploadedFiles()
|
||||
{
|
||||
return $this->uploadedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withUploadedFiles(array $uploadedFiles)
|
||||
{
|
||||
$this->validateUploadedFiles($uploadedFiles);
|
||||
$new = clone $this;
|
||||
$new->uploadedFiles = $uploadedFiles;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCookieParams()
|
||||
{
|
||||
return $this->cookieParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withCookieParams(array $cookies)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->cookieParams = $cookies;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQueryParams()
|
||||
{
|
||||
return $this->queryParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withQueryParams(array $query)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->queryParams = $query;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParsedBody()
|
||||
{
|
||||
return $this->parsedBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withParsedBody($data)
|
||||
{
|
||||
if (! is_array($data) && ! is_object($data) && null !== $data) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a null, array, or object argument; received %s',
|
||||
__METHOD__,
|
||||
gettype($data)
|
||||
));
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->parsedBody = $data;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttribute($attribute, $default = null)
|
||||
{
|
||||
if (! array_key_exists($attribute, $this->attributes)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $this->attributes[$attribute];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withAttribute($attribute, $value)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->attributes[$attribute] = $value;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withoutAttribute($attribute)
|
||||
{
|
||||
$new = clone $this;
|
||||
unset($new->attributes[$attribute]);
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy to receive the request method.
|
||||
*
|
||||
* This overrides the parent functionality to ensure the method is never
|
||||
* empty; if no method is present, it returns 'GET'.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
if (empty($this->method)) {
|
||||
return 'GET';
|
||||
}
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request method.
|
||||
*
|
||||
* Unlike the regular Request implementation, the server-side
|
||||
* normalizes the method to uppercase to ensure consistency
|
||||
* and make checking the method simpler.
|
||||
*
|
||||
* This methods returns a new instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @return self
|
||||
*/
|
||||
public function withMethod($method)
|
||||
{
|
||||
$this->validateMethod($method);
|
||||
$new = clone $this;
|
||||
$new->method = $method;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively validate the structure in an uploaded files array.
|
||||
*
|
||||
* @param array $uploadedFiles
|
||||
* @throws InvalidArgumentException if any leaf is not an UploadedFileInterface instance.
|
||||
*/
|
||||
private function validateUploadedFiles(array $uploadedFiles)
|
||||
{
|
||||
foreach ($uploadedFiles as $file) {
|
||||
if (is_array($file)) {
|
||||
$this->validateUploadedFiles($file);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $file instanceof UploadedFileInterface) {
|
||||
throw new InvalidArgumentException('Invalid leaf in uploaded files structure');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
240
vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php
vendored
Normal file
240
vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php
vendored
Normal file
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use stdClass;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_change_key_case;
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function strtolower;
|
||||
|
||||
use const CASE_LOWER;
|
||||
|
||||
/**
|
||||
* Class for marshaling a request object from the current PHP environment.
|
||||
*
|
||||
* Logic largely refactored from the ZF2 Zend\Http\PhpEnvironment\Request class.
|
||||
*
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class ServerRequestFactory
|
||||
{
|
||||
/**
|
||||
* Function to use to get apache request headers; present only to simplify mocking.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
private static $apacheRequestHeaders = 'apache_request_headers';
|
||||
|
||||
/**
|
||||
* Create a request from the supplied superglobal values.
|
||||
*
|
||||
* If any argument is not supplied, the corresponding superglobal value will
|
||||
* be used.
|
||||
*
|
||||
* The ServerRequest created is then passed to the fromServer() method in
|
||||
* order to marshal the request URI and headers.
|
||||
*
|
||||
* @see fromServer()
|
||||
* @param array $server $_SERVER superglobal
|
||||
* @param array $query $_GET superglobal
|
||||
* @param array $body $_POST superglobal
|
||||
* @param array $cookies $_COOKIE superglobal
|
||||
* @param array $files $_FILES superglobal
|
||||
* @return ServerRequest
|
||||
* @throws InvalidArgumentException for invalid file values
|
||||
*/
|
||||
public static function fromGlobals(
|
||||
array $server = null,
|
||||
array $query = null,
|
||||
array $body = null,
|
||||
array $cookies = null,
|
||||
array $files = null
|
||||
) {
|
||||
$server = normalizeServer(
|
||||
$server ?: $_SERVER,
|
||||
is_callable(self::$apacheRequestHeaders) ? self::$apacheRequestHeaders : null
|
||||
);
|
||||
$files = normalizeUploadedFiles($files ?: $_FILES);
|
||||
$headers = marshalHeadersFromSapi($server);
|
||||
|
||||
if (null === $cookies && array_key_exists('cookie', $headers)) {
|
||||
$cookies = parseCookieHeader($headers['cookie']);
|
||||
}
|
||||
|
||||
return new ServerRequest(
|
||||
$server,
|
||||
$files,
|
||||
marshalUriFromSapi($server, $headers),
|
||||
marshalMethodFromSapi($server),
|
||||
'php://input',
|
||||
$headers,
|
||||
$cookies ?: $_COOKIE,
|
||||
$query ?: $_GET,
|
||||
$body ?: $_POST,
|
||||
marshalProtocolVersionFromSapi($server)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access a value in an array, returning a default value if not found
|
||||
*
|
||||
* @deprecated since 1.8.0; no longer used internally.
|
||||
* @param string $key
|
||||
* @param array $values
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($key, array $values, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, $values)) {
|
||||
return $values[$key];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a header value.
|
||||
*
|
||||
* Does a case-insensitive search for a matching header.
|
||||
*
|
||||
* If found, it is returned as a string, using comma concatenation.
|
||||
*
|
||||
* If not, the $default is returned.
|
||||
*
|
||||
* @deprecated since 1.8.0; no longer used internally.
|
||||
* @param string $header
|
||||
* @param array $headers
|
||||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
public static function getHeader($header, array $headers, $default = null)
|
||||
{
|
||||
$header = strtolower($header);
|
||||
$headers = array_change_key_case($headers, CASE_LOWER);
|
||||
if (array_key_exists($header, $headers)) {
|
||||
$value = is_array($headers[$header]) ? implode(', ', $headers[$header]) : $headers[$header];
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal the $_SERVER array
|
||||
*
|
||||
* Pre-processes and returns the $_SERVER superglobal.
|
||||
*
|
||||
* @deprected since 1.8.0; use Zend\Diactoros\normalizeServer() instead.
|
||||
* @param array $server
|
||||
* @return array
|
||||
*/
|
||||
public static function normalizeServer(array $server)
|
||||
{
|
||||
return normalizeServer(
|
||||
$server ?: $_SERVER,
|
||||
is_callable(self::$apacheRequestHeaders) ? self::$apacheRequestHeaders : null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize uploaded files
|
||||
*
|
||||
* Transforms each value into an UploadedFileInterface instance, and ensures
|
||||
* that nested arrays are normalized.
|
||||
*
|
||||
* @deprecated since 1.8.0; use \Zend\Diactoros\normalizeUploadedFiles instead.
|
||||
* @param array $files
|
||||
* @return array
|
||||
* @throws InvalidArgumentException for unrecognized values
|
||||
*/
|
||||
public static function normalizeFiles(array $files)
|
||||
{
|
||||
return normalizeUploadedFiles($files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal headers from $_SERVER
|
||||
*
|
||||
* @deprecated since 1.8.0; use Zend\Diactoros\marshalHeadersFromSapi().
|
||||
* @param array $server
|
||||
* @return array
|
||||
*/
|
||||
public static function marshalHeaders(array $server)
|
||||
{
|
||||
return marshalHeadersFromSapi($server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal the URI from the $_SERVER array and headers
|
||||
*
|
||||
* @deprecated since 1.8.0; use Zend\Diactoros\marshalUriFromSapi() instead.
|
||||
* @param array $server
|
||||
* @param array $headers
|
||||
* @return Uri
|
||||
*/
|
||||
public static function marshalUriFromServer(array $server, array $headers)
|
||||
{
|
||||
return marshalUriFromSapi($server, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal the host and port from HTTP headers and/or the PHP environment
|
||||
*
|
||||
* @deprecated since 1.8.0; use Zend\Diactoros\marshalUriFromSapi() instead,
|
||||
* and pull the host and port from the Uri instance that function
|
||||
* returns.
|
||||
* @param stdClass $accumulator
|
||||
* @param array $server
|
||||
* @param array $headers
|
||||
*/
|
||||
public static function marshalHostAndPortFromHeaders(stdClass $accumulator, array $server, array $headers)
|
||||
{
|
||||
$uri = marshalUriFromSapi($server, $headers);
|
||||
$accumulator->host = $uri->getHost();
|
||||
$accumulator->port = $uri->getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the base URI for the request
|
||||
*
|
||||
* Looks at a variety of criteria in order to attempt to autodetect a base
|
||||
* URI, including rewrite URIs, proxy URIs, etc.
|
||||
*
|
||||
* @deprecated since 1.8.0; use Zend\Diactoros\marshalUriFromSapi() instead,
|
||||
* and pull the path from the Uri instance that function returns.
|
||||
* @param array $server
|
||||
* @return string
|
||||
*/
|
||||
public static function marshalRequestUri(array $server)
|
||||
{
|
||||
$uri = marshalUriFromSapi($server, []);
|
||||
return $uri->getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the query string from a path
|
||||
*
|
||||
* @deprecated since 1.8.0; no longer used internally.
|
||||
* @param mixed $path
|
||||
* @return string
|
||||
*/
|
||||
public static function stripQueryString($path)
|
||||
{
|
||||
return explode('?', $path, 2)[0];
|
||||
}
|
||||
}
|
359
vendor/zendframework/zend-diactoros/src/Stream.php
vendored
Normal file
359
vendor/zendframework/zend-diactoros/src/Stream.php
vendored
Normal file
|
@ -0,0 +1,359 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use RuntimeException;
|
||||
|
||||
use function array_key_exists;
|
||||
use function fclose;
|
||||
use function feof;
|
||||
use function fopen;
|
||||
use function fread;
|
||||
use function fseek;
|
||||
use function fstat;
|
||||
use function ftell;
|
||||
use function fwrite;
|
||||
use function get_resource_type;
|
||||
use function is_int;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function restore_error_handler;
|
||||
use function set_error_handler;
|
||||
use function stream_get_contents;
|
||||
use function stream_get_meta_data;
|
||||
use function strstr;
|
||||
|
||||
use const E_WARNING;
|
||||
use const SEEK_SET;
|
||||
|
||||
/**
|
||||
* Implementation of PSR HTTP streams
|
||||
*/
|
||||
class Stream implements StreamInterface
|
||||
{
|
||||
/**
|
||||
* @var resource|null
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var string|resource
|
||||
*/
|
||||
protected $stream;
|
||||
|
||||
/**
|
||||
* @param string|resource $stream
|
||||
* @param string $mode Mode with which to open stream
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($stream, $mode = 'r')
|
||||
{
|
||||
$this->setStream($stream, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (! $this->isReadable()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->isSeekable()) {
|
||||
$this->rewind();
|
||||
}
|
||||
|
||||
return $this->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
return;
|
||||
}
|
||||
|
||||
$resource = $this->detach();
|
||||
fclose($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
$resource = $this->resource;
|
||||
$this->resource = null;
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a new stream/resource to the instance.
|
||||
*
|
||||
* @param string|resource $resource
|
||||
* @param string $mode
|
||||
* @throws InvalidArgumentException for stream identifier that cannot be
|
||||
* cast to a resource
|
||||
* @throws InvalidArgumentException for non-resource stream
|
||||
*/
|
||||
public function attach($resource, $mode = 'r')
|
||||
{
|
||||
$this->setStream($resource, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stats = fstat($this->resource);
|
||||
if ($stats !== false) {
|
||||
return $stats['size'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
throw new RuntimeException('No resource available; cannot tell position');
|
||||
}
|
||||
|
||||
$result = ftell($this->resource);
|
||||
if (! is_int($result)) {
|
||||
throw new RuntimeException('Error occurred during tell operation');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return feof($this->resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSeekable()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = stream_get_meta_data($this->resource);
|
||||
return $meta['seekable'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
if (! $this->resource) {
|
||||
throw new RuntimeException('No resource available; cannot seek position');
|
||||
}
|
||||
|
||||
if (! $this->isSeekable()) {
|
||||
throw new RuntimeException('Stream is not seekable');
|
||||
}
|
||||
|
||||
$result = fseek($this->resource, $offset, $whence);
|
||||
|
||||
if (0 !== $result) {
|
||||
throw new RuntimeException('Error seeking within stream');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
return $this->seek(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = stream_get_meta_data($this->resource);
|
||||
$mode = $meta['mode'];
|
||||
|
||||
return (
|
||||
strstr($mode, 'x')
|
||||
|| strstr($mode, 'w')
|
||||
|| strstr($mode, 'c')
|
||||
|| strstr($mode, 'a')
|
||||
|| strstr($mode, '+')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($string)
|
||||
{
|
||||
if (! $this->resource) {
|
||||
throw new RuntimeException('No resource available; cannot write');
|
||||
}
|
||||
|
||||
if (! $this->isWritable()) {
|
||||
throw new RuntimeException('Stream is not writable');
|
||||
}
|
||||
|
||||
$result = fwrite($this->resource, $string);
|
||||
|
||||
if (false === $result) {
|
||||
throw new RuntimeException('Error writing to stream');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable()
|
||||
{
|
||||
if (! $this->resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = stream_get_meta_data($this->resource);
|
||||
$mode = $meta['mode'];
|
||||
|
||||
return (strstr($mode, 'r') || strstr($mode, '+'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if (! $this->resource) {
|
||||
throw new RuntimeException('No resource available; cannot read');
|
||||
}
|
||||
|
||||
if (! $this->isReadable()) {
|
||||
throw new RuntimeException('Stream is not readable');
|
||||
}
|
||||
|
||||
$result = fread($this->resource, $length);
|
||||
|
||||
if (false === $result) {
|
||||
throw new RuntimeException('Error reading stream');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
if (! $this->isReadable()) {
|
||||
throw new RuntimeException('Stream is not readable');
|
||||
}
|
||||
|
||||
$result = stream_get_contents($this->resource);
|
||||
if (false === $result) {
|
||||
throw new RuntimeException('Error reading from stream');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
if (null === $key) {
|
||||
return stream_get_meta_data($this->resource);
|
||||
}
|
||||
|
||||
$metadata = stream_get_meta_data($this->resource);
|
||||
if (! array_key_exists($key, $metadata)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $metadata[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the internal stream resource.
|
||||
*
|
||||
* @param string|resource $stream String stream target or stream resource.
|
||||
* @param string $mode Resource mode for stream target.
|
||||
* @throws InvalidArgumentException for invalid streams or resources.
|
||||
*/
|
||||
private function setStream($stream, $mode = 'r')
|
||||
{
|
||||
$error = null;
|
||||
$resource = $stream;
|
||||
|
||||
if (is_string($stream)) {
|
||||
set_error_handler(function ($e) use (&$error) {
|
||||
if ($e !== E_WARNING) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = $e;
|
||||
});
|
||||
$resource = fopen($stream, $mode);
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
throw new InvalidArgumentException('Invalid stream reference provided');
|
||||
}
|
||||
|
||||
if (! is_resource($resource) || 'stream' !== get_resource_type($resource)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid stream provided; must be a string stream identifier or stream resource'
|
||||
);
|
||||
}
|
||||
|
||||
if ($stream !== $resource) {
|
||||
$this->stream = $stream;
|
||||
}
|
||||
|
||||
$this->resource = $resource;
|
||||
}
|
||||
}
|
283
vendor/zendframework/zend-diactoros/src/UploadedFile.php
vendored
Normal file
283
vendor/zendframework/zend-diactoros/src/UploadedFile.php
vendored
Normal file
|
@ -0,0 +1,283 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RuntimeException;
|
||||
|
||||
use function dirname;
|
||||
use function fclose;
|
||||
use function fopen;
|
||||
use function fwrite;
|
||||
use function is_dir;
|
||||
use function is_int;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function is_writable;
|
||||
use function move_uploaded_file;
|
||||
use function sprintf;
|
||||
use function strpos;
|
||||
|
||||
use const PHP_SAPI;
|
||||
use const UPLOAD_ERR_CANT_WRITE;
|
||||
use const UPLOAD_ERR_EXTENSION;
|
||||
use const UPLOAD_ERR_FORM_SIZE;
|
||||
use const UPLOAD_ERR_INI_SIZE;
|
||||
use const UPLOAD_ERR_NO_FILE;
|
||||
use const UPLOAD_ERR_NO_TMP_DIR;
|
||||
use const UPLOAD_ERR_OK;
|
||||
use const UPLOAD_ERR_PARTIAL;
|
||||
|
||||
class UploadedFile implements UploadedFileInterface
|
||||
{
|
||||
const ERROR_MESSAGES = [
|
||||
UPLOAD_ERR_OK => 'There is no error, the file uploaded with success',
|
||||
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
|
||||
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was '
|
||||
. 'specified in the HTML form',
|
||||
UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded',
|
||||
UPLOAD_ERR_NO_FILE => 'No file was uploaded',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
|
||||
UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $clientFilename;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $clientMediaType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* @var null|string
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $moved = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* @var null|StreamInterface
|
||||
*/
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* @param string|resource $streamOrFile
|
||||
* @param int $size
|
||||
* @param int $errorStatus
|
||||
* @param string|null $clientFilename
|
||||
* @param string|null $clientMediaType
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($streamOrFile, $size, $errorStatus, $clientFilename = null, $clientMediaType = null)
|
||||
{
|
||||
if ($errorStatus === UPLOAD_ERR_OK) {
|
||||
if (is_string($streamOrFile)) {
|
||||
$this->file = $streamOrFile;
|
||||
}
|
||||
if (is_resource($streamOrFile)) {
|
||||
$this->stream = new Stream($streamOrFile);
|
||||
}
|
||||
|
||||
if (! $this->file && ! $this->stream) {
|
||||
if (! $streamOrFile instanceof StreamInterface) {
|
||||
throw new InvalidArgumentException('Invalid stream or file provided for UploadedFile');
|
||||
}
|
||||
$this->stream = $streamOrFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (! is_int($size)) {
|
||||
throw new InvalidArgumentException('Invalid size provided for UploadedFile; must be an int');
|
||||
}
|
||||
$this->size = $size;
|
||||
|
||||
if (! is_int($errorStatus)
|
||||
|| 0 > $errorStatus
|
||||
|| 8 < $errorStatus
|
||||
) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid error status for UploadedFile; must be an UPLOAD_ERR_* constant'
|
||||
);
|
||||
}
|
||||
$this->error = $errorStatus;
|
||||
|
||||
if (null !== $clientFilename && ! is_string($clientFilename)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid client filename provided for UploadedFile; must be null or a string'
|
||||
);
|
||||
}
|
||||
$this->clientFilename = $clientFilename;
|
||||
|
||||
if (null !== $clientMediaType && ! is_string($clientMediaType)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid client media type provided for UploadedFile; must be null or a string'
|
||||
);
|
||||
}
|
||||
$this->clientMediaType = $clientMediaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws \RuntimeException if the upload was not successful.
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
if ($this->error !== UPLOAD_ERR_OK) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Cannot retrieve stream due to upload error: %s',
|
||||
self::ERROR_MESSAGES[$this->error]
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->moved) {
|
||||
throw new RuntimeException('Cannot retrieve stream after it has already been moved');
|
||||
}
|
||||
|
||||
if ($this->stream instanceof StreamInterface) {
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
$this->stream = new Stream($this->file);
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see http://php.net/is_uploaded_file
|
||||
* @see http://php.net/move_uploaded_file
|
||||
* @param string $targetPath Path to which to move the uploaded file.
|
||||
* @throws \RuntimeException if the upload was not successful.
|
||||
* @throws \InvalidArgumentException if the $path specified is invalid.
|
||||
* @throws \RuntimeException on any error during the move operation, or on
|
||||
* the second or subsequent call to the method.
|
||||
*/
|
||||
public function moveTo($targetPath)
|
||||
{
|
||||
if ($this->moved) {
|
||||
throw new RuntimeException('Cannot move file; already moved!');
|
||||
}
|
||||
|
||||
if ($this->error !== UPLOAD_ERR_OK) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Cannot retrieve stream due to upload error: %s',
|
||||
self::ERROR_MESSAGES[$this->error]
|
||||
));
|
||||
}
|
||||
|
||||
if (! is_string($targetPath) || empty($targetPath)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid path provided for move operation; must be a non-empty string'
|
||||
);
|
||||
}
|
||||
|
||||
$targetDirectory = dirname($targetPath);
|
||||
if (! is_dir($targetDirectory) || ! is_writable($targetDirectory)) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'The target directory `%s` does not exists or is not writable',
|
||||
$targetDirectory
|
||||
));
|
||||
}
|
||||
|
||||
$sapi = PHP_SAPI;
|
||||
switch (true) {
|
||||
case (empty($sapi) || 0 === strpos($sapi, 'cli') || ! $this->file):
|
||||
// Non-SAPI environment, or no filename present
|
||||
$this->writeFile($targetPath);
|
||||
break;
|
||||
default:
|
||||
// SAPI environment, with file present
|
||||
if (false === move_uploaded_file($this->file, $targetPath)) {
|
||||
throw new RuntimeException('Error occurred while moving uploaded file');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$this->moved = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int|null The file size in bytes or null if unknown.
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see http://php.net/manual/en/features.file-upload.errors.php
|
||||
* @return int One of PHP's UPLOAD_ERR_XXX constants.
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string|null The filename sent by the client or null if none
|
||||
* was provided.
|
||||
*/
|
||||
public function getClientFilename()
|
||||
{
|
||||
return $this->clientFilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClientMediaType()
|
||||
{
|
||||
return $this->clientMediaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write internal stream to given path
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
private function writeFile($path)
|
||||
{
|
||||
$handle = fopen($path, 'wb+');
|
||||
if (false === $handle) {
|
||||
throw new RuntimeException('Unable to write to designated path');
|
||||
}
|
||||
|
||||
$stream = $this->getStream();
|
||||
$stream->rewind();
|
||||
while (! $stream->eof()) {
|
||||
fwrite($handle, $stream->read(4096));
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
706
vendor/zendframework/zend-diactoros/src/Uri.php
vendored
Normal file
706
vendor/zendframework/zend-diactoros/src/Uri.php
vendored
Normal file
|
@ -0,0 +1,706 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function count;
|
||||
use function explode;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_numeric;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function ltrim;
|
||||
use function parse_url;
|
||||
use function preg_replace;
|
||||
use function preg_replace_callback;
|
||||
use function rawurlencode;
|
||||
use function sprintf;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Implementation of Psr\Http\UriInterface.
|
||||
*
|
||||
* Provides a value object representing a URI for HTTP requests.
|
||||
*
|
||||
* Instances of this class are considered immutable; all methods that
|
||||
* might change state are implemented such that they retain the internal
|
||||
* state of the current instance and return a new instance that contains the
|
||||
* changed state.
|
||||
*/
|
||||
class Uri implements UriInterface
|
||||
{
|
||||
/**
|
||||
* Sub-delimiters used in user info, query strings and fragments.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
|
||||
|
||||
/**
|
||||
* Unreserved characters used in user info, paths, query strings, and fragments.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~\pL';
|
||||
|
||||
/**
|
||||
* @var int[] Array indexed by valid scheme names to their corresponding ports.
|
||||
*/
|
||||
protected $allowedSchemes = [
|
||||
'http' => 80,
|
||||
'https' => 443,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $scheme = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $userInfo = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $port;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $query = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fragment = '';
|
||||
|
||||
/**
|
||||
* generated uri string cache
|
||||
* @var string|null
|
||||
*/
|
||||
private $uriString;
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @throws InvalidArgumentException on non-string $uri argument
|
||||
*/
|
||||
public function __construct($uri = '')
|
||||
{
|
||||
if ('' === $uri) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_string($uri)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'URI passed to constructor must be a string; received "%s"',
|
||||
is_object($uri) ? get_class($uri) : gettype($uri)
|
||||
));
|
||||
}
|
||||
|
||||
$this->parseUri($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operations to perform on clone.
|
||||
*
|
||||
* Since cloning usually is for purposes of mutation, we reset the
|
||||
* $uriString property so it will be re-calculated.
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->uriString = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (null !== $this->uriString) {
|
||||
return $this->uriString;
|
||||
}
|
||||
|
||||
$this->uriString = static::createUriString(
|
||||
$this->scheme,
|
||||
$this->getAuthority(),
|
||||
$this->getPath(), // Absolute URIs should use a "/" for an empty path
|
||||
$this->query,
|
||||
$this->fragment
|
||||
);
|
||||
|
||||
return $this->uriString;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAuthority()
|
||||
{
|
||||
if ('' === $this->host) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$authority = $this->host;
|
||||
if ('' !== $this->userInfo) {
|
||||
$authority = $this->userInfo . '@' . $authority;
|
||||
}
|
||||
|
||||
if ($this->isNonStandardPort($this->scheme, $this->host, $this->port)) {
|
||||
$authority .= ':' . $this->port;
|
||||
}
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user-info part of the URI.
|
||||
*
|
||||
* This value is percent-encoded, per RFC 3986 Section 3.2.1.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUserInfo()
|
||||
{
|
||||
return $this->userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->isNonStandardPort($this->scheme, $this->host, $this->port)
|
||||
? $this->port
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFragment()
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withScheme($scheme)
|
||||
{
|
||||
if (! is_string($scheme)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a string argument; received %s',
|
||||
__METHOD__,
|
||||
is_object($scheme) ? get_class($scheme) : gettype($scheme)
|
||||
));
|
||||
}
|
||||
|
||||
$scheme = $this->filterScheme($scheme);
|
||||
|
||||
if ($scheme === $this->scheme) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->scheme = $scheme;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new instance containing the provided user credentials.
|
||||
*
|
||||
* The value will be percent-encoded in the new instance, but with measures
|
||||
* taken to prevent double-encoding.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withUserInfo($user, $password = null)
|
||||
{
|
||||
if (! is_string($user)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a string user argument; received %s',
|
||||
__METHOD__,
|
||||
is_object($user) ? get_class($user) : gettype($user)
|
||||
));
|
||||
}
|
||||
if (null !== $password && ! is_string($password)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a string or null password argument; received %s',
|
||||
__METHOD__,
|
||||
is_object($password) ? get_class($password) : gettype($password)
|
||||
));
|
||||
}
|
||||
|
||||
$info = $this->filterUserInfoPart($user);
|
||||
if (null !== $password) {
|
||||
$info .= ':' . $this->filterUserInfoPart($password);
|
||||
}
|
||||
|
||||
if ($info === $this->userInfo) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->userInfo = $info;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withHost($host)
|
||||
{
|
||||
if (! is_string($host)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a string argument; received %s',
|
||||
__METHOD__,
|
||||
is_object($host) ? get_class($host) : gettype($host)
|
||||
));
|
||||
}
|
||||
|
||||
if ($host === $this->host) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->host = strtolower($host);
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withPort($port)
|
||||
{
|
||||
if ($port !== null) {
|
||||
if (! is_numeric($port) || is_float($port)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid port "%s" specified; must be an integer, an integer string, or null',
|
||||
is_object($port) ? get_class($port) : gettype($port)
|
||||
));
|
||||
}
|
||||
|
||||
$port = (int) $port;
|
||||
}
|
||||
|
||||
if ($port === $this->port) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($port !== null && ($port < 1 || $port > 65535)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid port "%d" specified; must be a valid TCP/UDP port',
|
||||
$port
|
||||
));
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->port = $port;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withPath($path)
|
||||
{
|
||||
if (! is_string($path)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid path provided; must be a string'
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($path, '?') !== false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid path provided; must not contain a query string'
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($path, '#') !== false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid path provided; must not contain a URI fragment'
|
||||
);
|
||||
}
|
||||
|
||||
$path = $this->filterPath($path);
|
||||
|
||||
if ($path === $this->path) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->path = $path;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withQuery($query)
|
||||
{
|
||||
if (! is_string($query)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Query string must be a string'
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($query, '#') !== false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Query string must not include a URI fragment'
|
||||
);
|
||||
}
|
||||
|
||||
$query = $this->filterQuery($query);
|
||||
|
||||
if ($query === $this->query) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->query = $query;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withFragment($fragment)
|
||||
{
|
||||
if (! is_string($fragment)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s expects a string argument; received %s',
|
||||
__METHOD__,
|
||||
is_object($fragment) ? get_class($fragment) : gettype($fragment)
|
||||
));
|
||||
}
|
||||
|
||||
$fragment = $this->filterFragment($fragment);
|
||||
|
||||
if ($fragment === $this->fragment) {
|
||||
// Do nothing if no change was made.
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->fragment = $fragment;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URI into its parts, and set the properties
|
||||
*
|
||||
* @param string $uri
|
||||
*/
|
||||
private function parseUri($uri)
|
||||
{
|
||||
$parts = parse_url($uri);
|
||||
|
||||
if (false === $parts) {
|
||||
throw new \InvalidArgumentException(
|
||||
'The source URI string appears to be malformed'
|
||||
);
|
||||
}
|
||||
|
||||
$this->scheme = isset($parts['scheme']) ? $this->filterScheme($parts['scheme']) : '';
|
||||
$this->userInfo = isset($parts['user']) ? $this->filterUserInfoPart($parts['user']) : '';
|
||||
$this->host = isset($parts['host']) ? strtolower($parts['host']) : '';
|
||||
$this->port = isset($parts['port']) ? $parts['port'] : null;
|
||||
$this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : '';
|
||||
$this->query = isset($parts['query']) ? $this->filterQuery($parts['query']) : '';
|
||||
$this->fragment = isset($parts['fragment']) ? $this->filterFragment($parts['fragment']) : '';
|
||||
|
||||
if (isset($parts['pass'])) {
|
||||
$this->userInfo .= ':' . $parts['pass'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URI string from its various parts
|
||||
*
|
||||
* @param string $scheme
|
||||
* @param string $authority
|
||||
* @param string $path
|
||||
* @param string $query
|
||||
* @param string $fragment
|
||||
* @return string
|
||||
*/
|
||||
private static function createUriString($scheme, $authority, $path, $query, $fragment)
|
||||
{
|
||||
$uri = '';
|
||||
|
||||
if ('' !== $scheme) {
|
||||
$uri .= sprintf('%s:', $scheme);
|
||||
}
|
||||
|
||||
if ('' !== $authority) {
|
||||
$uri .= '//' . $authority;
|
||||
}
|
||||
|
||||
if ('' !== $path && '/' !== substr($path, 0, 1)) {
|
||||
$path = '/' . $path;
|
||||
}
|
||||
|
||||
$uri .= $path;
|
||||
|
||||
|
||||
if ('' !== $query) {
|
||||
$uri .= sprintf('?%s', $query);
|
||||
}
|
||||
|
||||
if ('' !== $fragment) {
|
||||
$uri .= sprintf('#%s', $fragment);
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a given port non-standard for the current scheme?
|
||||
*
|
||||
* @param string $scheme
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @return bool
|
||||
*/
|
||||
private function isNonStandardPort($scheme, $host, $port)
|
||||
{
|
||||
if ('' === $scheme) {
|
||||
return '' === $host || null !== $port;
|
||||
}
|
||||
|
||||
if ('' === $host || null === $port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! isset($this->allowedSchemes[$scheme]) || $port !== $this->allowedSchemes[$scheme];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the scheme to ensure it is a valid scheme.
|
||||
*
|
||||
* @param string $scheme Scheme name.
|
||||
*
|
||||
* @return string Filtered scheme.
|
||||
*/
|
||||
private function filterScheme($scheme)
|
||||
{
|
||||
$scheme = strtolower($scheme);
|
||||
$scheme = preg_replace('#:(//)?$#', '', $scheme);
|
||||
|
||||
if ('' === $scheme) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (! isset($this->allowedSchemes[$scheme])) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unsupported scheme "%s"; must be any empty string or in the set (%s)',
|
||||
$scheme,
|
||||
implode(', ', array_keys($this->allowedSchemes))
|
||||
));
|
||||
}
|
||||
|
||||
return $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a part of user info in a URI to ensure it is properly encoded.
|
||||
*
|
||||
* @param string $part
|
||||
* @return string
|
||||
*/
|
||||
private function filterUserInfoPart($part)
|
||||
{
|
||||
// Note the addition of `%` to initial charset; this allows `|` portion
|
||||
// to match and thus prevent double-encoding.
|
||||
return preg_replace_callback(
|
||||
'/(?:[^%' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . ']+|%(?![A-Fa-f0-9]{2}))/u',
|
||||
[$this, 'urlEncodeChar'],
|
||||
$part
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the path of a URI to ensure it is properly encoded.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
private function filterPath($path)
|
||||
{
|
||||
$path = preg_replace_callback(
|
||||
'/(?:[^' . self::CHAR_UNRESERVED . ')(:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/u',
|
||||
[$this, 'urlEncodeChar'],
|
||||
$path
|
||||
);
|
||||
|
||||
if ('' === $path) {
|
||||
// No path
|
||||
return $path;
|
||||
}
|
||||
|
||||
if ($path[0] !== '/') {
|
||||
// Relative path
|
||||
return $path;
|
||||
}
|
||||
|
||||
// Ensure only one leading slash, to prevent XSS attempts.
|
||||
return '/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a query string to ensure it is propertly encoded.
|
||||
*
|
||||
* Ensures that the values in the query string are properly urlencoded.
|
||||
*
|
||||
* @param string $query
|
||||
* @return string
|
||||
*/
|
||||
private function filterQuery($query)
|
||||
{
|
||||
if ('' !== $query && strpos($query, '?') === 0) {
|
||||
$query = substr($query, 1);
|
||||
}
|
||||
|
||||
$parts = explode('&', $query);
|
||||
foreach ($parts as $index => $part) {
|
||||
list($key, $value) = $this->splitQueryValue($part);
|
||||
if ($value === null) {
|
||||
$parts[$index] = $this->filterQueryOrFragment($key);
|
||||
continue;
|
||||
}
|
||||
$parts[$index] = sprintf(
|
||||
'%s=%s',
|
||||
$this->filterQueryOrFragment($key),
|
||||
$this->filterQueryOrFragment($value)
|
||||
);
|
||||
}
|
||||
|
||||
return implode('&', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a query value into a key/value tuple.
|
||||
*
|
||||
* @param string $value
|
||||
* @return array A value with exactly two elements, key and value
|
||||
*/
|
||||
private function splitQueryValue($value)
|
||||
{
|
||||
$data = explode('=', $value, 2);
|
||||
if (! isset($data[1])) {
|
||||
$data[] = null;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a fragment value to ensure it is properly encoded.
|
||||
*
|
||||
* @param string $fragment
|
||||
* @return string
|
||||
*/
|
||||
private function filterFragment($fragment)
|
||||
{
|
||||
if ('' !== $fragment && strpos($fragment, '#') === 0) {
|
||||
$fragment = '%23' . substr($fragment, 1);
|
||||
}
|
||||
|
||||
return $this->filterQueryOrFragment($fragment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a query string key or value, or a fragment.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
private function filterQueryOrFragment($value)
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/u',
|
||||
[$this, 'urlEncodeChar'],
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encode a character returned by a regex.
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string
|
||||
*/
|
||||
private function urlEncodeChar(array $matches)
|
||||
{
|
||||
return rawurlencode($matches[0]);
|
||||
}
|
||||
}
|
40
vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php
vendored
Normal file
40
vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Create an uploaded file instance from an array of values.
|
||||
*
|
||||
* @param array $spec A single $_FILES entry.
|
||||
* @return UploadedFile
|
||||
* @throws InvalidArgumentException if one or more of the tmp_name, size,
|
||||
* or error keys are missing from $spec.
|
||||
*/
|
||||
function createUploadedFile(array $spec)
|
||||
{
|
||||
if (! isset($spec['tmp_name'])
|
||||
|| ! isset($spec['size'])
|
||||
|| ! isset($spec['error'])
|
||||
) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'$spec provided to %s MUST contain each of the keys "tmp_name",'
|
||||
. ' "size", and "error"; one or more were missing',
|
||||
__FUNCTION__
|
||||
));
|
||||
}
|
||||
|
||||
return new UploadedFile(
|
||||
$spec['tmp_name'],
|
||||
$spec['size'],
|
||||
$spec['error'],
|
||||
isset($spec['name']) ? $spec['name'] : null,
|
||||
isset($spec['type']) ? $spec['type'] : null
|
||||
);
|
||||
}
|
50
vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php
vendored
Normal file
50
vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use function array_key_exists;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function strtr;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* @param array $server Values obtained from the SAPI (generally `$_SERVER`).
|
||||
* @return array Header/value pairs
|
||||
*/
|
||||
function marshalHeadersFromSapi(array $server)
|
||||
{
|
||||
$headers = [];
|
||||
foreach ($server as $key => $value) {
|
||||
// Apache prefixes environment variables with REDIRECT_
|
||||
// if they are added by rewrite rules
|
||||
if (strpos($key, 'REDIRECT_') === 0) {
|
||||
$key = substr($key, 9);
|
||||
|
||||
// We will not overwrite existing variables with the
|
||||
// prefixed versions, though
|
||||
if (array_key_exists($key, $server)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value && strpos($key, 'HTTP_') === 0) {
|
||||
$name = strtr(strtolower(substr($key, 5)), '_', '-');
|
||||
$headers[$name] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value && strpos($key, 'CONTENT_') === 0) {
|
||||
$name = 'content-' . strtolower(substr($key, 8));
|
||||
$headers[$name] = $value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
19
vendor/zendframework/zend-diactoros/src/functions/marshal_method_from_sapi.php
vendored
Normal file
19
vendor/zendframework/zend-diactoros/src/functions/marshal_method_from_sapi.php
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
/**
|
||||
* Retrieve the request method from the SAPI parameters.
|
||||
*
|
||||
* @param array $server
|
||||
* @return string
|
||||
*/
|
||||
function marshalMethodFromSapi(array $server)
|
||||
{
|
||||
return isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET';
|
||||
}
|
36
vendor/zendframework/zend-diactoros/src/functions/marshal_protocol_version_from_sapi.php
vendored
Normal file
36
vendor/zendframework/zend-diactoros/src/functions/marshal_protocol_version_from_sapi.php
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* Return HTTP protocol version (X.Y) as discovered within a `$_SERVER` array.
|
||||
*
|
||||
* @param array $server
|
||||
* @return string
|
||||
* @throws UnexpectedValueException if the $server['SERVER_PROTOCOL'] value is
|
||||
* malformed.
|
||||
*/
|
||||
function marshalProtocolVersionFromSapi(array $server)
|
||||
{
|
||||
if (! isset($server['SERVER_PROTOCOL'])) {
|
||||
return '1.1';
|
||||
}
|
||||
|
||||
if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'Unrecognized protocol version (%s)',
|
||||
$server['SERVER_PROTOCOL']
|
||||
));
|
||||
}
|
||||
|
||||
return $matches['version'];
|
||||
}
|
212
vendor/zendframework/zend-diactoros/src/functions/marshal_uri_from_sapi.php
vendored
Normal file
212
vendor/zendframework/zend-diactoros/src/functions/marshal_uri_from_sapi.php
vendored
Normal file
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use function array_change_key_case;
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function ltrim;
|
||||
use function preg_match;
|
||||
use function preg_replace;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Marshal a Uri instance based on the values presnt in the $_SERVER array and headers.
|
||||
*
|
||||
* @param array $server SAPI parameters
|
||||
* @param array $headers HTTP request headers
|
||||
* @return Uri
|
||||
*/
|
||||
function marshalUriFromSapi(array $server, array $headers)
|
||||
{
|
||||
/**
|
||||
* Retrieve a header value from an array of headers using a case-insensitive lookup.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $headers Key/value header pairs
|
||||
* @param mixed $default Default value to return if header not found
|
||||
* @return mixed
|
||||
*/
|
||||
$getHeaderFromArray = function ($name, array $headers, $default = null) {
|
||||
$header = strtolower($name);
|
||||
$headers = array_change_key_case($headers, CASE_LOWER);
|
||||
if (array_key_exists($header, $headers)) {
|
||||
$value = is_array($headers[$header]) ? implode(', ', $headers[$header]) : $headers[$header];
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $default;
|
||||
};
|
||||
|
||||
/**
|
||||
* Marshal the host and port from HTTP headers and/or the PHP environment.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param array $server
|
||||
* @return array Array of two items, host and port, in that order (can be
|
||||
* passed to a list() operation).
|
||||
*/
|
||||
$marshalHostAndPort = function (array $headers, array $server) use ($getHeaderFromArray) {
|
||||
/**
|
||||
* @param string|array $host
|
||||
* @return array Array of two items, host and port, in that order (can be
|
||||
* passed to a list() operation).
|
||||
*/
|
||||
$marshalHostAndPortFromHeader = function ($host) {
|
||||
if (is_array($host)) {
|
||||
$host = implode(', ', $host);
|
||||
}
|
||||
|
||||
$port = null;
|
||||
|
||||
// works for regname, IPv4 & IPv6
|
||||
if (preg_match('|\:(\d+)$|', $host, $matches)) {
|
||||
$host = substr($host, 0, -1 * (strlen($matches[1]) + 1));
|
||||
$port = (int) $matches[1];
|
||||
}
|
||||
|
||||
return [$host, $port];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param array $server
|
||||
* @param string $host
|
||||
* @param null|int $port
|
||||
* @return array Array of two items, host and port, in that order (can be
|
||||
* passed to a list() operation).
|
||||
*/
|
||||
$marshalIpv6HostAndPort = function (array $server, $host, $port) {
|
||||
$host = '[' . $server['SERVER_ADDR'] . ']';
|
||||
$port = $port ?: 80;
|
||||
if ($port . ']' === substr($host, strrpos($host, ':') + 1)) {
|
||||
// The last digit of the IPv6-Address has been taken as port
|
||||
// Unset the port so the default port can be used
|
||||
$port = null;
|
||||
}
|
||||
return [$host, $port];
|
||||
};
|
||||
|
||||
static $defaults = ['', null];
|
||||
|
||||
if ($getHeaderFromArray('host', $headers, false)) {
|
||||
return $marshalHostAndPortFromHeader($getHeaderFromArray('host', $headers));
|
||||
}
|
||||
|
||||
if (! isset($server['SERVER_NAME'])) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
$host = $server['SERVER_NAME'];
|
||||
$port = isset($server['SERVER_PORT']) ? (int) $server['SERVER_PORT'] : null;
|
||||
|
||||
if (! isset($server['SERVER_ADDR'])
|
||||
|| ! preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)
|
||||
) {
|
||||
return [$host, $port];
|
||||
}
|
||||
|
||||
// Misinterpreted IPv6-Address
|
||||
// Reported for Safari on Windows
|
||||
return $marshalIpv6HostAndPort($server, $host, $port);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detect the path for the request
|
||||
*
|
||||
* Looks at a variety of criteria in order to attempt to autodetect the base
|
||||
* request path, including:
|
||||
*
|
||||
* - IIS7 UrlRewrite environment
|
||||
* - REQUEST_URI
|
||||
* - ORIG_PATH_INFO
|
||||
*
|
||||
* From ZF2's Zend\Http\PhpEnvironment\Request class
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*
|
||||
* @param array $server SAPI environment array (typically `$_SERVER`)
|
||||
* @return string Discovered path
|
||||
*/
|
||||
$marshalRequestPath = function (array $server) {
|
||||
// IIS7 with URL Rewrite: make sure we get the unencoded url
|
||||
// (double slash problem).
|
||||
$iisUrlRewritten = array_key_exists('IIS_WasUrlRewritten', $server) ? $server['IIS_WasUrlRewritten'] : null;
|
||||
$unencodedUrl = array_key_exists('UNENCODED_URL', $server) ? $server['UNENCODED_URL'] : '';
|
||||
if ('1' === $iisUrlRewritten && ! empty($unencodedUrl)) {
|
||||
return $unencodedUrl;
|
||||
}
|
||||
|
||||
$requestUri = array_key_exists('REQUEST_URI', $server) ? $server['REQUEST_URI'] : null;
|
||||
|
||||
if ($requestUri !== null) {
|
||||
return preg_replace('#^[^/:]+://[^/]+#', '', $requestUri);
|
||||
}
|
||||
|
||||
$origPathInfo = array_key_exists('ORIG_PATH_INFO', $server) ? $server['ORIG_PATH_INFO'] : null;
|
||||
if (empty($origPathInfo)) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return $origPathInfo;
|
||||
};
|
||||
|
||||
$uri = new Uri('');
|
||||
|
||||
// URI scheme
|
||||
$scheme = 'http';
|
||||
if (array_key_exists('HTTPS', $server)) {
|
||||
$https = $server['HTTPS'];
|
||||
} elseif (array_key_exists('https', $server)) {
|
||||
$https = $server['https'];
|
||||
} else {
|
||||
$https = false;
|
||||
}
|
||||
if (($https && 'off' !== strtolower($https))
|
||||
|| strtolower($getHeaderFromArray('x-forwarded-proto', $headers, false)) === 'https'
|
||||
) {
|
||||
$scheme = 'https';
|
||||
}
|
||||
$uri = $uri->withScheme($scheme);
|
||||
|
||||
// Set the host
|
||||
list($host, $port) = $marshalHostAndPort($headers, $server);
|
||||
if (! empty($host)) {
|
||||
$uri = $uri->withHost($host);
|
||||
if (! empty($port)) {
|
||||
$uri = $uri->withPort($port);
|
||||
}
|
||||
}
|
||||
|
||||
// URI path
|
||||
$path = $marshalRequestPath($server);
|
||||
|
||||
// Strip query string
|
||||
$path = explode('?', $path, 2)[0];
|
||||
|
||||
// URI query
|
||||
$query = '';
|
||||
if (isset($server['QUERY_STRING'])) {
|
||||
$query = ltrim($server['QUERY_STRING'], '?');
|
||||
}
|
||||
|
||||
// URI fragment
|
||||
$fragment = '';
|
||||
if (strpos($path, '#') !== false) {
|
||||
list($path, $fragment) = explode('#', $path, 2);
|
||||
}
|
||||
|
||||
return $uri
|
||||
->withPath($path)
|
||||
->withFragment($fragment)
|
||||
->withQuery($query);
|
||||
}
|
51
vendor/zendframework/zend-diactoros/src/functions/normalize_server.php
vendored
Normal file
51
vendor/zendframework/zend-diactoros/src/functions/normalize_server.php
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use function is_callable;
|
||||
|
||||
/**
|
||||
* Marshal the $_SERVER array
|
||||
*
|
||||
* Pre-processes and returns the $_SERVER superglobal. In particularly, it
|
||||
* attempts to detect the Authorization header, which is often not aggregated
|
||||
* correctly under various SAPI/httpd combinations.
|
||||
*
|
||||
* @param array $server
|
||||
* @param null|callable $apacheRequestHeaderCallback Callback that can be used to
|
||||
* retrieve Apache request headers. This defaults to
|
||||
* `apache_request_headers` under the Apache mod_php.
|
||||
* @return array Either $server verbatim, or with an added HTTP_AUTHORIZATION header.
|
||||
*/
|
||||
function normalizeServer(array $server, callable $apacheRequestHeaderCallback = null)
|
||||
{
|
||||
if (null === $apacheRequestHeaderCallback && is_callable('apache_request_headers')) {
|
||||
$apacheRequestHeaderCallback = 'apache_request_headers';
|
||||
}
|
||||
|
||||
// If the HTTP_AUTHORIZATION value is already set, or the callback is not
|
||||
// callable, we return verbatim
|
||||
if (isset($server['HTTP_AUTHORIZATION'])
|
||||
|| ! is_callable($apacheRequestHeaderCallback)
|
||||
) {
|
||||
return $server;
|
||||
}
|
||||
|
||||
$apacheRequestHeaders = $apacheRequestHeaderCallback();
|
||||
if (isset($apacheRequestHeaders['Authorization'])) {
|
||||
$server['HTTP_AUTHORIZATION'] = $apacheRequestHeaders['Authorization'];
|
||||
return $server;
|
||||
}
|
||||
|
||||
if (isset($apacheRequestHeaders['authorization'])) {
|
||||
$server['HTTP_AUTHORIZATION'] = $apacheRequestHeaders['authorization'];
|
||||
return $server;
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
129
vendor/zendframework/zend-diactoros/src/functions/normalize_uploaded_files.php
vendored
Normal file
129
vendor/zendframework/zend-diactoros/src/functions/normalize_uploaded_files.php
vendored
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Normalize uploaded files
|
||||
*
|
||||
* Transforms each value into an UploadedFile instance, and ensures that nested
|
||||
* arrays are normalized.
|
||||
*
|
||||
* @param array $files
|
||||
* @return UploadedFileInterface[]
|
||||
* @throws InvalidArgumentException for unrecognized values
|
||||
*/
|
||||
function normalizeUploadedFiles(array $files)
|
||||
{
|
||||
/**
|
||||
* Traverse a nested tree of uploaded file specifications.
|
||||
*
|
||||
* @param string[]|array[] $tmpNameTree
|
||||
* @param int[]|array[] $sizeTree
|
||||
* @param int[]|array[] $errorTree
|
||||
* @param string[]|array[]|null $nameTree
|
||||
* @param string[]|array[]|null $typeTree
|
||||
* @return UploadedFile[]|array[]
|
||||
*/
|
||||
$recursiveNormalize = function (
|
||||
array $tmpNameTree,
|
||||
array $sizeTree,
|
||||
array $errorTree,
|
||||
array $nameTree = null,
|
||||
array $typeTree = null
|
||||
) use (&$recursiveNormalize) {
|
||||
$normalized = [];
|
||||
foreach ($tmpNameTree as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
// Traverse
|
||||
$normalized[$key] = $recursiveNormalize(
|
||||
$tmpNameTree[$key],
|
||||
$sizeTree[$key],
|
||||
$errorTree[$key],
|
||||
isset($nameTree[$key]) ? $nameTree[$key] : null,
|
||||
isset($typeTree[$key]) ? $typeTree[$key] : null
|
||||
);
|
||||
continue;
|
||||
}
|
||||
$normalized[$key] = createUploadedFile([
|
||||
'tmp_name' => $tmpNameTree[$key],
|
||||
'size' => $sizeTree[$key],
|
||||
'error' => $errorTree[$key],
|
||||
'name' => isset($nameTree[$key]) ? $nameTree[$key] : null,
|
||||
'type' => isset($typeTree[$key]) ? $typeTree[$key] : null
|
||||
]);
|
||||
}
|
||||
return $normalized;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize an array of file specifications.
|
||||
*
|
||||
* Loops through all nested files (as determined by receiving an array to the
|
||||
* `tmp_name` key of a `$_FILES` specification) and returns a normalized array
|
||||
* of UploadedFile instances.
|
||||
*
|
||||
* This function normalizes a `$_FILES` array representing a nested set of
|
||||
* uploaded files as produced by the php-fpm SAPI, CGI SAPI, or mod_php
|
||||
* SAPI.
|
||||
*
|
||||
* @param array $files
|
||||
* @return UploadedFile[]
|
||||
*/
|
||||
$normalizeUploadedFileSpecification = function (array $files = []) use (&$recursiveNormalize) {
|
||||
if (! isset($files['tmp_name']) || ! is_array($files['tmp_name'])
|
||||
|| ! isset($files['size']) || ! is_array($files['size'])
|
||||
|| ! isset($files['error']) || ! is_array($files['error'])
|
||||
) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'$files provided to %s MUST contain each of the keys "tmp_name",'
|
||||
. ' "size", and "error", with each represented as an array;'
|
||||
. ' one or more were missing or non-array values',
|
||||
__FUNCTION__
|
||||
));
|
||||
}
|
||||
|
||||
return $recursiveNormalize(
|
||||
$files['tmp_name'],
|
||||
$files['size'],
|
||||
$files['error'],
|
||||
isset($files['name']) ? $files['name'] : null,
|
||||
isset($files['type']) ? $files['type'] : null
|
||||
);
|
||||
};
|
||||
|
||||
$normalized = [];
|
||||
foreach ($files as $key => $value) {
|
||||
if ($value instanceof UploadedFileInterface) {
|
||||
$normalized[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value) && isset($value['tmp_name']) && is_array($value['tmp_name'])) {
|
||||
$normalized[$key] = $normalizeUploadedFileSpecification($value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value) && isset($value['tmp_name'])) {
|
||||
$normalized[$key] = createUploadedFile($value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$normalized[$key] = normalizeUploadedFiles($value);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Invalid value in files specification');
|
||||
}
|
||||
return $normalized;
|
||||
}
|
41
vendor/zendframework/zend-diactoros/src/functions/parse_cookie_header.php
vendored
Normal file
41
vendor/zendframework/zend-diactoros/src/functions/parse_cookie_header.php
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros;
|
||||
|
||||
use function preg_match_all;
|
||||
use function urldecode;
|
||||
|
||||
/**
|
||||
* Parse a cookie header according to RFC 6265.
|
||||
*
|
||||
* PHP will replace special characters in cookie names, which results in other cookies not being available due to
|
||||
* overwriting. Thus, the server request should take the cookies from the request header instead.
|
||||
*
|
||||
* @param string $cookieHeader A string cookie header value.
|
||||
* @return array key/value cookie pairs.
|
||||
*/
|
||||
function parseCookieHeader($cookieHeader)
|
||||
{
|
||||
preg_match_all('(
|
||||
(?:^\\n?[ \t]*|;[ ])
|
||||
(?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
|
||||
=
|
||||
(?P<DQUOTE>"?)
|
||||
(?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
|
||||
(?P=DQUOTE)
|
||||
(?=\\n?[ \t]*$|;[ ])
|
||||
)x', $cookieHeader, $matches, PREG_SET_ORDER);
|
||||
|
||||
$cookies = [];
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$cookies[$match['name']] = urldecode($match['value']);
|
||||
}
|
||||
|
||||
return $cookies;
|
||||
}
|
Reference in a new issue