FEATURE: First commit for ProcessMaker Rest Support

What is Functional

- Restler thirdparty library added
- Restler integration with gulliver added
- Rest requests are dispatched by sysGeneric
- Restler autodiscover for classes that implements Restler iAuthenticate interface added

What Missing

- ProcessMaker Api implemented yet
- some rest api class are in workflow/engine/services/rest/*.php
This commit is contained in:
Erik Amaru Ortiz
2012-08-10 16:54:12 -04:00
parent f783bc09f4
commit 9b1867a410
41 changed files with 8285 additions and 85 deletions

View File

@@ -917,7 +917,7 @@ class G
* @param string $urlLink
* @return string
*/
static function parseURI($uri, $config = array())
static function parseURI($uri, $isRestRequest = false)
{
//*** process the $_POST with magic_quotes enabled
// The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0.
@@ -926,82 +926,111 @@ class G
}
$aRequestUri = explode('/', $uri );
if ( substr ( $aRequestUri[1], 0, 3 ) == 'sys' ) {
define( 'SYS_TEMP', substr ( $aRequestUri[1], 3 ) );
if ($isRestRequest) {
$args = self::parseRestUri($aRequestUri);
} else {
$args = self::parseNormalUri($aRequestUri);
}
else {
define("ENABLE_ENCRYPT", 'yes' );
define( 'SYS_TEMP', $aRequestUri[1] );
define("SYS_LANG", $args['SYS_LANG']);
define("SYS_SKIN", $args['SYS_SKIN']);
define('SYS_COLLECTION', $args['SYS_COLLECTION']);
define('SYS_TARGET', $args['SYS_TARGET']);
if ( $args['SYS_COLLECTION'] == 'js2' ) {
print "ERROR"; die;
}
}
public function parseNormalUri($aRequestUri)
{
if (substr($aRequestUri[1], 0, 3) == 'sys') {
define('SYS_TEMP', substr($aRequestUri[1], 3));
} else {
define("ENABLE_ENCRYPT", 'yes');
define('SYS_TEMP', $aRequestUri[1]);
$plain = '/sys' . SYS_TEMP;
for ($i = 2 ; $i < count($aRequestUri); $i++ ) {
$decoded = G::decrypt ( urldecode($aRequestUri[$i]) , URL_KEY );
if ( $decoded == 'sWì' ) $decoded = $VARS[$i]; //this is for the string "../"
for ($i = 2; $i < count($aRequestUri); $i++) {
$decoded = G::decrypt(urldecode($aRequestUri[$i]), URL_KEY);
if ( $decoded == 'sWì' ) {
$decoded = $VARS[$i]; //this is for the string "../"
}
$plain .= '/' . $decoded;
}
$_SERVER["REQUEST_URI"] = $plain;
}
$CURRENT_PAGE = $_SERVER["REQUEST_URI"];
$work = explode('?', $_SERVER["REQUEST_URI"]);
$work = explode('?', $CURRENT_PAGE);
if ( count($work) > 1 )
define( 'SYS_CURRENT_PARMS', $work[1]);
else
define( 'SYS_CURRENT_PARMS', '');
define( 'SYS_CURRENT_URI' , $work[0]);
if (!defined('SYS_CURRENT_PARMS'))
if (count($work) > 1) {
define('SYS_CURRENT_PARMS', $work[1]);
} else {
define('SYS_CURRENT_PARMS', '');
}
define('SYS_CURRENT_URI', $work[0]);
if (!defined('SYS_CURRENT_PARMS')) {
define('SYS_CURRENT_PARMS', $work[1]);
}
$preArray = explode('&', SYS_CURRENT_PARMS);
$buffer = explode( '.', $work[0] );
if ( count($buffer) == 1 ) $buffer[1]='';
$buffer = explode('.', $work[0]);
if (count($buffer) == 1) {
$buffer[1]='';
}
//request type
define('REQUEST_TYPE', ($buffer[1] != "" ?$buffer[1] : 'html'));
$toparse = substr($buffer[0], 1, strlen($buffer[0]) - 1);
$URL = "";
$URI_VARS = explode('/', $toparse);
for ( $i=3; $i < count( $URI_VARS) ; $i++)
$URL .= $URI_VARS[$i].'/';
$URI_VARS = explode('/', $toparse);
$uriVars = explode('/', $toparse);
unset($work);
unset($buffer);
unset($toparse);
array_shift($uriVars);
array_shift($URI_VARS);
$SYS_LANG = array_shift($URI_VARS);
$SYS_SKIN = array_shift($URI_VARS);
$SYS_COLLECTION = array_shift($URI_VARS);
$SYS_TARGET = array_shift($URI_VARS);
$args = array();
$args['SYS_LANG'] = array_shift($uriVars);
$args['SYS_SKIN'] = array_shift($uriVars);
$args['SYS_COLLECTION'] = array_shift($uriVars);
$args['SYS_TARGET'] = array_shift($uriVars);
//to enable more than 2 directories...in the methods structure
$exit = 0;
while ( count ( $URI_VARS ) > 0 && $exit == 0) {
$SYS_TARGET .= '/' . array_shift($URI_VARS);
while (count($uriVars) > 0) {
$args['SYS_TARGET'] .= '/' . array_shift($uriVars);
}
/* Fix to prevent use uxs skin outside siplified interface,
because that skin is not compatible with others interfaces*/
if ($SYS_SKIN == 'uxs' && $SYS_COLLECTION != 'home' && $SYS_COLLECTION != 'cases') {
if ($args['SYS_SKIN'] == 'uxs' && $args['SYS_COLLECTION'] != 'home' && $args['SYS_COLLECTION'] != 'cases') {
$config = System::getSystemConfiguration();
$SYS_SKIN = $config['default_skin'];
$args['SYS_SKIN'] = $config['default_skin'];
}
define("SYS_LANG", $SYS_LANG);
define("SYS_SKIN", $SYS_SKIN);
define('SYS_COLLECTION', $SYS_COLLECTION);
define('SYS_TARGET', $SYS_TARGET);
return $args;
}
if ( $SYS_COLLECTION == 'js2' ) {
print "ERROR"; die;
public function parseRestUri($requestUri)
{
$args = array();
//$args['SYS_TEMP'] = $requestUri[1];
define('SYS_TEMP', $requestUri[2]);
$restUri = '';
for ($i=3; $i < count($requestUri); $i++) {
$restUri .= '/' . $requestUri[$i];
}
$args['SYS_LANG'] = 'en'; // TODO, this can be set from http header
$args['SYS_SKIN'] = '';
$args['SYS_COLLECTION'] = '';
$args['SYS_TARGET'] = $restUri;
return $args;
}
function strip_slashes($vVar) {
@@ -5134,7 +5163,43 @@ function getDirectorySize($path,$maxmtime=0)
return false;
}
}
};
/**
* This method allow dispatch rest services using 'Restler' thirdparty library
*
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com>
*/
public function dispatchRestService($uri)
{
require_once 'restler/restler.php';
$rest = new Restler();
$rest->setSupportedFormats('JsonFormat', 'XmlFormat');
// override global REQUEST_URI to pass to Restler library
$_SERVER['REQUEST_URI'] = $uri;
// getting all services class
$srvClasses = glob(PATH_SERVICES_REST . '*.php');
foreach ($srvClasses as $classFile) {
require_once $classFile;
$className = str_replace('.php', '', basename($classFile));
$reflClass = new ReflectionClass($className);
// verify if there is an auth class implementing 'iAuthenticate'
if ($reflClass->implementsInterface('iAuthenticate')) {
// auth class found, set as restler authentication class handler
$rest->addAuthenticationClass($className);
} else {
// add api class
$rest->addAPIClass($className);
}
}
$rest->handle();
}
}
/**
* eprint

View File

@@ -0,0 +1,87 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Constants.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* The following constants are used throughout serialization and
* deserialization to detect the AMF marker and encoding types.
*
* @package Zend_Amf
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
final class Zend_Amf_Constants
{
const AMF0_NUMBER = 0x00;
const AMF0_BOOLEAN = 0x01;
const AMF0_STRING = 0x02;
const AMF0_OBJECT = 0x03;
const AMF0_MOVIECLIP = 0x04;
const AMF0_NULL = 0x05;
const AMF0_UNDEFINED = 0x06;
const AMF0_REFERENCE = 0x07;
const AMF0_MIXEDARRAY = 0x08;
const AMF0_OBJECTTERM = 0x09;
const AMF0_ARRAY = 0x0a;
const AMF0_DATE = 0x0b;
const AMF0_LONGSTRING = 0x0c;
const AMF0_UNSUPPORTED = 0x0e;
const AMF0_XML = 0x0f;
const AMF0_TYPEDOBJECT = 0x10;
const AMF0_AMF3 = 0x11;
const AMF0_OBJECT_ENCODING = 0x00;
const AMF3_UNDEFINED = 0x00;
const AMF3_NULL = 0x01;
const AMF3_BOOLEAN_FALSE = 0x02;
const AMF3_BOOLEAN_TRUE = 0x03;
const AMF3_INTEGER = 0x04;
const AMF3_NUMBER = 0x05;
const AMF3_STRING = 0x06;
const AMF3_XML = 0x07;
const AMF3_DATE = 0x08;
const AMF3_ARRAY = 0x09;
const AMF3_OBJECT = 0x0A;
const AMF3_XMLSTRING = 0x0B;
const AMF3_BYTEARRAY = 0x0C;
const AMF3_OBJECT_ENCODING = 0x03;
// Object encodings for AMF3 object types
const ET_PROPLIST = 0x00;
const ET_EXTERNAL = 0x01;
const ET_DYNAMIC = 0x02;
const ET_PROXY = 0x03;
const FMS_OBJECT_ENCODING = 0x01;
/**
* Special content length value that indicates "unknown" content length
* per AMF Specification
*/
const UNKNOWN_CONTENT_LENGTH = -1;
const URL_APPEND_HEADER = 'AppendToGatewayUrl';
const RESULT_METHOD = '/onResult';
const STATUS_METHOD = '/onStatus';
const CREDENTIALS_HEADER = 'Credentials';
const PERSISTENT_HEADER = 'RequestPersistentHeader';
const DESCRIBE_HEADER = 'DescribeService';
const GUEST_ROLE = 'anonymous';
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,65 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Deserializer.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Abstract cass that all deserializer must implement.
*
* Logic for deserialization of the AMF envelop is based on resources supplied
* by Adobe Blaze DS. For and example of deserialization please review the BlazeDS
* source tree.
*
* @see http://opensource.adobe.com/svn/opensource/blazeds/trunk/modules/core/src/java/flex/messaging/io/amf/
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Amf_Parse_Deserializer
{
/**
* The raw string that represents the AMF request.
*
* @var Zend_Amf_Parse_InputStream
*/
protected $_stream;
/**
* Constructor
*
* @param Zend_Amf_Parse_InputStream $stream
* @return void
*/
public function __construct(Zend_Amf_Parse_InputStream $stream)
{
$this->_stream = $stream;
}
/**
* Checks for AMF marker types and calls the appropriate methods
* for deserializing those marker types. Markers are the data type of
* the following value.
*
* @param int $typeMarker
* @return mixed Whatever the data type is of the marker in php
*/
public abstract function readTypeMarker($markerType = null);
}

View File

@@ -0,0 +1,39 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: InputStream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Amf_Util_BinaryStream */
require_once 'Zend/Amf/Util/BinaryStream.php';
/**
* InputStream is used to iterate at a binary level through the AMF request.
*
* InputStream extends BinaryStream as eventually BinaryStream could be placed
* outside of Zend_Amf in order to allow other packages to use the class.
*
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Parse_InputStream extends Zend_Amf_Util_BinaryStream
{
}

View File

@@ -0,0 +1,49 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: OutputStream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Amf_Util_BinaryStream */
require_once 'Zend/Amf/Util/BinaryStream.php';
/**
* Iterate at a binary level through the AMF response
*
* OutputStream extends BinaryStream as eventually BinaryStream could be placed
* outside of Zend_Amf in order to allow other packages to use the class.
*
* @uses Zend_Amf_Util_BinaryStream
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Parse_OutputStream extends Zend_Amf_Util_BinaryStream
{
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct('');
}
}

View File

@@ -0,0 +1,59 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Serializer.php 21210 2010-02-27 10:37:39Z yoshida@zend.co.jp $
*/
/**
* Base abstract class for all AMF serializers.
*
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Amf_Parse_Serializer
{
/**
* Reference to the current output stream being constructed
*
* @var string
*/
protected $_stream;
/**
* Constructor
*
* @param Zend_Amf_Parse_OutputStream $stream
* @return void
*/
public function __construct(Zend_Amf_Parse_OutputStream $stream)
{
$this->_stream = $stream;
}
/**
* Find the PHP object type and convert it into an AMF object type
*
* @param mixed $content
* @param int $markerType
* @return void
*/
public abstract function writeTypeMarker($content, $markerType=null);
}

View File

@@ -0,0 +1,231 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Parse
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TypeLoader.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Amf_Value_Messaging_AcknowledgeMessage
*/
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
/**
* @see Zend_Amf_Value_Messaging_AsyncMessage
*/
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
/**
* @see Zend_Amf_Value_Messaging_CommandMessage
*/
require_once 'Zend/Amf/Value/Messaging/CommandMessage.php';
/**
* @see Zend_Amf_Value_Messaging_ErrorMessage
*/
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
/**
* @see Zend_Amf_Value_Messaging_RemotingMessage
*/
require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
/**
* 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-2010 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
{
/**
* @var string callback class
*/
public static $callbackClass;
/**
* @var array AMF class map
*/
public static $classMap = array (
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
);
/**
* @var array Default class map
*/
protected static $_defaultClassMap = array(
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
);
/**
* @var Zend_Loader_PluginLoader_Interface
*/
protected static $_resourceLoader = null;
/**
* Load the mapped class type into a callback.
*
* @param string $className
* @return object|false
*/
public static function loadType($className)
{
$class = self::getMappedClassName($className);
if(!$class) {
$class = str_replace('.', '_', $className);
}
if (!class_exists($class)) {
return "stdClass";
}
return $class;
}
/**
* Looks up the supplied call name to its mapped class name
*
* @param string $className
* @return string
*/
public static function getMappedClassName($className)
{
$mappedName = array_search($className, self::$classMap);
if ($mappedName) {
return $mappedName;
}
$mappedName = array_search($className, array_flip(self::$classMap));
if ($mappedName) {
return $mappedName;
}
return false;
}
/**
* Map PHP class names to ActionScript class names
*
* Allows users to map the class names of there action script classes
* to the equivelent php class name. Used in deserialization to load a class
* and serialiation to set the class name of the returned object.
*
* @param string $asClassName
* @param string $phpClassName
* @return void
*/
public static function setMapping($asClassName, $phpClassName)
{
self::$classMap[$asClassName] = $phpClassName;
}
/**
* Reset type map
*
* @return void
*/
public static function resetMap()
{
self::$classMap = self::$_defaultClassMap;
}
/**
* Set loader for resource type handlers
*
* @param Zend_Loader_PluginLoader_Interface $loader
*/
public static function setResourceLoader(Zend_Loader_PluginLoader_Interface $loader)
{
self::$_resourceLoader = $loader;
}
/**
* Add directory to the list of places where to look for resource handlers
*
* @param string $prefix
* @param string $dir
*/
public static function addResourceDirectory($prefix, $dir)
{
if(self::$_resourceLoader) {
self::$_resourceLoader->addPrefixPath($prefix, $dir);
}
}
/**
* Get plugin class that handles this resource
*
* @param resource $resource Resource type
* @return string Class name
*/
public static function getResourceParser($resource)
{
if(self::$_resourceLoader) {
$type = preg_replace("/[^A-Za-z0-9_]/", " ", get_resource_type($resource));
$type = str_replace(" ","", ucwords($type));
return self::$_resourceLoader->load($type);
}
return false;
}
/**
* Convert resource to a serializable object
*
* @param resource $resource
* @return mixed
*/
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');
}
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));
}
$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");
}
}
return $resource;
} catch(Zend_Amf_Exception $e) {
throw new Zend_Amf_Exception($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);
}
}
}

