Skip to content
Browse files

1.3.1 release. http://aws.amazon.com/releasenotes/PHP/0253227731786490

  • Loading branch information...
1 parent 406dd51 commit 1a7232c5f8bf6b6b4242c250a340ff2e9eb030f0 amazonwebservices committed Mar 25, 2011
View
2 _compatibility_test/sdk_compatibility_test.php
@@ -53,7 +53,7 @@
<style type="text/css">
body {
- font:14px/1.4em "Helvetica Neue", Helvetica, "Lucida Grande", Verdana, Arial, Clean, Sans, sans-serif;
+ font:14px/1.4em "Helvetica Neue", Helvetica, "Lucida Grande", "Droid Sans", Ubuntu, Verdana, Arial, Clean, Sans, sans-serif;
letter-spacing:0px;
color:#333;
margin:0;
View
30 _docs/CHANGELOG.md
@@ -1,3 +1,33 @@
+# Changelog: 1.3.1 "Kraken"
+
+Launched Friday, March 25, 2011
+
+## New Features & Highlights (Summary)
+* Fixed issues with Signature v3 authentication (SES).
+* Added gzip decoding.
+* Added support for converting data to more alternate formats.
+* Bug fixes and enhancements:
+ * [Cannot send email](https://forums.aws.amazon.com/thread.jspa?threadID=62833)
+ * [AmazonCloudWatch get_metric_statistics returns gzipped body](https://forums.aws.amazon.com/thread.jspa?threadID=62625)
+
+## Utility Classes
+### CFArray
+* **New:** The `to_json()` and `to_yaml()` methoda have been added to the class.
+
+### CFGzipDecode
+* **New:** Handles a variety of primary and edge cases around gzip/deflate decoding in PHP.
+
+### CFRuntime
+* **New:** Gzip decoding has been added to the SDK.
+* **Fixed:** The previous release contained a regression in the Signature v3 support that affected AmazonSES. This has been resolved.
+* **Fixed:** Completed support for Signature v3 over HTTP connections.
+
+### CFSimpleXML
+* **New:** The `to_stdClass()` and `to_yaml()` methoda have been added to the class.
+
+
+----
+
# Changelog: 1.3 "Jecht"
Launched Tuesday, March 15, 2011
View
4 _docs/NOTICE.md
@@ -129,13 +129,13 @@ POSSIBILITY OF SUCH DAMAGE.
<http://opensource.org/licenses/bsd-license.php>
-## SimplePie Compatibility Test
+## SimplePie
<http://simplepie.org>
* Copyright 2004-2010 [Ryan Parman](http://ryanparman.com)
* Copyright 2005-2010 [Geoffrey Sneddon](http://gsnedders.com)
-* Copyright 2008-2010 [Ryan McCue](http://ryanmccue.info)
+* Copyright 2008-2011 [Ryan McCue](http://ryanmccue.info)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
View
106 sdk.class.php
@@ -102,9 +102,9 @@ function __aws_sdk_ua_callback()
// INTERMEDIARY CONSTANTS
define('CFRUNTIME_NAME', 'aws-sdk-php');
-define('CFRUNTIME_VERSION', '1.3');
+define('CFRUNTIME_VERSION', '1.3.1');
// define('CFRUNTIME_BUILD', gmdate('YmdHis', filemtime(__FILE__))); // @todo: Hardcode for release.
-define('CFRUNTIME_BUILD', '20110315164556');
+define('CFRUNTIME_BUILD', '20110325210828');
define('CFRUNTIME_USERAGENT', CFRUNTIME_NAME . '/' . CFRUNTIME_VERSION . ' PHP/' . PHP_VERSION . ' ' . php_uname('s') . '/' . php_uname('r') . ' Arch/' . php_uname('m') . ' SAPI/' . php_sapi_name() . ' Integer/' . PHP_INT_MAX . ' Build/' . CFRUNTIME_BUILD . __aws_sdk_ua_callback());
@@ -115,7 +115,7 @@ function __aws_sdk_ua_callback()
* Core functionality and default settings shared across all SDK classes. All methods and properties in this
* class are inherited by the service-specific classes.
*
- * @version 2011.03.14
+ * @version 2011.03.25
* @license See the included NOTICE.md file for more information.
* @copyright See the included NOTICE.md file for more information.
* @link http://aws.amazon.com/php/ PHP Developer Center
@@ -750,6 +750,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
$method_arguments = func_get_args();
$headers = array();
+ $signed_headers = array();
// Use the caching flow to determine if we need to do a round-trip to the server.
if ($this->use_cache_flow)
@@ -788,8 +789,8 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Determine signing values
$current_time = time() + $this->adjust_offset;
- $date = gmdate($this->util->konst($this->util, 'DATE_FORMAT_RFC2616'), $current_time);
- $timestamp = gmdate($this->util->konst($this->util, 'DATE_FORMAT_ISO8601'), $current_time);
+ $date = gmdate(CFUtilities::DATE_FORMAT_RFC2616, $current_time);
+ $timestamp = gmdate(CFUtilities::DATE_FORMAT_ISO8601, $current_time);
$nonce = $this->util->generate_guid();
// Manage the key-value pairs that are used in the query.
@@ -825,9 +826,9 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
uksort($query, 'strcmp');
// Normalize JSON input
- if ($query['body'] === '[]')
+ if (isset($query['body']) && $query['body'] === '[]')
{
- $query['body'] = '';
+ $query['body'] = '{}';
}
if ($this->use_aws_query)
@@ -892,7 +893,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Do we have an authentication token?
if ($this->auth_token)
{
- $headers['x-amz-security-token'] = $this->auth_token;
+ $headers['X-Amz-Security-Token'] = $this->auth_token;
}
// Signing using X-Amz-Target is handled differently.
@@ -920,10 +921,11 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Add authentication headers
if ($signature_version === 3)
{
+ $headers['X-Amz-Nonce'] = $nonce;
$headers['Date'] = $date;
$headers['Content-Length'] = strlen($querystring);
$headers['Content-MD5'] = $this->util->hex_to_base64(md5($querystring));
- $headers['x-amz-nonce'] = $nonce;
+ $headers['Host'] = $host_header;
}
// Sort headers
@@ -934,10 +936,10 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Prepare the string to sign (HTTPS)
$string_to_sign = $date . $nonce;
}
- elseif ($signature_version === 3)
+ elseif ($signature_version === 3 && !$this->use_ssl)
{
// Prepare the string to sign (HTTP)
- $string_to_sign = "POST\n$host_header\n$request_uri\n$canonical_query_string";
+ $string_to_sign = "POST\n$request_uri\n\n";
}
// Add headers to request and compute the string to sign
@@ -959,32 +961,47 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
if (
substr(strtolower($header_key), 0, 8) === 'content-' ||
strtolower($header_key) === 'date' ||
- strtolower($header_key) === 'expires'
+ strtolower($header_key) === 'expires' ||
+ strtolower($header_key) === 'host' ||
+ substr(strtolower($header_key), 0, 6) === 'x-amz-'
)
{
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
- }
- elseif (substr(strtolower($header_key), 0, 6) === 'x-amz-')
- {
- $string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
+ $signed_headers[] = $header_key;
}
}
}
if ($signature_version === 3)
{
- if ($this->use_ssl)
+ if (!$this->use_ssl)
{
+ $string_to_sign .= "\n";
+
+ if (isset($query['body']) && $query['body'] !== '')
+ {
+ $string_to_sign .= $query['body'];
+ }
+
+ // Convert from string-to-sign to bytes-to-sign
+ $bytes_to_sign = hash('sha256', $string_to_sign, true);
+
// Hash the AWS secret key and generate a signature for the request.
- $signature = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
- $request->add_header('X-Amzn-Authorization', 'AWS3-HTTPS AWSAccessKeyId=' . $this->key . ',Algorithm=HmacSHA256,Signature=' . $signature);
+ $signature = base64_encode(hash_hmac('sha256', $bytes_to_sign, $this->secret_key, true));
}
else
{
// Hash the AWS secret key and generate a signature for the request.
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
- $request->add_header('X-Amzn-Authorization', 'AWS3 AWSAccessKeyId=' . $this->key . ',Algorithm=HmacSHA256,Signature=' . $signature);
}
+
+ $headers['X-Amzn-Authorization'] = 'AWS3' . ($this->use_ssl ? '-HTTPS' : '')
+ . ' AWSAccessKeyId=' . $this->key
+ . ',Algorithm=HmacSHA256'
+ . ',SignedHeaders=' . implode(';', $signed_headers)
+ . ',Signature=' . $signature;
+
+ $request->add_header('X-Amzn-Authorization', $headers['X-Amzn-Authorization']);
}
// Update RequestCore settings
@@ -994,7 +1011,7 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
$curlopts = array();
// Set custom CURLOPT settings
- if (isset($opt['curlopts']))
+ if (is_array($opt) && isset($opt['curlopts']))
{
$curlopts = $opt['curlopts'];
unset($opt['curlopts']);
@@ -1028,13 +1045,15 @@ public function authenticate($action, $opt = null, $domain = null, $signature_ve
// Send!
$request->send_request();
+ $request_headers = $headers;
+
// Prepare the response.
$headers = $request->get_response_header();
$headers['x-aws-stringtosign'] = $string_to_sign;
+ $headers['x-aws-request-headers'] = $request_headers;
$headers['x-aws-body'] = $querystring;
- $mime = isset($headers['content-type']) ? $headers['content-type'] : null;
- $data = new $this->response_class($headers, $this->parse_callback($request->get_response_body(), $mime), $request->get_response_code());
+ $data = new $this->response_class($headers, $this->parse_callback($request->get_response_body(), $headers), $request->get_response_code());
// Was it Amazon's fault the request failed? Retry the request until we reach $max_retries.
if ((integer) $request->get_response_code() === 500 || (integer) $request->get_response_code() === 503)
@@ -1153,19 +1172,14 @@ public function send($clear_after_send = true)
* @param string $content_type (Optional) The content-type to use when determining how to parse the content.
* @return CFResponse|string A parsed <CFResponse> object, or parsed XML.
*/
- public function parse_callback($response, $content_type = null)
+ public function parse_callback($response, $headers = null)
{
// Shorten this so we have a (mostly) single code path
if (isset($response->body))
{
if (is_string($response->body))
{
$body = $response->body;
-
- if (!$content_type)
- {
- $content_type = $response->header['content-type'];
- }
}
else
{
@@ -1181,10 +1195,36 @@ public function parse_callback($response, $content_type = null)
return $response;
}
+ // Decompress gzipped content
+ if (isset($headers['content-encoding']))
+ {
+ switch (strtolower(trim($headers['content-encoding'], "\x09\x0A\x0D\x20")))
+ {
+ case 'gzip':
+ case 'x-gzip':
+ $decoder = new CFGzipDecode($body);
+ if ($decoder->parse())
+ {
+ $body = $decoder->data;
+ }
+ break;
+
+ case 'deflate':
+ if (($body = gzuncompress($body)) === false)
+ {
+ if (($body = gzinflate($body)) === false)
+ {
+ continue;
+ }
+ }
+ break;
+ }
+ }
+
// Look for XML cues
if (
- ($content_type && ($content_type === 'text/xml' || $content_type === 'application/xml')) || // We know it's XML
- (!$content_type && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML
+ (isset($headers['content-type']) && ($headers['content-type'] === 'text/xml' || $headers['content-type'] === 'application/xml')) || // We know it's XML
+ (!isset($headers['content-type']) && (stripos($body, '<?xml') === 0 || strpos($body, '<Error>') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML
)
{
// Strip the default XML namespace to simplify XPath expressions
@@ -1195,8 +1235,8 @@ public function parse_callback($response, $content_type = null)
}
// Look for JSON cues
elseif (
- ($content_type && $content_type === 'application/json') || // We know it's JSON
- (!$content_type && $this->util->is_json($body)) // Sniff for JSON
+ (isset($headers['content-type']) && $headers['content-type'] === 'application/json') || // We know it's JSON
+ (!isset($headers['content-type']) && $this->util->is_json($body)) // Sniff for JSON
)
{
// Normalize JSON to a CFSimpleXML object
View
2 services/as.class.php
@@ -47,7 +47,7 @@
*
* </ul>
*
- * @version Tue Mar 15 11:06:05 PDT 2011
+ * @version Fri Mar 25 13:12:03 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/autoscaling/Amazon Auto-Scaling
View
2 services/cloudformation.class.php
@@ -33,7 +33,7 @@
* Amazon CloudFormation makes use of other AWS products. If you need additional technical information about a specific AWS
* product, you can find the product's technical documentation at http://aws.amazon.com/documentation/.
*
- * @version Tue Mar 15 11:07:12 PDT 2011
+ * @version Fri Mar 25 13:12:48 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/cloudformation/Amazon CloudFormation
View
2 services/cloudwatch.class.php
@@ -31,7 +31,7 @@
* automatically make changes to the resources you are monitoring, based on rules that you define. For example, you can
* create alarms that initiate Auto Scaling and Simple Notification Service actions on your behalf.
*
- * @version Tue Mar 15 11:08:01 PDT 2011
+ * @version Fri Mar 25 13:13:27 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/cloudwatch/Amazon CloudWatch
View
2 services/ec2.class.php
@@ -28,7 +28,7 @@
*
* Visit <a href="http://aws.amazon.com/ec2/">http://aws.amazon.com/ec2/</a> for more information.
*
- * @version Tue Mar 15 11:09:51 PDT 2011
+ * @version Fri Mar 25 13:14:50 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/ec2/Amazon Elastic Compute Cloud
View
2 services/elasticbeanstalk.class.php
@@ -36,7 +36,7 @@
*
* </ul>
*
- * @version Tue Mar 15 11:08:52 PDT 2011
+ * @version Fri Mar 25 13:14:04 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticbeanstalk/AWS Elastic Beanstalk
View
2 services/elb.class.php
@@ -20,7 +20,7 @@
* of your application. It makes it easy for you to distribute application loads between two or more EC2 instances. Elastic
* Load Balancing enables availability through redundancy and supports traffic growth of your application.
*
- * @version Tue Mar 15 11:11:03 PDT 2011
+ * @version Fri Mar 25 13:15:34 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticloadbalancing/Amazon Elastic Load Balancing
View
2 services/emr.class.php
@@ -19,7 +19,7 @@
* This is the Amazon Elastic MapReduce API Reference Guide. This guide is for programmers who need detailed information
* about the Amazon Elastic MapReduce APIs.
*
- * @version Tue Mar 15 11:12:53 PDT 2011
+ * @version Fri Mar 25 13:16:39 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/elasticmapreduce/Amazon Elastic MapReduce
View
2 services/iam.class.php
@@ -35,7 +35,7 @@
* We will refer to Amazon AWS Identity and Access Management using the abbreviated form IAM. All copyrights and legal
* protections still apply.
*
- * @version Tue Mar 15 11:13:44 PDT 2011
+ * @version Fri Mar 25 13:17:16 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/iam/Amazon Identity and Access Management Service
View
2 services/importexport.class.php
@@ -22,7 +22,7 @@
* high-speed internal network and bypassing the Internet. For large data sets, AWS Import/Export is often faster than
* Internet transfer and more cost effective than upgrading your connectivity.
*
- * @version Tue Mar 15 11:14:38 PDT 2011
+ * @version Fri Mar 25 13:17:53 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/importexport/Amazon Import/Export Service
View
2 services/rds.class.php
@@ -28,7 +28,7 @@
* flexible: you can scale your database instance's compute resources and storage capacity to meet your application's
* demand. As with all Amazon Web Services, there are no up-front investments, and you pay only for the resources you use.
*
- * @version Tue Mar 15 11:15:28 PDT 2011
+ * @version Fri Mar 25 13:18:27 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/rds/Amazon Relational Database Service
View
4 services/s3.class.php
@@ -1140,7 +1140,7 @@ public function set_bucket_acl($bucket, $acl = self::ACL_PRIVATE, $opt = null)
* <li><code>meta</code> - <code>array</code> - Optional - An associative array of key-value pairs. Represented by <code>x-amz-meta-:</code>. Any header starting with this prefix is considered user metadata. It will be stored with the object and returned when you retrieve the object. The total size of the HTTP request, not including the body, must be less than 4 KB.</li>
* <li><code>seekTo</code> - <code>integer</code> - Optional - The starting position in bytes within the file/stream to upload from.</li>
* <li><code>storage</code> - <code>string</code> - Optional - Whether to use Standard or Reduced Redundancy storage. [Allowed values: <code>AmazonS3::STORAGE_STANDARD</code>, <code>AmazonS3::STORAGE_REDUCED</code>]. The default value is <code>STORAGE_STANDARD</code>.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
+ * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
* @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAccessPolicy.html REST Access Control Policy
@@ -3058,7 +3058,7 @@ public function list_multipart_uploads($bucket, $opt = null)
* <li><code>seekTo</code> - <code>integer</code> - Optional - The starting position in bytes for the first piece of the file/stream to upload.</li>
* <li><code>storage</code> - <code>string</code> - Optional - Whether to use Standard or Reduced Redundancy storage. [Allowed values: <code>AmazonS3::STORAGE_STANDARD</code>, <code>AmazonS3::STORAGE_REDUCED</code>]. The default value is <code>STORAGE_STANDARD</code>.</li>
* <li><code>uploadId</code> - <code>string</code> - Optional - An upload ID identifying an existing multipart upload to use. If this option is not set, one will be created automatically.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
+ * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
* @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAccessPolicy.html REST Access Control Policy
View
2 services/sdb.class.php
@@ -31,7 +31,7 @@
*
* Visit <a href="http://aws.amazon.com/simpledb/">http://aws.amazon.com/simpledb/</a> for more information.
*
- * @version Tue Mar 15 11:16:25 PDT 2011
+ * @version Fri Mar 25 13:19:04 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/simpledb/Amazon SimpleDB
View
2 services/ses.class.php
@@ -23,7 +23,7 @@
* For specific details on how to construct a service request, please consult the <a
* href="http://docs.amazonwebservices.com/ses/latest/DeveloperGuide">Amazon SES Developer Guide</a>.
*
- * @version Tue Mar 15 11:12:03 PDT 2011
+ * @version Fri Mar 25 13:16:07 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/ses/Amazon Simple Email Service
View
2 services/sns.class.php
@@ -17,7 +17,7 @@
/**
*
- * @version Tue Mar 15 11:17:16 PDT 2011
+ * @version Fri Mar 25 13:19:36 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/sns/Amazon Simple Notification Service
View
2 services/sqs.class.php
@@ -30,7 +30,7 @@
*
* Visit <a href="http://aws.amazon.com/sqs/">http://aws.amazon.com/sqs/</a> for more information.
*
- * @version Tue Mar 15 11:18:04 PDT 2011
+ * @version Fri Mar 25 13:20:11 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/sqs/Amazon Simple Queue Service
View
40 utilities/array.class.php
@@ -54,6 +54,10 @@ public function __toString()
return 'Array';
}
+
+ /*%******************************************************************************************%*/
+ // REFORMATTING
+
/**
* Maps each element in the <CFArray> object as an integer.
*
@@ -88,6 +92,10 @@ public function map_string($pcre = null)
return $list;
}
+
+ /*%******************************************************************************************%*/
+ // CONFIRMATION
+
/**
* Verifies that _all_ responses were successful. A single failed request will cause <areOK()> to return false. Equivalent to <CFResponse::isOK()>, except it applies to all responses.
*
@@ -109,6 +117,10 @@ public function areOK()
return (array_search(false, $dlist, true) !== false) ? false : true;
}
+
+ /*%******************************************************************************************%*/
+ // ITERATING AND EXECUTING
+
/**
* Iterates over a <CFArray> object, and executes a function for each matched element.
*
@@ -186,6 +198,10 @@ public function reduce($callback, &$bind = null)
return $this->filter($callback, $bind);
}
+
+ /*%******************************************************************************************%*/
+ // TRAVERSAL
+
/**
* Gets the first result in the array.
*
@@ -227,4 +243,28 @@ public function reindex()
{
return new CFArray(array_values($this->getArrayCopy()));
}
+
+
+ /*%******************************************************************************************%*/
+ // ALTERNATE FORMATS
+
+ /**
+ * Gets the current XML node as a JSON string.
+ *
+ * @return string The current XML node as a JSON string.
+ */
+ public function to_json()
+ {
+ return json_encode($this->getArrayCopy());
+ }
+
+ /**
+ * Gets the current XML node as a YAML string.
+ *
+ * @return string The current XML node as a YAML string.
+ */
+ public function to_yaml()
+ {
+ return sfYaml::dump($this->getArrayCopy(), 5);
+ }
}
View
377 utilities/gzipdecode.class.php
@@ -0,0 +1,377 @@
+<?php
+/*
+ * Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License").
+ * You may not use this file except in compliance with the License.
+ * A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0
+ *
+ * or in the "license" file accompanying this file. This file is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+/**
+ * SimplePie
+ *
+ * A PHP-Based RSS and Atom Feed Framework.
+ * Takes the hard work out of managing a complete RSS/Atom solution.
+ *
+ * Copyright (c) 2004-2010, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * * Neither the name of the SimplePie Team nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
+ * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @package SimplePie
+ * @version 1.3-dev
+ * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
+ * @author Ryan Parman
+ * @author Geoffrey Sneddon
+ * @author Ryan McCue
+ * @link http://simplepie.org/ SimplePie
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @todo phpDoc comments
+ */
+
+
+/*%******************************************************************************************%*/
+// CLASS
+
+/**
+ * Handles a variety of primary and edge cases around gzip/deflate decoding in PHP.
+ *
+ * @version 2011.02.21
+ * @license See the included NOTICE.md file for more information.
+ * @copyright See the included NOTICE.md file for more information.
+ * @link http://aws.amazon.com/php/ PHP Developer Center
+ * @link https://github.com/simplepie/simplepie/blob/master/SimplePie/gzdecode.php SimplePie_gzdecode
+ */
+class CFGzipDecode
+{
+ /**
+ * Compressed data
+ *
+ * @access private
+ * @see gzdecode::$data
+ */
+ public $compressed_data;
+
+ /**
+ * Size of compressed data
+ *
+ * @access private
+ */
+ public $compressed_size;
+
+ /**
+ * Minimum size of a valid gzip string
+ *
+ * @access private
+ */
+ public $min_compressed_size = 18;
+
+ /**
+ * Current position of pointer
+ *
+ * @access private
+ */
+ public $position = 0;
+
+ /**
+ * Flags (FLG)
+ *
+ * @access private
+ */
+ public $flags;
+
+ /**
+ * Uncompressed data
+ *
+ * @access public
+ * @see gzdecode::$compressed_data
+ */
+ public $data;
+
+ /**
+ * Modified time
+ *
+ * @access public
+ */
+ public $MTIME;
+
+ /**
+ * Extra Flags
+ *
+ * @access public
+ */
+ public $XFL;
+
+ /**
+ * Operating System
+ *
+ * @access public
+ */
+ public $OS;
+
+ /**
+ * Subfield ID 1
+ *
+ * @access public
+ * @see gzdecode::$extra_field
+ * @see gzdecode::$SI2
+ */
+ public $SI1;
+
+ /**
+ * Subfield ID 2
+ *
+ * @access public
+ * @see gzdecode::$extra_field
+ * @see gzdecode::$SI1
+ */
+ public $SI2;
+
+ /**
+ * Extra field content
+ *
+ * @access public
+ * @see gzdecode::$SI1
+ * @see gzdecode::$SI2
+ */
+ public $extra_field;
+
+ /**
+ * Original filename
+ *
+ * @access public
+ */
+ public $filename;
+
+ /**
+ * Human readable comment
+ *
+ * @access public
+ */
+ public $comment;
+
+ /**
+ * Don't allow anything to be set
+ *
+ * @access public
+ */
+ public function __set($name, $value)
+ {
+ trigger_error("Cannot write property $name", E_USER_ERROR);
+ }
+
+ /**
+ * Set the compressed string and related properties
+ *
+ * @access public
+ */
+ public function __construct($data)
+ {
+ $this->compressed_data = $data;
+ $this->compressed_size = strlen($data);
+ }
+
+ /**
+ * Decode the GZIP stream
+ *
+ * @access public
+ */
+ public function parse()
+ {
+ if ($this->compressed_size >= $this->min_compressed_size)
+ {
+ // Check ID1, ID2, and CM
+ if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
+ {
+ return false;
+ }
+
+ // Get the FLG (FLaGs)
+ $this->flags = ord($this->compressed_data[3]);
+
+ // FLG bits above (1 << 4) are reserved
+ if ($this->flags > 0x1F)
+ {
+ return false;
+ }
+
+ // Advance the pointer after the above
+ $this->position += 4;
+
+ // MTIME
+ $mtime = substr($this->compressed_data, $this->position, 4);
+ // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
+ if (current(unpack('S', "\x00\x01")) === 1)
+ {
+ $mtime = strrev($mtime);
+ }
+ $this->MTIME = current(unpack('l', $mtime));
+ $this->position += 4;
+
+ // Get the XFL (eXtra FLags)
+ $this->XFL = ord($this->compressed_data[$this->position++]);
+
+ // Get the OS (Operating System)
+ $this->OS = ord($this->compressed_data[$this->position++]);
+
+ // Parse the FEXTRA
+ if ($this->flags & 4)
+ {
+ // Read subfield IDs
+ $this->SI1 = $this->compressed_data[$this->position++];
+ $this->SI2 = $this->compressed_data[$this->position++];
+
+ // SI2 set to zero is reserved for future use
+ if ($this->SI2 === "\x00")
+ {
+ return false;
+ }
+
+ // Get the length of the extra field
+ $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
+ $position += 2;
+
+ // Check the length of the string is still valid
+ $this->min_compressed_size += $len + 4;
+ if ($this->compressed_size >= $this->min_compressed_size)
+ {
+ // Set the extra field to the given data
+ $this->extra_field = substr($this->compressed_data, $this->position, $len);
+ $this->position += $len;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // Parse the FNAME
+ if ($this->flags & 8)
+ {
+ // Get the length of the filename
+ $len = strcspn($this->compressed_data, "\x00", $this->position);
+
+ // Check the length of the string is still valid
+ $this->min_compressed_size += $len + 1;
+ if ($this->compressed_size >= $this->min_compressed_size)
+ {
+ // Set the original filename to the given string
+ $this->filename = substr($this->compressed_data, $this->position, $len);
+ $this->position += $len + 1;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // Parse the FCOMMENT
+ if ($this->flags & 16)
+ {
+ // Get the length of the comment
+ $len = strcspn($this->compressed_data, "\x00", $this->position);
+
+ // Check the length of the string is still valid
+ $this->min_compressed_size += $len + 1;
+ if ($this->compressed_size >= $this->min_compressed_size)
+ {
+ // Set the original comment to the given string
+ $this->comment = substr($this->compressed_data, $this->position, $len);
+ $this->position += $len + 1;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // Parse the FHCRC
+ if ($this->flags & 2)
+ {
+ // Check the length of the string is still valid
+ $this->min_compressed_size += $len + 2;
+ if ($this->compressed_size >= $this->min_compressed_size)
+ {
+ // Read the CRC
+ $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
+
+ // Check the CRC matches
+ if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
+ {
+ $this->position += 2;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // Decompress the actual data
+ if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
+ {
+ return false;
+ }
+ else
+ {
+ $this->position = $this->compressed_size - 8;
+ }
+
+ // Check CRC of data
+ $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
+ $this->position += 4;
+ /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
+ {
+ return false;
+ }*/
+
+ // Check ISIZE of data
+ $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
+ $this->position += 4;
+ if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
+ {
+ return false;
+ }
+
+ // Wow, against all odds, we've actually got a valid gzip string
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
View
2 utilities/json.class.php
@@ -21,7 +21,7 @@
/**
* Handles the conversion of data from JSON to other formats.
*
- * @version 2011.03.02
+ * @version 2011.03.25
* @license See the included NOTICE.md file for more information.
* @copyright See the included NOTICE.md file for more information.
* @link http://aws.amazon.com/php/ PHP Developer Center
View
34 utilities/simplexml.class.php
@@ -22,7 +22,7 @@
* Wraps the underlying `SimpleXMLIterator` class with enhancements for rapidly traversing the DOM tree,
* converting types, and comparisons.
*
- * @version 2010.11.08
+ * @version 2011.03.25
* @license See the included NOTICE.md file for more information.
* @copyright See the included NOTICE.md file for more information.
* @link http://aws.amazon.com/php/ PHP Developer Center
@@ -77,6 +77,10 @@ public function __call($name, $arguments)
return $results;
}
+
+ /*%******************************************************************************************%*/
+ // TRAVERSAL
+
/**
* Wraps the results of an XPath query in a <CFArray> object.
*
@@ -108,6 +112,10 @@ public function parent($node = null)
return $parents[0];
}
+
+ /*%******************************************************************************************%*/
+ // ALTERNATE FORMATS
+
/**
* Gets the current XML node as a true string.
*
@@ -129,6 +137,16 @@ public function to_array()
}
/**
+ * Gets the current XML node as a stdClass object.
+ *
+ * @return array The current XML node as a stdClass object.
+ */
+ public function to_stdClass()
+ {
+ return json_decode(json_encode($this));
+ }
+
+ /**
* Gets the current XML node as a JSON string.
*
* @return string The current XML node as a JSON string.
@@ -139,6 +157,20 @@ public function to_json()
}
/**
+ * Gets the current XML node as a YAML string.
+ *
+ * @return string The current XML node as a YAML string.
+ */
+ public function to_yaml()
+ {
+ return sfYaml::dump(json_decode(json_encode($this), true), 5);
+ }
+
+
+ /*%******************************************************************************************%*/
+ // COMPARISONS
+
+ /**
* Whether or not the current node exactly matches the compared value.
*
* @param string $value (Required) The value to compare the current node to.
View
5 utilities/utilities.class.php
@@ -112,7 +112,10 @@ public function to_query_string($array)
foreach ($array as $key => $value)
{
- $temp[] = rawurlencode($key) . '=' . rawurlencode($value);
+ if (is_string($key) && !is_array($value))
+ {
+ $temp[] = rawurlencode($key) . '=' . rawurlencode($value);
+ }
}
return implode('&', $temp);

0 comments on commit 1a7232c

Please sign in to comment.
Something went wrong with that request. Please try again.