Skip to content

Commit

Permalink
#6 migrate Zend_Amf_Server
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Apr 30, 2016
1 parent ebcabe7 commit 03dc8a5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 75 deletions.
2 changes: 1 addition & 1 deletion fproject/amf/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

/**
* Handle the incoming AMF request by deserializing the data to php object
* types and storing the data for Zend_Amf_Server to handle for processing.
* types and storing the data for fproject\amf\Server to handle for processing.
*
* @todo Currently not checking if the object needs to be Type Mapped to a server object.
*/
Expand Down
99 changes: 46 additions & 53 deletions fproject/Zend/Amf/Server.php → fproject/amf/Server.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?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\auth\AuthAbstract;
use fproject\amf\loader\ResourceLoader;
use fproject\amf\reflect\AbstractFunctionReflector;
use fproject\amf\reflect\FunctionReflector;
use fproject\amf\reflect\MethodReflector;
use fproject\amf\AmfException;
use fproject\amf\reflect\ClassReflector;
use fproject\amf\reflect\ReflectorHelper;
use fproject\amf\value\messaging\AcknowledgeMessage;
Expand All @@ -34,24 +32,20 @@
use fproject\amf\value\messaging\RemotingMessage;
use fproject\amf\value\MessageHeader;
use fproject\amf\value\MessageBody;
use fproject\amf\Constants;
use fproject\amf\parse\TypeLoader;
use fproject\amf\Request;
use fproject\amf\HttpRequest;
use fproject\amf\Response;
use fproject\amf\HttpResponse;
use fproject\amf\acl\Acl;
use fproject\amf\acl\Resource;
use Exception;
use fproject\amf\auth\Auth;
use fproject\amf\auth\AuthResult;

