Skip to content

Commit

Permalink
Implement #6: remove Zend_Amf_Exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Jan 21, 2016
1 parent f2255cc commit a8b02eb
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 131 deletions.
34 changes: 0 additions & 34 deletions fproject/Zend/Amf/Exception.php

This file was deleted.

12 changes: 5 additions & 7 deletions fproject/Zend/Amf/Parse/Amf0/Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Zend_Amf_Parse_Amf0_Deserializer extends Zend_Amf_Parse_Deserializer
*
* @param integer $typeMarker
* @return mixed whatever the data type is of the marker in php
* @throws Zend_Amf_Exception for invalid type
* @throws \fproject\amf\AmfException for invalid type
*/
public function readTypeMarker($typeMarker = null)
{
Expand Down Expand Up @@ -133,8 +133,7 @@ public function readTypeMarker($typeMarker = null)
return $this->readAmf3TypeMarker();

default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unsupported marker type: ' . $typeMarker);
throw new \fproject\amf\AmfException('Unsupported marker type: ' . $typeMarker);
}
}

Expand Down Expand Up @@ -177,14 +176,13 @@ public function readObject($object = null)
* Called when marker type is 7.
*
* @return object
* @throws Zend_Amf_Exception for invalid reference keys
* @throws \fproject\amf\AmfException for invalid reference keys
*/
public function readReference()
{
$key = $this->_stream->readInt();
if (!array_key_exists($key, $this->_reference)) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Invalid reference key: '. $key);
throw new \fproject\amf\AmfException('Invalid reference key: '. $key);
}
return $this->_reference[$key];
}
Expand Down Expand Up @@ -268,7 +266,7 @@ public function readXmlString()
*
* @todo implement Typed Class mapping
* @return object|array
* @throws Zend_Amf_Exception if unable to load type
* @throws \fproject\amf\AmfException if unable to load type
*/
public function readTypedObject()
{
Expand Down
13 changes: 5 additions & 8 deletions fproject/Zend/Amf/Parse/Amf0/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
* @param mixed $markerType
* @param mixed $dataByVal
* @return Zend_Amf_Parse_Amf0_Serializer
* @throws Zend_Amf_Exception for unrecognized types or data
* @throws \fproject\amf\AmfException for unrecognized types or data
*/
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
{
Expand Down Expand Up @@ -112,8 +112,7 @@ public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
$this->writeAmf3TypeMarker($data);
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception("Unknown Type Marker: " . $markerType);
throw new \fproject\amf\AmfException("Unknown Type Marker: " . $markerType);
}
}
} else {
Expand Down Expand Up @@ -175,8 +174,7 @@ public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
}
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
throw new \fproject\amf\AmfException('Unsupported data type: ' . gettype($data));
}

$this->writeTypeMarker($data, $markerType);
Expand Down Expand Up @@ -270,16 +268,15 @@ public function writeArray(&$array)
* Convert the DateTime into an AMF Date
*
* @param DateTime $data
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Amf_Parse_Amf0_Serializer
*/
public function writeDate($data)
{
if ($data instanceof DateTime) {
$dateString = $data->format('U');
} else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Invalid date specified; must be a DateTime object');
throw new \fproject\amf\AmfException('Invalid date specified; must be a DateTime object');
}
$dateString *= 1000;