View File

@@ -0,0 +1,285 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Util
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: BinaryStream.php 21210 2010-02-27 10:37:39Z yoshida@zend.co.jp $
*/
/**
* Utility class to walk through a data stream byte by byte with conventional names
*
* @package Zend_Amf
* @subpackage Util
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Util_BinaryStream
{
/**
* @var string Byte stream
*/
protected $_stream;
/**
* @var int Length of stream
*/
protected $_streamLength;
/**
* @var bool BigEndian encoding?
*/
protected $_bigEndian;
/**
* @var int Current position in stream
*/
protected $_needle;
/**
* Constructor
*
* Create a reference to a byte stream that is going to be parsed or created
* by the methods in the class. Detect if the class should use big or
* little Endian encoding.
*
* @param string $stream use '' if creating a new stream or pass a string if reading.
* @return void
*/
public function __construct($stream)
{
if (!is_string($stream)) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Inputdata is not of type String');
}
$this->_stream = $stream;
$this->_needle = 0;
$this->_streamLength = strlen($stream);
$this->_bigEndian = (pack('l', 1) === "\x00\x00\x00\x01");
}
/**
* Returns the current stream
*
* @return string
*/
public function getStream()
{
return $this->_stream;
}
/**
* Read the number of bytes in a row for the length supplied.
*
* @todo Should check that there are enough bytes left in the stream we are about to read.
* @param int $length
* @return string
* @throws Zend_Amf_Exception for buffer underrun
*/
public function readBytes($length)
{
if (($length + $this->_needle) > $this->_streamLength) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
}
$bytes = substr($this->_stream, $this->_needle, $length);
$this->_needle+= $length;
return $bytes;
}
/**
* Write any length of bytes to the stream
*
* Usually a string.
*
* @param string $bytes
* @return Zend_Amf_Util_BinaryStream
*/
public function writeBytes($bytes)
{
$this->_stream.= $bytes;
return $this;
}
/**
* Reads a signed byte
*
* @return int Value is in the range of -128 to 127.
*/
public function readByte()
{
if (($this->_needle + 1) > $this->_streamLength) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
}
return ord($this->_stream{$this->_needle++});
}
/**
* Writes the passed string into a signed byte on the stream.
*
* @param string $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeByte($stream)
{
$this->_stream.= pack('c', $stream);
return $this;
}
/**
* Reads a signed 32-bit integer from the data stream.
*
* @return int Value is in the range of -2147483648 to 2147483647
*/
public function readInt()
{
return ($this->readByte() << 8) + $this->readByte();
}
/**
* Write an the integer to the output stream as a 32 bit signed integer
*
* @param int $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeInt($stream)
{
$this->_stream.= pack('n', $stream);
return $this;
}
/**
* Reads a UTF-8 string from the data stream
*
* @return string A UTF-8 string produced by the byte representation of characters
*/
public function readUtf()
{
$length = $this->readInt();
return $this->readBytes($length);
}
/**
* Wite a UTF-8 string to the outputstream
*
* @param string $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeUtf($stream)
{
$this->writeInt(strlen($stream));
$this->_stream.= $stream;
return $this;
}
/**
* Read a long UTF string
*
* @return string
*/
public function readLongUtf()
{
$length = $this->readLong();
return $this->readBytes($length);
}
/**
* Write a long UTF string to the buffer
*
* @param string $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeLongUtf($stream)
{
$this->writeLong(strlen($stream));
$this->_stream.= $stream;
}
/**
* Read a long numeric value
*
* @return double
*/
public function readLong()
{
return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
}
/**
* Write long numeric value to output stream
*
* @param int|string $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeLong($stream)
{
$this->_stream.= pack('N', $stream);
return $this;
}
/**
* Read a 16 bit unsigned short.
*
* @todo This could use the unpack() w/ S,n, or v
* @return double
*/
public function readUnsignedShort()
{
$byte1 = $this->readByte();
$byte2 = $this->readByte();
return (($byte1 << 8) | $byte2);
}
/**
* Reads an IEEE 754 double-precision floating point number from the data stream.
*
* @return double Floating point number
*/
public function readDouble()
{
$bytes = substr($this->_stream, $this->_needle, 8);
$this->_needle+= 8;
if (!$this->_bigEndian) {
$bytes = strrev($bytes);
}
$double = unpack('dflt', $bytes);
return $double['flt'];
}
/**
* Writes an IEEE 754 double-precision floating point number from the data stream.
*
* @param string|double $stream
* @return Zend_Amf_Util_BinaryStream
*/
public function writeDouble($stream)
{
$stream = pack('d', $stream);
if (!$this->_bigEndian) {
$stream = strrev($stream);
}
$this->_stream.= $stream;
return $this;
}
}

