Skip to content

Commit

Permalink
#6: migrate Zend_Amf_Parse_TypeLoader and Zend_Amf_Parse_Amf3_Deseria…
Browse files Browse the repository at this point in the history
…lizer
  • Loading branch information
Bui Sy Nguyen committed Apr 29, 2016
1 parent 153f44e commit ee810cc
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 116 deletions.
8 changes: 4 additions & 4 deletions fproject/Zend/Amf/Parse/Amf0/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use fproject\amf\parse\Serializer;
use fproject\amf\Constants;
use fproject\amf\parse\TypeLoader;

/**
* Serializer PHP misc types back to there corresponding AMF0 Type Marker.
Expand Down Expand Up @@ -114,7 +115,7 @@ public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
}
} else {
if (is_resource($data)) {
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
$data = TypeLoader::handleResource($data);
}
switch (true) {
case (is_int($data) || is_float($data)):
Expand Down Expand Up @@ -323,13 +324,12 @@ public function writeAmf3TypeMarker(&$data)
*/
protected function getClassName($object)
{
require_once 'Zend/Amf/Parse/TypeLoader.php';
//Check to see if the object is a typed object and we need to change
$className = '';
switch (true) {
// the return class mapped name back to actionscript class name.
case Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
$className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object));
case TypeLoader::getMappedClassName(get_class($object)):
$className = TypeLoader::getMappedClassName(get_class($object));
break;
// Check to see if the user has defined an explicit Action Script type.
case isset($object->_explicitType):
Expand Down
8 changes: 3 additions & 5 deletions fproject/Zend/Amf/Parse/Amf3/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* @version $Id$
*/

/** Zend_Amf_Parse_TypeLoader */
require_once 'Zend/Amf/Parse/TypeLoader.php';

use fproject\amf\AmfException;
use fproject\amf\value\ByteArray;
use fproject\amf\parse\Serializer;
use fproject\amf\Constants;
use fproject\amf\parse\TypeLoader;

/**
* Detect PHP object type and convert it to a corresponding AMF3 object type
Expand Down Expand Up @@ -131,7 +129,7 @@ public function writeTypeMarker(&$data, $markerType = null, $extraData = false)
} else {
// Detect Type Marker
if (is_resource($data)) {
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
$data = TypeLoader::handleResource($data);
}
switch (true) {
case (null === $data):
Expand Down Expand Up @@ -511,7 +509,7 @@ public function writeObject($object)
//Check to see if the object is a typed object and we need to change
switch (true) {
// the return class mapped name back to actionscript class name.
case ($className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object))):
case ($className = TypeLoader::getMappedClassName(get_class($object))):
break;

// Check to see if the user has defined an explicit Action Script type.
Expand Down
11 changes: 4 additions & 7 deletions fproject/Zend/Amf/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*/


/** @see Zend_Amf_Parse_TypeLoader */
require_once 'Zend/Amf/Parse/TypeLoader.php';

use fproject\amf\auth\AuthAbstract;
use fproject\amf\loader\ResourceLoader;
use fproject\amf\reflect\AbstractFunctionReflector;
Expand All @@ -38,6 +35,7 @@
use fproject\amf\value\MessageHeader;
use fproject\amf\value\MessageBody;
use fproject\amf\Constants;
use fproject\amf\parse\TypeLoader;

/**
* An AMF gateway server implementation to allow the connection of the Adobe Flash Player to
Expand Down Expand Up @@ -124,7 +122,7 @@ class Zend_Amf_Server
*/
public function __construct()
{
Zend_Amf_Parse_TypeLoader::setResourceLoader(new ResourceLoader(array("Zend_Amf_Parse_Resource" => "Zend/Amf/Parse/Resource")));
TypeLoader::setResourceLoader(new ResourceLoader(array("Zend_Amf_Parse_Resource" => "Zend/Amf/Parse/Resource")));
}

/**
Expand Down Expand Up @@ -288,7 +286,7 @@ protected function getLoader()
protected function _dispatch($method, $params = null, $source = null)
{
if($source) {
if(($mapped = Zend_Amf_Parse_TypeLoader::getMappedClassName($source)) !== false) {
if(($mapped = TypeLoader::getMappedClassName($source)) !== false) {
$source = $mapped;
}
}
Expand Down Expand Up @@ -926,8 +924,7 @@ public function loadFunctions($definition)
*/
public function setClassMap($asClass, $phpClass)
{
require_once 'Zend/Amf/Parse/TypeLoader.php';
Zend_Amf_Parse_TypeLoader::setMapping($asClass, $phpClass);
TypeLoader::setMapping($asClass, $phpClass);
return $this;
}