/**
* An AMF gateway server implementation to allow the connection of the Adobe Flash Player to
* Zend Framework
*
* @todo Make the reflection methods cache and autoload.
* @package Zend_Amf
* @subpackage Server
* @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_Server
class Server
{
/**
* Array of dispatchables
Expand Down Expand Up @@ -118,7 +112,7 @@ class Zend_Amf_Server
/**
* ACL handler object
*
* @var \fproject\amf\acl\Acl
* @var Acl
*/
protected $_acl;
/**
Expand All @@ -136,7 +130,7 @@ public function __construct()
* the ACL of this instance with it (if none exists already).
*
* @param AuthAbstract $auth
* @return Zend_Amf_Server
* @return Server
*/
public function setAuth(AuthAbstract $auth)
{
Expand All @@ -159,18 +153,18 @@ public function getAuth()
/**
* Set ACL adapter
*
* @param \fproject\amf\acl\Acl $acl
* @return Zend_Amf_Server
* @param Acl $acl
* @return Server
*/
public function setAcl(\fproject\amf\acl\Acl $acl)
public function setAcl(Acl $acl)
{
$this->_acl = $acl;
return $this;
}
/**
* Get ACL adapter
*
* @return \fproject\amf\acl\Acl
* @return Acl
*/
public function getAcl()
{
Expand All @@ -181,7 +175,7 @@ public function getAcl()
* Set production flag
*
* @param bool $flag
* @return Zend_Amf_Server
* @return Server
*/
public function setProduction($flag)
{
Expand All @@ -201,7 +195,7 @@ public function isProduction()

/**
* @param string $namespace
* @return Zend_Amf_Server
* @return Server
* @internal param of $namespace all incoming sessions defaults to Zend_Amf
*/
public function setSession($namespace = 'Zend_Amf')
Expand Down Expand Up @@ -236,7 +230,7 @@ protected function _checkAcl($object, $function)
if($object) {
$class = is_object($object)?get_class($object):$object;
if(!$this->_acl->has($class)) {
$this->_acl->addResource(new \fproject\amf\acl\Resource($class));
$this->_acl->addResource(new Resource($class));
}
$call = array($object, "initAcl");
if(is_callable($call) && !call_user_func($call, $this->_acl)) {
Expand All @@ -247,7 +241,7 @@ protected function _checkAcl($object, $function)
$class = null;
}

$auth = \fproject\amf\auth\Auth::getInstance();
$auth = Auth::getInstance();
if($auth->hasIdentity()) {
$role = $auth->getIdentity()->role;
} else {
Expand Down Expand Up @@ -397,7 +391,7 @@ protected function _loadCommandMessage(CommandMessage $message)
break;
case CommandMessage::LOGOUT_OPERATION :
if($this->_auth) {
\fproject\amf\auth\Auth::getInstance()->clearIdentity();
Auth::getInstance()->clearIdentity();
}
$return = new AcknowledgeMessage($message);
break;
Expand Down Expand Up @@ -445,7 +439,7 @@ protected function _errorMessage($objectEncoding, $message, $description, $detai
*
* @param string $userId
* @param string $password
* @return bool|\fproject\amf\auth\AuthResult
* @return bool|AuthResult
* @throws AmfException
*
*/
Expand All @@ -455,7 +449,7 @@ protected function _handleAuth( $userId, $password)
return true;
}
$this->_auth->setCredentials($userId, $password);
$auth = \fproject\amf\auth\Auth::getInstance();
$auth = Auth::getInstance();
$result = $auth->authenticate($this->_auth);
if ($result->isValid()) {
if (!$this->isSession()) {
Expand Down Expand Up @@ -503,7 +497,7 @@ protected function _handle(Request $request)
$headers[Constants::CREDENTIALS_HEADER]->userid,
$headers[Constants::CREDENTIALS_HEADER]->password
);
if ($authResult === true || $authResult->getCode() == \fproject\amf\auth\AuthResult::SUCCESS) {
if ($authResult === true || $authResult->getCode() == AuthResult::SUCCESS) {
// use RequestPersistentHeader to clear credentials
$response->addAmfHeader(
new MessageHeader(
Expand Down Expand Up @@ -661,7 +655,7 @@ public function handle($request = null)
* Set request object
*
* @param string|Request $request
* @return Zend_Amf_Server
* @return Server
* @throws AmfException
*/
public function setRequest($request)
Expand Down Expand Up @@ -696,7 +690,7 @@ public function getRequest()
* Public access method to private Response reference
*
* @param string|Response $response
* @return Zend_Amf_Server
* @return Server
* @throws AmfException
*/
public function setResponse($response)
Expand Down Expand Up @@ -738,7 +732,7 @@ public function getResponse()
* @param string|object $class
* @param string $namespace Optional
* @param mixed $argv Optional arguments to pass to a method
* @return Zend_Amf_Server
* @return Server
* @throws AmfException on invalid input
* @throws AmfException
*/
Expand Down Expand Up @@ -777,7 +771,7 @@ public function setClass($class, $namespace = '', $argv = null)
*
* @param string|array $function Valid callback
* @param string $namespace Optional namespace prefix
* @return Zend_Amf_Server
* @return Server
* @throws AmfException
*/
public function addFunction($function, $namespace = '')
Expand Down Expand Up @@ -867,14 +861,13 @@ protected function _buildDispatchTable()
}



/**
* Raise a server fault
*
* Unimplemented
*
* @param string|Exception $fault
* @return void
* @param int $code
*/
public function fault($fault = null, $code = 404)
{
Expand Down Expand Up @@ -922,7 +915,7 @@ public function loadFunctions($definition)
*
* @param string $asClass
* @param string $phpClass
* @return Zend_Amf_Server
* @return Server
*/
public function setClassMap($asClass, $phpClass)
{
Expand All @@ -948,7 +941,7 @@ public function listMethods()
* Takes the provided parameters from the request, and attempts to cast them
* to objects, if the prototype defines any as explicit object types
*
* @param Reflection $reflectionMethod
* @param MethodReflector $reflectionMethod
* @param array $params
* @return array
* @updated 2014/05/24: Bui Sy Nguyen <[email protected]> modified to support typed array parameter
Expand Down
4 changes: 3 additions & 1 deletion fproject/amf/reflect/AbstractFunctionReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* method invocation arguments, and retrieving the
* method {@link Prototype prototypes}.
*
* @method string getName()
*
*/
abstract class AbstractFunctionReflector
{
Expand Down Expand Up @@ -461,7 +463,7 @@ public function getDescription()
* Retrieve all prototypes as array of
* {@link Prototype Prototypes}
*
* @return array
* @return Prototype[]
*/
public function getPrototypes()
{
Expand Down
8 changes: 6 additions & 2 deletions fproject/amf/reflect/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
*
* Proxies calls to a ReflectionClass object, and decorates getMethods() by
* creating its own list of {@link MethodReflector}s.
*
*
* @method string getName()
*
* @method mixed newInstance()
*
*/
class ClassReflector
{
Expand Down Expand Up @@ -139,7 +143,7 @@ public function __set($key, $value)
* Return array of dispatchable {@link MethodReflector}s.
*
* @access public
* @return array
* @return MethodReflector[]
*/
public function getMethods()
{
Expand Down
2 changes: 1 addition & 1 deletion fproject/amf/reflect/Prototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getReturnValue()
/**
* Retrieve method parameters
*
* @return array Array of {@link ParameterReflector}s
* @return ParameterReflector[] Array of {@link ParameterReflector}s
*/
public function getParameters()
{
Expand Down
7 changes: 3 additions & 4 deletions tests/Zend/Amf/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
define("PHPUnit_MAIN_METHOD", "Zend_Amf_AuthTest::main");
}

require_once 'Zend/Amf/Server.php';

use fproject\amf\value\messaging\AcknowledgeMessage;
use fproject\amf\value\messaging\CommandMessage;
use fproject\amf\value\messaging\ErrorMessage;
use fproject\amf\value\MessageBody;
use fproject\amf\Constants;
use fproject\amf\parse\TypeLoader;
use fproject\amf\Request;
use fproject\amf\Server;

/**
* @category Zend
Expand All @@ -49,7 +48,7 @@ class Zend_Amf_AuthTest extends PHPUnit_Framework_TestCase
/**
* Enter description here...
*
* @var Zend_Amf_Server
* @var Server
*/
protected $_server;

Expand All @@ -61,7 +60,7 @@ public static function main()

public function setUp()
{
$this->_server = new Zend_Amf_Server();
$this->_server = new Server();
$this->_server->setProduction(false);
TypeLoader::resetMap();
$this->_acl = new \fproject\amf\acl\Acl();
Expand Down
7 changes: 3 additions & 4 deletions tests/Zend/Amf/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
* @version $Id$
*/

require_once 'Zend/Amf/Server.php';

use fproject\amf\value\MessageBody;
use fproject\amf\parse\TypeLoader;
use fproject\amf\Request;
use fproject\amf\Server;

/**
* @category Zend
Expand All @@ -40,13 +39,13 @@ class Zend_Amf_ResourceTest extends PHPUnit_Framework_TestCase
/**
* Enter description here...
*
* @var Zend_Amf_Server
* @var Server
*/
protected $_server;

public function setUp()
{
$this->_server = new Zend_Amf_Server();
$this->_server = new Server();
$this->_server->setProduction(false);
TypeLoader::resetMap();
}
Expand Down
Loading

0 comments on commit 03dc8a5

Please sign in to comment.