Skip to content

Commit

Permalink
Dev: Imported XML-RPC library from Zend framework
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11745 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shitiz Garg committed Dec 23, 2011
1 parent 3a436ce commit f451705
Show file tree
Hide file tree
Showing 55 changed files with 8,191 additions and 0 deletions.
242 changes: 242 additions & 0 deletions application/helpers/Zend/Server/Abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
<?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_Server
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/** Zend_Server_Interface */
require_once 'Zend/Server/Interface.php';

/**
* Zend_Server_Definition
*/
require_once 'Zend/Server/Definition.php';

/**
* Zend_Server_Method_Definition
*/
require_once 'Zend/Server/Method/Definition.php';

/**
* Zend_Server_Method_Callback
*/
require_once 'Zend/Server/Method/Callback.php';

/**
* Zend_Server_Method_Prototype
*/
require_once 'Zend/Server/Method/Prototype.php';

/**
* Zend_Server_Method_Parameter
*/
require_once 'Zend/Server/Method/Parameter.php';

/**
* Zend_Server_Abstract
*
* @category Zend
* @package Zend_Server
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
*/
abstract class Zend_Server_Abstract implements Zend_Server_Interface
{
/**
* @deprecated
* @var array List of PHP magic methods (lowercased)
*/
protected static $magic_methods = array(
'__call',
'__clone',
'__construct',
'__destruct',
'__get',
'__isset',
'__set',
'__set_state',
'__sleep',
'__tostring',
'__unset',
'__wakeup',
);

/**
* @var bool Flag; whether or not overwriting existing methods is allowed
*/
protected $_overwriteExistingMethods = false;

/**
* @var Zend_Server_Definition
*/
protected $_table;

/**
* Constructor
*
* Setup server description
*
* @return void
*/
public function __construct()
{
$this->_table = new Zend_Server_Definition();
$this->_table->setOverwriteExistingMethods($this->_overwriteExistingMethods);
}

/**
* Returns a list of registered methods
*
* Returns an array of method definitions.
*
* @return Zend_Server_Definition
*/
public function getFunctions()
{
return $this->_table;
}

/**
* Lowercase a string
*
* Lowercase's a string by reference
*
* @deprecated
* @param string $string value
* @param string $key
* @return string Lower cased string
*/
public static function lowerCase(&$value, &$key)
{
trigger_error(__CLASS__ . '::' . __METHOD__ . '() is deprecated and will be removed in a future version', E_USER_NOTICE);
return $value = strtolower($value);
}

/**
* Build callback for method signature
*
* @param Zend_Server_Reflection_Function_Abstract $reflection
* @return Zend_Server_Method_Callback
*/
protected function _buildCallback(Zend_Server_Reflection_Function_Abstract $reflection)
{
$callback = new Zend_Server_Method_Callback();
if ($reflection instanceof Zend_Server_Reflection_Method) {
$callback->setType($reflection->isStatic() ? 'static' : 'instance')
->setClass($reflection->getDeclaringClass()->getName())
->setMethod($reflection->getName());
} elseif ($reflection instanceof Zend_Server_Reflection_Function) {
$callback->setType('function')
->setFunction($reflection->getName());
}
return $callback;
}

/**
* Build a method signature
*
* @param Zend_Server_Reflection_Function_Abstract $reflection
* @param null|string|object $class
* @return Zend_Server_Method_Definition
* @throws Zend_Server_Exception on duplicate entry
*/
protected function _buildSignature(Zend_Server_Reflection_Function_Abstract $reflection, $class = null)
{
$ns = $reflection->getNamespace();
$name = $reflection->getName();
$method = empty($ns) ? $name : $ns . '.' . $name;

if (!$this->_overwriteExistingMethods && $this->_table->hasMethod($method)) {
require_once 'Zend/Server/Exception.php';
throw new Zend_Server_Exception('Duplicate method registered: ' . $method);
}

$definition = new Zend_Server_Method_Definition();
$definition->setName($method)
->setCallback($this->_buildCallback($reflection))
->setMethodHelp($reflection->getDescription())
->setInvokeArguments($reflection->getInvokeArguments());

foreach ($reflection->getPrototypes() as $proto) {
$prototype = new Zend_Server_Method_Prototype();
$prototype->setReturnType($this->_fixType($proto->getReturnType()));
foreach ($proto->getParameters() as $parameter) {
$param = new Zend_Server_Method_Parameter(array(
'type' => $this->_fixType($parameter->getType()),
'name' => $parameter->getName(),
'optional' => $parameter->isOptional(),
));
if ($parameter->isDefaultValueAvailable()) {
$param->setDefaultValue($parameter->getDefaultValue());
}
$prototype->addParameter($param);
}
$definition->addPrototype($prototype);
}
if (is_object($class)) {
$definition->setObject($class);
}
$this->_table->addMethod($definition);
return $definition;
}

/**
* Dispatch method
*
* @param Zend_Server_Method_Definition $invocable
* @param array $params
* @return mixed
*/
protected function _dispatch(Zend_Server_Method_Definition $invocable, array $params)
{
$callback = $invocable->getCallback();
$type = $callback->getType();

if ('function' == $type) {
$function = $callback->getFunction();
return call_user_func_array($function, $params);
}

$class = $callback->getClass();
$method = $callback->getMethod();

if ('static' == $type) {
return call_user_func_array(array($class, $method), $params);
}

$object = $invocable->getObject();
if (!is_object($object)) {
$invokeArgs = $invocable->getInvokeArguments();
if (!empty($invokeArgs)) {
$reflection = new ReflectionClass($class);
$object = $reflection->newInstanceArgs($invokeArgs);
} else {
$object = new $class;
}
}
return call_user_func_array(array($object, $method), $params);
}

/**
* Map PHP type to protocol type
*
* @param string $type
* @return string
*/
abstract protected function _fixType($type);
}
147 changes: 147 additions & 0 deletions application/helpers/Zend/Server/Cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?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_Server
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Cache.php 23775 2011-03-01 17:25:24Z ralph $
*/

