Skip to content

Commit

Permalink
#6 migrate Zend_Amf_Response
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Apr 30, 2016
1 parent 9f6eaef commit 6887831
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 53 deletions.
5 changes: 2 additions & 3 deletions fproject/Zend/Amf/Response/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* @version $Id$
*/

/** Zend_Amf_Response */
require_once 'Zend/Amf/Response.php';
use fproject\amf\Response;

/**
* Creates the proper http headers and send the serialized AMF stream to standard out.
Expand All @@ -31,7 +30,7 @@
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Response_Http extends Zend_Amf_Response
class Zend_Amf_Response_Http extends Response
{
/**
* Create the application response header for AMF and sends the serialized AMF string
Expand Down
21 changes: 11 additions & 10 deletions fproject/Zend/Amf/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use fproject\amf\parse\TypeLoader;
use fproject\amf\Request;
use fproject\amf\HttpRequest;
use fproject\amf\Response;

/**
* An AMF gateway server implementation to allow the connection of the Adobe Flash Player to
Expand Down Expand Up @@ -85,7 +86,7 @@ class Zend_Amf_Server

/**
* Class to use for responses
* @var null|Zend_Amf_Response
* @var null|Response
*/
protected $_response;

Expand Down Expand Up @@ -475,7 +476,7 @@ protected function _handleAuth( $userId, $password)
* @todo should implement and SPL observer pattern for custom AMF headers
* @todo DescribeService support
* @param Request $request
* @return Zend_Amf_Response
* @return Response
* @throws AmfException|Exception
*/
protected function _handle(Request $request)
Expand Down Expand Up @@ -622,7 +623,7 @@ protected function _handle(Request $request)
* Handle an AMF call from the gateway.
*
* @param null|Request $request Optional
* @return Zend_Amf_Response
* @return Response
* @throws AmfException
*/
public function handle($request = null)
Expand All @@ -643,7 +644,7 @@ public function handle($request = null)
// Check for errors that may have happend in deserialization of Request.
try {
// Take converted PHP objects and handle service call.
// Serialize to Zend_Amf_response for output stream
// Serialize to Response for output stream
$this->_handle($request);
$response = $this->getResponse();
} catch (Exception $e) {
Expand Down Expand Up @@ -691,30 +692,30 @@ public function getRequest()
}

/**
* Public access method to private Zend_Amf_Server_Response reference
* Public access method to private Response reference
*
* @param string|Zend_Amf_Server_Response $response
* @param string|Response $response
* @return Zend_Amf_Server
* @throws AmfException
*/
public function setResponse($response)
{
if (is_string($response) && class_exists($response)) {
$response = new $response();
if (!$response instanceof Zend_Amf_Response) {
if (!$response instanceof Response) {
throw new AmfException('Invalid response class');
}
} elseif (!$response instanceof Zend_Amf_Response) {
} elseif (!$response instanceof Response) {
throw new AmfException('Invalid response object');
}
$this->_response = $response;
return $this;
}

/**
* get a reference to the Zend_Amf_response instance
* Get a reference to the Response instance
*
* @return Zend_Amf_Response
* @return Response
*/
public function getResponse()
{
Expand Down
2 changes: 1 addition & 1 deletion fproject/amf/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function readBody()
/**
* Return an array of the body objects that were found in the amf request.
*
* @return array {target, response, length, content}
* @return MessageBody[] {target, response, length, content}
*/
public function getAmfBodies()
{
Expand Down
54 changes: 25 additions & 29 deletions fproject/Zend/Amf/Response.php → fproject/amf/Response.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
///////////////////////////////////////////////////////////////////////////////
//
// © Copyright f-project.net 2010-present.
//
// 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 fproject\amf;

use fproject\amf\value\MessageHeader;
use fproject\amf\value\MessageBody;
use fproject\amf\parse\OutputStream;
use fproject\amf\Constants;
use fproject\amf\parse\Amf0Serializer;

/**
* Handles converting the PHP object ready for response back into AMF
*
* @package Zend_Amf
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Response
class Response
{
/**
* @var int Object encoding for response
Expand All @@ -58,7 +54,7 @@ class Zend_Amf_Response
/**
* Instantiate new output stream and start serialization
*
* @return Zend_Amf_Response
* @return Response
*/
public function finalize()
{
Expand All @@ -72,7 +68,7 @@ public function finalize()
* create and AMF stream.
*
* @param OutputStream $stream
* @return Zend_Amf_Response
* @return Response
*/
public function writeMessage(OutputStream $stream)
{
Expand Down Expand Up @@ -147,7 +143,7 @@ public function __toString()
* Add an AMF body to be sent to the Flash Player
*
* @param MessageBody $body
* @return Zend_Amf_Response
* @return Response
*/
public function addAmfBody(MessageBody $body)
{
Expand All @@ -169,7 +165,7 @@ public function getAmfBodies()
* Add an AMF Header to be sent back to the flash player
*
* @param MessageHeader $header
* @return Zend_Amf_Response
* @return Response
*/
public function addAmfHeader(MessageHeader $header)
{
Expand All @@ -191,7 +187,7 @@ public function getAmfHeaders()
* Set the AMF encoding that will be used for serialization
*
* @param int $encoding
* @return Zend_Amf_Response
* @return Response
*/
public function setObjectEncoding($encoding)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Amf/Response/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
require_once 'Zend/Amf/Response/Http.php';

/**
* Test case for Zend_Amf_Response
* Test case for Response
*
* @category Zend
* @package Zend_Amf
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Amf
* @group Zend_Amf_Response
* @group Response
*/
class Zend_Amf_Response_HttpTest extends PHPUnit_Framework_TestCase
{
Expand Down
9 changes: 4 additions & 5 deletions tests/Zend/Amf/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* @version $Id$
*/

require_once 'Zend/Amf/Response.php';

require_once 'Contact.php';
require_once 'ContactVO.php';

Expand All @@ -30,9 +28,10 @@
use fproject\amf\value\MessageBody;
use fproject\amf\parse\TypeLoader;
use fproject\amf\Request;
use fproject\amf\Response;

/**
* Test case for Zend_Amf_Response
* Test case for Response
*
* @category Zend
* @package Zend_Amf
Expand All @@ -48,7 +47,7 @@ class Zend_Amf_ResponseTest extends PHPUnit_Framework_TestCase

/**
* Response object
* @var Zend_Amf_Response
* @var Response
*/
protected $_response;

Expand All @@ -59,7 +58,7 @@ public function setUp()
{
date_default_timezone_set('America/Chicago');
TypeLoader::resetMap();
$this->_response = new Zend_Amf_Response();
$this->_response = new Response();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Zend/Amf/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ public function testSetRequestShouldAllowValidRequestObjects()

public function testSetResponseShouldAllowValidStringClassNames()
{
$this->_server->setResponse('Zend_Amf_Response');
$this->_server->setResponse('fproject\amf\Response');
$response = $this->_server->getResponse();
$this->assertTrue($response instanceof Zend_Amf_Response);
$this->assertTrue($response instanceof Response);
$this->assertFalse($response instanceof Zend_Amf_Response_Http);
}

Expand All @@ -771,7 +771,7 @@ public function testSetResponseShouldRaiseExceptionOnInvalidStringClassName()

public function testSetResponseShouldAllowValidResponseObjects()
{
$response = new Zend_Amf_Response;
$response = new Response;
$this->_server->setResponse($response);
$this->assertSame($response, $this->_server->getResponse());
}
Expand Down

0 comments on commit 6887831

Please sign in to comment.