Expand Down
6 changes: 2 additions & 4 deletions fproject/amf/parse/Amf0Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ public function readXmlString()
*/
public function readTypedObject()
{
require_once 'Zend/Amf/Parse/TypeLoader.php';
// get the remote class name
$className = $this->_stream->readUTF();
$loader = Zend_Amf_Parse_TypeLoader::loadType($className);
$loader = TypeLoader::loadType($className);
$returnObject = new $loader();
$properties = get_object_vars($this->readObject());
foreach($properties as $key=>$value) {
Expand All @@ -285,8 +284,7 @@ public function readTypedObject()
*/
public function readAmf3TypeMarker()
{
require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
$deserializer = new Zend_Amf_Parse_Amf3_Deserializer($this->_stream);
$deserializer = new Amf3Deserializer($this->_stream);
$this->_objectEncoding = Constants::AMF3_OBJECT_ENCODING;
return $deserializer->readTypeMarker();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
<?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
* @subpackage Parse_Amf3
* @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$
*/

/** Zend_Amf_Parse_TypeLoader */
require_once 'Zend/Amf/Parse/TypeLoader.php';
///////////////////////////////////////////////////////////////////////////////
//
// © 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\parse;

use fproject\common\utils\XmlSecurity;
use fproject\amf\value\TraitsInfo;
use fproject\amf\parse\Deserializer;
use fproject\amf\Constants;

/**
Expand All @@ -34,12 +29,8 @@
* @todo readObject to handle Typed Objects
* @todo readXMLStrimg to be implemented.
* @todo Class could be implemented as Factory Class with each data type it's own class.
* @package Zend_Amf
* @subpackage Parse_Amf3
* @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_Parse_Amf3_Deserializer extends Deserializer
class Amf3Deserializer extends Deserializer
{
/**
* An array of reference objects per amf body
Expand Down Expand Up @@ -110,6 +101,7 @@ public function readTypeMarker($typeMarker = null)
//case Constants::AMF3_DICTIONARY:
default:
$this->throwZendException('Unsupported type marker: {0}',[$typeMarker]);
return 0;//To avoid PHP warning
}
}

Expand Down Expand Up @@ -490,13 +482,13 @@ protected function createObjectInstance($className)
// We now have the object traits defined in variables. Time to go to work:
if (!$className){
// No class name generic object
$returnObject = new stdClass();
$returnObject = new \stdClass();
}
else
{
// Defined object
// Typed object lookup against registered classname maps
if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
if ($loader = TypeLoader::loadType($className)) {
$returnObject = new $loader();
$className = $loader;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
<?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
* @subpackage Parse
* @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\parse;

use fproject\amf\loader\ResourceLoaderInterface;
use fproject\amf\AmfException;

/**
* Loads a local class and executes the instantiation of that class.
*
* @todo PHP 5.3 can drastically change this class w/ namespace and the new call_user_func w/ namespace
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
final class Zend_Amf_Parse_TypeLoader
final class TypeLoader
{
/**
* @var string callback class
Expand Down Expand Up @@ -187,31 +182,31 @@ public static function getResourceParser($resource)
*
* @param resource $resource
* @return mixed
* @throws \fproject\amf\AmfException
* @throws AmfException
*/
public static function handleResource($resource)
{
if(!self::$_resourceLoader) {
throw new \fproject\amf\AmfException('Unable to handle resources - resource plugin loader not set');
throw new AmfException('Unable to handle resources - resource plugin loader not set');
}
try {
while(is_resource($resource)) {
$resclass = self::getResourceParser($resource);
if(!$resclass) {
throw new \fproject\amf\AmfException('Can not serialize resource type: '. get_resource_type($resource));
throw new AmfException('Can not serialize resource type: '. get_resource_type($resource));
}
$parser = new $resclass();
if(is_callable(array($parser, 'parse'))) {
$resource = $parser->parse($resource);
} else {
throw new \fproject\amf\AmfException("Could not call parse() method on class $resclass");
throw new AmfException("Could not call parse() method on class $resclass");
}
}
return $resource;
} catch(\fproject\amf\AmfException $e) {
throw new \fproject\amf\AmfException($e->getMessage(), $e->getCode(), $e);
} catch(Exception $e) {
throw new \fproject\amf\AmfException('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
} catch(AmfException $e) {
throw new AmfException($e->getMessage(), $e->getCode(), $e);
} catch(\Exception $e) {
throw new AmfException('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
}
}
}
4 changes: 2 additions & 2 deletions tests/Zend/Amf/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@

require_once 'Zend/Amf/Server.php';
require_once 'Zend/Amf/Request.php';
require_once 'Zend/Amf/Parse/TypeLoader.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;

/**
* @category Zend
Expand Down Expand Up @@ -63,7 +63,7 @@ public function setUp()
{
$this->_server = new Zend_Amf_Server();
$this->_server->setProduction(false);
Zend_Amf_Parse_TypeLoader::resetMap();
TypeLoader::resetMap();
$this->_acl = new \fproject\amf\acl\Acl();
}

Expand Down
Loading

0 comments on commit ee810cc

Please sign in to comment.