/**
* Zend_Server_Cache: cache server definitions
*
* @category Zend
* @package Zend_Server
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Server_Cache
{
/**
* @var array Methods to skip when caching server
*/
protected static $_skipMethods = array();

/**
* Cache a file containing the dispatch list.
*
* Serializes the server definition stores the information
* in $filename.
*
* Returns false on any error (typically, inability to write to file), true
* on success.
*
* @param string $filename
* @param Zend_Server_Interface $server
* @return bool
*/
public static function save($filename, Zend_Server_Interface $server)
{
if (!is_string($filename)
|| (!file_exists($filename) && !is_writable(dirname($filename))))
{
return false;
}

$methods = $server->getFunctions();

if ($methods instanceof Zend_Server_Definition) {
$definition = new Zend_Server_Definition();
foreach ($methods as $method) {
if (in_array($method->getName(), self::$_skipMethods)) {
continue;
}
$definition->addMethod($method);
}
$methods = $definition;
}

if (0 === @file_put_contents($filename, serialize($methods))) {
return false;
}

return true;
}

/**
* Load server definition from a file
*
* Unserializes a stored server definition from $filename. Returns false if
* it fails in any way, true on success.
*
* Useful to prevent needing to build the server definition on each
* request. Sample usage:
*
* <code>
* if (!Zend_Server_Cache::get($filename, $server)) {
* require_once 'Some/Service/Class.php';
* require_once 'Another/Service/Class.php';
*
* // Attach Some_Service_Class with namespace 'some'
* $server->attach('Some_Service_Class', 'some');
*
* // Attach Another_Service_Class with namespace 'another'
* $server->attach('Another_Service_Class', 'another');
*
* Zend_Server_Cache::save($filename, $server);
* }
*
* $response = $server->handle();
* echo $response;
* </code>
*
* @param string $filename
* @param Zend_Server_Interface $server
* @return bool
*/
public static function get($filename, Zend_Server_Interface $server)
{
if (!is_string($filename)
|| !file_exists($filename)
|| !is_readable($filename))
{
return false;
}


if (false === ($dispatch = @file_get_contents($filename))) {
return false;
}

if (false === ($dispatchArray = @unserialize($dispatch))) {
return false;
}

$server->loadFunctions($dispatchArray);

return true;
}

/**
* Remove a cache file
*
* @param string $filename
* @return boolean
*/
public static function delete($filename)
{
if (is_string($filename) && file_exists($filename)) {
unlink($filename);
return true;
}

return false;
}
}
Loading

0 comments on commit f451705

Please sign in to comment.