View File

@@ -0,0 +1,92 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AbstractMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* This is the default Implementation of Message, which provides
* a convenient base for behavior and association of common endpoints
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_AbstractMessage
{
/**
* @var string Client identifier
*/
public $clientId;
/**
* @var string Destination
*/
public $destination;
/**
* @var string Message identifier
*/
public $messageId;
/**
* @var int Message timestamp
*/
public $timestamp;
/**
* @var int Message TTL
*/
public $timeToLive;
/**
* @var object Message headers
*/
public $headers;
/**
* @var string Message body
*/
public $body;
/**
* generate a unique id
*
* Format is: ########-####-####-####-############
* Where # is an uppercase letter or number
* example: 6D9DC7EC-A273-83A9-ABE3-00005FD752D6
*
* @return string
*/
public function generateId()
{
return sprintf(
'%08X-%04X-%04X-%02X%02X-%012X',
mt_rand(),
mt_rand(0, 65535),
bindec(substr_replace(
sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
),
bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)),
mt_rand(0, 255),
mt_rand()
);
}
}

View File

@@ -0,0 +1,60 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AcknowledgeMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Amf_Value_Messaging_AsyncMessage */
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
/**
* This is the type of message returned by the MessageBroker
* to endpoints after the broker has routed an endpoint's message
* to a service.
*
* flex.messaging.messages.AcknowledgeMessage
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_AcknowledgeMessage extends Zend_Amf_Value_Messaging_AsyncMessage
{
/**
* Create a new Acknowledge Message
*
* @param unknown_type $message
*/
public function __construct($message)
{
$this->clientId = $this->generateId();
$this->destination = null;
$this->messageId = $this->generateId();
$this->timestamp = time().'00';
$this->timeToLive = 0;
$this->headers = new STDClass();
$this->body = null;
// correleate the two messages
if ($message && isset($message->messageId)) {
$this->correlationId = $message->messageId;
}
}
}

