Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,3 @@
vendor/
composer.lock
phpunit.xml

View file

@ -0,0 +1,43 @@
language: php
sudo: false
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 5.3
env: deps=low
- php: 5.6
env: deps=high
- php: nightly
- php: hhvm
allow_failures:
- php: nightly
- php: hhvm
fast_finish: true
env:
global:
- deps=no
- SYMFONY_DEPRECATIONS_HELPER=weak
before_install:
- composer self-update
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi;
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then php -i; fi;
# Set the COMPOSER_ROOT_VERSION to the right version according to the branch being built
- if [ "$TRAVIS_BRANCH" = "master" ]; then export COMPOSER_ROOT_VERSION=dev-master; else export COMPOSER_ROOT_VERSION="$TRAVIS_BRANCH".x-dev; fi;
install:
- if [[ "$TRAVIS_PHP_VERSION" != "5.3" ]] && [[ "$TRAVIS_PHP_VERSION" != "5.4" ]]; then composer require --no-update zendframework/zend-diactoros; fi;
- if [ "$deps" = "no" ]; then export SYMFONY_DEPRECATIONS_HELPER=strict; fi;
- if [ "$deps" = "no" ]; then composer --prefer-source install; fi;
- if [ "$deps" = "high" ]; then composer --prefer-source update; fi;
- if [ "$deps" = "low" ]; then composer --prefer-source --prefer-lowest --prefer-stable update; fi;
script:
- phpunit

View file

@ -0,0 +1,7 @@
CHANGELOG
=========
2.8.0
-----
* added the component

View file

@ -0,0 +1,164 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PsrHttpMessage\Factory;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Zend\Diactoros\Response as DiactorosResponse;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory as DiactorosRequestFactory;
use Zend\Diactoros\Stream as DiactorosStream;
use Zend\Diactoros\UploadedFile as DiactorosUploadedFile;
/**
* Builds Psr\HttpMessage instances using the Zend Diactoros implementation.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DiactorosFactory implements HttpMessageFactoryInterface
{
public function __construct()
{
if (!class_exists('Zend\Diactoros\ServerRequestFactory')) {
throw new \RuntimeException('Zend Diactoros must be installed to use the DiactorosFactory.');
}
}
/**
* {@inheritdoc}
*/
public function createRequest(Request $symfonyRequest)
{
$server = DiactorosRequestFactory::normalizeServer($symfonyRequest->server->all());
$headers = $symfonyRequest->headers->all();
try {
$body = new DiactorosStream($symfonyRequest->getContent(true));
} catch (\LogicException $e) {
$body = new DiactorosStream('php://temp', 'wb+');
$body->write($symfonyRequest->getContent());
}
$request = new ServerRequest(
$server,
DiactorosRequestFactory::normalizeFiles($this->getFiles($symfonyRequest->files->all())),
$symfonyRequest->getUri(),
$symfonyRequest->getMethod(),
$body,
$headers
);
$request = $request
->withCookieParams($symfonyRequest->cookies->all())
->withQueryParams($symfonyRequest->query->all())
->withParsedBody($symfonyRequest->request->all())
;
foreach ($symfonyRequest->attributes->all() as $key => $value) {
$request = $request->withAttribute($key, $value);
}
return $request;
}
/**
* Converts Symfony uploaded files array to the PSR one.
*
* @param array $uploadedFiles
*
* @return array
*/
private function getFiles(array $uploadedFiles)
{
$files = array();
foreach ($uploadedFiles as $key => $value) {
if ($value instanceof UploadedFile) {
$files[$key] = $this->createUploadedFile($value);
} else {
$files[$key] = $this->getFiles($value);
}
}
return $files;
}
/**
* Creates a PSR-7 UploadedFile instance from a Symfony one.
*
* @param UploadedFile $symfonyUploadedFile
*
* @return UploadedFileInterface
*/
private function createUploadedFile(UploadedFile $symfonyUploadedFile)
{
return new DiactorosUploadedFile(
$symfonyUploadedFile->getRealPath(),
$symfonyUploadedFile->getSize(),
$symfonyUploadedFile->getError(),
$symfonyUploadedFile->getClientOriginalName(),
$symfonyUploadedFile->getClientMimeType()
);
}
/**
* {@inheritdoc}
*/
public function createResponse(Response $symfonyResponse)
{
if ($symfonyResponse instanceof BinaryFileResponse) {
$stream = new DiactorosStream($symfonyResponse->getFile()->getPathname(), 'r');
} else {
$stream = new DiactorosStream('php://temp', 'wb+');
if ($symfonyResponse instanceof StreamedResponse) {
ob_start(function ($buffer) use ($stream) {
$stream->write($buffer);
return false;
});
$symfonyResponse->sendContent();
ob_end_clean();
} else {
$stream->write($symfonyResponse->getContent());
}
}
$headers = $symfonyResponse->headers->all();
$cookies = $symfonyResponse->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = array();
foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
}
}
$response = new DiactorosResponse(
$stream,
$symfonyResponse->getStatusCode(),
$headers
);
$protocolVersion = $symfonyResponse->getProtocolVersion();
if ('1.1' !== $protocolVersion) {
$response = $response->withProtocolVersion($protocolVersion);
}
return $response;
}
}

View file