Expand Down
14 changes: 7 additions & 7 deletions fproject/Zend/Amf/Parse/Amf3/Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Zend_Amf_Parse_Amf3_Deserializer extends Zend_Amf_Parse_Deserializer
*
* @param integer $typeMarker
* @return mixed Whatever the corresponding PHP data type is
* @throws Zend_Amf_Exception for unidentified marker type
* @throws \fproject\amf\AmfException for unidentified marker type
*/
public function readTypeMarker($typeMarker = null)
{
Expand Down Expand Up @@ -212,7 +212,7 @@ public function readString()
*
* - date = 0x08 integer-data [ number-data ]
*
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
* @return DateTime date-time object
*
* 2014/05/24: Bui Sy Nguyen <[email protected]> modified to use
Expand Down Expand Up @@ -275,7 +275,7 @@ public function readArray()
* Read an amf Vector to PHP array
*
* @return array
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function readVector($type)
{
Expand Down Expand Up @@ -319,7 +319,7 @@ public function readVector($type)
* @param $eltSize
* @param $numberFormat
* @return array
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function readNumericVector($len, $fixed, $eltSize, $numberFormat)
{
Expand Down Expand Up @@ -363,7 +363,7 @@ public function readNumericVector($len, $fixed, $eltSize, $numberFormat)
* @param int $len
* @param bool $fixed
* @return array
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function readObjectVector($len, $fixed)
{
Expand Down Expand Up @@ -397,7 +397,7 @@ public function readObjectVector($len, $fixed)
/**
* Read amf Dictionary to PHP array
* @return array
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function readDictionary()
{
Expand Down Expand Up @@ -487,7 +487,7 @@ public function readObject()
/**
* @param $className
* @return array
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
protected function createObjectInstance($className)
{
Expand Down
34 changes: 13 additions & 21 deletions fproject/Zend/Amf/Parse/Amf3/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
* In the case $data is NULL, this will param be used as 'byval' value for $data.
* In the case $markerType is a AS3 Vector type (AMF3_VECTOR_INT, AMF3_VECTOR_UINT, AMF3_VECTOR_NUMBER or AMF3_VECTOR_OBJECT),
* the $extraData will contain AS3 reflection information for writing AS3 Vector.
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function writeTypeMarker(&$data, $markerType = null, $extraData = false)
{
Expand Down Expand Up @@ -128,8 +128,7 @@ public function writeTypeMarker(&$data, $markerType = null, $extraData = false)
return $this->writeVector($data, $markerType, $extraData);
//case Zend_Amf_Constants::AMF3_DICTIONARY:
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Type Marker: ' . $markerType);
throw new \fproject\amf\AmfException('Unknown Type Marker: ' . $markerType);
}
} else {
// Detect Type Marker
Expand Down Expand Up @@ -176,8 +175,7 @@ public function writeTypeMarker(&$data, $markerType = null, $extraData = false)
}
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
throw new \fproject\amf\AmfException('Unsupported data type: ' . gettype($data));
}
$this->writeTypeMarker($data, $markerType);
}
Expand Down Expand Up @@ -264,7 +262,7 @@ public function writeString(&$string)
*
* @param string|Zend_Amf_Value_ByteArray $data
* @return Zend_Amf_Parse_Amf3_Serializer
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function writeByteArray(&$data)
{
Expand All @@ -277,8 +275,7 @@ public function writeByteArray(&$data)
} else if ($data instanceof Zend_Amf_Value_ByteArray) {
$data = $data->getData();
} else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Invalid ByteArray specified; must be a string or Zend_Amf_Value_ByteArray');
throw new \fproject\amf\AmfException('Invalid ByteArray specified; must be a string or Zend_Amf_Value_ByteArray');
}

$this->writeBinaryString($data);
Expand All @@ -291,7 +288,7 @@ public function writeByteArray(&$data)
*
* @param DOMDocument|SimpleXMLElement $xml
* @return Zend_Amf_Parse_Amf3_Serializer
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function writeXml($xml)
{
Expand All @@ -306,8 +303,7 @@ public function writeXml($xml)
} else if ($xml instanceof SimpleXMLElement) {
$xml = $xml->asXML();
} else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Invalid xml specified; must be a DOMDocument or SimpleXMLElement');
throw new \fproject\amf\AmfException('Invalid xml specified; must be a DOMDocument or SimpleXMLElement');
}

$this->writeBinaryString($xml);
Expand All @@ -320,7 +316,7 @@ public function writeXml($xml)
*
* @param DateTime $date
* @return Zend_Amf_Parse_Amf3_Serializer
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function writeDate($date)
{
Expand All @@ -333,8 +329,7 @@ public function writeDate($date)
} /*elseif ($date instanceof Zend_Date) {
$dateString = $date->toString('U') * 1000;
}*/ else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Invalid date specified; must be a DateTime object');
throw new \fproject\amf\AmfException('Invalid date specified; must be a DateTime object');
}

$this->writeInteger(0x01);
Expand Down Expand Up @@ -507,7 +502,7 @@ protected function writeObjectReference(&$object, $objectByVal = false)
*
* @param mixed $object
* @return Zend_Amf_Parse_Amf3_Serializer
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function writeObject($object)
{
Expand Down Expand Up @@ -651,18 +646,15 @@ public function writeObject($object)
$this->writeString($this->_strEmpty);
break;
case Zend_Amf_Constants::ET_EXTERNAL:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('External Object Encoding not implemented');
throw new \fproject\amf\AmfException('External Object Encoding not implemented');
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
throw new \fproject\amf\AmfException('Unknown Object Encoding type: ' . $encoding);
}
}
catch (Exception $e)
{
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
throw new \fproject\amf\AmfException('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion fproject/Zend/Amf/Parse/OutputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Zend_Amf_Parse_OutputStream extends Zend_Amf_Util_BinaryStream
/**
* Constructor
*
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public function __construct()
{
Expand Down
18 changes: 7 additions & 11 deletions fproject/Zend/Amf/Parse/TypeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,31 @@ public static function getResourceParser($resource)
*
* @param resource $resource
* @return mixed
* @throws Zend_Amf_Exception
* @throws \fproject\amf\AmfException
*/
public static function handleResource($resource)
{
if(!self::$_resourceLoader) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to handle resources - resource plugin loader not set');
throw new \fproject\amf\AmfException('Unable to handle resources - resource plugin loader not set');
}
try {
while(is_resource($resource)) {
$resclass = self::getResourceParser($resource);
if(!$resclass) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource));
throw new \fproject\amf\AmfException('Can not serialize resource type: '. get_resource_type($resource));
}
$parser = new $resclass();
if(is_callable(array($parser, 'parse'))) {
$resource = $parser->parse($resource);
} else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception("Could not call parse() method on class $resclass");
throw new \fproject\amf\AmfException("Could not call parse() method on class $resclass");
}
}
return $resource;
} catch(Zend_Amf_Exception $e) {
throw new Zend_Amf_Exception($e->getMessage(), $e->getCode(), $e);
} catch(\fproject\amf\AmfException $e) {
throw new \fproject\amf\AmfException($e->getMessage(), $e->getCode(), $e);
} catch(Exception $e) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
throw new \fproject\amf\AmfException('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
}
}
}
Loading

0 comments on commit a8b02eb

Please sign in to comment.