import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Amazon.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Amazon.php 13551 2009-01-08 14:27:42Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -228,11 +228,16 @@ class Zend_Service_Amazon
|
||||
$code = $xpath->query('//az:Error/az:Code/text()')->item(0)->data;
|
||||
$message = $xpath->query('//az:Error/az:Message/text()')->item(0)->data;
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Exception.php';
|
||||
throw new Zend_Service_Exception("$message ($code)");
|
||||
switch($code) {
|
||||
case 'AWS.ECommerceService.NoExactMatches':
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Service_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Exception.php';
|
||||
throw new Zend_Service_Exception("$message ($code)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
167
libs/Zend/Service/Amazon/Abstract.php
Normal file
167
libs/Zend/Service/Amazon/Abstract.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?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_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Abstract.php';
|
||||
|
||||
/**
|
||||
* Abstract Amazon class that handles the credentials for any of the Web Services that
|
||||
* Amazon offers
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Service_Amazon_Abstract extends Zend_Service_Abstract
|
||||
{
|
||||
/**
|
||||
* @var string Amazon Access Key
|
||||
*/
|
||||
protected static $_defaultAccessKey = null;
|
||||
|
||||
/**
|
||||
* @var string Amazon Secret Key
|
||||
*/
|
||||
protected static $_defaultSecretKey = null;
|
||||
|
||||
/**
|
||||
* @var string Amazon Region
|
||||
*/
|
||||
protected static $_defaultRegion = null;
|
||||
|
||||
/**
|
||||
* @var string Amazon Secret Key
|
||||
*/
|
||||
protected $_secretKey;
|
||||
|
||||
/**
|
||||
* @var string Amazon Access Key
|
||||
*/
|
||||
protected $_accessKey;
|
||||
|
||||
/**
|
||||
* @var string Amazon Region
|
||||
*/
|
||||
protected $_region;
|
||||
|
||||
/**
|
||||
* An array that contains all the valid Amazon Ec2 Regions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_validEc2Regions = array('eu-west-1', 'us-east-1');
|
||||
|
||||
/**
|
||||
* Set the keys to use when accessing SQS.
|
||||
*
|
||||
* @param string $access_key Set the default Access Key
|
||||
* @param string $secret_key Set the default Secret Key
|
||||
* @return void
|
||||
*/
|
||||
public static function setKeys($accessKey, $secretKey)
|
||||
{
|
||||
self::$_defaultAccessKey = $accessKey;
|
||||
self::$_defaultSecretKey = $secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which region you are working in. It will append the
|
||||
* end point automaticly
|
||||
*
|
||||
* @param string $region
|
||||
*/
|
||||
public static function setRegion($region)
|
||||
{
|
||||
if(in_array(strtolower($region), self::$_validEc2Regions, true)) {
|
||||
self::$_defaultRegion = $region;
|
||||
} else {
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
throw new Zend_Service_Amazon_Exception('Invalid Amazon Ec2 Region');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Amazon Sqs client.
|
||||
*
|
||||
* @param string $access_key Override the default Access Key
|
||||
* @param string $secret_key Override the default Secret Key
|
||||
* @param string $region Sets the AWS Region
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($accessKey=null, $secretKey=null, $region=null)
|
||||
{
|
||||
if(!$accessKey) {
|
||||
$accessKey = self::$_defaultAccessKey;
|
||||
}
|
||||
if(!$secretKey) {
|
||||
$secretKey = self::$_defaultSecretKey;
|
||||
}
|
||||
if(!$region) {
|
||||
$region = self::$_defaultRegion;
|
||||
} else {
|
||||
// make rue the region is valid
|
||||
if(!empty($region) && !in_array(strtolower($region), self::$_validEc2Regions, true)) {
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
throw new Zend_Service_Amazon_Exception('Invalid Amazon Ec2 Region');
|
||||
}
|
||||
}
|
||||
|
||||
if(!$accessKey || !$secretKey) {
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
throw new Zend_Service_Amazon_Exception("AWS keys were not supplied");
|
||||
}
|
||||
$this->_accessKey = $accessKey;
|
||||
$this->_secretKey = $secretKey;
|
||||
$this->_region = $region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fetch the AWS Region
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getRegion()
|
||||
{
|
||||
return (!empty($this->_region)) ? $this->_region . '.' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fetch the Access Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getAccessKey()
|
||||
{
|
||||
return $this->_accessKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fetch the Secret AWS Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getSecretKey()
|
||||
{
|
||||
return $this->_secretKey;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Accessories.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Accessories.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,16 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_Accessories
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ASIN;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Title;
|
||||
|
||||
/**
|
||||
* Assigns values to properties relevant to Accessories
|
||||
*
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: CustomerReview.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: CustomerReview.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,41 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_CustomerReview
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Rating;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $HelpfulVotes;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $CustomerId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $TotalVotes;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Date;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Summary;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Content;
|
||||
|
||||
/**
|
||||
* Assigns values to properties relevant to CustomerReview
|
||||
*
|
||||
|
87
libs/Zend/Service/Amazon/Ec2.php
Normal file
87
libs/Zend/Service/Amazon/Ec2.php
Normal 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_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Amazon Ec2 Interface to allow easy creation of the Ec2 Components
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2
|
||||
{
|
||||
/**
|
||||
* Factory method to fetch what you want to work with.
|
||||
*
|
||||
* @param string $section Create the method that you want to work with
|
||||
* @param string $key Override the default aws key
|
||||
* @param string $secret_key Override the default aws secretkey
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
* @return object
|
||||
*/
|
||||
public static function factory($section, $key = null, $secret_key = null)
|
||||
{
|
||||
switch(strtolower($section)) {
|
||||
case 'keypair':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Keypair';
|
||||
break;
|
||||
case 'eip':
|
||||
// break left out
|
||||
case 'elasticip':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Elasticip';
|
||||
break;
|
||||
case 'ebs':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Ebs';
|
||||
break;
|
||||
case 'availabilityzones':
|
||||
// break left out
|
||||
case 'zones':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Availabilityzones';
|
||||
break;
|
||||
case 'ami':
|
||||
// break left out
|
||||
case 'image':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Image';
|
||||
break;
|
||||
case 'instance':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Instance';
|
||||
break;
|
||||
case 'security':
|
||||
// break left out
|
||||
case 'securitygroups':
|
||||
$class = 'Zend_Service_Amazon_Ec2_Securitygroups';
|
||||
break;
|
||||
default:
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Section: ' . $section);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($class);
|
||||
}
|
||||
return new $class($key, $secret_key);
|
||||
}
|
||||
}
|
||||
|
201
libs/Zend/Service/Amazon/Ec2/Abstract.php
Normal file
201
libs/Zend/Service/Amazon/Ec2/Abstract.php
Normal file
@ -0,0 +1,201 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Abstract.php';
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Response.php';
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
|
||||
/**
|
||||
* Provides the basic functionality to send a request to the Amazon Ec2 Query API
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abstract
|
||||
{
|
||||
/**
|
||||
* The HTTP query server
|
||||
*/
|
||||
const EC2_ENDPOINT = 'ec2.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
const EC2_API_VERSION = '2008-12-01';
|
||||
|
||||
/**
|
||||
* Signature Version
|
||||
*/
|
||||
const EC2_SIGNATURE_VERSION = '2';
|
||||
|
||||
/**
|
||||
* Signature Encoding Method
|
||||
*/
|
||||
const EC2_SIGNATURE_METHOD = 'HmacSHA256';
|
||||
|
||||
/**
|
||||
* Period after which HTTP request will timeout in seconds
|
||||
*/
|
||||
const HTTP_TIMEOUT = 10;
|
||||
|
||||
/**
|
||||
* Sends a HTTP request to the queue service using Zend_Http_Client
|
||||
*
|
||||
* @param array $params List of parameters to send with the request
|
||||
* @return Zend_Service_Amazon_Ec2_Response
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
*/
|
||||
protected function sendRequest(array $params = array())
|
||||
{
|
||||
$url = 'https://' . $this->_getRegion() . self::EC2_ENDPOINT . '/';
|
||||
|
||||
$params = $this->addRequiredParameters($params);
|
||||
|
||||
try {
|
||||
/* @var $request Zend_Http_Client */
|
||||
$request = self::getHttpClient();
|
||||
$request->resetParameters();
|
||||
|
||||
$request->setConfig(array(
|
||||
'timeout' => self::HTTP_TIMEOUT
|
||||
));
|
||||
|
||||
$request->setUri($url);
|
||||
$request->setMethod(Zend_Http_Client::POST);
|
||||
$request->setParameterPost($params);
|
||||
|
||||
$httpResponse = $request->request();
|
||||
|
||||
|
||||
} catch (Zend_Http_Client_Exception $zhce) {
|
||||
$message = 'Error in request to AWS service: ' . $zhce->getMessage();
|
||||
throw new Zend_Service_Amazon_Ec2_Exception($message, $zhce->getCode());
|
||||
}
|
||||
|
||||
$response = new Zend_Service_Amazon_Ec2_Response($httpResponse);
|
||||
$this->checkForErrors($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds required authentication and version parameters to an array of
|
||||
* parameters
|
||||
*
|
||||
* The required parameters are:
|
||||
* - AWSAccessKey
|
||||
* - SignatureVersion
|
||||
* - Timestamp
|
||||
* - Version and
|
||||
* - Signature
|
||||
*
|
||||
* If a required parameter is already set in the <tt>$parameters</tt> array,
|
||||
* it is overwritten.
|
||||
*
|
||||
* @param array $parameters the array to which to add the required
|
||||
* parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function addRequiredParameters(array $parameters)
|
||||
{
|
||||
$parameters['AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$parameters['SignatureVersion'] = self::EC2_SIGNATURE_VERSION;
|
||||
$parameters['Expires'] = gmdate('c');
|
||||
$parameters['Version'] = self::EC2_API_VERSION;
|
||||
$parameters['SignatureMethod'] = self::EC2_SIGNATURE_METHOD;
|
||||
$parameters['Signature'] = $this->signParameters($parameters);
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the RFC 2104-compliant HMAC signature for request parameters
|
||||
*
|
||||
* This implements the Amazon Web Services signature, as per the following
|
||||
* specification:
|
||||
*
|
||||
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
|
||||
* excluding <tt>Signature</tt>, the value of which is being created),
|
||||
* ignoring case.
|
||||
*
|
||||
* 2. Iterate over the sorted list and append the parameter name (in its
|
||||
* original case) and then its value. Do not URL-encode the parameter
|
||||
* values before constructing this string. Do not use any separator
|
||||
* characters when appending strings.
|
||||
*
|
||||
* @param array $parameters the parameters for which to get the signature.
|
||||
* @param string $secretKey the secret key to use to sign the parameters.
|
||||
*
|
||||
* @return string the signed data.
|
||||
*/
|
||||
protected function signParameters(array $paramaters)
|
||||
{
|
||||
$data = "POST\n";
|
||||
$data .= $this->_getRegion() . self::EC2_ENDPOINT . "\n";
|
||||
$data .= "/\n";
|
||||
|
||||
uksort($paramaters, 'strcmp');
|
||||
unset($paramaters['Signature']);
|
||||
|
||||
$arrData = array();
|
||||
foreach($paramaters as $key => $value) {
|
||||
$arrData[] = $key . '=' . str_replace("%7E", "~", urlencode($value));
|
||||
}
|
||||
|
||||
$data .= implode('&', $arrData);
|
||||
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
|
||||
|
||||
return base64_encode($hmac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for errors responses from Amazon
|
||||
*
|
||||
* @param Zend_Service_Amazon_Ec2_Response $response the response object to
|
||||
* check.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception if one or more errors are
|
||||
* returned from Amazon.
|
||||
*/
|
||||
private function checkForErrors(Zend_Service_Amazon_Ec2_Response $response)
|
||||
{
|
||||
$xpath = new DOMXPath($response->getDocument());
|
||||
$list = $xpath->query('//Error');
|
||||
if ($list->length > 0) {
|
||||
$node = $list->item(0);
|
||||
$code = $xpath->evaluate('string(Code/text())', $node);
|
||||
$message = $xpath->evaluate('string(Message/text())', $node);
|
||||
throw new Zend_Service_Amazon_Ec2_Exception($message, 0, $code);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
73
libs/Zend/Service/Amazon/Ec2/Availabilityzones.php
Normal file
73
libs/Zend/Service/Amazon/Ec2/Availabilityzones.php
Normal 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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to query which Availibity Zones your account has access to.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Availabilityzones extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Describes availability zones that are currently available to the account
|
||||
* and their states.
|
||||
*
|
||||
* @param string|array $zoneName Name of an availability zone.
|
||||
* @return array An array that contains all the return items. Keys: zoneName and zoneState.
|
||||
*/
|
||||
public function describe($zoneName = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeAvailabilityZones';
|
||||
|
||||
if(is_array($zoneName) && !empty($zoneName)) {
|
||||
foreach($zoneName as $k=>$name) {
|
||||
$params['ZoneName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($zoneName) {
|
||||
$params['ZoneName.1'] = $zoneName;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['zoneName'] = $xpath->evaluate('string(ec2:zoneName/text())', $node);
|
||||
$item['zoneState'] = $xpath->evaluate('string(ec2:zoneState/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
340
libs/Zend/Service/Amazon/Ec2/Ebs.php
Normal file
340
libs/Zend/Service/Amazon/Ec2/Ebs.php
Normal file
@ -0,0 +1,340 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, describe, attach, detach and delete Elastic Block
|
||||
* Storage Volumes and Snaphsots.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Ebs extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
|
||||
*
|
||||
* You must specify an availability zone when creating a volume. The volume and
|
||||
* any instance to which it attaches must be in the same availability zone.
|
||||
*
|
||||
* @param string $size The size of the volume, in GiB.
|
||||
* @param string $availabilityZone The availability zone in which to create the new volume.
|
||||
* @return array
|
||||
*/
|
||||
public function createNewVolume($size, $availabilityZone)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateVolume';
|
||||
$params['AvailabilityZone'] = $availabilityZone;
|
||||
$params['Size'] = $size;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['size'] = $xpath->evaluate('string(//ec2:size/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['createTime'] = $xpath->evaluate('string(//ec2:createTime/text())');
|
||||
$return['availabilityZone'] = $xpath->evaluate('string(//ec2:availabilityZone/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
|
||||
*
|
||||
* You must specify an availability zone when creating a volume. The volume and
|
||||
* any instance to which it attaches must be in the same availability zone.
|
||||
*
|
||||
* @param string $snapshotId The snapshot from which to create the new volume.
|
||||
* @param string $availabilityZone The availability zone in which to create the new volume.
|
||||
* @return array
|
||||
*/
|
||||
public function createVolumeFromSnapshot($snapshotId, $availabilityZone)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateVolume';
|
||||
$params['AvailabilityZone'] = $availabilityZone;
|
||||
$params['SnapshotId'] = $snapshotId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['size'] = $xpath->evaluate('string(//ec2:size/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['createTime'] = $xpath->evaluate('string(//ec2:createTime/text())');
|
||||
$return['availabilityZone'] = $xpath->evaluate('string(//ec2:availabilityZone/text())');
|
||||
$return['snapshotId'] = $xpath->evaluate('string(//ec2:snapshotId/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists one or more Amazon EBS volumes that you own, If you do not
|
||||
* specify any volumes, Amazon EBS returns all volumes that you own.
|
||||
*
|
||||
* @param string|array $volumeId The ID or array of ID's of the volume(s) to list
|
||||
* @return array
|
||||
*/
|
||||
public function describeVolume($volumeId = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeVolumes';
|
||||
|
||||
if(is_array($volumeId) && !empty($volumeId)) {
|
||||
foreach($volumeId as $k=>$name) {
|
||||
$params['VolumeId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($volumeId) {
|
||||
$params['VolumeId.1'] = $volumeId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:volumeSet/ec2:item', $response->getDocument());
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $node);
|
||||
$item['size'] = $xpath->evaluate('string(ec2:size/text())', $node);
|
||||
$item['status'] = $xpath->evaluate('string(ec2:status/text())', $node);
|
||||
$item['createTime'] = $xpath->evaluate('string(ec2:createTime/text())', $node);
|
||||
|
||||
$attachmentSet = $xpath->query('ec2:attachmentSet/ec2:item', $node);
|
||||
if($attachmentSet->length == 1) {
|
||||
$_as = $attachmentSet->item(0);
|
||||
$as = array();
|
||||
$as['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $_as);
|
||||
$as['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $_as);
|
||||
$as['device'] = $xpath->evaluate('string(ec2:device/text())', $_as);
|
||||
$as['status'] = $xpath->evaluate('string(ec2:status/text())', $_as);
|
||||
$as['attachTime'] = $xpath->evaluate('string(ec2:attachTime/text())', $_as);
|
||||
$item['attachmentSet'] = $as;
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function describeAttachedVolumes($instanceId)
|
||||
{
|
||||
$volumes = $this->describeVolume();
|
||||
|
||||
$return = array();
|
||||
foreach($volumes as $vol) {
|
||||
if(isset($vol['attachmentSet']) && $vol['attachmentSet']['instanceId'] == $instanceId) {
|
||||
$return[] = $vol;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an Amazon EBS volume to an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume
|
||||
* @param string $instanceId The ID of the instance to which the volume attaches
|
||||
* @param string $device Specifies how the device is exposed to the instance (e.g., /dev/sdh).
|
||||
* @return array
|
||||
*/
|
||||
public function attachVolume($volumeId, $instanceId, $device)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AttachVolume';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Device'] = $device;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['device'] = $xpath->evaluate('string(//ec2:device/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['attachTime'] = $xpath->evaluate('string(//ec2:attachTime/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an Amazon EBS volume from an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume
|
||||
* @param string $instanceId The ID of the instance from which the volume will detach
|
||||
* @param string $device The device name
|
||||
* @param boolean $force Forces detachment if the previous detachment attempt did not occur cleanly
|
||||
* (logging into an instance, unmounting the volume, and detaching normally).
|
||||
* This option can lead to data loss or a corrupted file system. Use this option
|
||||
* only as a last resort to detach an instance from a failed instance. The
|
||||
* instance will not have an opportunity to flush file system caches nor
|
||||
* file system meta data.
|
||||
* @return array
|
||||
*/
|
||||
public function detachVolume($volumeId, $instanceId = null, $device = null, $force = false)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DetachVolume';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Device'] = $device;
|
||||
$params['Force'] = $force;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['device'] = $xpath->evaluate('string(//ec2:device/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['attachTime'] = $xpath->evaluate('string(//ec2:attachTime/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an Amazon EBS volume
|
||||
*
|
||||
* @param string $volumeId The ID of the volume to delete
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteVolume($volumeId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteVolume';
|
||||
$params['volumeId'] = $volumeId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups,
|
||||
* to launch instances from identical snapshots, and to save data before shutting down an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume to snapshot
|
||||
* @return array
|
||||
*/
|
||||
public function createSnapshot($volumeId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateSnapshot';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['snapshotId'] = $xpath->evaluate('string(//ec2:snapshotId/text())');
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:startTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:progress/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the status of Amazon EBS snapshots
|
||||
*
|
||||
* @param string|array $snapshotId The ID or arry of ID's of the Amazon EBS snapshot
|
||||
* @return array
|
||||
*/
|
||||
public function describeSnapshot($snapshotId = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeSnapshots';
|
||||
|
||||
if(is_array($snapshotId) && !empty($snapshotId)) {
|
||||
foreach($snapshotId as $k=>$name) {
|
||||
$params['SnapshotId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($snapshotId) {
|
||||
$params['SnapshotId.1'] = $snapshotId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:snapshotSet/ec2:item', $response->getDocument());
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['snapshotId'] = $xpath->evaluate('string(ec2:snapshotId/text())', $node);
|
||||
$item['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $node);
|
||||
$item['status'] = $xpath->evaluate('string(ec2:status/text())', $node);
|
||||
$item['startTime'] = $xpath->evaluate('string(ec2:startTime/text())', $node);
|
||||
$item['progress'] = $xpath->evaluate('string(ec2:progress/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3
|
||||
*
|
||||
* @param string $snapshotId The ID of the Amazon EBS snapshot to delete
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteSnapshot($snapshotId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteSnapshot';
|
||||
$params['SnapshotId'] = $snapshotId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
}
|
155
libs/Zend/Service/Amazon/Ec2/Elasticip.php
Normal file
155
libs/Zend/Service/Amazon/Ec2/Elasticip.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to allocate, associate, describe and release Elastic IP address
|
||||
* from your account.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Elasticip extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Acquires an elastic IP address for use with your account
|
||||
*
|
||||
* @return string Returns the newly Allocated IP Address
|
||||
*/
|
||||
public function allocate()
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AllocateAddress';
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$ip = $xpath->evaluate('string(//ec2:publicIp/text())');
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists elastic IP addresses assigned to your account.
|
||||
*
|
||||
* @param string|array $publicIp Elastic IP or list of addresses to describe.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($publicIp = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeAddresses';
|
||||
|
||||
if(is_array($publicIp) && !empty($publicIp)) {
|
||||
foreach($publicIp as $k=>$name) {
|
||||
$params['PublicIp.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($publicIp) {
|
||||
$params['PublicIp.1'] = $publicIp;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['publicIp'] = $xpath->evaluate('string(ec2:publicIp/text())', $node);
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases an elastic IP address that is associated with your account
|
||||
*
|
||||
* @param string $publicIp IP address that you are releasing from your account.
|
||||
* @return boolean
|
||||
*/
|
||||
public function release($publicIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ReleaseAddress';
|
||||
$params['PublicIp'] = $publicIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates an elastic IP address with an instance
|
||||
*
|
||||
* @param string $instanceId The instance to which the IP address is assigned
|
||||
* @param string $publicIp IP address that you are assigning to the instance.
|
||||
* @return boolean
|
||||
*/
|
||||
public function associate($instanceId, $publicIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AssociateAddress';
|
||||
$params['PublicIp'] = $publicIp;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociates the specified elastic IP address from the instance to which it is assigned.
|
||||
* This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error.
|
||||
*
|
||||
* @param string $publicIp IP address that you are disassociating from the instance.
|
||||
* @return boolean
|
||||
*/
|
||||
public function disassocate($publicIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DisssociateAddress';
|
||||
$params['PublicIp'] = $publicIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
}
|
48
libs/Zend/Service/Amazon/Ec2/Exception.php
Normal file
48
libs/Zend/Service/Amazon/Ec2/Exception.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
|
||||
/**
|
||||
* The Custom Exception class that allows you to have access to the AWS Error Code.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Exception extends Zend_Service_Amazon_Exception
|
||||
{
|
||||
private $awsErrorCode = '';
|
||||
|
||||
public function __construct($message, $code = 0, $awsErrorCode = '')
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->awsErrorCode = $awsErrorCode;
|
||||
}
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->awsErrorCode;
|
||||
}
|
||||
}
|
330
libs/Zend/Service/Amazon/Ec2/Image.php
Normal file
330
libs/Zend/Service/Amazon/Ec2/Image.php
Normal file
@ -0,0 +1,330 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to register, describe and deregister Amamzon Machine Instances (AMI)
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Image extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Registers an AMI with Amazon EC2. Images must be registered before
|
||||
* they can be launched.
|
||||
*
|
||||
* Each AMI is associated with an unique ID which is provided by the Amazon
|
||||
* EC2 service through the RegisterImage operation. During registration, Amazon
|
||||
* EC2 retrieves the specified image manifest from Amazon S3 and verifies that
|
||||
* the image is owned by the user registering the image.
|
||||
*
|
||||
* The image manifest is retrieved once and stored within the Amazon EC2.
|
||||
* Any modifications to an image in Amazon S3 invalidates this registration.
|
||||
* If you make changes to an image, deregister the previous image and register
|
||||
* the new image. For more information, see DeregisterImage.
|
||||
*
|
||||
* @param string $imageLocation Full path to your AMI manifest in Amazon S3 storage.
|
||||
* @return string The ami fro the newly registred image;
|
||||
*/
|
||||
public function register($imageLocation)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RegisterImage';
|
||||
$params['ImageLocation']= $imageLocation;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$amiId = $xpath->evaluate('string(//ec2:imageId/text())');
|
||||
|
||||
return $amiId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about AMIs, AKIs, and ARIs available to the user.
|
||||
* Information returned includes image type, product codes, architecture,
|
||||
* and kernel and RAM disk IDs. Images available to the user include public
|
||||
* images available for any user to launch, private images owned by the user
|
||||
* making the request, and private images owned by other users for which the
|
||||
* user has explicit launch permissions.
|
||||
*
|
||||
* Launch permissions fall into three categories:
|
||||
* public: The owner of the AMI granted launch permissions for the AMI
|
||||
* to the all group. All users have launch permissions for these AMIs.
|
||||
* explicit: The owner of the AMI granted launch permissions to a specific user.
|
||||
* implicit: A user has implicit launch permissions for all AMIs he or she owns.
|
||||
*
|
||||
* The list of AMIs returned can be modified by specifying AMI IDs, AMI owners,
|
||||
* or users with launch permissions. If no options are specified, Amazon EC2 returns
|
||||
* all AMIs for which the user has launch permissions.
|
||||
*
|
||||
* If you specify one or more AMI IDs, only AMIs that have the specified IDs are returned.
|
||||
* If you specify an invalid AMI ID, a fault is returned. If you specify an AMI ID for which
|
||||
* you do not have access, it will not be included in the returned results.
|
||||
*
|
||||
* If you specify one or more AMI owners, only AMIs from the specified owners and for
|
||||
* which you have access are returned. The results can include the account IDs of the
|
||||
* specified owners, amazon for AMIs owned by Amazon or self for AMIs that you own.
|
||||
*
|
||||
* If you specify a list of executable users, only users that have launch permissions
|
||||
* for the AMIs are returned. You can specify account IDs (if you own the AMI(s)), self
|
||||
* for AMIs for which you own or have explicit permissions, or all for public AMIs.
|
||||
*
|
||||
* @param string|array $imageId A list of image descriptions
|
||||
* @param string|array $owner Owners of AMIs to describe.
|
||||
* @param string|array $executableBy AMIs for which specified users have access.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($imageId = null, $owner = null, $executableBy = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeImages';
|
||||
|
||||
if(is_array($imageId) && !empty($imageId)) {
|
||||
foreach($imageId as $k=>$name) {
|
||||
$params['ImageId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($imageId) {
|
||||
$params['ImageId.1'] = $imageId;
|
||||
}
|
||||
|
||||
if(is_array($owner) && !empty($owner)) {
|
||||
foreach($owner as $k=>$name) {
|
||||
$params['Owner.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($owner) {
|
||||
$params['Owner.1'] = $owner;
|
||||
}
|
||||
|
||||
if(is_array($executableBy) && !empty($executableBy)) {
|
||||
foreach($executableBy as $k=>$name) {
|
||||
$params['ExecutableBy.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($executableBy) {
|
||||
$params['ExecutableBy.1'] = $executableBy;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:imagesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $node);
|
||||
$item['imageLocation'] = $xpath->evaluate('string(ec2:imageLocation/text())', $node);
|
||||
$item['imageState'] = $xpath->evaluate('string(ec2:imageState/text())', $node);
|
||||
$item['imageOwnerId'] = $xpath->evaluate('string(ec2:imageOwnerId/text())', $node);
|
||||
$item['isPublic'] = $xpath->evaluate('string(ec2:isPublic/text())', $node);
|
||||
$item['architecture'] = $xpath->evaluate('string(ec2:architecture/text())', $node);
|
||||
$item['imageType'] = $xpath->evaluate('string(ec2:imageType/text())', $node);
|
||||
$item['kernelId'] = $xpath->evaluate('string(ec2:kernelId/text())', $node);
|
||||
$item['ramdiskId'] = $xpath->evaluate('string(ec2:ramdiskId/text())', $node);
|
||||
$item['platform'] = $xpath->evaluate('string(ec2:platform/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters an AMI. Once deregistered, instances of the AMI can no longer be launched.
|
||||
*
|
||||
* @param string $imageId Unique ID of a machine image, returned by a call
|
||||
* to RegisterImage or DescribeImages.
|
||||
* @return boolean
|
||||
*/
|
||||
public function deregister($imageId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeregisterImage';
|
||||
$params['ImageId'] = $imageId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies an attribute of an AMI.
|
||||
*
|
||||
* Valid Attributes:
|
||||
* launchPermission: Controls who has permission to launch the AMI. Launch permissions
|
||||
* can be granted to specific users by adding userIds.
|
||||
* To make the AMI public, add the all group.
|
||||
* productCodes: Associates a product code with AMIs. This allows developers to
|
||||
* charge users for using AMIs. The user must be signed up for the
|
||||
* product before they can launch the AMI. This is a write once attribute;
|
||||
* after it is set, it cannot be changed or removed.
|
||||
*
|
||||
* @param string $imageId AMI ID to modify.
|
||||
* @param string $attribute Specifies the attribute to modify. See the preceding
|
||||
* attributes table for supported attributes.
|
||||
* @param string $operationType Specifies the operation to perform on the attribute.
|
||||
* See the preceding attributes table for supported operations for attributes.
|
||||
* Valid Values: add | remove
|
||||
* Required for launchPermssion Attribute
|
||||
*
|
||||
* @param string|array $userId User IDs to add to or remove from the launchPermission attribute.
|
||||
* Required for launchPermssion Attribute
|
||||
* @param string|array $userGroup User groups to add to or remove from the launchPermission attribute.
|
||||
* Currently, the all group is available, which will make it a public AMI.
|
||||
* Required for launchPermssion Attribute
|
||||
* @param string $productCode Attaches a product code to the AMI. Currently only one product code
|
||||
* can be associated with an AMI. Once set, the product code cannot be changed or reset.
|
||||
* Required for productCodes Attribute
|
||||
* @return boolean
|
||||
*/
|
||||
public function modifyAttribute($imageId, $attribute, $operationType = 'add', $userId = null, $userGroup = null, $productCode = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ModifyImageAttribute';
|
||||
$parmas['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
switch($attribute) {
|
||||
case 'launchPermission':
|
||||
// break left out
|
||||
case 'launchpermission':
|
||||
$params['Attribute'] = 'launchPermission';
|
||||
$params['OperationType'] = $operationType;
|
||||
|
||||
if(is_array($userId) && !empty($userId)) {
|
||||
foreach($userId as $k=>$name) {
|
||||
$params['UserId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($userId) {
|
||||
$params['UserId.1'] = $userId;
|
||||
}
|
||||
|
||||
if(is_array($userGroup) && !empty($userGroup)) {
|
||||
foreach($userGroup as $k=>$name) {
|
||||
$params['UserGroup.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($userGroup) {
|
||||
$params['UserGroup.1'] = $userGroup;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'productCodes':
|
||||
// break left out
|
||||
case 'productcodes':
|
||||
$params['Attribute'] = 'productCodes';
|
||||
$parmas['ProductCode.1'] = $productCode;
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Attribute Passed In. Valid Image Attributes are launchPermission and productCode.');
|
||||
break;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about an attribute of an AMI. Only one attribute can be specified per call.
|
||||
*
|
||||
* @param string $imageId ID of the AMI for which an attribute will be described.
|
||||
* @param string $attribute Specifies the attribute to describe. Valid Attributes are
|
||||
* launchPermission, productCodes
|
||||
*/
|
||||
public function describeAttribute($imageId, $attribute)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeImageAttribute';
|
||||
$params['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['imageId'] = $xpath->evaluate('string(//ec2:imageId/text())');
|
||||
|
||||
// check for launchPermission
|
||||
if($attribute == 'launchPermission') {
|
||||
$lPnodes = $xpath->query('//ec2:launchPermission/ec2:item');
|
||||
|
||||
if($lPnodes->length > 0) {
|
||||
$return['launchPermission'] = array();
|
||||
foreach($lPnodes as $node) {
|
||||
$return['launchPermission'][] = $xpath->evaluate('string(ec2:userId/text())', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for product codes
|
||||
if($attribute == 'productCodes') {
|
||||
$pCnodes = $xpath->query('//ec2:productCodes/ec2:item');
|
||||
if($pCnodes->length > 0) {
|
||||
$return['productCodes'] = array();
|
||||
foreach($pCnodes as $node) {
|
||||
$return['productCodes'][] = $xpath->evaluate('string(ec2:productCode/text())', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets an attribute of an AMI to its default value. The productCodes attribute cannot be reset
|
||||
*
|
||||
* @param string $imageId ID of the AMI for which an attribute will be reset.
|
||||
* @param String $attribute Specifies the attribute to reset. Currently, only launchPermission is supported.
|
||||
* In the case of launchPermission, all public and explicit launch permissions for
|
||||
* the AMI are revoked.
|
||||
* @return boolean
|
||||
*/
|
||||
public function resetAttribute($imageId, $attribute)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ResetImageAttribute';
|
||||
$params['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
}
|
444
libs/Zend/Service/Amazon/Ec2/Instance.php
Normal file
444
libs/Zend/Service/Amazon/Ec2/Instance.php
Normal file
@ -0,0 +1,444 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Constant for Small Instance TYpe
|
||||
*/
|
||||
const SMALL = 'm1.small';
|
||||
|
||||
/**
|
||||
* Constant for Large Instance TYpe
|
||||
*/
|
||||
const LARGE = 'm1.large';
|
||||
|
||||
/**
|
||||
* Constant for X-Large Instance TYpe
|
||||
*/
|
||||
const XLARGE = 'm1.xlarge';
|
||||
|
||||
/**
|
||||
* Constant for High CPU Medium Instance TYpe
|
||||
*/
|
||||
const HCPU_MEDIUM = 'c1.medium';
|
||||
|
||||
/**
|
||||
* Constant for High CPU X-Large Instance TYpe
|
||||
*/
|
||||
const HCPU_XLARGE = 'c1.xlarge';
|
||||
|
||||
|
||||
/**
|
||||
* Launches a specified number of Instances.
|
||||
*
|
||||
* If Amazon EC2 cannot launch the minimum number AMIs you request, no
|
||||
* instances launch. If there is insufficient capacity to launch the
|
||||
* maximum number of AMIs you request, Amazon EC2 launches as many
|
||||
* as possible to satisfy the requested maximum values.
|
||||
*
|
||||
* Every instance is launched in a security group. If you do not specify
|
||||
* a security group at launch, the instances start in your default security group.
|
||||
* For more information on creating security groups, see CreateSecurityGroup.
|
||||
*
|
||||
* An optional instance type can be specified. For information
|
||||
* about instance types, see Instance Types.
|
||||
*
|
||||
* You can provide an optional key pair ID for each image in the launch request
|
||||
* (for more information, see CreateKeyPair). All instances that are created
|
||||
* from images that use this key pair will have access to the associated public
|
||||
* key at boot. You can use this key to provide secure access to an instance of an
|
||||
* image on a per-instance basis. Amazon EC2 public images use this feature to
|
||||
* provide secure access without passwords.
|
||||
*
|
||||
* Launching public images without a key pair ID will leave them inaccessible.
|
||||
*
|
||||
* @param array $options An array that contins the options to start an instance.
|
||||
* Required Values:
|
||||
* imageId string ID of the AMI with which to launch instances.
|
||||
* Optional Values:
|
||||
* minCount integer Minimum number of instances to launch.
|
||||
* maxCount integer Maximum number of instances to launch.
|
||||
* keyName string Name of the key pair with which to launch instances.
|
||||
* securityGruop string|array Names of the security groups with which to associate the instances.
|
||||
* userData string The user data available to the launched instances. This should not be Base64 encoded.
|
||||
* instanceType constant Specifies the instance type.
|
||||
* placement string Specifies the availability zone in which to launch the instance(s). By default, Amazon EC2 selects an availability zone for you.
|
||||
* kernelId string The ID of the kernel with which to launch the instance.
|
||||
* ramdiskId string The ID of the RAM disk with which to launch the instance.
|
||||
* blockDeviceVirtualName string Specifies the virtual name to map to the corresponding device name. For example: instancestore0
|
||||
* blockDeviceName string Specifies the device to which you are mapping a virtual name. For example: sdb
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $options)
|
||||
{
|
||||
$_defaultOptions = array(
|
||||
'minCount' => 1,
|
||||
'maxCount' => 1,
|
||||
'instanceType' => Zend_Service_Amazon_Ec2_Instance::SMALL
|
||||
);
|
||||
|
||||
// set / override the defualt optoins if they are not passed into the array;
|
||||
$options = array_merge($_defaultOptions, $options);
|
||||
|
||||
if(!isset($options['imageId'])) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('No Image Id Provided');
|
||||
}
|
||||
|
||||
|
||||
$params = array();
|
||||
$params['Action'] = 'RunInstances';
|
||||
$params['ImageId'] = $options['imageId'];
|
||||
$params['MinCount'] = $options['minCount'];
|
||||
$params['MaxCount'] = $options['maxCount'];
|
||||
|
||||
if(isset($options['keyName'])) {
|
||||
$params['KeyName'] = $options['keyName'];
|
||||
}
|
||||
|
||||
if(is_array($options['securityGroup']) && !empty($options['securityGroup'])) {
|
||||
foreach($options['securityGroup'] as $k=>$name) {
|
||||
$params['SecurityGroup.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif(isset($options['securityGroup'])) {
|
||||
$params['SecurityGroup.1'] = $options['securityGroup'];
|
||||
}
|
||||
|
||||
if(isset($options['userData'])) {
|
||||
$params['UserData'] = base64_encode($options['userData']);
|
||||
}
|
||||
|
||||
if(isset($options['instanceType'])) {
|
||||
$params['InstanceType'] = $options['instanceType'];
|
||||
}
|
||||
|
||||
if(isset($options['placement'])) {
|
||||
$params['Placement.AvailabilityZone'] = $options['placement'];
|
||||
}
|
||||
|
||||
if(isset($options['kernelId'])) {
|
||||
$params['KernelId'] = $options['kernelId'];
|
||||
}
|
||||
|
||||
if(isset($options['ramdiskId'])) {
|
||||
$params['RamdiskId'] = $options['ramdiskId'];
|
||||
}
|
||||
|
||||
if(isset($options['blockDeviceVirtualName']) && isset($options['blockDeviceName'])) {
|
||||
$params['BlockDeviceMapping.n.VirtualName'] = $options['blockDeviceVirtualName'];
|
||||
$params['BlockDeviceMapping.n.DeviceName'] = $options['blockDeviceName'];
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$return['reservationId'] = $xpath->evaluate('string(//ec2:reservationId/text())');
|
||||
$return['ownerId'] = $xpath->evaluate('string(//ec2:ownerId/text())');
|
||||
|
||||
$gs = $xpath->query('//ec2:groupSet/ec2:item');
|
||||
foreach($gs as $gs_node) {
|
||||
$return['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
unset($gs_node);
|
||||
}
|
||||
unset($gs);
|
||||
|
||||
$is = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
foreach($is as $is_node) {
|
||||
$item = array();
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $is_node);
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $is_node);
|
||||
$item['instanceState']['code'] = $xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node);
|
||||
$item['instanceState']['name'] = $xpath->evaluate('string(ec2:instanceState/ec2:name/text())', $is_node);
|
||||
$item['privateDnsName'] = $xpath->evaluate('string(ec2:privateDnsName/text())', $is_node);
|
||||
$item['dnsName'] = $xpath->evaluate('string(ec2:dnsName/text())', $is_node);
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $is_node);
|
||||
$item['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $is_node);
|
||||
$item['amiLaunchIndex'] = $xpath->evaluate('string(ec2:amiLaunchIndex/text())', $is_node);
|
||||
$item['launchTime'] = $xpath->evaluate('string(ec2:launchTime/text())', $is_node);
|
||||
$item['availabilityZone'] = $xpath->evaluate('string(ec2:placement/ec2:availabilityZone/text())', $is_node);
|
||||
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is_node);
|
||||
}
|
||||
unset($is);
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about instances that you own.
|
||||
*
|
||||
* If you specify one or more instance IDs, Amazon EC2 returns information
|
||||
* for those instances. If you do not specify instance IDs, Amazon EC2
|
||||
* returns information for all relevant instances. If you specify an invalid
|
||||
* instance ID, a fault is returned. If you specify an instance that you do
|
||||
* not own, it will not be included in the returned results.
|
||||
*
|
||||
* Recently terminated instances might appear in the returned results.
|
||||
* This interval is usually less than one hour.
|
||||
*
|
||||
* @param string|array $instaceId Set of instances IDs of which to get the status.
|
||||
* @param boolean Ture to ignore Terminated Instances.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($instanceId = null, $ignoreTerminated = false)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:reservationSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach($nodes as $node) {
|
||||
$return['reservationId'] = $xpath->evaluate('string(ec2:reservationId/text())', $node);
|
||||
$return['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
|
||||
$gs = $xpath->query('ec2:groupSet/ec2:item', $node);
|
||||
foreach($gs as $gs_node) {
|
||||
$return['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
unset($gs_node);
|
||||
}
|
||||
unset($gs);
|
||||
|
||||
$is = $xpath->query('ec2:instancesSet/ec2:item', $node);
|
||||
$return['instances'] = array();
|
||||
foreach($is as $is_node) {
|
||||
if($xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node) == 48 && $ignoreTerminated) continue;
|
||||
|
||||
$item = array();
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $is_node);
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $is_node);
|
||||
$item['instanceState']['code'] = $xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node);
|
||||
$item['instanceState']['name'] = $xpath->evaluate('string(ec2:instanceState/ec2:name/text())', $is_node);
|
||||
$item['privateDnsName'] = $xpath->evaluate('string(ec2:privateDnsName/text())', $is_node);
|
||||
$item['dnsName'] = $xpath->evaluate('string(ec2:dnsName/text())', $is_node);
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $is_node);
|
||||
$item['productCode'] = $xpath->evaluate('string(ec2:productCodesSet/ec2:item/ec2:productCode/text())', $is_node);
|
||||
$item['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $is_node);
|
||||
$item['launchTime'] = $xpath->evaluate('string(ec2:launchTime/text())', $is_node);
|
||||
$item['availabilityZone'] = $xpath->evaluate('string(ec2:placement/ec2:availabilityZone/text())', $is_node);
|
||||
$item['kernelId'] = $xpath->evaluate('string(ec2:kernelId/text())', $is_node);
|
||||
$item['ramediskId'] = $xpath->evaluate('string(ec2:ramediskId/text())', $is_node);
|
||||
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is_node);
|
||||
}
|
||||
unset($is);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about instances that you own that were started from
|
||||
* a specific imageId
|
||||
*
|
||||
* Recently terminated instances might appear in the returned results.
|
||||
* This interval is usually less than one hour.
|
||||
*
|
||||
* @param string $imageId The imageId used to start the Instance.
|
||||
* @param boolean Ture to ignore Terminated Instances.
|
||||
* @return array
|
||||
*/
|
||||
public function describeByImageId($imageId, $ignoreTerminated = false)
|
||||
{
|
||||
$arrInstances = $this->describe(null, $ignoreTerminated);
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach($arrInstances['instances'] as $k => $instance) {
|
||||
if($instance['imageId'] !== $imageId) continue;
|
||||
$instance['groupSet'] = $arrInstances['groupSet'][$k];
|
||||
$return[] = $instance;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down one or more instances. This operation is idempotent; if you terminate
|
||||
* an instance more than once, each call will succeed.
|
||||
*
|
||||
* Terminated instances will remain visible after termination (approximately one hour).
|
||||
*
|
||||
* @param string|array $instanceId One or more instance IDs returned.
|
||||
* @return array
|
||||
*/
|
||||
public function terminate($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'TerminateInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node);
|
||||
$item['shutdownState']['code'] = $xpath->evaluate('string(ec2:shutdownState/ec2:code/text())', $node);
|
||||
$item['shutdownState']['name'] = $xpath->evaluate('string(ec2:shutdownState/ec2:name/text())', $node);
|
||||
$item['previousState']['code'] = $xpath->evaluate('string(ec2:previousState/ec2:code/text())', $node);
|
||||
$item['previousState']['name'] = $xpath->evaluate('string(ec2:previousState/ec2:name/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a reboot of one or more instances.
|
||||
*
|
||||
* This operation is asynchronous; it only queues a request to reboot the specified instance(s). The operation
|
||||
* will succeed if the instances are valid and belong to the user. Requests to reboot terminated instances are ignored.
|
||||
*
|
||||
* @param string|array $instanceId One or more instance IDs.
|
||||
* @return boolean
|
||||
*/
|
||||
public function reboot($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RebootInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves console output for the specified instance.
|
||||
*
|
||||
* Instance console output is buffered and posted shortly after instance boot, reboot, and termination.
|
||||
* Amazon EC2 preserves the most recent 64 KB output which will be available for at least one hour after the most recent post.
|
||||
*
|
||||
* @param string $instanceId An instance ID
|
||||
* @return array
|
||||
*/
|
||||
public function consoleOutput($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'GetConsoleOutput';
|
||||
$params['InstanceId'] = $instanceId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['timestamp'] = $xpath->evaluate('string(//ec2:timestamp/text())');
|
||||
$return['output'] = base64_decode($xpath->evaluate('string(//ec2:output/text())'));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified product code is attached to the specified instance.
|
||||
* The operation returns false if the product code is not attached to the instance.
|
||||
*
|
||||
* The confirmProduct operation can only be executed by the owner of the AMI.
|
||||
* This feature is useful when an AMI owner is providing support and wants to
|
||||
* verify whether a user's instance is eligible.
|
||||
*
|
||||
* @param string $productCode The product code to confirm.
|
||||
* @param string $instanceId The instance for which to confirm the product code.
|
||||
* @return array|boolean An array if the product code is attached to the instance, false if it is not.
|
||||
*/
|
||||
public function confirmProduct($productCode, $instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ConfirmProductInstance';
|
||||
$params['ProductCode'] = $productCode;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$result = $xpath->evaluate('string(//ec2:result/text())');
|
||||
|
||||
if($result === "true") {
|
||||
$return['result'] = true;
|
||||
$return['ownerId'] = $xpath->evaluate('string(//ec2:ownerId/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
134
libs/Zend/Service/Amazon/Ec2/Keypair.php
Normal file
134
libs/Zend/Service/Amazon/Ec2/Keypair.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, delete and describe Ec2 KeyPairs.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Keypair extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new 2048 bit RSA key pair and returns a unique ID that can
|
||||
* be used to reference this key pair when launching new instances.
|
||||
*
|
||||
* @param string $keyName A unique name for the key pair.
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
* @return array
|
||||
*/
|
||||
public function create($keyName)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'CreateKeyPair';
|
||||
|
||||
if(!$keyName) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Key Name');
|
||||
}
|
||||
|
||||
$params['KeyName'] = $keyName;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['keyName'] = $xpath->evaluate('string(//ec2:keyName/text())');
|
||||
$return['keyFingerprint'] = $xpath->evaluate('string(//ec2:keyFingerprint/text())');
|
||||
$return['keyMaterial'] = $xpath->evaluate('string(//ec2:keyMaterial/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about key pairs available to you. If you specify
|
||||
* key pairs, information about those key pairs is returned. Otherwise,
|
||||
* information for all registered key pairs is returned.
|
||||
*
|
||||
* @param string|rarray $keyName Key pair IDs to describe.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($keyName = null)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'DescribeKeyPairs';
|
||||
if(is_array($keyName) && !empty($keyName)) {
|
||||
foreach($keyName as $k=>$name) {
|
||||
$params['KeyName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($keyName) {
|
||||
$params['KeyName.1'] = $keyName;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:keySet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $node);
|
||||
$item['keyFingerprint'] = $xpath->evaluate('string(ec2:keyFingerprint/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a key pair
|
||||
*
|
||||
* @param string $keyName Name of the key pair to delete.
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
* @return boolean Return true or false from the deletion.
|
||||
*/
|
||||
public function delete($keyName)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'DeleteKeyPair';
|
||||
|
||||
if(!$keyName) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Key Name');
|
||||
}
|
||||
|
||||
$params['KeyName'] = $keyName;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
}
|
73
libs/Zend/Service/Amazon/Ec2/Region.php
Normal file
73
libs/Zend/Service/Amazon/Ec2/Region.php
Normal 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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
/**
|
||||
* An Amazon EC2 interface to query which Regions your account has access to.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Region extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Describes availability zones that are currently available to the account
|
||||
* and their states.
|
||||
*
|
||||
* @param string|array $region Name of an region.
|
||||
* @return array An array that contains all the return items. Keys: regionName and regionUrl.
|
||||
*/
|
||||
public function describe($region = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeRegions';
|
||||
|
||||
if(is_array($region) && !empty($region)) {
|
||||
foreach($region as $k=>$name) {
|
||||
$params['Region.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($region) {
|
||||
$params['Region.1'] = $region;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['regionName'] = $xpath->evaluate('string(ec2:regionName/text())', $node);
|
||||
$item['regionUrl'] = $xpath->evaluate('string(ec2:regionUrl/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
139
libs/Zend/Service/Amazon/Ec2/Response.php
Normal file
139
libs/Zend/Service/Amazon/Ec2/Response.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Http/Response.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Response {
|
||||
/**
|
||||
* XML namespace used for EC2 responses.
|
||||
*/
|
||||
const XML_NAMESPACE = 'http://ec2.amazonaws.com/doc/2008-12-01/';
|
||||
|
||||
/**
|
||||
* The original HTTP response
|
||||
*
|
||||
* This contains the response body and headers.
|
||||
*
|
||||
* @var Zend_Http_Response
|
||||
*/
|
||||
private $_httpResponse = null;
|
||||
|
||||
/**
|
||||
* The response document object
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
private $_document = null;
|
||||
|
||||
/**
|
||||
* The response XPath
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
private $_xpath = null;
|
||||
|
||||
/**
|
||||
* Last error code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_errorCode = 0;
|
||||
|
||||
/**
|
||||
* Last error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_errorMessage = '';
|
||||
|
||||
/**
|
||||
* Creates a new high-level EC2 response object
|
||||
*
|
||||
* @param Zend_Http_Response $httpResponse the HTTP response.
|
||||
*/
|
||||
public function __construct(Zend_Http_Response $httpResponse)
|
||||
{
|
||||
$this->_httpResponse = $httpResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XPath object for this response
|
||||
*
|
||||
* @return DOMXPath the XPath object for response.
|
||||
*/
|
||||
public function getXPath()
|
||||
{
|
||||
if ($this->_xpath === null) {
|
||||
$document = $this->getDocument();
|
||||
if ($document === false) {
|
||||
$this->_xpath = false;
|
||||
} else {
|
||||
$this->_xpath = new DOMXPath($document);
|
||||
$this->_xpath->registerNamespace('ec2',
|
||||
self::XML_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the document object for this response
|
||||
*
|
||||
* @return DOMDocument the DOM Document for this response.
|
||||
*/
|
||||
public function getDocument()
|
||||
{
|
||||
try {
|
||||
$body = $this->_httpResponse->getBody();
|
||||
} catch (Zend_Http_Exception $e) {
|
||||
$body = false;
|
||||
}
|
||||
|
||||
if ($this->_document === null) {
|
||||
if ($body !== false) {
|
||||
// turn off libxml error handling
|
||||
$errors = libxml_use_internal_errors();
|
||||
|
||||
$this->_document = new DOMDocument();
|
||||
if (!$this->_document->loadXML($body)) {
|
||||
$this->_document = false;
|
||||
}
|
||||
|
||||
// reset libxml error handling
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($errors);
|
||||
} else {
|
||||
$this->_document = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_document;
|
||||
}
|
||||
}
|
288
libs/Zend/Service/Amazon/Ec2/Securitygroups.php
Normal file
288
libs/Zend/Service/Amazon/Ec2/Securitygroups.php
Normal file
@ -0,0 +1,288 @@
|
||||
<?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_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, delete, describe, grand and revoke sercurity permissions.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 22005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Securitygroups extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new security group.
|
||||
*
|
||||
* Every instance is launched in a security group. If no security group is specified
|
||||
* during launch, the instances are launched in the default security group. Instances
|
||||
* within the same security group have unrestricted network access to each other.
|
||||
* Instances will reject network access attempts from other instances in a different
|
||||
* security group. As the owner of instances you can grant or revoke specific permissions
|
||||
* using the {@link authorizeIp}, {@link authorizeGroup}, {@link revokeGroup} and
|
||||
* {$link revokeIp} operations.
|
||||
*
|
||||
* @param string $name Name of the new security group.
|
||||
* @param string $description Description of the new security group.
|
||||
* @return boolean
|
||||
*/
|
||||
public function create($name, $description)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateSecurityGroup';
|
||||
$params['GroupName'] = $name;
|
||||
$params['GroupDescription'] = $description;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about security groups that you own.
|
||||
*
|
||||
* If you specify security group names, information about those security group is returned.
|
||||
* Otherwise, information for all security group is returned. If you specify a group
|
||||
* that does not exist, a fault is returned.
|
||||
*
|
||||
* @param string|array $name List of security groups to describe
|
||||
* @return array
|
||||
*/
|
||||
public function describe($name = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeSecurityGroups';
|
||||
if(is_array($name) && !empty($name)) {
|
||||
foreach($name as $k=>$name) {
|
||||
$params['GroupName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($name) {
|
||||
$params['GroupName.1'] = $name;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$nodes = $xpath->query('//ec2:securityGroupInfo/ec2:item');
|
||||
|
||||
foreach($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
$item['groupName'] = $xpath->evaluate('string(ec2:groupName/text())', $node);
|
||||
$item['groupDescription'] = $xpath->evaluate('string(ec2:groupDescription/text())', $node);
|
||||
|
||||
$ip_nodes = $xpath->query('ec2:ipPermissions/ec2:item', $node);
|
||||
|
||||
foreach($ip_nodes as $ip_node) {
|
||||
$sItem = array();
|
||||
|
||||
$sItem['ipProtocol'] = $xpath->evaluate('string(ec2:ipProtocol/text())', $ip_node);
|
||||
$sItem['fromPort'] = $xpath->evaluate('string(ec2:fromPort/text())', $ip_node);
|
||||
$sItem['toPort'] = $xpath->evaluate('string(ec2:toPort/text())', $ip_node);
|
||||
$sItem['ipRanges'] = $xpath->evaluate('string(ec2:ipRanges/ec2:item/ec2:cidrIp/text())', $ip_node);
|
||||
|
||||
$item['ipPermissions'][] = $sItem;
|
||||
unset($ip_node, $sItem);
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a security group.
|
||||
*
|
||||
* If you attempt to delete a security group that contains instances, a fault is returned.
|
||||
* If you attempt to delete a security group that is referenced by another security group,
|
||||
* a fault is returned. For example, if security group B has a rule that allows access
|
||||
* from security group A, security group A cannot be deleted until the allow rule is removed.
|
||||
*
|
||||
* @param string $name Name of the security group to delete.
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete($name)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteSecurityGroup';
|
||||
$params['GroupName'] = $name;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds permissions to a security group
|
||||
*
|
||||
* Permissions are specified by the IP protocol (TCP, UDP or ICMP), the source of the request
|
||||
* (by IP range or an Amazon EC2 user-group pair), the source and destination port ranges
|
||||
* (for TCP and UDP), and the ICMP codes and types (for ICMP). When authorizing ICMP, -1
|
||||
* can be used as a wildcard in the type and code fields.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $ipProtocol IP protocol to authorize access to when operating on a CIDR IP.
|
||||
* @param integer $fromPort Bottom of port range to authorize access to when operating on a CIDR IP.
|
||||
* This contains the ICMP type if ICMP is being authorized.
|
||||
* @param integer $toPort Top of port range to authorize access to when operating on a CIDR IP.
|
||||
* This contains the ICMP code if ICMP is being authorized.
|
||||
* @param string $cidrIp CIDR IP range to authorize access to when operating on a CIDR IP.
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorizeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AuthorizeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['IpProtocol'] = $ipProtocol;
|
||||
$params['FromPort'] = $fromPort;
|
||||
$params['ToPort'] = $toPort;
|
||||
$params['CidrIp'] = $cidrIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds permissions to a security group
|
||||
*
|
||||
* When authorizing a user/group pair permission, GroupName, SourceSecurityGroupName and
|
||||
* SourceSecurityGroupOwnerId must be specified.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $groupName Name of security group to authorize access to when operating on a user/group pair.
|
||||
* @param string $ownerId Owner of security group to authorize access to when operating on a user/group pair.
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorizeGroup($name, $groupName, $ownerId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AuthorizeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['SourceSecurityGroupName'] = $groupName;
|
||||
$params['SourceSecurityGroupOwnerId'] = $ownerId;
|
||||
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes permissions from a security group. The permissions used to revoke must be specified
|
||||
* using the same values used to grant the permissions.
|
||||
*
|
||||
* Permissions are specified by the IP protocol (TCP, UDP or ICMP), the source of the request
|
||||
* (by IP range or an Amazon EC2 user-group pair), the source and destination port ranges
|
||||
* (for TCP and UDP), and the ICMP codes and types (for ICMP). When authorizing ICMP, -1
|
||||
* can be used as a wildcard in the type and code fields.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $ipProtocol IP protocol to revoke access to when operating on a CIDR IP.
|
||||
* @param integer $fromPort Bottom of port range to revoke access to when operating on a CIDR IP.
|
||||
* This contains the ICMP type if ICMP is being revoked.
|
||||
* @param integer $toPort Top of port range to revoked access to when operating on a CIDR IP.
|
||||
* This contains the ICMP code if ICMP is being revoked.
|
||||
* @param string $cidrIp CIDR IP range to revoke access to when operating on a CIDR IP.
|
||||
* @return boolean
|
||||
*/
|
||||
public function revokeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RevokeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['IpProtocol'] = $ipProtocol;
|
||||
$params['FromPort'] = $fromPort;
|
||||
$params['ToPort'] = $toPort;
|
||||
$params['CidrIp'] = $cidrIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes permissions from a security group. The permissions used to revoke must be specified
|
||||
* using the same values used to grant the permissions.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
* When revoking a user/group pair permission, GroupName, SourceSecurityGroupName and
|
||||
* SourceSecurityGroupOwnerId must be specified.
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $groupName Name of security group to revoke access to when operating on a user/group pair.
|
||||
* @param string $ownerId Owner of security group to revoke access to when operating on a user/group pair.
|
||||
* @return boolean
|
||||
*/
|
||||
public function revokeGroup($name, $groupName, $ownerId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RevokeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['SourceSecurityGroupName'] = $groupName;
|
||||
$params['SourceSecurityGroupOwnerId'] = $ownerId;
|
||||
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: EditorialReview.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: EditorialReview.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,16 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_EditorialReview
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Source;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Content;
|
||||
|
||||
/**
|
||||
* Assigns values to properties relevant to EditorialReview
|
||||
*
|
||||
|
35
libs/Zend/Service/Amazon/Exception.php
Executable file
35
libs/Zend/Service/Amazon/Exception.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?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_Service
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Service_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Exception extends Zend_Service_Exception
|
||||
{}
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Item.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Item.php 12666 2008-11-15 16:41:02Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,20 +31,80 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_Item
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ASIN;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $DetailPageURL;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $SalesRank;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $TotalReviews;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $AverageRating;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $SmallImage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $MediumImage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $LargeImage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Subjects;
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_OfferSet
|
||||
*/
|
||||
public $Offers;
|
||||
public $CustomerReviews;
|
||||
public $SimilarProducts;
|
||||
public $Accessories;
|
||||
public $Tracks;
|
||||
public $ListmaniaLists;
|
||||
public $PromotionalTag;
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_CustomerReview[]
|
||||
*/
|
||||
public $CustomerReviews = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_SimilarProducts[]
|
||||
*/
|
||||
public $SimilarProducts = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_Accessories[]
|
||||
*/
|
||||
public $Accessories = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $Tracks = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_ListmaniaLists[]
|
||||
*/
|
||||
public $ListmaniaLists = array();
|
||||
|
||||
protected $_dom;
|
||||
|
||||
@ -153,7 +213,9 @@ class Zend_Service_Amazon_Item
|
||||
if ($result->length > 1) {
|
||||
foreach ($result as $disk) {
|
||||
foreach ($xpath->query('./*/text()', $disk) as $t) {
|
||||
$this->Tracks[$disk->getAttribute('number')] = (string) $t->data;
|
||||
// TODO: For consistency in a bugfix all tracks are appended to one single array
|
||||
// Erroreous line: $this->Tracks[$disk->getAttribute('number')] = (string) $t->data;
|
||||
$this->Tracks[] = (string) $t->data;
|
||||
}
|
||||
}
|
||||
} else if ($result->length == 1) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ListmaniaList.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: ListmaniaList.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,16 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_ListmaniaList
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ListId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ListName;
|
||||
|
||||
/**
|
||||
* Assigns values to properties relevant to ListmaniaList
|
||||
*
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Offer.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Offer.php 14534 2009-03-30 11:14:53Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,46 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_Offer
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $MerchantId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $GlancePage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Condition;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $OfferListingId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Price;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $CurrencyCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Availability;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $IsEligibleForSuperSaverShipping = false;
|
||||
|
||||
/**
|
||||
* Parse the given Offer element
|
||||
*
|
||||
@ -47,7 +87,10 @@ class Zend_Service_Amazon_Offer
|
||||
$this->OfferListingId = (string) $xpath->query('./az:OfferListing/az:OfferListingId/text()', $dom)->item(0)->data;
|
||||
$this->Price = (int) $xpath->query('./az:OfferListing/az:Price/az:Amount/text()', $dom)->item(0)->data;
|
||||
$this->CurrencyCode = (string) $xpath->query('./az:OfferListing/az:Price/az:CurrencyCode/text()', $dom)->item(0)->data;
|
||||
$this->Availability = (string) $xpath->query('./az:OfferListing/az:Availability/text()', $dom)->item(0)->data;
|
||||
$availability = $xpath->query('./az:OfferListing/az:Availability/text()', $dom)->item(0);
|
||||
if($availability instanceof DOMText) {
|
||||
$this->Availability = (string) $availability->data;
|
||||
}
|
||||
$result = $xpath->query('./az:OfferListing/az:IsEligibleForSuperSaverShipping/text()', $dom);
|
||||
if ($result->length >= 1) {
|
||||
$this->IsEligibleForSuperSaverShipping = (bool) $result->item(0)->data;
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: OfferSet.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: OfferSet.php 12662 2008-11-15 15:29:58Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,51 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_OfferSet
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $LowestNewPrice;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $LowestNewPriceCurrency;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $LowestUsedPrice;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $LowestUsedPriceCurrency;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $TotalNew;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $TotalUsed;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $TotalCollectible;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $TotalRefurbished;
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_Offer[]
|
||||
*/
|
||||
public $Offers;
|
||||
|
||||
/**
|
||||
* Parse the given Offer Set Element
|
||||
*
|
||||
|
802
libs/Zend/Service/Amazon/S3.php
Executable file
802
libs/Zend/Service/Amazon/S3.php
Executable file
@ -0,0 +1,802 @@
|
||||
<?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_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2009, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: S3.php 14190 2009-02-28 04:32:18Z jplock $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Hmac
|
||||
*/
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
|
||||
/**
|
||||
* Amazon S3 PHP connection class
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
|
||||
*/
|
||||
class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
|
||||
{
|
||||
/**
|
||||
* Store for stream wrapper clients
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_wrapperClients = array();
|
||||
/**
|
||||
* Endpoint for the service
|
||||
*
|
||||
* @var Zend_Uri_Http
|
||||
*/
|
||||
protected $_endpoint;
|
||||
|
||||
const S3_ENDPOINT = 's3.amazonaws.com';
|
||||
|
||||
const S3_ACL_PRIVATE = 'private';
|
||||
const S3_ACL_PUBLIC_READ = 'public-read';
|
||||
const S3_ACL_PUBLIC_WRITE = 'public-read-write';
|
||||
const S3_ACL_AUTH_READ = 'authenticated-read';
|
||||
|
||||
const S3_REQUESTPAY_HEADER = 'x-amz-request-payer';
|
||||
const S3_ACL_HEADER = 'x-amz-acl';
|
||||
const S3_CONTENT_TYPE_HEADER = 'Content-Type';
|
||||
|
||||
/**
|
||||
* Set S3 endpoint to use
|
||||
*
|
||||
* @param string|Zend_Uri_Http $endpoint
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
if(!($endpoint instanceof Zend_Uri_Http)) {
|
||||
$endpoint = Zend_Uri::factory($endpoint);
|
||||
}
|
||||
if(!$endpoint->valid()) {
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Invalid endpoint supplied");
|
||||
}
|
||||
$this->_endpoint = $endpoint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current S3 endpoint
|
||||
*
|
||||
* @return Zend_Uri_Http
|
||||
*/
|
||||
public function getEndpoint()
|
||||
{
|
||||
return $this->_endpoint;
|
||||
}
|
||||
|
||||
public function __construct($accessKey=null, $secretKey=null, $region=null)
|
||||
{
|
||||
parent::__construct($accessKey, $secretKey, $region);
|
||||
$this->setEndpoint("http://".self::S3_ENDPOINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the bucket name is valid
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return boolean
|
||||
*/
|
||||
public function _validBucketName($bucket)
|
||||
{
|
||||
$len = strlen($bucket);
|
||||
if ($len < 3 || $len > 255) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" must be between 3 and 255 characters long");
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-z0-9\._-]/', $bucket)) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" contains invalid characters");
|
||||
}
|
||||
|
||||
if (preg_match('/(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/', $bucket)) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" cannot be an IP address");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new bucket
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return boolean
|
||||
*/
|
||||
public function createBucket($bucket, $location = null)
|
||||
{
|
||||
$this->_validBucketName($bucket);
|
||||
|
||||
if($location) {
|
||||
$data = "<CreateBucketConfiguration><LocationConstraint>$location</LocationConstraint></CreateBucketConfiguration>";
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
$response = $this->_makeRequest('PUT', $bucket, null, array(), $data);
|
||||
|
||||
return ($response->getStatus() == 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given bucket name is available
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBucketAvailable($bucket)
|
||||
{
|
||||
$response = $this->_makeRequest('HEAD', $bucket, array('max-keys'=>0));
|
||||
|
||||
return ($response->getStatus() != 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given object exists
|
||||
*
|
||||
* @param string $object
|
||||
* @return boolean
|
||||
*/
|
||||
public function isObjectAvailable($object)
|
||||
{
|
||||
$response = $this->_makeRequest('HEAD', $object);
|
||||
|
||||
return ($response->getStatus() == 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given bucket. All objects in the bucket must be removed prior
|
||||
* to removing the bucket.
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return boolean
|
||||
*/
|
||||
public function removeBucket($bucket)
|
||||
{
|
||||
$response = $this->_makeRequest('DELETE', $bucket);
|
||||
|
||||
// Look for a 204 No Content response
|
||||
return ($response->getStatus() == 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata information for a given object
|
||||
*
|
||||
* @param string $object
|
||||
* @return array|false
|
||||
*/
|
||||
public function getInfo($object)
|
||||
{
|
||||
$info = array();
|
||||
|
||||
$object = $this->_fixupObjectName($object);
|
||||
$response = $this->_makeRequest('HEAD', $object);
|
||||
|
||||
if ($response->getStatus() == 200) {
|
||||
$info['type'] = $response->getHeader('Content-type');
|
||||
$info['size'] = $response->getHeader('Content-length');
|
||||
$info['mtime'] = strtotime($response->getHeader('Last-modified'));
|
||||
$info['etag'] = $response->getHeader('ETag');
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the S3 buckets
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function getBuckets()
|
||||
{
|
||||
$response = $this->_makeRequest('GET');
|
||||
|
||||
if ($response->getStatus() != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xml = new SimpleXMLElement($response->getBody());
|
||||
|
||||
$buckets = array();
|
||||
foreach ($xml->Buckets->Bucket as $bucket) {
|
||||
$buckets[] = (string)$bucket->Name;
|
||||
}
|
||||
|
||||
return $buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all objects in the bucket.
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return boolean
|
||||
*/
|
||||
public function cleanBucket($bucket)
|
||||
{
|
||||
$objects = $this->getObjectsByBucket($bucket);
|
||||
if (!$objects) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($objects as $object) {
|
||||
$this->removeObject("$bucket/$object");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the objects in a bucket.
|
||||
*
|
||||
* Provides the list of object keys that are contained in the bucket.
|
||||
*
|
||||
* @param string $bucket
|
||||
* @return array|false
|
||||
*/
|
||||
public function getObjectsByBucket($bucket)
|
||||
{
|
||||
$response = $this->_makeRequest('GET', $bucket);
|
||||
|
||||
if ($response->getStatus() != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xml = new SimpleXMLElement($response->getBody());
|
||||
|
||||
$objects = array();
|
||||
if (isset($xml->Contents)) {
|
||||
foreach ($xml->Contents as $contents) {
|
||||
foreach ($contents->Key as $object) {
|
||||
$objects[] = (string)$object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
protected function _fixupObjectName($object)
|
||||
{
|
||||
$nameparts = explode('/', $object);
|
||||
|
||||
$this->_validBucketName($nameparts[0]);
|
||||
|
||||
$firstpart = array_shift($nameparts);
|
||||
if(count($nameparts) == 0) {
|
||||
return $firstpart;
|
||||
}
|
||||
|
||||
return $firstpart.'/'.join("/", array_map('rawurlencode',$nameparts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an object
|
||||
*
|
||||
* @param string $object
|
||||
* @param bool $paidobject This is "requestor pays" object
|
||||
* @return string|false
|
||||
*/
|
||||
public function getObject($object, $paidobject = false)
|
||||
{
|
||||
$object = $this->_fixupObjectName($object);
|
||||
if($paidobject) {
|
||||
$response = $this->_makeRequest('GET', $object, null, array(self::S3_REQUESTPAY_HEADER => "requester"));
|
||||
} else {
|
||||
$response = $this->_makeRequest('GET', $object);
|
||||
}
|
||||
|
||||
if ($response->getStatus() != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an object by a PHP string
|
||||
*
|
||||
* @param string $object Object name
|
||||
* @param string $data Object data
|
||||
* @param array $meta Metadata
|
||||
* @return boolean
|
||||
*/
|
||||
public function putObject($object, $data, $meta=null)
|
||||
{
|
||||
$object = $this->_fixupObjectName($object);
|
||||
$headers = (is_array($meta)) ? $meta : array();
|
||||
|
||||
$headers['Content-MD5'] = base64_encode(md5($data, true));
|
||||
$headers['Expect'] = '100-continue';
|
||||
|
||||
if (!isset($headers[self::S3_CONTENT_TYPE_HEADER])) {
|
||||
$headers[self::S3_CONTENT_TYPE_HEADER] = self::getMimeType($object);
|
||||
}
|
||||
|
||||
$response = $this->_makeRequest('PUT', $object, null, $headers, $data);
|
||||
|
||||
// Check the MD5 Etag returned by S3 against and MD5 of the buffer
|
||||
if ($response->getStatus() == 200) {
|
||||
// It is escaped by double quotes for some reason
|
||||
$etag = str_replace('"', '', $response->getHeader('Etag'));
|
||||
|
||||
if ($etag == md5($data)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put file to S3 as object
|
||||
*
|
||||
* @param string $path File name
|
||||
* @param string $object Object name
|
||||
* @param array $meta Metadata
|
||||
* @return boolean
|
||||
*/
|
||||
public function putFile($path, $object, $meta=null)
|
||||
{
|
||||
$data = @file_get_contents($path);
|
||||
if ($data === false) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Cannot read file $path");
|
||||
}
|
||||
|
||||
if (!is_array($meta)) {
|
||||
$meta = array();
|
||||
}
|
||||
|
||||
if (!isset($meta[self::S3_CONTENT_TYPE_HEADER])) {
|
||||
$meta[self::S3_CONTENT_TYPE_HEADER] = self::getMimeType($path);
|
||||
}
|
||||
|
||||
return $this->putObject($object, $data, $meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given object
|
||||
*
|
||||
* @param string $object
|
||||
* @return boolean
|
||||
*/
|
||||
public function removeObject($object)
|
||||
{
|
||||
$object = $this->_fixupObjectName($object);
|
||||
$response = $this->_makeRequest('DELETE', $object);
|
||||
|
||||
// Look for a 204 No Content response
|
||||
return ($response->getStatus() == 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to Amazon S3
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param string $data
|
||||
* @return Zend_Http_Response
|
||||
*/
|
||||
public function _makeRequest($method, $path='', $params=null, $headers=array(), $data=null)
|
||||
{
|
||||
$retry_count = 0;
|
||||
|
||||
if (!is_array($headers)) {
|
||||
$headers = array($headers);
|
||||
}
|
||||
|
||||
$headers['Date'] = gmdate(DATE_RFC1123, time());
|
||||
|
||||
// build the end point out
|
||||
$parts = explode('/', $path, 2);
|
||||
$endpoint = clone($this->_endpoint);
|
||||
if($parts[0]) {
|
||||
// prepend bucket name to the hostname
|
||||
$endpoint->setHost($parts[0].".".$endpoint->getHost());
|
||||
}
|
||||
if(!empty($parts[1])) {
|
||||
$endpoint->setPath('/'.$parts[1]);
|
||||
} else {
|
||||
$endpoint->setPath('/');
|
||||
if($parts[0]) {
|
||||
$path = $parts[0]."/";
|
||||
}
|
||||
}
|
||||
|
||||
self::addSignature($method, $path, $headers);
|
||||
|
||||
$client = self::getHttpClient();
|
||||
|
||||
$client->resetParameters();
|
||||
// Work around buglet in HTTP client - it doesn't clean headers
|
||||
// Remove when ZHC is fixed
|
||||
$client->setHeaders(array('Content-MD5' => null,
|
||||
'Expect' => null,
|
||||
'Range' => null,
|
||||
'x-amz-acl' => null));
|
||||
|
||||
$client->setUri($endpoint);
|
||||
$client->setHeaders($headers);
|
||||
|
||||
if (is_array($params)) {
|
||||
foreach ($params as $name=>$value) {
|
||||
$client->setParameterGet($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (($method == 'PUT') && ($data !== null)) {
|
||||
if (!isset($headers['Content-type'])) {
|
||||
$headers['Content-type'] = self::getMimeType($path);
|
||||
}
|
||||
$client->setRawData($data, $headers['Content-type']);
|
||||
}
|
||||
do {
|
||||
$retry = false;
|
||||
|
||||
$response = $client->request($method);
|
||||
$response_code = $response->getStatus();
|
||||
|
||||
// Some 5xx errors are expected, so retry automatically
|
||||
if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
|
||||
$retry = true;
|
||||
$retry_count++;
|
||||
sleep($retry_count / 4 * $retry_count);
|
||||
}
|
||||
else if ($response_code == 307) {
|
||||
// Need to redirect, new S3 endpoint given
|
||||
// This should never happen as Zend_Http_Client will redirect automatically
|
||||
}
|
||||
else if ($response_code == 100) {
|
||||
// echo 'OK to Continue';
|
||||
}
|
||||
} while ($retry);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the S3 Authorization signature to the request headers
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param array &$headers
|
||||
* @return string
|
||||
*/
|
||||
protected function addSignature($method, $path, &$headers)
|
||||
{
|
||||
if (!is_array($headers)) {
|
||||
$headers = array($headers);
|
||||
}
|
||||
|
||||
$type = $md5 = $date = '';
|
||||
|
||||
// Search for the Content-type, Content-MD5 and Date headers
|
||||
foreach ($headers as $key=>$val) {
|
||||
if (strcasecmp($key, 'content-type') == 0) {
|
||||
$type = $val;
|
||||
}
|
||||
else if (strcasecmp($key, 'content-md5') == 0) {
|
||||
$md5 = $val;
|
||||
}
|
||||
else if (strcasecmp($key, 'date') == 0) {
|
||||
$date = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have an x-amz-date header, use that instead of the normal Date
|
||||
if (isset($headers['x-amz-date']) && isset($date)) {
|
||||
$date = '';
|
||||
}
|
||||
|
||||
$sig_str = "$method\n$md5\n$type\n$date\n";
|
||||
// For x-amz- headers, combine like keys, lowercase them, sort them
|
||||
// alphabetically and remove excess spaces around values
|
||||
$amz_headers = array();
|
||||
foreach ($headers as $key=>$val) {
|
||||
$key = strtolower($key);
|
||||
if (substr($key, 0, 6) == 'x-amz-') {
|
||||
if (is_array($val)) {
|
||||
$amz_headers[$key] = $val;
|
||||
}
|
||||
else {
|
||||
$amz_headers[$key][] = preg_replace('/\s+/', ' ', $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($amz_headers)) {
|
||||
ksort($amz_headers);
|
||||
foreach ($amz_headers as $key=>$val) {
|
||||
$sig_str .= $key.':'.implode(',', $val)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
$sig_str .= '/'.parse_url($path, PHP_URL_PATH);
|
||||
if (strpos($path, '?location') !== false) {
|
||||
$sig_str .= '?location';
|
||||
}
|
||||
else if (strpos($path, '?acl') !== false) {
|
||||
$sig_str .= '?acl';
|
||||
}
|
||||
else if (strpos($path, '?torrent') !== false) {
|
||||
$sig_str .= '?torrent';
|
||||
}
|
||||
|
||||
$signature = base64_encode(Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
|
||||
$headers['Authorization'] = 'AWS '.$this->_getAccessKey().':'.$signature;
|
||||
|
||||
return $sig_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the content-type of a file based on the extension
|
||||
*
|
||||
* TODO: move this to Zend_Mime
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function getMimeType($path)
|
||||
{
|
||||
$ext = substr(strrchr($path, '.'), 1);
|
||||
|
||||
if(!$ext) {
|
||||
// shortcut
|
||||
return 'binary/octet-stream';
|
||||
}
|
||||
|
||||
switch ($ext) {
|
||||
case 'xls':
|
||||
$content_type = 'application/excel';
|
||||
break;
|
||||
case 'hqx':
|
||||
$content_type = 'application/macbinhex40';
|
||||
break;
|
||||
case 'doc':
|
||||
case 'dot':
|
||||
case 'wrd':
|
||||
$content_type = 'application/msword';
|
||||
break;
|
||||
case 'pdf':
|
||||
$content_type = 'application/pdf';
|
||||
break;
|
||||
case 'pgp':
|
||||
$content_type = 'application/pgp';
|
||||
break;
|
||||
case 'ps':
|
||||
case 'eps':
|
||||
case 'ai':
|
||||
$content_type = 'application/postscript';
|
||||
break;
|
||||
case 'ppt':
|
||||
$content_type = 'application/powerpoint';
|
||||
break;
|
||||
case 'rtf':
|
||||
$content_type = 'application/rtf';
|
||||
break;
|
||||
case 'tgz':
|
||||
case 'gtar':
|
||||
$content_type = 'application/x-gtar';
|
||||
break;
|
||||
case 'gz':
|
||||
$content_type = 'application/x-gzip';
|
||||
break;
|
||||
case 'php':
|
||||
case 'php3':
|
||||
case 'php4':
|
||||
$content_type = 'application/x-httpd-php';
|
||||
break;
|
||||
case 'js':
|
||||
$content_type = 'application/x-javascript';
|
||||
break;
|
||||
case 'ppd':
|
||||
case 'psd':
|
||||
$content_type = 'application/x-photoshop';
|
||||
break;
|
||||
case 'swf':
|
||||
case 'swc':
|
||||
case 'rf':
|
||||
$content_type = 'application/x-shockwave-flash';
|
||||
break;
|
||||
case 'tar':
|
||||
$content_type = 'application/x-tar';
|
||||
break;
|
||||
case 'zip':
|
||||
$content_type = 'application/zip';
|
||||
break;
|
||||
case 'mid':
|
||||
case 'midi':
|
||||
case 'kar':
|
||||
$content_type = 'audio/midi';
|
||||
break;
|
||||
case 'mp2':
|
||||
case 'mp3':
|
||||
case 'mpga':
|
||||
$content_type = 'audio/mpeg';
|
||||
break;
|
||||
case 'ra':
|
||||
$content_type = 'audio/x-realaudio';
|
||||
break;
|
||||
case 'wav':
|
||||
$content_type = 'audio/wav';
|
||||
break;
|
||||
case 'bmp':
|
||||
$content_type = 'image/bitmap';
|
||||
break;
|
||||
case 'gif':
|
||||
$content_type = 'image/gif';
|
||||
break;
|
||||
case 'iff':
|
||||
$content_type = 'image/iff';
|
||||
break;
|
||||
case 'jb2':
|
||||
$content_type = 'image/jb2';
|
||||
break;
|
||||
case 'jpg':
|
||||
case 'jpe':
|
||||
case 'jpeg':
|
||||
$content_type = 'image/jpeg';
|
||||
break;
|
||||
case 'jpx':
|
||||
$content_type = 'image/jpx';
|
||||
break;
|
||||
case 'png':
|
||||
$content_type = 'image/png';
|
||||
break;
|
||||
case 'tif':
|
||||
case 'tiff':
|
||||
$content_type = 'image/tiff';
|
||||
break;
|
||||
case 'wbmp':
|
||||
$content_type = 'image/vnd.wap.wbmp';
|
||||
break;
|
||||
case 'xbm':
|
||||
$content_type = 'image/xbm';
|
||||
break;
|
||||
case 'css':
|
||||
$content_type = 'text/css';
|
||||
break;
|
||||
case 'txt':
|
||||
$content_type = 'text/plain';
|
||||
break;
|
||||
case 'htm':
|
||||
case 'html':
|
||||
$content_type = 'text/html';
|
||||
break;
|
||||
case 'xml':
|
||||
$content_type = 'text/xml';
|
||||
break;
|
||||
case 'xsl':
|
||||
$content_type = 'text/xsl';
|
||||
break;
|
||||
case 'mpg':
|
||||
case 'mpe':
|
||||
case 'mpeg':
|
||||
$content_type = 'video/mpeg';
|
||||
break;
|
||||
case 'qt':
|
||||
case 'mov':
|
||||
$content_type = 'video/quicktime';
|
||||
break;
|
||||
case 'avi':
|
||||
$content_type = 'video/x-ms-video';
|
||||
break;
|
||||
case 'eml':
|
||||
$content_type = 'message/rfc822';
|
||||
break;
|
||||
default:
|
||||
$content_type = 'binary/octet-stream';
|
||||
break;
|
||||
}
|
||||
|
||||
return $content_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this object as stream wrapper client
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function registerAsClient($name)
|
||||
{
|
||||
self::$_wrapperClients[$name] = $this;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister this object as stream wrapper client
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function unregisterAsClient($name)
|
||||
{
|
||||
unset(self::$_wrapperClients[$name]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wrapper client for stream type
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public static function getWrapperClient($name)
|
||||
{
|
||||
return self::$_wrapperClients[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this object as stream wrapper
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function registerStreamWrapper($name='s3')
|
||||
{
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Stream
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Stream.php';
|
||||
|
||||
stream_register_wrapper($name, 'Zend_Service_Amazon_S3_Stream');
|
||||
$this->registerAsClient($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister this object as stream wrapper
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
public function unregisterStreamWrapper($name='s3')
|
||||
{
|
||||
stream_wrapper_unregister($name);
|
||||
$this->unregisterAsClient($name);
|
||||
}
|
||||
}
|
37
libs/Zend/Service/Amazon/S3/Exception.php
Executable file
37
libs/Zend/Service/Amazon/S3/Exception.php
Executable file
@ -0,0 +1,37 @@
|
||||
<?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_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Service_Amazon_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_S3_Exception extends Zend_Service_Amazon_Exception
|
||||
{}
|
497
libs/Zend/Service/Amazon/S3/Stream.php
Executable file
497
libs/Zend/Service/Amazon/S3/Stream.php
Executable file
@ -0,0 +1,497 @@
|
||||
<?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_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: S3.php 9786 2008-06-24 23:50:25Z jplock $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3.php';
|
||||
|
||||
/**
|
||||
* Amazon S3 PHP stream wrapper
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Amazon_S3
|
||||
* @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_S3_Stream
|
||||
{
|
||||
/**
|
||||
* @var boolean Write the buffer on fflush()?
|
||||
*/
|
||||
private $_writeBuffer = false;
|
||||
|
||||
/**
|
||||
* @var integer Current read/write position
|
||||
*/
|
||||
private $_position = 0;
|
||||
|
||||
/**
|
||||
* @var integer Total size of the object as returned by S3 (Content-length)
|
||||
*/
|
||||
private $_objectSize = 0;
|
||||
|
||||
/**
|
||||
* @var string File name to interact with
|
||||
*/
|
||||
private $_objectName = null;
|
||||
|
||||
/**
|
||||
* @var string Current read/write buffer
|
||||
*/
|
||||
private $_objectBuffer = null;
|
||||
|
||||
/**
|
||||
* @var array Available buckets
|
||||
*/
|
||||
private $_bucketList = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Service_Amazon_S3
|
||||
*/
|
||||
private $_s3 = null;
|
||||
|
||||
/**
|
||||
* Retrieve client for this stream type
|
||||
*
|
||||
* @param string $path
|
||||
* @return Zend_Service_Amazon_S3
|
||||
*/
|
||||
protected function _getS3Client($path)
|
||||
{
|
||||
if ($this->_s3 === null) {
|
||||
$url = explode(':', $path);
|
||||
|
||||
if (!$url) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Unable to parse URL $path");
|
||||
}
|
||||
|
||||
$this->_s3 = Zend_Service_Amazon_S3::getWrapperClient($url[0]);
|
||||
if (!$this->_s3) {
|
||||
/**
|
||||
* @see Zend_Service_Amazon_S3_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/S3/Exception.php';
|
||||
throw new Zend_Service_Amazon_S3_Exception("Unknown client for wrapper {$url[0]}");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_s3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract object name from URL
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function _getNamePart($path)
|
||||
{
|
||||
$url = parse_url($path);
|
||||
if ($url['host']) {
|
||||
return !empty($url['path']) ? $url['host'].$url['path'] : $url['host'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Open the stream
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $mode
|
||||
* @param integer $options
|
||||
* @param string $opened_path
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_open($path, $mode, $options, $opened_path)
|
||||
{
|
||||
$name = $this->_getNamePart($path);
|
||||
// If we open the file for writing, just return true. Create the object
|
||||
// on fflush call
|
||||
if (strpbrk($mode, 'wax')) {
|
||||
$this->_objectName = $name;
|
||||
$this->_objectBuffer = null;
|
||||
$this->_objectSize = 0;
|
||||
$this->_position = 0;
|
||||
$this->_writeBuffer = true;
|
||||
$this->_getS3Client($path);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// Otherwise, just see if the file exists or not
|
||||
$info = $this->_getS3Client($path)->getInfo($name);
|
||||
if ($info) {
|
||||
$this->_objectName = $name;
|
||||
$this->_objectBuffer = null;
|
||||
$this->_objectSize = $info['size'];
|
||||
$this->_position = 0;
|
||||
$this->_writeBuffer = false;
|
||||
$this->_getS3Client($path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the stream
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stream_close()
|
||||
{
|
||||
$this->_objectName = null;
|
||||
$this->_objectBuffer = null;
|
||||
$this->_objectSize = 0;
|
||||
$this->_position = 0;
|
||||
$this->_writeBuffer = false;
|
||||
unset($this->_s3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the stream
|
||||
*
|
||||
* @param integer $count
|
||||
* @return string
|
||||
*/
|
||||
public function stream_read($count)
|
||||
{
|
||||
if (!$this->_objectName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$range_start = $this->_position;
|
||||
$range_end = $this->_position+$count;
|
||||
|
||||
// Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
|
||||
// OR, the range end position is greater than the size of the current object
|
||||
// buffer AND if the range end position is less than or equal to the object's
|
||||
// size returned by S3
|
||||
if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {
|
||||
|
||||
$headers = array(
|
||||
'Range' => "$range_start-$range_end"
|
||||
);
|
||||
|
||||
$response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);
|
||||
|
||||
if ($response->getStatus() == 200) {
|
||||
$this->_objectBuffer .= $response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
$data = substr($this->_objectBuffer, $this->_position, $count);
|
||||
$this->_position += strlen($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to the stream
|
||||
*
|
||||
* @param string $data
|
||||
* @return integer
|
||||
*/
|
||||
public function stream_write($data)
|
||||
{
|
||||
if (!$this->_objectName) {
|
||||
return 0;
|
||||
}
|
||||
$len = strlen($data);
|
||||
$this->_objectBuffer .= $data;
|
||||
$this->_objectSize += $len;
|
||||
// TODO: handle current position for writing!
|
||||
return $len;
|
||||
}
|
||||
|
||||
/**
|
||||
* End of the stream?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_eof()
|
||||
{
|
||||
if (!$this->_objectName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ($this->_position >= $this->_objectSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the current read/write position of the stream
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function stream_tell()
|
||||
{
|
||||
return $this->_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the read/write position of the stream
|
||||
*
|
||||
* @param integer $offset
|
||||
* @param integer $whence
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_seek($offset, $whence)
|
||||
{
|
||||
if (!$this->_objectName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($whence) {
|
||||
case SEEK_CUR:
|
||||
// Set position to current location plus $offset
|
||||
$new_pos = $this->_position + $offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
// Set position to end-of-file plus $offset
|
||||
$new_pos = $this->_objectSize + $offset;
|
||||
break;
|
||||
case SEEK_SET:
|
||||
default:
|
||||
// Set position equal to $offset
|
||||
$new_pos = $offset;
|
||||
break;
|
||||
}
|
||||
$ret = ($new_pos >= 0 && $new_pos <= $this->_objectSize);
|
||||
if ($ret) {
|
||||
$this->_position = $new_pos;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush current cached stream data to storage
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_flush()
|
||||
{
|
||||
// If the stream wasn't opened for writing, just return false
|
||||
if (!$this->_writeBuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ret = $this->_s3->putObject($this->_objectName, $this->_objectBuffer);
|
||||
|
||||
$this->_objectBuffer = null;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data array of stream variables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function stream_stat()
|
||||
{
|
||||
if (!$this->_objectName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stat = array();
|
||||
$stat['dev'] = 0;
|
||||
$stat['ino'] = 0;
|
||||
$stat['mode'] = 0777;
|
||||
$stat['nlink'] = 0;
|
||||
$stat['uid'] = 0;
|
||||
$stat['gid'] = 0;
|
||||
$stat['rdev'] = 0;
|
||||
$stat['size'] = 0;
|
||||
$stat['atime'] = 0;
|
||||
$stat['mtime'] = 0;
|
||||
$stat['ctime'] = 0;
|
||||
$stat['blksize'] = 0;
|
||||
$stat['blocks'] = 0;
|
||||
|
||||
if(($slash = strchr($this->_objectName, '/')) === false || $slash == strlen($this->_objectName)-1) {
|
||||
/* bucket */
|
||||
$stat['mode'] |= 040000;
|
||||
} else {
|
||||
$stat['mode'] |= 0100000;
|
||||
}
|
||||
$info = $this->_s3->getInfo($this->_objectName);
|
||||
if (!empty($info)) {
|
||||
$stat['size'] = $info['size'];
|
||||
$stat['atime'] = time();
|
||||
$stat['mtime'] = $info['mtime'];
|
||||
}
|
||||
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to delete the item
|
||||
*
|
||||
* @param string $path
|
||||
* @return boolean
|
||||
*/
|
||||
public function unlink($path)
|
||||
{
|
||||
return $this->_getS3Client($path)->removeObject($this->_getNamePart($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to rename the item
|
||||
*
|
||||
* @param string $path_from
|
||||
* @param string $path_to
|
||||
* @return boolean False
|
||||
*/
|
||||
public function rename($path_from, $path_to)
|
||||
{
|
||||
// TODO: Renaming isn't supported, always return false
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new directory
|
||||
*
|
||||
* @param string $path
|
||||
* @param integer $mode
|
||||
* @param integer $options
|
||||
* @return boolean
|
||||
*/
|
||||
public function mkdir($path, $mode, $options)
|
||||
{
|
||||
return $this->_getS3Client($path)->createBucket(parse_url($path, PHP_URL_HOST));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a directory
|
||||
*
|
||||
* @param string $path
|
||||
* @param integer $options
|
||||
* @return boolean
|
||||
*/
|
||||
public function rmdir($path, $options)
|
||||
{
|
||||
return $this->_getS3Client($path)->removeBucket(parse_url($path, PHP_URL_HOST));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to open a directory
|
||||
*
|
||||
* @param string $path
|
||||
* @param integer $options
|
||||
* @return boolean
|
||||
*/
|
||||
public function dir_opendir($path, $options)
|
||||
{
|
||||
|
||||
if (preg_match('@^([a-z0-9+.]|-)+://$@', $path)) {
|
||||
$this->_bucketList = $this->_getS3Client($path)->getBuckets();
|
||||
}
|
||||
else {
|
||||
$url = parse_url($path);
|
||||
$this->_bucketList = $this->_getS3Client($path)->getObjectsByBucket($url["host"]);
|
||||
}
|
||||
|
||||
return ($this->_bucketList !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of URL variables
|
||||
*
|
||||
* @param string $path
|
||||
* @param integer $flags
|
||||
* @return array
|
||||
*/
|
||||
public function url_stat($path, $flags)
|
||||
{
|
||||
$stat = array();
|
||||
$stat['dev'] = 0;
|
||||
$stat['ino'] = 0;
|
||||
$stat['mode'] = 0777;
|
||||
$stat['nlink'] = 0;
|
||||
$stat['uid'] = 0;
|
||||
$stat['gid'] = 0;
|
||||
$stat['rdev'] = 0;
|
||||
$stat['size'] = 0;
|
||||
$stat['atime'] = 0;
|
||||
$stat['mtime'] = 0;
|
||||
$stat['ctime'] = 0;
|
||||
$stat['blksize'] = 0;
|
||||
$stat['blocks'] = 0;
|
||||
|
||||
$name = $this->_getNamePart($path);
|
||||
if(($slash = strchr($name, '/')) === false || $slash == strlen($name)-1) {
|
||||
/* bucket */
|
||||
$stat['mode'] |= 040000;
|
||||
} else {
|
||||
$stat['mode'] |= 0100000;
|
||||
}
|
||||
$info = $this->_getS3Client($path)->getInfo($name);
|
||||
|
||||
if (!empty($info)) {
|
||||
$stat['size'] = $info['size'];
|
||||
$stat['atime'] = time();
|
||||
$stat['mtime'] = $info['mtime'];
|
||||
}
|
||||
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next filename in the directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dir_readdir()
|
||||
{
|
||||
$object = current($this->_bucketList);
|
||||
if ($object !== false) {
|
||||
next($this->_bucketList);
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the directory pointer
|
||||
*
|
||||
* @return boolean True
|
||||
*/
|
||||
public function dir_rewinddir()
|
||||
{
|
||||
reset($this->_bucketList);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a directory
|
||||
*
|
||||
* @return boolean True
|
||||
*/
|
||||
public function dir_closedir()
|
||||
{
|
||||
$this->_bucketList = array();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Amazon
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SimilarProduct.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: SimilarProduct.php 12667 2008-11-15 16:51:39Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -31,6 +31,16 @@
|
||||
*/
|
||||
class Zend_Service_Amazon_SimilarProduct
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ASIN;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Title;
|
||||
|
||||
/**
|
||||
* Assigns values to properties relevant to SimilarProduct
|
||||
*
|
||||
@ -42,7 +52,10 @@ class Zend_Service_Amazon_SimilarProduct
|
||||
$xpath = new DOMXPath($dom->ownerDocument);
|
||||
$xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
|
||||
foreach (array('ASIN', 'Title') as $el) {
|
||||
$this->$el = (string) $xpath->query("./az:$el/text()", $dom)->item(0)->data;
|
||||
$text = $xpath->query("./az:$el/text()", $dom)->item(0);
|
||||
if($text instanceof DOMText) {
|
||||
$this->$el = (string)$text->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Audioscrobbler
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Audioscrobbler.php 9094 2008-03-30 18:36:55Z thomas $
|
||||
* @version $Id: Audioscrobbler.php 14809 2009-04-09 19:01:40Z beberlei $
|
||||
*/
|
||||
|
||||
|
||||
@ -53,22 +53,6 @@ class Zend_Service_Audioscrobbler
|
||||
*/
|
||||
protected $_params;
|
||||
|
||||
/**
|
||||
* Flag if we're doing testing or not
|
||||
*
|
||||
* @var boolean
|
||||
* @access protected
|
||||
*/
|
||||
protected $_testing;
|
||||
|
||||
/**
|
||||
* Http response used for testing purposes
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_testingResponse;
|
||||
|
||||
/**
|
||||
* Holds error information (e.g., for handling simplexml_load_string() warnings)
|
||||
*
|
||||
@ -78,33 +62,50 @@ class Zend_Service_Audioscrobbler
|
||||
protected $_error = null;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////// CORE METHODS ///////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Sets up character encoding, instantiates the HTTP client, and assigns the web service version
|
||||
* and testing parameters (if provided).
|
||||
*
|
||||
* @param boolean $testing
|
||||
* @param string $testingResponse
|
||||
* @return void
|
||||
* Sets up character encoding, instantiates the HTTP client, and assigns the web service version.
|
||||
*/
|
||||
public function __construct($testing = false, $testingResponse = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->set('version', '1.0');
|
||||
|
||||
iconv_set_encoding('output_encoding', 'UTF-8');
|
||||
iconv_set_encoding('input_encoding', 'UTF-8');
|
||||
iconv_set_encoding('internal_encoding', 'UTF-8');
|
||||
|
||||
$this->_client = new Zend_Http_Client();
|
||||
|
||||
$this->_testing = (boolean) $testing;
|
||||
$this->_testingResponse = (string) $testingResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Http Client
|
||||
*
|
||||
* @param Zend_Http_Client $client
|
||||
*/
|
||||
public function setHttpClient(Zend_Http_Client $client)
|
||||
{
|
||||
$this->_client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current http client.
|
||||
*
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
if($this->_client == null) {
|
||||
$this->lazyLoadHttpClient();
|
||||
}
|
||||
return $this->_client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy load Http Client if none is instantiated yet.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function lazyLoadHttpClient()
|
||||
{
|
||||
$this->_client = new Zend_Http_Client();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field value, or false if the named field does not exist
|
||||
@ -151,24 +152,12 @@ class Zend_Service_Audioscrobbler
|
||||
$params = (string) $params;
|
||||
|
||||
if ($params === '') {
|
||||
$this->_client->setUri("http://ws.audioscrobbler.com{$service}");
|
||||
$this->getHttpClient()->setUri("http://ws.audioscrobbler.com{$service}");
|
||||
} else {
|
||||
$this->_client->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
|
||||
$this->getHttpClient()->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
|
||||
}
|
||||
|
||||
if ($this->_testing) {
|
||||
/**
|
||||
* @see Zend_Http_Client_Adapter_Test
|
||||
*/
|
||||
require_once 'Zend/Http/Client/Adapter/Test.php';
|
||||
$adapter = new Zend_Http_Client_Adapter_Test();
|
||||
|
||||
$this->_client->setConfig(array('adapter' => $adapter));
|
||||
|
||||
$adapter->setResponse($this->_testingResponse);
|
||||
}
|
||||
|
||||
$response = $this->_client->request();
|
||||
$response = $this->getHttpClient()->request();
|
||||
$responseBody = $response->getBody();
|
||||
|
||||
if (preg_match('/No such path/', $responseBody)) {
|
||||
@ -210,12 +199,9 @@ class Zend_Service_Audioscrobbler
|
||||
return $simpleXmlElementResponse;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// USER ///////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Utility function to get Audioscrobbler profile information (eg: Name, Gender)
|
||||
*
|
||||
* @return array containing information
|
||||
*/
|
||||
public function userGetProfileInformation()
|
||||
@ -226,6 +212,7 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function get this user's 50 most played artists
|
||||
*
|
||||
* @return array containing info
|
||||
*/
|
||||
public function userGetTopArtists()
|
||||
@ -236,7 +223,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function to get this user's 50 most played albums
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopAlbums()
|
||||
{
|
||||
@ -256,7 +244,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function to get this user's 50 most used tags
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTags()
|
||||
{
|
||||
@ -266,8 +255,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns the user's top tags used most used on a specific artist
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForArtist()
|
||||
{
|
||||
@ -278,8 +267,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns this user's top tags for an album
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForAlbum()
|
||||
{
|
||||
@ -290,8 +279,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns this user's top tags for a track
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetTopTagsForTrack()
|
||||
{
|
||||
@ -302,7 +291,7 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that retrieves this user's list of friends
|
||||
* @return SimpleXML object containing result set
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetFriends()
|
||||
{
|
||||
@ -312,8 +301,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of people with similar listening preferences to this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetNeighbours()
|
||||
{
|
||||
@ -323,8 +312,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 most recent tracks played by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentTracks()
|
||||
{
|
||||
@ -334,8 +323,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 tracks most recently banned by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentBannedTracks()
|
||||
{
|
||||
@ -345,8 +334,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of the 10 tracks most recently loved by this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetRecentLovedTracks()
|
||||
{
|
||||
@ -356,9 +345,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of dates of available weekly charts for a this user
|
||||
* Should actually be named userGetWeeklyChartDateList() but we have to follow audioscrobbler's naming
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* Should actually be named userGetWeeklyChartDateList() but we have to follow audioscrobbler's naming
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyChartList()
|
||||
{
|
||||
@ -369,10 +359,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly album chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyAlbumChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -390,10 +380,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly artist chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyArtistChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -411,10 +401,10 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns weekly track chart data for this user
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @param integer $from optional UNIX timestamp for start of date range
|
||||
* @param integer $to optional UNIX timestamp for end of date range
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function userGetWeeklyTrackChart($from = NULL, $to = NULL)
|
||||
{
|
||||
@ -431,20 +421,10 @@ class Zend_Service_Audioscrobbler
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// ARTIST /////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Public functions for retrieveing artist-specific information
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of artists similiar to this artist
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetRelatedArtists()
|
||||
{
|
||||
@ -454,8 +434,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top listeners
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopFans()
|
||||
{
|
||||
@ -465,8 +445,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated tracks
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopTracks()
|
||||
{
|
||||
@ -476,8 +456,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated albums
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopAlbums()
|
||||
{
|
||||
@ -487,8 +467,8 @@ class Zend_Service_Audioscrobbler
|
||||
|
||||
/**
|
||||
* Utility function that returns a list of this artist's top-rated tags
|
||||
* @return SimpleXML object containing result set
|
||||
*
|
||||
*
|
||||
* @return SimpleXMLElement object containing result set
|
||||
*/
|
||||
public function artistGetTopTags()
|
||||
{
|
||||
@ -496,70 +476,103 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// ALBUM //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get information about an album
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function albumGetInfo()
|
||||
{
|
||||
$service = "/{$this->get('version')}/album/{$this->get('artist')}/{$this->get('album')}/info.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// TRACKS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get top fans of the current track.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function trackGetTopFans()
|
||||
{
|
||||
$service = "/{$this->get('version')}/track/{$this->get('artist')}/{$this->get('track')}/fans.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top tags of the current track.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function trackGetTopTags()
|
||||
{
|
||||
$service = "/{$this->get('version')}/track/{$this->get('artist')}/{$this->get('track')}/toptags.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// TAGS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get Top Tags.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopTags()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/toptags.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top albums by current tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopAlbums()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/topalbums.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top artists by current tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopArtists()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/topartists.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Top Tracks by currently set tag.
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function tagGetTopTracks()
|
||||
{
|
||||
$service = "/{$this->get('version')}/tag/{$this->get('tag')}/toptracks.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/////////////////////// GROUPS //////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Get weekly chart list by current set group.
|
||||
*
|
||||
* @see set()
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyChartList()
|
||||
{
|
||||
$service = "/{$this->get('version')}/group/{$this->get('group')}/weeklychartlist.xml";
|
||||
return $this->_getInfo($service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve weekly Artist Charts
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyArtistChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
|
||||
@ -575,6 +588,13 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Weekly Track Charts
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyTrackChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
if ($from != NULL && $to != NULL) {
|
||||
@ -589,6 +609,13 @@ class Zend_Service_Audioscrobbler
|
||||
return $this->_getInfo($service, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Weekly album charts.
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function groupGetWeeklyAlbumChartList($from = NULL, $to = NULL)
|
||||
{
|
||||
if ($from != NULL && $to != NULL) {
|
||||
@ -623,4 +650,32 @@ class Zend_Service_Audioscrobbler
|
||||
'errcontext' => $errcontext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Intercept for set($name, $field)
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return Zend_Service_Audioscrobbler
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if(substr($method, 0, 3) !== "set") {
|
||||
require_once "Zend/Service/Exception.php";
|
||||
throw new Zend_Service_Exception(
|
||||
"Method ".$method." does not exist in class Zend_Service_Audioscrobbler."
|
||||
);
|
||||
}
|
||||
$field = strtolower(substr($method, 3));
|
||||
|
||||
if(!is_array($args) || count($args) != 1) {
|
||||
require_once "Zend/Service/Exception.php";
|
||||
throw new Zend_Service_Exception(
|
||||
"A value is required for setting a parameter field."
|
||||
);
|
||||
}
|
||||
$this->set($field, $args[0]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Http_Client
|
||||
*/
|
||||
@ -91,7 +86,10 @@ class Zend_Service_Nirvanix
|
||||
$options['namespace'] = ucfirst($namespace);
|
||||
$options = array_merge($this->_options, $options);
|
||||
|
||||
Zend_Loader::loadClass($class);
|
||||
if (!class_exists($class)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($class);
|
||||
}
|
||||
return new $class($options);
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,12 @@
|
||||
* @subpackage Simpy
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Simpy.php 10478 2008-07-26 17:29:07Z elazar $
|
||||
* @version $Id: Simpy.php 15893 2009-06-04 23:12:54Z elazar $
|
||||
*/
|
||||
|
||||
|
||||
require_once 'Zend/Http/Client.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
@ -37,14 +39,14 @@ class Zend_Service_Simpy
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_baseUri = 'http://simpy.com';
|
||||
protected $_baseUri = 'http://simpy.com/simpy/api/rest/';
|
||||
|
||||
/**
|
||||
* Zend_Service_Rest object
|
||||
* HTTP client for use in making web service calls
|
||||
*
|
||||
* @var Zend_Service_Rest
|
||||
* @var Zend_Http_Client
|
||||
*/
|
||||
protected $_rest;
|
||||
protected $_http;
|
||||
|
||||
/**
|
||||
* Constructs a new Simpy (free) REST API Client
|
||||
@ -59,17 +61,27 @@ class Zend_Service_Simpy
|
||||
* @see Zend_Service_Rest
|
||||
*/
|
||||
require_once 'Zend/Rest/Client.php';
|
||||
$this->_rest = new Zend_Rest_Client($this->_baseUri);
|
||||
$this->_rest->getHttpClient()
|
||||
->setAuth($username, $password);
|
||||
$this->_http = new Zend_Http_Client;
|
||||
$this->_http->setAuth($username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP client currently in use by this class for REST API
|
||||
* calls, intended mainly for testing.
|
||||
*
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
return $this->_http;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the REST API service and does initial processing
|
||||
* on the response.
|
||||
*
|
||||
* @param string $op Name of the operation for the request
|
||||
* @param string|array $query Query data for the request (optional)
|
||||
* @param string $op Name of the operation for the request
|
||||
* @param array $query Query data for the request (optional)
|
||||
* @throws Zend_Service_Exception
|
||||
* @return DOMDocument Parsed XML response
|
||||
*/
|
||||
@ -77,9 +89,11 @@ class Zend_Service_Simpy
|
||||
{
|
||||
if ($query != null) {
|
||||
$query = array_diff($query, array_filter($query, 'is_null'));
|
||||
$query = '?' . http_build_query($query);
|
||||
}
|
||||
|
||||
$response = $this->_rest->restGet('/simpy/api/rest/' . $op . '.do', $query);
|
||||
$this->_http->setUri($this->_baseUri . $op . '.do' . $query);
|
||||
$response = $this->_http->request('GET');
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$doc = new DOMDocument();
|
||||
@ -108,7 +122,7 @@ class Zend_Service_Simpy
|
||||
* @see Zend_Service_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Exception.php';
|
||||
throw new Zend_Service_Exception('HTTP ' . $response->getStatus());
|
||||
throw new Zend_Service_Exception($response->getMessage(), $response->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Simpy
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Watchlist.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Watchlist.php 13522 2009-01-06 16:35:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ class Zend_Service_Simpy_Watchlist
|
||||
$this->_filters = new Zend_Service_Simpy_WatchlistFilterSet();
|
||||
|
||||
$childNode = $node->firstChild;
|
||||
while (is_null($childNode) == false) {
|
||||
while ($childNode !== null) {
|
||||
if ($childNode->nodeName == 'user') {
|
||||
$this->_users[] = $childNode->attributes->getNamedItem('username')->nodeValue;
|
||||
} elseif ($childNode->nodeName == 'filter') {
|
||||
|
@ -17,7 +17,7 @@
|
||||
* @subpackage SlideShare
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SlideShare.php 9094 2008-03-30 18:36:55Z thomas $
|
||||
* @version $Id: SlideShare.php 13522 2009-01-06 16:35:55Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -30,11 +30,6 @@ require_once 'Zend/Http/Client.php';
|
||||
*/
|
||||
require_once 'Zend/Cache.php';
|
||||
|
||||
/**
|
||||
* Zend_Service_SlideShare_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Service_SlideShare_SlideShow
|
||||
*/
|
||||
@ -328,6 +323,7 @@ class Zend_Service_SlideShare
|
||||
$filename = $ss->getFilename();
|
||||
|
||||
if(!file_exists($filename) || !is_readable($filename)) {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Specified Slideshow for upload not found or unreadable");
|
||||
}
|
||||
|
||||
@ -353,9 +349,11 @@ class Zend_Service_SlideShare
|
||||
$client->setParameterPost($params);
|
||||
$client->setFileUpload($filename, "slideshow_srcfile");
|
||||
|
||||
require_once 'Zend/Http/Client/Exception.php';
|
||||
try {
|
||||
$response = $client->request('POST');
|
||||
} catch(Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Service Request Failed: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
@ -364,10 +362,12 @@ class Zend_Service_SlideShare
|
||||
if($sxe->getName() == "SlideShareServiceError") {
|
||||
$message = (string)$sxe->Message[0];
|
||||
list($code, $error_str) = explode(':', $message);
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception(trim($error_str), $code);
|
||||
}
|
||||
|
||||
if(!$sxe->getName() == "SlideShowUploaded") {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Unknown XML Respons Received");
|
||||
}
|
||||
|
||||
@ -401,9 +401,11 @@ class Zend_Service_SlideShare
|
||||
$client->setUri(self::SERVICE_GET_SHOW_URI);
|
||||
$client->setParameterPost($params);
|
||||
|
||||
require_once 'Zend/Http/Client/Exception.php';
|
||||
try {
|
||||
$response = $client->request('POST');
|
||||
} catch(Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Service Request Failed: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
@ -412,10 +414,12 @@ class Zend_Service_SlideShare
|
||||
if($sxe->getName() == "SlideShareServiceError") {
|
||||
$message = (string)$sxe->Message[0];
|
||||
list($code, $error_str) = explode(':', $message);
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception(trim($error_str), $code);
|
||||
}
|
||||
|
||||
if(!$sxe->getName() == 'Slideshows') {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception('Unknown XML Repsonse Received');
|
||||
}
|
||||
|
||||
@ -505,6 +509,7 @@ class Zend_Service_SlideShare
|
||||
$queryUri = self::SERVICE_GET_SHOW_BY_TAG_URI;
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Invalid SlideShare Query");
|
||||
}
|
||||
|
||||
@ -515,11 +520,11 @@ class Zend_Service_SlideShare
|
||||
'hash' => sha1($this->getSharedSecret().$timestamp),
|
||||
$key => $value);
|
||||
|
||||
if(!is_null($offset)) {
|
||||
if($offset !== null) {
|
||||
$params['offset'] = (int)$offset;
|
||||
}
|
||||
|
||||
if(!is_null($limit)) {
|
||||
if($limit !== null) {
|
||||
$params['limit'] = (int)$limit;
|
||||
}
|
||||
|
||||
@ -534,9 +539,11 @@ class Zend_Service_SlideShare
|
||||
$client->setUri($queryUri);
|
||||
$client->setParameterPost($params);
|
||||
|
||||
require_once 'Zend/Http/Client/Exception.php';
|
||||
try {
|
||||
$response = $client->request('POST');
|
||||
} catch(Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Service Request Failed: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
@ -545,10 +552,12 @@ class Zend_Service_SlideShare
|
||||
if($sxe->getName() == "SlideShareServiceError") {
|
||||
$message = (string)$sxe->Message[0];
|
||||
list($code, $error_str) = explode(':', $message);
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception(trim($error_str), $code);
|
||||
}
|
||||
|
||||
if(!$sxe->getName() == $responseTag) {
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception('Unknown or Invalid XML Repsonse Received');
|
||||
}
|
||||
|
||||
@ -604,6 +613,7 @@ class Zend_Service_SlideShare
|
||||
|
||||
}
|
||||
|
||||
require_once 'Zend/Service/SlideShare/Exception.php';
|
||||
throw new Zend_Service_SlideShare_Exception("Was not provided the expected XML Node for processing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,16 +17,10 @@
|
||||
* @subpackage StrikeIron
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: StrikeIron.php 8539 2008-03-04 20:29:55Z darby $
|
||||
* @version $Id: StrikeIron.php 15577 2009-05-14 12:43:34Z matthew $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
|
||||
/**
|
||||
* This class allows StrikeIron authentication credentials to be specified
|
||||
* in one place and provides a factory for returning instances of different
|
||||
@ -74,7 +68,10 @@ class Zend_Service_StrikeIron
|
||||
}
|
||||
|
||||
try {
|
||||
@Zend_Loader::loadClass($class);
|
||||
if (!class_exists($class)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
@Zend_Loader::loadClass($class);
|
||||
}
|
||||
if (!class_exists($class, false)) {
|
||||
throw new Exception('Class file not found');
|
||||
}
|
||||
|
@ -18,17 +18,17 @@
|
||||
* @subpackage Technorati
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Technorati.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Technorati.php 13522 2009-01-06 16:35:55Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Service_Technorati provides an easy, intuitive and object-oriented interface
|
||||
* for using the Technorati API.
|
||||
*
|
||||
* It provides access to all available Technorati API queries
|
||||
* Zend_Service_Technorati provides an easy, intuitive and object-oriented interface
|
||||
* for using the Technorati API.
|
||||
*
|
||||
* It provides access to all available Technorati API queries
|
||||
* and returns the original XML response as a friendly PHP object.
|
||||
*
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service
|
||||
* @subpackage Technorati
|
||||
@ -39,7 +39,7 @@ class Zend_Service_Technorati
|
||||
{
|
||||
/** Base Technorati API URI */
|
||||
const API_URI_BASE = 'http://api.technorati.com';
|
||||
|
||||
|
||||
/** Query paths */
|
||||
const API_PATH_COSMOS = '/cosmos';
|
||||
const API_PATH_SEARCH = '/search';
|
||||
@ -50,7 +50,7 @@ class Zend_Service_Technorati
|
||||
const API_PATH_BLOGPOSTTAGS = '/blogposttags';
|
||||
const API_PATH_GETINFO = '/getinfo';
|
||||
const API_PATH_KEYINFO = '/keyinfo';
|
||||
|
||||
|
||||
/** Prevent magic numbers */
|
||||
const PARAM_LIMIT_MIN_VALUE = 1;
|
||||
const PARAM_LIMIT_MAX_VALUE = 100;
|
||||
@ -94,7 +94,7 @@ class Zend_Service_Technorati
|
||||
|
||||
/**
|
||||
* Cosmos query lets you see what blogs are linking to a given URL.
|
||||
*
|
||||
*
|
||||
* On the Technorati site, you can enter a URL in the searchbox and
|
||||
* it will return a list of blogs linking to it.
|
||||
* The API version allows more features and gives you a way
|
||||
@ -131,7 +131,7 @@ class Zend_Service_Technorati
|
||||
* highlights the citation of the given URL within the weblog excerpt.
|
||||
* Set this parameter to FALSE to apply no special markup to the blog excerpt.
|
||||
* Internally the value is converted in (int).
|
||||
*
|
||||
*
|
||||
* @param string $url the URL you are searching for. Prefixes http:// and www. are optional.
|
||||
* @param array $options additional parameters to refine your query
|
||||
* @return Zend_Service_Technorati_CosmosResultSet
|
||||
@ -156,8 +156,8 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_COSMOS, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Technorati_CosmosResultSet
|
||||
/**
|
||||
* @see Zend_Service_Technorati_CosmosResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/CosmosResultSet.php';
|
||||
return new Zend_Service_Technorati_CosmosResultSet($dom, $options);
|
||||
@ -169,14 +169,14 @@ class Zend_Service_Technorati
|
||||
* Query options include:
|
||||
*
|
||||
* 'language' => (string)
|
||||
* optional - a ISO 639-1 two character language code
|
||||
* to retrieve results specific to that language.
|
||||
* optional - a ISO 639-1 two character language code
|
||||
* to retrieve results specific to that language.
|
||||
* This feature is currently beta and may not work for all languages.
|
||||
* 'authority' => (n|a1|a4|a7)
|
||||
* optional - filter results to those from blogs with at least
|
||||
* the Technorati Authority specified.
|
||||
* Technorati calculates a blog's authority by how many people link to it.
|
||||
* Filtering by authority is a good way to refine your search results.
|
||||
* optional - filter results to those from blogs with at least
|
||||
* the Technorati Authority specified.
|
||||
* Technorati calculates a blog's authority by how many people link to it.
|
||||
* Filtering by authority is a good way to refine your search results.
|
||||
* There are four settings:
|
||||
* - n => Any authority: All results.
|
||||
* - a1 => A little authority: Results from blogs with at least one link.
|
||||
@ -197,7 +197,7 @@ class Zend_Service_Technorati
|
||||
* in the result set when a weblog in your result set
|
||||
* has been successfully claimed by a member of Technorati.
|
||||
* Internally the value is converted in (int).
|
||||
*
|
||||
*
|
||||
* @param string $query the words you are searching for.
|
||||
* @param array $options additional parameters to refine your query
|
||||
* @return Zend_Service_Technorati_SearchResultSet
|
||||
@ -218,7 +218,7 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_SEARCH, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_SearchResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/SearchResultSet.php';
|
||||
@ -229,7 +229,7 @@ class Zend_Service_Technorati
|
||||
* Tag lets you see what posts are associated with a given tag.
|
||||
*
|
||||
* Query options include:
|
||||
*
|
||||
*
|
||||
* 'limit' => (int)
|
||||
* optional - adjust the size of your result from the default value of 20
|
||||
* to between 1 and 100 results.
|
||||
@ -239,12 +239,12 @@ class Zend_Service_Technorati
|
||||
* the portion of Technorati's total result set ranging from start to start+limit.
|
||||
* The default start value is 1.
|
||||
* 'excerptsize' => (int)
|
||||
* optional - number of word characters to include in the post excerpts.
|
||||
* optional - number of word characters to include in the post excerpts.
|
||||
* By default 100 word characters are returned.
|
||||
* 'topexcerptsize' => (int)
|
||||
* optional - number of word characters to include in the first post excerpt.
|
||||
* optional - number of word characters to include in the first post excerpt.
|
||||
* By default 150 word characters are returned.
|
||||
*
|
||||
*
|
||||
* @param string $tag the tag term you are searching posts for.
|
||||
* @param array $options additional parameters to refine your query
|
||||
* @return Zend_Service_Technorati_TagResultSet
|
||||
@ -266,7 +266,7 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_TAG, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_TagResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/TagResultSet.php';
|
||||
@ -279,10 +279,10 @@ class Zend_Service_Technorati
|
||||
* Query options include:
|
||||
*
|
||||
* 'days' => (int)
|
||||
* optional - Used to specify the number of days in the past
|
||||
* to request daily count data for.
|
||||
* optional - Used to specify the number of days in the past
|
||||
* to request daily count data for.
|
||||
* Can be any integer between 1 and 180, default is 180
|
||||
*
|
||||
*
|
||||
* @param string $q the keyword query
|
||||
* @param array $options additional parameters to refine your query
|
||||
* @return Zend_Service_Technorati_DailyCountsResultSet
|
||||
@ -302,13 +302,13 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_DAILYCOUNTS, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_DailyCountsResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/DailyCountsResultSet.php';
|
||||
return new Zend_Service_Technorati_DailyCountsResultSet($dom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TopTags provides information on top tags indexed by Technorati.
|
||||
*
|
||||
@ -322,7 +322,7 @@ class Zend_Service_Technorati
|
||||
* Set this number to larger than zero and you will receive
|
||||
* the portion of Technorati's total result set ranging from start to start+limit.
|
||||
* The default start value is 1.
|
||||
*
|
||||
*
|
||||
* @param array $options additional parameters to refine your query
|
||||
* @return Zend_Service_Technorati_TagsResultSet
|
||||
* @throws Zend_Service_Technorati_Exception
|
||||
@ -340,7 +340,7 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_TOPTAGS, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_TagsResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/TagsResultSet.php';
|
||||
@ -369,13 +369,13 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_BLOGINFO, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_BlogInfoResult
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/BlogInfoResult.php';
|
||||
return new Zend_Service_Technorati_BlogInfoResult($dom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BlogPostTags provides information on the top tags used by a specific blog.
|
||||
*
|
||||
@ -390,7 +390,7 @@ class Zend_Service_Technorati
|
||||
* the portion of Technorati's total result set ranging from start to start+limit.
|
||||
* The default start value is 1.
|
||||
* Note. This property is not documented.
|
||||
*
|
||||
*
|
||||
* @param string $url the URL you are searching for. Prefixes http:// and www. are optional.
|
||||
* The URL must be recognized by Technorati as a blog.
|
||||
* @param array $options additional parameters to refine your query
|
||||
@ -412,21 +412,21 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_BLOGPOSTTAGS, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_TagsResultSet
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/TagsResultSet.php';
|
||||
return new Zend_Service_Technorati_TagsResultSet($dom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GetInfo query tells you things that Technorati knows about a member.
|
||||
*
|
||||
* The returned info is broken up into two sections:
|
||||
* The first part describes some information that the user wants
|
||||
* to allow people to know about him- or herself.
|
||||
* The second part of the document is a listing of the weblogs
|
||||
* that the user has successfully claimed and the information
|
||||
*
|
||||
* The returned info is broken up into two sections:
|
||||
* The first part describes some information that the user wants
|
||||
* to allow people to know about him- or herself.
|
||||
* The second part of the document is a listing of the weblogs
|
||||
* that the user has successfully claimed and the information
|
||||
* that Technorati knows about these weblogs.
|
||||
*
|
||||
* @param string $username the Technorati user name you are searching for
|
||||
@ -435,7 +435,7 @@ class Zend_Service_Technorati
|
||||
* @throws Zend_Service_Technorati_Exception
|
||||
* @link http://technorati.com/developers/api/getinfo.html Technorati API: GetInfo reference
|
||||
*/
|
||||
public function getInfo($username, $options = null)
|
||||
public function getInfo($username, $options = null)
|
||||
{
|
||||
static $defaultOptions = array('format' => 'xml');
|
||||
|
||||
@ -446,19 +446,19 @@ class Zend_Service_Technorati
|
||||
$response = $this->_makeRequest(self::API_PATH_GETINFO, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_GetInfoResult
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/GetInfoResult.php';
|
||||
return new Zend_Service_Technorati_GetInfoResult($dom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* KeyInfo query provides information on daily usage of an API key.
|
||||
* KeyInfo query provides information on daily usage of an API key.
|
||||
* Key Info Queries do not count against a key's daily query limit.
|
||||
*
|
||||
*
|
||||
* A day is defined as 00:00-23:59 Pacific time.
|
||||
*
|
||||
*
|
||||
* @return Zend_Service_Technorati_KeyInfoResult
|
||||
* @throws Zend_Service_Technorati_Exception
|
||||
* @link http://developers.technorati.com/wiki/KeyInfo Technorati API: Key Info reference
|
||||
@ -469,15 +469,15 @@ class Zend_Service_Technorati
|
||||
|
||||
$options = $this->_prepareOptions(array(), $defaultOptions);
|
||||
// you don't need to validate this request
|
||||
// because key is the only mandatory element
|
||||
// because key is the only mandatory element
|
||||
// and it's already set in #_prepareOptions
|
||||
$response = $this->_makeRequest(self::API_PATH_KEYINFO, $options);
|
||||
$dom = $this->_convertResponseAndCheckContent($response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see Zend_Service_Technorati_KeyInfoResult
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/KeyInfoResult.php';
|
||||
require_once 'Zend/Service/Technorati/KeyInfoResult.php';
|
||||
return new Zend_Service_Technorati_KeyInfoResult($dom, $this->_apiKey);
|
||||
}
|
||||
|
||||
@ -502,7 +502,7 @@ class Zend_Service_Technorati
|
||||
*/
|
||||
public function getRestClient()
|
||||
{
|
||||
if (is_null($this->_restClient)) {
|
||||
if ($this->_restClient === null) {
|
||||
/**
|
||||
* @see Zend_Rest_Client
|
||||
*/
|
||||
@ -515,7 +515,7 @@ class Zend_Service_Technorati
|
||||
|
||||
/**
|
||||
* Sets Technorati API key.
|
||||
*
|
||||
*
|
||||
* Be aware that this function doesn't validate the key.
|
||||
* The key is validated as soon as the first API request is sent.
|
||||
* If the key is invalid, the API request method will throw
|
||||
@ -568,7 +568,7 @@ class Zend_Service_Technorati
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates Search query options.
|
||||
*
|
||||
@ -597,7 +597,7 @@ class Zend_Service_Technorati
|
||||
// Validate format (optional)
|
||||
$this->_validateOptionFormat($options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates Tag query options.
|
||||
*
|
||||
@ -627,7 +627,7 @@ class Zend_Service_Technorati
|
||||
$this->_validateOptionFormat($options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Validates DailyCounts query options.
|
||||
*
|
||||
@ -650,7 +650,7 @@ class Zend_Service_Technorati
|
||||
// Validate days (optional)
|
||||
if (isset($options['days'])) {
|
||||
$options['days'] = (int) $options['days'];
|
||||
if ($options['days'] < self::PARAM_DAYS_MIN_VALUE ||
|
||||
if ($options['days'] < self::PARAM_DAYS_MIN_VALUE ||
|
||||
$options['days'] > self::PARAM_DAYS_MAX_VALUE) {
|
||||
/**
|
||||
* @see Zend_Service_Technorati_Exception
|
||||
@ -661,7 +661,7 @@ class Zend_Service_Technorati
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates GetInfo query options.
|
||||
*
|
||||
@ -693,7 +693,7 @@ class Zend_Service_Technorati
|
||||
*/
|
||||
protected function _validateTopTags(array $options)
|
||||
{
|
||||
static $validOptions = array('key',
|
||||
static $validOptions = array('key',
|
||||
'limit', 'start', 'format');
|
||||
|
||||
// Validate keys in the $options array
|
||||
@ -705,7 +705,7 @@ class Zend_Service_Technorati
|
||||
// Validate format (optional)
|
||||
$this->_validateOptionFormat($options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates BlogInfo query options.
|
||||
*
|
||||
@ -726,7 +726,7 @@ class Zend_Service_Technorati
|
||||
// Validate format (optional)
|
||||
$this->_validateOptionFormat($options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates TopTags query options.
|
||||
*
|
||||
@ -737,7 +737,7 @@ class Zend_Service_Technorati
|
||||
*/
|
||||
protected function _validateBlogPostTags(array $options)
|
||||
{
|
||||
static $validOptions = array('key', 'url',
|
||||
static $validOptions = array('key', 'url',
|
||||
'limit', 'start', 'format');
|
||||
|
||||
// Validate keys in the $options array
|
||||
@ -773,16 +773,16 @@ class Zend_Service_Technorati
|
||||
"Invalid value '{$options[$name]}' for '$name' option");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether mandatory $name option exists and it's valid.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @throws Zend_Service_Technorati_Exception
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateMandatoryOption($name, $options)
|
||||
protected function _validateMandatoryOption($name, $options)
|
||||
{
|
||||
if (!isset($options[$name]) || !trim($options[$name])) {
|
||||
/**
|
||||
@ -793,25 +793,25 @@ class Zend_Service_Technorati
|
||||
"Empty value for '$name' option");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether $name option is a valid integer and casts it.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateIntegerOption($name, $options)
|
||||
protected function _validateIntegerOption($name, $options)
|
||||
{
|
||||
if (isset($options[$name])) {
|
||||
$options[$name] = (int) $options[$name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes and HTTP GET request to given $path with $options.
|
||||
* HTTP Response is first validated, then returned.
|
||||
*
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $options
|
||||
* @return Zend_Http_Response
|
||||
@ -828,27 +828,27 @@ class Zend_Service_Technorati
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether 'claim' option value is valid.
|
||||
*
|
||||
* Checks whether 'claim' option value is valid.
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateOptionClaim(array $options)
|
||||
protected function _validateOptionClaim(array $options)
|
||||
{
|
||||
$this->_validateIntegerOption('claim', $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether 'format' option value is valid.
|
||||
* Checks whether 'format' option value is valid.
|
||||
* Be aware that Zend_Service_Technorati supports only XML as format value.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @throws Zend_Service_Technorati_Exception if 'format' value != XML
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateOptionFormat(array $options)
|
||||
protected function _validateOptionFormat(array $options)
|
||||
{
|
||||
if (isset($options['format']) && $options['format'] != 'xml') {
|
||||
/**
|
||||
@ -860,23 +860,23 @@ class Zend_Service_Technorati
|
||||
"Zend_Service_Technorati supports only 'xml'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether 'limit' option value is valid.
|
||||
* Checks whether 'limit' option value is valid.
|
||||
* Value must be an integer greater than PARAM_LIMIT_MIN_VALUE
|
||||
* and lower than PARAM_LIMIT_MAX_VALUE.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @throws Zend_Service_Technorati_Exception if 'limit' value is invalid
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateOptionLimit(array $options)
|
||||
protected function _validateOptionLimit(array $options)
|
||||
{
|
||||
if (!isset($options['limit'])) return;
|
||||
|
||||
|
||||
$options['limit'] = (int) $options['limit'];
|
||||
if ($options['limit'] < self::PARAM_LIMIT_MIN_VALUE ||
|
||||
if ($options['limit'] < self::PARAM_LIMIT_MIN_VALUE ||
|
||||
$options['limit'] > self::PARAM_LIMIT_MAX_VALUE) {
|
||||
/**
|
||||
* @see Zend_Service_Technorati_Exception
|
||||
@ -886,20 +886,20 @@ class Zend_Service_Technorati
|
||||
"Invalid value '" . $options['limit'] . "' for 'limit' option");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether 'start' option value is valid.
|
||||
* Checks whether 'start' option value is valid.
|
||||
* Value must be an integer greater than 0.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @throws Zend_Service_Technorati_Exception if 'start' value is invalid
|
||||
* @access protected
|
||||
*/
|
||||
protected function _validateOptionStart(array $options)
|
||||
protected function _validateOptionStart(array $options)
|
||||
{
|
||||
if (!isset($options['start'])) return;
|
||||
|
||||
|
||||
$options['start'] = (int) $options['start'];
|
||||
if ($options['start'] < self::PARAM_START_MIN_VALUE) {
|
||||
/**
|
||||
@ -912,20 +912,20 @@ class Zend_Service_Technorati
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether 'url' option value exists and is valid.
|
||||
* Checks whether 'url' option value exists and is valid.
|
||||
* 'url' must be a valid HTTP(s) URL.
|
||||
*
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @throws Zend_Service_Technorati_Exception if 'url' value is invalid
|
||||
* @access protected
|
||||
* @todo support for Zend_Uri_Http
|
||||
*/
|
||||
protected function _validateOptionUrl(array $options)
|
||||
protected function _validateOptionUrl(array $options)
|
||||
{
|
||||
$this->_validateMandatoryOption('url', $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks XML response content for errors.
|
||||
*
|
||||
@ -952,7 +952,7 @@ class Zend_Service_Technorati
|
||||
|
||||
/**
|
||||
* Converts $response body to a DOM object and checks it.
|
||||
*
|
||||
*
|
||||
* @param Zend_Http_Response $response
|
||||
* @return DOMDocument
|
||||
* @throws Zend_Service_Technorati_Exception if response content contains an error message
|
||||
@ -965,7 +965,7 @@ class Zend_Service_Technorati
|
||||
self::_checkErrors($dom);
|
||||
return $dom;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks ReST response for errors.
|
||||
*
|
||||
@ -989,7 +989,7 @@ class Zend_Service_Technorati
|
||||
|
||||
/**
|
||||
* Checks whether user given options are valid.
|
||||
*
|
||||
*
|
||||
* @param array $options user options
|
||||
* @param array $validOptions valid options
|
||||
* @return void
|
||||
@ -1005,7 +1005,7 @@ class Zend_Service_Technorati
|
||||
*/
|
||||
require_once 'Zend/Service/Technorati/Exception.php';
|
||||
throw new Zend_Service_Technorati_Exception(
|
||||
"The following parameters are invalid: '" .
|
||||
"The following parameters are invalid: '" .
|
||||
implode("', '", $difference) . "'");
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Twitter
|
||||
* @subpackage RememberTheMilk
|
||||
* @package Zend_Service
|
||||
* @subpackage Twitter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: $
|
||||
@ -55,7 +55,7 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
* Date format for 'since' strings
|
||||
* @var string
|
||||
*/
|
||||
protected $_dateFormat = 'D, d M Y H:i:s e';
|
||||
protected $_dateFormat = 'D, d M Y H:i:s T';
|
||||
|
||||
/**
|
||||
* Username
|
||||
@ -251,7 +251,9 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
*
|
||||
* $params may include one or more of the following keys
|
||||
* - id: ID of a friend whose timeline you wish to receive
|
||||
* - count: how many statuses to return
|
||||
* - since: return results only after the date specified
|
||||
* - since_id: return results only after the specific tweet
|
||||
* - page: return page X of results
|
||||
*
|
||||
* @param array $params
|
||||
@ -261,20 +263,33 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
{
|
||||
$this->_init();
|
||||
$path = '/statuses/friends_timeline';
|
||||
$_params = array();
|
||||
foreach ($params as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'count':
|
||||
$count = (int) $value;
|
||||
if (0 >= $count) {
|
||||
$count = 1;
|
||||
} elseif (200 < $count) {
|
||||
$count = 200;
|
||||
}
|
||||
$_params['count'] = (int) $count;
|
||||
break;
|
||||
case 'since_id':
|
||||
$_params['since_id'] = (int) $value;
|
||||
break;
|
||||
case 'since':
|
||||
$this->_setDate($value);
|
||||
break;
|
||||
case 'page':
|
||||
$this->page = (int) $value;
|
||||
$_params['page'] = (int) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
$path .= '.xml';
|
||||
$response = $this->restGet($path);
|
||||
$response = $this->restGet($path, $_params);
|
||||
return new Zend_Rest_Client_Result($response->getBody());
|
||||
}
|
||||
|
||||
@ -349,7 +364,7 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
{
|
||||
$this->_init();
|
||||
$path = '/statuses/update.xml';
|
||||
$len = strlen($status);
|
||||
$len = iconv_strlen($status, 'UTF-8');
|
||||
if ($len > 140) {
|
||||
include_once 'Zend/Service/Twitter/Exception.php';
|
||||
throw new Zend_Service_Twitter_Exception('Status must be no more than 140 characters in length');
|
||||
@ -367,7 +382,7 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
}
|
||||
|
||||
//$this->status = $status;
|
||||
$response = $this->restPost($path, $data);
|
||||
$response = $this->restPost($path, $data);
|
||||
return new Zend_Rest_Client_Result($response->getBody());
|
||||
}
|
||||
|
||||
@ -516,22 +531,23 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
{
|
||||
$this->_init();
|
||||
$path = '/direct_messages.xml';
|
||||
$_params = array();
|
||||
foreach ($params as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'since':
|
||||
$this->_setDate($value);
|
||||
break;
|
||||
case 'since_id':
|
||||
$this->since_id = (int) $value;
|
||||
$_params['since_id'] = (int) $value;
|
||||
break;
|
||||
case 'page':
|
||||
$this->page = (int) $value;
|
||||
$_params['page'] = (int) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
$response = $this->restGet($path);
|
||||
$response = $this->restGet($path, $_params);
|
||||
return new Zend_Rest_Client_Result($response->getBody());
|
||||
}
|
||||
|
||||
@ -550,22 +566,23 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
{
|
||||
$this->_init();
|
||||
$path = '/direct_messages/sent.xml';
|
||||
$_params = array();
|
||||
foreach ($params as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'since':
|
||||
$this->_setDate($value);
|
||||
break;
|
||||
case 'since_id':
|
||||
$this->since_id = (int) $value;
|
||||
$_params['since_id'] = (int) $value;
|
||||
break;
|
||||
case 'page':
|
||||
$this->page = (int) $value;
|
||||
$_params['page'] = (int) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
$response = $this->restGet($path);
|
||||
$response = $this->restGet($path, $_params);
|
||||
return new Zend_Rest_Client_Result($response->getBody());
|
||||
}
|
||||
|
||||
@ -582,7 +599,7 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
$this->_init();
|
||||
$path = '/direct_messages/new.xml';
|
||||
|
||||
$len = strlen($text);
|
||||
$len = iconv_strlen($text, 'UTF-8');
|
||||
if (0 == $len) {
|
||||
throw new Zend_Service_Twitter_Exception('Direct message must contain at least one character');
|
||||
} elseif (140 < $len) {
|
||||
@ -683,7 +700,7 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
public function accountEndSession()
|
||||
{
|
||||
$this->_init();
|
||||
$response = $this->restGet('/account/end_session');
|
||||
$this->restGet('/account/end_session');
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -713,20 +730,21 @@ class Zend_Service_Twitter extends Zend_Rest_Client
|
||||
{
|
||||
$this->_init();
|
||||
$path = '/favorites';
|
||||
$_params = array();
|
||||
foreach ($params as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'id':
|
||||
$path .= '/' . $value;
|
||||
break;
|
||||
case 'page':
|
||||
$this->page = (int) $value;
|
||||
$_params['page'] = (int) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
$path .= '.xml';
|
||||
$response = $this->restGet($path);
|
||||
$response = $this->restGet($path, $_params);
|
||||
return new Zend_Rest_Client_Result($response->getBody());
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Twitter
|
||||
* @package Zend_Service
|
||||
* @subpackage Twitter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Yahoo
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Yahoo.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Yahoo.php 13004 2008-12-03 21:14:45Z matthew $
|
||||
*/
|
||||
|
||||
|
||||
@ -400,6 +400,7 @@ class Zend_Service_Yahoo
|
||||
* 'similar_ok' => bool permit similar results in the result set
|
||||
* 'country' => string The country code for the content searched
|
||||
* 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched
|
||||
* 'region' => The regional search engine on which the service performs the search. default us.
|
||||
*
|
||||
* @param string $query the query being run
|
||||
* @param array $options any optional parameters
|
||||
@ -803,7 +804,7 @@ class Zend_Service_Yahoo
|
||||
protected function _validateWebSearch(array $options)
|
||||
{
|
||||
$validOptions = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok',
|
||||
'similar_ok', 'country', 'site', 'subscription', 'license');
|
||||
'similar_ok', 'country', 'site', 'subscription', 'license', 'region');
|
||||
|
||||
$this->_compareOptions($options, $validOptions);
|
||||
|
||||
@ -838,6 +839,12 @@ class Zend_Service_Yahoo
|
||||
'txt', 'xls'));
|
||||
$this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial',
|
||||
'cc_modifiable'));
|
||||
if (isset($options['region'])){
|
||||
$this->_validateInArray('region', $options['region'], array('ar', 'au', 'at', 'br', 'ca', 'ct', 'dk', 'fi',
|
||||
'fr', 'de', 'in', 'id', 'it', 'my', 'mx',
|
||||
'nl', 'no', 'ph', 'ru', 'sg', 'es', 'se',
|
||||
'ch', 'th', 'uk', 'us'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
* @subpackage Yahoo
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: WebResult.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: WebResult.php 13005 2008-12-03 21:15:02Z matthew $
|
||||
*/
|
||||
|
||||
|
||||
@ -93,8 +93,17 @@ class Zend_Service_Yahoo_WebResult extends Zend_Service_Yahoo_Result
|
||||
|
||||
$this->_xpath = new DOMXPath($result->ownerDocument);
|
||||
$this->_xpath->registerNamespace('yh', $this->_namespace);
|
||||
|
||||
$this->CacheUrl = $this->_xpath->query('./yh:Cache/yh:Url/text()', $result)->item(0)->data;
|
||||
$this->CacheSize = (int) $this->_xpath->query('./yh:Cache/yh:Size/text()', $result)->item(0)->data;
|
||||
|
||||
// check if the cache section exists
|
||||
$cacheUrl = $this->_xpath->query('./yh:Cache/yh:Url/text()', $result)->item(0);
|
||||
if ($cacheUrl instanceof DOMNode)
|
||||
{
|
||||
$this->CacheUrl = $cacheUrl->data;
|
||||
}
|
||||
$cacheSize = $this->_xpath->query('./yh:Cache/yh:Size/text()', $result)->item(0);
|
||||
if ($cacheSize instanceof DOMNode)
|
||||
{
|
||||
$this->CacheSize = (int) $cacheSize->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user