cvs: pear /HTML_AJAX/AJAX/Serializer JSON.php Null.php PHP.php Urlencoded.php
| From: | David Coallier | Date: | Thu, 09 Feb 2006 15:21:50 +0000 |
| Subject: | cvs: pear /HTML_AJAX/AJAX/Serializer JSON.php Null.php PHP.php Urlencoded.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38079@lists.php.net to get a copy of this message | ||
davidc Thu Feb 9 15:21:50 2006 UTC
Added files:
/pear/HTML_AJAX/AJAX/Serializer PHP.php Urlencoded.php
Modified files:
/pear/HTML_AJAX/AJAX/Serializer JSON.php Null.php
Log:
View http://websvn.bluga.net for more infos on the commit
messages, just sync'ing.
http://cvs.php.net/viewcvs.cgi/pear/HTML_AJAX/AJAX/Serializer/JSON.php?r1=1.9&r2=1.10&diff_format=u
Index: pear/HTML_AJAX/AJAX/Serializer/JSON.php
diff -u pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.9 pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.10
--- pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.9 Thu Nov 3 13:51:02 2005
+++ pear/HTML_AJAX/AJAX/Serializer/JSON.php Thu Feb 9 15:21:50 2006
@@ -1,6 +1,6 @@
<?php
require_once 'HTML/AJAX/JSON.php';
-// $Id: JSON.php,v 1.9 2005/11/03 13:51:02 davidc Exp $
+// $Id: JSON.php,v 1.10 2006/02/09 15:21:50 davidc Exp $
/**
* JSON Serializer
*
http://cvs.php.net/viewcvs.cgi/pear/HTML_AJAX/AJAX/Serializer/Null.php?r1=1.8&r2=1.9&diff_format=u
Index: pear/HTML_AJAX/AJAX/Serializer/Null.php
diff -u pear/HTML_AJAX/AJAX/Serializer/Null.php:1.8 pear/HTML_AJAX/AJAX/Serializer/Null.php:1.9
--- pear/HTML_AJAX/AJAX/Serializer/Null.php:1.8 Thu Nov 3 13:51:02 2005
+++ pear/HTML_AJAX/AJAX/Serializer/Null.php Thu Feb 9 15:21:50 2006
@@ -1,5 +1,5 @@
<?php
-// $Id: Null.php,v 1.8 2005/11/03 13:51:02 davidc Exp $
+// $Id: Null.php,v 1.9 2006/02/09 15:21:50 davidc Exp $
/**
* Null Serializer
*
http://cvs.php.net/viewcvs.cgi/pear/HTML_AJAX/AJAX/Serializer/PHP.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/AJAX/Serializer/PHP.php
+++ pear/HTML_AJAX/AJAX/Serializer/PHP.php
<?php
// $Id: PHP.php,v 1.1 2006/02/09 15:21:50 davidc Exp $
/**
* PHP Serializer
*
* @category HTML
* @package AJAX
* @author Arpad Ray <arpad@php.net>
* @copyright 2005 Arpad Ray
* @license http://www.opensource.org/licenses/lgpl-license.php
LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/HTML_AJAX
*/
class HTML_AJAX_Serializer_PHP
{
function serialize($input)
{
return serialize($input);
}
/**
* Unserializes the given string
*
* Triggers an error if a class is found which is not
* in the provided array of allowed class names.
*
* @param string $input
* the serialized string to process
* @param array $allowedClasses
* an array of class names to check objects against
* before instantion
* @return mixed
* the unserialized variable on success, or false on
* failure. If this method fails it will also trigger
* a warning.
*/
function unserialize($input, $allowedClasses)
{
if (version_compare(PHP_VERSION, '4.3.10', '<')
|| (substr(PHP_VERSION, 0, 1) == '5' && version_compare(PHP_VERSION,
'5.0.3', '<'))) {
trigger_error('Unsafe version of PHP for native unserialization');
return false;
}
$classes = $this->_getSerializedClassNames($input);
if ($classes === false) {
trigger_error('Invalidly serialized string');
return false;
}
$diff = array_diff($classes, $allowedClasses);
if (!empty($diff)) {
trigger_error('Class(es) not allowed to be serialized');
return false;
}
return unserialize($input);
}
/**
* Extract class names from serialized string
*
* Adapted from code by Harry Fuecks
*
* @param string $string
* the serialized string to process
* @return mixed
* an array of class names found, or false if the input
* is invalidly formed
*/
function _getSerializedClassNames($string) {
// Strip any string representations (which might contain object syntax)
while (($pos = strpos($string, 's:')) !== false) {
$pos2 = strpos($string, ':', $pos + 2);
if ($pos2 === false) {
// invalidly serialized string
return false;
}
$end = $pos + 2 + substr($string, $pos + 2, $pos2) + 1;
$string = substr($string, 0, $pos) . substr($string, $end);
}
// Pull out the class names
preg_match_all('/O:[0-9]+:"(.*)"/U', $string, $matches);
// Make sure names are unique (same object serialized twice)
return array_unique($matches[1]);
}
}
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
?>
http://cvs.php.net/viewcvs.cgi/pear/HTML_AJAX/AJAX/Serializer/Urlencoded.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/AJAX/Serializer/Urlencoded.php
+++ pear/HTML_AJAX/AJAX/Serializer/Urlencoded.php
<?php
// $Id: Urlencoded.php,v 1.1 2006/02/09 15:21:50 davidc Exp $
// {{{ http_build_query
/**
* Replacement for http_build_query()
*
* @link http://php.net/function.http-build-query
* @author vlad_mustafin@ukr.net
* @author Arpad Ray <arpad@php.net>
*/
if (!function_exists('http_build_query')) {
function http_build_query($formdata, $numeric_prefix = null, $key = null)
{
$res = array();
foreach ((array)$formdata as $k => $v) {
if (is_resource($v)) {
return null;
}
$tmp_key = urlencode(is_int($k) ? $numeric_prefix . $k : $k);
if (!is_null($key)) {
$tmp_key = $key . '[' . $tmp_key . ']';
}
$res[] = (is_scalar($v))
? $tmp_key . '=' . urlencode($v)
: http_build_query($v, null , $tmp_key);
}
$separator = ini_get('arg_separator.output');
if (strlen($separator) == 0) {
$separator = '&';
}
return implode($separator, $res);
}
}
// }}}
// {{{ class HTML_AJAX_Serialize_Urlencoded
/**
* URL Encoding Serializer
*
* @category HTML
* @package AJAX
* @author Arpad Ray <arpad@php.net>
* @author David Coallier <davidc@php.net>
* @copyright 2005 Arpad Ray
* @license http://www.opensource.org/licenses/lgpl-license.php
LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/HTML_AJAX
*/
class HTML_AJAX_Serializer_Urlencoded
{
// {{{ serialize
function serialize($input)
{
return http_build_query(array('_HTML_AJAX' => $input));
}
// }}}
// {{{ unserialize
function unserialize($input)
{
parse_str($input, $ret);
return (isset($ret['_HTML_AJAX']) ? $ret['_HTML_AJAX'] : $ret);
}
// }}}
}
// }}}
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
?>