@ -0,0 +1,199 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PsrHttpMessage\Factory;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UploadedFileInterface;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* {@inheritdoc}
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class HttpFoundationFactory implements HttpFoundationFactoryInterface
{
/**
* {@inheritdoc}
*/
public function createRequest(ServerRequestInterface $psrRequest)
{
$parsedBody = $psrRequest->getParsedBody();
$parsedBody = is_array($parsedBody) ? $parsedBody : array();
$request = new Request(
$psrRequest->getQueryParams(),
$parsedBody,
$psrRequest->getAttributes(),
$psrRequest->getCookieParams(),
$this->getFiles($psrRequest->getUploadedFiles()),
$psrRequest->getServerParams(),
$psrRequest->getBody()->__toString()
);
$request->headers->replace($psrRequest->getHeaders());
return $request;
}
/**
* Converts to the input array to $_FILES structure.
*
* @param array $uploadedFiles
*
* @return array
*/
private function getFiles(array $uploadedFiles)
{
$files = array();
foreach ($uploadedFiles as $key => $value) {
if ($value instanceof UploadedFileInterface) {
$files[$key] = $this->createUploadedFile($value);
} else {
$files[$key] = $this->getFiles($value);
}
}
return $files;
}
/**
* Creates Symfony UploadedFile instance from PSR-7 ones.
*
* @param UploadedFileInterface $psrUploadedFile
*
* @return UploadedFile
*/
private function createUploadedFile(UploadedFileInterface $psrUploadedFile)
{
$temporaryPath = $this->getTemporaryPath();
$psrUploadedFile->moveTo($temporaryPath);
$clientFileName = $psrUploadedFile->getClientFilename();
return new UploadedFile(
$temporaryPath,
null === $clientFileName ? '' : $clientFileName,
$psrUploadedFile->getClientMediaType(),
$psrUploadedFile->getSize(),
$psrUploadedFile->getError(),
true
);
}
/**
* Gets a temporary file path.
*
* @return string
*/
protected function getTemporaryPath()
{
return tempnam(sys_get_temp_dir(), uniqid('symfony', true));
}
/**
* {@inheritdoc}
*/
public function createResponse(ResponseInterface $psrResponse)
{
$response = new Response(
$psrResponse->getBody()->__toString(),
$psrResponse->getStatusCode(),
$psrResponse->getHeaders()
);
$response->setProtocolVersion($psrResponse->getProtocolVersion());
foreach ($psrResponse->getHeader('Set-Cookie') as $cookie) {
$response->headers->setCookie($this->createCookie($cookie));
}
return $response;
}
/**
* Creates a Cookie instance from a cookie string.
*
* Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34
*
* @param string $cookie
*
* @return Cookie
*
* @throws \InvalidArgumentException
*/
private function createCookie($cookie)
{
foreach (explode(';', $cookie) as $part) {
$part = trim($part);
$data = explode('=', $part, 2);
$name = $data[0];
$value = isset($data[1]) ? trim($data[1], " \n\r\t\0\x0B\"") : null;
if (!isset($cookieName)) {
$cookieName = $name;
$cookieValue = $value;
continue;
}
if ('expires' === strtolower($name) && null !== $value) {
$cookieExpire = new \DateTime($value);
continue;
}
if ('path' === strtolower($name) && null !== $value) {
$cookiePath = $value;
continue;
}
if ('domain' === strtolower($name) && null !== $value) {
$cookieDomain = $value;
continue;
}
if ('secure' === strtolower($name)) {
$cookieSecure = true;
continue;
}
if ('httponly' === strtolower($name)) {
$cookieHttpOnly = true;
continue;
}
}
if (!isset($cookieName)) {
throw new \InvalidArgumentException('The value of the Set-Cookie header is malformed.');
}
return new Cookie(
$cookieName,
$cookieValue,
isset($cookieExpire) ? $cookieExpire : 0,
isset($cookiePath) ? $cookiePath : '/',
isset($cookieDomain) ? $cookieDomain : null,
isset($cookieSecure),
isset($cookieHttpOnly)
);
}
}

View file

@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PsrHttpMessage;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Creates Symfony Request and Response instances from PSR-7 ones.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
interface HttpFoundationFactoryInterface
{
/**
* Creates a Symfony Request instance from a PSR-7 one.
*
* @param ServerRequestInterface $psrRequest
*
* @return Request
*/
public function createRequest(ServerRequestInterface $psrRequest);
/**
* Creates a Symfony Response instance from a PSR-7 one.
*
* @param ResponseInterface $psrResponse
*
* @return Response
*/
public function createResponse(ResponseInterface $psrResponse);
}

View file

@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PsrHttpMessage;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Creates PSR HTTP Request and Response instances from Symfony ones.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
interface HttpMessageFactoryInterface
{
/**
* Creates a PSR-7 Request instance from a Symfony one.
*
* @param Request $symfonyRequest
*
* @return ServerRequestInterface
*/
public function createRequest(Request $symfonyRequest);
/**
* Creates a PSR-7 Response instance from a Symfony one.
*
* @param Response $symfonyResponse
*
* @return ResponseInterface
*/
public function createResponse(Response $symfonyResponse);
}

View file

@ -0,0 +1,19 @@
Copyright (c) 2004-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,14 @@
PSR-7 Bridge
============
Provides integration for PSR7.
Resources
---------
If you want to run the unit tests, install dev dependencies before
running PHPUnit:
$ cd path/to/Symfony/Bridge/PsrHttpMessage/
$ composer.phar install
$ phpunit

View file

@ -0,0 +1,33 @@
{
"name": "symfony/psr-http-message-bridge",
"type": "symfony-bridge",
"description": "PSR HTTP message bridge",
"keywords": ["http", "psr-7", "http-message"],
"homepage": "http://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3",
"psr/http-message": "~1.0",
"symfony/http-foundation": "~2.3|~3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7|~3.0"
},
"suggest": {
"zendframework/zend-diactoros": "To use the Zend Diactoros factory"
},
"autoload": {
"psr-4": { "Symfony\\Bridge\\PsrHttpMessage\\": "" }
},
"minimum-stability": "dev"
}

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Symfony PSR-7 HTTP message Bridge Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>