View File

@@ -0,0 +1,43 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: AsyncMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Amf_Value_Messaging_AbstractMessage */
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
/**
* This type of message contains information necessary to perform
* point-to-point or publish-subscribe messaging.
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_AsyncMessage extends Zend_Amf_Value_Messaging_AbstractMessage
{
/**
* The message id to be responded to.
* @var String
*/
public $correlationId;
}

View File

@@ -0,0 +1,119 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: CommandMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Amf_Value_Messaging_AsyncMessage
*/
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
/**
* A message that represents an infrastructure command passed between
* client and server. Subscribe/unsubscribe operations result in
* CommandMessage transmissions, as do polling operations.
*
* Corresponds to flex.messaging.messages.CommandMessage
*
* Note: THESE VALUES MUST BE THE SAME ON CLIENT AND SERVER
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_CommandMessage extends Zend_Amf_Value_Messaging_AsyncMessage
{
/**
* This operation is used to subscribe to a remote destination.
*/
const SUBSCRIBE_OPERATION = 0;
/**
* This operation is used to unsubscribe from a remote destination.
*/
const UNSUSBSCRIBE_OPERATION = 1;
/**
* This operation is used to poll a remote destination for pending,
* undelivered messages.
*/
const POLL_OPERATION = 2;
/**
* This operation is used by a remote destination to sync missed or cached messages
* back to a client as a result of a client issued poll command.
*/
const CLIENT_SYNC_OPERATION = 4;
/**
* This operation is used to test connectivity over the current channel to
* the remote endpoint.
*/
const CLIENT_PING_OPERATION = 5;
/**
* This operation is used to request a list of failover endpoint URIs
* for the remote destination based on cluster membership.
*/
const CLUSTER_REQUEST_OPERATION = 7;
/**
* This operation is used to send credentials to the endpoint so that
* the user can be logged in over the current channel.
* The credentials need to be Base64 encoded and stored in the <code>body</code>
* of the message.
*/
const LOGIN_OPERATION = 8;
/**
* This operation is used to log the user out of the current channel, and
* will invalidate the server session if the channel is HTTP based.
*/
const LOGOUT_OPERATION = 9;
/**
* This operation is used to indicate that the client's subscription to a
* remote destination has been invalidated.
*/
const SESSION_INVALIDATE_OPERATION = 10;
/**
* This operation is used by the MultiTopicConsumer to subscribe/unsubscribe
* from multiple subtopics/selectors in the same message.
*/
const MULTI_SUBSCRIBE_OPERATION = 11;
/**
* This operation is used to indicate that a channel has disconnected
*/
const DISCONNECT_OPERATION = 12;
/**
* This is the default operation for new CommandMessage instances.
*/
const UNKNOWN_OPERATION = 10000;
/**
* The operation to execute for messages of this type
* @var int
*/
public $operation = self::UNKNOWN_OPERATION;
}

