Skip to content

Commit

Permalink
add psr7 factory and use psr7 stream and uri interface
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jun 6, 2015
1 parent 28a3350 commit a5ba088
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 640 deletions.
176 changes: 104 additions & 72 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -183,78 +183,6 @@ PSX includes a number of subcomponents with separate copyright notices
and license terms. Your use of these subcomponents is subject to the terms and
conditions of the following licenses.

################################################################################
- psr/log

Copyright (c) 2013 PHP Framework Interop Group

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.

################################################################################
- monolog/monolog

Copyright (c) 2011-2014 Jordi Boggiano

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.

################################################################################
- symfony/console
- symfony/dependency-injection
- symfony/event-dispatcher
- symfony/yaml

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.

################################################################################
- doctrine/annotations
- doctrine/dbal
Expand Down Expand Up @@ -484,3 +412,107 @@ SOFTWARE.
See the License for the specific language governing permissions and
limitations under the License.

################################################################################
- monolog/monolog

Copyright (c) 2011-2014 Jordi Boggiano

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.

################################################################################
- psr/http-message
- psr/log

Copyright (c) 2013 PHP Framework Interop Group

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.

################################################################################
- symfony/console
- symfony/dependency-injection
- symfony/event-dispatcher
- symfony/yaml

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.

################################################################################
- zendframework/zend-diactoros

Copyright (c) 2015, 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.

10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
],
"require": {
"php": ">=5.4",
"psr/log": "~1.0",
"doctrine/annotations": "~1.2",
"doctrine/dbal": "~2.5",
"jms/serializer": "0.16.0",
"monolog/monolog": "~1.0",
"psr/http-message": "~1.0",
"psr/log": "~1.0",
"symfony/console": "~2.6",
"symfony/dependency-injection": "~2.6",
"symfony/event-dispatcher": "~2.6",
"symfony/yaml": "~2.6",
"doctrine/annotations": "~1.2",
"doctrine/dbal": "~2.5",
"jms/serializer": "0.16.0"
"zendframework/zend-diactoros": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,24 @@
* limitations under the License.
*/

namespace PSX\Http\Psr;
namespace PSX\Http\Factory;

use Psr\Http\Message\RequestInterface as PsrRequestInterface;
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
use Psr\Http\Message\ServerRequestInterface as PsrServerRequestInterface;
use PSX\Http\Request;
use PSX\Http\RequestInterface;
use PSX\Http\Response;
use PSX\Http\ResponseInterface;
use PSX\Uri;

/**
* Factory
* NativeFactory
*
* @author Christoph Kappestein <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link http://phpsx.org
*/
class Factory implements FactoryInterface
class NativeFactory
{
public function getPsrRequest(RequestInterface $request)
{
// @TODO wait until the PSR gets accepted and use an open-source
// implementation

return null;
}

public function getPsrServerRequest(RequestInterface $request)
{
// @TODO wait until the PSR gets accepted and use an open-source
// implementation

return null;
}

public function getPsrResponse(ResponseInterface $response)
{
// @TODO wait until the PSR gets accepted and use an open-source
// implementation

return null;
}

public function getNativeRequest(PsrRequestInterface $psrRequest)
{
return new Request(
new Uri($psrRequest->getUri()),
$psrRequest->getMethod(),
$psrRequest->getHeaders(),
$psrRequest->getBody()
);
}

public function getNativeServerRequest(PsrServerRequestInterface $psrRequest)
public static function createRequest(PsrServerRequestInterface $psrRequest)
{
$request = new Request(
new Uri($psrRequest->getUri()),
Expand All @@ -81,10 +44,16 @@ public function getNativeServerRequest(PsrServerRequestInterface $psrRequest)
$psrRequest->getBody()
);

$attributes = $psrRequest->getAttributes();
foreach($attributes as $name => $value)
{
$request->setAttribute($name, $value);
}

return $request;
}

public function getNativeResponse(PsrResponseInterface $psrResponse)
public static function createResponse(PsrResponseInterface $psrResponse)
{
return new Response(
$psrResponse->getStatusCode(),
Expand Down
60 changes: 60 additions & 0 deletions library/PSX/Http/Factory/Psr7Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
* PSX is a open source PHP framework to develop RESTful APIs.
* For the current version and informations visit <http://phpsx.org>
*
* Copyright 2010-2015 Christoph Kappestein <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace PSX\Http\Factory;

use Zend\Diactoros\Response as PsrResponse;
use Zend\Diactoros\ServerRequestFactory;
use PSX\Http\RequestInterface;
use PSX\Http\ResponseInterface;

/**
* Psr7Factory
*
* @author Christoph Kappestein <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link http://phpsx.org
*/
class Psr7Factory
{
public static function createRequest(RequestInterface $request)
{
$psrRequest = ServerRequestFactory::fromGlobals()
->withUri($request->getUri())
->withMethod($request->getMethod())
->withBody($request->getBody());

foreach($request->getHeaders() as $name => $values)
{
$psrRequest = $psrRequest->withHeader($name, $values);
}

return $psrRequest;
}

public static function createResponse(ResponseInterface $response)
{
return new PsrResponse(
$response->getBody(),
$response->getStatusCode(),
$response->getHeaders()
);
}
}
2 changes: 1 addition & 1 deletion library/PSX/Http/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
namespace PSX\Http;

use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use PSX\Http\Stream;
use PSX\Http\StreamInterface;

/**
* Message
Expand Down
4 changes: 3 additions & 1 deletion library/PSX/Http/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace PSX\Http;

use Psr\Http\Message\StreamInterface;

/**
* This is a mutable version of the PSR HTTP message interface
*
Expand All @@ -32,7 +34,7 @@
* @link http://phpsx.org
* @link http://www.ietf.org/rfc/rfc7230.txt
* @link http://www.ietf.org/rfc/rfc7231.txt
* @see https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md
*/
interface MessageInterface
{
Expand Down
Loading

0 comments on commit a5ba088

Please sign in to comment.