View File

@@ -0,0 +1,67 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ErrorMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** @see Zend_Amf_Value_Messaging_AcknowledgeMessage */
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
/**
* Creates the error message to report to flex the issue with the call
*
* Corresponds to flex.messaging.messages.ErrorMessage
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_ErrorMessage extends Zend_Amf_Value_Messaging_AcknowledgeMessage
{
/**
* Additional data with error
* @var object
*/
public $extendedData = null;
/**
* Error code number
* @var string
*/
public $faultCode;
/**
* Description as to the cause of the error
* @var string
*/
public $faultDetail;
/**
* Short description of error
* @var string
*/
public $faultString = '';
/**
* root cause of error
* @var object
*/
public $rootCause = null;
}

View File

@@ -0,0 +1,73 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: RemotingMessage.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Amf_Value_Messaging_AbstractMessage */
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
/**
* This type of message contains information needed to perform
* a Remoting invocation.
*
* Corresponds to flex.messaging.messages.RemotingMessage
*
* @package Zend_Amf
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Amf_Value_Messaging_RemotingMessage extends Zend_Amf_Value_Messaging_AbstractMessage
{
/**
* The name of the service to be called including package name
* @var String
*/
public $source;
/**
* The name of the method to be called
* @var string
*/
public $operation;
/**
* The arguments to call the mathod with
* @var array
*/
public $parameters;
/**
* Create a new Remoting Message
*
* @return void
*/
public function __construct()
{
$this->clientId = $this->generateId();
$this->destination = null;
$this->messageId = $this->generateId();
$this->timestamp = time().'00';
$this->timeToLive = 0;
$this->headers = new stdClass();
$this->body = null;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* AMF Binary Format for Restler Framework.
* Native format supported by Adobe Flash and Adobe AIR
* @category Framework
* @package restler
* @subpackage format
* @author R.Arul Kumaran <arul@luracast.com>
* @copyright 2010 Luracast
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://luracast.com/products/restler/
*/
class AmfFormat implements iFormat
{
const PATH = '/Zend/Amf/Parse/';
const MIME = 'application/x-amf';
const EXTENSION = 'amf';
public $path = '';
public function init(){
$this->path = dirname(__FILE__);
$include_path = get_include_path();
if(strpos($include_path, 'Zend')===FALSE){
set_include_path($this->path.':'.$include_path);
}
$this->path .= AmfFormat::PATH;
}
public function getMIMEMap()
{
return array(AmfFormat::EXTENSION=>AmfFormat::MIME);
}
public function getMIME(){
return AmfFormat::MIME;
}
public function getExtension(){
return AmfFormat::EXTENSION;
}
public function setMIME($mime){
//do nothing
}
public function setExtension($extension){
//do nothing
}
public function encode($data, $human_readable=false){
$this->init();
require_once $this->path . 'OutputStream.php';
require_once $this->path . 'Amf3/Serializer.php';
$stream = new Zend_Amf_Parse_OutputStream();
$serializer = new Zend_Amf_Parse_Amf3_Serializer($stream);
$serializer->writeTypeMarker($data);
return $stream->getStream();
}
public function decode($data){
$this->init();
require_once $this->path .'InputStream.php';
require_once $this->path .'Amf3/Deserializer.php';
$stream = new Zend_Amf_Parse_InputStream(substr($data, 1));
$deserializer = new Zend_Amf_Parse_Amf3_Deserializer($stream);
return $deserializer->readTypeMarker();
}
public function __toString(){
return $this->getExtension();
}
}

58
gulliver/thirdparty/restler/compat.php vendored Normal file
View File

@@ -0,0 +1,58 @@
<?php
if(version_compare('5.0.0',PHP_VERSION)>0){
die('Restler requires PHP 5.x.x');
}
#requires 5.3.2
if(!method_exists('ReflectionMethod', 'setAccessible')){
#echo'RESTLER_METHOD_UNPROTECTION_MODE';
function isRestlerCompatibilityModeEnabled(){
return TRUE;
}
function unprotect($method_info){
$class_name = $method_info->class_name;
$method = $method_info->method_name;
$params = $method_info->arguments;
$unique = uniqid('Dynamic')."_";
$class_code = "class $unique$class_name extends $class_name {";
$p = array();
for ($i = 0; $i < count($params); $i++) {
$p[]='$'."P$i";
}
$p = implode(',', $p);
$class_code .= "function $unique$method($p){return parent::$method($p);}";
$class_code .= "}";
#echo $class_code;
eval($class_code);
$method_info->class_name = "$unique$class_name";
$method_info->method_name = "$unique$method";
return $method_info;
}
function call_protected_user_method_array($class_name, $method, $params)
{
if(is_object($class_name))$class_name = get_class($class_name);
$unique = uniqid('Dynamic')."_";
$class_code = "class $unique$class_name extends $class_name {";
$p = array();
for ($i = 0; $i < count($params); $i++) {
$p[]='$'."P$i";
}
$p = implode(',', $p);
$class_code .= "function $unique$method($p){return parent::$method($p);}";
$class_code .= "}";
#echo $class_code;
eval($class_code);
$obj = $unique.$class_name;
$obj = new $obj();
return call_user_func_array(array($obj,$unique.$method), $params);
}
}
#requires 5.2.3
#if(!method_exists('ReflectionParameter', 'getPosition')){
#found fix! not using getPosition in restler 2.0
#}
#requires 5.3.0
#if(!defined('__DIR__')){
# avoided using it in Restler and replaced it with dirname(__FILE__)
#}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
<?php
/**
* CFTypeDetector
* Interface for converting native PHP data structures to CFPropertyList objects.
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
* @subpackage plist.types
* @example example-create-02.php Using {@link CFTypeDetector}
* @example example-create-03.php Using {@link CFTypeDetector} with {@link CFDate} and {@link CFData}
* @example example-create-04.php Using and extended {@link CFTypeDetector}
*/
class CFTypeDetector {
/**
* flag stating if all arrays should automatically be converted to {@link CFDictionary}
* @var boolean
*/
protected $autoDictionary = false;
/**
* flag stating if exceptions should be suppressed or thrown
* @var boolean
*/
protected $suppressExceptions = false;
/**
* name of a method that will be used for array to object conversations
* @var boolean
*/
protected $objectToArrayMethod = false;
/**
* Create new CFTypeDetector
* @param boolean $autoDicitionary if set to true all arrays will be converted to {@link CFDictionary}
* @param boolean $suppressExceptions if set to true toCFType() will not throw any exceptions
* @param boolean $objectToArrayMethod if non-null, this method will be called on objects (if possible) to convert the object to an array
*/
public function __construct($autoDicitionary=false,$suppressExceptions=false,$objectToArrayMethod=null) {
$this->autoDicitionary = $autoDicitionary;
$this->suppressExceptions = $suppressExceptions;
$this->objectToArrayMethod = $objectToArrayMethod;
}
/**
* Determine if an array is associative or numerical.
* Numerical Arrays have incrementing index-numbers that don't contain gaps.
* @param array $value Array to check indexes of
* @return boolean true if array is associative, false if array has numeric indexes
*/
protected function isAssociativeArray($value) {
$numericKeys = true;
$previousKey = null;
foreach($value as $key => $v) {
if(!is_numeric($key) || ($previousKey !== null && $previousKey != $key-1)) {
$numericKeys = false;
break;
}
$previousKey = $key;
}
return !$numericKeys;
}
/**
* Get the default value
* @return CFType the default value to return if no suitable type could be determined
*/
protected function defaultValue() {
return new CFString();
}
/**
* Create CFType-structure by guessing the data-types.
* {@link CFArray}, {@link CFDictionary}, {@link CFBoolean}, {@link CFNumber} and {@link CFString} can be created, {@link CFDate} and {@link CFData} cannot.
* <br /><b>Note:</b>Distinguishing between {@link CFArray} and {@link CFDictionary} is done by examining the keys.
* Keys must be strictly incrementing integers to evaluate to a {@link CFArray}.
* Since PHP does not offer a function to test for associative arrays,
* this test causes the input array to be walked twice and thus work rather slow on large collections.
* If you work with large arrays and can live with all arrays evaluating to {@link CFDictionary},
* feel free to set the appropriate flag.
* <br /><b>Note:</b> If $value is an instance of CFType it is simply returned.
* <br /><b>Note:</b> If $value is neither a CFType, array, numeric, boolean nor string, it is omitted.
* @param mixed $value Value to convert to CFType
* @param boolean $autoDictionary if true {@link CFArray}-detection is bypassed and arrays will be returned as {@link CFDictionary}.
* @return CFType CFType based on guessed type
* @uses isAssociativeArray() to check if an array only has numeric indexes
*/
public function toCFType($value) {
switch(true) {
case $value instanceof CFType:
return $value;
break;
case is_object($value):
// DateTime should be CFDate
if(class_exists( 'DateTime' ) && $value instanceof DateTime){
return new CFDate($value->getTimestamp());
}
// convert possible objects to arrays, arrays will be arrays
if($this->objectToArrayMethod && is_callable(array($value, $this->objectToArrayMethod))){
$value = call_user_func( array( $value, $this->objectToArrayMethod ) );
}
if(!is_array($value)){
if($this->suppressExceptions)
return $this->defaultValue();
throw new PListException('Could not determine CFType for object of type '. get_class($value));
}
/* break; omitted */
case $value instanceof Iterator:
case is_array($value):
// test if $value is simple or associative array
if(!$this->autoDictionary) {
if(!$this->isAssociativeArray($value)) {
$t = new CFArray();
foreach($value as $v) $t->add($this->toCFType($v));
return $t;
}
}
$t = new CFDictionary();
foreach($value as $k => $v) $t->add($k, $this->toCFType($v));
return $t;
break;
case is_numeric($value):
return new CFNumber($value);
break;
case is_bool($value):
return new CFBoolean($value);
break;
case is_string($value):
return new CFString($value);
break;
case is_null($value):
return new CFString();
break;
case is_resource($value):
if( $this->suppressExceptions )
return $this->defaultValue();
throw new PListException('Could not determine CFType for resource of type '. get_resource_type($value));
break;
default:
if( $this->suppressExceptions )
return $this->defaultValue();
throw new PListException('Could not determine CFType for '. gettype($value));
break;
}
}
}
?>

View File

@@ -0,0 +1,99 @@
<?php
/**
* CFPropertyList
* {@link http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html Property Lists}
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
* @version $Id$
*/
/**
* Basic Input / Output Exception
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
*/
class IOException extends Exception {
/**
* Flag telling the File could not be found
*/
const NOT_FOUND = 1;
/**
* Flag telling the File is not readable
*/
const NOT_READABLE = 2;
/**
* Flag telling the File is not writable
*/
const NOT_WRITABLE = 3;
/**
* Flag telling there was a read error
*/
const READ_ERROR = 4;
/**
* Flag telling there was a read error
*/
const WRITE_ERROR = 5;
/**
* Create new IOException
* @param string $path Source of the problem
* @param integer $type Type of the problem
*/
public function __construct($path, $type=null) {
parent::__construct( $path, $type );
}
/**
* Create new FileNotFound-Exception
* @param string $path Source of the problem
* @return IOException new FileNotFound-Exception
*/
public static function notFound($path) {
return new IOException( $path, self::NOT_FOUND );
}
/**
* Create new FileNotReadable-Exception
* @param string $path Source of the problem
* @return IOException new FileNotReadable-Exception
*/
public static function notReadable($path) {
return new IOException( $path, self::NOT_READABLE );
}
/**
* Create new FileNotWritable-Exception
* @param string $path Source of the problem
* @return IOException new FileNotWritable-Exception
*/
public static function notWritable($path) {
return new IOException( $path, self::NOT_WRITABLE );
}
/**
* Create new ReadError-Exception
* @param string $path Source of the problem
* @return IOException new ReadError-Exception
*/
public static function readError($path) {
return new IOException( $path, self::READ_ERROR );
}
/**
* Create new WriteError-Exception
* @param string $path Source of the problem
* @return IOException new WriteError-Exception
*/
public static function writeError($path) {
return new IOException( $path, self::WRITE_ERROR );
}
}
?>

View File

@@ -0,0 +1,22 @@
<?php
/**
* CFPropertyList
* {@link http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html Property Lists}
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
* @version $Id$
*/
/**
* Exception for errors with the PList format
* @author Rodney Rehm <rodney.rehm@medialize.de>
* @author Christian Kruse <cjk@wwwtech.de>
* @package plist
*/
class PListException extends Exception {
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* Plist Format for Restler Framework.
* Plist is the native data exchange format for Apple iOS and Mac platform.
* Use this format to talk to mac applications and iOS devices.
* This class is capable of serving both xml plist and binary plist.
* @category Framework
* @package restler
* @subpackage format
* @author R.Arul Kumaran <arul@luracast.com>
* @copyright 2010 Luracast
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://luracast.com/products/restler/
*/
class PlistFormat implements iFormat
{
public static $binary_mode = false;
const MIME_BINARY = 'application/x-plist';
const MIME_XML = 'application/xml';
const EXTENSION_BINARY = 'bplist';
const EXTENSION_XML = 'plist';
public function getMIMEMap(){
return array(
PlistFormat::EXTENSION_BINARY=>PlistFormat::MIME_BINARY,
PlistFormat::EXTENSION_XML=>PlistFormat::MIME_XML
);
}
public function getMIME(){
return PlistFormat::$binary_mode ? PlistFormat::MIME_BINARY : PlistFormat::MIME_XML;
}
public function getExtension(){
return PlistFormat::$binary_mode ? PlistFormat::EXTENSION_BINARY : PlistFormat::EXTENSION_XML;
}
public function setMIME($mime){
PlistFormat::$binary_mode = $mime==PlistFormat::MIME_BINARY;
}
public function setExtension($extension){
PlistFormat::$binary_mode = $extension==PlistFormat::EXTENSION_BINARY;
}
/**
* Encode the given data in plist format
* @param array $data resulting data that needs to
* be encoded in plist format
* @param boolean $human_readable set to true when restler
* is not running in production mode. Formatter has to
* make the encoded output more human readable
* @return string encoded string
*/
public function encode($data, $human_readable=false){
require_once'CFPropertyList.php';
if(!PlistFormat::$binary_mode) {
PlistFormat::$binary_mode = !$human_readable;
} else {
$human_readable=false;
}
/**
* @var CFPropertyList
*/
$plist = new CFPropertyList();
$td = new CFTypeDetector();
$guessedStructure = $td->toCFType(object_to_array($data));
$plist->add( $guessedStructure );
return $human_readable ? $plist->toXML(true) : $plist->toBinary();
}
/**
* Decode the given data from plist format
* @param string $data data sent from client to
* the api in the given format.
* @return array associative array of the parsed data
*/
public function decode($data){
require_once'CFPropertyList.php';
$plist = new CFPropertyList();
$plist->parse($data);
return $plist->toArray();
}
public function __toString(){
return $this->getExtension();
}
}

1454
gulliver/thirdparty/restler/restler.php vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,213 @@
<?php
/**
* XML Markup Format for Restler Framework
* @category Framework
* @package restler
* @subpackage format
* @author R.Arul Kumaran <arul@luracast.com>
* @copyright 2010 Luracast
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://luracast.com/products/restler/
*/
class XmlFormat implements iFormat
{
public static $parse_attributes=true;
public static $parse_namespaces=false;
public static $attribute_names=array('xmlns');
/**
* Default name for the root node.
* @var string $rootNodeName
*/
public static $root_name='response';
public static $default_tag_name='item';
public static $mime = 'application/xml';
const MIME = 'application/xml,text/xml';
const EXTENSION = 'xml';
public function getMIMEMap()
{
return array(self::EXTENSION=>self::MIME);
}
public function getMIME(){
return self::$mime;
}
public function getExtension(){
return self::EXTENSION;
}
public function setMIME($mime){
self::$mime = $mime;
}
public function setExtension($extension){
//do nothing
}
public function encode($data, $human_readable=false){
return $this->toXML( object_to_array($data, false),
self::$root_name, $human_readable);
}
public function decode($data){
try {
if($data=='')return array();
return $this->toArray($data);
} catch (Exception $e) {
throw new RestException(400, "Error decoding request. ".
$e->getMessage());
}
}
public function __toString(){
return $this->getExtension();
}
/**
* determine if a variable is an associative array
*/
public function isAssoc( $array ) {
return (is_array($array) && 0 !== count(array_diff_key($array,
array_keys(array_keys($array)))));
}
/**
* The main function for converting to an XML document.
* Pass in a multi dimensional array and this recrusively loops through
* and builds up an XML document.
* @param array $data
* @param string $rootNodeName - what you want the root node to be -
* defaults to data.
* @param SimpleXMLElement $xml - should only be used recursively
* @return string XML
* @link http://bit.ly/n85yLi
*/
public function toXML( $data, $root_node_name = 'result',
$human_readable=false, &$xml=null) {
// turn off compatibility mode as simple xml
//throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1)
ini_set ('zend.ze1_compatibility_mode', 0);
if (is_null($xml))
$xml = @simplexml_load_string("<$root_node_name/>");
if(is_array($data)){
$numeric=0;
// loop through the data passed in.
foreach( $data as $key => $value ) {
// no numeric keys in our xml please!
if ( is_numeric( $key ) ) {
$numeric = 1;
$key = self::$root_name == $root_node_name ?
self::$default_tag_name : $root_node_name;
}
// delete any char not allowed in XML element names
$key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
// if there is another array found recrusively
//call this function
if ( is_array( $value ) ) {
$node = $this->isAssoc( $value ) || $numeric ?
$xml->addChild( $key ) : $xml;
// recrusive call.
if ( $numeric ) $key = 'anon';
$this->toXML($value, $key, $human_readable, $node);
} else {
// add single node or attribute
$value=htmlspecialchars($value);
in_array($key,self::$attribute_names) ?
$xml->addAttribute($key,$value) :
$xml->addChild( $key, $value);
}
}
}else{ //if given data is a string or number
//simply wrap it as text node to root
if(is_bool($data)) $data = $data ? 'true' : 'false';
$xml = @simplexml_load_string(
"<$root_node_name>".htmlspecialchars($data)."</$root_node_name>");
//$xml->{0} = $data;
}
if(!$human_readable){
return $xml->asXML();
}else{
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
return $dom->saveXML();
}
}
/**
* Convert an XML document to a multi dimensional array
* Pass in an XML document (or SimpleXMLElement object) and this
* recrusively loops through and builds a representative array
*
* @param string $xml - XML document - can optionally be a
* SimpleXMLElement object
* @return array ARRAY
* @link http://bit.ly/n85yLi
*/
public function toArray( $xml, $firstCall=true) {
if ( is_string( $xml ) ) $xml = new SimpleXMLElement( $xml );
$children = $xml->children();
if ( !$children ) {
$r = (string) $xml;
if($r=='true' || $r=='false')$r=$r=='true';
return $r;
}
$arr = array();
if($firstCall){
//reset the attribute names list
self::$attribute_names=array();
self::$root_name = $xml->getName();
if (self::$parse_namespaces){
foreach($xml->getDocNamespaces(TRUE) as $namepace => $uri) {
$arr[$namepace=='' ? 'xmlns' :
'xmlns:'.$namepace] = (string)$uri;
}
}
}
if(self::$parse_attributes){
foreach($xml->attributes() as $attName => $attValue) {
$arr[$attName] = (string)$attValue;
//add to attribute list for round trip support
self::$attribute_names[]=$attName;
}
}
foreach ($children as $key => $node) {
$node = $this->toArray($node, false);
// support for 'anon' non-associative arrays
if ($key == 'anon') $key = count($arr);
// if the node is already set, put it into an array
if (isset($arr[$key])) {
if ( !is_array($arr[$key]) || @$arr[$key][0] == null )
$arr[$key] = array($arr[$key]);
$arr[$key][] = $node;
} else {
$arr[$key] = $node;
}
}
return $arr;
}
/**
* When you decode an XML its structure is copied to the static vars
* we can use this function to echo them out and then copy paste inside
* our service methods
* @return string PHP source code to reproduce the configuration
*/
public static function exportCurrentSettings() {
$s = 'self::$root_name = "'.
(self::$root_name)."\";\n";
$s .= 'self::$attribute_names = '.
(var_export(self::$attribute_names, true)).";\n";
$s .= 'self::$default_tag_name = "'.
self::$default_tag_name."\";\n";
$s .= 'self::$parse_attributes = '.
(self::$parse_attributes ? 'true' : 'false').";\n";
$s .= 'self::$parse_namespaces = '.
(self::$parse_namespaces ? 'true' : 'false').";\n\n\n";
return $s;
}
}

View File

@@ -0,0 +1,19 @@
Copyright (c) 2008-2009 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.

View File

@@ -0,0 +1,15 @@
Symfony YAML: A PHP library that speaks YAML
============================================
Symfony YAML is a PHP library that parses YAML strings and converts them to
PHP arrays. It can also converts PHP arrays to YAML strings. Its official
website is at http://components.symfony-project.org/yaml/.
The documentation is to be found in the `doc/` directory.
Symfony YAML is licensed under the MIT license (see LICENSE file).
The Symfony YAML library is developed and maintained by the
[symfony](http://www.symfony-project.org/) project team. It has been extracted
from symfony to be used as a standalone library. Symfony YAML is part of the
[symfony components project](http://components.symfony-project.org/).

View File

@@ -0,0 +1,137 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include_once 'sfyamlinline.php';
/**
* sfYaml offers convenience methods to load and dump YAML.
*
* @package symfony
* @subpackage yaml
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfYaml.class.php 8988 2008-05-15 20:24:26Z fabien $
*/
class sfYaml
{
static protected
$spec = '1.2';
/**
* Sets the YAML specification version to use.
*
* @param string $version The YAML specification version
*/
static public function setSpecVersion($version)
{
if (!in_array($version, array('1.1', '1.2')))
{
throw new InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
}
self::$spec = $version;
}
/**
* Gets the YAML specification version to use.
*
* @return string The YAML specification version
*/
static public function getSpecVersion()
{
return self::$spec;
}
/**
* Loads YAML into a PHP array.
*
* The load method, when supplied with a YAML stream (string or file),
* will do its best to convert YAML in a file into a PHP array.
*
* Usage:
* <code>
* $array = sfYaml::load('config.yml');
* print_r($array);
* </code>
*
* @param string $input Path of YAML file or string containing YAML
*
* @return array The YAML converted to a PHP array
*
* @throws InvalidArgumentException If the YAML is not valid
*/
public static function load($input)
{
$file = '';
// if input is a file, process it
if (strpos($input, "\n") === false && is_file($input))
{
$file = $input;
ob_start();
$retval = include($input);
$content = ob_get_clean();
// if an array is returned by the config file assume it's in plain php form else in YAML
$input = is_array($retval) ? $retval : $content;
}
// if an array is returned by the config file assume it's in plain php form else in YAML
if (is_array($input))
{
return $input;
}
require_once dirname(__FILE__).'/sfYamlParser.php';
$yaml = new sfYamlParser();
try
{
$ret = $yaml->parse($input);
}
catch (Exception $e)
{
throw new InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
}
return $ret;
}
/**
* Dumps a PHP array to a YAML string.
*
* The dump method, when supplied with an array, will do its best
* to convert the array into friendly YAML.
*
* @param array $array PHP array
* @param integer $inline The level where you switch to inline YAML
*
* @return string A YAML string representing the original PHP array
*/
public static function dump($array, $inline = 2)
{
require_once dirname(__FILE__).'/sfyamldumper.php';
$yaml = new sfYamlDumper();
return $yaml->dump($array, $inline);
}
}
/**
* Wraps echo to automatically provide a newline.
*
* @param string $string The string to echo with new line
*/
function echoln($string)
{
echo $string."\n";
}

Some files were not shown because too many files have changed in this diff Show More