Current File : /home/k/a/r/karenpetzb/www/items/category/Zend.tar |
Feed/Entry/Atom.php 0000604 00000022604 15071256134 0010125 0 ustar 00 <?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_Feed
* @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: Atom.php 10383 2008-07-24 19:46:15Z matthew $
*/
/**
* @see Zend_Feed_Entry_Abstract
*/
require_once 'Zend/Feed/Entry/Abstract.php';
/**
* Concrete class for working with Atom entries.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Entry_Atom extends Zend_Feed_Entry_Abstract
{
/**
* Root XML element for Atom entries.
*
* @var string
*/
protected $_rootElement = 'entry';
/**
* Root namespace for Atom entries.
*
* @var string
*/
protected $_rootNamespace = 'atom';
/**
* Delete an atom entry.
*
* Delete tries to delete this entry from its feed. If the entry
* does not contain a link rel="edit", we throw an error (either
* the entry does not yet exist or this is not an editable
* feed). If we have a link rel="edit", we do the empty-body
* HTTP DELETE to that URI and check for a response of 2xx.
* Usually the response would be 204 No Content, but the Atom
* Publishing Protocol permits it to be 200 OK.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function delete()
{
// Look for link rel="edit" in the entry object.
$deleteUri = $this->link('edit');
if (!$deleteUri) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot delete entry; no link rel="edit" is present.');
}
// DELETE
$client = Zend_Feed::getHttpClient();
do {
$client->setUri($deleteUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeader('X-HTTP-Method-Override', 'DELETE');
$response = $client->request('POST');
} else {
$response = $client->request('DELETE');
}
$httpStatus = $response->getStatus();
switch ((int) $httpStatus / 100) {
// Success
case 2:
return true;
// Redirect
case 3:
$deleteUri = $response->getHeader('Location');
continue;
// Error
default:
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("Expected response code 2xx, got $httpStatus");
}
} while (true);
}
/**
* Save a new or updated Atom entry.
*
* Save is used to either create new entries or to save changes to
* existing ones. If we have a link rel="edit", we are changing
* an existing entry. In this case we re-serialize the entry and
* PUT it to the edit URI, checking for a 200 OK result.
*
* For posting new entries, you must specify the $postUri
* parameter to save() to tell the object where to post itself.
* We use $postUri and POST the serialized entry there, checking
* for a 201 Created response. If the insert is successful, we
* then parse the response from the POST to get any values that
* the server has generated: an id, an updated time, and its new
* link rel="edit".
*
* @param string $postUri Location to POST for creating new entries.
* @return void
* @throws Zend_Feed_Exception
*/
public function save($postUri = null)
{
if ($this->id()) {
// If id is set, look for link rel="edit" in the
// entry object and PUT.
$editUri = $this->link('edit');
if (!$editUri) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($editUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeaders(array('X-HTTP-Method-Override: PUT',
'Content-Type: application/atom+xml'));
$client->setRawData($this->saveXML());
$response = $client->request('POST');
} else {
$client->setHeaders('Content-Type', 'application/atom+xml');
$client->setRawData($this->saveXML());
$response = $client->request('PUT');
}
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
}
} else {
if ($postUri === null) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($postUri);
$client->setRawData($this->saveXML());
$response = $client->request('POST');
if ($response->getStatus() !== 201) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 201, got '
. $response->getStatus());
}
}
// Update internal properties using $client->responseBody;
@ini_set('track_errors', 1);
$newEntry = new DOMDocument;
$status = @$newEntry->loadXML($response->getBody());
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
}
$newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
if (!$newEntry) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <feed> element found in server response:'
. "\n\n" . $client->responseBody);
}
if ($this->_element->parentNode) {
$oldElement = $this->_element;
$this->_element = $oldElement->ownerDocument->importNode($newEntry, true);
$oldElement->parentNode->replaceChild($this->_element, $oldElement);
} else {
$this->_element = $newEntry;
}
}
/**
* Easy access to <link> tags keyed by "rel" attributes.
*
* If $elt->link() is called with no arguments, we will attempt to
* return the value of the <link> tag(s) like all other
* method-syntax attribute access. If an argument is passed to
* link(), however, then we will return the "href" value of the
* first <link> tag that has a "rel" attribute matching $rel:
*
* $elt->link(): returns the value of the link tag.
* $elt->link('self'): returns the href from the first <link rel="self"> in the entry.
*
* @param string $rel The "rel" attribute to look for.
* @return mixed
*/
public function link($rel = null)
{
if ($rel === null) {
return parent::__call('link', null);
}
// index link tags by their "rel" attribute.
$links = parent::__get('link');
if (!is_array($links)) {
if ($links instanceof Zend_Feed_Element) {
$links = array($links);
} else {
return $links;
}
}
foreach ($links as $link) {
if (empty($link['rel'])) {
continue;
}
if ($rel == $link['rel']) {
return $link['href'];
}
}
return null;
}
}
Feed/Entry/Rss.php 0000604 00000007014 15071256134 0007772 0 ustar 00 <?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_Feed
* @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: Rss.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Feed_Entry_Abstract
*/
require_once 'Zend/Feed/Entry/Abstract.php';
/**
* Concrete class for working with RSS items.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Entry_Rss extends Zend_Feed_Entry_Abstract
{
/**
* Root XML element for RSS items.
*
* @var string
*/
protected $_rootElement = 'item';
/**
* Overwrites parent::_get method to enable read access
* to content:encoded element.
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'content':
$prefix = $this->_element->lookupPrefix('http://purl.org/rss/1.0/modules/content/');
return parent::__get("$prefix:encoded");
default:
return parent::__get($var);
}
}
/**
* Overwrites parent::_set method to enable write access
* to content:encoded element.
*
* @param string $var The property to change.
* @param string $val The property's new value.
* @return void
*/
public function __set($var, $value)
{
switch ($var) {
case 'content':
parent::__set('content:encoded', $value);
break;
default:
parent::__set($var, $value);
}
}
/**
* Overwrites parent::_isset method to enable access
* to content:encoded element.
*
* @param string $var
* @return boolean
*/
public function __isset($var)
{
switch ($var) {
case 'content':
// don't use other callback to prevent invalid returned value
return $this->content() !== null;
default:
return parent::__isset($var);
}
}
/**
* Overwrites parent::_call method to enable read access
* to content:encoded element.
* Please note that method-style write access is not currently supported
* by parent method, consequently this method doesn't as well.
*
* @param string $var The element to get the string value of.
* @param mixed $unused This parameter is not used.
* @return mixed The node's value, null, or an array of nodes.
*/
public function __call($var, $unused)
{
switch ($var) {
case 'content':
$prefix = $this->_element->lookupPrefix('http://purl.org/rss/1.0/modules/content/');
return parent::__call("$prefix:encoded", $unused);
default:
return parent::__call($var, $unused);
}
}
}
Feed/Entry/Abstract.php 0000604 00000010007 15071256134 0010762 0 ustar 00 <?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_Feed
* @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: Abstract.php 10383 2008-07-24 19:46:15Z matthew $
*/
/**
* @see Zend_Feed
*/
require_once 'Zend/Feed.php';
/**
* @see Zend_Feed_Element
*/
require_once 'Zend/Feed/Element.php';
/**
* Zend_Feed_Entry_Abstract represents a single entry in an Atom or RSS
* feed.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Feed_Entry_Abstract extends Zend_Feed_Element
{
/**
* Root XML element for entries. Subclasses must define this to a
* non-null value.
*
* @var string
*/
protected $_rootElement;
/**
* Root namespace for entries. Subclasses may define this to a
* non-null value.
*
* @var string
*/
protected $_rootNamespace = null;
/**
* Zend_Feed_Entry_Abstract constructor
*
* The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
* is part of, and optionally an XML construct (usually a
* SimpleXMLElement, but it can be an XML string or a DOMNode as
* well) that contains the contents of the entry.
*
* @param string $uri
* @param SimpleXMLElement|DOMNode|string $element
* @return void
* @throws Zend_Feed_Exception
*/
public function __construct($uri = null, $element = null)
{
if (!($element instanceof DOMElement)) {
if ($element) {
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$status = @$doc->loadXML($element);
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
} else {
$doc = new DOMDocument('1.0', 'utf-8');
if ($this->_rootNamespace !== null) {
$element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
} else {
$element = $doc->createElement($this->_rootElement);
}
}
}
parent::__construct($element);
}
}
Feed/Builder.php 0000604 00000043001 15071256134 0007504 0 ustar 00 <?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_Feed
* @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: Builder.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Feed_Builder_Interface
*/
require_once 'Zend/Feed/Builder/Interface.php';
/**
* @see Zend_Feed_Builder_Header
*/
require_once 'Zend/Feed/Builder/Header.php';
/**
* @see Zend_Feed_Builder_Entry
*/
require_once 'Zend/Feed/Builder/Entry.php';
/**
* A simple implementation of Zend_Feed_Builder_Interface.
*
* Users are encouraged to make their own classes to implement Zend_Feed_Builder_Interface
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Builder implements Zend_Feed_Builder_Interface
{
/**
* The data of the feed
*
* @var $_data array
*/
private $_data;
/**
* Header of the feed
*
* @var $_header Zend_Feed_Builder_Header
*/
private $_header;
/**
* List of the entries of the feed
*
* @var $_entries array
*/
private $_entries = array();
/**
* Constructor. The $data array must conform to the following format:
* <code>
* array(
* 'title' => 'title of the feed', //required
* 'link' => 'canonical url to the feed', //required
* 'lastUpdate' => 'timestamp of the update date', // optional
* 'published' => 'timestamp of the publication date', //optional
* 'charset' => 'charset', // required
* 'description' => 'short description of the feed', //optional
* 'author' => 'author/publisher of the feed', //optional
* 'email' => 'email of the author', //optional
* 'webmaster' => 'email address for person responsible for technical issues' // optional, ignored if atom is used
* 'copyright' => 'copyright notice', //optional
* 'image' => 'url to image', //optional
* 'generator' => 'generator', // optional
* 'language' => 'language the feed is written in', // optional
* 'ttl' => 'how long in minutes a feed can be cached before refreshing', // optional, ignored if atom is used
* 'rating' => 'The PICS rating for the channel.', // optional, ignored if atom is used
* 'cloud' => array(
* 'domain' => 'domain of the cloud, e.g. rpc.sys.com' // required
* 'port' => 'port to connect to' // optional, default to 80
* 'path' => 'path of the cloud, e.g. /RPC2 //required
* 'registerProcedure' => 'procedure to call, e.g. myCloud.rssPleaseNotify' // required
* 'protocol' => 'protocol to use, e.g. soap or xml-rpc' // required
* ), a cloud to be notified of updates // optional, ignored if atom is used
* 'textInput' => array(
* 'title' => 'the label of the Submit button in the text input area' // required,
* 'description' => 'explains the text input area' // required
* 'name' => 'the name of the text object in the text input area' // required
* 'link' => 'the URL of the CGI script that processes text input requests' // required
* ) // a text input box that can be displayed with the feed // optional, ignored if atom is used
* 'skipHours' => array(
* 'hour in 24 format', // e.g 13 (1pm)
* // up to 24 rows whose value is a number between 0 and 23
* ) // Hint telling aggregators which hours they can skip // optional, ignored if atom is used
* 'skipDays ' => array(
* 'a day to skip', // e.g Monday
* // up to 7 rows whose value is a Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday
* ) // Hint telling aggregators which days they can skip // optional, ignored if atom is used
* 'itunes' => array(
* 'author' => 'Artist column' // optional, default to the main author value
* 'owner' => array(
* 'name' => 'name of the owner' // optional, default to main author value
* 'email' => 'email of the owner' // optional, default to main email value
* ) // Owner of the podcast // optional
* 'image' => 'album/podcast art' // optional, default to the main image value
* 'subtitle' => 'short description' // optional, default to the main description value
* 'summary' => 'longer description' // optional, default to the main description value
* 'block' => 'Prevent an episode from appearing (yes|no)' // optional
* 'category' => array(
* array('main' => 'main category', // required
* 'sub' => 'sub category' // optional
* ),
* // up to 3 rows
* ) // 'Category column and in iTunes Music Store Browse' // required
* 'explicit' => 'parental advisory graphic (yes|no|clean)' // optional
* 'keywords' => 'a comma separated list of 12 keywords maximum' // optional
* 'new-feed-url' => 'used to inform iTunes of new feed URL location' // optional
* ) // Itunes extension data // optional, ignored if atom is used
* 'entries' => array(
* array(
* 'title' => 'title of the feed entry', //required
* 'link' => 'url to a feed entry', //required
* 'description' => 'short version of a feed entry', // only text, no html, required
* 'guid' => 'id of the article, if not given link value will used', //optional
* 'content' => 'long version', // can contain html, optional
* 'lastUpdate' => 'timestamp of the publication date', // optional
* 'comments' => 'comments page of the feed entry', // optional
* 'commentRss' => 'the feed url of the associated comments', // optional
* 'source' => array(
* 'title' => 'title of the original source' // required,
* 'url' => 'url of the original source' // required
* ) // original source of the feed entry // optional
* 'category' => array(
* array(
* 'term' => 'first category label' // required,
* 'scheme' => 'url that identifies a categorization scheme' // optional
* ),
* array(
* //data for the second category and so on
* )
* ) // list of the attached categories // optional
* 'enclosure' => array(
* array(
* 'url' => 'url of the linked enclosure' // required
* 'type' => 'mime type of the enclosure' // optional
* 'length' => 'length of the linked content in octets' // optional
* ),
* array(
* //data for the second enclosure and so on
* )
* ) // list of the enclosures of the feed entry // optional
* ),
* array(
* //data for the second entry and so on
* )
* )
* );
* </code>
*
* @param array $data
* @return void
*/
public function __construct(array $data)
{
$this->_data = $data;
$this->_createHeader($data);
if (isset($data['entries'])) {
$this->_createEntries($data['entries']);
}
}
/**
* Returns an instance of Zend_Feed_Builder_Header
* describing the header of the feed
*
* @return Zend_Feed_Builder_Header
*/
public function getHeader()
{
return $this->_header;
}
/**
* Returns an array of Zend_Feed_Builder_Entry instances
* describing the entries of the feed
*
* @return array of Zend_Feed_Builder_Entry
*/
public function getEntries()
{
return $this->_entries;
}
/**
* Create the Zend_Feed_Builder_Header instance
*
* @param array $data
* @throws Zend_Feed_Builder_Exception
* @return void
*/
private function _createHeader(array $data)
{
$mandatories = array('title', 'link', 'charset');
foreach ($mandatories as $mandatory) {
if (!isset($data[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$this->_header = new Zend_Feed_Builder_Header($data['title'], $data['link'], $data['charset']);
if (isset($data['lastUpdate'])) {
$this->_header->setLastUpdate($data['lastUpdate']);
}
if (isset($data['published'])) {
$this->_header->setPublishedDate($data['published']);
}
if (isset($data['description'])) {
$this->_header->setDescription($data['description']);
}
if (isset($data['author'])) {
$this->_header->setAuthor($data['author']);
}
if (isset($data['email'])) {
$this->_header->setEmail($data['email']);
}
if (isset($data['webmaster'])) {
$this->_header->setWebmaster($data['webmaster']);
}
if (isset($data['copyright'])) {
$this->_header->setCopyright($data['copyright']);
}
if (isset($data['image'])) {
$this->_header->setImage($data['image']);
}
if (isset($data['generator'])) {
$this->_header->setGenerator($data['generator']);
}
if (isset($data['language'])) {
$this->_header->setLanguage($data['language']);
}
if (isset($data['ttl'])) {
$this->_header->setTtl($data['ttl']);
}
if (isset($data['rating'])) {
$this->_header->setRating($data['rating']);
}
if (isset($data['cloud'])) {
$mandatories = array('domain', 'path', 'registerProcedure', 'protocol');
foreach ($mandatories as $mandatory) {
if (!isset($data['cloud'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your cloud");
}
}
$uri_str = 'http://' . $data['cloud']['domain'] . $data['cloud']['path'];
$this->_header->setCloud($uri_str, $data['cloud']['registerProcedure'], $data['cloud']['protocol']);
}
if (isset($data['textInput'])) {
$mandatories = array('title', 'description', 'name', 'link');
foreach ($mandatories as $mandatory) {
if (!isset($data['textInput'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your textInput");
}
}
$this->_header->setTextInput($data['textInput']['title'],
$data['textInput']['description'],
$data['textInput']['name'],
$data['textInput']['link']);
}
if (isset($data['skipHours'])) {
$this->_header->setSkipHours($data['skipHours']);
}
if (isset($data['skipDays'])) {
$this->_header->setSkipDays($data['skipDays']);
}
if (isset($data['itunes'])) {
$itunes = new Zend_Feed_Builder_Header_Itunes($data['itunes']['category']);
if (isset($data['itunes']['author'])) {
$itunes->setAuthor($data['itunes']['author']);
}
if (isset($data['itunes']['owner'])) {
$name = isset($data['itunes']['owner']['name']) ? $data['itunes']['owner']['name'] : '';
$email = isset($data['itunes']['owner']['email']) ? $data['itunes']['owner']['email'] : '';
$itunes->setOwner($name, $email);
}
if (isset($data['itunes']['image'])) {
$itunes->setImage($data['itunes']['image']);
}
if (isset($data['itunes']['subtitle'])) {
$itunes->setSubtitle($data['itunes']['subtitle']);
}
if (isset($data['itunes']['summary'])) {
$itunes->setSummary($data['itunes']['summary']);
}
if (isset($data['itunes']['block'])) {
$itunes->setBlock($data['itunes']['block']);
}
if (isset($data['itunes']['explicit'])) {
$itunes->setExplicit($data['itunes']['explicit']);
}
if (isset($data['itunes']['keywords'])) {
$itunes->setKeywords($data['itunes']['keywords']);
}
if (isset($data['itunes']['new-feed-url'])) {
$itunes->setNewFeedUrl($data['itunes']['new-feed-url']);
}
$this->_header->setITunes($itunes);
}
}
/**
* Create the array of article entries
*
* @param array $data
* @throws Zend_Feed_Builder_Exception
* @return void
*/
private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
}
} Feed/Builder/Header.php 0000604 00000027261 15071256134 0010706 0 ustar 00 <?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_Feed
* @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: Header.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Feed_Builder_Header_Itunes
*/
require_once 'Zend/Feed/Builder/Header/Itunes.php';
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* Header of a custom build feed
*
* Classes implementing the Zend_Feed_Builder_Interface interface
* uses this class to describe the header of a feed
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Builder_Header extends ArrayObject
{
/**
* Constructor
*
* @param string $title title of the feed
* @param string $link canonical url of the feed
* @param string $charset charset of the textual data
* @return void
*/
public function __construct($title, $link, $charset = 'utf-8')
{
$this->offsetSet('title', $title);
$this->offsetSet('link', $link);
$this->offsetSet('charset', $charset);
$this->setLastUpdate(time())
->setGenerator('Zend_Feed');
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
/**
* Timestamp of the update date
*
* @param int $lastUpdate
* @return Zend_Feed_Builder_Header
*/
public function setLastUpdate($lastUpdate)
{
$this->offsetSet('lastUpdate', $lastUpdate);
return $this;
}
/**
* Timestamp of the publication date
*
* @param int $published
* @return Zend_Feed_Builder_Header
*/
public function setPublishedDate($published)
{
$this->offsetSet('published', $published);
return $this;
}
/**
* Short description of the feed
*
* @param string $description
* @return Zend_Feed_Builder_Header
*/
public function setDescription($description)
{
$this->offsetSet('description', $description);
return $this;
}
/**
* Sets the author of the feed
*
* @param string $author
* @return Zend_Feed_Builder_Header
*/
public function setAuthor($author)
{
$this->offsetSet('author', $author);
return $this;
}
/**
* Sets the author's email
*
* @param string $email
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setEmail($email)
{
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($email)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property");
}
$this->offsetSet('email', $email);
return $this;
}
/**
* Sets the copyright notice
*
* @param string $copyright
* @return Zend_Feed_Builder_Header
*/
public function setCopyright($copyright)
{
$this->offsetSet('copyright', $copyright);
return $this;
}
/**
* Sets the image of the feed
*
* @param string $image
* @return Zend_Feed_Builder_Header
*/
public function setImage($image)
{
$this->offsetSet('image', $image);
return $this;
}
/**
* Sets the generator of the feed
*
* @param string $generator
* @return Zend_Feed_Builder_Header
*/
public function setGenerator($generator)
{
$this->offsetSet('generator', $generator);
return $this;
}
/**
* Sets the language of the feed
*
* @param string $language
* @return Zend_Feed_Builder_Header
*/
public function setLanguage($language)
{
$this->offsetSet('language', $language);
return $this;
}
/**
* Email address for person responsible for technical issues
* Ignored if atom is used
*
* @param string $webmaster
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setWebmaster($webmaster)
{
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($webmaster)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property");
}
$this->offsetSet('webmaster', $webmaster);
return $this;
}
/**
* How long in minutes a feed can be cached before refreshing
* Ignored if atom is used
*
* @param int $ttl
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setTtl($ttl)
{
Zend_Loader::loadClass('Zend_Validate_Int');
$validate = new Zend_Validate_Int();
if (!$validate->isValid($ttl)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property");
}
$this->offsetSet('ttl', $ttl);
return $this;
}
/**
* PICS rating for the feed
* Ignored if atom is used
*
* @param string $rating
* @return Zend_Feed_Builder_Header
*/
public function setRating($rating)
{
$this->offsetSet('rating', $rating);
return $this;
}
/**
* Cloud to be notified of updates of the feed
* Ignored if atom is used
*
* @param string|Zend_Uri_Http $uri
* @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify
* @param string $protocol protocol to use, e.g. soap or xml-rpc
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setCloud($uri, $procedure, $protocol)
{
if (is_string($uri) && Zend_Uri_Http::check($uri)) {
$uri = Zend_Uri::factory($uri);
}
if (!$uri instanceof Zend_Uri_Http) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
}
if (!$uri->getPort()) {
$uri->setPort(80);
}
$this->offsetSet('cloud', array('uri' => $uri,
'procedure' => $procedure,
'protocol' => $protocol));
return $this;
}
/**
* A text input box that can be displayed with the feed
* Ignored if atom is used
*
* @param string $title the label of the Submit button in the text input area
* @param string $description explains the text input area
* @param string $name the name of the text object in the text input area
* @param string $link the URL of the CGI script that processes text input requests
* @return Zend_Feed_Builder_Header
*/
public function setTextInput($title, $description, $name, $link)
{
$this->offsetSet('textInput', array('title' => $title,
'description' => $description,
'name' => $name,
'link' => $link));
return $this;
}
/**
* Hint telling aggregators which hours they can skip
* Ignored if atom is used
*
* @param array $hours list of hours in 24 format
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setSkipHours(array $hours)
{
if (count($hours) > 24) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property");
}
foreach ($hours as $hour) {
if ($hour < 0 || $hour > 23) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23");
}
}
$this->offsetSet('skipHours', $hours);
return $this;
}
/**
* Hint telling aggregators which days they can skip
* Ignored if atom is used
*
* @param array $days list of days to skip, e.g. Monday
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setSkipDays(array $days)
{
if (count($days) > 7) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property");
}
$valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
foreach ($days as $day) {
if (!in_array(strtolower($day), $valid)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$day is not a valid day");
}
}
$this->offsetSet('skipDays', $days);
return $this;
}
/**
* Sets the iTunes rss extension
*
* @param Zend_Feed_Builder_Header_Itunes $itunes
* @return Zend_Feed_Builder_Header
*/
public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes)
{
$this->offsetSet('itunes', $itunes);
return $this;
}
}
Feed/Builder/Exception.php 0000604 00000002177 15071256134 0011453 0 ustar 00 <?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_Feed
* @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 $
*/
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
/**
* Zend_Feed_Builder exception class
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Builder_Exception extends Zend_Feed_Exception
{
}
Feed/Builder/Interface.php 0000604 00000003057 15071256134 0011413 0 ustar 00 <?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_Feed
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Input feed data interface
*
* Classes implementing this interface can be passe to Zend_Feed::importBuilder
* as an input data source for the Zend_Feed construction
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Feed_Builder_Interface
{
/**
* Returns an instance of Zend_Feed_Builder_Header
* describing the header of the feed
*
* @return Zend_Feed_Builder_Header
*/
public function getHeader();
/**
* Returns an array of Zend_Feed_Builder_Entry instances
* describing the entries of the feed
*
* @return array of Zend_Feed_Builder_Entry
*/
public function getEntries();
}
Feed/Builder/Header/Itunes.php 0000604 00000017532 15071256134 0012155 0 ustar 00 <?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_Feed
* @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: Itunes.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* ITunes rss extension
*
* Classes used to describe the itunes channel extension
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Builder_Header_Itunes extends ArrayObject
{
/**
* Constructor
*
* @param array $categories Categories columns and in iTunes Music Store Browse
* @return void
*/
public function __construct(array $categories)
{
$this->setCategories($categories);
}
/**
* Sets the categories column and in iTunes Music Store Browse
* $categories must conform to the following format:
* <code>
* array(array('main' => 'main category',
* 'sub' => 'sub category' // optionnal
* ),
* // up to 3 rows
* )
* </code>
*
* @param array $categories
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setCategories(array $categories)
{
$nb = count($categories);
if (0 === $nb) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set at least one itunes category");
}
if ($nb > 3) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set at most three itunes categories");
}
foreach ($categories as $i => $category) {
if (empty($category['main'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set the main category (category #$i)");
}
}
$this->offsetSet('category', $categories);
return $this;
}
/**
* Sets the artist value, default to the feed's author value
*
* @param string $author
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setAuthor($author)
{
$this->offsetSet('author', $author);
return $this;
}
/**
* Sets the owner of the postcast
*
* @param string $name default to the feed's author value
* @param string $email default to the feed's email value
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setOwner($name = '', $email = '')
{
if (!empty($email)) {
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($email)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the itunes owner's email property");
}
}
$this->offsetSet('owner', array('name' => $name, 'email' => $email));
return $this;
}
/**
* Sets the album/podcast art picture
* Default to the feed's image value
*
* @param string $image
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setImage($image)
{
$this->offsetSet('image', $image);
return $this;
}
/**
* Sets the short description of the podcast
* Default to the feed's description
*
* @param string $subtitle
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setSubtitle($subtitle)
{
$this->offsetSet('subtitle', $subtitle);
return $this;
}
/**
* Sets the longer description of the podcast
* Default to the feed's description
*
* @param string $summary
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setSummary($summary)
{
$this->offsetSet('summary', $summary);
return $this;
}
/**
* Prevent a feed from appearing
*
* @param string $block can be 'yes' or 'no'
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setBlock($block)
{
$block = strtolower($block);
if (!in_array($block, array('yes', 'no'))) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
}
$this->offsetSet('block', $block);
return $this;
}
/**
* Configuration of the parental advisory graphic
*
* @param string $explicit can be 'yes', 'no' or 'clean'
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setExplicit($explicit)
{
$explicit = strtolower($explicit);
if (!in_array($explicit, array('yes', 'no', 'clean'))) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set yes, no or clean to the itunes explicit property");
}
$this->offsetSet('explicit', $explicit);
return $this;
}
/**
* Sets a comma separated list of 12 keywords maximum
*
* @param string $keywords
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setKeywords($keywords)
{
$this->offsetSet('keywords', $keywords);
return $this;
}
/**
* Sets the new feed URL location
*
* @param string $url
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setNewFeedUrl($url)
{
$this->offsetSet('new_feed_url', $url);
return $this;
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
} Feed/Builder/Entry.php 0000604 00000016704 15071256134 0010617 0 ustar 00 <?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_Feed
* @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: Entry.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* An entry of a custom build feed
*
* Classes implementing the Zend_Feed_Builder_Interface interface
* uses this class to describe an entry of a feed
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Builder_Entry extends ArrayObject
{
/**
* Create a new builder entry
*
* @param string $title
* @param string $link
* @param string $description short version of the entry, no html
* @return void
*/
public function __construct($title, $link, $description)
{
$this->offsetSet('title', $title);
$this->offsetSet('link', $link);
$this->offsetSet('description', $description);
$this->setLastUpdate(time());
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
/**
* Sets the id/guid of the entry
*
* @param string $id
* @return Zend_Feed_Builder_Entry
*/
public function setId($id)
{
$this->offsetSet('guid', $id);
return $this;
}
/**
* Sets the full html content of the entry
*
* @param string $content
* @return Zend_Feed_Builder_Entry
*/
public function setContent($content)
{
$this->offsetSet('content', $content);
return $this;
}
/**
* Timestamp of the update date
*
* @param int $lastUpdate
* @return Zend_Feed_Builder_Entry
*/
public function setLastUpdate($lastUpdate)
{
$this->offsetSet('lastUpdate', $lastUpdate);
return $this;
}
/**
* Sets the url of the commented page associated to the entry
*
* @param string $comments
* @return Zend_Feed_Builder_Entry
*/
public function setCommentsUrl($comments)
{
$this->offsetSet('comments', $comments);
return $this;
}
/**
* Sets the url of the comments feed link
*
* @param string $commentRss
* @return Zend_Feed_Builder_Entry
*/
public function setCommentsRssUrl($commentRss)
{
$this->offsetSet('commentRss', $commentRss);
return $this;
}
/**
* Defines a reference to the original source
*
* @param string $title
* @param string $url
* @return Zend_Feed_Builder_Entry
*/
public function setSource($title, $url)
{
$this->offsetSet('source', array('title' => $title,
'url' => $url));
return $this;
}
/**
* Sets the categories of the entry
* Format of the array:
* <code>
* array(
* array(
* 'term' => 'first category label',
* 'scheme' => 'url that identifies a categorization scheme' // optional
* ),
* // second category and so one
* )
* </code>
*
* @param array $categories
* @return Zend_Feed_Builder_Entry
*/
public function setCategories(array $categories)
{
foreach ($categories as $category) {
$this->addCategory($category);
}
return $this;
}
/**
* Add a category to the entry
*
* @param array $category see Zend_Feed_Builder_Entry::setCategories() for format
* @return Zend_Feed_Builder_Entry
* @throws Zend_Feed_Builder_Exception
*/
public function addCategory(array $category)
{
if (empty($category['term'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define the name of the category");
}
if (!$this->offsetExists('category')) {
$categories = array($category);
} else {
$categories = $this->offsetGet('category');
$categories[] = $category;
}
$this->offsetSet('category', $categories);
return $this;
}
/**
* Sets the enclosures of the entry
* Format of the array:
* <code>
* array(
* array(
* 'url' => 'url of the linked enclosure',
* 'type' => 'mime type of the enclosure' // optional
* 'length' => 'length of the linked content in octets' // optional
* ),
* // second enclosure and so one
* )
* </code>
*
* @param array $enclosures
* @return Zend_Feed_Builder_Entry
* @throws Zend_Feed_Builder_Exception
*/
public function setEnclosures(array $enclosures)
{
foreach ($enclosures as $enclosure) {
if (empty($enclosure['url'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to supply an url for your enclosure");
}
$type = isset($enclosure['type']) ? $enclosure['type'] : '';
$length = isset($enclosure['length']) ? $enclosure['length'] : '';
$this->addEnclosure($enclosure['url'], $type, $length);
}
return $this;
}
/**
* Add an enclosure to the entry
*
* @param string $url
* @param string $type
* @param string $length
* @return Zend_Feed_Builder_Entry
*/
public function addEnclosure($url, $type = '', $length = '')
{
if (!$this->offsetExists('enclosure')) {
$enclosure = array();
} else {
$enclosure = $this->offsetGet('enclosure');
}
$enclosure[] = array('url' => $url,
'type' => $type,
'length' => $length);
$this->offsetSet('enclosure', $enclosure);
return $this;
}
}
Feed/Element.php 0000604 00000026342 15071256134 0007520 0 ustar 00 <?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_Feed
* @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: Element.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Wraps a DOMElement allowing for SimpleXML-like access to attributes.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Element implements ArrayAccess
{
/**
* @var DOMElement
*/
protected $_element;
/**
* @var Zend_Feed_Element
*/
protected $_parentElement;
/**
* @var boolean
*/
protected $_appended = true;
/**
* Zend_Feed_Element constructor.
*
* @param DOMElement $element The DOM element we're encapsulating.
* @return void
*/
public function __construct($element = null)
{
$this->_element = $element;
}
/**
* Get a DOM representation of the element
*
* Returns the underlying DOM object, which can then be
* manipulated with full DOM methods.
*
* @return DOMDocument
*/
public function getDOM()
{
return $this->_element;
}
/**
* Update the object from a DOM element
*
* Take a DOMElement object, which may be originally from a call
* to getDOM() or may be custom created, and use it as the
* DOM tree for this Zend_Feed_Element.
*
* @param DOMElement $element
* @return void
*/
public function setDOM(DOMElement $element)
{
$this->_element = $this->_element->ownerDocument->importNode($element, true);
}
/**
* Set the parent element of this object to another
* Zend_Feed_Element.
*
* @param Zend_Feed_Element $element
* @return void
*/
public function setParent(Zend_Feed_Element $element)
{
$this->_parentElement = $element;
$this->_appended = false;
}
/**
* Appends this element to its parent if necessary.
*
* @return void
*/
protected function ensureAppended()
{
if (!$this->_appended) {
$this->_parentElement->getDOM()->appendChild($this->_element);
$this->_appended = true;
$this->_parentElement->ensureAppended();
}
}
/**
* Get an XML string representation of this element
*
* Returns a string of this element's XML, including the XML
* prologue.
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$doc->appendChild($doc->importNode($this->_element, true));
return $doc->saveXML();
}
/**
* Get the XML for only this element
*
* Returns a string of this element's XML without prologue.
*
* @return string
*/
public function saveXmlFragment()
{
return $this->_element->ownerDocument->saveXML($this->_element);
}
/**
* Map variable access onto the underlying entry representation.
*
* Get-style access returns a Zend_Feed_Element representing the
* child element accessed. To get string values, use method syntax
* with the __call() overriding.
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
$nodes = $this->_children($var);
$length = count($nodes);
if ($length == 1) {
return new Zend_Feed_Element($nodes[0]);
} elseif ($length > 1) {
return array_map(create_function('$e', 'return new Zend_Feed_Element($e);'), $nodes);
} else {
// When creating anonymous nodes for __set chaining, don't
// call appendChild() on them. Instead we pass the current
// element to them as an extra reference; the child is
// then responsible for appending itself when it is
// actually set. This way "if ($foo->bar)" doesn't create
// a phantom "bar" element in our tree.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
$node = $this->_element->ownerDocument->createElementNS(Zend_Feed::lookupNamespace($ns), $elt);
} else {
$node = $this->_element->ownerDocument->createElement($var);
}
$node = new self($node);
$node->setParent($this);
return $node;
}
}
/**
* Map variable sets onto the underlying entry representation.
*
* @param string $var The property to change.
* @param string $val The property's new value.
* @return void
* @throws Zend_Feed_Exception
*/
public function __set($var, $val)
{
$this->ensureAppended();
$nodes = $this->_children($var);
if (!$nodes) {
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
$node = $this->_element->ownerDocument->createElementNS(Zend_Feed::lookupNamespace($ns), $var, $val);
$this->_element->appendChild($node);
} else {
$node = $this->_element->ownerDocument->createElement($var, $val);
$this->_element->appendChild($node);
}
} elseif (count($nodes) > 1) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot set the value of multiple tags simultaneously.');
} else {
$nodes[0]->nodeValue = $val;
}
}
/**
* Map isset calls onto the underlying entry representation.
*
* @param string $var
* @return boolean
*/
public function __isset($var)
{
// Look for access of the form {ns:var}. We don't use
// _children() here because we can break out of the loop
// immediately once we find something.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
return true;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
return true;
}
}
}
}
/**
* Get the value of an element with method syntax.
*
* Map method calls to get the string value of the requested
* element. If there are multiple elements that match, this will
* return an array of those objects.
*
* @param string $var The element to get the string value of.
* @param mixed $unused This parameter is not used.
* @return mixed The node's value, null, or an array of nodes.
*/
public function __call($var, $unused)
{
$nodes = $this->_children($var);
if (!$nodes) {
return null;
} elseif (count($nodes) > 1) {
return $nodes;
} else {
return $nodes[0]->nodeValue;
}
}
/**
* Remove all children matching $var.
*
* @param string $var
* @return void
*/
public function __unset($var)
{
$nodes = $this->_children($var);
foreach ($nodes as $node) {
$parent = $node->parentNode;
$parent->removeChild($node);
}
}
/**
* Returns the nodeValue of this element when this object is used
* in a string context.
*
* @return string
*/
public function __toString()
{
return $this->_element->nodeValue;
}
/**
* Finds children with tagnames matching $var
*
* Similar to SimpleXML's children() method.
*
* @param string $var Tagname to match, can be either namespace:tagName or just tagName.
* @return array
*/
protected function _children($var)
{
$found = array();
// Look for access of the form {ns:var}.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
$found[] = $child;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
$found[] = $child;
}
}
}
return $found;
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return boolean
*/
public function offsetExists($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->hasAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->hasAttribute($offset);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return string
*/
public function offsetGet($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->getAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->getAttribute($offset);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @param string $value
* @return string
*/
public function offsetSet($offset, $value)
{
$this->ensureAppended();
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->setAttributeNS(Zend_Feed::lookupNamespace($ns), $attr, $value);
} else {
return $this->_element->setAttribute($offset, $value);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return boolean
*/
public function offsetUnset($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->removeAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->removeAttribute($offset);
}
}
}
Feed/Atom.php 0000604 00000032714 15071256134 0007027 0 ustar 00 <?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_Feed
* @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: Atom.php 11654 2008-10-03 16:03:35Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Feed_Abstract
*/
require_once 'Zend/Feed/Abstract.php';
/**
* @see Zend_Feed_Entry_Atom
*/
require_once 'Zend/Feed/Entry/Atom.php';
/**
* Atom feed class
*
* The Zend_Feed_Atom class is a concrete subclass of the general
* Zend_Feed_Abstract class, tailored for representing an Atom
* feed. It shares all of the same methods with its abstract
* parent. The distinction is made in the format of data that
* Zend_Feed_Atom expects, and as a further pointer for users as to
* what kind of feed object they have been passed.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Atom extends Zend_Feed_Abstract
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Feed_Entry_Atom';
/**
* The element name for individual feed elements (Atom <entry>
* elements).
*
* @var string
*/
protected $_entryElementName = 'entry';
/**
* The default namespace for Atom feeds.
*
* @var string
*/
protected $_defaultNamespace = 'atom';
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base feed element and create an alias to it.
$element = $this->_element->getElementsByTagName('feed')->item(0);
if (!$element) {
// Try to find a single <entry> instead.
$element = $this->_element->getElementsByTagName($this->_entryElementName)->item(0);
if (!$element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <feed> or <' . $this->_entryElementName
. '> element found, cannot parse feed.');
}
$doc = new DOMDocument($this->_element->version,
$this->_element->actualEncoding);
$feed = $doc->appendChild($doc->createElement('feed'));
$feed->appendChild($doc->importNode($element, true));
$element = $feed;
}
$this->_element = $element;
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
/**
* Easy access to <link> tags keyed by "rel" attributes.
*
* If $elt->link() is called with no arguments, we will attempt to
* return the value of the <link> tag(s) like all other
* method-syntax attribute access. If an argument is passed to
* link(), however, then we will return the "href" value of the
* first <link> tag that has a "rel" attribute matching $rel:
*
* $elt->link(): returns the value of the link tag.
* $elt->link('self'): returns the href from the first <link rel="self"> in the entry.
*
* @param string $rel The "rel" attribute to look for.
* @return mixed
*/
public function link($rel = null)
{
if ($rel === null) {
return parent::__call('link', null);
}
// index link tags by their "rel" attribute.
$links = parent::__get('link');
if (!is_array($links)) {
if ($links instanceof Zend_Feed_Element) {
$links = array($links);
} else {
return $links;
}
}
foreach ($links as $link) {
if (empty($link['rel'])) {
continue;
}
if ($rel == $link['rel']) {
return $link['href'];
}
}
return null;
}
/**
* Make accessing some individual elements of the feed easier.
*
* Special accessors 'entry' and 'entries' are provided so that if
* you wish to iterate over an Atom feed's entries, you can do so
* using foreach ($feed->entries as $entry) or foreach
* ($feed->entry as $entry).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'entry':
// fall through to the next case
case 'entries':
return $this;
default:
return parent::__get($var);
}
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
protected function _mapFeedHeaders($array)
{
$feed = $this->_element->createElement('feed');
$feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$id = $this->_element->createElement('id', $array->link);
$feed->appendChild($id);
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($array->title));
$feed->appendChild($title);
if (isset($array->author)) {
$author = $this->_element->createElement('author');
$name = $this->_element->createElement('name', $array->author);
$author->appendChild($name);
if (isset($array->email)) {
$email = $this->_element->createElement('email', $array->email);
$author->appendChild($email);
}
$feed->appendChild($author);
}
$updated = isset($array->lastUpdate) ? $array->lastUpdate : time();
$updated = $this->_element->createElement('updated', date(DATE_ATOM, $updated));
$feed->appendChild($updated);
if (isset($array->published)) {
$published = $this->_element->createElement('published', date(DATE_ATOM, $array->published));
$feed->appendChild($published);
}
$link = $this->_element->createElement('link');
$link->setAttribute('rel', 'self');
$link->setAttribute('href', $array->link);
if (isset($array->language)) {
$link->setAttribute('hreflang', $array->language);
}
$feed->appendChild($link);
if (isset($array->description)) {
$subtitle = $this->_element->createElement('subtitle');
$subtitle->appendChild($this->_element->createCDATASection($array->description));
$feed->appendChild($subtitle);
}
if (isset($array->copyright)) {
$copyright = $this->_element->createElement('rights', $array->copyright);
$feed->appendChild($copyright);
}
if (isset($array->image)) {
$image = $this->_element->createElement('logo', $array->image);
$feed->appendChild($image);
}
$generator = !empty($array->generator) ? $array->generator : 'Zend_Feed';
$generator = $this->_element->createElement('generator', $generator);
$feed->appendChild($generator);
return $feed;
}
/**
* Generate the entries of the feed when working in write mode
*
* The following nodes are constructed for each feed entry
* <entry>
* <id>url to feed entry</id>
* <title>entry title</title>
* <updated>last update</updated>
* <link rel="alternate" href="url to feed entry" />
* <summary>short text</summary>
* <content>long version, can contain html</content>
* </entry>
*
* @param array $array the data to use
* @param DOMElement $root the root node to use
* @return void
*/
protected function _mapFeedEntries(DOMElement $root, $array)
{
foreach ($array as $dataentry) {
$entry = $this->_element->createElement('entry');
$id = $this->_element->createElement('id', isset($dataentry->guid) ? $dataentry->guid : $dataentry->link);
$entry->appendChild($id);
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($dataentry->title));
$entry->appendChild($title);
$updated = isset($dataentry->lastUpdate) ? $dataentry->lastUpdate : time();
$updated = $this->_element->createElement('updated', date(DATE_ATOM, $updated));
$entry->appendChild($updated);
$link = $this->_element->createElement('link');
$link->setAttribute('rel', 'alternate');
$link->setAttribute('href', $dataentry->link);
$entry->appendChild($link);
$summary = $this->_element->createElement('summary');
$summary->appendChild($this->_element->createCDATASection($dataentry->description));
$entry->appendChild($summary);
if (isset($dataentry->content)) {
$content = $this->_element->createElement('content');
$content->setAttribute('type', 'html');
$content->appendChild($this->_element->createCDATASection($dataentry->content));
$entry->appendChild($content);
}
if (isset($dataentry->category)) {
foreach ($dataentry->category as $category) {
$node = $this->_element->createElement('category');
$node->setAttribute('term', $category['term']);
if (isset($category['scheme'])) {
$node->setAttribute('scheme', $category['scheme']);
}
$entry->appendChild($node);
}
}
if (isset($dataentry->source)) {
$source = $this->_element->createElement('source');
$title = $this->_element->createElement('title', $dataentry->source['title']);
$source->appendChild($title);
$link = $this->_element->createElement('link', $dataentry->source['title']);
$link->setAttribute('rel', 'alternate');
$link->setAttribute('href', $dataentry->source['url']);
$source->appendChild($link);
}
if (isset($dataentry->enclosure)) {
foreach ($dataentry->enclosure as $enclosure) {
$node = $this->_element->createElement('link');
$node->setAttribute('rel', 'enclosure');
$node->setAttribute('href', $enclosure['url']);
if (isset($enclosure['type'])) {
$node->setAttribute('type', $enclosure['type']);
}
if (isset($enclosure['length'])) {
$node->setAttribute('length', $enclosure['length']);
}
$entry->appendChild($node);
}
}
if (isset($dataentry->comments)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:comment',
$dataentry->comments);
$entry->appendChild($comments);
}
if (isset($dataentry->commentRss)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:commentRss',
$dataentry->commentRss);
$entry->appendChild($comments);
}
$root->appendChild($entry);
}
}
/**
* Override Zend_Feed_Element to allow formated feeds
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$doc->appendChild($doc->importNode($this->_element, true));
$doc->formatOutput = true;
return $doc->saveXML();
}
/**
* Send feed to a http client with the correct header
*
* @return void
* @throws Zend_Feed_Exception if headers have already been sent
*/
public function send()
{
if (headers_sent()) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot send ATOM because headers have already been sent.');
}
header('Content-Type: application/atom+xml; charset=' . $this->_element->ownerDocument->actualEncoding);
echo $this->saveXML();
}
}
Feed/Abstract.php 0000604 00000016211 15071256134 0007664 0 ustar 00 <?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_Feed
* @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: Abstract.php 12507 2008-11-10 16:29:09Z matthew $
*/
/**
* @see Zend_Feed_Element
*/
require_once 'Zend/Feed/Element.php';
/**
* The Zend_Feed_Abstract class is an abstract class representing feeds.
*
* Zend_Feed_Abstract implements two core PHP 5 interfaces: ArrayAccess and
* Iterator. In both cases the collection being treated as an array is
* considered to be the entry collection, such that iterating over the
* feed takes you through each of the feed.s entries.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Feed_Abstract extends Zend_Feed_Element implements Iterator
{
/**
* Current index on the collection of feed entries for the
* Iterator implementation.
*
* @var integer
*/
protected $_entryIndex = 0;
/**
* Cache of feed entries.
*
* @var array
*/
protected $_entries;
/**
* Feed constructor
*
* The Zend_Feed_Abstract constructor takes the URI of a feed or a
* feed represented as a string and loads it as XML.
*
* @param string $uri The full URI of the feed to load, or NULL if not retrieved via HTTP or as an array.
* @param string $string The feed as a string, or NULL if retrieved via HTTP or as an array.
* @param Zend_Feed_Builder_Interface $builder The feed as a builder instance or NULL if retrieved as a string or via HTTP.
* @return void
* @throws Zend_Feed_Exception If loading the feed failed.
*/
public function __construct($uri = null, $string = null, Zend_Feed_Builder_Interface $builder = null)
{
if ($uri !== null) {
// Retrieve the feed via HTTP
$client = Zend_Feed::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$this->_element = $response->getBody();
$this->__wakeup();
} elseif ($string !== null) {
// Retrieve the feed from $string
$this->_element = $string;
$this->__wakeup();
} else {
// Generate the feed from the array
$header = $builder->getHeader();
$this->_element = new DOMDocument('1.0', $header['charset']);
$root = $this->_mapFeedHeaders($header);
$this->_mapFeedEntries($root, $builder->getEntries());
$this->_element = $root;
$this->_buildEntryCache();
}
}
/**
* Load the feed as an XML DOMDocument object
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
@ini_set('track_errors', 1);
$doc = new DOMDocument;
$status = @$doc->loadXML($this->_element);
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$this->_element = $doc;
}
/**
* Prepare for serialiation
*
* @return array
*/
public function __sleep()
{
$this->_element = $this->saveXML();
return array('_element');
}
/**
* Cache the individual feed elements so they don't need to be
* searched for on every operation.
*
* @return void
*/
protected function _buildEntryCache()
{
$this->_entries = array();
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $this->_entryElementName) {
$this->_entries[] = $child;
}
}
}
/**
* Get the number of entries in this feed object.
*
* @return integer Entry count.
*/
public function count()
{
return count($this->_entries);
}
/**
* Required by the Iterator interface.
*
* @return void
*/
public function rewind()
{
$this->_entryIndex = 0;
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row, or null if no rows.
*/
public function current()
{
return new $this->_entryClassName(
null,
$this->_entries[$this->_entryIndex]);
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row number (starts at 0), or NULL if no rows
*/
public function key()
{
return $this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return mixed The next row, or null if no more rows.
*/
public function next()
{
++$this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return boolean Whether the iteration is valid
*/
public function valid()
{
return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count();
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
abstract protected function _mapFeedHeaders($array);
/**
* Generate the entries of the feed when working in write mode
*
* @param DOMElement $root the root node to use
* @param array $array the data to use
* @return DOMElement root node
*/
abstract protected function _mapFeedEntries(DOMElement $root, $array);
/**
* Send feed to a http client with the correct header
*
* @throws Zend_Feed_Exception if headers have already been sent
* @return void
*/
abstract public function send();
}
Feed/Rss.php 0000604 00000045254 15071256134 0006701 0 ustar 00 <?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_Feed
* @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: Rss.php 11654 2008-10-03 16:03:35Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Feed_Abstract
*/
require_once 'Zend/Feed/Abstract.php';
/**
* @see Zend_Feed_Entry_Rss
*/
require_once 'Zend/Feed/Entry/Rss.php';
/**
* RSS channel class
*
* The Zend_Feed_Rss class is a concrete subclass of
* Zend_Feed_Abstract meant for representing RSS channels. It does not
* add any methods to its parent, just provides a classname to check
* against with the instanceof operator, and expects to be handling
* RSS-formatted data instead of Atom.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Rss extends Zend_Feed_Abstract
{
/**
* The classname for individual channel elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Feed_Entry_Rss';
/**
* The element name for individual channel elements (RSS <item>s).
*
* @var string
*/
protected $_entryElementName = 'item';
/**
* The default namespace for RSS channels.
*
* @var string
*/
protected $_defaultNamespace = 'rss';
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base channel element and create an alias to it.
$this->_element = $this->_element->getElementsByTagName('channel')->item(0);
if (!$this->_element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <channel> element found, cannot parse channel.');
}
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
/**
* Make accessing some individual elements of the channel easier.
*
* Special accessors 'item' and 'items' are provided so that if
* you wish to iterate over an RSS channel's items, you can do so
* using foreach ($channel->items as $item) or foreach
* ($channel->item as $item).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'item':
// fall through to the next case
case 'items':
return $this;
default:
return parent::__get($var);
}
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
protected function _mapFeedHeaders($array)
{
$channel = $this->_element->createElement('channel');
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($array->title));
$channel->appendChild($title);
$link = $this->_element->createElement('link', $array->link);
$channel->appendChild($link);
$desc = isset($array->description) ? $array->description : '';
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($desc));
$channel->appendChild($description);
$pubdate = isset($array->lastUpdate) ? $array->lastUpdate : time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r', $pubdate));
$channel->appendChild($pubdate);
if (isset($array->published)) {
$lastBuildDate = $this->_element->createElement('lastBuildDate', gmdate('r', $array->published));
}
$editor = '';
if (!empty($array->email)) {
$editor .= $array->email;
}
if (!empty($array->author)) {
$editor .= ' (' . $array->author . ')';
}
if (!empty($editor)) {
$author = $this->_element->createElement('managingEditor', ltrim($editor));
$channel->appendChild($author);
}
if (isset($array->webmaster)) {
$channel->appendChild($this->_element->createElement('webMaster', $array->webmaster));
}
if (!empty($array->copyright)) {
$copyright = $this->_element->createElement('copyright', $array->copyright);
$channel->appendChild($copyright);
}
if (!empty($array->image)) {
$image = $this->_element->createElement('image');
$url = $this->_element->createElement('url', $array->image);
$image->appendChild($url);
$imagetitle = $this->_element->createElement('title', $array->title);
$image->appendChild($imagetitle);
$imagelink = $this->_element->createElement('link', $array->link);
$image->appendChild($imagelink);
$channel->appendChild($image);
}
$generator = !empty($array->generator) ? $array->generator : 'Zend_Feed';
$generator = $this->_element->createElement('generator', $generator);
$channel->appendChild($generator);
if (!empty($array->language)) {
$language = $this->_element->createElement('language', $array->language);
$channel->appendChild($language);
}
$doc = $this->_element->createElement('docs', 'http://blogs.law.harvard.edu/tech/rss');
$channel->appendChild($doc);
if (isset($array->cloud)) {
$cloud = $this->_element->createElement('cloud');
$cloud->setAttribute('domain', $array->cloud['uri']->getHost());
$cloud->setAttribute('port', $array->cloud['uri']->getPort());
$cloud->setAttribute('path', $array->cloud['uri']->getPath());
$cloud->setAttribute('registerProcedure', $array->cloud['procedure']);
$cloud->setAttribute('protocol', $array->cloud['protocol']);
$channel->appendChild($cloud);
}
if (isset($array->rating)) {
$rating = $this->_element->createElement('rating', $array->rating);
$channel->appendChild($rating);
}
if (isset($array->textInput)) {
$textinput = $this->_element->createElement('textInput');
$textinput->appendChild($this->_element->createElement('title', $array->textInput['title']));
$textinput->appendChild($this->_element->createElement('description', $array->textInput['description']));
$textinput->appendChild($this->_element->createElement('name', $array->textInput['name']));
$textinput->appendChild($this->_element->createElement('link', $array->textInput['link']));
$channel->appendChild($textinput);
}
if (isset($array->skipHours)) {
$skipHours = $this->_element->createElement('skipHours');
foreach ($array->skipHours as $hour) {
$skipHours->appendChild($this->_element->createElement('hour', $hour));
}
$channel->appendChild($skipHours);
}
if (isset($array->skipDays)) {
$skipDays = $this->_element->createElement('skipDays');
foreach ($array->skipDays as $day) {
$skipDays->appendChild($this->_element->createElement('day', $day));
}
$channel->appendChild($skipDays);
}
if (isset($array->itunes)) {
$this->_buildiTunes($channel, $array);
}
return $channel;
}
/**
* Adds the iTunes extensions to a root node
*
* @param DOMElement $root
* @param array $array
* @return void
*/
private function _buildiTunes(DOMElement $root, $array)
{
/* author node */
$author = '';
if (isset($array->itunes->author)) {
$author = $array->itunes->author;
} elseif (isset($array->author)) {
$author = $array->author;
}
if (!empty($author)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:author', $author);
$root->appendChild($node);
}
/* owner node */
$author = '';
$email = '';
if (isset($array->itunes->owner)) {
if (isset($array->itunes->owner['name'])) {
$author = $array->itunes->owner['name'];
}
if (isset($array->itunes->owner['email'])) {
$email = $array->itunes->owner['email'];
}
}
if (empty($author) && isset($array->author)) {
$author = $array->author;
}
if (empty($email) && isset($array->email)) {
$email = $array->email;
}
if (!empty($author) || !empty($email)) {
$owner = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:owner');
if (!empty($author)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:name', $author);
$owner->appendChild($node);
}
if (!empty($email)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:email', $email);
$owner->appendChild($node);
}
$root->appendChild($owner);
}
$image = '';
if (isset($array->itunes->image)) {
$image = $array->itunes->image;
} elseif (isset($array->image)) {
$image = $array->image;
}
if (!empty($image)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:image');
$node->setAttribute('href', $image);
$root->appendChild($node);
}
$subtitle = '';
if (isset($array->itunes->subtitle)) {
$subtitle = $array->itunes->subtitle;
} elseif (isset($array->description)) {
$subtitle = $array->description;
}
if (!empty($subtitle)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:subtitle', $subtitle);
$root->appendChild($node);
}
$summary = '';
if (isset($array->itunes->summary)) {
$summary = $array->itunes->summary;
} elseif (isset($array->description)) {
$summary = $array->description;
}
if (!empty($summary)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:summary', $summary);
$root->appendChild($node);
}
if (isset($array->itunes->block)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:block', $array->itunes->block);
$root->appendChild($node);
}
if (isset($array->itunes->explicit)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:explicit', $array->itunes->explicit);
$root->appendChild($node);
}
if (isset($array->itunes->keywords)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:keywords', $array->itunes->keywords);
$root->appendChild($node);
}
if (isset($array->itunes->new_feed_url)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:new-feed-url', $array->itunes->new_feed_url);
$root->appendChild($node);
}
if (isset($array->itunes->category)) {
foreach ($array->itunes->category as $i => $category) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$node->setAttribute('text', $category['main']);
$root->appendChild($node);
$add_end_category = false;
if (!empty($category['sub'])) {
$add_end_category = true;
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$node->setAttribute('text', $category['sub']);
$root->appendChild($node);
}
if ($i > 0 || $add_end_category) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$root->appendChild($node);
}
}
}
}
/**
* Generate the entries of the feed when working in write mode
*
* The following nodes are constructed for each feed entry
* <item>
* <title>entry title</title>
* <link>url to feed entry</link>
* <guid>url to feed entry</guid>
* <description>short text</description>
* <content:encoded>long version, can contain html</content:encoded>
* </item>
*
* @param DOMElement $root the root node to use
* @param array $array the data to use
* @return void
*/
protected function _mapFeedEntries(DOMElement $root, $array)
{
Zend_Feed::registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
foreach ($array as $dataentry) {
$item = $this->_element->createElement('item');
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($dataentry->title));
$item->appendChild($title);
$link = $this->_element->createElement('link', $dataentry->link);
$item->appendChild($link);
if (isset($dataentry->guid)) {
$guid = $this->_element->createElement('guid', $dataentry->guid);
$item->appendChild($guid);
}
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($dataentry->description));
$item->appendChild($description);
if (isset($dataentry->content)) {
$content = $this->_element->createElement('content:encoded');
$content->appendChild($this->_element->createCDATASection($dataentry->content));
$item->appendChild($content);
}
$pubdate = isset($dataentry->lastUpdate) ? $dataentry->lastUpdate : time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r', $pubdate));
$item->appendChild($pubdate);
if (isset($dataentry->category)) {
foreach ($dataentry->category as $category) {
$node = $this->_element->createElement('category', $category['term']);
if (isset($category['scheme'])) {
$node->setAttribute('domain', $category['scheme']);
}
$item->appendChild($node);
}
}
if (isset($dataentry->source)) {
$source = $this->_element->createElement('source', $dataentry->source['title']);
$source->setAttribute('url', $dataentry->source['url']);
$item->appendChild($source);
}
if (isset($dataentry->comments)) {
$comments = $this->_element->createElement('comments', $dataentry->comments);
$item->appendChild($comments);
}
if (isset($dataentry->commentRss)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:commentRss',
$dataentry->commentRss);
$item->appendChild($comments);
}
if (isset($dataentry->enclosure)) {
foreach ($dataentry->enclosure as $enclosure) {
$node = $this->_element->createElement('enclosure');
$node->setAttribute('url', $enclosure['url']);
if (isset($enclosure['type'])) {
$node->setAttribute('type', $enclosure['type']);
}
if (isset($enclosure['length'])) {
$node->setAttribute('length', $enclosure['length']);
}
$item->appendChild($node);
}
}
$root->appendChild($item);
}
}
/**
* Override Zend_Feed_Element to include <rss> root node
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$root = $doc->createElement('rss');
// Use rss version 2.0
$root->setAttribute('version', '2.0');
// Content namespace
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:content', 'http://purl.org/rss/1.0/modules/content/');
$root->appendChild($doc->importNode($this->_element, true));
// Append root node
$doc->appendChild($root);
// Format output
$doc->formatOutput = true;
return $doc->saveXML();
}
/**
* Send feed to a http client with the correct header
*
* @return void
* @throws Zend_Feed_Exception if headers have already been sent
*/
public function send()
{
if (headers_sent()) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot send RSS because headers have already been sent.');
}
header('Content-Type: application/rss+xml; charset=' . $this->_element->ownerDocument->actualEncoding);
echo $this->saveXml();
}
}
Feed/Exception.php 0000604 00000002235 15071256134 0010060 0 ustar 00 <?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_Feed
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Feed exceptions
*
* Class to represent exceptions that occur during Feed operations.
*
* @category Zend
* @package Zend_Feed
* @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_Feed_Exception extends Zend_Exception
{}
Date/DateObject.php 0000604 00000112422 15071256134 0010140 0 ustar 00 <?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_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: DateObject.php 13319 2008-12-16 09:27:04Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_DateObject
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Date_DateObject {
/**
* UNIX Timestamp
*/
private $_unixTimestamp;
protected static $_cache = null;
protected static $_defaultOffset = 0;
/**
* active timezone
*/
private $_timezone = 'UTC';
private $_offset = 0;
private $_syncronised = 0;
// turn off DST correction if UTC or GMT
protected $_dst = true;
/**
* Table of Monthdays
*/
private static $_monthTable = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
/**
* Table of Years
*/
private static $_yearTable = array(
1970 => 0, 1960 => -315619200, 1950 => -631152000,
1940 => -946771200, 1930 => -1262304000, 1920 => -1577923200,
1910 => -1893456000, 1900 => -2208988800, 1890 => -2524521600,
1880 => -2840140800, 1870 => -3155673600, 1860 => -3471292800,
1850 => -3786825600, 1840 => -4102444800, 1830 => -4417977600,
1820 => -4733596800, 1810 => -5049129600, 1800 => -5364662400,
1790 => -5680195200, 1780 => -5995814400, 1770 => -6311347200,
1760 => -6626966400, 1750 => -6942499200, 1740 => -7258118400,
1730 => -7573651200, 1720 => -7889270400, 1710 => -8204803200,
1700 => -8520336000, 1690 => -8835868800, 1680 => -9151488000,
1670 => -9467020800, 1660 => -9782640000, 1650 => -10098172800,
1640 => -10413792000, 1630 => -10729324800, 1620 => -11044944000,
1610 => -11360476800, 1600 => -11676096000);
/**
* Set this object to have a new UNIX timestamp.
*
* @param string|integer $timestamp OPTIONAL timestamp; defaults to local time using time()
* @return string|integer old timestamp
* @throws Zend_Date_Exception
*/
protected function setUnixTimestamp($timestamp = null)
{
$old = $this->_unixTimestamp;
if (is_numeric($timestamp)) {
$this->_unixTimestamp = $timestamp;
} else if ($timestamp === null) {
$this->_unixTimestamp = time();
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('\'' . $timestamp . '\' is not a valid UNIX timestamp', $timestamp);
}
return $old;
}
/**
* Returns this object's UNIX timestamp
* A timestamp greater then the integer range will be returned as string
* This function does not return the timestamp as object. Use copy() instead.
*
* @return integer|string timestamp
*/
protected function getUnixTimestamp()
{
if ($this->_unixTimestamp === intval($this->_unixTimestamp)) {
return (int) $this->_unixTimestamp;
} else {
return (string) $this->_unixTimestamp;
}
}
/**
* Internal function.
* Returns time(). This method exists to allow unit tests to work-around methods that might otherwise
* be hard-coded to use time(). For example, this makes it possible to test isYesterday() in Date.php.
*
* @param integer $sync OPTIONAL time syncronisation value
* @return integer timestamp
*/
protected function _getTime($sync = null)
{
if ($sync !== null) {
$this->_syncronised = round($sync);
}
return (time() + $this->_syncronised);
}
/**
* Internal mktime function used by Zend_Date.
* The timestamp returned by mktime() can exceed the precision of traditional UNIX timestamps,
* by allowing PHP to auto-convert to using a float value.
*
* Returns a timestamp relative to 1970/01/01 00:00:00 GMT/UTC.
* DST (Summer/Winter) is depriciated since php 5.1.0.
* Year has to be 4 digits otherwise it would be recognised as
* year 70 AD instead of 1970 AD as expected !!
*
* @param integer $hour
* @param integer $minute
* @param integer $second
* @param integer $month
* @param integer $day
* @param integer $year
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return integer|float timestamp (number of seconds elapsed relative to 1970/01/01 00:00:00 GMT/UTC)
*/
protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
{
// complete date but in 32bit timestamp - use PHP internal
if ((1901 < $year) and ($year < 2038)) {
$oldzone = @date_default_timezone_get();
// Timezone also includes DST settings, therefor substracting the GMT offset is not enough
// We have to set the correct timezone to get the right value
if (($this->_timezone != $oldzone) and ($gmt === false)) {
date_default_timezone_set($this->_timezone);
}
$result = ($gmt) ? @gmmktime($hour, $minute, $second, $month, $day, $year)
: @mktime($hour, $minute, $second, $month, $day, $year);
date_default_timezone_set($oldzone);
return $result;
}
if ($gmt !== true) {
$second += $this->_offset;
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_mkTime_' . $this->_offset . '_' . $year.$month.$day.'_'.$hour.$minute.$second . '_'.(int)$gmt, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
// date to integer
$day = intval($day);
$month = intval($month);
$year = intval($year);
// correct months > 12 and months < 1
if ($month > 12) {
$overlap = floor($month / 12);
$year += $overlap;
$month -= $overlap * 12;
} else {
$overlap = ceil((1 - $month) / 12);
$year -= $overlap;
$month += $overlap * 12;
}
$date = 0;
if ($year >= 1970) {
// Date is after UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1970; $count <= $year; $count++) {
$leapyear = self::isYearLeapYear($count);
if ($count < $year) {
$date += 365;
if ($leapyear === true) {
$date++;
}
} else {
for ($mcount = 0; $mcount < ($month - 1); $mcount++) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += $day - 1;
$date = (($date * 86400) + ($hour * 3600) + ($minute * 60) + $second);
} else {
// Date is before UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1969; $count >= $year; $count--) {
$leapyear = self::isYearLeapYear($count);
if ($count > $year)
{
$date += 365;
if ($leapyear === true)
$date++;
} else {
for ($mcount = 11; $mcount > ($month - 1); $mcount--) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += (self::$_monthTable[$month - 1] - $day);
$date = -(($date * 86400) + (86400 - (($hour * 3600) + ($minute * 60) + $second)));
// gregorian correction for 5.Oct.1582
if ($date < -12220185600) {
$date += 864000;
} else if ($date < -12219321600) {
$date = -12219321600;
}
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($date), $id);
}
return $date;
}
/**
* Returns true, if given $year is a leap year.
*
* @param integer $year
* @return boolean true, if year is leap year
*/
protected static function isYearLeapYear($year)
{
// all leapyears can be divided through 4
if (($year % 4) != 0) {
return false;
}
// all leapyears can be divided through 400
if ($year % 400 == 0) {
return true;
} else if (($year > 1582) and ($year % 100 == 0)) {
return false;
}
return true;
}
/**
* Internal mktime function used by Zend_Date for handling 64bit timestamps.
*
* Returns a formatted date for a given timestamp.
*
* @param string $format format for output
* @param mixed $timestamp
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return string
*/
protected function date($format, $timestamp = null, $gmt = false)
{
$oldzone = @date_default_timezone_get();
if ($this->_timezone != $oldzone) {
date_default_timezone_set($this->_timezone);
}
if ($timestamp === null) {
$result = ($gmt) ? @gmdate($format) : @date($format);
date_default_timezone_set($oldzone);
return $result;
}
if (abs($timestamp) <= 0x7FFFFFFF) {
$result = ($gmt) ? @gmdate($format, $timestamp) : @date($format, $timestamp);
date_default_timezone_set($oldzone);
return $result;
}
$jump = false;
if (isset(self::$_cache)) {
$idstamp = strtr('Zend_DateObject_date_' . $this->_offset . '_'. $timestamp . '_'.(int)$gmt, '-','_');
if ($result2 = self::$_cache->load($idstamp)) {
$timestamp = unserialize($result2);
$jump = true;
}
}
// check on false or null alone failes
if (empty($gmt) and empty($jump)) {
$tempstamp = $timestamp;
if ($tempstamp > 0) {
while (abs($tempstamp) > 0x7FFFFFFF) {
$tempstamp -= (86400 * 23376);
}
$dst = date("I", $tempstamp);
if ($dst === 1) {
$timestamp += 3600;
}
$temp = date('Z', $tempstamp);
$timestamp += $temp;
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($timestamp), $idstamp);
}
}
if (($timestamp < 0) and ($gmt !== true)) {
$timestamp -= $this->_offset;
}
date_default_timezone_set($oldzone);
$date = $this->getDateParts($timestamp, true);
$length = strlen($format);
$output = '';
for ($i = 0; $i < $length; $i++) {
switch($format[$i]) {
// day formats
case 'd': // day of month, 2 digits, with leading zero, 01 - 31
$output .= (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']);
break;
case 'D': // day of week, 3 letters, Mon - Sun
$output .= date('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'j': // day of month, without leading zero, 1 - 31
$output .= $date['mday'];
break;
case 'l': // day of week, full string name, Sunday - Saturday
$output .= date('l', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'N': // ISO 8601 numeric day of week, 1 - 7
$day = self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
if ($day == 0) {
$day = 7;
}
$output .= $day;
break;
case 'S': // english suffix for day of month, st nd rd th
if (($date['mday'] % 10) == 1) {
$output .= 'st';
} else if ((($date['mday'] % 10) == 2) and ($date['mday'] != 12)) {
$output .= 'nd';
} else if (($date['mday'] % 10) == 3) {
$output .= 'rd';
} else {
$output .= 'th';
}
break;
case 'w': // numeric day of week, 0 - 6
$output .= self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
break;
case 'z': // day of year, 0 - 365
$output .= $date['yday'];
break;
// week formats
case 'W': // ISO 8601, week number of year
$output .= $this->weekNumber($date['year'], $date['mon'], $date['mday']);
break;
// month formats
case 'F': // string month name, january - december
$output .= date('F', mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'm': // number of month, with leading zeros, 01 - 12
$output .= (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']);
break;
case 'M': // 3 letter month name, Jan - Dec
$output .= date('M',mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'n': // number of month, without leading zeros, 1 - 12
$output .= $date['mon'];
break;
case 't': // number of day in month
$output .= self::$_monthTable[$date['mon'] - 1];
break;
// year formats
case 'L': // is leap year ?
$output .= (self::isYearLeapYear($date['year'])) ? '1' : '0';
break;
case 'o': // ISO 8601 year number
$week = $this->weekNumber($date['year'], $date['mon'], $date['mday']);
if (($week > 50) and ($date['mon'] == 1)) {
$output .= ($date['year'] - 1);
} else {
$output .= $date['year'];
}
break;
case 'Y': // year number, 4 digits
$output .= $date['year'];
break;
case 'y': // year number, 2 digits
$output .= substr($date['year'], strlen($date['year']) - 2, 2);
break;
// time formats
case 'a': // lower case am/pm
$output .= (($date['hours'] >= 12) ? 'pm' : 'am');
break;
case 'A': // upper case am/pm
$output .= (($date['hours'] >= 12) ? 'PM' : 'AM');
break;
case 'B': // swatch internet time
$dayseconds = ($date['hours'] * 3600) + ($date['minutes'] * 60) + $date['seconds'];
if ($gmt === true) {
$dayseconds += 3600;
}
$output .= (int) (($dayseconds % 86400) / 86.4);
break;
case 'g': // hours without leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= $hour;
break;
case 'G': // hours without leading zeros, 24h format
$output .= $date['hours'];
break;
case 'h': // hours with leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= (($hour < 10) ? '0'.$hour : $hour);
break;
case 'H': // hours with leading zeros, 24h format
$output .= (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']);
break;
case 'i': // minutes with leading zeros
$output .= (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']);
break;
case 's': // seconds with leading zeros
$output .= (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);
break;
// timezone formats
case 'e': // timezone identifier
if ($gmt === true) {
$output .= gmdate('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'I': // daylight saving time or not
if ($gmt === true) {
$output .= gmdate('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'O': // difference to GMT in hours
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$output .= sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
break;
case 'P': // difference to GMT with colon
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$gmtstr = sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
$output = $output . substr($gmtstr, 0, 3) . ':' . substr($gmtstr, 3);
break;
case 'T': // timezone settings
if ($gmt === true) {
$output .= gmdate('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'Z': // timezone offset in seconds
$output .= ($gmt === true) ? 0 : -$this->_offset;
break;
// complete time formats
case 'c': // ISO 8601 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= $date['year'] . '-'
. (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']) . '-'
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . 'T'
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds'])
. $difference;
break;
case 'r': // RFC 2822 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= gmdate('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday']))) . ', '
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . ' '
. date('M', mktime(0, 0, 0, $date['mon'], 2, 1971)) . ' '
. $date['year'] . ' '
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']) . ' '
. $difference;
break;
case 'U': // Unix timestamp
$output .= $timestamp;
break;
// special formats
case "\\": // next letter to print with no format
$i++;
if ($i < $length) {
$output .= $format[$i];
}
break;
default: // letter is no format so add it direct
$output .= $format[$i];
break;
}
}
return (string) $output;
}
/**
* Returns the day of week for a Gregorian calendar date.
* 0 = sunday, 6 = saturday
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer dayOfWeek
*/
protected static function dayOfWeek($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('w', mktime(0, 0, 0, $month, $day, $year));
}
// gregorian correction
$correction = 0;
if (($year < 1582) or (($year == 1582) and (($month < 10) or (($month == 10) && ($day < 15))))) {
$correction = 3;
}
if ($month > 2) {
$month -= 2;
} else {
$month += 10;
$year--;
}
$day = floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4);
$day += floor(($year / 100) / 4) - 2 * floor($year / 100) + 77 + $correction;
return (int) ($day - 7 * floor($day / 7));
}
/**
* Internal getDateParts function for handling 64bit timestamps, similar to:
* http://www.php.net/getdate
*
* Returns an array of date parts for $timestamp, relative to 1970/01/01 00:00:00 GMT/UTC.
*
* $fast specifies ALL date parts should be returned (slower)
* Default is false, and excludes $dayofweek, weekday, month and timestamp from parts returned.
*
* @param mixed $timestamp
* @param boolean $fast OPTIONAL defaults to fast (false), resulting in fewer date parts
* @return array
*/
protected function getDateParts($timestamp = null, $fast = null)
{
// actual timestamp
if ($timestamp === null) {
return getdate();
}
// 32bit timestamp
if (abs($timestamp) <= 0x7FFFFFFF) {
return @getdate($timestamp);
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_getDateParts_' . $timestamp.'_'.(int)$fast, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
$otimestamp = $timestamp;
$numday = 0;
$month = 0;
// gregorian correction
if ($timestamp < -12219321600) {
$timestamp -= 864000;
}
// timestamp lower 0
if ($timestamp < 0) {
$sec = 0;
$act = 1970;
// iterate through 10 years table, increasing speed
foreach(self::$_yearTable as $year => $seconds) {
if ($timestamp >= $seconds) {
$i = $act;
break;
}
$sec = $seconds;
$act = $year;
}
$timestamp -= $sec;
if (!isset($i)) {
$i = $act;
}
// iterate the max last 10 years
do {
--$i;
$day = $timestamp;
$timestamp += 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$year = $i;
break;
}
} while ($timestamp < 0);
$secondsPerYear = 86400 * ($leapyear ? 366 : 365) + $day;
$timestamp = $day;
// iterate through months
for ($i = 12; --$i >= 0;) {
$day = $timestamp;
$timestamp += self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = $numday + ceil(($timestamp + 1) / 86400);
$timestamp += ($numday - $numberdays + 1) * 86400;
$hours = floor($timestamp / 3600);
} else {
// iterate through years
for ($i = 1970;;$i++) {
$day = $timestamp;
$timestamp -= 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$year = $i;
break;
}
}
$secondsPerYear = $day;
$timestamp = $day;
// iterate through months
for ($i = 0; $i <= 11; $i++) {
$day = $timestamp;
$timestamp -= self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = ceil(($timestamp + 1) / 86400);
$timestamp = $timestamp - ($numberdays - 1) * 86400;
$hours = floor($timestamp / 3600);
}
$timestamp -= $hours * 3600;
$month += 1;
$minutes = floor($timestamp / 60);
$seconds = $timestamp - $minutes * 60;
if ($fast === true) {
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
);
} else {
$dayofweek = self::dayOfWeek($year, $month, $numberdays);
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'wday' => $dayofweek,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
'weekday' => gmdate('l', 86400 * (3 + $dayofweek)),
'month' => gmdate('F', mktime(0, 0, 0, $month, 1, 1971)),
0 => $otimestamp
);
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($array), $id);
}
return $array;
}
/**
* Internal getWeekNumber function for handling 64bit timestamps
*
* Returns the ISO 8601 week number of a given date
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer
*/
protected function weekNumber($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('W', mktime(0, 0, 0, $month, $day, $year));
}
$dayofweek = self::dayOfWeek($year, $month, $day);
$firstday = self::dayOfWeek($year, 1, 1);
if (($month == 1) and (($firstday < 1) or ($firstday > 4)) and ($day < 4)) {
$firstday = self::dayOfWeek($year - 1, 1, 1);
$month = 12;
$day = 31;
} else if (($month == 12) and ((self::dayOfWeek($year + 1, 1, 1) < 5) and
(self::dayOfWeek($year + 1, 1, 1) > 0))) {
return 1;
}
return intval (((self::dayOfWeek($year, 1, 1) < 5) and (self::dayOfWeek($year, 1, 1) > 0)) +
4 * ($month - 1) + (2 * ($month - 1) + ($day - 1) + $firstday - $dayofweek + 6) * 36 / 256);
}
/**
* Internal _range function
* Sets the value $a to be in the range of [0, $b]
*
* @param float $a - value to correct
* @param float $b - maximum range to set
*/
private function _range($a, $b) {
while ($a < 0) {
$a += $b;
}
while ($a >= $b) {
$a -= $b;
}
return $a;
}
/**
* Calculates the sunrise or sunset based on a location
*
* @param array $location Location for calculation MUST include 'latitude', 'longitude', 'horizon'
* @param bool $horizon true: sunrise; false: sunset
* @return mixed - false: midnight sun, integer:
*/
protected function calcSun($location, $horizon, $rise = false)
{
// timestamp within 32bit
if (abs($this->_unixTimestamp) <= 0x7FFFFFFF) {
if ($rise === false) {
return date_sunset($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'],
$location['longitude'], 90 + $horizon, $this->_offset / 3600);
}
return date_sunrise($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'],
$location['longitude'], 90 + $horizon, $this->_offset / 3600);
}
// self calculation - timestamp bigger than 32bit
// fix circle values
$quarterCircle = 0.5 * M_PI;
$halfCircle = M_PI;
$threeQuarterCircle = 1.5 * M_PI;
$fullCircle = 2 * M_PI;
// radiant conversion for coordinates
$radLatitude = $location['latitude'] * $halfCircle / 180;
$radLongitude = $location['longitude'] * $halfCircle / 180;
// get solar coordinates
$tmpRise = $rise ? $quarterCircle : $threeQuarterCircle;
$radDay = $this->date('z',$this->_unixTimestamp) + ($tmpRise - $radLongitude) / $fullCircle;
// solar anomoly and longitude
$solAnomoly = $radDay * 0.017202 - 0.0574039;
$solLongitude = $solAnomoly + 0.0334405 * sin($solAnomoly);
$solLongitude += 4.93289 + 3.49066E-4 * sin(2 * $solAnomoly);
// get quadrant
$solLongitude = $this->_range($solLongitude, $fullCircle);
if (($solLongitude / $quarterCircle) - intval($solLongitude / $quarterCircle) == 0) {
$solLongitude += 4.84814E-6;
}
// solar ascension
$solAscension = sin($solLongitude) / cos($solLongitude);
$solAscension = atan2(0.91746 * $solAscension, 1);
// adjust quadrant
if ($solLongitude > $threeQuarterCircle) {
$solAscension += $fullCircle;
} else if ($solLongitude > $quarterCircle) {
$solAscension += $halfCircle;
}
// solar declination
$solDeclination = 0.39782 * sin($solLongitude);
$solDeclination /= sqrt(-$solDeclination * $solDeclination + 1);
$solDeclination = atan2($solDeclination, 1);
$solHorizon = $horizon - sin($solDeclination) * sin($radLatitude);
$solHorizon /= cos($solDeclination) * cos($radLatitude);
// midnight sun, always night
if (abs($solHorizon) > 1) {
return false;
}
$solHorizon /= sqrt(-$solHorizon * $solHorizon + 1);
$solHorizon = $quarterCircle - atan2($solHorizon, 1);
if ($rise) {
$solHorizon = $fullCircle - $solHorizon;
}
// time calculation
$localTime = $solHorizon + $solAscension - 0.0172028 * $radDay - 1.73364;
$universalTime = $localTime - $radLongitude;
// determinate quadrant
$universalTime = $this->_range($universalTime, $fullCircle);
// radiant to hours
$universalTime *= 24 / $fullCircle;
// convert to time
$hour = intval($universalTime);
$universalTime = ($universalTime - $hour) * 60;
$min = intval($universalTime);
$universalTime = ($universalTime - $min) * 60;
$sec = intval($universalTime);
return $this->mktime($hour, $min, $sec, $this->date('m', $this->_unixTimestamp),
$this->date('j', $this->_unixTimestamp), $this->date('Y', $this->_unixTimestamp),
-1, true);
}
/**
* Sets a new timezone for calculation of $this object's gmt offset.
* For a list of supported timezones look here: http://php.net/timezones
* If no timezone can be detected or the given timezone is wrong UTC will be set.
*
* @param string $zone OPTIONAL timezone for date calculation; defaults to date_default_timezone_get()
* @return Zend_Date_DateObject Provides fluent interface
* @throws Zend_Date_Exception
*/
public function setTimezone($zone = null)
{
$oldzone = @date_default_timezone_get();
if ($zone === null) {
$zone = $oldzone;
}
// throw an error on false input, but only if the new date extension is available
if (function_exists('timezone_open')) {
if (!@timezone_open($zone)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("timezone ($zone) is not a known timezone", $zone);
}
}
// this can generate an error if the date extension is not available and a false timezone is given
$result = @date_default_timezone_set($zone);
if ($result === true) {
$this->_offset = mktime(0, 0, 0, 1, 2, 1970) - gmmktime(0, 0, 0, 1, 2, 1970);
$this->_timezone = $zone;
}
date_default_timezone_set($oldzone);
if (($zone == 'UTC') or ($zone == 'GMT')) {
$this->_dst = false;
} else {
$this->_dst = true;
}
return $this;
}
/**
* Return the timezone of $this object.
* The timezone is initially set when the object is instantiated.
*
* @return string actual set timezone string
*/
public function getTimezone()
{
return $this->_timezone;
}
/**
* Return the offset to GMT of $this object's timezone.
* The offset to GMT is initially set when the object is instantiated using the currently,
* in effect, default timezone for PHP functions.
*
* @return integer seconds difference between GMT timezone and timezone when object was instantiated
*/
public function getGmtOffset()
{
return $this->_offset;
}
}
Date/Exception.php 0000604 00000002456 15071256134 0010077 0 ustar 00 <?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_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Date
* @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_Date_Exception extends Zend_Exception
{
protected $operand = null;
public function __construct($message, $op = null)
{
$this->operand = $op;
parent::__construct($message);
}
public function getOperand()
{
return $this->operand;
}
}
Date/Cities.php 0000604 00000056357 15071256134 0007372 0 ustar 00 <?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_Date
* @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: DateObject.php 2511 2006-12-26 22:54:37Z bkarwin $
*/
/**
* Additional data for sunset/sunrise calculations
*
* Holds the geographical data for all capital cities and many others worldwide
* Original data from http://www.fallingrain.com/world/
*
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_Cities
* @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_Date_Cities
{
/**
* Array Collection of known cities
*
* The array contains 'latitude' and 'longitude' for every known city
*
* @var Array
*/
public static $cities = array(
'Abidjan' => array('latitude' => 5.3411111, 'longitude' => -4.0280556),
'Abu Dhabi' => array('latitude' => 24.4666667, 'longitude' => 54.3666667),
'Abuja' => array('latitude' => 9.1758333, 'longitude' => 7.1808333),
'Accra' => array('latitude' => 5.55, 'longitude' => -0.2166667),
'Adamstown' => array('latitude' => -25.0666667, 'longitude' => -130.0833333),
'Addis Ababa' => array('latitude' => 9.0333333, 'longitude' => 38.7),
'Adelaide' => array('latitude' => -34.9333333, 'longitude' => 138.6),
'Algiers' => array('latitude' => 36.7630556, 'longitude' => 3.0505556),
'Alofi' => array('latitude' => -19.0166667, 'longitude' => -169.9166667),
'Amman' => array('latitude' => 31.95, 'longitude' => 35.9333333),
'Amsterdam' => array('latitude' => 52.35, 'longitude' => 4.9166667),
'Andorra la Vella' => array('latitude' => 42.5, 'longitude' => 1.5166667),
'Ankara' => array('latitude' => 39.9272222, 'longitude' => 32.8644444),
'Antananarivo' => array('latitude' => -18.9166667, 'longitude' => 47.5166667),
'Apia' => array('latitude' => -13.8333333, 'longitude' => -171.7333333),
'Ashgabat' => array('latitude' => 37.95, 'longitude' => 58.3833333),
'Asmara' => array('latitude' => 15.3333333, 'longitude' => 38.9333333),
'Astana' => array('latitude' => 51.1811111, 'longitude' => 71.4277778),
'Asunción' => array('latitude' => -25.2666667, 'longitude' => -57.6666667),
'Athens' => array('latitude' => 37.9833333, 'longitude' => 23.7333333),
'Auckland' => array('latitude' => -36.8666667, 'longitude' => 174.7666667),
'Avarua' => array('latitude' => -21.2, 'longitude' => -159.7666667),
'Baghdad' => array('latitude' => 33.3386111, 'longitude' => 44.3938889),
'Baku' => array('latitude' => 40.3952778, 'longitude' => 49.8822222),
'Bamako' => array('latitude' => 12.65, 'longitude' => -8),
'Bandar Seri Begawan' => array('latitude' => 4.8833333, 'longitude' => 114.9333333),
'Bankok' => array('latitude' => 13.5833333, 'longitude' => 100.2166667),
'Bangui' => array('latitude' => 4.3666667, 'longitude' => 18.5833333),
'Banjul' => array('latitude' => 13.4530556, 'longitude' => -16.5775),
'Basel' => array('latitude' => 47.5666667, 'longitude' => 7.6),
'Basseterre' => array('latitude' => 17.3, 'longitude' => -62.7166667),
'Beijing' => array('latitude' => 39.9288889, 'longitude' => 116.3883333),
'Beirut' => array('latitude' => 33.8719444, 'longitude' => 35.5097222),
'Belgrade' => array('latitude' => 44.8186111, 'longitude' => 20.4680556),
'Belmopan' => array('latitude' => 17.25, 'longitude' => -88.7666667),
'Berlin' => array('latitude' => 52.5166667, 'longitude' => 13.4),
'Bern' => array('latitude' => 46.9166667, 'longitude' => 7.4666667),
'Bishkek' => array('latitude' => 42.8730556, 'longitude' => 74.6002778),
'Bissau' => array('latitude' => 11.85, 'longitude' => -15.5833333),
'Bloemfontein' => array('latitude' => -29.1333333, 'longitude' => 26.2),
'Bogotá' => array('latitude' => 4.6, 'longitude' => -74.0833333),
'Brasilia' => array('latitude' => -15.7833333, 'longitude' => -47.9166667),
'Bratislava' => array('latitude' => 48.15, 'longitude' => 17.1166667),
'Brazzaville' => array('latitude' => -4.2591667, 'longitude' => 15.2847222),
'Bridgetown' => array('latitude' => 13.1, 'longitude' => -59.6166667),
'Brisbane' => array('latitude' => -27.5, 'longitude' => 153.0166667),
'Brussels' => array('latitude' => 50.8333333, 'longitude' => 4.3333333),
'Bucharest' => array('latitude' => 44.4333333, 'longitude' => 26.1),
'Budapest' => array('latitude' => 47.5, 'longitude' => 19.0833333),
'Buenos Aires' => array('latitude' => -34.5875, 'longitude' => -58.6725),
'Bujumbura' => array('latitude' => -3.3761111, 'longitude' => 29.36),
'Cairo' => array('latitude' => 30.05, 'longitude' => 31.25),
'Calgary' => array('latitude' => 51.0833333, 'longitude' => -114.0833333),
'Canberra' => array('latitude' => -35.2833333, 'longitude' => 149.2166667),
'Cape Town' => array('latitude' => -33.9166667, 'longitude' => 18.4166667),
'Caracas' => array('latitude' => 10.5, 'longitude' => -66.9166667),
'Castries' => array('latitude' => 14, 'longitude' => -61),
'Charlotte Amalie' => array('latitude' => 18.34389, 'longitude' => -64.93111),
'Chicago' => array('latitude' => 41.85, 'longitude' => -87.65),
'Chisinau' => array('latitude' => 47.055556, 'longitude' => 28.8575),
'Cockburn Town' => array('latitude' => 21.4666667, 'longitude' => -71.1333333),
'Colombo' => array('latitude' => 6.9319444, 'longitude' => 79.8477778),
'Conakry' => array('latitude' => 9.5091667, 'longitude' => -13.7122222),
'Copenhagen' => array('latitude' => 55.6666667, 'longitude' => 12.5833333),
'Cotonou' => array('latitude' => 6.35, 'longitude' => 2.4333333),
'Dakar' => array('latitude' => 14.6708333, 'longitude' => -17.4380556),
'Damascus' => array('latitude' => 33.5, 'longitude' => 36.3),
'Dar es Salaam' => array('latitude' => -6.8, 'longitude' => 39.2833333),
'Dhaka' => array('latitude' => 23.7230556, 'longitude' => 90.4086111),
'Dili' => array('latitude' => -8.5586111, 'longitude' => 125.5736111),
'Djibouti' => array('latitude' => 11.595, 'longitude' => 43.1480556),
'Dodoma' => array('latitude' => -6.1833333, 'longitude' => 35.75),
'Doha' => array('latitude' => 25.2866667, 'longitude' => 51.5333333),
'Dubai' => array('latitude' => 25.2522222, 'longitude' => 55.28),
'Dublin' => array('latitude' => 53.3330556, 'longitude' => -6.2488889),
'Dushanbe' => array('latitude' => 38.56, 'longitude' => 68.7738889 ),
'Fagatogo' => array('latitude' => -14.2825, 'longitude' => -170.69),
'Fongafale' => array('latitude' => -8.5166667, 'longitude' => 179.2166667),
'Freetown' => array('latitude' => 8.49, 'longitude' => -13.2341667),
'Gaborone' => array('latitude' => -24.6463889, 'longitude' => 25.9119444),
'Geneva' => array('latitude' => 46.2, 'longitude' => 6.1666667),
'George Town' => array('latitude' => 19.3, 'longitude' => -81.3833333),
'Georgetown' => array('latitude' => 6.8, 'longitude' => -58.1666667),
'Gibraltar' => array('latitude' => 36.1333333, 'longitude' => -5.35),
'Glasgow' => array('latitude' => 55.8333333, 'longitude' => -4.25),
'Guatemala la Nueva' => array('latitude' => 14.6211111, 'longitude' => -90.5269444),
'Hagatna' => array('latitude' => 13.47417, 'longitude' => 144.74778),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Hamilton' => array('latitude' => 32.2941667, 'longitude' => -64.7838889),
'Hanoi' => array('latitude' => 21.0333333, 'longitude' => 105.85),
'Harare' => array('latitude' => -17.8177778, 'longitude' => 31.0447222),
'Havana' => array('latitude' => 23.1319444, 'longitude' => -82.3641667),
'Helsinki' => array('latitude' => 60.1755556, 'longitude' => 24.9341667),
'Honiara' => array('latitude' => -9.4333333, 'longitude' => 159.95),
'Islamabad' => array('latitude' => 30.8486111, 'longitude' => 72.4944444),
'Istanbul' => array('latitude' => 41.0186111, 'longitude' => 28.9647222),
'Jakarta' => array('latitude' => -6.1744444, 'longitude' => 106.8294444),
'Jamestown' => array('latitude' => -15.9333333, 'longitude' => -5.7166667),
'Jerusalem' => array('latitude' => 31.7666667, 'longitude' => 35.2333333),
'Johannesburg' => array('latitude' => -26.2, 'longitude' => 28.0833333),
'Kabul' => array('latitude' => 34.5166667, 'longitude' => 69.1833333),
'Kampala' => array('latitude' => 0.3155556, 'longitude' => 32.5655556),
'Kathmandu' => array('latitude' => 27.7166667, 'longitude' => 85.3166667),
'Khartoum' => array('latitude' => 15.5880556, 'longitude' => 32.5341667),
'Kigali' => array('latitude' => -1.9536111, 'longitude' => 30.0605556),
'Kingston' => array('latitude' => -29.05, 'longitude' => 167.95),
'Kingstown' => array('latitude' => 13.1333333, 'longitude' => -61.2166667),
'Kinshasa' => array('latitude' => -4.3, 'longitude' => 15.3),
'Kolkata' => array('latitude' => 22.5697222, 'longitude' => 88.3697222),
'Kuala Lumpur' => array('latitude' => 3.1666667, 'longitude' => 101.7),
'Kuwait City' => array('latitude' => 29.3697222, 'longitude' => 47.9783333),
'Kiev' => array('latitude' => 50.4333333, 'longitude' => 30.5166667),
'La Paz' => array('latitude' => -16.5, 'longitude' => -68.15),
'Libreville' => array('latitude' => 0.3833333, 'longitude' => 9.45),
'Lilongwe' => array('latitude' => -13.9833333, 'longitude' => 33.7833333),
'Lima' => array('latitude' => -12.05, 'longitude' => -77.05),
'Lisbon' => array('latitude' => 38.7166667, 'longitude' => -9.1333333),
'Ljubljana' => array('latitude' => 46.0552778, 'longitude' => 14.5144444),
'Lobamba' => array('latitude' => -26.4666667, 'longitude' => 31.2),
'Lomé' => array('latitude' => 9.7166667, 'longitude' => 38.3),
'London' => array('latitude' => 51.5, 'longitude' => -0.1166667),
'Los Angeles' => array('latitude' => 34.05222, 'longitude' => -118.24278),
'Luanda' => array('latitude' => -8.8383333, 'longitude' => 13.2344444),
'Lusaka' => array('latitude' => -15.4166667, 'longitude' => 28.2833333),
'Luxembourg' => array('latitude' => 49.6116667, 'longitude' => 6.13),
'Madrid' => array('latitude' => 40.4, 'longitude' => -3.6833333),
'Majuro' => array('latitude' => 7.1, 'longitude' => 171.3833333),
'Malabo' => array('latitude' => 3.75, 'longitude' => 8.7833333),
'Managua' => array('latitude' => 12.1508333, 'longitude' => -86.2683333),
'Manama' => array('latitude' => 26.2361111, 'longitude' => 50.5830556),
'Manila' => array('latitude' => 14.6041667, 'longitude' => 120.9822222),
'Maputo' => array('latitude' => -25.9652778, 'longitude' => 32.5891667),
'Maseru' => array('latitude' => -29.3166667, 'longitude' => 27.4833333),
'Mbabane' => array('latitude' => -26.3166667, 'longitude' => 31.1333333),
'Melbourne' => array('latitude' => -37.8166667, 'longitude' => 144.9666667),
'Melekeok' => array('latitude' => 7.4933333, 'longitude' => 134.6341667),
'Mexiko City' => array('latitude' => 19.4341667, 'longitude' => -99.1386111),
'Minsk' => array('latitude' => 53.9, 'longitude' => 27.5666667),
'Mogadishu' => array('latitude' => 2.0666667, 'longitude' => 45.3666667),
'Monaco' => array('latitude' => 43.7333333, 'longitude' => 7.4166667),
'Monrovia' => array('latitude' => 6.3105556, 'longitude' => -10.8047222),
'Montevideo' => array('latitude' => -34.8580556, 'longitude' => -56.1708333),
'Montreal' => array('latitude' => 45.5, 'longitude' => -73.5833333),
'Moroni' => array('latitude' => -11.7041667, 'longitude' => 43.2402778),
'Moscow' => array('latitude' => 55.7522222, 'longitude' => 37.6155556),
'Muscat' => array('latitude' => 23.6133333, 'longitude' => 58.5933333),
'Nairobi' => array('latitude' => -1.3166667, 'longitude' => 36.8333333),
'Nassau' => array('latitude' => 25.0833333, 'longitude' => -77.35),
'N´Djamena' => array('latitude' => 12.1130556, 'longitude' => 15.0491667),
'New Dehli' => array('latitude' => 28.6, 'longitude' => 77.2),
'New York' => array('latitude' => 40.71417, 'longitude' => -74.00639),
'Newcastle' => array('latitude' => -32.9166667, 'longitude' => 151.75),
'Niamey' => array('latitude' => 13.6666667, 'longitude' => 1.7833333),
'Nicosia' => array('latitude' => 35.1666667, 'longitude' => 33.3666667),
'Nouakchott' => array('latitude' => 18.0863889, 'longitude' => -15.9752778),
'Noumea' => array('latitude' => -22.2666667, 'longitude' => 166.45),
'Nuku´alofa' => array('latitude' => -21.1333333, 'longitude' => -175.2),
'Nuuk' => array('latitude' => 64.1833333, 'longitude' => -51.75),
'Oranjestad' => array('latitude' => 12.5166667, 'longitude' => -70.0333333),
'Oslo' => array('latitude' => 59.9166667, 'longitude' => 10.75),
'Ouagadougou' => array('latitude' => 12.3702778, 'longitude' => -1.5247222),
'Palikir' => array('latitude' => 6.9166667, 'longitude' => 158.15),
'Panama City' => array('latitude' => 8.9666667, 'longitude' => -79.5333333),
'Papeete' => array('latitude' => -17.5333333, 'longitude' => -149.5666667),
'Paramaribo' => array('latitude' => 5.8333333, 'longitude' => -55.1666667),
'Paris' => array('latitude' => 48.8666667, 'longitude' => 2.3333333),
'Perth' => array('latitude' => -31.9333333, 'longitude' => 115.8333333),
'Phnom Penh' => array('latitude' => 11.55, 'longitude' => 104.9166667),
'Podgorica' => array('latitude' => 43.7752778, 'longitude' => 19.6827778),
'Port Louis' => array('latitude' => -20.1666667, 'longitude' => 57.5),
'Port Moresby' => array('latitude' => -9.4647222, 'longitude' => 147.1925),
'Port-au-Prince' => array('latitude' => 18.5391667, 'longitude' => -72.335),
'Port of Spain' => array('latitude' => 10.6666667, 'longitude' => -61.5),
'Porto-Novo' => array('latitude' => 6.4833333, 'longitude' => 2.6166667),
'Prague' => array('latitude' => 50.0833333, 'longitude' => 14.4666667),
'Praia' => array('latitude' => 14.9166667, 'longitude' => -23.5166667),
'Pretoria' => array('latitude' => -25.7069444, 'longitude' => 28.2294444),
'Pyongyang' => array('latitude' => 39.0194444, 'longitude' => 125.7547222),
'Quito' => array('latitude' => -0.2166667, 'longitude' => -78.5),
'Rabat' => array('latitude' => 34.0252778, 'longitude' => -6.8361111),
'Reykjavik' => array('latitude' => 64.15, 'longitude' => -21.95),
'Riga' => array('latitude' => 56.95, 'longitude' => 24.1),
'Rio de Janero' => array('latitude' => -22.9, 'longitude' => -43.2333333),
'Road Town' => array('latitude' => 18.4166667, 'longitude' => -64.6166667),
'Rome' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Roseau' => array('latitude' => 15.3, 'longitude' => -61.4),
'Rotterdam' => array('latitude' => 51.9166667, 'longitude' => 4.5),
'Salvador' => array('latitude' => -12.9833333, 'longitude' => -38.5166667),
'San José' => array('latitude' => 9.9333333, 'longitude' => -84.0833333),
'San Juan' => array('latitude' => 18.46833, 'longitude' => -66.10611),
'San Marino' => array('latitude' => 43.5333333, 'longitude' => 12.9666667),
'San Salvador' => array('latitude' => 13.7086111, 'longitude' => -89.2030556),
'Sanaá' => array('latitude' => 15.3547222, 'longitude' => 44.2066667),
'Santa Cruz' => array('latitude' => -17.8, 'longitude' => -63.1666667),
'Santiago' => array('latitude' => -33.45, 'longitude' => -70.6666667),
'Santo Domingo' => array('latitude' => 18.4666667, 'longitude' => -69.9),
'Sao Paulo' => array('latitude' => -23.5333333, 'longitude' => -46.6166667),
'Sarajevo' => array('latitude' => 43.85, 'longitude' => 18.3833333),
'Seoul' => array('latitude' => 37.5663889, 'longitude' => 126.9997222),
'Shanghai' => array('latitude' => 31.2222222, 'longitude' => 121.4580556),
'Sydney' => array('latitude' => -33.8833333, 'longitude' => 151.2166667),
'Singapore' => array('latitude' => 1.2930556, 'longitude' => 103.8558333),
'Skopje' => array('latitude' => 42, 'longitude' => 21.4333333),
'Sofia' => array('latitude' => 42.6833333, 'longitude' => 23.3166667),
'St. George´s' => array('latitude' => 12.05, 'longitude' => -61.75),
'St. John´s' => array('latitude' => 17.1166667, 'longitude' => -61.85),
'Stanley' => array('latitude' => -51.7, 'longitude' => -57.85),
'Stockholm' => array('latitude' => 59.3333333, 'longitude' => 18.05),
'Suva' => array('latitude' => -18.1333333, 'longitude' => 178.4166667),
'Taipei' => array('latitude' => 25.0166667, 'longitude' => 121.45),
'Tallinn' => array('latitude' => 59.4338889, 'longitude' => 24.7280556),
'Tashkent' => array('latitude' => 41.3166667, 'longitude' => 69.25),
'Tbilisi' => array('latitude' => 41.725, 'longitude' => 44.7908333),
'Tegucigalpa' => array('latitude' => 14.1, 'longitude' => -87.2166667),
'Tehran' => array('latitude' => 35.6719444, 'longitude' => 51.4244444),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Thimphu' => array('latitude' => 27.4833333, 'longitude' => 89.6),
'Tirana' => array('latitude' => 41.3275, 'longitude' => 19.8188889),
'Tiraspol' => array('latitude' => 46.8402778, 'longitude' => 29.6433333),
'Tokyo' => array('latitude' => 35.685, 'longitude' => 139.7513889),
'Toronto' => array('latitude' => 43.6666667, 'longitude' => -79.4166667),
'Tórshavn' => array('latitude' => 62.0166667, 'longitude' => -6.7666667),
'Tripoli' => array('latitude' => 32.8925, 'longitude' => 13.18),
'Tunis' => array('latitude' => 36.8027778, 'longitude' => 10.1797222),
'Ulaanbaatar' => array('latitude' => 47.9166667, 'longitude' => 106.9166667),
'Vaduz' => array('latitude' => 47.1333333, 'longitude' => 9.5166667),
'Valletta' => array('latitude' => 35.8997222, 'longitude' => 14.5147222),
'Valparaiso' => array('latitude' => -33.0477778, 'longitude' => -71.6011111),
'Vancouver' => array('latitude' => 49.25, 'longitude' => -123.1333333),
'Vatican City' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Victoria' => array('latitude' => -4.6166667, 'longitude' => 55.45),
'Vienna' => array('latitude' => 48.2, 'longitude' => 16.3666667),
'Vientaine' => array('latitude' => 17.9666667, 'longitude' => 102.6),
'Vilnius' => array('latitude' => 54.6833333, 'longitude' => 25.3166667),
'Warsaw' => array('latitude' => 52.25, 'longitude' => 21),
'Washington dc' => array('latitude' => 38.895, 'longitude' => -77.03667),
'Wellington' => array('latitude' => -41.3, 'longitude' => 174.7833333),
'Willemstad' => array('latitude' => 12.1, 'longitude' => -68.9166667),
'Windhoek' => array('latitude' => -22.57, 'longitude' => 17.0836111),
'Yamoussoukro' => array('latitude' => 6.8166667, 'longitude' => -5.2833333),
'Yaoundé' => array('latitude' => 3.8666667, 'longitude' => 11.5166667),
'Yerevan' => array('latitude' => 40.1811111, 'longitude' => 44.5136111),
'Zürich' => array('latitude' => 47.3666667, 'longitude' => 8.55),
'Zagreb' => array('latitude' => 45.8, 'longitude' => 16)
);
/**
* Returns the location from the selected city
*
* @param string $city City to get location for
* @param string $horizon Horizon to use :
* default: effective
* others are civil, nautic, astronomic
* @return array
* @throws Zend_Date_Exception When city is unknown
*/
public static function City($city, $horizon = false)
{
foreach (self::$cities as $key => $value) {
if (strtolower($key) === strtolower($city)) {
$return = $value;
$return['horizon'] = $horizon;
return $return;
}
}
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('unknown city');
}
/**
* Return a list with all known cities
*
* @return array
*/
public static function getCityList()
{
return array_keys(self::$cities);
}
}
Loader/PluginLoader.php 0000604 00000033577 15071256134 0011067 0 ustar 00 <?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_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Loader_PluginLoader_Interface */
require_once 'Zend/Loader/PluginLoader/Interface.php';
/** Zend_Loader */
require_once 'Zend/Loader.php';
/**
* Generic plugin class loader
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @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_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
{
/**
* Class map cache file
* @var string
*/
protected static $_includeFileCache;
/**
* Instance loaded plugin paths
*
* @var array
*/
protected $_loadedPluginPaths = array();
/**
* Instance loaded plugins
*
* @var array
*/
protected $_loadedPlugins = array();
/**
* Instance registry property
*
* @var array
*/
protected $_prefixToPaths = array();
/**
* Statically loaded plugin path mappings
*
* @var array
*/
protected static $_staticLoadedPluginPaths = array();
/**
* Statically loaded plugins
*
* @var array
*/
protected static $_staticLoadedPlugins = array();
/**
* Static registry property
*
* @var array
*/
protected static $_staticPrefixToPaths = array();
/**
* Whether to use a statically named registry for loading plugins
*
* @var string|null
*/
protected $_useStaticRegistry = null;
/**
* Constructor
*
* @param array $prefixToPaths
* @param string $staticRegistryName OPTIONAL
*/
public function __construct(Array $prefixToPaths = array(), $staticRegistryName = null)
{
if (is_string($staticRegistryName) && !empty($staticRegistryName)) {
$this->_useStaticRegistry = $staticRegistryName;
if(!isset(self::$_staticPrefixToPaths[$staticRegistryName])) {
self::$_staticPrefixToPaths[$staticRegistryName] = array();
}
if(!isset(self::$_staticLoadedPlugins[$staticRegistryName])) {
self::$_staticLoadedPlugins[$staticRegistryName] = array();
}
}
foreach ($prefixToPaths as $prefix => $path) {
$this->addPrefixPath($prefix, $path);
}
}
/**
* Format prefix for internal use
*
* @param string $prefix
* @return string
*/
protected function _formatPrefix($prefix)
{
return rtrim($prefix, '_') . '_';
}
/**
* Add prefixed paths to the registry of paths
*
* @param string $prefix
* @param string $path
* @return Zend_Loader_PluginLoader
*/
public function addPrefixPath($prefix, $path)
{
if (!is_string($prefix) || !is_string($path)) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Zend_Loader_PluginLoader::addPrefixPath() method only takes strings for prefix and path.');
}
$prefix = $this->_formatPrefix($prefix);
$path = rtrim($path, '/\\') . '/';
if ($this->_useStaticRegistry) {
self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix][] = $path;
} else {
$this->_prefixToPaths[$prefix][] = $path;
}
return $this;
}
/**
* Get path stack
*
* @param string $prefix
* @return false|array False if prefix does not exist, array otherwise
*/
public function getPaths($prefix = null)
{
if ((null !== $prefix) && is_string($prefix)) {
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix])) {
return self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix];
}
return false;
}
if (isset($this->_prefixToPaths[$prefix])) {
return $this->_prefixToPaths[$prefix];
}
return false;
}
if ($this->_useStaticRegistry) {
return self::$_staticPrefixToPaths[$this->_useStaticRegistry];
}
return $this->_prefixToPaths;
}
/**
* Clear path stack
*
* @param string $prefix
* @return bool False only if $prefix does not exist
*/
public function clearPaths($prefix = null)
{
if ((null !== $prefix) && is_string($prefix)) {
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix])) {
unset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix]);
return true;
}
return false;
}
if (isset($this->_prefixToPaths[$prefix])) {
unset($this->_prefixToPaths[$prefix]);
return true;
}
return false;
}
if ($this->_useStaticRegistry) {
self::$_staticPrefixToPaths[$this->_useStaticRegistry] = array();
} else {
$this->_prefixToPaths = array();
}
return true;
}
/**
* Remove a prefix (or prefixed-path) from the registry
*
* @param string $prefix
* @param string $path OPTIONAL
* @return Zend_Loader_PluginLoader
*/
public function removePrefixPath($prefix, $path = null)
{
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
$registry =& self::$_staticPrefixToPaths[$this->_useStaticRegistry];
} else {
$registry =& $this->_prefixToPaths;
}
if (!isset($registry[$prefix])) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' was not found in the PluginLoader.');
}
if ($path != null) {
$pos = array_search($path, $registry[$prefix]);
if ($pos === null) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' / Path ' . $path . ' was not found in the PluginLoader.');
}
unset($registry[$prefix][$pos]);
} else {
unset($registry[$prefix]);
}
return $this;
}
/**
* Normalize plugin name
*
* @param string $name
* @return string
*/
protected function _formatName($name)
{
return ucfirst((string) $name);
}
/**
* Whether or not a Plugin by a specific name is loaded
*
* @param string $name
* @return Zend_Loader_PluginLoader
*/
public function isLoaded($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry) {
return isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name]);
}
return isset($this->_loadedPlugins[$name]);
}
/**
* Return full class name for a named plugin
*
* @param string $name
* @return string|false False if class not found, class name otherwise
*/
public function getClassName($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry
&& isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name])
) {
return self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name];
} elseif (isset($this->_loadedPlugins[$name])) {
return $this->_loadedPlugins[$name];
}
return false;
}
/**
* Get path to plugin class
*
* @param mixed $name
* @return string|false False if not found
*/
public function getClassPath($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry
&& !empty(self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name])
) {
return self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name];
} elseif (!empty($this->_loadedPluginPaths[$name])) {
return $this->_loadedPluginPaths[$name];
}
if ($this->isLoaded($name)) {
$class = $this->getClassName($name);
$r = new ReflectionClass($class);
$path = $r->getFileName();
if ($this->_useStaticRegistry) {
self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = $path;
} else {
$this->_loadedPluginPaths[$name] = $path;
}
return $path;
}
return false;
}
/**
* Load a plugin via the name provided
*
* @param string $name
* @return string Class name of loaded class
* @throws Zend_Loader_Exception if class not found
*/
public function load($name)
{
$name = $this->_formatName($name);
if ($this->isLoaded($name)) {
return $this->getClassName($name);
}
if ($this->_useStaticRegistry) {
$registry = self::$_staticPrefixToPaths[$this->_useStaticRegistry];
} else {
$registry = $this->_prefixToPaths;
}
$registry = array_reverse($registry, true);
$found = false;
$classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
$incFile = self::getIncludeFileCache();
foreach ($registry as $prefix => $paths) {
$className = $prefix . $name;
if (class_exists($className, false)) {
$found = true;
break;
}
$paths = array_reverse($paths, true);
foreach ($paths as $path) {
$loadFile = $path . $classFile;
if (Zend_Loader::isReadable($loadFile)) {
include_once $loadFile;
if (class_exists($className, false)) {
if (null !== $incFile) {
self::_appendIncFile($loadFile);
}
$found = true;
break 2;
}
}
}
}
if (!$found) {
$message = "Plugin by name '$name' was not found in the registry; used paths:";
foreach ($registry as $prefix => $paths) {
$message .= "\n$prefix: " . implode(PATH_SEPARATOR, $paths);
}
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception($message);
}
if ($this->_useStaticRegistry) {
self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name] = $className;
self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = (isset($loadFile) ? $loadFile : '');
} else {
$this->_loadedPlugins[$name] = $className;
$this->_loadedPluginPaths[$name] = (isset($loadFile) ? $loadFile : '');
}
return $className;
}
/**
* Set path to class file cache
*
* Specify a path to a file that will add include_once statements for each
* plugin class loaded. This is an opt-in feature for performance purposes.
*
* @param string $file
* @return void
* @throws Zend_Loader_PluginLoader_Exception if file is not writeable or path does not exist
*/
public static function setIncludeFileCache($file)
{
if (null === $file) {
self::$_includeFileCache = null;
return;
}
if (!file_exists($file) && !file_exists(dirname($file))) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file does not exist and/or directory does not exist (' . $file . ')');
}
if (file_exists($file) && !is_writable($file)) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file is not writeable (' . $file . ')');
}
if (!file_exists($file) && file_exists(dirname($file)) && !is_writable(dirname($file))) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file is not writeable (' . $file . ')');
}
self::$_includeFileCache = $file;
}
/**
* Retrieve class file cache path
*
* @return string|null
*/
public static function getIncludeFileCache()
{
return self::$_includeFileCache;
}
/**
* Append an include_once statement to the class file cache
*
* @param string $incFile
* @return void
*/
protected static function _appendIncFile($incFile)
{
if (!file_exists(self::$_includeFileCache)) {
$file = '<?php';
} else {
$file = file_get_contents(self::$_includeFileCache);
}
if (!strstr($file, $incFile)) {
$file .= "\ninclude_once '$incFile';";
file_put_contents(self::$_includeFileCache, $file);
}
}
}
Loader/Exception.php 0000604 00000002155 15071256134 0010424 0 ustar 00 <?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_Loader
* @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: CamelCaseToUnderscore.php 6779 2007-11-08 15:10:41Z matthew $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Loader
* @uses Zend_Exception
* @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_Loader_Exception extends Zend_Exception
{} Loader/PluginLoader/Interface.php 0000604 00000003736 15071256134 0012761 0 ustar 00 <?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_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Plugin class loader interface
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Loader_PluginLoader_Interface
{
/**
* Add prefixed paths to the registry of paths
*
* @param string $prefix
* @param string $path
* @return Zend_Loader_PluginLoader
*/
public function addPrefixPath($prefix, $path);
/**
* Remove a prefix (or prefixed-path) from the registry
*
* @param string $prefix
* @param string $path OPTIONAL
* @return Zend_Loader_PluginLoader
*/
public function removePrefixPath($prefix, $path = null);
/**
* Whether or not a Helper by a specific name
*
* @param string $name
* @return Zend_Loader_PluginLoader
*/
public function isLoaded($name);
/**
* Return full class name for a named helper
*
* @param string $name
* @return string
*/
public function getClassName($name);
/**
* Load a helper via the name provided
*
* @param string $name
* @return string
*/
public function load($name);
}
Loader/PluginLoader/Exception.php 0000604 00000002175 15071256134 0013013 0 ustar 00 <?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_Loader
* @subpackage PluginLoader
* @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 Zend_Loader_Exception
*/
require_once 'Zend/Loader/Exception.php';
/**
* Plugin class loader exceptions
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @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_Loader_PluginLoader_Exception extends Zend_Loader_Exception
{
}
Filter.php 0000604 00000007451 15071256134 0006511 0 ustar 00 <?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_Filter
* @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: Filter.php 8434 2008-02-27 19:15:13Z darby $
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @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_Filter implements Zend_Filter_Interface
{
/**
* Filter chain
*
* @var array
*/
protected $_filters = array();
/**
* Adds a filter to the end of the chain
*
* @param Zend_Filter_Interface $filter
* @return Zend_Filter Provides a fluent interface
*/
public function addFilter(Zend_Filter_Interface $filter)
{
$this->_filters[] = $filter;
return $this;
}
/**
* Returns $value filtered through each filter in the chain
*
* Filters are run in the order in which they were added to the chain (FIFO)
*
* @param mixed $value
* @return mixed
*/
public function filter($value)
{
$valueFiltered = $value;
foreach ($this->_filters as $filter) {
$valueFiltered = $filter->filter($valueFiltered);
}
return $valueFiltered;
}
/**
* Returns a value filtered through a specified filter class, without requiring separate
* instantiation of the filter object.
*
* The first argument of this method is a data input value, that you would have filtered.
* The second argument is a string, which corresponds to the basename of the filter class,
* relative to the Zend_Filter namespace. This method automatically loads the class,
* creates an instance, and applies the filter() method to the data input. You can also pass
* an array of constructor arguments, if they are needed for the filter class.
*
* @param mixed $value
* @param string $classBaseName
* @param array $args OPTIONAL
* @param array|string $namespaces OPTIONAL
* @return mixed
* @throws Zend_Filter_Exception
*/
public static function get($value, $classBaseName, array $args = array(), $namespaces = array())
{
require_once 'Zend/Loader.php';
$namespaces = array_merge(array('Zend_Filter'), (array) $namespaces);
foreach ($namespaces as $namespace) {
$className = $namespace . '_' . ucfirst($classBaseName);
try {
@Zend_Loader::loadClass($className);
} catch (Zend_Exception $ze) {
continue;
}
$class = new ReflectionClass($className);
if ($class->implementsInterface('Zend_Filter_Interface')) {
if ($class->hasMethod('__construct')) {
$object = $class->newInstanceArgs($args);
} else {
$object = $class->newInstance();
}
return $object->filter($value);
}
}
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Filter class not found from basename '$classBaseName'");
}
}
Rest/Server.php 0000604 00000044767 15071256134 0007462 0 ustar 00 <?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_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Server_Interface
*/
require_once 'Zend/Server/Interface.php';
/**
* Zend_Server_Reflection
*/
require_once 'Zend/Server/Reflection.php';
/**
* Zend_Rest_Server_Exception
*/
require_once 'Zend/Rest/Server/Exception.php';
/**
* Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
/**
* @category Zend
* @package Zend_Rest
* @subpackage Server
* @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_Rest_Server implements Zend_Server_Interface
{
/**
* Class Constructor Args
* @var array
*/
protected $_args = array();
/**
* @var string Encoding
*/
protected $_encoding = 'UTF-8';
/**
* @var array An array of Zend_Server_Reflect_Method
*/
protected $_functions = array();
/**
* @var array Array of headers to send
*/
protected $_headers = array();
/**
* @var array PHP's Magic Methods, these are ignored
*/
protected static $magicMethods = array(
'__construct',
'__destruct',
'__get',
'__set',
'__call',
'__sleep',
'__wakeup',
'__isset',
'__unset',
'__tostring',
'__clone',
'__set_state',
);
/**
* @var string Current Method
*/
protected $_method;
/**
* @var Zend_Server_Reflection
*/
protected $_reflection = null;
/**
* Whether or not {@link handle()} should send output or return the response.
* @var boolean Defaults to false
*/
protected $_returnResponse = false;
/**
* Constructor
*/
public function __construct()
{
set_exception_handler(array($this, "fault"));
$this->_reflection = new Zend_Server_Reflection();
}
/**
* Set XML encoding
*
* @param string $encoding
* @return Zend_Rest_Server
*/
public function setEncoding($encoding)
{
$this->_encoding = (string) $encoding;
return $this;
}
/**
* Get XML encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Lowercase a string
*
* Lowercase's a string by reference
*
* @param string $value
* @param string $key
* @return string Lower cased string
*/
public static function lowerCase(&$value, &$key)
{
return $value = strtolower($value);
}
/**
* Whether or not to return a response
*
* If called without arguments, returns the value of the flag. If called
* with an argument, sets the flag.
*
* When 'return response' is true, {@link handle()} will not send output,
* but will instead return the response from the dispatched function/method.
*
* @param boolean $flag
* @return boolean|Zend_Rest_Server Returns Zend_Rest_Server when used to set the flag; returns boolean flag value otherwise.
*/
public function returnResponse($flag = null)
{
if (null == $flag) {
return $this->_returnResponse;
}
$this->_returnResponse = ($flag) ? true : false;
return $this;
}
/**
* Implement Zend_Server_Interface::handle()
*
* @param array $request
* @throws Zend_Rest_Server_Exception
* @return string|void
*/
public function handle($request = false)
{
$this->_headers = array('Content-Type: text/xml');
if (!$request) {
$request = $_REQUEST;
}
if (isset($request['method'])) {
$this->_method = $request['method'];
if (isset($this->_functions[$this->_method])) {
if ($this->_functions[$this->_method] instanceof Zend_Server_Reflection_Function || $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method && $this->_functions[$this->_method]->isPublic()) {
$request_keys = array_keys($request);
array_walk($request_keys, array(__CLASS__, "lowerCase"));
$request = array_combine($request_keys, $request);
$func_args = $this->_functions[$this->_method]->getParameters();
$calling_args = array();
foreach ($func_args as $arg) {
if (isset($request[strtolower($arg->getName())])) {
$calling_args[] = $request[strtolower($arg->getName())];
} elseif ($arg->isOptional()) {
$calling_args[] = $arg->getDefaultValue();
}
}
foreach ($request as $key => $value) {
if (substr($key, 0, 3) == 'arg') {
$key = str_replace('arg', '', $key);
$calling_args[$key] = $value;
}
}
// Sort arguments by key -- @see ZF-2279
ksort($calling_args);
$result = false;
if (count($calling_args) < count($func_args)) {
$result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Requires ' . count($func_args) . ', ' . count($calling_args) . ' given.'), 400);
}
if (!$result && $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method) {
// Get class
$class = $this->_functions[$this->_method]->getDeclaringClass()->getName();
if ($this->_functions[$this->_method]->isStatic()) {
// for some reason, invokeArgs() does not work the same as
// invoke(), and expects the first argument to be an object.
// So, using a callback if the method is static.
$result = $this->_callStaticMethod($class, $calling_args);
} else {
// Object method
$result = $this->_callObjectMethod($class, $calling_args);
}
} elseif (!$result) {
try {
$result = call_user_func_array($this->_functions[$this->_method]->getName(), $calling_args); //$this->_functions[$this->_method]->invokeArgs($calling_args);
} catch (Exception $e) {
$result = $this->fault($e);
}
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
404
);
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
404
);
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("No Method Specified."),
404
);
}
if ($result instanceof SimpleXMLElement) {
$response = $result->asXML();
} elseif ($result instanceof DOMDocument) {
$response = $result->saveXML();
} elseif ($result instanceof DOMNode) {
$response = $result->ownerDocument->saveXML($result);
} elseif (is_array($result) || is_object($result)) {
$response = $this->_handleStruct($result);
} else {
$response = $this->_handleScalar($result);
}
if (!$this->returnResponse()) {
if (!headers_sent()) {
foreach ($this->_headers as $header) {
header($header);
}
}
echo $response;
return;
}
return $response;
}
/**
* Implement Zend_Server_Interface::setClass()
*
* @param string $classname Class name
* @param string $namespace Class namespace (unused)
* @param array $argv An array of Constructor Arguments
*/
public function setClass($classname, $namespace = '', $argv = array())
{
$this->_args = $argv;
foreach ($this->_reflection->reflectClass($classname, $argv)->getMethods() as $method) {
$this->_functions[$method->getName()] = $method;
}
}
/**
* Handle an array or object result
*
* @param array|object $struct Result Value
* @return string XML Response
*/
protected function _handleStruct($struct)
{
$function = $this->_functions[$this->_method];
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
$method = $function->getName();
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$root = $dom->createElement($class);
$method = $dom->createElement($method);
$root->appendChild($method);
} else {
$root = $dom->createElement($method);
$method = $root;
}
$root->setAttribute('generator', 'zend');
$root->setAttribute('version', '1.0');
$dom->appendChild($root);
$this->_structValue($struct, $dom, $method);
$struct = (array) $struct;
if (!isset($struct['status'])) {
$status = $dom->createElement('status', 'success');
$method->appendChild($status);
}
return $dom->saveXML();
}
/**
* Recursively iterate through a struct
*
* Recursively iterates through an associative array or object's properties
* to build XML response.
*
* @param mixed $struct
* @param DOMDocument $dom
* @param DOMElement $parent
* @return void
*/
protected function _structValue($struct, DOMDocument $dom, DOMElement $parent)
{
$struct = (array) $struct;
foreach ($struct as $key => $value) {
if ($value === false) {
$value = 0;
} elseif ($value === true) {
$value = 1;
}
if (ctype_digit((string) $key)) {
$key = 'key_' . $key;
}
if (is_array($value) || is_object($value)) {
$element = $dom->createElement($key);
$this->_structValue($value, $dom, $element);
} else {
$element = $dom->createElement($key);
$element->appendChild($dom->createTextNode($value));
}
$parent->appendChild($element);
}
}
/**
* Handle a single value
*
* @param string|int|boolean $value Result value
* @return string XML Response
*/
protected function _handleScalar($value)
{
$function = $this->_functions[$this->_method];
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
$method = $function->getName();
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$xml = $dom->createElement($class);
$methodNode = $dom->createElement($method);
$xml->appendChild($methodNode);
} else {
$xml = $dom->createElement($method);
$methodNode = $xml;
}
$xml->setAttribute('generator', 'zend');
$xml->setAttribute('version', '1.0');
$dom->appendChild($xml);
if ($value === false) {
$value = 0;
} elseif ($value === true) {
$value = 1;
}
if (isset($value)) {
$element = $dom->createElement('response');
$element->appendChild($dom->createTextNode($value));
$methodNode->appendChild($element);
} else {
$methodNode->appendChild($dom->createElement('response'));
}
$methodNode->appendChild($dom->createElement('status', 'success'));
return $dom->saveXML();
}
/**
* Implement Zend_Server_Interface::fault()
*
* Creates XML error response, returning DOMDocument with response.
*
* @param string|Exception $fault Message
* @param int $code Error Code
* @return DOMDocument
*/
public function fault($exception = null, $code = null)
{
if (isset($this->_functions[$this->_method])) {
$function = $this->_functions[$this->_method];
} elseif (isset($this->_method)) {
$function = $this->_method;
} else {
$function = 'rest';
}
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
if ($function instanceof Zend_Server_Reflection_Function_Abstract) {
$method = $function->getName();
} else {
$method = $function;
}
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$xml = $dom->createElement($class);
$xmlMethod = $dom->createElement($method);
$xml->appendChild($xmlMethod);
} else {
$xml = $dom->createElement($method);
$xmlMethod = $xml;
}
$xml->setAttribute('generator', 'zend');
$xml->setAttribute('version', '1.0');
$dom->appendChild($xml);
$xmlResponse = $dom->createElement('response');
$xmlMethod->appendChild($xmlResponse);
if ($exception instanceof Exception) {
$element = $dom->createElement('message');
$element->appendChild($dom->createTextNode($exception->getMessage()));
$xmlResponse->appendChild($element);
$code = $exception->getCode();
} elseif (!is_null($exception) || 'rest' == $function) {
$xmlResponse->appendChild($dom->createElement('message', 'An unknown error occured. Please try again.'));
} else {
$xmlResponse->appendChild($dom->createElement('message', 'Call to ' . $method . ' failed.'));
}
$xmlMethod->appendChild($xmlResponse);
$xmlMethod->appendChild($dom->createElement('status', 'failed'));
// Headers to send
if (is_null($code) || (404 != $code))
{
$this->_headers[] = 'HTTP/1.0 400 Bad Request';
} else {
$this->_headers[] = 'HTTP/1.0 404 File Not Found';
}
return $dom;
}
/**
* Retrieve any HTTP extra headers set by the server
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Implement Zend_Server_Interface::addFunction()
*
* @param string $function Function Name
* @param string $namespace Function namespace (unused)
*/
public function addFunction($function, $namespace = '')
{
if (!is_array($function)) {
$function = (array) $function;
}
foreach ($function as $func) {
if (is_callable($func) && !in_array($func, self::$magicMethods)) {
$this->_functions[$func] = $this->_reflection->reflectFunction($func);
} else {
throw new Zend_Rest_Server_Exception("Invalid Method Added to Service.");
}
}
}
/**
* Implement Zend_Server_Interface::getFunctions()
*
* @return array An array of Zend_Server_Reflection_Method's
*/
public function getFunctions()
{
return $this->_functions;
}
/**
* Implement Zend_Server_Interface::loadFunctions()
*
* @todo Implement
* @param array $functions
*/
public function loadFunctions($functions)
{
}
/**
* Implement Zend_Server_Interface::setPersistence()
*
* @todo Implement
* @param int $mode
*/
public function setPersistence($mode)
{
}
/**
* Call a static class method and return the result
*
* @param string $class
* @param array $args
* @return mixed
*/
protected function _callStaticMethod($class, array $args)
{
try {
$result = call_user_func_array(array($class, $this->_functions[$this->_method]->getName()), $args);
} catch (Exception $e) {
$result = $this->fault($e);
}
return $result;
}
/**
* Call an instance method of an object
*
* @param string $class
* @param array $args
* @return mixed
* @throws Zend_Rest_Server_Exception For invalid class name
*/
protected function _callObjectMethod($class, array $args)
{
try {
if ($this->_functions[$this->_method]->getDeclaringClass()->getConstructor()) {
$object = $this->_functions[$this->_method]->getDeclaringClass()->newInstanceArgs($this->_args);
} else {
$object = $this->_functions[$this->_method]->getDeclaringClass()->newInstance();
}
} catch (Exception $e) {
echo $e->getMessage();
throw new Zend_Rest_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $this->_functions[$this->_method]->getName(), 500);
}
try {
$result = $this->_functions[$this->_method]->invokeArgs($object, $args);
} catch (Exception $e) {
$result = $this->fault($e);
}
return $result;
}
}
Rest/Server/Exception.php 0000604 00000002061 15071256134 0011375 0 ustar 00 <?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.
*
* @package Zend_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Rest_Exception
*/
require_once 'Zend/Rest/Exception.php';
/**
* Zend_Rest_Server_Exception
*
* @package Zend_Rest
* @subpackage Server
* @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_Rest_Server_Exception extends Zend_Rest_Exception
{
}
Rest/Client/Exception.php 0000604 00000002104 15071256134 0011343 0 ustar 00 <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Rest_Exception
*/
require_once 'Zend/Rest/Exception.php';
/**
* Zend_Rest_Server_Exception
*
* @package Zend_Rest
* @subpackage Client
* @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_Rest_Client_Exception extends Zend_Rest_Exception
{
}
Rest/Client/Result/Exception.php 0000604 00000001543 15071256134 0012627 0 ustar 00 <?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_Rest
* @subpackage Client
* @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 Zend_Rest_Client_Exception
*/
require_once "Zend/Rest/Client/Exception.php";
class Zend_Rest_Client_Result_Exception extends Zend_Rest_Client_Exception{} Rest/Client/Result.php 0000604 00000013060 15071256134 0010666 0 ustar 00 <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Rest
* @subpackage Client
* @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_Rest_Client_Result implements IteratorAggregate {
/**
* @var SimpleXMLElement
*/
protected $_sxml;
/**
* Constructor
*
* @param string $data XML Result
* @return void
*/
public function __construct($data)
{
set_error_handler(array($this, 'handleXmlErrors'));
$this->_sxml = simplexml_load_string($data);
if($this->_sxml === false) {
$this->handleXmlErrors(0, "An error occured while parsing the REST response with simplexml.");
} else {
restore_error_handler();
}
}
/**
* Temporary error handler for parsing REST responses.
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @param array $errcontext
* @throws Zend_Result_Client_Result_Exception
*/
public function handleXmlErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
{
restore_error_handler();
require_once "Zend/Rest/Client/Result/Exception.php";
throw new Zend_Rest_Client_Result_Exception("REST Response Error: ".$errstr);
}
/**
* Casts a SimpleXMLElement to its appropriate PHP value
*
* @param SimpleXMLElement $value
* @return mixed
*/
public function toValue(SimpleXMLElement $value)
{
$node = dom_import_simplexml($value);
return $node->nodeValue;
}
/**
* Get Property Overload
*
* @param string $name
* @return null|SimpleXMLElement|array Null if not found, SimpleXMLElement if only one value found, array of Zend_Rest_Client_Result objects otherwise
*/
public function __get($name)
{
if (isset($this->_sxml->{$name})) {
return $this->_sxml->{$name};
}
$result = $this->_sxml->xpath("//$name");
$count = count($result);
if ($count == 0) {
return null;
} elseif ($count == 1) {
return $result[0];
} else {
return $result;
}
}
/**
* Cast properties to PHP values
*
* For arrays, loops through each element and casts to a value as well.
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if (null !== ($value = $this->__get($method))) {
if (!is_array($value)) {
return $this->toValue($value);
} else {
$return = array();
foreach ($value as $element) {
$return[] = $this->toValue($element);
}
return $return;
}
}
return null;
}
/**
* Isset Overload
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
if (isset($this->_sxml->{$name})) {
return true;
}
$result = $this->_sxml->xpath("//$name");
if (sizeof($result) > 0) {
return true;
}
return false;
}
/**
* Implement IteratorAggregate::getIterator()
*
* @return SimpleXMLIterator
*/
public function getIterator()
{
return $this->_sxml;
}
/**
* Get Request Status
*
* @return boolean
*/
public function getStatus()
{
$status = $this->_sxml->xpath('//status/text()');
$status = strtolower($status[0]);
if (ctype_alpha($status) && $status == 'success') {
return true;
} elseif (ctype_alpha($status) && $status != 'success') {
return false;
} else {
return (bool) $status;
}
}
public function isError()
{
$status = $this->getStatus();
if ($status) {
return false;
} else {
return true;
}
}
public function isSuccess()
{
$status = $this->getStatus();
if ($status) {
return true;
} else {
return false;
}
}
/**
* toString overload
*
* Be sure to only call this when the result is a single value!
*
* @return string
*/
public function __toString()
{
if (!$this->getStatus()) {
$message = $this->_sxml->xpath('//message');
return (string) $message[0];
} else {
$result = $this->_sxml->xpath('//response');
if (sizeof($result) > 1) {
return (string) "An error occured.";
} else {
return (string) $result[0];
}
}
}
}
Rest/Exception.php 0000604 00000001765 15071256134 0010141 0 ustar 00 <?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_Rest
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Rest
* @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_Rest_Exception extends Zend_Exception
{}
Rest/Client.php 0000604 00000016336 15071256134 0007421 0 ustar 00 <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Service_Abstract */
require_once 'Zend/Service/Abstract.php';
/** Zend_Rest_Client_Result */
require_once 'Zend/Rest/Client/Result.php';
/** Zend_Uri */
require_once 'Zend/Uri.php';
/**
* @category Zend
* @package Zend_Rest
* @subpackage Client
* @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_Rest_Client extends Zend_Service_Abstract
{
/**
* Data for the query
* @var array
*/
protected $_data = array();
/**
* Zend_Uri of this web service
* @var Zend_Uri_Http
*/
protected $_uri = null;
/**
* Constructor
*
* @param string|Zend_Uri_Http $uri URI for the web service
* @return void
*/
public function __construct($uri = null)
{
if (!empty($uri)) {
$this->setUri($uri);
}
}
/**
* Set the URI to use in the request
*
* @param string|Zend_Uri_Http $uri URI for the web service
* @return Zend_Rest_Client
*/
public function setUri($uri)
{
if ($uri instanceof Zend_Uri_Http) {
$this->_uri = $uri;
} else {
$this->_uri = Zend_Uri::factory($uri);
}
return $this;
}
/**
* Retrieve the current request URI object
*
* @return Zend_Uri_Http
*/
public function getUri()
{
return $this->_uri;
}
/**
* Call a remote REST web service URI and return the Zend_Http_Response object
*
* @param string $path The path to append to the URI
* @throws Zend_Rest_Client_Exception
* @return void
*/
final private function _prepareRest($path)
{
// Get the URI object and configure it
if (!$this->_uri instanceof Zend_Uri_Http) {
require_once 'Zend/Rest/Client/Exception.php';
throw new Zend_Rest_Client_Exception('URI object must be set before performing call');
}
$uri = $this->_uri->getUri();
if ($path[0] != '/' && $uri[strlen($uri)-1] != '/') {
$path = '/' . $path;
}
$this->_uri->setPath($path);
/**
* Get the HTTP client and configure it for the endpoint URI. Do this each time
* because the Zend_Http_Client instance is shared among all Zend_Service_Abstract subclasses.
*/
self::getHttpClient()->resetParameters()->setUri($this->_uri);
}
/**
* Performs an HTTP GET request to the $path.
*
* @param string $path
* @param array $query Array of GET parameters
* @return Zend_Http_Response
*/
final public function restGet($path, array $query = null)
{
$this->_prepareRest($path);
$client = self::getHttpClient();
$client->setParameterGet($query);
return $client->request('GET');
}
/**
* Perform a POST or PUT
*
* Performs a POST or PUT request. Any data provided is set in the HTTP
* client. String data is pushed in as raw POST data; array or object data
* is pushed in as POST parameters.
*
* @param mixed $method
* @param mixed $data
* @return Zend_Http_Response
*/
protected function _performPost($method, $data = null)
{
$client = self::getHttpClient();
if (is_string($data)) {
$client->setRawData($data);
} elseif (is_array($data) || is_object($data)) {
$client->setParameterPost((array) $data);
}
return $client->request($method);
}
/**
* Performs an HTTP POST request to $path.
*
* @param string $path
* @param mixed $data Raw data to send
* @return Zend_Http_Response
*/
final public function restPost($path, $data = null)
{
$this->_prepareRest($path);
return $this->_performPost('POST', $data);
}
/**
* Performs an HTTP PUT request to $path.
*
* @param string $path
* @param mixed $data Raw data to send in request
* @return Zend_Http_Response
*/
final public function restPut($path, $data = null)
{
$this->_prepareRest($path);
return $this->_performPost('PUT', $data);
}
/**
* Performs an HTTP DELETE request to $path.
*
* @param string $path
* @return Zend_Http_Response
*/
final public function restDelete($path)
{
$this->_prepareRest($path);
return self::getHttpClient()->request('DELETE');
}
/**
* Method call overload
*
* Allows calling REST actions as object methods; however, you must
* follow-up by chaining the request with a request to an HTTP request
* method (post, get, delete, put):
* <code>
* $response = $rest->sayHello('Foo', 'Manchu')->get();
* </code>
*
* Or use them together, but in sequential calls:
* <code>
* $rest->sayHello('Foo', 'Manchu');
* $response = $rest->get();
* </code>
*
* @param string $method Method name
* @param array $args Method args
* @return Zend_Rest_Client_Result|Zend_Rest_Client Zend_Rest_Client if using
* a remote method, Zend_Rest_Client_Result if using an HTTP request method
*/
public function __call($method, $args)
{
$methods = array('post', 'get', 'delete', 'put');
if (in_array(strtolower($method), $methods)) {
if (!isset($args[0])) {
$args[0] = $this->_uri->getPath();
}
$this->_data['rest'] = 1;
$data = array_slice($args, 1) + $this->_data;
$response = $this->{'rest' . $method}($args[0], $data);
$this->_data = array();//Initializes for next Rest method.
return new Zend_Rest_Client_Result($response->getBody());
} else {
// More than one arg means it's definitely a Zend_Rest_Server
if (sizeof($args) == 1) {
// Uses first called function name as method name
if (!isset($this->_data['method'])) {
$this->_data['method'] = $method;
$this->_data['arg1'] = $args[0];
}
$this->_data[$method] = $args[0];
} else {
$this->_data['method'] = $method;
if (sizeof($args) > 0) {
foreach ($args as $key => $arg) {
$key = 'arg' . $key;
$this->_data[$key] = $arg;
}
}
}
return $this;
}
}
}
Dom/Query.php 0000604 00000013065 15071256134 0007106 0 ustar 00 <?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_Dom
* @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 Zend_Dom_Query_Css2Xpath
*/
require_once 'Zend/Dom/Query/Css2Xpath.php';
/**
* @see Zend_Dom_Query_Result
*/
require_once 'Zend/Dom/Query/Result.php';
/**
* Query DOM structures based on CSS selectors and/or XPath
*
* @package Zend_Dom
* @subpackage Query
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dom_Query
{
/**#@+
* @const string Document types
*/
const DOC_XML = 'docXml';
const DOC_HTML = 'docHtml';
const DOC_XHTML = 'docXhtml';
/**#@-*/
/**
* @var string
*/
protected $_document;
/**
* Document type
* @var string
*/
protected $_docType;
/**
* Constructor
*
* @param null|string $document
* @return void
*/
public function __construct($document = null)
{
if (null !== $document) {
$this->setDocument($document);
}
}
/**
* Set document to query
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocument($document)
{
if ('<?xml' == substr(trim($document), 0, 5)) {
return $this->setDocumentXml($document);
}
if (strstr($document, 'DTD XHTML')) {
return $this->setDocumentXhtml($document);
}
return $this->setDocumentHtml($document);
}
/**
* Register HTML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentHtml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_HTML;
return $this;
}
/**
* Register XHTML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentXhtml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_XHTML;
return $this;
}
/**
* Register XML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentXml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_XML;
return $this;
}
/**
* Retrieve current document
*
* @return string
*/
public function getDocument()
{
return $this->_document;
}
/**
* Get document type
*
* @return string
*/
public function getDocumentType()
{
return $this->_docType;
}
/**
* Perform a CSS selector query
*
* @param string $query
* @return Zend_Dom_Query_Result
*/
public function query($query)
{
$xpathQuery = Zend_Dom_Query_Css2Xpath::transform($query);
return $this->queryXpath($xpathQuery, $query);
}
/**
* Perform an XPath query
*
* @param string $xpathQuery
* @param string $query CSS selector query
* @return Zend_Dom_Query_Result
*/
public function queryXpath($xpathQuery, $query = null)
{
if (null === ($document = $this->getDocument())) {
require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception('Cannot query; no document registered');
}
$domDoc = new DOMDocument;
$type = $this->getDocumentType();
switch ($type) {
case self::DOC_XML:
$success = @$domDoc->loadXML($document);
break;
case self::DOC_HTML:
case self::DOC_XHTML:
default:
$success = @$domDoc->loadHTML($document);
break;
}
if (!$success) {
require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception(sprintf('Error parsing document (type == %s)', $type));
}
$nodeList = $this->_getNodeList($domDoc, $xpathQuery);
return new Zend_Dom_Query_Result($query, $xpathQuery, $domDoc, $nodeList);
}
/**
* Prepare node list
*
* @param DOMDocument $document
* @param string|array $xpathQuery
* @return array
*/
protected function _getNodeList($document, $xpathQuery)
{
$xpath = new DOMXPath($document);
$xpathQuery = (string) $xpathQuery;
if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) {
foreach ($matches[1] as $attribute) {
$queryString = '//*[' . $attribute . ']';
$attributeName = substr($attribute, 1);
$nodes = $xpath->query($queryString);
foreach ($nodes as $node) {
$attr = $node->attributes->getNamedItem($attributeName);
$attr->value = ' ' . $attr->value . ' ';
}
}
}
return $xpath->query($xpathQuery);
}
}
Dom/Exception.php 0000604 00000000475 15071256134 0007740 0 ustar 00 <?php
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* Zend_Dom Exceptions
*
* @package Zend_Dom
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dom_Exception extends Zend_Exception
{
}
Dom/Query/Css2Xpath.php 0000604 00000011414 15071256134 0010721 0 ustar 00 <?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_Dom
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Transform CSS selectors to XPath
*
* @package Zend_Dom
* @subpackage Query
* @copyright Copyright (C) 2007 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: Css2Xpath.php 11013 2008-08-24 21:06:20Z thomas $
*/
class Zend_Dom_Query_Css2Xpath
{
/**
* Transform CSS expression to XPath
*
* @param string $path
* @return string
*/
public static function transform($path)
{
$path = (string) $path;
if (strstr($path, ',')) {
$paths = explode(',', $path);
$expressions = array();
foreach ($paths as $path) {
$xpath = self::transform(trim($path));
if (is_string($xpath)) {
$expressions[] = $xpath;
} elseif (is_array($xpath)) {
$expressions = array_merge($expressions, $xpath);
}
}
return $expressions;
}
$paths = array('//');
$segments = preg_split('/\s+/', $path);
foreach ($segments as $key => $segment) {
$pathSegment = self::_tokenize($segment);
if (0 == $key) {
if (0 === strpos($pathSegment, '[contains(@class')) {
$paths[0] .= '*' . $pathSegment;
} else {
$paths[0] .= $pathSegment;
}
continue;
}
if (0 === strpos($pathSegment, '[contains(@class')) {
foreach ($paths as $key => $xpath) {
$paths[$key] .= '//*' . $pathSegment;
$paths[] = $xpath . $pathSegment;
}
} else {
foreach ($paths as $key => $xpath) {
$paths[$key] .= '//' . $pathSegment;
}
}
}
if (1 == count($paths)) {
return $paths[0];
}
return implode(' | ', $paths);
}
/**
* Tokenize CSS expressions to XPath
*
* @param string $expression
* @return string
*/
protected static function _tokenize($expression)
{
// Child selectors
$expression = str_replace('>', '/', $expression);
// IDs
$expression = preg_replace('|#([a-z][a-z0-9_-]*)|i', '[@id=\'$1\']', $expression);
$expression = preg_replace('|(?<![a-z0-9_-])(\[@id=)|i', '*$1', $expression);
// arbitrary attribute strict equality
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[@" . strtolower($matches[2]) . "=\'" . $matches[3] . "\']";'
),
$expression
);
}
// arbitrary attribute contains full word
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)~=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)~=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[contains(@" . strtolower($matches[2]) . ", \' $matches[3] \')]";'
),
$expression
);
}
// arbitrary attribute contains specified content
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)\*=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)\*=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[contains(@" . strtolower($matches[2]) . ", \'" . $matches[3] . "\')]";'
),
$expression
);
}
// Classes
$expression = preg_replace('|\.([a-z][a-z0-9_-]*)|i', "[contains(@class, ' \$1 ')]", $expression);
return $expression;
}
}
Dom/Query/Result.php 0000604 00000007275 15071256134 0010372 0 ustar 00 <?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_Dom
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Results for DOM XPath query
*
* @package Zend_Dom
* @subpackage Query
* @uses Iterator
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: Result.php 12507 2008-11-10 16:29:09Z matthew $
*/
class Zend_Dom_Query_Result implements Iterator,Countable
{
/**
* Number of results
* @var int
*/
protected $_count;
/**
* CSS Selector query
* @var string
*/
protected $_cssQuery;
/**
* @var DOMDocument
*/
protected $_document;
/**
* @var DOMNodeList
*/
protected $_nodeList;
/**
* Current iterator position
* @var int
*/
protected $_position = 0;
/**
* @var DOMXPath
*/
protected $_xpath;
/**
* XPath query
* @var string
*/
protected $_xpathQuery;
/**
* Constructor
*
* @param string $cssQuery
* @param string|array $xpathQuery
* @param DOMDocument $document
* @param DOMNodeList $nodeList
* @return void
*/
public function __construct($cssQuery, $xpathQuery, DOMDocument $document, DOMNodeList $nodeList)
{
$this->_cssQuery = $cssQuery;
$this->_xpathQuery = $xpathQuery;
$this->_document = $document;
$this->_nodeList = $nodeList;
}
/**
* Retrieve CSS Query
*
* @return string
*/
public function getCssQuery()
{
return $this->_cssQuery;
}
/**
* Retrieve XPath query
*
* @return string
*/
public function getXpathQuery()
{
return $this->_xpathQuery;
}
/**
* Retrieve DOMDocument
*
* @return DOMDocument
*/
public function getDocument()
{
return $this->_document;
}
/**
* Iterator: rewind to first element
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
return $this->_nodeList->item(0);
}
/**
* Iterator: is current position valid?
*
* @return bool
*/
public function valid()
{
if (in_array($this->_position, range(0, $this->_nodeList->length - 1)) && $this->_nodeList->length > 0) {
return true;
}
return false;
}
/**
* Iterator: return current element
*
* @return DOMElement
*/
public function current()
{
return $this->_nodeList->item($this->_position);
}
/**
* Iterator: return key of current element
*
* @return int
*/
public function key()
{
return $this->_position;
}
/**
* Iterator: move to next element
*
* @return void
*/
public function next()
{
++$this->_position;
return $this->_nodeList->item($this->_position);
}
/**
* Countable: get count
*
* @return int
*/
public function count()
{
return $this->_nodeList->length;
}
}
Mail/Message/Interface.php 0000604 00000003044 15071256134 0011424 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Message_Interface
{
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines();
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag);
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags();
} Mail/Message/File.php 0000604 00000005123 15071256134 0010403 0 ustar 00 <?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_Mail
* @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: Message.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Zend_Mail_Part
*/
require_once 'Zend/Mail/Part/File.php';
/**
* Zend_Mail_Message_Interface
*/
require_once 'Zend/Mail/Message/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Message_File extends Zend_Mail_Part_File implements Zend_Mail_Message_Interface
{
/**
* flags for this message
* @var array
*/
protected $_flags = array();
/**
* Public constructor
*
* In addition to the parameters of Zend_Mail_Part::__construct() this constructor supports:
* - flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
*
* @param string $rawMessage full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (!empty($params['flags'])) {
// set key and value to the same value for easy lookup
$this->_flags = array_combine($params['flags'], $params['flags']);
}
parent::__construct($params);
}
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines()
{
return $this->_topLines;
}
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag)
{
return isset($this->_flags[$flag]);
}
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags()
{
return $this->_flags;
}
}
Mail/Transport/Sendmail.php 0000604 00000011323 15071256134 0011667 0 ustar 00 <?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_Mail
* @subpackage Transport
* @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: Sendmail.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Transport_Abstract
*/
require_once 'Zend/Mail/Transport/Abstract.php';
/**
* Class for sending eMails via the PHP internal mail() function
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @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_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
{
/**
* Subject
* @var string
* @access public
*/
public $subject = null;
/**
* Config options for sendmail parameters
*
* @var string
*/
public $parameters;
/**
* EOL character string
* @var string
* @access public
*/
public $EOL = PHP_EOL;
/**
* Constructor.
*
* @param string $parameters OPTIONAL (Default: null)
* @return void
*/
public function __construct($parameters = null)
{
$this->parameters = $parameters;
}
/**
* Send mail using PHP native mail()
*
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception on mail() failure
*/
public function _sendMail()
{
if ($this->parameters === null) {
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
} else {
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header,
$this->parameters);
}
if (!$result) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Unable to send mail');
}
}
/**
* Format and fix headers
*
* mail() uses its $to and $subject arguments to set the To: and Subject:
* headers, respectively. This method strips those out as a sanity check to
* prevent duplicate header entries.
*
* @access protected
* @param array $headers
* @return void
* @throws Zend_Mail_Transport_Exception
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
// mail() uses its $to parameter to set the To: header, and the $subject
// parameter to set the Subject: header. We need to strip them out.
if (0 === strpos(PHP_OS, 'WIN')) {
// If the current recipients list is empty, throw an error
if (empty($this->recipients)) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To addresses');
}
} else {
// All others, simply grab the recipients and unset the To: header
if (!isset($headers['To'])) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To header');
}
unset($headers['To']['append']);
$this->recipients = implode(',', $headers['To']);
}
// Remove recipient header
unset($headers['To']);
// Remove subject header, if present
if (isset($headers['Subject'])) {
unset($headers['Subject']);
}
// Prepare headers
parent::_prepareHeaders($headers);
}
}
Mail/Transport/Exception.php 0000604 00000002213 15071256134 0012067 0 ustar 00 <?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_Mail
* @subpackage Transport
* @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 $
*/
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @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_Mail_Transport_Exception extends Zend_Mail_Exception
{}
Mail/Transport/Abstract.php 0000604 00000024317 15071256134 0011705 0 ustar 00 <?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_Mail
* @subpackage Transport
* @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: Abstract.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* Abstract for sending eMails through different
* ways of transport
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Mail_Transport_Abstract
{
/**
* Mail body
* @var string
* @access public
*/
public $body = '';
/**
* MIME boundary
* @var string
* @access public
*/
public $boundary = '';
/**
* Mail header string
* @var string
* @access public
*/
public $header = '';
/**
* Array of message headers
* @var array
* @access protected
*/
protected $_headers = array();
/**
* Message is a multipart message
* @var boolean
* @access protected
*/
protected $_isMultipart = false;
/**
* Zend_Mail object
* @var false|Zend_Mail
* @access protected
*/
protected $_mail = false;
/**
* Array of message parts
* @var array
* @access protected
*/
protected $_parts = array();
/**
* Recipients string
* @var string
* @access public
*/
public $recipients = '';
/**
* EOL character string used by transport
* @var string
* @access public
*/
public $EOL = "\r\n";
/**
* Send an email independent from the used transport
*
* The requisite information for the email will be found in the following
* properties:
*
* - {@link $recipients} - list of recipients (string)
* - {@link $header} - message header
* - {@link $body} - message body
*/
abstract protected function _sendMail();
/**
* Return all mail headers as an array
*
* If a boundary is given, a multipart header is generated with a
* Content-Type of either multipart/alternative or multipart/mixed depending
* on the mail parts present in the {@link $_mail Zend_Mail object} present.
*
* @param string $boundary
* @return array
*/
protected function _getHeaders($boundary)
{
if (null !== $boundary) {
// Build multipart mail
$type = $this->_mail->getType();
if (!$type) {
if ($this->_mail->hasAttachments) {
$type = Zend_Mime::MULTIPART_MIXED;
} elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) {
$type = Zend_Mime::MULTIPART_ALTERNATIVE;
} else {
$type = Zend_Mime::MULTIPART_MIXED;
}
}
$this->_headers['Content-Type'] = array(
$type . '; charset="' . $this->_mail->getCharset() . '";'
. $this->EOL
. " " . 'boundary="' . $boundary . '"'
);
$this->_headers['MIME-Version'] = array('1.0');
$this->boundary = $boundary;
}
return $this->_headers;
}
/**
* Prepend header name to header value
*
* @param string $item
* @param string $key
* @param string $prefix
* @static
* @access protected
* @return void
*/
protected static function _formatHeader(&$item, $key, $prefix)
{
$item = $prefix . ': ' . $item;
}
/**
* Prepare header string for use in transport
*
* Prepares and generates {@link $header} based on the headers provided.
*
* @param mixed $headers
* @access protected
* @return void
* @throws Zend_Mail_Transport_Exception if any header lines exceed 998
* characters
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing Zend_Mail object in _mail property');
}
$this->header = '';
foreach ($headers as $header => $content) {
if (isset($content['append'])) {
unset($content['append']);
$value = implode(',' . $this->EOL . ' ', $content);
$this->header .= $header . ': ' . $value . $this->EOL;
} else {
array_walk($content, array(get_class($this), '_formatHeader'), $header);
$this->header .= implode($this->EOL, $content) . $this->EOL;
}
}
// Sanity check on headers -- should not be > 998 characters
$sane = true;
foreach (explode($this->EOL, $this->header) as $line) {
if (strlen(trim($line)) > 998) {
$sane = false;
break;
}
}
if (!$sane) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Exception('At least one mail header line is too long');
}
}
/**
* Generate MIME compliant message from the current configuration
*
* If both a text and HTML body are present, generates a
* multipart/alternative Zend_Mime_Part containing the headers and contents
* of each. Otherwise, uses whichever of the text or HTML parts present.
*
* The content part is then prepended to the list of Zend_Mime_Parts for
* this message.
*
* @return void
*/
protected function _buildBody()
{
if (($text = $this->_mail->getBodyText())
&& ($html = $this->_mail->getBodyHtml()))
{
// Generate unique boundary for multipart/alternative
$mime = new Zend_Mime(null);
$boundaryLine = $mime->boundaryLine($this->EOL);
$boundaryEnd = $mime->mimeEnd($this->EOL);
$text->disposition = false;
$html->disposition = false;
$body = $boundaryLine
. $text->getHeaders($this->EOL)
. $this->EOL
. $text->getContent($this->EOL)
. $this->EOL
. $boundaryLine
. $html->getHeaders($this->EOL)
. $this->EOL
. $html->getContent($this->EOL)
. $this->EOL
. $boundaryEnd;
$mp = new Zend_Mime_Part($body);
$mp->type = Zend_Mime::MULTIPART_ALTERNATIVE;
$mp->boundary = $mime->boundary();
$this->_isMultipart = true;
// Ensure first part contains text alternatives
array_unshift($this->_parts, $mp);
// Get headers
$this->_headers = $this->_mail->getHeaders();
return;
}
// If not multipart, then get the body
if (false !== ($body = $this->_mail->getBodyHtml())) {
array_unshift($this->_parts, $body);
} elseif (false !== ($body = $this->_mail->getBodyText())) {
array_unshift($this->_parts, $body);
}
if (!$body) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('No body specified');
}
// Get headers
$this->_headers = $this->_mail->getHeaders();
$headers = $body->getHeadersArray($this->EOL);
foreach ($headers as $header) {
// Headers in Zend_Mime_Part are kept as arrays with two elements, a
// key and a value
$this->_headers[$header[0]] = array($header[1]);
}
}
/**
* Send a mail using this transport
*
* @param Zend_Mail $mail
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception if mail is empty
*/
public function send(Zend_Mail $mail)
{
$this->_isMultipart = false;
$this->_mail = $mail;
$this->_parts = $mail->getParts();
$mime = $mail->getMime();
// Build body content
$this->_buildBody();
// Determine number of parts and boundary
$count = count($this->_parts);
$boundary = null;
if ($count < 1) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Empty mail cannot be sent');
}
if ($count > 1) {
// Multipart message; create new MIME object and boundary
$mime = new Zend_Mime($this->_mail->getMimeBoundary());
$boundary = $mime->boundary();
} elseif ($this->_isMultipart) {
// multipart/alternative -- grab boundary
$boundary = $this->_parts[0]->boundary;
}
// Determine recipients, and prepare headers
$this->recipients = implode(',', $mail->getRecipients());
$this->_prepareHeaders($this->_getHeaders($boundary));
// Create message body
// This is done so that the same Zend_Mail object can be used in
// multiple transports
$message = new Zend_Mime_Message();
$message->setParts($this->_parts);
$message->setMime($mime);
$this->body = $message->generateMessage($this->EOL);
// Send to transport!
$this->_sendMail();
}
}
Mail/Transport/Smtp.php 0000604 00000013603 15071256134 0011061 0 ustar 00 <?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_Mail
* @subpackage Transport
* @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: Smtp.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* @see Zend_Mail_Transport_Abstract
*/
require_once 'Zend/Mail/Transport/Abstract.php';
/**
* SMTP connection object
*
* Loads an instance of Zend_Mail_Protocol_Smtp and forwards smtp transactions
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @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_Mail_Transport_Smtp extends Zend_Mail_Transport_Abstract
{
/**
* EOL character string used by transport
* @var string
* @access public
*/
public $EOL = "\n";
/**
* Remote smtp hostname or i.p.
*
* @var string
*/
protected $_host;
/**
* Port number
*
* @var integer|null
*/
protected $_port;
/**
* Local client hostname or i.p.
*
* @var string
*/
protected $_name = 'localhost';
/**
* Authentication type OPTIONAL
*
* @var string
*/
protected $_auth;
/**
* Config options for authentication
*
* @var array
*/
protected $_config;
/**
* Instance of Zend_Mail_Protocol_Smtp
*
* @var Zend_Mail_Protocol_Smtp
*/
protected $_connection;
/**
* Constructor.
*
* @param string $host OPTIONAL (Default: 127.0.0.1)
* @param array|null $config OPTIONAL (Default: null)
* @return void
*/
public function __construct($host = '127.0.0.1', Array $config = array())
{
if (isset($config['name'])) {
$this->_name = $config['name'];
}
if (isset($config['port'])) {
$this->_port = $config['port'];
}
if (isset($config['auth'])) {
$this->_auth = $config['auth'];
}
$this->_host = $host;
$this->_config = $config;
}
/**
* Class destructor to ensure all open connections are closed
*
* @return void
*/
public function __destruct()
{
if ($this->_connection instanceof Zend_Mail_Protocol_Smtp) {
try {
$this->_connection->quit();
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore
}
$this->_connection->disconnect();
}
}
/**
* Sets the connection protocol instance
*
* @param Zend_Mail_Protocol_Abstract $client
*
* @return void
*/
public function setConnection(Zend_Mail_Protocol_Abstract $connection)
{
$this->_connection = $connection;
}
/**
* Gets the connection protocol instance
*
* @return Zend_Mail_Protocol|null
*/
public function getConnection()
{
return $this->_connection;
}
/**
* Send an email via the SMTP connection protocol
*
* The connection via the protocol adapter is made just-in-time to allow a
* developer to add a custom adapter if required before mail is sent.
*
* @return void
*/
public function _sendMail()
{
// If sending multiple messages per session use existing adapter
if (!($this->_connection instanceof Zend_Mail_Protocol_Smtp)) {
// Check if authentication is required and determine required class
$connectionClass = 'Zend_Mail_Protocol_Smtp';
if ($this->_auth) {
$connectionClass .= '_Auth_' . ucwords($this->_auth);
}
Zend_Loader::loadClass($connectionClass);
$this->setConnection(new $connectionClass($this->_host, $this->_port, $this->_config));
$this->_connection->connect();
$this->_connection->helo($this->_name);
} else {
// Reset connection to ensure reliable transaction
$this->_connection->rset();
}
// Set mail return path from sender email address
$this->_connection->mail($this->_mail->getReturnPath());
// Set recipient forward paths
foreach ($this->_mail->getRecipients() as $recipient) {
$this->_connection->rcpt($recipient);
}
// Issue DATA command to client
$this->_connection->data($this->header . Zend_Mime::LINEEND . $this->body);
}
/**
* Format and fix headers
*
* Some SMTP servers do not strip BCC headers. Most clients do it themselves as do we.
*
* @access protected
* @param array $headers
* @return void
* @throws Zend_Transport_Exception
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
unset($headers['Bcc']);
// Prepare headers
parent::_prepareHeaders($headers);
}
}
Mail/Message.php 0000604 00000006300 15071256134 0007522 0 ustar 00 <?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_Mail
* @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: Message.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* Zend_Mail_Part
*/
require_once 'Zend/Mail/Part.php';
/**
* Zend_Mail_Message_Interface
*/
require_once 'Zend/Mail/Message/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Message extends Zend_Mail_Part implements Zend_Mail_Message_Interface
{
/**
* flags for this message
* @var array
*/
protected $_flags = array();
/**
* Public constructor
*
* In addition to the parameters of Zend_Mail_Part::__construct() this constructor supports:
* - file filename or file handle of a file with raw message content
* - flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
*
* @param string $rawMessage full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (isset($params['file'])) {
if (!is_resource($params['file'])) {
$params['raw'] = @file_get_contents($params['file']);
if ($params['raw'] === false) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('could not open file');
}
} else {
$params['raw'] = stream_get_contents($params['file']);
}
}
if (!empty($params['flags'])) {
// set key and value to the same value for easy lookup
$this->_flags = array_combine($params['flags'], $params['flags']);
}
parent::__construct($params);
}
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines()
{
return $this->_topLines;
}
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag)
{
return isset($this->_flags[$flag]);
}
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags()
{
return $this->_flags;
}
}
Mail/Part/File.php 0000604 00000014053 15071256134 0007727 0 ustar 00 <?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_Mail
* @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: Part.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mime_Decode
*/
require_once 'Zend/Mime/Decode.php';
/**
* @see Zend_Mail_Part
*/
require_once 'Zend/Mail/Part.php';
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Part_File extends Zend_Mail_Part
{
protected $_contentPos = array();
protected $_partPos = array();
protected $_fh;
/**
* Public constructor
*
* This handler supports the following params:
* - file filename or open file handler with message content (required)
* - startPos start position of message or part in file (default: current position)
* - endPos end position of message or part in file (default: end of file)
*
* @param array $params full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (empty($params['file'])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no file given in params');
}
if (!is_resource($params['file'])) {
$this->_fh = fopen($params['file'], 'r');
} else {
$this->_fh = $params['file'];
}
if (!$this->_fh) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('could not open file');
}
if (isset($params['startPos'])) {
fseek($this->_fh, $params['startPos']);
}
$header = '';
$endPos = isset($params['endPos']) ? $params['endPos'] : null;
while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) {
$header .= $line;
}
Zend_Mime_Decode::splitMessage($header, $this->_headers, $null);
$this->_contentPos[0] = ftell($this->_fh);
if ($endPos !== null) {
$this->_contentPos[1] = $endPos;
} else {
fseek($this->_fh, 0, SEEK_END);
$this->_contentPos[1] = ftell($this->_fh);
}
if (!$this->isMultipart()) {
return;
}
$boundary = $this->getHeaderField('content-type', 'boundary');
if (!$boundary) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no boundary found in content type to split message');
}
$part = array();
$pos = $this->_contentPos[0];
fseek($this->_fh, $pos);
while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) {
$line = fgets($this->_fh);
if ($line === false) {
if (feof($this->_fh)) {
break;
}
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('error reading file');
}
$lastPos = $pos;
$pos = ftell($this->_fh);
$line = trim($line);
if ($line == '--' . $boundary) {
if ($part) {
// not first part
$part[1] = $lastPos;
$this->_partPos[] = $part;
}
$part = array($pos);
} else if ($line == '--' . $boundary . '--') {
$part[1] = $lastPos;
$this->_partPos[] = $part;
break;
}
}
$this->_countParts = count($this->_partPos);
}
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent($stream = null)
{
fseek($this->_fh, $this->_contentPos[0]);
if ($stream !== null) {
return stream_copy_to_stream($this->_fh, $stream, $this->_contentPos[1] - $this->_contentPos[0]);
}
$length = $this->_contentPos[1] - $this->_contentPos[0];
return $length < 1 ? '' : fread($this->_fh, $length);
}
/**
* Return size of part
*
* Quite simple implemented currently (not decoding). Handle with care.
*
* @return int size
*/
public function getSize() {
return $this->_contentPos[1] - $this->_contentPos[0];
}
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num)
{
--$num;
if (!isset($this->_partPos[$num])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
return new self(array('file' => $this->_fh, 'startPos' => $this->_partPos[$num][0],
'endPos' => $this->_partPos[$num][1]));
}
}
Mail/Part/Interface.php 0000604 00000010201 15071256134 0010737 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Part_Interface extends RecursiveIterator
{
/**
* Check if part is a multipart message
*
* @return bool if part is multipart
*/
public function isMultipart();
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent();
/**
* Return size of part
*
* @return int size
*/
public function getSize();
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num);
/**
* Count parts of a multipart part
*
* @return int number of sub-parts
*/
public function countParts();
/**
* Get all headers
*
* The returned headers are as saved internally. All names are lowercased. The value is a string or an array
* if a header with the same name occurs more than once.
*
* @return array headers as array(name => value)
*/
public function getHeaders();
/**
* Get a header in specificed format
*
* Internally headers that occur more than once are saved as array, all other as string. If $format
* is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim).
*
* @param string $name name of header, matches case-insensitive, but camel-case is replaced with dashes
* @param string $format change type of return value to 'string' or 'array'
* @return string|array value of header in wanted or internal format
* @throws Zend_Mail_Exception
*/
public function getHeader($name, $format = null);
/**
* Get a specific field from a header like content type or all fields as array
*
* If the header occurs more than once, only the value from the first header
* is returned.
*
* Throws a Zend_Mail_Exception if the requested header does not exist. If
* the specific header field does not exist, returns null.
*
* @param string $name name of header, like in getHeader()
* @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned
* @param string $firstName key name for the first part
* @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
* @throws Zend_Exception, Zend_Mail_Exception
*/
public function getHeaderField($name, $wantedPart = 0, $firstName = 0);
/**
* Getter for mail headers - name is matched in lowercase
*
* This getter is short for Zend_Mail_Part::getHeader($name, 'string')
*
* @see Zend_Mail_Part::getHeader()
*
* @param string $name header name
* @return string value of header
* @throws Zend_Mail_Exception
*/
public function __get($name);
/**
* magic method to get content of part
*
* @return string content
*/
public function __toString();
} Mail/Storage.php 0000604 00000002555 15071256134 0007552 0 ustar 00 <?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_Mail
* @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: Storage.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Storage
{
// maildir and IMAP flags, using IMAP names, where possible to be able to distinguish between IMAP
// system flags and other flags
const FLAG_PASSED = 'Passed';
const FLAG_SEEN = '\Seen';
const FLAG_ANSWERED = '\Answered';
const FLAG_FLAGGED = '\Flagged';
const FLAG_DELETED = '\Deleted';
const FLAG_DRAFT = '\Draft';
const FLAG_RECENT = '\Recent';
}
Mail/Part.php 0000604 00000032531 15071256134 0007051 0 ustar 00 <?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_Mail
* @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: Part.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Mime_Decode
*/
require_once 'Zend/Mime/Decode.php';
/**
* @see Zend_Mail_Part_Interface
*/
require_once 'Zend/Mail/Part/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface
{
/**
* headers of part as array
* @var null|array
*/
protected $_headers;
/**
* raw part body
* @var null|string
*/
protected $_content;
/**
* toplines as fetched with headers
* @var string
*/
protected $_topLines = '';
/**
* parts of multipart message
* @var array
*/
protected $_parts = array();
/**
* count of parts of a multipart message
* @var null|int
*/
protected $_countParts;
/**
* current position of iterator
* @var int
*/
protected $_iterationPos = 1;
/**
* mail handler, if late fetch is active
* @var null|Zend_Mail_Storage_Abstract
*/
protected $_mail;
/**
* message number for mail handler
* @var int
*/
protected $_messageNum = 0;
/**
* Public constructor
*
* Zend_Mail_Part supports different sources for content. The possible params are:
* - handler a instance of Zend_Mail_Storage_Abstract for late fetch
* - id number of message for handler
* - raw raw content with header and body as string
* - headers headers as array (name => value) or string, if a content part is found it's used as toplines
* - noToplines ignore content found after headers in param 'headers'
* - content content as string
*
* @param array $params full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (isset($params['handler'])) {
if (!$params['handler'] instanceof Zend_Mail_Storage_Abstract) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('handler is not a valid mail handler');
}
if (!isset($params['id'])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('need a message id with a handler');
}
$this->_mail = $params['handler'];
$this->_messageNum = $params['id'];
}
if (isset($params['raw'])) {
Zend_Mime_Decode::splitMessage($params['raw'], $this->_headers, $this->_content);
} else if (isset($params['headers'])) {
if (is_array($params['headers'])) {
$this->_headers = $params['headers'];
} else {
if (!empty($params['noToplines'])) {
Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $null);
} else {
Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $this->_topLines);
}
}
if (isset($params['content'])) {
$this->_content = $params['content'];
}
}
}
/**
* Check if part is a multipart message
*
* @return bool if part is multipart
*/
public function isMultipart()
{
try {
return stripos($this->contentType, 'multipart/') === 0;
} catch(Zend_Mail_Exception $e) {
return false;
}
}
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent()
{
if ($this->_content !== null) {
return $this->_content;
}
if ($this->_mail) {
return $this->_mail->getRawContent($this->_messageNum);
} else {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no content');
}
}
/**
* Return size of part
*
* Quite simple implemented currently (not decoding). Handle with care.
*
* @return int size
*/
public function getSize() {
return strlen($this->getContent());
}
/**
* Cache content and split in parts if multipart
*
* @return null
* @throws Zend_Mail_Exception
*/
protected function _cacheContent()
{
// caching content if we can't fetch parts
if ($this->_content === null && $this->_mail) {
$this->_content = $this->_mail->getRawContent($this->_messageNum);
}
if (!$this->isMultipart()) {
return;
}
// split content in parts
$boundary = $this->getHeaderField('content-type', 'boundary');
if (!$boundary) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no boundary found in content type to split message');
}
$parts = Zend_Mime_Decode::splitMessageStruct($this->_content, $boundary);
if ($parts === null) {
return;
}
$counter = 1;
foreach ($parts as $part) {
$this->_parts[$counter++] = new self(array('headers' => $part['header'], 'content' => $part['body']));
}
}
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num)
{
if (isset($this->_parts[$num])) {
return $this->_parts[$num];
}
if (!$this->_mail && $this->_content === null) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
if ($this->_mail && $this->_mail->hasFetchPart) {
// TODO: fetch part
// return
}
$this->_cacheContent();
if (!isset($this->_parts[$num])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
return $this->_parts[$num];
}
/**
* Count parts of a multipart part
*
* @return int number of sub-parts
*/
public function countParts()
{
if ($this->_countParts) {
return $this->_countParts;
}
$this->_countParts = count($this->_parts);
if ($this->_countParts) {
return $this->_countParts;
}
if ($this->_mail && $this->_mail->hasFetchPart) {
// TODO: fetch part
// return
}
$this->_cacheContent();
$this->_countParts = count($this->_parts);
return $this->_countParts;
}
/**
* Get all headers
*
* The returned headers are as saved internally. All names are lowercased. The value is a string or an array
* if a header with the same name occurs more than once.
*
* @return array headers as array(name => value)
*/
public function getHeaders()
{
if ($this->_headers === null) {
if (!$this->_mail) {
$this->_headers = array();
} else {
$part = $this->_mail->getRawHeader($this->_messageNum);
Zend_Mime_Decode::splitMessage($part, $this->_headers, $null);
}
}
return $this->_headers;
}
/**
* Get a header in specificed format
*
* Internally headers that occur more than once are saved as array, all other as string. If $format
* is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim).
*
* @param string $name name of header, matches case-insensitive, but camel-case is replaced with dashes
* @param string $format change type of return value to 'string' or 'array'
* @return string|array value of header in wanted or internal format
* @throws Zend_Mail_Exception
*/
public function getHeader($name, $format = null)
{
if ($this->_headers === null) {
$this->getHeaders();
}
$lowerName = strtolower($name);
if (!isset($this->_headers[$lowerName])) {
$lowerName = strtolower(preg_replace('%([a-z])([A-Z])%', '\1-\2', $name));
if (!isset($this->_headers[$lowerName])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception("no Header with Name $name found");
}
}
$name = $lowerName;
$header = $this->_headers[$name];
switch ($format) {
case 'string':
if (is_array($header)) {
$header = implode(Zend_Mime::LINEEND, $header);
}
break;
case 'array':
$header = (array)$header;
default:
// do nothing
}
return $header;
}
/**
* Get a specific field from a header like content type or all fields as array
*
* If the header occurs more than once, only the value from the first header
* is returned.
*
* Throws a Zend_Mail_Exception if the requested header does not exist. If
* the specific header field does not exist, returns null.
*
* @param string $name name of header, like in getHeader()
* @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned
* @param string $firstName key name for the first part
* @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
* @throws Zend_Exception, Zend_Mail_Exception
*/
public function getHeaderField($name, $wantedPart = 0, $firstName = 0) {
return Zend_Mime_Decode::splitHeaderField(current($this->getHeader($name, 'array')), $wantedPart, $firstName);
}
/**
* Getter for mail headers - name is matched in lowercase
*
* This getter is short for Zend_Mail_Part::getHeader($name, 'string')
*
* @see Zend_Mail_Part::getHeader()
*
* @param string $name header name
* @return string value of header
* @throws Zend_Mail_Exception
*/
public function __get($name)
{
return $this->getHeader($name, 'string');
}
/**
* magic method to get content of part
*
* @return string content
*/
public function __toString()
{
return $this->getContent();
}
/**
* implements RecursiveIterator::hasChildren()
*
* @return bool current element has children/is multipart
*/
public function hasChildren()
{
$current = $this->current();
return $current && $current instanceof Zend_Mail_Part && $current->isMultipart();
}
/**
* implements RecursiveIterator::getChildren()
*
* @return Zend_Mail_Part same as self::current()
*/
public function getChildren()
{
return $this->current();
}
/**
* implements Iterator::valid()
*
* @return bool check if there's a current element
*/
public function valid()
{
if ($this->_countParts === null) {
$this->countParts();
}
return $this->_iterationPos && $this->_iterationPos <= $this->_countParts;
}
/**
* implements Iterator::next()
*
* @return null
*/
public function next()
{
++$this->_iterationPos;
}
/**
* implements Iterator::key()
*
* @return string key/number of current part
*/
public function key()
{
return $this->_iterationPos;
}
/**
* implements Iterator::current()
*
* @return Zend_Mail_Part current part
*/
public function current()
{
return $this->getPart($this->_iterationPos);
}
/**
* implements Iterator::rewind()
*
* @return null
*/
public function rewind()
{
$this->countParts();
$this->_iterationPos = 1;
}
}
Mail/Protocol/Pop3.php 0000604 00000031230 15071256134 0010560 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Pop3.php 12539 2008-11-11 02:47:17Z yoshida@zend.co.jp $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Pop3
{
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
/**
* saves if server supports top
* @var null|bool
*/
public $hasTop = null;
/**
* socket to pop3
* @var null|resource
*/
protected $_socket;
/**
* greeting timestamp for apop
* @var null|string
*/
protected $_timestamp;
/**
* Public constructor
*
* @param string $host hostname of IP address of POP3 server, if given connect() is called
* @param int|null $port port of POP3 server, null for default (110 or 995 for ssl)
* @param bool|string $ssl use ssl? 'SSL', 'TLS' or false
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($host = '', $port = null, $ssl = false)
{
if ($host) {
$this->connect($host, $port, $ssl);
}
}
/**
* Public destructor
*/
public function __destruct()
{
$this->logout();
}
/**
* Open connection to POP3 server
*
* @param string $host hostname of IP address of POP3 server
* @param int|null $port of POP3 server, default is 110 (995 for ssl)
* @param string|bool $ssl use 'SSL', 'TLS' or false
* @return string welcome message
* @throws Zend_Mail_Protocol_Exception
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
}
if ($port === null) {
$port = $ssl == 'SSL' ? 995 : 110;
}
$errno = 0;
$errstr = '';
$this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
if (!$this->_socket) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot connect to host : ' . $errno . ' : ' . $errstr);
}
$welcome = $this->readResponse();
strtok($welcome, '<');
$this->_timestamp = strtok('>');
if (!strpos($this->_timestamp, '@')) {
$this->_timestamp = null;
} else {
$this->_timestamp = '<' . $this->_timestamp . '>';
}
if ($ssl === 'TLS') {
$this->request('STLS');
$result = stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot enable TLS');
}
}
return $welcome;
}
/**
* Send a request
*
* @param string $request your request without newline
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function sendRequest($request)
{
$result = @fputs($this->_socket, $request . "\r\n");
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('send failed - connection closed?');
}
}
/**
* read a response
*
* @param boolean $multiline response has multiple lines and should be read until "<nl>.<nl>"
* @return string response
* @throws Zend_Mail_Protocol_Exception
*/
public function readResponse($multiline = false)
{
$result = @fgets($this->_socket);
if (!is_string($result)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('read failed - connection closed?');
}
$result = trim($result);
if (strpos($result, ' ')) {
list($status, $message) = explode(' ', $result, 2);
} else {
$status = $result;
$message = '';
}
if ($status != '+OK') {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('last request failed');
}
if ($multiline) {
$message = '';
$line = fgets($this->_socket);
while ($line && rtrim($line, "\r\n") != '.') {
if ($line[0] == '.') {
$line = substr($line, 1);
}
$message .= $line;
$line = fgets($this->_socket);
};
}
return $message;
}
/**
* Send request and get resposne
*
* @see sendRequest(), readResponse()
*
* @param string $request request
* @param bool $multiline multiline response?
* @return string result from readResponse()
* @throws Zend_Mail_Protocol_Exception
*/
public function request($request, $multiline = false)
{
$this->sendRequest($request);
return $this->readResponse($multiline);
}
/**
* End communication with POP3 server (also closes socket)
*
* @return null
*/
public function logout()
{
if (!$this->_socket) {
return;
}
try {
$this->request('QUIT');
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore error - we're closing the socket anyway
}
fclose($this->_socket);
$this->_socket = null;
}
/**
* Get capabilities from POP3 server
*
* @return array list of capabilities
* @throws Zend_Mail_Protocol_Exception
*/
public function capa()
{
$result = $this->request('CAPA', true);
return explode("\n", $result);
}
/**
* Login to POP3 server. Can use APOP
*
* @param string $user username
* @param string $password password
* @param bool $try_apop should APOP be tried?
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function login($user, $password, $tryApop = true)
{
if ($tryApop && $this->_timestamp) {
try {
$this->request("APOP $user " . md5($this->_timestamp . $password));
return;
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore
}
}
$result = $this->request("USER $user");
$result = $this->request("PASS $password");
}
/**
* Make STAT call for message count and size sum
*
* @param int $messages out parameter with count of messages
* @param int $octets out parameter with size in octects of messages
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function status(&$messages, &$octets)
{
$messages = 0;
$octets = 0;
$result = $this->request('STAT');
list($messages, $octets) = explode(' ', $result);
}
/**
* Make LIST call for size of message(s)
*
* @param int|null $msgno number of message, null for all
* @return int|array size of given message or list with array(num => size)
* @throws Zend_Mail_Protocol_Exception
*/
public function getList($msgno = null)
{
if ($msgno !== null) {
$result = $this->request("LIST $msgno");
list(, $result) = explode(' ', $result);
return (int)$result;
}
$result = $this->request('LIST', true);
$messages = array();
$line = strtok($result, "\n");
while ($line) {
list($no, $size) = explode(' ', trim($line));
$messages[(int)$no] = (int)$size;
$line = strtok("\n");
}
return $messages;
}
/**
* Make UIDL call for getting a uniqueid
*
* @param int|null $msgno number of message, null for all
* @return string|array uniqueid of message or list with array(num => uniqueid)
* @throws Zend_Mail_Protocol_Exception
*/
public function uniqueid($msgno = null)
{
if ($msgno !== null) {
$result = $this->request("UIDL $msgno");
list(, $result) = explode(' ', $result);
return $result;
}
$result = $this->request('UIDL', true);
$result = explode("\n", $result);
$messages = array();
foreach ($result as $line) {
if (!$line) {
continue;
}
list($no, $id) = explode(' ', trim($line), 2);
$messages[(int)$no] = $id;
}
return $messages;
}
/**
* Make TOP call for getting headers and maybe some body lines
* This method also sets hasTop - before it it's not known if top is supported
*
* The fallback makes normale RETR call, which retrieves the whole message. Additional
* lines are not removed.
*
* @param int $msgno number of message
* @param int $lines number of wanted body lines (empty line is inserted after header lines)
* @param bool $fallback fallback with full retrieve if top is not supported
* @return string message headers with wanted body lines
* @throws Zend_Mail_Protocol_Exception
*/
public function top($msgno, $lines = 0, $fallback = false)
{
if ($this->hasTop === false) {
if ($fallback) {
return $this->retrieve($msgno);
} else {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('top not supported and no fallback wanted');
}
}
$this->hasTop = true;
$lines = (!$lines || $lines < 1) ? 0 : (int)$lines;
try {
$result = $this->request("TOP $msgno $lines", true);
} catch (Zend_Mail_Protocol_Exception $e) {
$this->hasTop = false;
if ($fallback) {
$result = $this->retrieve($msgno);
} else {
throw $e;
}
}
return $result;
}
/**
* Make a RETR call for retrieving a full message with headers and body
*
* @deprecated since 1.1.0; this method has a typo - please use retrieve()
* @param int $msgno message number
* @return string message
* @throws Zend_Mail_Protocol_Exception
*/
public function retrive($msgno)
{
return $this->retrieve($msgno);
}
/**
* Make a RETR call for retrieving a full message with headers and body
*
* @param int $msgno message number
* @return string message
* @throws Zend_Mail_Protocol_Exception
*/
public function retrieve($msgno)
{
$result = $this->request("RETR $msgno", true);
return $result;
}
/**
* Make a NOOP call, maybe needed for keeping the server happy
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function noop()
{
$this->request('NOOP');
}
/**
* Make a DELE count to remove a message
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function delete($msgno)
{
$this->request("DELE $msgno");
}
/**
* Make RSET call, which rollbacks delete requests
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function undelete()
{
$this->request('RSET');
}
}
Mail/Protocol/Smtp/Auth/Login.php 0000604 00000004730 15071256134 0012640 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Login.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs LOGIN authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Smtp_Auth_Login extends Zend_Mail_Protocol_Smtp
{
/**
* LOGIN username
*
* @var string
*/
protected $_username;
/**
* LOGIN password
*
* @var string
*/
protected $_password;
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* Perform LOGIN authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH LOGIN');
$this->_expect(334);
$this->_send(base64_encode($this->_username));
$this->_expect(334);
$this->_send(base64_encode($this->_password));
$this->_expect(235);
$this->_auth = true;
}
}
Mail/Protocol/Smtp/Auth/Crammd5.php 0000604 00000006133 15071256134 0013057 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Crammd5.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs CRAM-MD5 authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Smtp_Auth_Crammd5 extends Zend_Mail_Protocol_Smtp
{
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* @todo Perform CRAM-MD5 authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH CRAM-MD5');
$challenge = $this->_expect(334);
$challenge = base64_decode($challenge);
$digest = $this->_hmacMd5($this->_password, $challenge);
$this->_send(base64_encode($this->_username . ' ' . $digest));
$this->_expect(235);
$this->_auth = true;
}
/**
* Prepare CRAM-MD5 response to server's ticket
*
* @param string $key Challenge key (usually password)
* @param string $data Challenge data
* @param string $block Length of blocks
* @return string
*/
protected function _hmacMd5($key, $data, $block = 64)
{
if (strlen($key) > 64) {
$key = pack('H32', md5($key));
} elseif (strlen($key) < 64) {
$key = str_pad($key, $block, chr(0));
}
$k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
$inner = pack('H32', md5($k_ipad . $data));
$digest = md5($k_opad . $inner);
return $digest;
}
}
Mail/Protocol/Smtp/Auth/Plain.php 0000604 00000004651 15071256134 0012635 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Plain.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs PLAIN authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Smtp_Auth_Plain extends Zend_Mail_Protocol_Smtp
{
/**
* PLAIN username
*
* @var string
*/
protected $_username;
/**
* PLAIN password
*
* @var string
*/
protected $_password;
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* Perform PLAIN authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH PLAIN');
$this->_expect(334);
$this->_send(base64_encode(chr(0) . $this->_username . chr(0) . $this->_password));
$this->_expect(235);
$this->_auth = true;
}
}
Mail/Protocol/Smtp.php 0000604 00000027147 15071256134 0010676 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Smtp.php 11196 2008-09-02 00:56:25Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* @see Zend_Mail_Protocol_Abstract
*/
require_once 'Zend/Mail/Protocol/Abstract.php';
/**
* Smtp implementation of Zend_Mail_Protocol_Abstract
*
* Minimum implementation according to RFC2821: EHLO, MAIL FROM, RCPT TO, DATA, RSET, NOOP, QUIT
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Smtp extends Zend_Mail_Protocol_Abstract
{
/**
* The transport method for the socket
*
* @var string
*/
protected $_transport = 'tcp';
/**
* Indicates that a session is requested to be secure
*
* @var string
*/
protected $_secure;
/**
* Indicates an smtp session has been started by the HELO command
*
* @var boolean
*/
protected $_sess = false;
/**
* Indicates the HELO command has been issues
*
* @var unknown_type
*/
protected $_helo = false;
/**
* Indicates an smtp AUTH has been issued and authenticated
*
* @var unknown_type
*/
protected $_auth = false;
/**
* Indicates a MAIL command has been issued
*
* @var unknown_type
*/
protected $_mail = false;
/**
* Indicates one or more RCTP commands have been issued
*
* @var unknown_type
*/
protected $_rcpt = false;
/**
* Indicates that DATA has been issued and sent
*
* @var unknown_type
*/
protected $_data = null;
/**
* Constructor.
*
* @param string $host
* @param integer $port
* @param array $config
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($host = '127.0.0.1', $port = null, array $config = array())
{
if (isset($config['ssl'])) {
switch (strtolower($config['ssl'])) {
case 'tls':
$this->_secure = 'tls';
break;
case 'ssl':
$this->_transport = 'ssl';
$this->_secure = 'ssl';
if ($port == null) {
$port = 465;
}
break;
default:
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($config['ssl'] . ' is unsupported SSL type');
break;
}
}
// If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null.
if ($port == null) {
if (($port = ini_get('smtp_port')) == '') {
$port = 25;
}
}
parent::__construct($host, $port);
}
/**
* Connect to the server with the parameters given in the constructor.
*
* @return boolean
*/
public function connect()
{
return $this->_connect($this->_transport . '://' . $this->_host . ':'. $this->_port);
}
/**
* Initiate HELO/EHLO sequence and set flag to indicate valid smtp session
*
* @param string $host The client hostname or IP address (default: 127.0.0.1)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function helo($host = '127.0.0.1')
{
// Respect RFC 2821 and disallow HELO attempts if session is already initiated.
if ($this->_sess === true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Cannot issue HELO to existing session');
}
// Validate client hostname
if (!$this->_validHost->isValid($host)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
}
// Initiate helo sequence
$this->_expect(220, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_ehlo($host);
// If a TLS session is required, commence negotiation
if ($this->_secure == 'tls') {
$this->_send('STARTTLS');
$this->_expect(220, 180);
if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Unable to connect via TLS');
}
$this->_ehlo($host);
}
$this->_startSession();
$this->auth();
}
/**
* Send EHLO or HELO depending on capabilities of smtp host
*
* @param string $host The client hostname or IP address (default: 127.0.0.1)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
protected function _ehlo($host)
{
// Support for older, less-compliant remote servers. Tries multiple attempts of EHLO or HELO.
try {
$this->_send('EHLO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
} catch (Zend_Mail_Protocol_Exception $e) {
$this->_send('HELO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
} catch (Zend_Mail_Protocol_Exception $e) {
throw $e;
}
}
/**
* Issues MAIL command
*
* @param string $from Sender mailbox
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function mail($from)
{
if ($this->_sess !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('A valid session has not been started');
}
$this->_send('MAIL FROM:<' . $from . '>');
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
// Set mail to true, clear recipients and any existing data flags as per 4.1.1.2 of RFC 2821
$this->_mail = true;
$this->_rcpt = false;
$this->_data = false;
}
/**
* Issues RCPT command
*
* @param string $to Receiver(s) mailbox
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function rcpt($to)
{
if ($this->_mail !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No sender reverse path has been supplied');
}
// Set rcpt to true, as per 4.1.1.3 of RFC 2821
$this->_send('RCPT TO:<' . $to . '>');
$this->_expect(array(250, 251), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_rcpt = true;
}
/**
* Issues DATA command
*
* @param string $data
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function data($data)
{
// Ensure recipients have been set
if ($this->_rcpt !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No recipient forward path has been supplied');
}
$this->_send('DATA');
$this->_expect(354, 120); // Timeout set for 2 minutes as per RFC 2821 4.5.3.2
foreach (explode(Zend_Mime::LINEEND, $data) as $line) {
if (strpos($line, '.') === 0) {
// Escape lines prefixed with a '.'
$line = '.' . $line;
}
$this->_send($line);
}
$this->_send('.');
$this->_expect(250, 600); // Timeout set for 10 minutes as per RFC 2821 4.5.3.2
$this->_data = true;
}
/**
* Issues the RSET command end validates answer
*
* Can be used to restore a clean smtp communication state when a transaction has been cancelled or commencing a new transaction.
*
* @return void
*/
public function rset()
{
$this->_send('RSET');
// MS ESMTP doesn't follow RFC, see [ZF-1377]
$this->_expect(array(250, 220));
$this->_mail = false;
$this->_rcpt = false;
$this->_data = false;
}
/**
* Issues the NOOP command end validates answer
*
* Not used by Zend_Mail, could be used to keep a connection alive or check if it is still open.
*
* @return void
*/
public function noop()
{
$this->_send('NOOP');
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
}
/**
* Issues the VRFY command end validates answer
*
* Not used by Zend_Mail.
*
* @param string $user User Name or eMail to verify
* @return void
*/
public function vrfy($user)
{
$this->_send('VRFY ' . $user);
$this->_expect(array(250, 251, 252), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
}
/**
* Issues the QUIT command and clears the current session
*
* @return void
*/
public function quit()
{
if ($this->_sess) {
$this->_send('QUIT');
$this->_expect(221, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_stopSession();
}
}
/**
* Default authentication method
*
* This default method is implemented by AUTH adapters to properly authenticate to a remote host.
*
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function auth()
{
if ($this->_auth === true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Already authenticated for this session');
}
}
/**
* Closes connection
*
* @return void
*/
public function disconnect()
{
$this->_disconnect();
}
/**
* Start mail session
*
* @return void
*/
protected function _startSession()
{
$this->_sess = true;
}
/**
* Stop mail session
*
* @return void
*/
protected function _stopSession()
{
$this->_sess = false;
}
}
Mail/Protocol/Imap.php 0000604 00000065710 15071256134 0010637 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Imap.php 12539 2008-11-11 02:47:17Z yoshida@zend.co.jp $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Imap
{
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
/**
* socket to imap server
* @var resource|null
*/
protected $_socket;
/**
* counter for request tag
* @var int
*/
protected $_tagCount = 0;
/**
* Public constructor
*
* @param string $host hostname of IP address of IMAP server, if given connect() is called
* @param int|null $port port of IMAP server, null for default (143 or 993 for ssl)
* @param bool $ssl use ssl? 'SSL', 'TLS' or false
* @throws Zend_Mail_Protocol_Exception
*/
function __construct($host = '', $port = null, $ssl = false)
{
if ($host) {
$this->connect($host, $port, $ssl);
}
}
/**
* Public destructor
*/
public function __destruct()
{
$this->logout();
}
/**
* Open connection to POP3 server
*
* @param string $host hostname of IP address of POP3 server
* @param int|null $port of IMAP server, default is 143 (993 for ssl)
* @param string|bool $ssl use 'SSL', 'TLS' or false
* @return string welcome message
* @throws Zend_Mail_Protocol_Exception
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
}
if ($port === null) {
$port = $ssl === 'SSL' ? 993 : 143;
}
$errno = 0;
$errstr = '';
$this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
if (!$this->_socket) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot connect to host : ' . $errno . ' : ' . $errstr);
}
if (!$this->_assumedNextLine('* OK')) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('host doesn\'t allow connection');
}
if ($ssl === 'TLS') {
$result = $this->requestAndResponse('STARTTLS');
$result = $result && stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot enable TLS');
}
}
}
/**
* get the next line from socket with error checking, but nothing else
*
* @return string next line
* @throws Zend_Mail_Protocol_Exception
*/
protected function _nextLine()
{
$line = @fgets($this->_socket);
if ($line === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot read - connection closed?');
}
return $line;
}
/**
* get next line and assume it starts with $start. some requests give a simple
* feedback so we can quickly check if we can go on.
*
* @param string $start the first bytes we assume to be in the next line
* @return bool line starts with $start
* @throws Zend_Mail_Protocol_Exception
*/
protected function _assumedNextLine($start)
{
$line = $this->_nextLine();
return strpos($line, $start) === 0;
}
/**
* get next line and split the tag. that's the normal case for a response line
*
* @param string $tag tag of line is returned by reference
* @return string next line
* @throws Zend_Mail_Protocol_Exception
*/
protected function _nextTaggedLine(&$tag)
{
$line = $this->_nextLine();
// seperate tag from line
list($tag, $line) = explode(' ', $line, 2);
return $line;
}
/**
* split a given line in tokens. a token is literal of any form or a list
*
* @param string $line line to decode
* @return array tokens, literals are returned as string, lists as array
* @throws Zend_Mail_Protocol_Exception
*/
protected function _decodeLine($line)
{
$tokens = array();
$stack = array();
/*
We start to decode the response here. The unterstood tokens are:
literal
"literal" or also "lit\\er\"al"
{bytes}<NL>literal
(literals*)
All tokens are returned in an array. Literals in braces (the last unterstood
token in the list) are returned as an array of tokens. I.e. the following response:
"foo" baz {3}<NL>bar ("f\\\"oo" bar)
would be returned as:
array('foo', 'baz', 'bar', array('f\\\"oo', 'bar'));
// TODO: add handling of '[' and ']' to parser for easier handling of response text
*/
// replace any trailling <NL> including spaces with a single space
$line = rtrim($line) . ' ';
while (($pos = strpos($line, ' ')) !== false) {
$token = substr($line, 0, $pos);
while ($token[0] == '(') {
array_push($stack, $tokens);
$tokens = array();
$token = substr($token, 1);
}
if ($token[0] == '"') {
if (preg_match('%^"((.|\\\\|\\")*?)" *%', $line, $matches)) {
$tokens[] = $matches[1];
$line = substr($line, strlen($matches[0]));
continue;
}
}
if ($token[0] == '{') {
$endPos = strpos($token, '}');
$chars = substr($token, 1, $endPos - 1);
if (is_numeric($chars)) {
$token = '';
while (strlen($token) < $chars) {
$token .= $this->_nextLine();
}
$line = '';
if (strlen($token) > $chars) {
$line = substr($token, $chars);
$token = substr($token, 0, $chars);
} else {
$line .= $this->_nextLine();
}
$tokens[] = $token;
$line = trim($line) . ' ';
continue;
}
}
if ($stack && $token[strlen($token) - 1] == ')') {
// closing braces are not seperated by spaces, so we need to count them
$braces = strlen($token);
$token = rtrim($token, ')');
// only count braces if more than one
$braces -= strlen($token) + 1;
// only add if token had more than just closing braces
if ($token) {
$tokens[] = $token;
}
$token = $tokens;
$tokens = array_pop($stack);
// special handline if more than one closing brace
while ($braces-- > 0) {
$tokens[] = $token;
$token = $tokens;
$tokens = array_pop($stack);
}
}
$tokens[] = $token;
$line = substr($line, $pos + 1);
}
// maybe the server forgot to send some closing braces
while ($stack) {
$child = $tokens;
$tokens = array_pop($stack);
$tokens[] = $child;
}
return $tokens;
}
/**
* read a response "line" (could also be more than one real line if response has {..}<NL>)
* and do a simple decode
*
* @param array|string $tokens decoded tokens are returned by reference, if $dontParse
* is true the unparsed line is returned here
* @param string $wantedTag check for this tag for response code. Default '*' is
* continuation tag.
* @param bool $dontParse if true only the unparsed line is returned $tokens
* @return bool if returned tag matches wanted tag
* @throws Zend_Mail_Protocol_Exception
*/
public function readLine(&$tokens = array(), $wantedTag = '*', $dontParse = false)
{
$line = $this->_nextTaggedLine($tag);
if (!$dontParse) {
$tokens = $this->_decodeLine($line);
} else {
$tokens = $line;
}
// if tag is wanted tag we might be at the end of a multiline response
return $tag == $wantedTag;
}
/**
* read all lines of response until given tag is found (last line of response)
*
* @param string $tag the tag of your request
* @param string|array $filter you can filter the response so you get only the
* given response lines
* @param bool $dontParse if true every line is returned unparsed instead of
* the decoded tokens
* @return null|bool|array tokens if success, false if error, null if bad request
* @throws Zend_Mail_Protocol_Exception
*/
public function readResponse($tag, $dontParse = false)
{
$lines = array();
while (!$this->readLine($tokens, $tag, $dontParse)) {
$lines[] = $tokens;
}
if ($dontParse) {
// last to chars are still needed for response code
$tokens = array(substr($tokens, 0, 2));
}
// last line has response code
if ($tokens[0] == 'OK') {
return $lines ? $lines : true;
} else if ($tokens[0] == 'NO'){
return false;
}
return null;
}
/**
* send a request
*
* @param string $command your request command
* @param array $tokens additional parameters to command, use escapeString() to prepare
* @param string $tag provide a tag otherwise an autogenerated is returned
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function sendRequest($command, $tokens = array(), &$tag = null)
{
if (!$tag) {
++$this->_tagCount;
$tag = 'TAG' . $this->_tagCount;
}
$line = $tag . ' ' . $command;
foreach ($tokens as $token) {
if (is_array($token)) {
if (@fputs($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot write - connection closed?');
}
if (!$this->_assumedNextLine('+ ')) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot send literal string');
}
$line = $token[1];
} else {
$line .= ' ' . $token;
}
}
if (@fputs($this->_socket, $line . "\r\n") === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot write - connection closed?');
}
}
/**
* send a request and get response at once
*
* @param string $command command as in sendRequest()
* @param array $tokens parameters as in sendRequest()
* @param bool $dontParse if true unparsed lines are returned instead of tokens
* @return mixed response as in readResponse()
* @throws Zend_Mail_Protocol_Exception
*/
public function requestAndResponse($command, $tokens = array(), $dontParse = false)
{
$this->sendRequest($command, $tokens, $tag);
$response = $this->readResponse($tag, $dontParse);
return $response;
}
/**
* escape one or more literals i.e. for sendRequest
*
* @param string|array $string the literal/-s
* @return string|array escape literals, literals with newline ar returned
* as array('{size}', 'string');
*/
public function escapeString($string)
{
if (func_num_args() < 2) {
if (strpos($string, "\n") !== false) {
return array('{' . strlen($string) . '}', $string);
} else {
return '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $string) . '"';
}
}
$result = array();
foreach (func_get_args() as $string) {
$result[] = $this->escapeString($string);
}
return $result;
}
/**
* escape a list with literals or lists
*
* @param array $list list with literals or lists as PHP array
* @return string escaped list for imap
*/
public function escapeList($list)
{
$result = array();
foreach ($list as $k => $v) {
if (!is_array($v)) {
// $result[] = $this->escapeString($v);
$result[] = $v;
continue;
}
$result[] = $this->escapeList($v);
}
return '(' . implode(' ', $result) . ')';
}
/**
* Login to IMAP server.
*
* @param string $user username
* @param string $password password
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function login($user, $password)
{
return $this->requestAndResponse('LOGIN', $this->escapeString($user, $password), true);
}
/**
* logout of imap server
*
* @return bool success
*/
public function logout()
{
$result = false;
if ($this->_socket) {
try {
$result = $this->requestAndResponse('LOGOUT', array(), true);
} catch (Zend_Mail_Protocol_Exception $e) {
// ignoring exception
}
fclose($this->_socket);
$this->_socket = null;
}
return $result;
}
/**
* Get capabilities from IMAP server
*
* @return array list of capabilities
* @throws Zend_Mail_Protocol_Exception
*/
public function capability()
{
$response = $this->requestAndResponse('CAPABILITY');
if (!$response) {
return $response;
}
$capabilities = array();
foreach ($response as $line) {
$capabilities = array_merge($capabilities, $line);
}
return $capabilities;
}
/**
* Examine and select have the same response. The common code for both
* is in this method
*
* @param string $command can be 'EXAMINE' or 'SELECT' and this is used as command
* @param string $box which folder to change to or examine
* @return bool|array false if error, array with returned information
* otherwise (flags, exists, recent, uidvalidity)
* @throws Zend_Mail_Protocol_Exception
*/
public function examineOrSelect($command = 'EXAMINE', $box = 'INBOX')
{
$this->sendRequest($command, array($this->escapeString($box)), $tag);
$result = array();
while (!$this->readLine($tokens, $tag)) {
if ($tokens[0] == 'FLAGS') {
array_shift($tokens);
$result['flags'] = $tokens;
continue;
}
switch ($tokens[1]) {
case 'EXISTS':
case 'RECENT':
$result[strtolower($tokens[1])] = $tokens[0];
break;
case '[UIDVALIDITY':
$result['uidvalidity'] = (int)$tokens[2];
break;
default:
// ignore
}
}
if ($tokens[0] != 'OK') {
return false;
}
return $result;
}
/**
* change folder
*
* @param string $box change to this folder
* @return bool|array see examineOrselect()
* @throws Zend_Mail_Protocol_Exception
*/
public function select($box = 'INBOX')
{
return $this->examineOrSelect('SELECT', $box);
}
/**
* examine folder
*
* @param string $box examine this folder
* @return bool|array see examineOrselect()
* @throws Zend_Mail_Protocol_Exception
*/
public function examine($box = 'INBOX')
{
return $this->examineOrSelect('EXAMINE', $box);
}
/**
* fetch one or more items of one or more messages
*
* @param string|array $items items to fetch from message(s) as string (if only one item)
* or array of strings
* @param int $from message for items or start message if $to !== null
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @return string|array if only one item of one message is fetched it's returned as string
* if items of one message are fetched it's returned as (name => value)
* if one items of messages are fetched it's returned as (msgno => value)
* if items of messages are fetchted it's returned as (msgno => (name => value))
* @throws Zend_Mail_Protocol_Exception
*/
public function fetch($items, $from, $to = null)
{
if (is_array($from)) {
$set = implode(',', $from);
} else if ($to === null) {
$set = (int)$from;
} else if ($to === INF) {
$set = (int)$from . ':*';
} else {
$set = (int)$from . ':' . (int)$to;
}
$items = (array)$items;
$itemList = $this->escapeList($items);
$this->sendRequest('FETCH', array($set, $itemList), $tag);
$result = array();
while (!$this->readLine($tokens, $tag)) {
// ignore other responses
if ($tokens[1] != 'FETCH') {
continue;
}
// ignore other messages
if ($to === null && !is_array($from) && $tokens[0] != $from) {
continue;
}
// if we only want one item we return that one directly
if (count($items) == 1) {
if ($tokens[2][0] == $items[0]) {
$data = $tokens[2][1];
} else {
// maybe the server send an other field we didn't wanted
$count = count($tokens[2]);
// we start with 2, because 0 was already checked
for ($i = 2; $i < $count; $i += 2) {
if ($tokens[2][$i] != $items[0]) {
continue;
}
$data = $tokens[2][$i + 1];
break;
}
}
} else {
$data = array();
while (key($tokens[2]) !== null) {
$data[current($tokens[2])] = next($tokens[2]);
next($tokens[2]);
}
}
// if we want only one message we can ignore everything else and just return
if ($to === null && !is_array($from) && $tokens[0] == $from) {
// we still need to read all lines
while (!$this->readLine($tokens, $tag));
return $data;
}
$result[$tokens[0]] = $data;
}
if ($to === null && !is_array($from)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('the single id was not found in response');
}
return $result;
}
/**
* get mailbox list
*
* this method can't be named after the IMAP command 'LIST', as list is a reserved keyword
*
* @param string $reference mailbox reference for list
* @param string $mailbox mailbox name match with wildcards
* @return array mailboxes that matched $mailbox as array(globalName => array('delim' => .., 'flags' => ..))
* @throws Zend_Mail_Protocol_Exception
*/
public function listMailbox($reference = '', $mailbox = '*')
{
$result = array();
$list = $this->requestAndResponse('LIST', $this->escapeString($reference, $mailbox));
if (!$list || $list === true) {
return $result;
}
foreach ($list as $item) {
if (count($item) != 4 || $item[0] != 'LIST') {
continue;
}
$result[$item[3]] = array('delim' => $item[2], 'flags' => $item[1]);
}
return $result;
}
/**
* set flags
*
* @param array $flags flags to set, add or remove - see $mode
* @param int $from message for items or start message if $to !== null
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @param string|null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given
* @param bool $silent if false the return values are the new flags for the wanted messages
* @return bool|array new flags if $silent is false, else true or false depending on success
* @throws Zend_Mail_Protocol_Exception
*/
public function store(array $flags, $from, $to = null, $mode = null, $silent = true)
{
$item = 'FLAGS';
if ($mode == '+' || $mode == '-') {
$item = $mode . $item;
}
if ($silent) {
$item .= '.SILENT';
}
$flags = $this->escapeList($flags);
$set = (int)$from;
if ($to != null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
$result = $this->requestAndResponse('STORE', array($set, $item, $flags), $silent);
if ($silent) {
return $result ? true : false;
}
$tokens = $result;
$result = array();
foreach ($tokens as $token) {
if ($token[1] != 'FETCH' || $token[2][0] != 'FLAGS') {
continue;
}
$result[$token[0]] = $token[2][1];
}
return $result;
}
/**
* append a new message to given folder
*
* @param string $folder name of target folder
* @param string $message full message content
* @param array $flags flags for new message
* @param string $date date for new message
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function append($folder, $message, $flags = null, $date = null)
{
$tokens = array();
$tokens[] = $this->escapeString($folder);
if ($flags !== null) {
$tokens[] = $this->escapeList($flags);
}
if ($date !== null) {
$tokens[] = $this->escapeString($date);
}
$tokens[] = $this->escapeString($message);
return $this->requestAndResponse('APPEND', $tokens, true);
}
/**
* copy message set from current folder to other folder
*
* @param string $folder destination folder
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function copy($folder, $from, $to = null)
{
$set = (int)$from;
if ($to != null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
return $this->requestAndResponse('COPY', array($set, $this->escapeString($folder)), true);
}
/**
* create a new folder (and parent folders if needed)
*
* @param string $folder folder name
* @return bool success
*/
public function create($folder)
{
return $this->requestAndResponse('CREATE', array($this->escapeString($folder)), true);
}
/**
* rename an existing folder
*
* @param string $old old name
* @param string $new new name
* @return bool success
*/
public function rename($old, $new)
{
return $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
}
/**
* remove a folder
*
* @param string $folder folder name
* @return bool success
*/
public function delete($folder)
{
return $this->requestAndResponse('DELETE', array($this->escapeString($folder)), true);
}
/**
* permanently remove messages
*
* @return bool success
*/
public function expunge()
{
// TODO: parse response?
return $this->requestAndResponse('EXPUNGE');
}
/**
* send noop
*
* @return bool success
*/
public function noop()
{
// TODO: parse response
return $this->requestAndResponse('NOOP');
}
/**
* do a search request
*
* This method is currently marked as internal as the API might change and is not
* safe if you don't take precautions.
*
* @internal
* @return array message ids
*/
public function search(array $params)
{
$response = $this->requestAndResponse('SEARCH', $params);
if (!$response) {
return $response;
}
foreach ($response as $ids) {
if ($ids[0] == 'SEARCH') {
array_shift($ids);
return $ids;
}
}
return array();
}
}
Mail/Protocol/Abstract.php 0000604 00000023302 15071256134 0011503 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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: Abstract.php 12395 2008-11-07 23:58:38Z nico $
*/
/**
* @see Zend_Validate
*/
require_once 'Zend/Validate.php';
/**
* @see Zend_Validate_Hostname
*/
require_once 'Zend/Validate/Hostname.php';
/**
* Zend_Mail_Protocol_Abstract
*
* Provides low-level methods for concrete adapters to communicate with a remote mail server and track requests and responses.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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: Abstract.php 12395 2008-11-07 23:58:38Z nico $
* @todo Implement proxy settings
*/
abstract class Zend_Mail_Protocol_Abstract
{
/**
* Mail default EOL string
*/
const EOL = "\r\n";
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
/**
* Hostname or IP address of remote server
* @var string
*/
protected $_host;
/**
* Port number of connection
* @var integer
*/
protected $_port;
/**
* Instance of Zend_Validate to check hostnames
* @var Zend_Validate
*/
protected $_validHost;
/**
* Socket connection resource
* @var resource
*/
protected $_socket;
/**
* Last request sent to server
* @var string
*/
protected $_request;
/**
* Array of server responses to last request
* @var array
*/
protected $_response;
/**
* String template for parsing server responses using sscanf (default: 3 digit code and response string)
* @var resource
*/
protected $_template = '%d%s';
/**
* Log of mail requests and server responses for a session
* @var string
*/
private $_log;
/**
* Constructor.
*
* @param string $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
* @param integer $port OPTIONAL Port number (default: null)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null)
{
$this->_validHost = new Zend_Validate();
$this->_validHost->addValidator(new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL));
if (!$this->_validHost->isValid($host)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
}
$this->_host = $host;
$this->_port = $port;
}
/**
* Class destructor to cleanup open resources
*
* @return void
*/
public function __destruct()
{
$this->_disconnect();
}
/**
* Create a connection to the remote host
*
* Concrete adapters for this class will implement their own unique connect scripts, using the _connect() method to create the socket resource.
*/
abstract public function connect();
/**
* Retrieve the last client request
*
* @return string
*/
public function getRequest()
{
return $this->_request;
}
/**
* Retrieve the last server response
*
* @return array
*/
public function getResponse()
{
return $this->_response;
}
/**
* Retrieve the transaction log
*
* @return string
*/
public function getLog()
{
return $this->_log;
}
/**
* Reset the transaction log
*
* @return void
*/
public function resetLog()
{
$this->_log = '';
}
/**
* Connect to the server using the supplied transport and target
*
* An example $remote string may be 'tcp://mail.example.com:25' or 'ssh://hostname.com:2222'
*
* @param string $remote Remote
* @throws Zend_Mail_Protocol_Exception
* @return boolean
*/
protected function _connect($remote)
{
$errorNum = 0;
$errorStr = '';
// open connection
$this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
if (($result = stream_set_timeout($this->_socket, self::TIMEOUT_CONNECTION)) === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
}
return $result;
}
/**
* Disconnect from remote host and free resource
*
* @return void
*/
protected function _disconnect()
{
if (is_resource($this->_socket)) {
fclose($this->_socket);
}
}
/**
* Send the given request followed by a LINEEND to the server.
*
* @param string $request
* @throws Zend_Mail_Protocol_Exception
* @return integer|boolean Number of bytes written to remote host
*/
protected function _send($request)
{
if (!is_resource($this->_socket)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No connection has been established to ' . $this->_host);
}
$this->_request = $request;
$result = fwrite($this->_socket, $request . self::EOL);
// Save request to internal log
$this->_log .= $request . self::EOL;
if ($result === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not send request to ' . $this->_host);
}
return $result;
}
/**
* Get a line from the stream.
*
* @var integer $timeout Per-request timeout value if applicable
* @throws Zend_Mail_Protocol_Exception
* @return string
*/
protected function _receive($timeout = null)
{
if (!is_resource($this->_socket)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No connection has been established to ' . $this->_host);
}
// Adapters may wish to supply per-commend timeouts according to appropriate RFC
if ($timeout !== null) {
stream_set_timeout($this->_socket, $timeout);
}
// Retrieve response
$reponse = fgets($this->_socket, 1024);
// Save request to internal log
$this->_log .= $reponse;
// Check meta data to ensure connection is still valid
$info = stream_get_meta_data($this->_socket);
if (!empty($info['timed_out'])) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($this->_host . ' has timed out');
}
if ($reponse === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not read from ' . $this->_host);
}
return $reponse;
}
/**
* Parse server response for successful codes
*
* Read the response from the stream and check for expected return code.
* Throws a Zend_Mail_Protocol_Exception if an unexpected code is returned.
*
* @param string|array $code One or more codes that indicate a successful response
* @throws Zend_Mail_Protocol_Exception
* @return string Last line of response string
*/
protected function _expect($code, $timeout = null)
{
$this->_response = array();
$cmd = '';
$msg = '';
if (!is_array($code)) {
$code = array($code);
}
do {
$this->_response[] = $result = $this->_receive($timeout);
sscanf($result, $this->_template, $cmd, $msg);
if ($cmd === null || !in_array($cmd, $code)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($result);
}
} while (strpos($msg, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
return $msg;
}
}
Mail/Protocol/Exception.php 0000604 00000002203 15071256134 0011673 0 ustar 00 <?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_Mail
* @subpackage Protocol
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Mail/Exception.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @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_Mail_Protocol_Exception extends Zend_Mail_Exception
{}
Mail/Exception.php 0000604 00000002077 15071256134 0010103 0 ustar 00 <?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_Mail
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Mail
* @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_Mail_Exception extends Zend_Exception
{}
Mail/Storage/Exception.php 0000604 00000002205 15071256135 0011501 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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 $
*/
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Exception extends Zend_Mail_Exception
{}
Mail/Storage/Folder/Interface.php 0000604 00000003513 15071256135 0012661 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Interface.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Storage_Folder_Interface
{
/**
* get root folder or given folder
*
* @param string $rootFolder get folder structure for given folder, else root
* @return Zend_Mail_Storage_Folder root or wanted folder
*/
public function getFolders($rootFolder = null);
/**
* select given folder
*
* folder must be selectable!
*
* @param Zend_Mail_Storage_Folder|string $globalName global name of folder or instance for subfolder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function selectFolder($globalName);
/**
* get Zend_Mail_Storage_Folder instance for current folder
*
* @return Zend_Mail_Storage_Folder instance of current folder
* @throws Zend_Mail_Storage_Exception
*/
public function getCurrentFolder();
}
Mail/Storage/Folder/Maildir.php 0000604 00000021304 15071256135 0012340 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Maildir.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Mail_Storage_Folder
*/
require_once 'Zend/Mail/Storage/Folder.php';
/**
* @see Zend_Mail_Storage_Folder_Interface
*/
require_once 'Zend/Mail/Storage/Folder/Interface.php';
/**
* @see Zend_Mail_Storage_Maildir
*/
require_once 'Zend/Mail/Storage/Maildir.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Folder_Maildir extends Zend_Mail_Storage_Maildir implements Zend_Mail_Storage_Folder_Interface
{
/**
* Zend_Mail_Storage_Folder root folder for folder structure
* @var Zend_Mail_Storage_Folder
*/
protected $_rootFolder;
/**
* rootdir of folder structure
* @var string
*/
protected $_rootdir;
/**
* name of current folder
* @var string
*/
protected $_currentFolder;
/**
* delim char for subfolders
* @var string
*/
protected $_delim;
/**
* Create instance with parameters
* Supported parameters are:
* - dirname rootdir of maildir structure
* - delim delim char for folder structur, default is '.'
* - folder intial selected folder, default is 'INBOX'
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
if (!isset($params->dirname) || !is_dir($params->dirname)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('no valid dirname given in params');
}
$this->_rootdir = rtrim($params->dirname, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->_delim = isset($params->delim) ? $params->delim : '.';
$this->_buildFolderTree();
$this->selectFolder(!empty($params->folder) ? $params->folder : 'INBOX');
$this->_has['top'] = true;
$this->_has['flags'] = true;
}
/**
* find all subfolders and mbox files for folder structure
*
* Result is save in Zend_Mail_Storage_Folder instances with the root in $this->_rootFolder.
* $parentFolder and $parentGlobalName are only used internally for recursion.
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
protected function _buildFolderTree()
{
$this->_rootFolder = new Zend_Mail_Storage_Folder('/', '/', false);
$this->_rootFolder->INBOX = new Zend_Mail_Storage_Folder('INBOX', 'INBOX', true);
$dh = @opendir($this->_rootdir);
if (!$dh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("can't read folders in maildir");
}
$dirs = array();
while (($entry = readdir($dh)) !== false) {
// maildir++ defines folders must start with .
if ($entry[0] != '.' || $entry == '.' || $entry == '..') {
continue;
}
if ($this->_isMaildir($this->_rootdir . $entry)) {
$dirs[] = $entry;
}
}
closedir($dh);
sort($dirs);
$stack = array(null);
$folderStack = array(null);
$parentFolder = $this->_rootFolder;
$parent = '.';
foreach ($dirs as $dir) {
do {
if (strpos($dir, $parent) === 0) {
$local = substr($dir, strlen($parent));
if (strpos($local, $this->_delim) !== false) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('error while reading maildir');
}
array_push($stack, $parent);
$parent = $dir . $this->_delim;
$folder = new Zend_Mail_Storage_Folder($local, substr($dir, 1), true);
$parentFolder->$local = $folder;
array_push($folderStack, $parentFolder);
$parentFolder = $folder;
break;
} else if ($stack) {
$parent = array_pop($stack);
$parentFolder = array_pop($folderStack);
}
} while ($stack);
if (!$stack) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('error while reading maildir');
}
}
}
/**
* get root folder or given folder
*
* @param string $rootFolder get folder structure for given folder, else root
* @return Zend_Mail_Storage_Folder root or wanted folder
* @throws Zend_Mail_Storage_Exception
*/
public function getFolders($rootFolder = null)
{
if (!$rootFolder || $rootFolder == 'INBOX') {
return $this->_rootFolder;
}
// rootdir is same as INBOX in maildir
if (strpos($rootFolder, 'INBOX' . $this->_delim) === 0) {
$rootFolder = substr($rootFolder, 6);
}
$currentFolder = $this->_rootFolder;
$subname = trim($rootFolder, $this->_delim);
while ($currentFolder) {
@list($entry, $subname) = @explode($this->_delim, $subname, 2);
$currentFolder = $currentFolder->$entry;
if (!$subname) {
break;
}
}
if ($currentFolder->getGlobalName() != rtrim($rootFolder, $this->_delim)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("folder $rootFolder not found");
}
return $currentFolder;
}
/**
* select given folder
*
* folder must be selectable!
*
* @param Zend_Mail_Storage_Folder|string $globalName global name of folder or instance for subfolder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function selectFolder($globalName)
{
$this->_currentFolder = (string)$globalName;
// getting folder from folder tree for validation
$folder = $this->getFolders($this->_currentFolder);
try {
$this->_openMaildir($this->_rootdir . '.' . $folder->getGlobalName());
} catch(Zend_Mail_Storage_Exception $e) {
// check what went wrong
if (!$folder->isSelectable()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable");
}
// seems like file has vanished; rebuilding folder tree - but it's still an exception
$this->_buildFolderTree($this->_rootdir);
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('seems like the maildir has vanished, I\'ve rebuild the ' .
'folder tree, search for an other folder and try again');
}
}
/**
* get Zend_Mail_Storage_Folder instance for current folder
*
* @return Zend_Mail_Storage_Folder instance of current folder
* @throws Zend_Mail_Storage_Exception
*/
public function getCurrentFolder()
{
return $this->_currentFolder;
}
}
Mail/Storage/Folder/Mbox.php 0000604 00000021001 15071256135 0011656 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Mbox.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Mail_Storage_Folder
*/
require_once 'Zend/Mail/Storage/Folder.php';
/**
* @see Zend_Mail_Storage_Folder_Interface
*/
require_once 'Zend/Mail/Storage/Folder/Interface.php';
/**
* @see Zend_Mail_Storage_Mbox
*/
require_once 'Zend/Mail/Storage/Mbox.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Folder_Mbox extends Zend_Mail_Storage_Mbox implements Zend_Mail_Storage_Folder_Interface
{
/**
* Zend_Mail_Storage_Folder root folder for folder structure
* @var Zend_Mail_Storage_Folder
*/
protected $_rootFolder;
/**
* rootdir of folder structure
* @var string
*/
protected $_rootdir;
/**
* name of current folder
* @var string
*/
protected $_currentFolder;
/**
* Create instance with parameters
*
* Disallowed parameters are:
* - filename use Zend_Mail_Storage_Mbox for a single file
* Supported parameters are:
* - dirname rootdir of mbox structure
* - folder intial selected folder, default is 'INBOX'
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
if (isset($params->filename)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('use Zend_Mail_Storage_Mbox for a single file');
}
if (!isset($params->dirname) || !is_dir($params->dirname)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('no valid dirname given in params');
}
$this->_rootdir = rtrim($params->dirname, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->_buildFolderTree($this->_rootdir);
$this->selectFolder(!empty($params->folder) ? $params->folder : 'INBOX');
$this->_has['top'] = true;
$this->_has['uniqueid'] = false;
}
/**
* find all subfolders and mbox files for folder structure
*
* Result is save in Zend_Mail_Storage_Folder instances with the root in $this->_rootFolder.
* $parentFolder and $parentGlobalName are only used internally for recursion.
*
* @param string $currentDir call with root dir, also used for recursion.
* @param Zend_Mail_Storage_Folder|null $parentFolder used for recursion
* @param string $parentGlobalName used for rescursion
* @return null
* @throws Zend_Mail_Storage_Exception
*/
protected function _buildFolderTree($currentDir, $parentFolder = null, $parentGlobalName = '')
{
if (!$parentFolder) {
$this->_rootFolder = new Zend_Mail_Storage_Folder('/', '/', false);
$parentFolder = $this->_rootFolder;
}
$dh = @opendir($currentDir);
if (!$dh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("can't read dir $currentDir");
}
while (($entry = readdir($dh)) !== false) {
// ignore hidden files for mbox
if ($entry[0] == '.') {
continue;
}
$absoluteEntry = $currentDir . $entry;
$globalName = $parentGlobalName . DIRECTORY_SEPARATOR . $entry;
if (is_file($absoluteEntry) && $this->_isMboxFile($absoluteEntry)) {
$parentFolder->$entry = new Zend_Mail_Storage_Folder($entry, $globalName);
continue;
}
if (!is_dir($absoluteEntry) /* || $entry == '.' || $entry == '..' */) {
continue;
}
$folder = new Zend_Mail_Storage_Folder($entry, $globalName, false);
$parentFolder->$entry = $folder;
$this->_buildFolderTree($absoluteEntry . DIRECTORY_SEPARATOR, $folder, $globalName);
}
closedir($dh);
}
/**
* get root folder or given folder
*
* @param string $rootFolder get folder structure for given folder, else root
* @return Zend_Mail_Storage_Folder root or wanted folder
* @throws Zend_Mail_Storage_Exception
*/
public function getFolders($rootFolder = null)
{
if (!$rootFolder) {
return $this->_rootFolder;
}
$currentFolder = $this->_rootFolder;
$subname = trim($rootFolder, DIRECTORY_SEPARATOR);
while ($currentFolder) {
@list($entry, $subname) = @explode(DIRECTORY_SEPARATOR, $subname, 2);
$currentFolder = $currentFolder->$entry;
if (!$subname) {
break;
}
}
if ($currentFolder->getGlobalName() != DIRECTORY_SEPARATOR . trim($rootFolder, DIRECTORY_SEPARATOR)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("folder $rootFolder not found");
}
return $currentFolder;
}
/**
* select given folder
*
* folder must be selectable!
*
* @param Zend_Mail_Storage_Folder|string $globalName global name of folder or instance for subfolder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function selectFolder($globalName)
{
$this->_currentFolder = (string)$globalName;
// getting folder from folder tree for validation
$folder = $this->getFolders($this->_currentFolder);
try {
$this->_openMboxFile($this->_rootdir . $folder->getGlobalName());
} catch(Zend_Mail_Storage_Exception $e) {
// check what went wrong
if (!$folder->isSelectable()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable");
}
// seems like file has vanished; rebuilding folder tree - but it's still an exception
$this->_buildFolderTree($this->_rootdir);
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('seems like the mbox file has vanished, I\'ve rebuild the ' .
'folder tree, search for an other folder and try again');
}
}
/**
* get Zend_Mail_Storage_Folder instance for current folder
*
* @return Zend_Mail_Storage_Folder instance of current folder
* @throws Zend_Mail_Storage_Exception
*/
public function getCurrentFolder()
{
return $this->_currentFolder;
}
/**
* magic method for serialize()
*
* with this method you can cache the mbox class
*
* @return array name of variables
*/
public function __sleep()
{
return array_merge(parent::__sleep(), array('_currentFolder', '_rootFolder', '_rootdir'));
}
/**
* magic method for unserialize()
*
* with this method you can cache the mbox class
*
* @return null
*/
public function __wakeup()
{
// if cache is stall selectFolder() rebuilds the tree on error
parent::__wakeup();
}
}
Mail/Storage/Imap.php 0000604 00000052525 15071256135 0010443 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Imap.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Mail_Storage_Abstract
*/
require_once 'Zend/Mail/Storage/Abstract.php';
/**
* @see Zend_Mail_Protocol_Imap
*/
require_once 'Zend/Mail/Protocol/Imap.php';
/**
* @see Zend_Mail_Storage_Writable_Interface
*/
require_once 'Zend/Mail/Storage/Writable/Interface.php';
/**
* @see Zend_Mail_Storage_Folder_Interface
*/
require_once 'Zend/Mail/Storage/Folder/Interface.php';
/**
* @see Zend_Mail_Storage_Folder
*/
require_once 'Zend/Mail/Storage/Folder.php';
/**
* @see Zend_Mail_Message
*/
require_once 'Zend/Mail/Message.php';
/**
* @see Zend_Mail_Storage
*/
require_once 'Zend/Mail/Storage.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Imap extends Zend_Mail_Storage_Abstract
implements Zend_Mail_Storage_Folder_Interface, Zend_Mail_Storage_Writable_Interface
{
// TODO: with an internal cache we could optimize this class, or create an extra class with
// such optimizations. Especially the various fetch calls could be combined to one cache call
/**
* protocol handler
* @var null|Zend_Mail_Protocol_Imap
*/
protected $_protocol;
/**
* name of current folder
* @var string
*/
protected $_currentFolder = '';
/**
* imap flags to constants translation
* @var array
*/
protected static $_knownFlags = array('\Passed' => Zend_Mail_Storage::FLAG_PASSED,
'\Answered' => Zend_Mail_Storage::FLAG_ANSWERED,
'\Seen' => Zend_Mail_Storage::FLAG_SEEN,
'\Deleted' => Zend_Mail_Storage::FLAG_DELETED,
'\Draft' => Zend_Mail_Storage::FLAG_DRAFT,
'\Flagged' => Zend_Mail_Storage::FLAG_FLAGGED);
/**
* map flags to search criterias
* @var array
*/
protected static $_searchFlags = array('\Recent' => 'RECENT',
'\Answered' => 'ANSWERED',
'\Seen' => 'SEEN',
'\Deleted' => 'DELETED',
'\Draft' => 'DRAFT',
'\Flagged' => 'FLAGGED');
/**
* Count messages all messages in current box
*
* @return int number of messages
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function countMessages($flags = null)
{
if (!$this->_currentFolder) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('No selected folder to count');
}
if ($flags === null) {
return count($this->_protocol->search(array('ALL')));
}
$params = array();
foreach ((array)$flags as $flag) {
if (isset(self::$_searchFlags[$flag])) {
$params[] = self::$_searchFlags[$flag];
} else {
$params[] = 'KEYWORD';
$params[] = $this->_protocol->escapeString($flag);
}
}
return count($this->_protocol->search($params));
}
/**
* get a list of messages with number and size
*
* @param int $id number of message
* @return int|array size of given message of list with all messages as array(num => size)
* @throws Zend_Mail_Protocol_Exception
*/
public function getSize($id = 0)
{
if ($id) {
return $this->_protocol->fetch('RFC822.SIZE', $id);
}
return $this->_protocol->fetch('RFC822.SIZE', 1, INF);
}
/**
* Fetch a message
*
* @param int $id number of message
* @return Zend_Mail_Message
* @throws Zend_Mail_Protocol_Exception
*/
public function getMessage($id)
{
$data = $this->_protocol->fetch(array('FLAGS', 'RFC822.HEADER'), $id);
$header = $data['RFC822.HEADER'];
$flags = array();
foreach ($data['FLAGS'] as $flag) {
$flags[] = isset(self::$_knownFlags[$flag]) ? self::$_knownFlags[$flag] : $flag;
}
return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $header, 'flags' => $flags));
}
/*
* Get raw header of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage header
* @param int $topLines include this many lines with header (after an empty line)
* @param int $topLines include this many lines with header (after an empty line)
* @return string raw header
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawHeader($id, $part = null, $topLines = 0)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
// TODO: toplines
return $this->_protocol->fetch('RFC822.HEADER', $id);
}
/*
* Get raw content of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage content
* @return string raw content
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawContent($id, $part = null)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
return $this->_protocol->fetch('RFC822.TEXT', $id);
}
/**
* create instance with parameters
* Supported paramters are
* - user username
* - host hostname or ip address of IMAP server [optional, default = 'localhost']
* - password password for user 'username' [optional, default = '']
* - port port for IMAP server [optional, default = 110]
* - ssl 'SSL' or 'TLS' for secure sockets
* - folder select this folder [optional, default = 'INBOX']
*
* @param array $params mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
$this->_has['flags'] = true;
if ($params instanceof Zend_Mail_Protocol_Imap) {
$this->_protocol = $params;
try {
$this->selectFolder('INBOX');
} catch(Zend_Mail_Storage_Exception $e) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot select INBOX, is this a valid transport?');
}
return;
}
if (!isset($params->user)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('need at least user in params');
}
$host = isset($params->host) ? $params->host : 'localhost';
$password = isset($params->password) ? $params->password : '';
$port = isset($params->port) ? $params->port : null;
$ssl = isset($params->ssl) ? $params->ssl : false;
$this->_protocol = new Zend_Mail_Protocol_Imap();
$this->_protocol->connect($host, $port, $ssl);
if (!$this->_protocol->login($params->user, $password)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot login, user or password wrong');
}
$this->selectFolder(isset($params->folder) ? $params->folder : 'INBOX');
}
/**
* Close resource for mail lib. If you need to control, when the resource
* is closed. Otherwise the destructor would call this.
*
* @return null
*/
public function close()
{
$this->_currentFolder = '';
$this->_protocol->logout();
}
/**
* Keep the server busy.
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function noop()
{
if (!$this->_protocol->noop()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('could not do nothing');
}
}
/**
* Remove a message from server. If you're doing that from a web enviroment
* you should be careful and use a uniqueid as parameter if possible to
* identify the message.
*
* @param int $id number of message
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeMessage($id)
{
if (!$this->_protocol->store(array(Zend_Mail_Storage::FLAG_DELETED), $id, null, '+')) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot set deleted flag');
}
// TODO: expunge here or at close? we can handle an error here better and are more fail safe
if (!$this->_protocol->expunge()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('message marked as deleted, but could not expunge');
}
}
/**
* get unique id for one or all messages
*
* if storage does not support unique ids it's the same as the message number
*
* @param int|null $id message number
* @return array|string message number for given message or all messages as array
* @throws Zend_Mail_Storage_Exception
*/
public function getUniqueId($id = null)
{
if ($id) {
return $this->_protocol->fetch('UID', $id);
}
return $this->_protocol->fetch('UID', 1, INF);
}
/**
* get a message number from a unique id
*
* I.e. if you have a webmailer that supports deleting messages you should use unique ids
* as parameter and use this method to translate it to message number right before calling removeMessage()
*
* @param string $id unique id
* @return int message number
* @throws Zend_Mail_Storage_Exception
*/
public function getNumberByUniqueId($id)
{
// TODO: use search to find number directly
$ids = $this->getUniqueId();
foreach ($ids as $k => $v) {
if ($v == $id) {
return $k;
}
}
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('unique id not found');
}
/**
* get root folder or given folder
*
* @param string $rootFolder get folder structure for given folder, else root
* @return Zend_Mail_Storage_Folder root or wanted folder
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function getFolders($rootFolder = null)
{
$folders = $this->_protocol->listMailbox((string)$rootFolder);
if (!$folders) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('folder not found');
}
ksort($folders, SORT_STRING);
$root = new Zend_Mail_Storage_Folder('/', '/', false);
$stack = array(null);
$folderStack = array(null);
$parentFolder = $root;
$parent = '';
foreach ($folders as $globalName => $data) {
do {
if (!$parent || strpos($globalName, $parent) === 0) {
$pos = strrpos($globalName, $data['delim']);
if ($pos === false) {
$localName = $globalName;
} else {
$localName = substr($globalName, $pos + 1);
}
$selectable = !$data['flags'] || !in_array('\\Noselect', $data['flags']);
array_push($stack, $parent);
$parent = $globalName . $data['delim'];
$folder = new Zend_Mail_Storage_Folder($localName, $globalName, $selectable);
$parentFolder->$localName = $folder;
array_push($folderStack, $parentFolder);
$parentFolder = $folder;
break;
} else if ($stack) {
$parent = array_pop($stack);
$parentFolder = array_pop($folderStack);
}
} while ($stack);
if (!$stack) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('error while constructing folder tree');
}
}
return $root;
}
/**
* select given folder
*
* folder must be selectable!
*
* @param Zend_Mail_Storage_Folder|string $globalName global name of folder or instance for subfolder
* @return null
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function selectFolder($globalName)
{
$this->_currentFolder = $globalName;
if (!$this->_protocol->select($this->_currentFolder)) {
$this->_currentFolder = '';
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot change folder, maybe it does not exist');
}
}
/**
* get Zend_Mail_Storage_Folder instance for current folder
*
* @return Zend_Mail_Storage_Folder instance of current folder
* @throws Zend_Mail_Storage_Exception
*/
public function getCurrentFolder()
{
return $this->_currentFolder;
}
/**
* create a new folder
*
* This method also creates parent folders if necessary. Some mail storages may restrict, which folder
* may be used as parent or which chars may be used in the folder name
*
* @param string $name global name of folder, local name if $parentFolder is set
* @param string|Zend_Mail_Storage_Folder $parentFolder parent folder for new folder, else root folder is parent
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function createFolder($name, $parentFolder = null)
{
// TODO: we assume / as the hierarchy delim - need to get that from the folder class!
if ($parentFolder instanceof Zend_Mail_Storage_Folder) {
$folder = $parentFolder->getGlobalName() . '/' . $name;
} else if ($parentFolder != null) {
$folder = $parentFolder . '/' . $name;
} else {
$folder = $name;
}
if (!$this->_protocol->create($folder)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot create folder');
}
}
/**
* remove a folder
*
* @param string|Zend_Mail_Storage_Folder $name name or instance of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeFolder($name)
{
if ($name instanceof Zend_Mail_Storage_Folder) {
$name = $name->getGlobalName();
}
if (!$this->_protocol->delete($name)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot delete folder');
}
}
/**
* rename and/or move folder
*
* The new name has the same restrictions as in createFolder()
*
* @param string|Zend_Mail_Storage_Folder $oldName name or instance of folder
* @param string $newName new global name of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function renameFolder($oldName, $newName)
{
if ($oldName instanceof Zend_Mail_Storage_Folder) {
$oldName = $oldName->getGlobalName();
}
if (!$this->_protocol->rename($oldName, $newName)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot rename folder');
}
}
/**
* append a new message to mail storage
*
* @param string $message message as string or instance of message class
* @param null|string|Zend_Mail_Storage_Folder $folder folder for new message, else current folder is taken
* @param null|array $flags set flags for new message, else a default set is used
* @throws Zend_Mail_Storage_Exception
*/
// not yet * @param string|Zend_Mail_Message|Zend_Mime_Message $message message as string or instance of message class
public function appendMessage($message, $folder = null, $flags = null)
{
if ($folder === null) {
$folder = $this->_currentFolder;
}
if ($flags === null) {
$flags = array(Zend_Mail_Storage::FLAG_SEEN);
}
// TODO: handle class instances for $message
if (!$this->_protocol->append($folder, $message, $flags)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot create message, please check if the folder exists and your flags');
}
}
/**
* copy an existing message
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function copyMessage($id, $folder)
{
if (!$this->_protocol->copy($folder, $id)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot copy message, does the folder exist?');
}
}
/**
* move an existing message
*
* NOTE: imap has no native move command, thus it's emulated with copy and delete
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function moveMessage($id, $folder) {
$this->copyMessage($id, $folder);
$this->removeMessage($id);
}
/**
* set flags for message
*
* NOTE: this method can't set the recent flag.
*
* @param int $id number of message
* @param array $flags new flags for message
* @throws Zend_Mail_Storage_Exception
*/
public function setFlags($id, $flags)
{
if (!$this->_protocol->store($flags, $id)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot set flags, have you tried to set the recent flag or special chars?');
}
}
}
Mail/Storage/Pop3.php 0000604 00000023076 15071256135 0010375 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Pop3.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* @see Zend_Mail_Storage_Abstract
*/
require_once 'Zend/Mail/Storage/Abstract.php';
/**
* @see Zend_Mail_Protocol_Pop3
*/
require_once 'Zend/Mail/Protocol/Pop3.php';
/**
* @see Zend_Mail_Message
*/
require_once 'Zend/Mail/Message.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Pop3 extends Zend_Mail_Storage_Abstract
{
/**
* protocol handler
* @var null|Zend_Mail_Protocol_Pop3
*/
protected $_protocol;
/**
* Count messages all messages in current box
*
* @return int number of messages
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function countMessages()
{
$this->_protocol->status($count, $null);
return (int)$count;
}
/**
* get a list of messages with number and size
*
* @param int $id number of message
* @return int|array size of given message of list with all messages as array(num => size)
* @throws Zend_Mail_Protocol_Exception
*/
public function getSize($id = 0)
{
$id = $id ? $id : null;
return $this->_protocol->getList($id);
}
/**
* Fetch a message
*
* @param int $id number of message
* @return Zend_Mail_Message
* @throws Zend_Mail_Protocol_Exception
*/
public function getMessage($id)
{
$bodyLines = 0;
$message = $this->_protocol->top($id, $bodyLines, true);
return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $message,
'noToplines' => $bodyLines < 1));
}
/*
* Get raw header of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage header
* @param int $topLines include this many lines with header (after an empty line)
* @return string raw header
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawHeader($id, $part = null, $topLines = 0)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
return $this->_protocol->top($id, 0, true);
}
/*
* Get raw content of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage content
* @return string raw content
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawContent($id, $part = null)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
$content = $this->_protocol->retrieve($id);
// TODO: find a way to avoid decoding the headers
Zend_Mime_Decode::splitMessage($content, $null, $body);
return $body;
}
/**
* create instance with parameters
* Supported paramters are
* - host hostname or ip address of POP3 server
* - user username
* - password password for user 'username' [optional, default = '']
* - port port for POP3 server [optional, default = 110]
* - ssl 'SSL' or 'TLS' for secure sockets
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
$this->_has['fetchPart'] = false;
$this->_has['top'] = null;
$this->_has['uniqueid'] = null;
if ($params instanceof Zend_Mail_Protocol_Pop3) {
$this->_protocol = $params;
return;
}
if (!isset($params->user)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('need at least user in params');
}
$host = isset($params->host) ? $params->host : 'localhost';
$password = isset($params->password) ? $params->password : '';
$port = isset($params->port) ? $params->port : null;
$ssl = isset($params->ssl) ? $params->ssl : false;
$this->_protocol = new Zend_Mail_Protocol_Pop3();
$this->_protocol->connect($host, $port, $ssl);
$this->_protocol->login($params->user, $password);
}
/**
* Close resource for mail lib. If you need to control, when the resource
* is closed. Otherwise the destructor would call this.
*
* @return null
*/
public function close()
{
$this->_protocol->logout();
}
/**
* Keep the server busy.
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function noop()
{
return $this->_protocol->noop();
}
/**
* Remove a message from server. If you're doing that from a web enviroment
* you should be careful and use a uniqueid as parameter if possible to
* identify the message.
*
* @param int $id number of message
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function removeMessage($id)
{
$this->_protocol->delete($id);
}
/**
* get unique id for one or all messages
*
* if storage does not support unique ids it's the same as the message number
*
* @param int|null $id message number
* @return array|string message number for given message or all messages as array
* @throws Zend_Mail_Storage_Exception
*/
public function getUniqueId($id = null)
{
if (!$this->hasUniqueid) {
if ($id) {
return $id;
}
$count = $this->countMessages();
if ($count < 1) {
return array();
}
$range = range(1, $count);
return array_combine($range, $range);
}
return $this->_protocol->uniqueid($id);
}
/**
* get a message number from a unique id
*
* I.e. if you have a webmailer that supports deleting messages you should use unique ids
* as parameter and use this method to translate it to message number right before calling removeMessage()
*
* @param string $id unique id
* @return int message number
* @throws Zend_Mail_Storage_Exception
*/
public function getNumberByUniqueId($id)
{
if (!$this->hasUniqueid) {
return $id;
}
$ids = $this->getUniqueId();
foreach ($ids as $k => $v) {
if ($v == $id) {
return $k;
}
}
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('unique id not found');
}
/**
* Special handling for hasTop and hasUniqueid. The headers of the first message is
* retrieved if Top wasn't needed/tried yet.
*
* @see Zend_Mail_Storage_Abstract:__get()
* @param string $var
* @return string
* @throws Zend_Mail_Storage_Exception
*/
public function __get($var)
{
$result = parent::__get($var);
if ($result !== null) {
return $result;
}
if (strtolower($var) == 'hastop') {
if ($this->_protocol->hasTop === null) {
// need to make a real call, because not all server are honest in their capas
try {
$this->_protocol->top(1, 0, false);
} catch(Zend_Mail_Exception $e) {
// ignoring error
}
}
$this->_has['top'] = $this->_protocol->hasTop;
return $this->_protocol->hasTop;
}
if (strtolower($var) == 'hasuniqueid') {
$id = null;
try {
$id = $this->_protocol->uniqueid(1);
} catch(Zend_Mail_Exception $e) {
// ignoring error
}
$this->_has['uniqueid'] = $id ? true : false;
return $this->_has['uniqueid'];
}
return $result;
}
}
Mail/Storage/Folder.php 0000604 00000013151 15071256135 0010760 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Folder.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Folder implements RecursiveIterator
{
/**
* subfolders of folder array(localName => Zend_Mail_Storage_Folder folder)
* @var array
*/
protected $_folders;
/**
* local name (name of folder in parent folder)
* @var string
*/
protected $_localName;
/**
* global name (absolute name of folder)
* @var string
*/
protected $_globalName;
/**
* folder is selectable if folder is able to hold messages, else it's just a parent folder
* @var bool
*/
protected $_selectable = true;
/**
* create a new mail folder instance
*
* @param string $localName name of folder in current subdirectory
* @param string $globalName absolute name of folder
* @param bool $selectable if true folder holds messages, if false it's just a parent for subfolders
* @param array $folders init with given instances of Zend_Mail_Storage_Folder as subfolders
*/
public function __construct($localName, $globalName = '', $selectable = true, array $folders = array())
{
$this->_localName = $localName;
$this->_globalName = $globalName ? $globalName : $localName;
$this->_selectable = $selectable;
$this->_folders = $folders;
}
/**
* implements RecursiveIterator::hasChildren()
*
* @return bool current element has children
*/
public function hasChildren()
{
$current = $this->current();
return $current && $current instanceof Zend_Mail_Storage_Folder && !$current->isLeaf();
}
/**
* implements RecursiveIterator::getChildren()
*
* @return Zend_Mail_Storage_Folder same as self::current()
*/
public function getChildren()
{
return $this->current();
}
/**
* implements Iterator::valid()
*
* @return bool check if there's a current element
*/
public function valid()
{
return key($this->_folders) !== null;
}
/**
* implements Iterator::next()
*
* @return null
*/
public function next()
{
next($this->_folders);
}
/**
* implements Iterator::key()
*
* @return string key/local name of current element
*/
public function key()
{
return key($this->_folders);
}
/**
* implements Iterator::current()
*
* @return Zend_Mail_Storage_Folder current folder
*/
public function current()
{
return current($this->_folders);
}
/**
* implements Iterator::rewind()
*
* @return null
*/
public function rewind()
{
reset($this->_folders);
}
/**
* get subfolder named $name
*
* @param string $name wanted subfolder
* @return Zend_Mail_Storage_Folder folder named $folder
* @throws Zend_Mail_Storage_Exception
*/
public function __get($name)
{
if (!isset($this->_folders[$name])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("no subfolder named $name");
}
return $this->_folders[$name];
}
/**
* add or replace subfolder named $name
*
* @param string $name local name of subfolder
* @param Zend_Mail_Storage_Folder $folder instance for new subfolder
* @return null
*/
public function __set($name, Zend_Mail_Storage_Folder $folder)
{
$this->_folders[$name] = $folder;
}
/**
* remove subfolder named $name
*
* @param string $name local name of subfolder
* @return null
*/
public function __unset($name)
{
unset($this->_folders[$name]);
}
/**
* magic method for easy output of global name
*
* @return string global name of folder
*/
public function __toString()
{
return (string)$this->getGlobalName();
}
/**
* get local name
*
* @return string local name
*/
public function getLocalName()
{
return $this->_localName;
}
/**
* get global name
*
* @return string global name
*/
public function getGlobalName()
{
return $this->_globalName;
}
/**
* is this folder selectable?
*
* @return bool selectable
*/
public function isSelectable()
{
return $this->_selectable;
}
/**
* check if folder has no subfolder
*
* @return bool true if no subfolders
*/
public function isLeaf()
{
return empty($this->_folders);
}
}
Mail/Storage/Writable/Interface.php 0000604 00000007332 15071256135 0013222 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Interface.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Storage_Writable_Interface
{
/**
* create a new folder
*
* This method also creates parent folders if necessary. Some mail storages may restrict, which folder
* may be used as parent or which chars may be used in the folder name
*
* @param string $name global name of folder, local name if $parentFolder is set
* @param string|Zend_Mail_Storage_Folder $parentFolder parent folder for new folder, else root folder is parent
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function createFolder($name, $parentFolder = null);
/**
* remove a folder
*
* @param string|Zend_Mail_Storage_Folder $name name or instance of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeFolder($name);
/**
* rename and/or move folder
*
* The new name has the same restrictions as in createFolder()
*
* @param string|Zend_Mail_Storage_Folder $oldName name or instance of folder
* @param string $newName new global name of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function renameFolder($oldName, $newName);
/**
* append a new message to mail storage
*
* @param string|Zend_Mail_Message|Zend_Mime_Message $message message as string or instance of message class
* @param null|string|Zend_Mail_Storage_Folder $folder folder for new message, else current folder is taken
* @param null|array $flags set flags for new message, else a default set is used
* @throws Zend_Mail_Storage_Exception
*/
public function appendMessage($message, $folder = null, $flags = null);
/**
* copy an existing message
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function copyMessage($id, $folder);
/**
* move an existing message
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function moveMessage($id, $folder);
/**
* set flags for message
*
* NOTE: this method can't set the recent flag.
*
* @param int $id number of message
* @param array $flags new flags for message
* @throws Zend_Mail_Storage_Exception
*/
public function setFlags($id, $flags);
} Mail/Storage/Writable/Maildir.php 0000604 00000116147 15071256135 0012710 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Maildir.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Mail_Storage_Folder_Maildir
*/
require_once 'Zend/Mail/Storage/Folder/Maildir.php';
/**
* @see Zend_Mail_Storage_Writable_Interface
*/
require_once 'Zend/Mail/Storage/Writable/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Writable_Maildir extends Zend_Mail_Storage_Folder_Maildir
implements Zend_Mail_Storage_Writable_Interface
{
// TODO: init maildir (+ constructor option create if not found)
/**
* use quota and size of quota if given
* @var bool|int
*/
protected $_quota;
/**
* create a new maildir
*
* If the given dir is already a valid maildir this will not fail.
*
* @param string $dir directory for the new maildir (may already exist)
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public static function initMaildir($dir)
{
if (file_exists($dir)) {
if (!is_dir($dir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('maildir must be a directory if already exists');
}
} else {
if (!mkdir($dir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
$dir = dirname($dir);
if (!file_exists($dir)) {
throw new Zend_Mail_Storage_Exception("parent $dir not found");
} else if (!is_dir($dir)) {
throw new Zend_Mail_Storage_Exception("parent $dir not a directory");
} else {
throw new Zend_Mail_Storage_Exception('cannot create maildir');
}
}
}
foreach (array('cur', 'tmp', 'new') as $subdir) {
if (!@mkdir($dir . DIRECTORY_SEPARATOR . $subdir)) {
// ignore if dir exists (i.e. was already valid maildir or two processes try to create one)
if (!file_exists($dir . DIRECTORY_SEPARATOR . $subdir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('could not create subdir ' . $subdir);
}
}
}
}
/**
* Create instance with parameters
* Additional parameters are (see parent for more):
* - create if true a new maildir is create if none exists
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
public function __construct($params) {
if (is_array($params)) {
$params = (object)$params;
}
if (!empty($params->create) && isset($params->dirname) && !file_exists($params->dirname . DIRECTORY_SEPARATOR . 'cur')) {
self::initMaildir($params->dirname);
}
parent::__construct($params);
}
/**
* create a new folder
*
* This method also creates parent folders if necessary. Some mail storages may restrict, which folder
* may be used as parent or which chars may be used in the folder name
*
* @param string $name global name of folder, local name if $parentFolder is set
* @param string|Zend_Mail_Storage_Folder $parentFolder parent folder for new folder, else root folder is parent
* @return string only used internally (new created maildir)
* @throws Zend_Mail_Storage_Exception
*/
public function createFolder($name, $parentFolder = null)
{
if ($parentFolder instanceof Zend_Mail_Storage_Folder) {
$folder = $parentFolder->getGlobalName() . $this->_delim . $name;
} else if ($parentFolder != null) {
$folder = rtrim($parentFolder, $this->_delim) . $this->_delim . $name;
} else {
$folder = $name;
}
$folder = trim($folder, $this->_delim);
// first we check if we try to create a folder that does exist
$exists = null;
try {
$exists = $this->getFolders($folder);
} catch (Zend_Mail_Exception $e) {
// ok
}
if ($exists) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('folder already exists');
}
if (strpos($folder, $this->_delim . $this->_delim) !== false) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('invalid name - folder parts may not be empty');
}
if (strpos($folder, 'INBOX' . $this->_delim) === 0) {
$folder = substr($folder, 6);
}
$fulldir = $this->_rootdir . '.' . $folder;
// check if we got tricked and would create a dir outside of the rootdir or not as direct child
if (strpos($folder, DIRECTORY_SEPARATOR) !== false || strpos($folder, '/') !== false
|| dirname($fulldir) . DIRECTORY_SEPARATOR != $this->_rootdir) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('invalid name - no directory seprator allowed in folder name');
}
// has a parent folder?
$parent = null;
if (strpos($folder, $this->_delim)) {
// let's see if the parent folder exists
$parent = substr($folder, 0, strrpos($folder, $this->_delim));
try {
$this->getFolders($parent);
} catch (Zend_Mail_Exception $e) {
// does not - create parent folder
$this->createFolder($parent);
}
}
if (!@mkdir($fulldir) || !@mkdir($fulldir . DIRECTORY_SEPARATOR . 'cur')) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('error while creating new folder, may be created incompletly');
}
mkdir($fulldir . DIRECTORY_SEPARATOR . 'new');
mkdir($fulldir . DIRECTORY_SEPARATOR . 'tmp');
$localName = $parent ? substr($folder, strlen($parent) + 1) : $folder;
$this->getFolders($parent)->$localName = new Zend_Mail_Storage_Folder($localName, $folder, true);
return $fulldir;
}
/**
* remove a folder
*
* @param string|Zend_Mail_Storage_Folder $name name or instance of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeFolder($name)
{
// TODO: This could fail in the middle of the task, which is not optimal.
// But there is no defined standard way to mark a folder as removed and there is no atomar fs-op
// to remove a directory. Also moving the folder to a/the trash folder is not possible, as
// all parent folders must be created. What we could do is add a dash to the front of the
// directory name and it should be ignored as long as other processes obey the standard.
if ($name instanceof Zend_Mail_Storage_Folder) {
$name = $name->getGlobalName();
}
$name = trim($name, $this->_delim);
if (strpos($name, 'INBOX' . $this->_delim) === 0) {
$name = substr($name, 6);
}
// check if folder exists and has no children
if (!$this->getFolders($name)->isLeaf()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('delete children first');
}
if ($name == 'INBOX' || $name == DIRECTORY_SEPARATOR || $name == '/') {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('wont delete INBOX');
}
if ($name == $this->getCurrentFolder()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('wont delete selected folder');
}
foreach (array('tmp', 'new', 'cur', '.') as $subdir) {
$dir = $this->_rootdir . '.' . $name . DIRECTORY_SEPARATOR . $subdir;
if (!file_exists($dir)) {
continue;
}
$dh = opendir($dir);
if (!$dh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("error opening $subdir");
}
while (($entry = readdir($dh)) !== false) {
if ($entry == '.' || $entry == '..') {
continue;
}
if (!unlink($dir . DIRECTORY_SEPARATOR . $entry)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("error cleaning $subdir");
}
}
closedir($dh);
if ($subdir !== '.') {
if (!rmdir($dir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("error removing $subdir");
}
}
}
if (!rmdir($this->_rootdir . '.' . $name)) {
// at least we should try to make it a valid maildir again
mkdir($this->_rootdir . '.' . $name . DIRECTORY_SEPARATOR . 'cur');
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("error removing maindir");
}
$parent = strpos($name, $this->_delim) ? substr($name, 0, strrpos($name, $this->_delim)) : null;
$localName = $parent ? substr($name, strlen($parent) + 1) : $name;
unset($this->getFolders($parent)->$localName);
}
/**
* rename and/or move folder
*
* The new name has the same restrictions as in createFolder()
*
* @param string|Zend_Mail_Storage_Folder $oldName name or instance of folder
* @param string $newName new global name of folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function renameFolder($oldName, $newName)
{
// TODO: This is also not atomar and has similar problems as removeFolder()
if ($oldName instanceof Zend_Mail_Storage_Folder) {
$oldName = $oldName->getGlobalName();
}
$oldName = trim($oldName, $this->_delim);
if (strpos($oldName, 'INBOX' . $this->_delim) === 0) {
$oldName = substr($oldName, 6);
}
$newName = trim($newName, $this->_delim);
if (strpos($newName, 'INBOX' . $this->_delim) === 0) {
$newName = substr($newName, 6);
}
if (strpos($newName, $oldName . $this->_delim) === 0) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('new folder cannot be a child of old folder');
}
// check if folder exists and has no children
$folder = $this->getFolders($oldName);
if ($oldName == 'INBOX' || $oldName == DIRECTORY_SEPARATOR || $oldName == '/') {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('wont rename INBOX');
}
if ($oldName == $this->getCurrentFolder()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('wont rename selected folder');
}
$newdir = $this->createFolder($newName);
if (!$folder->isLeaf()) {
foreach ($folder as $k => $v) {
$this->renameFolder($v->getGlobalName(), $newName . $this->_delim . $k);
}
}
$olddir = $this->_rootdir . '.' . $folder;
foreach (array('tmp', 'new', 'cur') as $subdir) {
$subdir = DIRECTORY_SEPARATOR . $subdir;
if (!file_exists($olddir . $subdir)) {
continue;
}
// using copy or moving files would be even better - but also much slower
if (!rename($olddir . $subdir, $newdir . $subdir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('error while moving ' . $subdir);
}
}
// create a dummy if removing fails - otherwise we can't read it next time
mkdir($olddir . DIRECTORY_SEPARATOR . 'cur');
$this->removeFolder($oldName);
}
/**
* create a uniqueid for maildir filename
*
* This is nearly the format defined in the maildir standard. The microtime() call should already
* create a uniqueid, the pid is for multicore/-cpu machine that manage to call this function at the
* exact same time, and uname() gives us the hostname for multiple machines accessing the same storage.
*
* If someone disables posix we create a random number of the same size, so this method should also
* work on Windows - if you manage to get maildir working on Windows.
* Microtime could also be disabled, altough I've never seen it.
*
* @return string new uniqueid
*/
protected function _createUniqueId()
{
$id = '';
$id .= function_exists('microtime') ? microtime(true) : (time() . ' ' . rand(0, 100000));
$id .= '.' . (function_exists('posix_getpid') ? posix_getpid() : rand(50, 65535));
$id .= '.' . php_uname('n');
return $id;
}
/**
* open a temporary maildir file
*
* makes sure tmp/ exists and create a file with a unique name
* you should close the returned filehandle!
*
* @param string $folder name of current folder without leading .
* @return array array('dirname' => dir of maildir folder, 'uniq' => unique id, 'filename' => name of create file
* 'handle' => file opened for writing)
* @throws Zend_Mail_Storage_Exception
*/
protected function _createTmpFile($folder = 'INBOX')
{
if ($folder == 'INBOX') {
$tmpdir = $this->_rootdir . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
} else {
$tmpdir = $this->_rootdir . '.' . $folder . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
}
if (!file_exists($tmpdir)) {
if (!mkdir($tmpdir)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('problems creating tmp dir');
}
}
// we should retry to create a unique id if a file with the same name exists
// to avoid a script timeout we only wait 1 second (instead of 2) and stop
// after a defined retry count
// if you change this variable take into account that it can take up to $max_tries seconds
// normally we should have a valid unique name after the first try, we're just following the "standard" here
$max_tries = 5;
for ($i = 0; $i < $max_tries; ++$i) {
$uniq = $this->_createUniqueId();
if (!file_exists($tmpdir . $uniq)) {
// here is the race condition! - as defined in the standard
// to avoid having a long time between stat()ing the file and creating it we're opening it here
// to mark the filename as taken
$fh = fopen($tmpdir . $uniq, 'w');
if (!$fh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('could not open temp file');
}
break;
}
sleep(1);
}
if (!$fh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception("tried $max_tries unique ids for a temp file, but all were taken"
. ' - giving up');
}
return array('dirname' => $this->_rootdir . '.' . $folder, 'uniq' => $uniq, 'filename' => $tmpdir . $uniq,
'handle' => $fh);
}
/**
* create an info string for filenames with given flags
*
* @param array $flags wanted flags, with the reference you'll get the set flags with correct key (= char for flag)
* @return string info string for version 2 filenames including the leading colon
* @throws Zend_Mail_Storage_Exception
*/
protected function _getInfoString(&$flags)
{
// accessing keys is easier, faster and it removes duplicated flags
$wanted_flags = array_flip($flags);
if (isset($wanted_flags[Zend_Mail_Storage::FLAG_RECENT])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('recent flag may not be set');
}
$info = ':2,';
$flags = array();
foreach (Zend_Mail_Storage_Maildir::$_knownFlags as $char => $flag) {
if (!isset($wanted_flags[$flag])) {
continue;
}
$info .= $char;
$flags[$char] = $flag;
unset($wanted_flags[$flag]);
}
if (!empty($wanted_flags)) {
$wanted_flags = implode(', ', array_keys($wanted_flags));
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('unknown flag(s): ' . $wanted_flags);
}
return $info;
}
/**
* append a new message to mail storage
*
* @param string|stream $message message as string or stream resource
* @param null|string|Zend_Mail_Storage_Folder $folder folder for new message, else current folder is taken
* @param null|array $flags set flags for new message, else a default set is used
* @param bool $recent handle this mail as if recent flag has been set,
* should only be used in delivery
* @throws Zend_Mail_Storage_Exception
*/
// not yet * @param string|Zend_Mail_Message|Zend_Mime_Message $message message as string or instance of message class
public function appendMessage($message, $folder = null, $flags = null, $recent = false)
{
if ($this->_quota && $this->checkQuota()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('storage is over quota!');
}
if ($folder === null) {
$folder = $this->_currentFolder;
}
if (!($folder instanceof Zend_Mail_Storage_Folder)) {
$folder = $this->getFolders($folder);
}
if ($flags === null) {
$flags = array(Zend_Mail_Storage::FLAG_SEEN);
}
$info = $this->_getInfoString($flags);
$temp_file = $this->_createTmpFile($folder->getGlobalName());
// TODO: handle class instances for $message
if (is_resource($message) && get_resource_type($message) == 'stream') {
stream_copy_to_stream($message, $temp_file['handle']);
} else {
fputs($temp_file['handle'], $message);
}
fclose($temp_file['handle']);
// we're adding the size to the filename for maildir++
$size = filesize($temp_file['filename']);
if ($size !== false) {
$info = ',S=' . $size . $info;
}
$new_filename = $temp_file['dirname'] . DIRECTORY_SEPARATOR;
$new_filename .= $recent ? 'new' : 'cur';
$new_filename .= DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info;
// we're throwing any exception after removing our temp file and saving it to this variable instead
$exception = null;
if (!link($temp_file['filename'], $new_filename)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
$exception = new Zend_Mail_Storage_Exception('cannot link message file to final dir');
}
@unlink($temp_file['filename']);
if ($exception) {
throw $exception;
}
$this->_files[] = array('uniq' => $temp_file['uniq'],
'flags' => $flags,
'filename' => $new_filename);
if ($this->_quota) {
$this->_addQuotaEntry((int)$size, 1);
}
}
/**
* copy an existing message
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function copyMessage($id, $folder)
{
if ($this->_quota && $this->checkQuota()) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('storage is over quota!');
}
if (!($folder instanceof Zend_Mail_Storage_Folder)) {
$folder = $this->getFolders($folder);
}
$filedata = $this->_getFileData($id);
$old_file = $filedata['filename'];
$flags = $filedata['flags'];
// copied message can't be recent
while (($key = array_search(Zend_Mail_Storage::FLAG_RECENT, $flags)) !== false) {
unset($flags[$key]);
}
$info = $this->_getInfoString($flags);
// we're creating the copy as temp file before moving to cur/
$temp_file = $this->_createTmpFile($folder->getGlobalName());
// we don't write directly to the file
fclose($temp_file['handle']);
// we're adding the size to the filename for maildir++
$size = filesize($old_file);
if ($size !== false) {
$info = ',S=' . $size . $info;
}
$new_file = $temp_file['dirname'] . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info;
// we're throwing any exception after removing our temp file and saving it to this variable instead
$exception = null;
if (!copy($old_file, $temp_file['filename'])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
$exception = new Zend_Mail_Storage_Exception('cannot copy message file');
} else if (!link($temp_file['filename'], $new_file)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
$exception = new Zend_Mail_Storage_Exception('cannot link message file to final dir');
}
@unlink($temp_file['filename']);
if ($exception) {
throw $exception;
}
if ($folder->getGlobalName() == $this->_currentFolder
|| ($this->_currentFolder == 'INBOX' && $folder->getGlobalName() == '/')) {
$this->_files[] = array('uniq' => $temp_file['uniq'],
'flags' => $flags,
'filename' => $new_file);
}
if ($this->_quota) {
$this->_addQuotaEntry((int)$size, 1);
}
}
/**
* move an existing message
*
* @param int $id number of message
* @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function moveMessage($id, $folder) {
if (!($folder instanceof Zend_Mail_Storage_Folder)) {
$folder = $this->getFolders($folder);
}
if ($folder->getGlobalName() == $this->_currentFolder
|| ($this->_currentFolder == 'INBOX' && $folder->getGlobalName() == '/')) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('target is current folder');
}
$filedata = $this->_getFileData($id);
$old_file = $filedata['filename'];
$flags = $filedata['flags'];
// moved message can't be recent
while (($key = array_search(Zend_Mail_Storage::FLAG_RECENT, $flags)) !== false) {
unset($flags[$key]);
}
$info = $this->_getInfoString($flags);
// reserving a new name
$temp_file = $this->_createTmpFile($folder->getGlobalName());
fclose($temp_file['handle']);
// we're adding the size to the filename for maildir++
$size = filesize($old_file);
if ($size !== false) {
$info = ',S=' . $size . $info;
}
$new_file = $temp_file['dirname'] . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info;
// we're throwing any exception after removing our temp file and saving it to this variable instead
$exception = null;
if (!rename($old_file, $new_file)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
$exception = new Zend_Mail_Storage_Exception('cannot move message file');
}
@unlink($temp_file['filename']);
if ($exception) {
throw $exception;
}
unset($this->_files[$id - 1]);
// remove the gap
$this->_files = array_values($this->_files);
}
/**
* set flags for message
*
* NOTE: this method can't set the recent flag.
*
* @param int $id number of message
* @param array $flags new flags for message
* @throws Zend_Mail_Storage_Exception
*/
public function setFlags($id, $flags)
{
$info = $this->_getInfoString($flags);
$filedata = $this->_getFileData($id);
// NOTE: double dirname to make sure we always move to cur. if recent flag has been set (message is in new) it will be moved to cur.
$new_filename = dirname(dirname($filedata['filename'])) . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR . "$filedata[uniq]$info";
if (!@rename($filedata['filename'], $new_filename)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot rename file');
}
$filedata['flags'] = $flags;
$filedata['filename'] = $new_filename;
$this->_files[$id - 1] = $filedata;
}
/**
* stub for not supported message deletion
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeMessage($id)
{
$filename = $this->_getFileData($id, 'filename');
if ($this->_quota) {
$size = filesize($filename);
}
if (!@unlink($filename)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot remove message');
}
unset($this->_files[$id - 1]);
// remove the gap
$this->_files = array_values($this->_files);
if ($this->_quota) {
$this->_addQuotaEntry(0 - (int)$size, -1);
}
}
/**
* enable/disable quota and set a quota value if wanted or needed
*
* You can enable/disable quota with true/false. If you don't have
* a MDA or want to enforce a quota value you can also set this value
* here. Use array('size' => SIZE_QUOTA, 'count' => MAX_MESSAGE) do
* define your quota. Order of these fields does matter!
*
* @param bool|array $value new quota value
* @return null
*/
public function setQuota($value) {
$this->_quota = $value;
}
/**
* get currently set quota
*
* @see Zend_Mail_Storage_Writable_Maildir::setQuota()
*
* @return bool|array
*/
public function getQuota($fromStorage = false) {
if ($fromStorage) {
$fh = @fopen($this->_rootdir . 'maildirsize', 'r');
if (!$fh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot open maildirsize');
}
$definition = fgets($fh);
fclose($fh);
$definition = explode(',', trim($definition));
$quota = array();
foreach ($definition as $member) {
$key = $member[strlen($member) - 1];
if ($key == 'S' || $key == 'C') {
$key = $key == 'C' ? 'count' : 'size';
}
$quota[$key] = substr($member, 0, -1);
}
return $quota;
}
return $this->_quota;
}
/**
* @see http://www.inter7.com/courierimap/README.maildirquota.html "Calculating maildirsize"
*/
protected function _calculateMaildirsize() {
$timestamps = array();
$messages = 0;
$total_size = 0;
if (is_array($this->_quota)) {
$quota = $this->_quota;
} else {
try {
$quota = $this->getQuota(true);
} catch (Zend_Mail_Storage_Exception $e) {
throw new Zend_Mail_Storage_Exception('no quota defintion found');
}
}
$folders = new RecursiveIteratorIterator($this->getFolders(), RecursiveIteratorIterator::SELF_FIRST);
foreach ($folders as $folder) {
$subdir = $folder->getGlobalName();
if ($subdir == 'INBOX') {
$subdir = '';
} else {
$subdir = '.' . $subdir;
}
if ($subdir == 'Trash') {
continue;
}
foreach (array('cur', 'new') as $subsubdir) {
$dirname = $this->_rootdir . $subdir . DIRECTORY_SEPARATOR . $subsubdir . DIRECTORY_SEPARATOR;
if (!file_exists($dirname)) {
continue;
}
// NOTE: we are using mtime instead of "the latest timestamp". The latest would be atime
// and as we are accessing the directory it would make the whole calculation useless.
$timestamps[$dirname] = filemtime($dirname);
$dh = opendir($dirname);
// NOTE: Should have been checked in constructor. Not throwing an exception here, quotas will
// therefore not be fully enforeced, but next request will fail anyway, if problem persists.
if (!$dh) {
continue;
}
while (($entry = readdir()) !== false) {
if ($entry[0] == '.' || !is_file($dirname . $entry)) {
continue;
}
if (strpos($entry, ',S=')) {
strtok($entry, '=');
$filesize = strtok(':');
if (is_numeric($filesize)) {
$total_size += $filesize;
++$messages;
continue;
}
}
$size = filesize($dirname . $entry);
if ($size === false) {
// ignore, as we assume file got removed
continue;
}
$total_size += $size;
++$messages;
}
}
}
$tmp = $this->_createTmpFile();
$fh = $tmp['handle'];
$definition = array();
foreach ($quota as $type => $value) {
if ($type == 'size' || $type == 'count') {
$type = $type == 'count' ? 'C' : 'S';
}
$definition[] = $value . $type;
}
$definition = implode(',', $definition);
fputs($fh, "$definition\n");
fputs($fh, "$total_size $messages\n");
fclose($fh);
rename($tmp['filename'], $this->_rootdir . 'maildirsize');
foreach ($timestamps as $dir => $timestamp) {
if ($timestamp < filemtime($dir)) {
unlink($this->_rootdir . 'maildirsize');
break;
}
}
return array('size' => $total_size, 'count' => $messages, 'quota' => $quota);
}
/**
* @see http://www.inter7.com/courierimap/README.maildirquota.html "Calculating the quota for a Maildir++"
*/
protected function _calculateQuota($forceRecalc = false) {
$fh = null;
$total_size = 0;
$messages = 0;
$maildirsize = '';
if (!$forceRecalc && file_exists($this->_rootdir . 'maildirsize') && filesize($this->_rootdir . 'maildirsize') < 5120) {
$fh = fopen($this->_rootdir . 'maildirsize', 'r');
}
if ($fh) {
$maildirsize = fread($fh, 5120);
if (strlen($maildirsize) >= 5120) {
fclose($fh);
$fh = null;
$maildirsize = '';
}
}
if (!$fh) {
$result = $this->_calculateMaildirsize();
$total_size = $result['size'];
$messages = $result['count'];
$quota = $result['quota'];
} else {
$maildirsize = explode("\n", $maildirsize);
if (is_array($this->_quota)) {
$quota = $this->_quota;
} else {
$definition = explode(',', $maildirsize[0]);
$quota = array();
foreach ($definition as $member) {
$key = $member[strlen($member) - 1];
if ($key == 'S' || $key == 'C') {
$key = $key == 'C' ? 'count' : 'size';
}
$quota[$key] = substr($member, 0, -1);
}
}
unset($maildirsize[0]);
foreach ($maildirsize as $line) {
list($size, $count) = explode(' ', trim($line));
$total_size += $size;
$messages += $count;
}
}
$over_quota = false;
$over_quota = $over_quota || (isset($quota['size']) && $total_size > $quota['size']);
$over_quota = $over_quota || (isset($quota['count']) && $messages > $quota['count']);
// NOTE: $maildirsize equals false if it wasn't set (AKA we recalculated) or it's only
// one line, because $maildirsize[0] gets unsetted.
// Also we're using local time to calculate the 15 minute offset. Touching a file just for known the
// local time of the file storage isn't worth the hassle.
if ($over_quota && ($maildirsize || filemtime($this->_rootdir . 'maildirsize') > time() - 900)) {
$result = $this->_calculateMaildirsize();
$total_size = $result['size'];
$messages = $result['count'];
$quota = $result['quota'];
$over_quota = false;
$over_quota = $over_quota || (isset($quota['size']) && $total_size > $quota['size']);
$over_quota = $over_quota || (isset($quota['count']) && $messages > $quota['count']);
}
if ($fh) {
// TODO is there a safe way to keep the handle open for writing?
fclose($fh);
}
return array('size' => $total_size, 'count' => $messages, 'quota' => $quota, 'over_quota' => $over_quota);
}
protected function _addQuotaEntry($size, $count = 1) {
if (!file_exists($this->_rootdir . 'maildirsize')) {
// TODO: should get file handler from _calculateQuota
}
$size = (int)$size;
$count = (int)$count;
file_put_contents($this->_rootdir . 'maildirsize', "$size $count\n", FILE_APPEND);
}
/**
* check if storage is currently over quota
*
* @param bool $detailedResponse return known data of quota and current size and message count @see _calculateQuota()
* @return bool|array over quota state or detailed response
*/
public function checkQuota($detailedResponse = false, $forceRecalc = false) {
$result = $this->_calculateQuota($forceRecalc);
return $detailedResponse ? $result : $result['over_quota'];
}
}
Mail/Storage/Mbox.php 0000604 00000031701 15071256135 0010453 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Mbox.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Loader
* May be used in constructor, but commented out for now
*/
// require_once 'Zend/Loader.php';
/**
* @see Zend_Mail_Storage_Abstract
*/
require_once 'Zend/Mail/Storage/Abstract.php';
/**
* @see Zend_Mail_Message_File
*/
require_once 'Zend/Mail/Message/File.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Mbox extends Zend_Mail_Storage_Abstract
{
/**
* file handle to mbox file
* @var null|resource
*/
protected $_fh;
/**
* filename of mbox file for __wakeup
* @var string
*/
protected $_filename;
/**
* modification date of mbox file for __wakeup
* @var int
*/
protected $_filemtime;
/**
* start and end position of messages as array('start' => start, 'seperator' => headersep, 'end' => end)
* @var array
*/
protected $_positions;
/**
* used message class, change it in an extened class to extend the returned message class
* @var string
*/
protected $_messageClass = 'Zend_Mail_Message_File';
/**
* Count messages all messages in current box
*
* @return int number of messages
* @throws Zend_Mail_Storage_Exception
*/
public function countMessages()
{
return count($this->_positions);
}
/**
* Get a list of messages with number and size
*
* @param int|null $id number of message or null for all messages
* @return int|array size of given message of list with all messages as array(num => size)
*/
public function getSize($id = 0)
{
if ($id) {
$pos = $this->_positions[$id - 1];
return $pos['end'] - $pos['start'];
}
$result = array();
foreach ($this->_positions as $num => $pos) {
$result[$num + 1] = $pos['end'] - $pos['start'];
}
return $result;
}
/**
* Get positions for mail message or throw exeption if id is invalid
*
* @param int $id number of message
* @return array positions as in _positions
* @throws Zend_Mail_Storage_Exception
*/
protected function _getPos($id)
{
if (!isset($this->_positions[$id - 1])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('id does not exist');
}
return $this->_positions[$id - 1];
}
/**
* Fetch a message
*
* @param int $id number of message
* @return Zend_Mail_Message_File
* @throws Zend_Mail_Storage_Exception
*/
public function getMessage($id)
{
// TODO that's ugly, would be better to let the message class decide
if (strtolower($this->_messageClass) == 'zend_mail_message_file' || is_subclass_of($this->_messageClass, 'zend_mail_message_file')) {
// TODO top/body lines
$messagePos = $this->_getPos($id);
return new $this->_messageClass(array('file' => $this->_fh, 'startPos' => $messagePos['start'],
'endPos' => $messagePos['end']));
}
$bodyLines = 0; // TODO: need a way to change that
$message = $this->getRawHeader($id);
// file pointer is after headers now
if ($bodyLines) {
$message .= "\n";
while ($bodyLines-- && ftell($this->_fh) < $this->_positions[$id - 1]['end']) {
$message .= fgets($this->_fh);
}
}
return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $message));
}
/*
* Get raw header of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage header
* @param int $topLines include this many lines with header (after an empty line)
* @return string raw header
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawHeader($id, $part = null, $topLines = 0)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
$messagePos = $this->_getPos($id);
// TODO: toplines
return stream_get_contents($this->_fh, $messagePos['separator'] - $messagePos['start'], $messagePos['start']);
}
/*
* Get raw content of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage content
* @return string raw content
* @throws Zend_Mail_Protocol_Exception
* @throws Zend_Mail_Storage_Exception
*/
public function getRawContent($id, $part = null)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
$messagePos = $this->_getPos($id);
return stream_get_contents($this->_fh, $messagePos['end'] - $messagePos['separator'], $messagePos['separator']);
}
/**
* Create instance with parameters
* Supported parameters are:
* - filename filename of mbox file
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
if (!isset($params->filename) /* || Zend_Loader::isReadable($params['filename']) */) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('no valid filename given in params');
}
$this->_openMboxFile($params->filename);
$this->_has['top'] = true;
$this->_has['uniqueid'] = false;
}
/**
* check if given file is a mbox file
*
* if $file is a resource its file pointer is moved after the first line
*
* @param resource|string $file stream resource of name of file
* @param bool $fileIsString file is string or resource
* @return bool file is mbox file
*/
protected function _isMboxFile($file, $fileIsString = true)
{
if ($fileIsString) {
$file = @fopen($file, 'r');
if (!$file) {
return false;
}
} else {
fseek($file, 0);
}
$result = false;
$line = fgets($file);
if (strpos($line, 'From ') === 0) {
$result = true;
}
if ($fileIsString) {
@fclose($file);
}
return $result;
}
/**
* open given file as current mbox file
*
* @param string $filename filename of mbox file
* @return null
* @throws Zend_Mail_Storage_Exception
*/
protected function _openMboxFile($filename)
{
if ($this->_fh) {
$this->close();
}
$this->_fh = @fopen($filename, 'r');
if (!$this->_fh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot open mbox file');
}
$this->_filename = $filename;
$this->_filemtime = filemtime($this->_filename);
if (!$this->_isMboxFile($this->_fh, false)) {
@fclose($this->_fh);
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('file is not a valid mbox format');
}
$messagePos = array('start' => ftell($this->_fh), 'separator' => 0, 'end' => 0);
while (($line = fgets($this->_fh)) !== false) {
if (strpos($line, 'From ') === 0) {
$messagePos['end'] = ftell($this->_fh) - strlen($line) - 2; // + newline
if (!$messagePos['separator']) {
$messagePos['separator'] = $messagePos['end'];
}
$this->_positions[] = $messagePos;
$messagePos = array('start' => ftell($this->_fh), 'separator' => 0, 'end' => 0);
}
if (!$messagePos['separator'] && !trim($line)) {
$messagePos['separator'] = ftell($this->_fh);
}
}
$messagePos['end'] = ftell($this->_fh);
if (!$messagePos['separator']) {
$messagePos['separator'] = $messagePos['end'];
}
$this->_positions[] = $messagePos;
}
/**
* Close resource for mail lib. If you need to control, when the resource
* is closed. Otherwise the destructor would call this.
*
* @return void
*/
public function close()
{
@fclose($this->_fh);
$this->_positions = array();
}
/**
* Waste some CPU cycles doing nothing.
*
* @return void
*/
public function noop()
{
return true;
}
/**
* stub for not supported message deletion
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeMessage($id)
{
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('mbox is read-only');
}
/**
* get unique id for one or all messages
*
* Mbox does not support unique ids (yet) - it's always the same as the message number.
* That shouldn't be a problem, because we can't change mbox files. Therefor the message
* number is save enough.
*
* @param int|null $id message number
* @return array|string message number for given message or all messages as array
* @throws Zend_Mail_Storage_Exception
*/
public function getUniqueId($id = null)
{
if ($id) {
// check if id exists
$this->_getPos($id);
return $id;
}
$range = range(1, $this->countMessages());
return array_combine($range, $range);
}
/**
* get a message number from a unique id
*
* I.e. if you have a webmailer that supports deleting messages you should use unique ids
* as parameter and use this method to translate it to message number right before calling removeMessage()
*
* @param string $id unique id
* @return int message number
* @throws Zend_Mail_Storage_Exception
*/
public function getNumberByUniqueId($id)
{
// check if id exists
$this->_getPos($id);
return $id;
}
/**
* magic method for serialize()
*
* with this method you can cache the mbox class
*
* @return array name of variables
*/
public function __sleep()
{
return array('_filename', '_positions', '_filemtime');
}
/**
* magic method for unserialize()
*
* with this method you can cache the mbox class
* for cache validation the mtime of the mbox file is used
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function __wakeup()
{
if ($this->_filemtime != @filemtime($this->_filename)) {
$this->close();
$this->_openMboxFile($this->_filename);
} else {
$this->_fh = @fopen($this->_filename, 'r');
if (!$this->_fh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot open mbox file');
}
}
}
}
Mail/Storage/Maildir.php 0000604 00000034324 15071256135 0011133 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Maildir.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Mail_Storage_Abstract
*/
require_once 'Zend/Mail/Storage/Abstract.php';
/**
* @see Zend_Mail_Message_File
*/
require_once 'Zend/Mail/Message/File.php';
/**
* @see Zend_Mail_Storage
*/
require_once 'Zend/Mail/Storage.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @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_Mail_Storage_Maildir extends Zend_Mail_Storage_Abstract
{
/**
* used message class, change it in an extened class to extend the returned message class
* @var string
*/
protected $_messageClass = 'Zend_Mail_Message_File';
/**
* data of found message files in maildir dir
* @var array
*/
protected $_files = array();
/**
* known flag chars in filenames
*
* This list has to be in alphabetical order for setFlags()
*
* @var array
*/
protected static $_knownFlags = array('D' => Zend_Mail_Storage::FLAG_DRAFT,
'F' => Zend_Mail_Storage::FLAG_FLAGGED,
'P' => Zend_Mail_Storage::FLAG_PASSED,
'R' => Zend_Mail_Storage::FLAG_ANSWERED,
'S' => Zend_Mail_Storage::FLAG_SEEN,
'T' => Zend_Mail_Storage::FLAG_DELETED);
// TODO: getFlags($id) for fast access if headers are not needed (i.e. just setting flags)?
/**
* Count messages all messages in current box
*
* @return int number of messages
* @throws Zend_Mail_Storage_Exception
*/
public function countMessages($flags = null)
{
if ($flags === null) {
return count($this->_files);
}
$count = 0;
if (!is_array($flags)) {
foreach ($this->_files as $file) {
if (isset($file['flaglookup'][$flags])) {
++$count;
}
}
return $count;
}
$flags = array_flip($flags);
foreach ($this->_files as $file) {
foreach ($flags as $flag => $v) {
if (!isset($file['flaglookup'][$flag])) {
continue 2;
}
}
++$count;
}
return $count;
}
/**
* Get one or all fields from file structure. Also checks if message is valid
*
* @param int $id message number
* @param string|null $field wanted field
* @return string|array wanted field or all fields as array
* @throws Zend_Mail_Storage_Exception
*/
protected function _getFileData($id, $field = null)
{
if (!isset($this->_files[$id - 1])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('id does not exist');
}
if (!$field) {
return $this->_files[$id - 1];
}
if (!isset($this->_files[$id - 1][$field])) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('field does not exist');
}
return $this->_files[$id - 1][$field];
}
/**
* Get a list of messages with number and size
*
* @param int|null $id number of message or null for all messages
* @return int|array size of given message of list with all messages as array(num => size)
* @throws Zend_Mail_Storage_Exception
*/
public function getSize($id = null)
{
if ($id !== null) {
$filedata = $this->_getFileData($id);
return isset($filedata['size']) ? $filedata['size'] : filesize($filedata['filename']);
}
$result = array();
foreach ($this->_files as $num => $data) {
$result[$num + 1] = isset($data['size']) ? $data['size'] : filesize($data['filename']);
}
return $result;
}
/**
* Fetch a message
*
* @param int $id number of message
* @return Zend_Mail_Message_File
* @throws Zend_Mail_Storage_Exception
*/
public function getMessage($id)
{
// TODO that's ugly, would be better to let the message class decide
if (strtolower($this->_messageClass) == 'zend_mail_message_file' || is_subclass_of($this->_messageClass, 'zend_mail_message_file')) {
return new $this->_messageClass(array('file' => $this->_getFileData($id, 'filename'),
'flags' => $this->_getFileData($id, 'flags')));
}
return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $this->getRawHeader($id),
'flags' => $this->_getFileData($id, 'flags')));
}
/*
* Get raw header of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage header
* @param int $topLines include this many lines with header (after an empty line)
* @return string raw header
* @throws Zend_Mail_Storage_Exception
*/
public function getRawHeader($id, $part = null, $topLines = 0)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
$fh = fopen($this->_getFileData($id, 'filename'), 'r');
$content = '';
while (!feof($fh)) {
$line = fgets($fh);
if (!trim($line)) {
break;
}
$content .= $line;
}
fclose($fh);
return $content;
}
/*
* Get raw content of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage content
* @return string raw content
* @throws Zend_Mail_Storage_Exception
*/
public function getRawContent($id, $part = null)
{
if ($part !== null) {
// TODO: implement
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('not implemented');
}
$fh = fopen($this->_getFileData($id, 'filename'), 'r');
while (!feof($fh)) {
$line = fgets($fh);
if (!trim($line)) {
break;
}
}
$content = stream_get_contents($fh);
fclose($fh);
return $content;
}
/**
* Create instance with parameters
* Supported parameters are:
* - dirname dirname of mbox file
*
* @param $params array mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
public function __construct($params)
{
if (is_array($params)) {
$params = (object)$params;
}
if (!isset($params->dirname) || !is_dir($params->dirname)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('no valid dirname given in params');
}
if (!$this->_isMaildir($params->dirname)) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('invalid maildir given');
}
$this->_has['top'] = true;
$this->_has['flags'] = true;
$this->_openMaildir($params->dirname);
}
/**
* check if a given dir is a valid maildir
*
* @param string $dirname name of dir
* @return bool dir is valid maildir
*/
protected function _isMaildir($dirname)
{
if (file_exists($dirname . '/new') && !is_dir($dirname . '/new')) {
return false;
}
if (file_exists($dirname . '/tmp') && !is_dir($dirname . '/tmp')) {
return false;
}
return is_dir($dirname . '/cur');
}
/**
* open given dir as current maildir
*
* @param string $dirname name of maildir
* @return null
* @throws Zend_Mail_Storage_Exception
*/
protected function _openMaildir($dirname)
{
if ($this->_files) {
$this->close();
}
$dh = @opendir($dirname . '/cur/');
if (!$dh) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot open maildir');
}
$this->_getMaildirFiles($dh, $dirname . '/cur/');
closedir($dh);
$dh = @opendir($dirname . '/new/');
if ($dh) {
$this->_getMaildirFiles($dh, $dirname . '/new/', array(Zend_Mail_Storage::FLAG_RECENT));
closedir($dh);
} else if (file_exists($dirname . '/new/')) {
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot read recent mails in maildir');
}
}
/**
* find all files in opened dir handle and add to maildir files
*
* @param resource $dh dir handle used for search
* @param string $dirname dirname of dir in $dh
* @param array $default_flags default flags for given dir
* @return null
*/
protected function _getMaildirFiles($dh, $dirname, $default_flags = array())
{
while (($entry = readdir($dh)) !== false) {
if ($entry[0] == '.' || !is_file($dirname . $entry)) {
continue;
}
@list($uniq, $info) = explode(':', $entry, 2);
@list(,$size) = explode(',', $uniq, 2);
if ($size && $size[0] == 'S' && $size[1] == '=') {
$size = substr($size, 2);
}
if (!ctype_digit($size)) {
$size = null;
}
@list($version, $flags) = explode(',', $info, 2);
if ($version != 2) {
$flags = '';
}
$named_flags = $default_flags;
$length = strlen($flags);
for ($i = 0; $i < $length; ++$i) {
$flag = $flags[$i];
$named_flags[$flag] = isset(self::$_knownFlags[$flag]) ? self::$_knownFlags[$flag] : $flag;
}
$data = array('uniq' => $uniq,
'flags' => $named_flags,
'flaglookup' => array_flip($named_flags),
'filename' => $dirname . $entry);
if ($size !== null) {
$data['size'] = (int)$size;
}
$this->_files[] = $data;
}
}
/**
* Close resource for mail lib. If you need to control, when the resource
* is closed. Otherwise the destructor would call this.
*
* @return void
*/
public function close()
{
$this->_files = array();
}
/**
* Waste some CPU cycles doing nothing.
*
* @return void
*/
public function noop()
{
return true;
}
/**
* stub for not supported message deletion
*
* @return null
* @throws Zend_Mail_Storage_Exception
*/
public function removeMessage($id)
{
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('maildir is (currently) read-only');
}
/**
* get unique id for one or all messages
*
* if storage does not support unique ids it's the same as the message number
*
* @param int|null $id message number
* @return array|string message number for given message or all messages as array
* @throws Zend_Mail_Storage_Exception
*/
public function getUniqueId($id = null)
{
if ($id) {
return $this->_getFileData($id, 'uniq');
}
$ids = array();
foreach ($this->_files as $num => $file) {
$ids[$num + 1] = $file['uniq'];
}
return $ids;
}
/**
* get a message number from a unique id
*
* I.e. if you have a webmailer that supports deleting messages you should use unique ids
* as parameter and use this method to translate it to message number right before calling removeMessage()
*
* @param string $id unique id
* @return int message number
* @throws Zend_Mail_Storage_Exception
*/
public function getNumberByUniqueId($id)
{
foreach ($this->_files as $num => $file) {
if ($file['uniq'] == $id) {
return $num + 1;
}
}
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('unique id not found');
}
}
Mail/Storage/Abstract.php 0000604 00000022154 15071256135 0011313 0 ustar 00 <?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_Mail
* @subpackage Storage
* @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: Abstract.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Mail_Storage_Abstract implements Countable, ArrayAccess, SeekableIterator
{
/**
* class capabilities with default values
* @var array
*/
protected $_has = array('uniqueid' => true,
'delete' => false,
'create' => false,
'top' => false,
'fetchPart' => true,
'flags' => false);
/**
* current iteration position
* @var int
*/
protected $_iterationPos = 0;
/**
* maximum iteration position (= message count)
* @var null|int
*/
protected $_iterationMax = null;
/**
* used message class, change it in an extened class to extend the returned message class
* @var string
*/
protected $_messageClass = 'Zend_Mail_Message';
/**
* Getter for has-properties. The standard has properties
* are: hasFolder, hasUniqueid, hasDelete, hasCreate, hasTop
*
* The valid values for the has-properties are:
* - true if a feature is supported
* - false if a feature is not supported
* - null is it's not yet known or it can't be know if a feature is supported
*
* @param string $var property name
* @return bool supported or not
* @throws Zend_Mail_Storage_Exception
*/
public function __get($var)
{
if (strpos($var, 'has') === 0) {
$var = strtolower(substr($var, 3));
return isset($this->_has[$var]) ? $this->_has[$var] : null;
}
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception($var . ' not found');
}
/**
* Get a full list of features supported by the specific mail lib and the server
*
* @return array list of features as array(featurename => true|false[|null])
*/
public function getCapabilities()
{
return $this->_has;
}
/**
* Count messages messages in current box/folder
*
* @return int number of messages
* @throws Zend_Mail_Storage_Exception
*/
abstract public function countMessages();
/**
* Get a list of messages with number and size
*
* @param int $id number of message
* @return int|array size of given message of list with all messages as array(num => size)
*/
abstract public function getSize($id = 0);
/**
* Get a message with headers and body
*
* @param $id int number of message
* @return Zend_Mail_Message
*/
abstract public function getMessage($id);
/**
* Get raw header of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage header
* @param int $topLines include this many lines with header (after an empty line)
* @return string raw header
*/
abstract public function getRawHeader($id, $part = null, $topLines = 0);
/**
* Get raw content of message or part
*
* @param int $id number of message
* @param null|array|string $part path to part or null for messsage content
* @return string raw content
*/
abstract public function getRawContent($id, $part = null);
/**
* Create instance with parameters
*
* @param array $params mail reader specific parameters
* @throws Zend_Mail_Storage_Exception
*/
abstract public function __construct($params);
/**
* Destructor calls close() and therefore closes the resource.
*/
public function __destruct()
{
$this->close();
}
/**
* Close resource for mail lib. If you need to control, when the resource
* is closed. Otherwise the destructor would call this.
*
* @return null
*/
abstract public function close();
/**
* Keep the resource alive.
*
* @return null
*/
abstract public function noop();
/**
* delete a message from current box/folder
*
* @return null
*/
abstract public function removeMessage($id);
/**
* get unique id for one or all messages
*
* if storage does not support unique ids it's the same as the message number
*
* @param int|null $id message number
* @return array|string message number for given message or all messages as array
* @throws Zend_Mail_Storage_Exception
*/
abstract public function getUniqueId($id = null);
/**
* get a message number from a unique id
*
* I.e. if you have a webmailer that supports deleting messages you should use unique ids
* as parameter and use this method to translate it to message number right before calling removeMessage()
*
* @param string $id unique id
* @return int message number
* @throws Zend_Mail_Storage_Exception
*/
abstract public function getNumberByUniqueId($id);
// interface implementations follows
/**
* Countable::count()
*
* @return int
*/
public function count()
{
return $this->countMessages();
}
/**
* ArrayAccess::offsetExists()
*
* @param int $id
* @return boolean
*/
public function offsetExists($id)
{
try {
if ($this->getMessage($id)) {
return true;
}
} catch(Zend_Mail_Storage_Exception $e) {}
return false;
}
/**
* ArrayAccess::offsetGet()
*
* @param int $id
* @return Zend_Mail_Message message object
*/
public function offsetGet($id)
{
return $this->getMessage($id);
}
/**
* ArrayAccess::offsetSet()
*
* @param id $id
* @param mixed $value
* @throws Zend_Mail_Storage_Exception
* @return void
*/
public function offsetSet($id, $value)
{
/**
* @see Zend_Mail_Storage_Exception
*/
require_once 'Zend/Mail/Storage/Exception.php';
throw new Zend_Mail_Storage_Exception('cannot write mail messages via array access');
}
/**
* ArrayAccess::offsetUnset()
*
* @param int $id
* @return boolean success
*/
public function offsetUnset($id)
{
return $this->removeMessage($id);
}
/**
* Iterator::rewind()
*
* Rewind always gets the new count from the storage. Thus if you use
* the interfaces and your scripts take long you should use reset()
* from time to time.
*
* @return void
*/
public function rewind()
{
$this->_iterationMax = $this->countMessages();
$this->_iterationPos = 1;
}
/**
* Iterator::current()
*
* @return Zend_Mail_Message current message
*/
public function current()
{
return $this->getMessage($this->_iterationPos);
}
/**
* Iterator::key()
*
* @return int id of current position
*/
public function key()
{
return $this->_iterationPos;
}
/**
* Iterator::next()
*
* @return void
*/
public function next()
{
++$this->_iterationPos;
}
/**
* Iterator::valid()
*
* @return boolean
*/
public function valid()
{
if ($this->_iterationMax === null) {
$this->_iterationMax = $this->countMessages();
}
return $this->_iterationPos && $this->_iterationPos <= $this->_iterationMax;
}
/**
* SeekableIterator::seek()
*
* @param int $pos
* @return void
* @throws OutOfBoundsException
*/
public function seek($pos)
{
if ($this->_iterationMax === null) {
$this->_iterationMax = $this->countMessages();
}
if ($pos > $this->_iterationMax) {
throw new OutOfBoundsException('this position does not exist');
}
$this->_iterationPos = $pos;
}
}
Uri.php 0000604 00000012444 15071256135 0006022 0 ustar 00 <?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_Uri
* @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: Uri.php 12037 2008-10-20 18:54:44Z shahar $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* Abstract class for all Zend_Uri handlers
*
* @category Zend
* @package Zend_Uri
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Uri
{
/**
* Scheme of this URI (http, ftp, etc.)
*
* @var string
*/
protected $_scheme = '';
/**
* Global configuration array
*
* @var array
*/
static protected $_config = array(
'allow_unwise' => false
);
/**
* Return a string representation of this URI.
*
* @see getUri()
* @return string
*/
public function __toString()
{
return $this->getUri();
}
/**
* Convenience function, checks that a $uri string is well-formed
* by validating it but not returning an object. Returns TRUE if
* $uri is a well-formed URI, or FALSE otherwise.
*
* @param string $uri The URI to check
* @return boolean
*/
public static function check($uri)
{
try {
$uri = self::factory($uri);
} catch (Exception $e) {
return false;
}
return $uri->valid();
}
/**
* Create a new Zend_Uri object for a URI. If building a new URI, then $uri should contain
* only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI.
*
* @param string $uri The URI form which a Zend_Uri instance is created
* @throws Zend_Uri_Exception When an empty string was supplied for the scheme
* @throws Zend_Uri_Exception When an illegal scheme is supplied
* @throws Zend_Uri_Exception When the scheme is not supported
* @return Zend_Uri
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
public static function factory($uri = 'http')
{
// Separate the scheme from the scheme-specific parts
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
if (strlen($scheme) === 0) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('An empty string was supplied for the scheme');
}
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
if (ctype_alnum($scheme) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
}
/**
* Create a new Zend_Uri object for the $uri. If a subclass of Zend_Uri exists for the
* scheme, return an instance of that class. Otherwise, a Zend_Uri_Exception is thrown.
*/
switch ($scheme) {
case 'http':
// Break intentionally omitted
case 'https':
$className = 'Zend_Uri_Http';
break;
case 'mailto':
// TODO
default:
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported");
break;
}
Zend_Loader::loadClass($className);
$schemeHandler = new $className($scheme, $schemeSpecific);
return $schemeHandler;
}
/**
* Get the URI's scheme
*
* @return string|false Scheme or false if no scheme is set.
*/
public function getScheme()
{
if (empty($this->_scheme) === false) {
return $this->_scheme;
} else {
return false;
}
}
/**
* Set global configuration options
*
* @param array $config
*/
static public function setConfig(array $config)
{
foreach ($config as $k => $v) {
self::$_config[$k] = $v;
}
}
/**
* Zend_Uri and its subclasses cannot be instantiated directly.
* Use Zend_Uri::factory() to return a new Zend_Uri object.
*
* @param string $scheme The scheme of the URI
* @param string $schemeSpecific The scheme-specific part of the URI
*/
abstract protected function __construct($scheme, $schemeSpecific = '');
/**
* Return a string representation of this URI.
*
* @return string
*/
abstract public function getUri();
/**
* Returns TRUE if this URI is valid, or FALSE otherwise.
*
* @return boolean
*/
abstract public function valid();
}
Validate/NotEmpty.php 0000604 00000003564 15071256135 0010576 0 ustar 00 <?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_Validate
* @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: NotEmpty.php 13249 2008-12-14 19:29:40Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_NotEmpty extends Zend_Validate_Abstract
{
const IS_EMPTY = 'isEmpty';
/**
* @var array
*/
protected $_messageTemplates = array(
self::IS_EMPTY => "Value is required and can't be empty"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is not an empty value.
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue((string) $value);
if (is_string($value)
&& (('' === $value)
|| preg_match('/^\s+$/s', $value))
) {
$this->_error();
return false;
} elseif (!is_string($value) && empty($value)) {
$this->_error();
return false;
}
return true;
}
}
Validate/Between.php 0000604 00000011144 15071256135 0010401 0 ustar 00 <?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_Validate
* @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: Between.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Between extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is not between the min and max, inclusively
*/
const NOT_BETWEEN = 'notBetween';
/**
* Validation failure message key for when the value is not strictly between the min and max
*/
const NOT_BETWEEN_STRICT = 'notBetweenStrict';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_BETWEEN => "'%value%' is not between '%min%' and '%max%', inclusively",
self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'"
);
/**
* Additional variables available for validation failure messages
*
* @var array
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max'
);
/**
* Minimum value
*
* @var mixed
*/
protected $_min;
/**
* Maximum value
*
* @var mixed
*/
protected $_max;
/**
* Whether to do inclusive comparisons, allowing equivalence to min and/or max
*
* If false, then strict comparisons are done, and the value may equal neither
* the min nor max options
*
* @var boolean
*/
protected $_inclusive;
/**
* Sets validator options
*
* @param mixed $min
* @param mixed $max
* @param boolean $inclusive
* @return void
*/
public function __construct($min, $max, $inclusive = true)
{
$this->setMin($min)
->setMax($max)
->setInclusive($inclusive);
}
/**
* Returns the min option
*
* @return mixed
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param mixed $min
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setMin($min)
{
$this->_min = $min;
return $this;
}
/**
* Returns the max option
*
* @return mixed
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param mixed $max
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setMax($max)
{
$this->_max = $max;
return $this;
}
/**
* Returns the inclusive option
*
* @return boolean
*/
public function getInclusive()
{
return $this->_inclusive;
}
/**
* Sets the inclusive option
*
* @param boolean $inclusive
* @return Zend_Validate_Between Provides a fluent interface
*/
public function setInclusive($inclusive)
{
$this->_inclusive = $inclusive;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is between min and max options, inclusively
* if inclusive option is true.
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_inclusive) {
if ($this->_min > $value || $value > $this->_max) {
$this->_error(self::NOT_BETWEEN);
return false;
}
} else {
if ($this->_min >= $value || $value >= $this->_max) {
$this->_error(self::NOT_BETWEEN_STRICT);
return false;
}
}
return true;
}
}
Validate/Regex.php 0000604 00000005760 15071256135 0010071 0 ustar 00 <?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_Validate
* @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: Regex.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Regex extends Zend_Validate_Abstract
{
const NOT_MATCH = 'regexNotMatch';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'pattern' => '_pattern'
);
/**
* Regular expression pattern
*
* @var string
*/
protected $_pattern;
/**
* Sets validator options
*
* @param string $pattern
* @return void
*/
public function __construct($pattern)
{
$this->setPattern($pattern);
}
/**
* Returns the pattern option
*
* @return string
*/
public function getPattern()
{
return $this->_pattern;
}
/**
* Sets the pattern option
*
* @param string $pattern
* @return Zend_Validate_Regex Provides a fluent interface
*/
public function setPattern($pattern)
{
$this->_pattern = (string) $pattern;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value matches against the pattern option
*
* @param string $value
* @throws Zend_Validate_Exception if there is a fatal error in pattern matching
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$status = @preg_match($this->_pattern, $valueString);
if (false === $status) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$valueString'");
}
if (!$status) {
$this->_error();
return false;
}
return true;
}
}
Validate/Alnum.php 0000604 00000006136 15071256135 0010071 0 ustar 00 <?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_Validate
* @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: Alnum.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Alnum extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-alphabetic or non-digit characters
*/
const NOT_ALNUM = 'notAlnum';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Whether to allow white space characters; off by default
*
* @var boolean
*/
public $allowWhiteSpace;
/**
* Alphanumeric filter used for validation
*
* @var Zend_Filter_Alnum
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_ALNUM => "'%value%' has not only alphabetic and digit characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only alphabetic and digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Alnum
*/
require_once 'Zend/Filter/Alnum.php';
self::$_filter = new Zend_Filter_Alnum();
}
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_ALNUM);
return false;
}
return true;
}
}
Validate/Date.php 0000604 00000016152 15071256135 0007671 0 ustar 00 <?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_Validate
* @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: Date.php 12062 2008-10-21 17:28:12Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Date extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value does not follow the YYYY-MM-DD format
*/
const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
/**
* Validation failure message key for when the value does not appear to be a valid date
*/
const INVALID = 'dateInvalid';
/**
* Validation failure message key for when the value does not fit the given dateformat or locale
*/
const FALSEFORMAT = 'dateFalseFormat';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD",
self::INVALID => "'%value%' does not appear to be a valid date",
self::FALSEFORMAT => "'%value%' does not fit given date format"
);
/**
* Optional format
*
* @var string|null
*/
protected $_format;
/**
* Optional locale
*
* @var string|Zend_Locale|null
*/
protected $_locale;
/**
* Sets validator options
*
* @param string $format OPTIONAL
* @param string|Zend_Locale $locale OPTIONAL
* @return void
*/
public function __construct($format = null, $locale = null)
{
$this->setFormat($format);
$this->setLocale($locale);
}
/**
* Returns the locale option
*
* @return string|Zend_Locale|null
*/
public function getLocale()
{
return $this->_locale;
}
/**
* Sets the locale option
*
* @param string|Zend_Locale $locale
* @return Zend_Validate_Date provides a fluent interface
*/
public function setLocale($locale = null)
{
if ($locale === null) {
$this->_locale = null;
return $this;
}
require_once 'Zend/Locale.php';
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The locale '$locale' is no known locale");
}
$locale = new Zend_Locale($locale);
}
$this->_locale = (string) $locale;
return $this;
}
/**
* Returns the locale option
*
* @return string|null
*/
public function getFormat()
{
return $this->_format;
}
/**
* Sets the format option
*
* @param string $format
* @return Zend_Validate_Date provides a fluent interface
*/
public function setFormat($format = null)
{
$this->_format = $format;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if $value is a valid date of the format YYYY-MM-DD
* If optional $format or $locale is set the date format is checked
* according to Zend_Date, see Zend_Date::isDate()
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (($this->_format !== null) or ($this->_locale !== null)) {
require_once 'Zend/Date.php';
if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
if ($this->_checkFormat($value) === false) {
$this->_error(self::FALSEFORMAT);
} else {
$this->_error(self::INVALID);
}
return false;
}
} else {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $valueString)) {
$this->_error(self::NOT_YYYY_MM_DD);
return false;
}
list($year, $month, $day) = sscanf($valueString, '%d-%d-%d');
if (!checkdate($month, $day, $year)) {
$this->_error(self::INVALID);
return false;
}
}
return true;
}
/**
* Check if the given date fits the given format
*
* @param string $value Date to check
* @return boolean False when date does not fit the format
*/
private function _checkFormat($value)
{
try {
require_once 'Zend/Locale/Format.php';
$parsed = Zend_Locale_Format::getDate($value, array(
'date_format' => $this->_format, 'format_type' => 'iso',
'fix_date' => false));
if (isset($parsed['year']) and ((strpos(strtoupper($this->_format), 'YY') !== false) and
(strpos(strtoupper($this->_format), 'YYYY') === false))) {
$parsed['year'] = Zend_Date::getFullYear($parsed['year']);
}
} catch (Exception $e) {
// Date can not be parsed
return false;
}
if (((strpos($this->_format, 'Y') !== false) or (strpos($this->_format, 'y') !== false)) and
(!isset($parsed['year']))) {
// Year expected but not found
return false;
}
if ((strpos($this->_format, 'M') !== false) and (!isset($parsed['month']))) {
// Month expected but not found
return false;
}
if ((strpos($this->_format, 'd') !== false) and (!isset($parsed['day']))) {
// Day expected but not found
return false;
}
if (((strpos($this->_format, 'H') !== false) or (strpos($this->_format, 'h') !== false)) and
(!isset($parsed['hour']))) {
// Hour expected but not found
return false;
}
if ((strpos($this->_format, 'm') !== false) and (!isset($parsed['minute']))) {
// Minute expected but not found
return false;
}
if ((strpos($this->_format, 's') !== false) and (!isset($parsed['second']))) {
// Second expected but not found
return false;
}
// Date fits the format
return true;
}
}
Validate/LessThan.php 0000604 00000004627 15071256135 0010541 0 ustar 00 <?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_Validate
* @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: LessThan.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_LessThan extends Zend_Validate_Abstract
{
const NOT_LESS = 'notLessThan';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_LESS => "'%value%' is not less than '%max%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'max' => '_max'
);
/**
* Maximum value
*
* @var mixed
*/
protected $_max;
/**
* Sets validator options
*
* @param mixed $max
* @return void
*/
public function __construct($max)
{
$this->setMax($max);
}
/**
* Returns the max option
*
* @return mixed
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param mixed $max
* @return Zend_Validate_LessThan Provides a fluent interface
*/
public function setMax($max)
{
$this->_max = $max;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is less than max option
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_max <= $value) {
$this->_error();
return false;
}
return true;
}
}
Validate/Interface.php 0000604 00000004521 15071256135 0010711 0 ustar 00 <?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_Validate
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Validate_Interface
{
/**
* Returns true if and only if $value meets the validation requirements
*
* If $value fails validation, then this method returns false, and
* getMessages() will return an array of messages that explain why the
* validation failed.
*
* @param mixed $value
* @return boolean
* @throws Zend_Valid_Exception If validation of $value is impossible
*/
public function isValid($value);
/**
* Returns an array of messages that explain why the most recent isValid()
* call returned false. The array keys are validation failure message identifiers,
* and the array values are the corresponding human-readable message strings.
*
* If isValid() was never called or if the most recent isValid() call
* returned true, then this method returns an empty array.
*
* @return array
*/
public function getMessages();
/**
* Returns an array of message codes that explain why a previous isValid() call
* returned false.
*
* If isValid() was never called or if the most recent isValid() call
* returned true, then this method returns an empty array.
*
* This is now the same as calling array_keys() on the return value from getMessages().
*
* @return array
* @deprecated Since 1.5.0
*/
public function getErrors();
}
Validate/Alpha.php 0000604 00000006073 15071256135 0010042 0 ustar 00 <?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_Validate
* @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: Alpha.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Alpha extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-alphabetic characters
*/
const NOT_ALPHA = 'notAlpha';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Whether to allow white space characters; off by default
*
* @var boolean
*/
public $allowWhiteSpace;
/**
* Alphabetic filter used for validation
*
* @var Zend_Filter_Alpha
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_ALPHA => "'%value%' has not only alphabetic characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Sets default option values for this instance
*
* @param boolean $allowWhiteSpace
* @return void
*/
public function __construct($allowWhiteSpace = false)
{
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only alphabetic characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Alpha
*/
require_once 'Zend/Filter/Alpha.php';
self::$_filter = new Zend_Filter_Alpha();
}
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_ALPHA);
return false;
}
return true;
}
}
Validate/Float.php 0000604 00000003676 15071256135 0010070 0 ustar 00 <?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_Validate
* @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: Float.php 8714 2008-03-09 20:03:45Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Float extends Zend_Validate_Abstract
{
const NOT_FLOAT = 'notFloat';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_FLOAT => "'%value%' does not appear to be a float"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a floating-point value
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
$locale = localeconv();
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
if (strval(floatval($valueFiltered)) != $valueFiltered) {
$this->_error();
return false;
}
return true;
}
}
Validate/Exception.php 0000604 00000002113 15071256135 0010742 0 ustar 00 <?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_Validate
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Exception extends Zend_Exception
{}
Validate/StringLength.php 0000604 00000013157 15071256135 0011426 0 ustar 00 <?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_Validate
* @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: StringLength.php 13278 2008-12-15 19:55:17Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_StringLength extends Zend_Validate_Abstract
{
const TOO_SHORT = 'stringLengthTooShort';
const TOO_LONG = 'stringLengthTooLong';
/**
* @var array
*/
protected $_messageTemplates = array(
self::TOO_SHORT => "'%value%' is less than %min% characters long",
self::TOO_LONG => "'%value%' is greater than %max% characters long"
);
/**
* @var array
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max'
);
/**
* Minimum length
*
* @var integer
*/
protected $_min;
/**
* Maximum length
*
* If null, there is no maximum length
*
* @var integer|null
*/
protected $_max;
/**
* Encoding to use
*
* @var string|null
*/
protected $_encoding;
/**
* Sets validator options
*
* @param integer $min
* @param integer $max
* @return void
*/
public function __construct($min = 0, $max = null, $encoding = null)
{
$this->setMin($min);
$this->setMax($max);
$this->setEncoding($encoding);
}
/**
* Returns the min option
*
* @return integer
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param integer $min
* @throws Zend_Validate_Exception
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setMin($min)
{
if (null !== $this->_max && $min > $this->_max) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >"
. " $this->_max");
}
$this->_min = max(0, (integer) $min);
return $this;
}
/**
* Returns the max option
*
* @return integer|null
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the max option
*
* @param integer|null $max
* @throws Zend_Validate_Exception
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setMax($max)
{
if (null === $max) {
$this->_max = null;
} else if ($max < $this->_min) {
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum length, but "
. "$max < $this->_min");
} else {
$this->_max = (integer) $max;
}
return $this;
}
/**
* Returns the actual encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Sets a new encoding to use
*
* @param string $encoding
* @return Zend_Validate_StringLength
*/
public function setEncoding($encoding = null)
{
if ($encoding !== null) {
$orig = iconv_get_encoding('internal_encoding');
$result = iconv_set_encoding('internal_encoding', $encoding);
if (!$result) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
}
iconv_set_encoding('internal_encoding', $orig);
}
$this->_encoding = $encoding;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the string length of $value is at least the min option and
* no greater than the max option (when the max option is not null).
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ($this->_encoding !== null) {
$length = iconv_strlen($valueString, $this->_encoding);
} else {
$length = iconv_strlen($valueString);
}
if ($length < $this->_min) {
$this->_error(self::TOO_SHORT);
}
if (null !== $this->_max && $this->_max < $length) {
$this->_error(self::TOO_LONG);
}
if (count($this->_messages)) {
return false;
} else {
return true;
}
}
}
Validate/InArray.php 0000604 00000006167 15071256135 0010366 0 ustar 00 <?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_Validate
* @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: InArray.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_InArray extends Zend_Validate_Abstract
{
const NOT_IN_ARRAY = 'notInArray';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_IN_ARRAY => "'%value%' was not found in the haystack"
);
/**
* Haystack of possible values
*
* @var array
*/
protected $_haystack;
/**
* Whether a strict in_array() invocation is used
*
* @var boolean
*/
protected $_strict;
/**
* Sets validator options
*
* @param array $haystack
* @param boolean $strict
* @return void
*/
public function __construct(array $haystack, $strict = false)
{
$this->setHaystack($haystack)
->setStrict($strict);
}
/**
* Returns the haystack option
*
* @return mixed
*/
public function getHaystack()
{
return $this->_haystack;
}
/**
* Sets the haystack option
*
* @param mixed $haystack
* @return Zend_Validate_InArray Provides a fluent interface
*/
public function setHaystack(array $haystack)
{
$this->_haystack = $haystack;
return $this;
}
/**
* Returns the strict option
*
* @return boolean
*/
public function getStrict()
{
return $this->_strict;
}
/**
* Sets the strict option
*
* @param boolean $strict
* @return Zend_Validate_InArray Provides a fluent interface
*/
public function setStrict($strict)
{
$this->_strict = $strict;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is contained in the haystack option. If the strict
* option is true, then the type of $value is also checked.
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if (!in_array($value, $this->_haystack, $this->_strict)) {
$this->_error();
return false;
}
return true;
}
}
Validate/Identical.php 0000604 00000005422 15071256135 0010706 0 ustar 00 <?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_Validate
* @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: Identical.php 8118 2008-02-18 16:10:32Z matthew $
*/
/** Zend_Validate_Abstract */
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Identical extends Zend_Validate_Abstract
{
/**#@+
* Error codes
* @const string
*/
const NOT_SAME = 'notSame';
const MISSING_TOKEN = 'missingToken';
/**#@-*/
/**
* Error messages
* @var array
*/
protected $_messageTemplates = array(
self::NOT_SAME => 'Tokens do not match',
self::MISSING_TOKEN => 'No token was provided to match against',
);
/**
* Original token against which to validate
* @var string
*/
protected $_token;
/**
* Sets validator options
*
* @param string $token
* @return void
*/
public function __construct($token = null)
{
if (null !== $token) {
$this->setToken($token);
}
}
/**
* Set token against which to compare
*
* @param string $token
* @return Zend_Validate_Identical
*/
public function setToken($token)
{
$this->_token = (string) $token;
return $this;
}
/**
* Retrieve token
*
* @return string
*/
public function getToken()
{
return $this->_token;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if a token has been set and the provided value
* matches that token.
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
$token = $this->getToken();
if (empty($token)) {
$this->_error(self::MISSING_TOKEN);
return false;
}
if ($value !== $token) {
$this->_error(self::NOT_SAME);
return false;
}
return true;
}
}
Validate/Hex.php 0000604 00000003651 15071256135 0007540 0 ustar 00 <?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_Validate
* @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: Hex.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hex extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains characters other than hexadecimal digits
*/
const NOT_HEX = 'notHex';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_HEX => "'%value%' has not only hexadecimal digit characters"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains only hexadecimal digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (!ctype_xdigit($valueString)) {
$this->_error();
return false;
}
return true;
}
}
Validate/Digits.php 0000604 00000005140 15071256135 0010232 0 ustar 00 <?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_Validate
* @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: Digits.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Digits extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value contains non-digit characters
*/
const NOT_DIGITS = 'notDigits';
/**
* Validation failure message key for when the value is an empty string
*/
const STRING_EMPTY = 'stringEmpty';
/**
* Digits filter used for validation
*
* @var Zend_Filter_Digits
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::NOT_DIGITS => "'%value%' contains not only digit characters",
self::STRING_EMPTY => "'%value%' is an empty string"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value only contains digit characters
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ('' === $valueString) {
$this->_error(self::STRING_EMPTY);
return false;
}
if (null === self::$_filter) {
/**
* @see Zend_Filter_Digits
*/
require_once 'Zend/Filter/Digits.php';
self::$_filter = new Zend_Filter_Digits();
}
if ($valueString !== self::$_filter->filter($valueString)) {
$this->_error(self::NOT_DIGITS);
return false;
}
return true;
}
}
Validate/GreaterThan.php 0000604 00000004660 15071256135 0011221 0 ustar 00 <?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_Validate
* @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: GreaterThan.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_GreaterThan extends Zend_Validate_Abstract
{
const NOT_GREATER = 'notGreaterThan';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_GREATER => "'%value%' is not greater than '%min%'"
);
/**
* @var array
*/
protected $_messageVariables = array(
'min' => '_min'
);
/**
* Minimum value
*
* @var mixed
*/
protected $_min;
/**
* Sets validator options
*
* @param mixed $min
* @return void
*/
public function __construct($min)
{
$this->setMin($min);
}
/**
* Returns the min option
*
* @return mixed
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the min option
*
* @param mixed $min
* @return Zend_Validate_GreaterThan Provides a fluent interface
*/
public function setMin($min)
{
$this->_min = $min;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is greater than min option
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if ($this->_min >= $value) {
$this->_error();
return false;
}
return true;
}
}
Validate/Int.php 0000604 00000004020 15071256135 0007535 0 ustar 00 <?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_Validate
* @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: Int.php 12336 2008-11-06 19:11:46Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Int extends Zend_Validate_Abstract
{
const NOT_INT = 'notInt';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_INT => "'%value%' does not appear to be an integer"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid integer
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (is_bool($value)) {
$this->_error();
return false;
}
$locale = localeconv();
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueString);
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
if (strval(intval($valueFiltered)) != $valueFiltered) {
$this->_error();
return false;
}
return true;
}
}
Validate/Abstract.php 0000604 00000024020 15071256135 0010550 0 ustar 00 <?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_Validate
* @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: Abstract.php 13351 2008-12-18 15:26:14Z alexander $
*/
/**
* @see Zend_Validate_Interface
*/
require_once 'Zend/Validate/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Validate_Abstract implements Zend_Validate_Interface
{
/**
* The value to be validated
*
* @var mixed
*/
protected $_value;
/**
* Additional variables available for validation failure messages
*
* @var array
*/
protected $_messageVariables = array();
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array();
/**
* Array of validation failure messages
*
* @var array
*/
protected $_messages = array();
/**
* Flag indidcating whether or not value should be obfuscated in error
* messages
* @var bool
*/
protected $_obscureValue = false;
/**
* Array of validation failure message codes
*
* @var array
* @deprecated Since 1.5.0
*/
protected $_errors = array();
/**
* Translation object
* @var Zend_Translate
*/
protected $_translator;
/**
* Default translation object for all validate objects
* @var Zend_Translate
*/
protected static $_defaultTranslator;
/**
* Returns array of validation failure messages
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
/**
* Returns an array of the names of variables that are used in constructing validation failure messages
*
* @return array
*/
public function getMessageVariables()
{
return array_keys($this->_messageVariables);
}
/**
* Sets the validation failure message template for a particular key
*
* @param string $messageString
* @param string $messageKey OPTIONAL
* @return Zend_Validate_Abstract Provides a fluent interface
* @throws Zend_Validate_Exception
*/
public function setMessage($messageString, $messageKey = null)
{
if ($messageKey === null) {
$keys = array_keys($this->_messageTemplates);
$messageKey = current($keys);
}
if (!isset($this->_messageTemplates[$messageKey])) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
}
$this->_messageTemplates[$messageKey] = $messageString;
return $this;
}
/**
* Sets validation failure message templates given as an array, where the array keys are the message keys,
* and the array values are the message template strings.
*
* @param array $messages
* @return Zend_Validate_Abstract
*/
public function setMessages(array $messages)
{
foreach ($messages as $key => $message) {
$this->setMessage($message, $key);
}
return $this;
}
/**
* Magic function returns the value of the requested property, if and only if it is the value or a
* message variable.
*
* @param string $property
* @return mixed
* @throws Zend_Validate_Exception
*/
public function __get($property)
{
if ($property == 'value') {
return $this->_value;
}
if (array_key_exists($property, $this->_messageVariables)) {
return $this->{$this->_messageVariables[$property]};
}
/**
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("No property exists by the name '$property'");
}
/**
* Constructs and returns a validation failure message with the given message key and value.
*
* Returns null if and only if $messageKey does not correspond to an existing template.
*
* If a translator is available and a translation exists for $messageKey,
* the translation will be used.
*
* @param string $messageKey
* @param string $value
* @return string
*/
protected function _createMessage($messageKey, $value)
{
if (!isset($this->_messageTemplates[$messageKey])) {
return null;
}
$message = $this->_messageTemplates[$messageKey];
if (null !== ($translator = $this->getTranslator())) {
if ($translator->isTranslated($message)) {
$message = $translator->translate($message);
} elseif ($translator->isTranslated($messageKey)) {
$message = $translator->translate($messageKey);
}
}
if (is_object($value)) {
if (!in_array('__toString', get_class_methods($value))) {
$value = get_class($value) . ' object';
} else {
$value = $value->__toString();
}
} else {
$value = (string)$value;
}
if ($this->getObscureValue()) {
$value = str_repeat('*', strlen($value));
}
$message = str_replace('%value%', (string) $value, $message);
foreach ($this->_messageVariables as $ident => $property) {
$message = str_replace("%$ident%", (string) $this->$property, $message);
}
return $message;
}
/**
* @param string $messageKey OPTIONAL
* @param string $value OPTIONAL
* @return void
*/
protected function _error($messageKey = null, $value = null)
{
if ($messageKey === null) {
$keys = array_keys($this->_messageTemplates);
$messageKey = current($keys);
}
if ($value === null) {
$value = $this->_value;
}
$this->_errors[] = $messageKey;
$this->_messages[$messageKey] = $this->_createMessage($messageKey, $value);
}
/**
* Sets the value to be validated and clears the messages and errors arrays
*
* @param mixed $value
* @return void
*/
protected function _setValue($value)
{
$this->_value = $value;
$this->_messages = array();
$this->_errors = array();
}
/**
* Returns array of validation failure message codes
*
* @return array
* @deprecated Since 1.5.0
*/
public function getErrors()
{
return $this->_errors;
}
/**
* Set flag indicating whether or not value should be obfuscated in messages
*
* @param bool $flag
* @return Zend_Validate_Abstract
*/
public function setObscureValue($flag)
{
$this->_obscureValue = (bool) $flag;
return $this;
}
/**
* Retrieve flag indicating whether or not value should be obfuscated in
* messages
*
* @return bool
*/
public function getObscureValue()
{
return $this->_obscureValue;
}
/**
* Set translation object
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return Zend_Validate_Abstract
*/
public function setTranslator($translator = null)
{
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid translator specified');
}
return $this;
}
/**
* Return translation object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if (null === $this->_translator) {
return self::getDefaultTranslator();
}
return $this->_translator;
}
/**
* Set default translation object for all validate objects
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return void
*/
public static function setDefaultTranslator($translator = null)
{
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
self::$_defaultTranslator = $translator;
} elseif ($translator instanceof Zend_Translate) {
self::$_defaultTranslator = $translator->getAdapter();
} else {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid translator specified');
}
}
/**
* Get default translation object for all validate objects
*
* @return Zend_Translate_Adapter|null
*/
public static function getDefaultTranslator()
{
if (null === self::$_defaultTranslator) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Translate')) {
$translator = Zend_Registry::get('Zend_Translate');
if ($translator instanceof Zend_Translate_Adapter) {
return $translator;
} elseif ($translator instanceof Zend_Translate) {
return $translator->getAdapter();
}
}
}
return self::$_defaultTranslator;
}
}
Validate/Ip.php 0000604 00000004026 15071256135 0007361 0 ustar 00 <?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_Validate
* @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: Ip.php 13289 2008-12-15 23:18:58Z tjohns $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Ip extends Zend_Validate_Abstract
{
const NOT_IP_ADDRESS = 'notIpAddress';
/**
* @var array
*/
protected $_messageTemplates = array(
self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid IP address
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if ((ip2long($valueString) === false) || (long2ip(ip2long($valueString)) !== $valueString)) {
if (!function_exists('inet_pton')) {
$this->_error();
return false;
} else if ((@inet_pton($value) === false) ||(inet_ntop(@inet_pton($value)) !== $valueString)) {
$this->_error();
return false;
}
}
return true;
}
}
Validate/File/Size.php 0000604 00000025727 15071256135 0010615 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the maximum size of a file up to a max of 2GB
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Size extends Zend_Validate_Abstract
{
/**#@+
* @const string Error constants
*/
const TOO_BIG = 'fileSizeTooBig';
const TOO_SMALL = 'fileSizeTooSmall';
const NOT_FOUND = 'fileSizeNotFound';
/**#@-*/
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::TOO_BIG => "Maximum allowed size for file '%value%' is '%max%' but '%size%' detected",
self::TOO_SMALL => "Minimum expected size for file '%value%' is '%min%' but '%size%' detected",
self::NOT_FOUND => "The file '%value%' could not be found"
);
/**
* @var array Error message template variables
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max',
'size' => '_size',
);
/**
* Minimum filesize
* @var integer
*/
protected $_min;
/**
* Maximum filesize
*
* If null, there is no maximum filesize
*
* @var integer|null
*/
protected $_max;
/**
* Detected size
*
* @var integer
*/
protected $_size;
/**
* Use bytestring ?
*
* @var boolean
*/
protected $_useByteString = true;
/**
* Sets validator options
*
* If $options is a integer, it will be used as maximum filesize
* As Array is accepts the following keys:
* 'min': Minimum filesize
* 'max': Maximum filesize
* 'bytestring': Use bytestring or real size for messages
*
* @param integer|array $options Options for the adapter
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_string($options) || is_numeric($options)) {
$options = array('max' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
if (1 < func_num_args()) {
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
$argv = func_get_args();
array_shift($argv);
$options['max'] = array_shift($argv);
if (!empty($argv)) {
$options['bytestring'] = array_shift($argv);
}
}
if (isset($options['bytestring'])) {
$this->setUseByteString($options['bytestring']);
}
if (isset($options['min'])) {
$this->setMin($options['min']);
}
if (isset($options['max'])) {
$this->setMax($options['max']);
}
}
/**
* Returns the minimum filesize
*
* @param boolean $byteString Use bytestring ?
* @return integer
*/
public function setUseByteString($byteString = true)
{
$this->_useByteString = (bool) $byteString;
return $this;
}
/**
* Will bytestring be used?
*
* @return boolean
*/
public function useByteString()
{
return $this->_useByteString;
}
/**
* Returns the minimum filesize
*
* @param bool $raw Whether or not to force return of the raw value (defaults off)
* @return integer|string
*/
public function getMin($raw = false)
{
$min = $this->_min;
if (!$raw && $this->useByteString()) {
$min = $this->_toByteString($min);
}
return $min;
}
/**
* Sets the minimum filesize
*
* @param integer $min The minimum filesize
* @throws Zend_Validate_Exception When min is greater than max
* @return Zend_Validate_File_Size Provides a fluent interface
*/
public function setMin($min)
{
if (!is_string($min) and !is_numeric($min)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
$min = (integer) $this->_fromByteString($min);
$max = $this->getMax(true);
if (($max !== null) && ($min > $max)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum filesize, but $min >"
. " $max");
}
$this->_min = $min;
return $this;
}
/**
* Returns the maximum filesize
*
* @param bool $raw Whether or not to force return of the raw value (defaults off)
* @return integer|string
*/
public function getMax($raw = false)
{
$max = $this->_max;
if (!$raw && $this->useByteString()) {
$max = $this->_toByteString($max);
}
return $max;
}
/**
* Sets the maximum filesize
*
* @param integer $max The maximum filesize
* @throws Zend_Validate_Exception When max is smaller than min
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setMax($max)
{
if (!is_string($max) && !is_numeric($max)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
$max = (integer) $this->_fromByteString($max);
$min = $this->getMin(true);
if (($min !== null) && ($max < $min)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum filesize, but "
. "$max < $min");
}
$this->_max = $max;
return $this;
}
/**
* Retrieve current detected file size
*
* @return int
*/
protected function _getSize()
{
return $this->_size;
}
/**
* Set current size
*
* @param int $size
* @return Zend_Validate_File_Size
*/
protected function _setSize($size)
{
$this->_size = $size;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the filesize of $value is at least min and
* not bigger than max (when max is not null).
*
* @param string $value Real file to check for size
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
// limited to 4GB files
$size = sprintf("%u", @filesize($value));
// Check to see if it's smaller than min size
$min = $this->getMin(true);
$max = $this->getMax(true);
if (($min !== null) && ($size < $min)) {
if ($this->useByteString()) {
$this->_min = $this->_toByteString($min);
$this->_size = $this->_toByteString($size);
$this->_throw($file, self::TOO_SMALL);
$this->_min = $min;
$this->_size = $size;
} else {
$this->_throw($file, self::TOO_SMALL);
}
}
// Check to see if it's larger than max size
if (($max !== null) && ($max < $size)) {
if ($this->useByteString()) {
$this->_max = $this->_toByteString($max);
$this->_size = $this->_toByteString($size);
$this->_throw($file, self::TOO_BIG);
$this->_max = $max;
$this->_size = $size;
} else {
$this->_throw($file, self::TOO_BIG);
}
}
if (count($this->_messages) > 0) {
return false;
}
return true;
}
/**
* Returns the formatted size
*
* @param integer $size
* @return string
*/
protected function _toByteString($size)
{
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
for ($i=0; $size >= 1024 && $i < 9; $i++) {
$size /= 1024;
}
return round($size, 2) . $sizes[$i];
}
/**
* Returns the unformatted size
*
* @param string $size
* @return integer
*/
protected function _fromByteString($size)
{
if (is_numeric($size)) {
return (integer) $size;
}
$type = trim(substr($size, -2, 1));
$value = substr($size, 0, -1);
if (!is_numeric($value)) {
$value = substr($value, 0, -1);
}
switch (strtoupper($type)) {
case 'Y':
$value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024);
break;
case 'Z':
$value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024);
break;
case 'E':
$value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024);
break;
case 'P':
$value *= (1024 * 1024 * 1024 * 1024 * 1024);
break;
case 'T':
$value *= (1024 * 1024 * 1024 * 1024);
break;
case 'G':
$value *= (1024 * 1024 * 1024);
break;
case 'M':
$value *= (1024 * 1024);
break;
case 'K':
$value *= 1024;
break;
default:
break;
}
return $value;
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/MimeType.php 0000604 00000017274 15071256135 0011432 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the mime type of a file
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_MimeType extends Zend_Validate_Abstract
{
/**#@+
* @const Error type constants
*/
const FALSE_TYPE = 'fileMimeTypeFalse';
const NOT_DETECTED = 'fileMimeTypeNotDetected';
const NOT_READABLE = 'fileMimeTypeNotReadable';
/**#@-*/
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::FALSE_TYPE => "The file '%value%' has a false mimetype of '%type%'",
self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected",
self::NOT_READABLE => "The file '%value%' can not be read"
);
/**
* @var array
*/
protected $_messageVariables = array(
'type' => '_type'
);
/**
* @var string
*/
protected $_type;
/**
* Mimetypes
*
* If null, there is no mimetype
*
* @var string|null
*/
protected $_mimetype;
/**
* Magicfile to use
*
* @var string|null
*/
protected $_magicfile;
/**
* Sets validator options
*
* Mimetype to accept
*
* @param string|array $mimetype MimeType
* @return void
*/
public function __construct($mimetype)
{
if ($mimetype instanceof Zend_Config) {
$mimetype = $mimetype->toArray();
} elseif (is_string($mimetype)) {
$mimetype = explode(',', $mimetype);
} elseif (!is_array($mimetype)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Invalid options to validator provided");
}
if (isset($mimetype['magicfile'])) {
$this->setMagicFile($mimetype['magicfile']);
}
$this->setMimeType($mimetype);
}
/**
* Returna the actual set magicfile
*
* @return string
*/
public function getMagicFile()
{
return $this->_magicfile;
}
/**
* Sets the magicfile to use
* if null, the MAGIC constant from php is used
*
* @param string $file
* @return Zend_Validate_File_MimeType Provides fluid interface
*/
public function setMagicFile($file)
{
if (empty($file)) {
$this->_magicfile = null;
} else if (!is_readable($file)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('The given magicfile can not be read');
} else {
$this->_magicfile = (string) $file;
}
return $this;
}
/**
* Returns the set mimetypes
*
* @param boolean $asArray Returns the values as array, when false an concated string is returned
* @return string|array
*/
public function getMimeType($asArray = false)
{
$asArray = (bool) $asArray;
$mimetype = (string) $this->_mimetype;
if ($asArray) {
$mimetype = explode(',', $mimetype);
}
return $mimetype;
}
/**
* Sets the mimetypes
*
* @param string|array $mimetype The mimetypes to validate
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function setMimeType($mimetype)
{
$this->_mimetype = null;
$this->addMimeType($mimetype);
return $this;
}
/**
* Adds the mimetypes
*
* @param string|array $mimetype The mimetypes to add for validation
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function addMimeType($mimetype)
{
$mimetypes = $this->getMimeType(true);
if (is_string($mimetype)) {
$mimetype = explode(',', $mimetype);
} elseif (!is_array($mimetype)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Invalid options to validator provided");
}
if (isset($mimetype['magicfile'])) {
unset($mimetype['magicfile']);
}
foreach ($mimetype as $content) {
if (empty($content) || !is_string($content)) {
continue;
}
$mimetypes[] = trim($content);
}
$mimetypes = array_unique($mimetypes);
// Sanity check to ensure no empty values
foreach ($mimetypes as $key => $mt) {
if (empty($mt)) {
unset($mimetypes[$key]);
}
}
$this->_mimetype = implode(',', $mimetypes);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if the mimetype of the file matches the given ones. Also parts
* of mimetypes can be checked. If you give for example "image" all image
* mime types will be accepted like "image/gif", "image/jpeg" and so on.
*
* @param string $value Real file to check for mimetype
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
if ($file !== null) {
$mimefile = $this->getMagicFile();
if (class_exists('finfo', false) && ((!empty($mimefile)) or (defined('MAGIC')))) {
if (!empty($mimefile)) {
$mime = new finfo(FILEINFO_MIME, $mimefile);
} else {
$mime = new finfo(FILEINFO_MIME);
}
$this->_type = $mime->file($value);
unset($mime);
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
$this->_type = mime_content_type($value);
} else {
$this->_type = $file['type'];
}
}
if (empty($this->_type)) {
return $this->_throw($file, self::NOT_DETECTED);
}
$mimetype = $this->getMimeType(true);
if (in_array($this->_type, $mimetype)) {
return true;
}
$types = explode('/', $this->_type);
$types = array_merge($types, explode('-', $this->_type));
foreach($mimetype as $mime) {
if (in_array($mime, $types)) {
return true;
}
}
return $this->_throw($file, self::FALSE_TYPE);
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/ExcludeMimeType.php 0000604 00000006006 15071256135 0012733 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_MimeType
*/
require_once 'Zend/Validate/File/MimeType.php';
/**
* Validator for the mime type of a file
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType
{
const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
/**
* Defined by Zend_Validate_Interface
*
* Returns true if the mimetype of the file does not matche the given ones. Also parts
* of mimetypes can be checked. If you give for example "image" all image
* mime types will not be accepted like "image/gif", "image/jpeg" and so on.
*
* @param string $value Real file to check for mimetype
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
if ($file !== null) {
if (class_exists('finfo', false) && defined('MAGIC')) {
$mime = new finfo(FILEINFO_MIME);
$this->_type = $mime->file($value);
unset($mime);
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
$this->_type = mime_content_type($value);
} else {
$this->_type = $file['type'];
}
}
if (empty($this->_type)) {
return $this->_throw($file, self::NOT_DETECTED);
}
$mimetype = $this->getMimeType(true);
if (in_array($this->_type, $mimetype)) {
return $this->_throw($file, self::FALSE_TYPE);
}
$types = explode('/', $this->_type);
$types = array_merge($types, explode('-', $this->_type));
foreach($mimetype as $mime) {
if (in_array($mime, $types)) {
return $this->_throw($file, self::FALSE_TYPE);
}
}
return true;
}
}
Validate/File/ImageSize.php 0000604 00000026062 15071256135 0011551 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the image size of a image file
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_ImageSize extends Zend_Validate_Abstract
{
/**
* @const string Error constants
*/
const WIDTH_TOO_BIG = 'fileImageSizeWidthTooBig';
const WIDTH_TOO_SMALL = 'fileImageSizeWidthTooSmall';
const HEIGHT_TOO_BIG = 'fileImageSizeHeightTooBig';
const HEIGHT_TOO_SMALL = 'fileImageSizeHeightTooSmall';
const NOT_DETECTED = 'fileImageSizeNotDetected';
const NOT_READABLE = 'fileImageSizeNotReadable';
/**
* @var array Error message template
*/
protected $_messageTemplates = array(
self::WIDTH_TOO_BIG => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected",
self::WIDTH_TOO_SMALL => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected",
self::HEIGHT_TOO_BIG => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected",
self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected",
self::NOT_DETECTED => "The size of image '%value%' could not be detected",
self::NOT_READABLE => "The image '%value%' can not be read"
);
/**
* @var array Error message template variables
*/
protected $_messageVariables = array(
'minwidth' => '_minwidth',
'maxwidth' => '_maxwidth',
'minheight' => '_minheight',
'maxheight' => '_maxheight',
'width' => '_width',
'height' => '_height'
);
/**
* Minimum image width
*
* @var integer
*/
protected $_minwidth;
/**
* Maximum image width
*
* @var integer
*/
protected $_maxwidth;
/**
* Minimum image height
*
* @var integer
*/
protected $_minheight;
/**
* Maximum image height
*
* @var integer
*/
protected $_maxheight;
/**
* Detected width
*
* @var integer
*/
protected $_width;
/**
* Detected height
*
* @var integer
*/
protected $_height;
/**
* Sets validator options
*
* Accepts the following option keys:
* - minheight
* - minwidth
* - maxheight
* - maxwidth
*
* @param Zend_Config|array $options
* @return void
*/
public function __construct($options)
{
$minwidth = 0;
$minheight = 0;
$maxwidth = null;
$maxheight = null;
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (1 < func_num_args()) {
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
if (!is_array($options)) {
$options = array('minwidth' => $options);
}
$argv = func_get_args();
array_shift($argv);
$options['minheight'] = array_shift($argv);
if (!empty($argv)) {
$options['maxwidth'] = array_shift($argv);
if (!empty($argv)) {
$options['maxheight'] = array_shift($argv);
}
}
} else if (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
if (isset($options['minheight']) || isset($options['minwidth'])) {
$this->setImageMin($options);
}
if (isset($options['maxheight']) || isset($options['maxwidth'])) {
$this->setImageMax($options);
}
}
/**
* Returns the set minimum image sizes
*
* @return array
*/
public function getImageMin()
{
return array('minwidth' => $this->_minwidth, 'minheight' => $this->_minheight);
}
/**
* Returns the set maximum image sizes
*
* @return array
*/
public function getImageMax()
{
return array('maxwidth' => $this->_maxwidth, 'maxheight' => $this->_maxheight);
}
/**
* Returns the set image width sizes
*
* @return array
*/
public function getImageWidth()
{
return array('minwidth' => $this->_minwidth, 'maxwidth' => $this->_maxwidth);
}
/**
* Returns the set image height sizes
*
* @return array
*/
public function getImageHeight()
{
return array('minheight' => $this->_minheight, 'maxheight' => $this->_maxheight);
}
/**
* Sets the minimum image size
*
* @param array $options The minimum image dimensions
* @throws Zend_Validate_Exception When minwidth is greater than maxwidth
* @throws Zend_Validate_Exception When minheight is greater than maxheight
* @return Zend_Validate_File_ImageSize Provides a fluent interface
*/
public function setImageMin($options)
{
if (isset($options['minwidth'])) {
if (($this->_maxwidth !== null) and ($options['minwidth'] > $this->_maxwidth)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum image width must be less than or equal to the "
. " maximum image width, but {$options['minwidth']} > {$this->_maxwidth}");
}
}
if (isset($options['maxheight'])) {
if (($this->_maxheight !== null) and ($options['minheight'] > $this->_maxheight)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum image height must be less than or equal to the "
. " maximum image height, but {$options['minheight']} > {$this->_maxheight}");
}
}
if (isset($options['minwidth'])) {
$this->_minwidth = (int) $options['minwidth'];
}
if (isset($options['minheight'])) {
$this->_minheight = (int) $options['minheight'];
}
return $this;
}
/**
* Sets the maximum image size
*
* @param array $options The maximum image dimensions
* @throws Zend_Validate_Exception When maxwidth is smaller than minwidth
* @throws Zend_Validate_Exception When maxheight is smaller than minheight
* @return Zend_Validate_StringLength Provides a fluent interface
*/
public function setImageMax($options)
{
if (isset($options['maxwidth'])) {
if (($this->_minwidth !== null) and ($options['maxwidth'] < $this->_minwidth)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum image width must be greater than or equal to the "
. "minimum image width, but {$options['maxwidth']} < {$this->_minwidth}");
}
}
if (isset($options['maxheight'])) {
if (($this->_minheight !== null) and ($options['maxheight'] < $this->_minheight)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum image height must be greater than or equal to the "
. "minimum image height, but {$options['maxheight']} < {$this->_minwidth}");
}
}
if (isset($options['maxwidth'])) {
$this->_maxwidth = (int) $options['maxwidth'];
}
if (isset($options['maxheight'])) {
$this->_maxheight = (int) $options['maxheight'];
}
return $this;
}
/**
* Sets the mimimum and maximum image width
*
* @param array $options The image width dimensions
* @return Zend_Validate_File_ImageSize Provides a fluent interface
*/
public function setImageWidth($options)
{
$this->setImageMin($options);
$this->setImageMax($options);
return $this;
}
/**
* Sets the mimimum and maximum image height
*
* @param array $options The image height dimensions
* @return Zend_Validate_File_ImageSize Provides a fluent interface
*/
public function setImageHeight($options)
{
$this->setImageMin($options);
$this->setImageMax($options);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the imagesize of $value is at least min and
* not bigger than max
*
* @param string $value Real file to check for image size
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
$size = @getimagesize($value);
$this->_setValue($file);
if (empty($size) or ($size[0] === 0) or ($size[1] === 0)) {
return $this->_throw($file, self::NOT_DETECTED);
}
$this->_width = $size[0];
$this->_height = $size[1];
if ($this->_width < $this->_minwidth) {
$this->_throw($file, self::WIDTH_TOO_SMALL);
}
if (($this->_maxwidth !== null) and ($this->_maxwidth < $this->_width)) {
$this->_throw($file, self::WIDTH_TOO_BIG);
}
if ($this->_height < $this->_minheight) {
$this->_throw($file, self::HEIGHT_TOO_SMALL);
}
if (($this->_maxheight !== null) and ($this->_maxheight < $this->_height)) {
$this->_throw($file, self::HEIGHT_TOO_BIG);
}
if (count($this->_messages) > 0) {
return false;
}
return true;
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/Upload.php 0000604 00000016247 15071256135 0011124 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the maximum size of a file up to a max of 2GB
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Upload extends Zend_Validate_Abstract
{
/**@#+
* @const string Error constants
*/
const INI_SIZE = 'fileUploadErrorIniSize';
const FORM_SIZE = 'fileUploadErrorFormSize';
const PARTIAL = 'fileUploadErrorPartial';
const NO_FILE = 'fileUploadErrorNoFile';
const NO_TMP_DIR = 'fileUploadErrorNoTmpDir';
const CANT_WRITE = 'fileUploadErrorCantWrite';
const EXTENSION = 'fileUploadErrorExtension';
const ATTACK = 'fileUploadErrorAttack';
const FILE_NOT_FOUND = 'fileUploadErrorFileNotFound';
const UNKNOWN = 'fileUploadErrorUnknown';
/**@#-*/
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::INI_SIZE => "The file '%value%' exceeds the defined ini size",
self::FORM_SIZE => "The file '%value%' exceeds the defined form size",
self::PARTIAL => "The file '%value%' was only partially uploaded",
self::NO_FILE => "The file '%value%' was not uploaded",
self::NO_TMP_DIR => "No temporary directory was found for the file '%value%'",
self::CANT_WRITE => "The file '%value%' can't be written",
self::EXTENSION => "The extension returned an error while uploading the file '%value%'",
self::ATTACK => "The file '%value%' was illegal uploaded, possible attack",
self::FILE_NOT_FOUND => "The file '%value%' was not found",
self::UNKNOWN => "Unknown error while uploading the file '%value%'"
);
/**
* Internal array of files
* @var array
*/
protected $_files = array();
/**
* Sets validator options
*
* The array $files must be given in syntax of Zend_File_Transfer to be checked
* If no files are given the $_FILES array will be used automatically.
* NOTE: This validator will only work with HTTP POST uploads!
*
* @param array $files Array of files in syntax of Zend_File_Transfer
* @return void
*/
public function __construct($files = array())
{
$this->setFiles($files);
}
/**
* Returns the array of set files
*
* @param string $files (Optional) The file to return in detail
* @return array
* @throws Zend_Validate_Exception If file is not found
*/
public function getFiles($file = null)
{
if ($file !== null) {
$return = array();
foreach ($this->_files as $name => $content) {
if ($name === $file) {
$return[$file] = $this->_files[$name];
}
if ($content['name'] === $file) {
$return[$name] = $this->_files[$name];
}
}
if (count($return) === 0) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The file '$file' was not found");
}
return $return;
}
return $this->_files;
}
/**
* Sets the minimum filesize
*
* @param array $files The files to check in syntax of Zend_File_Transfer
* @return Zend_Validate_File_Upload Provides a fluent interface
*/
public function setFiles($files = array())
{
if (count($files) === 0) {
$this->_files = $_FILES;
} else {
$this->_files = $files;
}
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file was uploaded without errors
*
* @param string $value Single file to check for upload errors, when giving null the $_FILES array
* from initialization will be used
* @return boolean
*/
public function isValid($value, $file = null)
{
if (array_key_exists($value, $this->_files)) {
$files[$value] = $this->_files[$value];
} else {
foreach ($this->_files as $file => $content) {
if ($content['name'] === $value) {
$files[$file] = $this->_files[$file];
}
if ($content['tmp_name'] === $value) {
$files[$file] = $this->_files[$file];
}
}
}
if (empty($files)) {
return $this->_throw($file, self::FILE_NOT_FOUND);
}
foreach ($files as $file => $content) {
$this->_value = $file;
switch($content['error']) {
case 0:
if (!is_uploaded_file($content['tmp_name'])) {
$this->_throw($file, self::ATTACK);
}
break;
case 1:
$this->_throw($file, self::INI_SIZE);
break;
case 2:
$this->_throw($file, self::FORM_SIZE);
break;
case 3:
$this->_throw($file, self::PARTIAL);
break;
case 4:
$this->_throw($file, self::NO_FILE);
break;
case 6:
$this->_throw($file, self::NO_TMP_DIR);
break;
case 7:
$this->_throw($file, self::CANT_WRITE);
break;
case 8:
$this->_throw($file, self::EXTENSION);
break;
default:
$this->_throw($file, self::UNKNOWN);
break;
}
}
if (count($this->_messages) > 0) {
return false;
} else {
return true;
}
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
if (is_array($file) and !empty($file['name'])) {
$this->_value = $file['name'];
}
}
$this->_error($errorType);
return false;
}
}
Validate/File/ExcludeExtension.php 0000604 00000005502 15071256135 0013156 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/File/Extension.php';
/**
* Validator for the excluding file extensions
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension
{
/**
* @const string Error constants
*/
const FALSE_EXTENSION = 'fileExcludeExtensionFalse';
const NOT_FOUND = 'fileExcludeExtensionNotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::FALSE_EXTENSION => "The file '%value%' has a false extension",
self::NOT_FOUND => "The file '%value%' was not found"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the fileextension of $value is not included in the
* set extension list
*
* @param string $value Real file to check for extension
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
if ($file !== null) {
$info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
} else {
$info = pathinfo($value);
}
$extensions = $this->getExtension();
if ($this->_case and (!in_array($info['extension'], $extensions))) {
return true;
} else if (!$this->_case) {
$found = false;
foreach ($extensions as $extension) {
if (strtolower($extension) == strtolower($info['extension'])) {
$found = true;
}
}
if (!$found) {
return true;
}
}
return $this->_throw($file, self::FALSE_EXTENSION);
}
}
Validate/File/Exists.php 0000604 00000013131 15071256135 0011144 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator which checks if the file already exists in the directory
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Exists extends Zend_Validate_Abstract
{
/**
* @const string Error constants
*/
const DOES_NOT_EXIST = 'fileExistsDoesNotExist';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_NOT_EXIST => "The file '%value%' does not exist"
);
/**
* Internal list of directories
* @var string
*/
protected $_directory = '';
/**
* @var array Error message template variables
*/
protected $_messageVariables = array(
'directory' => '_directory'
);
/**
* Sets validator options
*
* @param string|array $directory
* @return void
*/
public function __construct($directory = array())
{
if ($directory instanceof Zend_Config) {
$directory = $directory->toArray();
} else if (is_string($directory)) {
$directory = explode(',', $directory);
} else if (!is_array($directory)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
$this->setDirectory($directory);
}
/**
* Returns the set file directories which are checked
*
* @param boolean $asArray Returns the values as array, when false an concated string is returned
* @return string
*/
public function getDirectory($asArray = false)
{
$asArray = (bool) $asArray;
$directory = (string) $this->_directory;
if ($asArray) {
$directory = explode(',', $directory);
}
return $directory;
}
/**
* Sets the file directory which will be checked
*
* @param string|array $directory The directories to validate
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function setDirectory($directory)
{
$this->_directory = null;
$this->addDirectory($directory);
return $this;
}
/**
* Adds the file directory which will be checked
*
* @param string|array $directory The directory to add for validation
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function addDirectory($directory)
{
$directories = $this->getDirectory(true);
if (is_string($directory)) {
$directory = explode(',', $directory);
} else if (!is_array($directory)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
foreach ($directory as $content) {
if (empty($content) || !is_string($content)) {
continue;
}
$directories[] = trim($content);
}
$directories = array_unique($directories);
// Sanity check to ensure no empty values
foreach ($directories as $key => $dir) {
if (empty($dir)) {
unset($directories[$key]);
}
}
$this->_directory = implode(',', $directories);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file already exists in the set directories
*
* @param string $value Real file to check for existance
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
$directories = $this->getDirectory(true);
if (($file !== null) and (!empty($file['destination']))) {
$directories[] = $file['destination'];
} else if (!isset($file['name'])) {
$file['name'] = $value;
}
$check = false;
foreach ($directories as $directory) {
if (empty($directory)) {
continue;
}
$check = true;
if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
return $this->_throw($file, self::DOES_NOT_EXIST);
}
}
if (!$check) {
return $this->_throw($file, self::DOES_NOT_EXIST);
}
return true;
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/Count.php 0000604 00000016505 15071256135 0010765 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for counting all given files
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Count extends Zend_Validate_Abstract
{
/**#@+
* @const string Error constants
*/
const TOO_MUCH = 'fileCountTooMuch';
const TOO_LESS = 'fileCountTooLess';
/**#@-*/
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::TOO_MUCH => "Too much files, maximum '%max%' are allowed but '%count%' are given",
self::TOO_LESS => "Too less files, minimum '%min%' are expected but '%count%' are given"
);
/**
* @var array Error message template variables
*/
protected $_messageVariables = array(
'min' => '_min',
'max' => '_max',
'count' => '_count'
);
/**
* Minimum file count
*
* If null, there is no minimum file count
*
* @var integer
*/
protected $_min;
/**
* Maximum file count
*
* If null, there is no maximum file count
*
* @var integer|null
*/
protected $_max;
/**
* Actual filecount
*
* @var integer
*/
protected $_count;
/**
* Internal file array
* @var array
*/
protected $_files;
/**
* Sets validator options
*
* Min limits the file count, when used with max=null it is the maximum file count
* It also accepts an array with the keys 'min' and 'max'
*
* If $options is a integer, it will be used as maximum file count
* As Array is accepts the following keys:
* 'min': Minimum filecount
* 'max': Maximum filecount
*
* @param integer|array $options Options for the adapter
* @param integer $max (Deprecated) Maximum value (implies $options is the minimum)
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_string($options) || is_numeric($options)) {
$options = array('max' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
if (1 < func_num_args()) {
trigger_error('Multiple arguments are deprecated in favor of an array of named arguments', E_USER_NOTICE);
$options['min'] = func_get_arg(0);
$options['max'] = func_get_arg(1);
}
if (isset($options['min'])) {
$this->setMin($options);
}
if (isset($options['max'])) {
$this->setMax($options);
}
}
/**
* Returns the minimum file count
*
* @return integer
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets the minimum file count
*
* @param integer|array $min The minimum file count
* @return Zend_Validate_File_Size Provides a fluent interface
* @throws Zend_Validate_Exception When min is greater than max
*/
public function setMin($min)
{
if (is_array($min) and isset($min['min'])) {
$min = $min['min'];
}
if (!is_string($min) and !is_numeric($min)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
$min = (integer) $min;
if (($this->_max !== null) && ($min > $this->_max)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum file count, but $min >"
. " {$this->_max}");
}
$this->_min = $min;
return $this;
}
/**
* Returns the maximum file count
*
* @return integer
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets the maximum file count
*
* @param integer|array $max The maximum file count
* @return Zend_Validate_StringLength Provides a fluent interface
* @throws Zend_Validate_Exception When max is smaller than min
*/
public function setMax($max)
{
if (is_array($max) and isset($max['max'])) {
$max = $max['max'];
}
if (!is_string($max) and !is_numeric($max)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception ('Invalid options to validator provided');
}
$max = (integer) $max;
if (($this->_min !== null) && ($max < $this->_min)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum file count, but "
. "$max < {$this->_min}");
}
$this->_max = $max;
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file count of all checked files is at least min and
* not bigger than max (when max is not null). Attention: When checking with set min you
* must give all files with the first call, otherwise you will get an false.
*
* @param string|array $value Filenames to check for count
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
if (is_string($value)) {
$value = array($value);
}
foreach ($value as $file) {
if (!isset($this->_files[$file])) {
$this->_files[$file] = $file;
}
}
$this->_count = count($this->_files);
if (($this->_max !== null) && ($this->_count > $this->_max)) {
return $this->_throw($file, self::TOO_MUCH);
}
if (($this->_min !== null) && ($this->_count < $this->_min)) {
return $this->_throw($file, self::TOO_LESS);
}
return true;
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/Md5.php 0000604 00000011662 15071256135 0010321 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_Hash
*/
require_once 'Zend/Validate/File/Hash.php';
/**
* Validator for the md5 hash of given files
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Md5 extends Zend_Validate_File_Hash
{
/**
* @const string Error constants
*/
const DOES_NOT_MATCH = 'fileMd5DoesNotMatch';
const NOT_DETECTED = 'fileMd5NotDetected';
const NOT_FOUND = 'fileMd5NotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_NOT_MATCH => "The file '%value%' does not match the given md5 hashes",
self::NOT_DETECTED => "There was no md5 hash detected for the given file",
self::NOT_FOUND => "The file '%value%' could not be found"
);
/**
* Hash of the file
*
* @var string
*/
protected $_hash;
/**
* Sets validator options
*
* $hash is the hash we accept for the file $file
*
* @param string|array $options
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_scalar($options)) {
$options = array('hash1' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid options to validator provided');
}
$this->setMd5($options);
}
/**
* Returns all set md5 hashes
*
* @return array
*/
public function getMd5()
{
return $this->getHash();
}
/**
* Sets the md5 hash for one or multiple files
*
* @param string|array $options
* @param string $algorithm (Deprecated) Algorithm to use, fixed to md5
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::setHash($options);
return $this;
}
/**
* Sets the md5 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setMd5($options)
{
$this->setHash($options);
return $this;
}
/**
* Adds the md5 hash for one or multiple files
*
* @param string|array $options
* @param string $algorithm (Depreciated) Algorithm to use, fixed to md5
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::addHash($options);
return $this;
}
/**
* Adds the md5 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addMd5($options)
{
$this->addHash($options);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the given file confirms the set hash
*
* @param string $value Filename to check for hash
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$hashes = array_unique(array_keys($this->_hash));
$filehash = hash_file('md5', $value);
if ($filehash === false) {
return $this->_throw($file, self::NOT_DETECTED);
}
foreach($hashes as $hash) {
if ($filehash === $hash) {
return true;
}
}
return $this->_throw($file, self::DOES_NOT_MATCH);
}
}
Validate/File/Sha1.php 0000604 00000011437 15071256135 0010470 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_Hash
*/
require_once 'Zend/Validate/File/Hash.php';
/**
* Validator for the sha1 hash of given files
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Sha1 extends Zend_Validate_File_Hash
{
/**
* @const string Error constants
*/
const DOES_NOT_MATCH = 'fileSha1DoesNotMatch';
const NOT_DETECTED = 'fileSha1NotDetected';
const NOT_FOUND = 'fileSha1NotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_NOT_MATCH => "The file '%value%' does not match the given sha1 hashes",
self::NOT_DETECTED => "There was no sha1 hash detected for the given file",
self::NOT_FOUND => "The file '%value%' could not be found"
);
/**
* Hash of the file
*
* @var string
*/
protected $_hash;
/**
* Sets validator options
*
* $hash is the hash we accept for the file $file
*
* @param string|array $options
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_scalar($options)) {
$options = array('hash1' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid options to validator provided');
}
$this->setHash($options);
}
/**
* Returns all set sha1 hashes
*
* @return array
*/
public function getSha1()
{
return $this->getHash();
}
/**
* Sets the sha1 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'sha1';
parent::setHash($options);
return $this;
}
/**
* Sets the sha1 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setSha1($options)
{
$this->setHash($options);
return $this;
}
/**
* Adds the sha1 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'sha1';
parent::addHash($options);
return $this;
}
/**
* Adds the sha1 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addSha1($options)
{
$this->addHash($options);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the given file confirms the set hash
*
* @param string $value Filename to check for hash
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$hashes = array_unique(array_keys($this->_hash));
$filehash = hash_file('sha1', $value);
if ($filehash === false) {
return $this->_throw($file, self::NOT_DETECTED);
}
foreach ($hashes as $hash) {
if ($filehash === $hash) {
return true;
}
}
return $this->_throw($file, self::DOES_NOT_MATCH);
}
}
Validate/File/FilesSize.php 0000604 00000012417 15071256135 0011570 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_Size
*/
require_once 'Zend/Validate/File/Size.php';
/**
* Validator for the size of all files which will be validated in sum
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_FilesSize extends Zend_Validate_File_Size
{
/**
* @const string Error constants
*/
const TOO_BIG = 'fileFilesSizeTooBig';
const TOO_SMALL = 'fileFilesSizeTooSmall';
const NOT_READABLE = 'fileFilesSizeNotReadable';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::TOO_BIG => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
self::TOO_SMALL => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
self::NOT_READABLE => "One or more files can not be read"
);
/**
* Internal file array
*
* @var array
*/
protected $_files;
/**
* Sets validator options
*
* Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
* It also accepts an array with the keys 'min' and 'max'
*
* @param integer|array $min Minimum diskspace for all files
* @param integer $max Maximum diskspace for all files (deprecated)
* @param boolean $bytestring Use bytestring or real size ? (deprecated)
* @return void
*/
public function __construct($options)
{
$this->_files = array();
$this->_setSize(0);
if (1 < func_num_args()) {
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_scalar($options)) {
$options = array('min' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid options to validator provided');
}
$argv = func_get_args();
array_shift($argv);
$options['max'] = array_shift($argv);
if (!empty($argv)) {
$options['bytestring'] = array_shift($argv);
}
}
parent::__construct($options);
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the disk usage of all files is at least min and
* not bigger than max (when max is not null).
*
* @param string|array $value Real file to check for size
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
require_once 'Zend/Loader.php';
if (is_string($value)) {
$value = array($value);
}
$min = $this->getMin(true);
$max = $this->getMax(true);
$size = $this->_getSize();
foreach ($value as $files) {
// Is file readable ?
if (!Zend_Loader::isReadable($files)) {
$this->_throw($file, self::NOT_READABLE);
continue;
}
if (!isset($this->_files[$files])) {
$this->_files[$files] = $files;
} else {
// file already counted... do not count twice
continue;
}
// limited to 2GB files
$size += @filesize($files);
$this->_setSize($size);
if (($max !== null) && ($max < $size)) {
if ($this->useByteString()) {
$this->setMax($this->_toByteString($max));
$this->_throw($file, self::TOO_BIG);
$this->setMax($max);
} else {
$this->_throw($file, self::TOO_BIG);
}
}
}
// Check that aggregate files are >= minimum size
if (($min !== null) && ($size < $min)) {
if ($this->useByteString()) {
$this->setMin($this->_toByteString($min));
$this->_throw($file, self::TOO_SMALL);
$this->setMin($min);
} else {
$this->_throw($file, self::TOO_SMALL);
}
}
if (count($this->_messages) > 0) {
return false;
}
return true;
}
}
Validate/File/Extension.php 0000604 00000013767 15071256135 0011660 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the file extension of a file
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Extension extends Zend_Validate_Abstract
{
/**
* @const string Error constants
*/
const FALSE_EXTENSION = 'fileExtensionFalse';
const NOT_FOUND = 'fileExtensionNotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::FALSE_EXTENSION => "The file '%value%' has a false extension",
self::NOT_FOUND => "The file '%value%' was not found"
);
/**
* Internal list of extensions
* @var string
*/
protected $_extension = '';
/**
* Validate case sensitive
*
* @var boolean
*/
protected $_case = false;
/**
* @var array Error message template variables
*/
protected $_messageVariables = array(
'extension' => '_extension'
);
/**
* Sets validator options
*
* @param string|array $extension
* @param boolean $case If true validation is done case sensitive
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (1 < func_num_args()) {
trigger_error('Multiple arguments to constructor are deprecated in favor of options array', E_USER_NOTICE);
$case = func_get_arg(1);
$this->setCase($case);
}
if (is_array($options) and isset($options['case'])) {
$this->setCase($options['case']);
unset($options['case']);
}
$this->setExtension($options);
}
/**
* Returns the case option
*
* @return boolean
*/
public function getCase()
{
return $this->_case;
}
/**
* Sets the case to use
*
* @param boolean $case
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function setCase($case)
{
$this->_case = (boolean) $case;
return $this;
}
/**
* Returns the set file extension
*
* @return array
*/
public function getExtension()
{
$extension = explode(',', $this->_extension);
return $extension;
}
/**
* Sets the file extensions
*
* @param string|array $extension The extensions to validate
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function setExtension($extension)
{
$this->_extension = null;
$this->addExtension($extension);
return $this;
}
/**
* Adds the file extensions
*
* @param string|array $extension The extensions to add for validation
* @return Zend_Validate_File_Extension Provides a fluent interface
*/
public function addExtension($extension)
{
$extensions = $this->getExtension();
if (is_string($extension)) {
$extension = explode(',', $extension);
}
foreach ($extension as $content) {
if (empty($content) || !is_string($content)) {
continue;
}
$extensions[] = trim($content);
}
$extensions = array_unique($extensions);
// Sanity check to ensure no empty values
foreach ($extensions as $key => $ext) {
if (empty($ext)) {
unset($extensions[$key]);
}
}
$this->_extension = implode(',', $extensions);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the fileextension of $value is included in the
* set extension list
*
* @param string $value Real file to check for extension
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
if ($file !== null) {
$info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
} else {
$info = pathinfo($value);
}
$extensions = $this->getExtension();
if ($this->_case && (in_array($info['extension'], $extensions))) {
return true;
} else if (!$this->getCase()) {
foreach ($extensions as $extension) {
if (strtolower($extension) == strtolower($info['extension'])) {
return true;
}
}
}
return $this->_throw($file, self::FALSE_EXTENSION);
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if (null !== $file) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/NotExists.php 0000604 00000004654 15071256135 0011637 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_Exists
*/
require_once 'Zend/Validate/File/Exists.php';
/**
* Validator which checks if the destination file does not exist
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_NotExists extends Zend_Validate_File_Exists
{
/**
* @const string Error constants
*/
const DOES_EXIST = 'fileNotExistsDoesExist';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_EXIST => "The file '%value%' does exist"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file does not exist in the set destinations
*
* @param string $value Real file to check for
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
$directories = $this->getDirectory(true);
if (($file !== null) and (!empty($file['destination']))) {
$directories[] = $file['destination'];
} else if (!isset($file['name'])) {
$file['name'] = $value;
}
foreach ($directories as $directory) {
if (empty($directory)) {
continue;
}
$check = true;
if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
return $this->_throw($file, self::DOES_EXIST);
}
}
if (!isset($check)) {
return $this->_throw($file, self::DOES_EXIST);
}
return true;
}
}
Validate/File/Hash.php 0000604 00000012627 15071256135 0010561 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* Validator for the hash of given files
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Hash extends Zend_Validate_Abstract
{
/**
* @const string Error constants
*/
const DOES_NOT_MATCH = 'fileHashDoesNotMatch';
const NOT_DETECTED = 'fileHashHashNotDetected';
const NOT_FOUND = 'fileHashNotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_NOT_MATCH => "The file '%value%' does not match the given hashes",
self::NOT_DETECTED => "There was no hash detected for the given file",
self::NOT_FOUND => "The file '%value%' could not be found"
);
/**
* Hash of the file
*
* @var string
*/
protected $_hash;
/**
* Sets validator options
*
* @param string|array $options
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_scalar($options)) {
$options = array('hash1' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid options to validator provided');
}
if (1 < func_num_args()) {
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
$options['algorithm'] = func_get_arg(1);
}
$this->setHash($options);
}
/**
* Returns the set hash values as array, the hash as key and the algorithm the value
*
* @return array
*/
public function getHash()
{
return $this->_hash;
}
/**
* Sets the hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setHash($options)
{
$this->_hash = null;
$this->addHash($options);
return $this;
}
/**
* Adds the hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addHash($options)
{
if (is_string($options)) {
$options = array($options);
} else if (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("False parameter given");
}
$known = hash_algos();
if (!isset($options['algorithm'])) {
$algorithm = 'crc32';
} else {
$algorithm = $options['algorithm'];
unset($options['algorithm']);
}
if (!in_array($algorithm, $known)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'");
}
foreach ($options as $value) {
$this->_hash[$value] = $algorithm;
}
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the given file confirms the set hash
*
* @param string $value Filename to check for hash
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$algos = array_unique(array_values($this->_hash));
$hashes = array_unique(array_keys($this->_hash));
foreach ($algos as $algorithm) {
$filehash = hash_file($algorithm, $value);
if ($filehash === false) {
return $this->_throw($file, self::NOT_DETECTED);
}
foreach($hashes as $hash) {
if ($filehash === $hash) {
return true;
}
}
}
return $this->_throw($file, self::DOES_NOT_MATCH);
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
$this->_value = $file['name'];
}
$this->_error($errorType);
return false;
}
}
Validate/File/Crc32.php 0000604 00000011361 15071256135 0010544 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_Hash
*/
require_once 'Zend/Validate/File/Hash.php';
/**
* Validator for the crc32 hash of given files
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_Crc32 extends Zend_Validate_File_Hash
{
/**
* @const string Error constants
*/
const DOES_NOT_MATCH = 'fileCrc32DoesNotMatch';
const NOT_DETECTED = 'fileCrc32NotDetected';
const NOT_FOUND = 'fileCrc32NotFound';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::DOES_NOT_MATCH => "The file '%value%' does not match the given crc32 hashes",
self::NOT_DETECTED => "There was no crc32 hash detected for the given file",
self::NOT_FOUND => "The file '%value%' could not be found"
);
/**
* Hash of the file
*
* @var string
*/
protected $_hash;
/**
* Sets validator options
*
* @param string|array $options
* @return void
*/
public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (is_scalar($options)) {
$options = array('hash1' => $options);
} elseif (!is_array($options)) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Invalid options to validator provided');
}
$this->setCrc32($options);
}
/**
* Returns all set crc32 hashes
*
* @return array
*/
public function getCrc32()
{
return $this->getHash();
}
/**
* Sets the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setHash($options)
{
if (!is_array($options)) {
$options = array($options);
}
$options['algorithm'] = 'crc32';
parent::setHash($options);
return $this;
}
/**
* Sets the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function setCrc32($options)
{
$this->setHash($options);
return $this;
}
/**
* Adds the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addHash($options)
{
if (!is_array($options)) {
$options = array($options);
}
$options['algorithm'] = 'crc32';
parent::addHash($options);
return $this;
}
/**
* Adds the crc32 hash for one or multiple files
*
* @param string|array $options
* @return Zend_Validate_File_Hash Provides a fluent interface
*/
public function addCrc32($options)
{
$this->addHash($options);
return $this;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the given file confirms the set hash
*
* @param string $value Filename to check for hash
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$hashes = array_unique(array_keys($this->_hash));
$filehash = hash_file('crc32', $value);
if ($filehash === false) {
return $this->_throw($file, self::NOT_DETECTED);
}
foreach($hashes as $hash) {
if ($filehash === $hash) {
return true;
}
}
return $this->_throw($file, self::DOES_NOT_MATCH);
}
} Validate/File/IsCompressed.php 0000604 00000010240 15071256135 0012263 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_MimeType
*/
require_once 'Zend/Validate/File/MimeType.php';
/**
* Validator which checks if the file already exists in the directory
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_IsCompressed extends Zend_Validate_File_MimeType
{
/**
* @const string Error constants
*/
const FALSE_TYPE = 'fileIsCompressedFalseType';
const NOT_DETECTED = 'fileIsCompressedNotDetected';
const NOT_READABLE = 'fileIsCompressedNotReadable';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::FALSE_TYPE => "The file '%value%' is not compressed, '%type%' detected",
self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected",
self::NOT_READABLE => "The file '%value%' can not be read"
);
/**
* Sets validator options
*
* @param string|array $compression
* @return void
*/
public function __construct($mimetype = array())
{
if (empty($mimetype)) {
$mimetype = array(
'application/x-tar',
'application/x-cpio',
'application/x-debian-package',
'application/x-archive',
'application/x-arc',
'application/x-arj',
'application/x-lharc',
'application/x-lha',
'application/x-rar',
'application/zip',
'application/zoo',
'application/x-eet',
'application/x-java-pack200',
'application/x-compress',
'application/x-gzip',
'application/x-bzip2'
);
}
$this->setMimeType($mimetype);
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file is compression with the set compression types
*
* @param string $value Real file to check for compression
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
if ($file !== null) {
if (class_exists('finfo', false) && defined('MAGIC')) {
$mime = new finfo(FILEINFO_MIME);
$this->_type = $mime->file($value);
unset($mime);
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
$this->_type = mime_content_type($value);
} else {
$this->_type = $file['type'];
}
}
if (empty($this->_type)) {
return $this->_throw($file, self::NOT_DETECTED);
}
$compressions = $this->getMimeType(true);
if (in_array($this->_type, $compressions)) {
return true;
}
$types = explode('/', $this->_type);
$types = array_merge($types, explode('-', $this->_type));
foreach ($compressions as $mime) {
if (in_array($mime, $types)) {
return true;
}
}
return $this->_throw($file, self::FALSE_TYPE);
}
}
Validate/File/IsImage.php 0000604 00000010312 15071256135 0011201 0 ustar 00 <?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_Validate
* @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: $
*/
/**
* @see Zend_Validate_File_MimeType
*/
require_once 'Zend/Validate/File/MimeType.php';
/**
* Validator which checks if the file already exists in the directory
*
* @category Zend
* @package Zend_Validate
* @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_Validate_File_IsImage extends Zend_Validate_File_MimeType
{
/**
* @const string Error constants
*/
const FALSE_TYPE = 'fileIsImageFalseType';
const NOT_DETECTED = 'fileIsImageNotDetected';
const NOT_READABLE = 'fileIsImageNotReadable';
/**
* @var array Error message templates
*/
protected $_messageTemplates = array(
self::FALSE_TYPE => "The file '%value%' is no image, '%type%' detected",
self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected",
self::NOT_READABLE => "The file '%value%' can not be read"
);
/**
* Sets validator options
*
* @param string|array $mimetype
* @return void
*/
public function __construct($mimetype = array())
{
if (empty($mimetype)) {
$mimetype = array(
'image/x-quicktime',
'image/jp2',
'image/x-xpmi',
'image/x-portable-bitmap',
'image/x-portable-greymap',
'image/x-portable-pixmap',
'image/x-niff',
'image/tiff',
'image/png',
'image/x-unknown',
'image/gif',
'image/x-ms-bmp',
'application/dicom',
'image/vnd.adobe.photoshop',
'image/vnd.djvu',
'image/x-cpi',
'image/jpeg',
'image/x-ico',
'image/x-coreldraw',
'image/svg+xml'
);
}
$this->setMimeType($mimetype);
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the file is compression with the set compression types
*
* @param string $value Real file to check for compression
* @param array $file File data from Zend_File_Transfer
* @return boolean
*/
public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_READABLE);
}
if ($file !== null) {
if (class_exists('finfo', false) && defined('MAGIC')) {
$mime = new finfo(FILEINFO_MIME);
$this->_type = $mime->file($value);
unset($mime);
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
$this->_type = mime_content_type($value);
} else {
$this->_type = $file['type'];
}
}
if (empty($this->_type)) {
return $this->_throw($file, self::NOT_DETECTED);
}
$compressions = $this->getMimeType(true);
if (in_array($this->_type, $compressions)) {
return true;
}
$types = explode('/', $this->_type);
$types = array_merge($types, explode('-', $this->_type));
foreach($compressions as $mime) {
if (in_array($mime, $types)) {
return true;
}
}
return $this->_throw($file, self::FALSE_TYPE);
}
}
Validate/Barcode.php 0000604 00000005262 15071256135 0010353 0 ustar 00 <?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_Validate
* @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: Barcode.php 8211 2008-02-20 14:29:24Z darby $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Barcode extends Zend_Validate_Abstract
{
/**
* Barcode validator
*
* @var Zend_Validate_Abstract
*/
protected $_barcodeValidator;
/**
* Generates the standard validator object
*
* @param string $barcodeType - Barcode validator to use
* @return void
* @throws Zend_Validate_Exception
*/
public function __construct($barcodeType)
{
$this->setType($barcodeType);
}
/**
* Sets a new barcode validator
*
* @param string $barcodeType - Barcode validator to use
* @return void
* @throws Zend_Validate_Exception
*/
public function setType($barcodeType)
{
switch (strtolower($barcodeType)) {
case 'upc':
case 'upc-a':
$className = 'UpcA';
break;
case 'ean13':
case 'ean-13':
$className = 'Ean13';
break;
default:
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'");
break;
}
require_once 'Zend/Validate/Barcode/' . $className . '.php';
$class = 'Zend_Validate_Barcode_' . $className;
$this->_barcodeValidator = new $class;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
return call_user_func(array($this->_barcodeValidator, 'isValid'), $value);
}
}
Validate/Hostname.php 0000604 00000037165 15071256135 0010601 0 ustar 00 <?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_Validate
* @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: Hostname.php 12274 2008-11-03 12:50:50Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Validate_Ip
*/
require_once 'Zend/Validate/Ip.php';
/**
* Please note there are two standalone test scripts for testing IDN characters due to problems
* with file encoding.
*
* The first is tests/Zend/Validate/HostnameTestStandalone.php which is designed to be run on
* the command line.
*
* The second is tests/Zend/Validate/HostnameTestForm.php which is designed to be run via HTML
* to allow users to test entering UTF-8 characters in a form.
*
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname extends Zend_Validate_Abstract
{
const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed';
const UNKNOWN_TLD = 'hostnameUnknownTld';
const INVALID_DASH = 'hostnameDashCharacter';
const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema';
const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld';
const INVALID_HOSTNAME = 'hostnameInvalidHostname';
const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName';
const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed';
/**
* @var array
*/
protected $_messageTemplates = array(
self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list",
self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position",
self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part",
self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname",
self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name",
self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed"
);
/**
* @var array
*/
protected $_messageVariables = array(
'tld' => '_tld'
);
/**
* Allows Internet domain names (e.g., example.com)
*/
const ALLOW_DNS = 1;
/**
* Allows IP addresses
*/
const ALLOW_IP = 2;
/**
* Allows local network names (e.g., localhost, www.localdomain)
*/
const ALLOW_LOCAL = 4;
/**
* Allows all types of hostnames
*/
const ALLOW_ALL = 7;
/**
* Whether IDN domains are validated
*
* @var boolean
*/
private $_validateIdn = true;
/**
* Whether TLDs are validated against a known list
*
* @var boolean
*/
private $_validateTld = true;
/**
* Bit field of ALLOW constants; determines which types of hostnames are allowed
*
* @var integer
*/
protected $_allow;
/**
* Bit field of CHECK constants; determines what additional hostname checks to make
*
* @var unknown_type
*/
// protected $_check;
/**
* Array of valid top-level-domains
*
* @var array
* @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain
*/
protected $_validTlds = array(
'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao',
'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb',
'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo',
'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd',
'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop',
'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do',
'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj',
'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh',
'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu',
'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il',
'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm',
'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw',
'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu',
'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm',
'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv',
'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng',
'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt',
'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd',
'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr',
'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj',
'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw',
'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've',
'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm',
'zw'
);
/**
* @var string
*/
protected $_tld;
/**
* Sets validator options
*
* @param integer $allow OPTIONAL Set what types of hostname to allow (default ALLOW_DNS)
* @param boolean $validateIdn OPTIONAL Set whether IDN domains are validated (default true)
* @param boolean $validateTld OPTIONAL Set whether the TLD element of a hostname is validated (default true)
* @param Zend_Validate_Ip $ipValidator OPTIONAL
* @return void
* @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs
*/
public function __construct($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = true, Zend_Validate_Ip $ipValidator = null)
{
// Set allow options
$this->setAllow($allow);
// Set validation options
$this->_validateIdn = $validateIdn;
$this->_validateTld = $validateTld;
$this->setIpValidator($ipValidator);
}
/**
* @param Zend_Validate_Ip $ipValidator OPTIONAL
* @return void;
*/
public function setIpValidator(Zend_Validate_Ip $ipValidator = null)
{
if ($ipValidator === null) {
$ipValidator = new Zend_Validate_Ip();
}
$this->_ipValidator = $ipValidator;
}
/**
* Returns the allow option
*
* @return integer
*/
public function getAllow()
{
return $this->_allow;
}
/**
* Sets the allow option
*
* @param integer $allow
* @return Zend_Validate_Hostname Provides a fluent interface
*/
public function setAllow($allow)
{
$this->_allow = $allow;
return $this;
}
/**
* Set whether IDN domains are validated
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate IDNs, and false to not validate them
*/
public function setValidateIdn ($allowed)
{
$this->_validateIdn = (bool) $allowed;
}
/**
* Set whether the TLD element of a hostname is validated
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate TLDs, and false to not validate them
*/
public function setValidateTld ($allowed)
{
$this->_validateTld = (bool) $allowed;
}
/**
* Sets the check option
*
* @param integer $check
* @return Zend_Validate_Hostname Provides a fluent interface
*/
/*
public function setCheck($check)
{
$this->_check = $check;
return $this;
}
*/
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if the $value is a valid hostname with respect to the current allow option
*
* @param string $value
* @throws Zend_Validate_Exception if a fatal error occurs for validation process
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
// Check input against IP address schema
if ($this->_ipValidator->setTranslator($this->getTranslator())->isValid($valueString)) {
if (!($this->_allow & self::ALLOW_IP)) {
$this->_error(self::IP_ADDRESS_NOT_ALLOWED);
return false;
} else{
return true;
}
}
// Check input against DNS hostname schema
$domainParts = explode('.', $valueString);
if ((count($domainParts) > 1) && (strlen($valueString) >= 4) && (strlen($valueString) <= 254)) {
$status = false;
do {
// First check TLD
if (preg_match('/([a-z]{2,10})$/i', end($domainParts), $matches)) {
reset($domainParts);
// Hostname characters are: *(label dot)(label dot label); max 254 chars
// label: id-prefix [*ldh{61} id-prefix]; max 63 chars
// id-prefix: alpha / digit
// ldh: alpha / digit / dash
// Match TLD against known list
$this->_tld = strtolower($matches[1]);
if ($this->_validateTld) {
if (!in_array($this->_tld, $this->_validTlds)) {
$this->_error(self::UNKNOWN_TLD);
$status = false;
break;
}
}
/**
* Match against IDN hostnames
* @see Zend_Validate_Hostname_Interface
*/
$labelChars = 'a-z0-9';
$utf8 = false;
$classFile = 'Zend/Validate/Hostname/' . ucfirst($this->_tld) . '.php';
if ($this->_validateIdn) {
if (Zend_Loader::isReadable($classFile)) {
// Load additional characters
$className = 'Zend_Validate_Hostname_' . ucfirst($this->_tld);
Zend_Loader::loadClass($className);
$labelChars .= call_user_func(array($className, 'getCharacters'));
$utf8 = true;
}
}
// Keep label regex short to avoid issues with long patterns when matching IDN hostnames
$regexLabel = '/^[' . $labelChars . '\x2d]{1,63}$/i';
if ($utf8) {
$regexLabel .= 'u';
}
// Check each hostname part
$valid = true;
foreach ($domainParts as $domainPart) {
// Check dash (-) does not start, end or appear in 3rd and 4th positions
if (strpos($domainPart, '-') === 0 ||
(strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3) ||
strrpos($domainPart, '-') === strlen($domainPart) - 1) {
$this->_error(self::INVALID_DASH);
$status = false;
break 2;
}
// Check each domain part
$status = @preg_match($regexLabel, $domainPart);
if ($status === false) {
/**
* Regex error
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: DNS validation failed');
} elseif ($status === 0) {
$valid = false;
}
}
// If all labels didn't match, the hostname is invalid
if (!$valid) {
$this->_error(self::INVALID_HOSTNAME_SCHEMA);
$status = false;
}
} else {
// Hostname not long enough
$this->_error(self::UNDECIPHERABLE_TLD);
$status = false;
}
} while (false);
// If the input passes as an Internet domain name, and domain names are allowed, then the hostname
// passes validation
if ($status && ($this->_allow & self::ALLOW_DNS)) {
return true;
}
} else {
$this->_error(self::INVALID_HOSTNAME);
}
// Check input against local network name schema; last chance to pass validation
$regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/';
$status = @preg_match($regexLocal, $valueString);
if (false === $status) {
/**
* Regex error
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: local network name validation failed');
}
// If the input passes as a local network name, and local network names are allowed, then the
// hostname passes validation
$allowLocal = $this->_allow & self::ALLOW_LOCAL;
if ($status && $allowLocal) {
return true;
}
// If the input does not pass as a local network name, add a message
if (!$status) {
$this->_error(self::INVALID_LOCAL_NAME);
}
// If local network names are not allowed, add a message
if ($status && !$allowLocal) {
$this->_error(self::LOCAL_NAME_NOT_ALLOWED);
}
return false;
}
/**
* Throws an exception if a regex for $type does not exist
*
* @param string $type
* @throws Zend_Validate_Exception
* @return Zend_Validate_Hostname Provides a fluent interface
*/
/*
protected function _checkRegexType($type)
{
if (!isset($this->_regex[$type])) {
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("'$type' must be one of ('" . implode(', ', array_keys($this->_regex))
. "')");
}
return $this;
}
*/
}
Validate/EmailAddress.php 0000604 00000021171 15071256135 0011346 0 ustar 00 <?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_Validate
* @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: EmailAddress.php 13253 2008-12-14 20:28:06Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @see Zend_Validate_Hostname
*/
require_once 'Zend/Validate/Hostname.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_EmailAddress extends Zend_Validate_Abstract
{
const INVALID = 'emailAddressInvalid';
const INVALID_HOSTNAME = 'emailAddressInvalidHostname';
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord';
const DOT_ATOM = 'emailAddressDotAtom';
const QUOTED_STRING = 'emailAddressQuotedString';
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded';
/**
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is not a valid email address in the basic format local-part@hostname",
self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'",
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
self::DOT_ATOM => "'%localPart%' not matched against dot-atom format",
self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format",
self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'",
self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length"
);
/**
* @var array
*/
protected $_messageVariables = array(
'hostname' => '_hostname',
'localPart' => '_localPart'
);
/**
* Local object for validating the hostname part of an email address
*
* @var Zend_Validate_Hostname
*/
public $hostnameValidator;
/**
* Whether we check for a valid MX record via DNS
*
* @var boolean
*/
protected $_validateMx = false;
/**
* @var string
*/
protected $_hostname;
/**
* @var string
*/
protected $_localPart;
/**
* Instantiates hostname validator for local use
*
* You can pass a bitfield to determine what types of hostnames are allowed.
* These bitfields are defined by the ALLOW_* constants in Zend_Validate_Hostname
* The default is to allow DNS hostnames only
*
* @param integer $allow OPTIONAL
* @param bool $validateMx OPTIONAL
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
* @return void
*/
public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null)
{
$this->setValidateMx($validateMx);
$this->setHostnameValidator($hostnameValidator, $allow);
}
/**
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
* @param int $allow OPTIONAL
* @return void
*/
public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS)
{
if ($hostnameValidator === null) {
$hostnameValidator = new Zend_Validate_Hostname($allow);
}
$this->hostnameValidator = $hostnameValidator;
}
/**
* Whether MX checking via dns_get_mx is supported or not
*
* This currently only works on UNIX systems
*
* @return boolean
*/
public function validateMxSupported()
{
return function_exists('dns_get_mx');
}
/**
* Set whether we check for a valid MX record via DNS
*
* This only applies when DNS hostnames are validated
*
* @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them
*/
public function setValidateMx($allowed)
{
$this->_validateMx = (bool) $allowed;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid email address
* according to RFC2822
*
* @link http://www.ietf.org/rfc/rfc2822.txt RFC2822
* @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$matches = array();
$length = true;
$this->_setValue($valueString);
// Split email address up and disallow '..'
if ((strpos($valueString, '..') !== false) or
(!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches))) {
$this->_error(self::INVALID);
return false;
}
$this->_localPart = $matches[1];
$this->_hostname = $matches[2];
if ((strlen($this->_localPart) > 64) || (strlen($this->_hostname) > 255)) {
$length = false;
$this->_error(self::LENGTH_EXCEEDED);
}
// Match hostname part
$hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())
->isValid($this->_hostname);
if (!$hostnameResult) {
$this->_error(self::INVALID_HOSTNAME);
// Get messages and errors from hostnameValidator
foreach ($this->hostnameValidator->getMessages() as $code => $message) {
$this->_messages[$code] = $message;
}
foreach ($this->hostnameValidator->getErrors() as $error) {
$this->_errors[] = $error;
}
} else if ($this->_validateMx) {
// MX check on hostname via dns_get_record()
if ($this->validateMxSupported()) {
$result = dns_get_mx($this->_hostname, $mxHosts);
if (count($mxHosts) < 1) {
$hostnameResult = false;
$this->_error(self::INVALID_MX_RECORD);
}
} else {
/**
* MX checks are not supported by this system
* @see Zend_Validate_Exception
*/
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
}
}
// First try to match the local part on the common dot-atom format
$localResult = false;
// Dot-atom characters are: 1*atext *("." 1*atext)
// atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
// "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
$atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d';
if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
$localResult = true;
} else {
// Try quoted string format
// Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
// qtext: Non white space controls, and the rest of the US-ASCII characters not
// including "\" or the quote character
$noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f';
$qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e';
$ws = '\x20\x09';
if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) {
$localResult = true;
} else {
$this->_error(self::DOT_ATOM);
$this->_error(self::QUOTED_STRING);
$this->_error(self::INVALID_LOCAL_PART);
}
}
// If both parts valid, return true
if ($localResult && $hostnameResult && $length) {
return true;
} else {
return false;
}
}
}
Validate/Ccnum.php 0000604 00000005657 15071256135 0010071 0 ustar 00 <?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_Validate
* @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: Ccnum.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Ccnum extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is not of valid length
*/
const LENGTH = 'ccnumLength';
/**
* Validation failure message key for when the value fails the mod-10 checksum
*/
const CHECKSUM = 'ccnumChecksum';
/**
* Digits filter for input
*
* @var Zend_Filter_Digits
*/
protected static $_filter = null;
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::LENGTH => "'%value%' must contain between 13 and 19 digits",
self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$this->_setValue($value);
if (null === self::$_filter) {
/**
* @see Zend_Filter_Digits
*/
require_once 'Zend/Filter/Digits.php';
self::$_filter = new Zend_Filter_Digits();
}
$valueFiltered = self::$_filter->filter($value);
$length = strlen($valueFiltered);
if ($length < 13 || $length > 19) {
$this->_error(self::LENGTH);
return false;
}
$sum = 0;
$weight = 2;
for ($i = $length - 2; $i >= 0; $i--) {
$digit = $weight * $valueFiltered[$i];
$sum += floor($digit / 10) + $digit % 10;
$weight = $weight % 2 + 1;
}
if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) {
$this->_error(self::CHECKSUM, $valueFiltered);
return false;
}
return true;
}
}
Validate/Barcode/Ean13.php 0000604 00000006050 15071256135 0011216 0 ustar 00 <?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_Validate
* @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: Ean13.php 11791 2008-10-09 18:19:13Z andries $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Barcode_Ean13 extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is
* an invalid barcode
*/
const INVALID = 'invalid';
/**
* Validation failure message key for when the value is
* not 13 characters long
*/
const INVALID_LENGTH = 'invalidLength';
/**
* Validation failure message key for when the value
* does not only contain numeric characters
*/
const NOT_NUMERIC = 'ean13NotNumeric';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is an invalid EAN-13 barcode",
self::INVALID_LENGTH => "'%value%' should be 13 characters",
self::NOT_NUMERIC => "'%value%' should contain only numeric characters",
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
if (false === ctype_digit($value)) {
$this->_error(self::NOT_NUMERIC);
return false;
}
$valueString = (string) $value;
$this->_setValue($valueString);
if (strlen($valueString) !== 13) {
$this->_error(self::INVALID_LENGTH);
return false;
}
$barcode = strrev(substr($valueString, 0, -1));
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 12; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10 - $calculation;
if ($valueString[12] != $checksum) {
$this->_error(self::INVALID);
return false;
}
return true;
}
}
Validate/Barcode/UpcA.php 0000604 00000005243 15071256135 0011202 0 ustar 00 <?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_Validate
* @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: UpcA.php 8210 2008-02-20 14:09:05Z andries $
*/
/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Barcode_UpcA extends Zend_Validate_Abstract
{
/**
* Validation failure message key for when the value is
* an invalid barcode
*/
const INVALID = 'invalid';
/**
* Validation failure message key for when the value is
* not 12 characters long
*/
const INVALID_LENGTH = 'invalidLength';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is an invalid UPC-A barcode",
self::INVALID_LENGTH => "'%value%' should be 12 characters",
);
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value contains a valid barcode
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (strlen($valueString) !== 12) {
$this->_error(self::INVALID_LENGTH);
return false;
}
$barcode = substr($valueString, 0, -1);
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 11; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10 - $calculation;
if ($valueString[11] != $checksum) {
$this->_error(self::INVALID);
return false;
}
return true;
}
}
Validate/Hostname/Se.php 0000604 00000002707 15071256135 0011142 0 ustar 00 <?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_Validate
* @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: Se.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_Se implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.iis.se/english/IDN_campaignsite.shtml?lang=en Sweden (.SE)
* @return string
*/
static function getCharacters()
{
return '\x{00E5}\x{00E4}\x{00F6}\x{00FC}\x{00E9}';
}
} Validate/Hostname/Li.php 0000604 00000002764 15071256135 0011142 0 ustar 00 <?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_Validate
* @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: Li.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_Li implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1 Liechtenstein (.LI)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}';
}
} Validate/Hostname/Hu.php 0000604 00000002743 15071256135 0011147 0 ustar 00 <?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_Validate
* @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: Hu.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_Hu implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.domain.hu/domain/English/szabalyzat.html Hungary (.HU)
* @return string
*/
static function getCharacters()
{
return '\x{00E1}\x{00E9}\x{00ED}\x{00F3}\x{00F6}\x{0151}\x{00FA}\x{00FC}\x{0171}';
}
} Validate/Hostname/At.php 0000604 00000002753 15071256135 0011140 0 ustar 00 <?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_Validate
* @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: At.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_At implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.nic.at/en/service/technical_information/idn/charset_converter/ Austria (.AT)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}\x{0161}\x{017E}';
}
} Validate/Hostname/Ch.php 0000604 00000002762 15071256135 0011126 0 ustar 00 <?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_Validate
* @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: Ch.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_Ch implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1 Switzerland (.CH)
* @return string
*/
static function getCharacters()
{
return '\x{00EO}-\x{00F6}\x{00F8}-\x{00FF}\x{0153}';
}
} Validate/Hostname/Fi.php 0000604 00000002715 15071256135 0011130 0 ustar 00 <?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_Validate
* @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: Fi.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_Fi implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.ficora.fi/en/index/palvelut/fiverkkotunnukset/aakkostenkaytto.html Finland (.FI)
* @return string
*/
static function getCharacters()
{
return '\x{00E5}\x{00E4}\x{00F6}';
}
} Validate/Hostname/De.php 0000604 00000004463 15071256135 0011124 0 ustar 00 <?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_Validate
* @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: De.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_De implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.denic.de/en/domains/idns/liste.html Germany (.DE) alllowed characters
* @return string
*/
static function getCharacters()
{
return '\x{00E1}\x{00E0}\x{0103}\x{00E2}\x{00E5}\x{00E4}\x{00E3}\x{0105}\x{0101}\x{00E6}\x{0107}' .
'\x{0109}\x{010D}\x{010B}\x{00E7}\x{010F}\x{0111}\x{00E9}\x{00E8}\x{0115}\x{00EA}\x{011B}' .
'\x{00EB}\x{0117}\x{0119}\x{0113}\x{011F}\x{011D}\x{0121}\x{0123}\x{0125}\x{0127}\x{00ED}' .
'\x{00EC}\x{012D}\x{00EE}\x{00EF}\x{0129}\x{012F}\x{012B}\x{0131}\x{0135}\x{0137}\x{013A}' .
'\x{013E}\x{013C}\x{0142}\x{0144}\x{0148}\x{00F1}\x{0146}\x{014B}\x{00F3}\x{00F2}\x{014F}' .
'\x{00F4}\x{00F6}\x{0151}\x{00F5}\x{00F8}\x{014D}\x{0153}\x{0138}\x{0155}\x{0159}\x{0157}' .
'\x{015B}\x{015D}\x{0161}\x{015F}\x{0165}\x{0163}\x{0167}\x{00FA}\x{00F9}\x{016D}\x{00FB}' .
'\x{016F}\x{00FC}\x{0171}\x{0169}\x{0173}\x{016B}\x{0175}\x{00FD}\x{0177}\x{00FF}\x{017A}' .
'\x{017E}\x{017C}\x{00F0}\x{00FE}';
}
} Validate/Hostname/Interface.php 0000604 00000003477 15071256135 0012500 0 ustar 00 <?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_Validate
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* UTF-8 characters should be written as four character hex codes \x{XXXX}
* For example é (lowercase e with acute) is represented by the hex code \x{00E9}
*
* You only need to include lower-case equivalents of characters since the hostname
* check is case-insensitive
*
* Please document the supported TLDs in the documentation file at:
* manual/en/module_specs/Zend_Validate-Hostname.xml
*
* @see http://en.wikipedia.org/wiki/Internationalized_domain_name
* @see http://www.iana.org/cctld/ Country-Code Top-Level Domains (TLDs)
* @see http://www.columbia.edu/kermit/utf8-t1.html UTF-8 characters
* @return string
*/
static function getCharacters();
} Validate/Hostname/No.php 0000604 00000003135 15071256135 0011143 0 ustar 00 <?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_Validate
* @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: No.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Validate_Hostname_Interface
*/
require_once 'Zend/Validate/Hostname/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate_Hostname_No implements Zend_Validate_Hostname_Interface
{
/**
* Returns UTF-8 characters allowed in DNS hostnames for the specified Top-Level-Domain
*
* @see http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html Norway (.NO)
* @return string
*/
static function getCharacters()
{
return '\x00E1\x00E0\x00E4\x010D\x00E7\x0111\x00E9\x00E8\x00EA\x\x014B' .
'\x0144\x00F1\x00F3\x00F2\x00F4\x00F6\x0161\x0167\x00FC\x017E\x00E6' .
'\x00F8\x00E5';
}
}
Gdata/Entry.php 0000604 00000010526 15071256135 0007403 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_App_MediaEntry
*/
require_once 'Zend/Gdata/App/MediaEntry.php';
/**
* Represents the Gdata flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Entry extends Zend_Gdata_App_MediaEntry
{
protected $_entryClassName = 'Zend_Gdata_Entry';
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
// ETags are special. We only support them in protocol >= 2.X.
// This will be duplicated by the HTTP ETag header.
if ($majorVersion >= 2) {
if ($this->_etag != null) {
$element->setAttributeNS($this->lookupNamespace('gd'),
'gd:etag',
$this->_etag);
}
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'content':
$content = new Zend_Gdata_App_Extension_Content();
$content->transferFromDOM($child);
$this->_content = $content;
break;
case $this->lookupNamespace('atom') . ':' . 'published':
$published = new Zend_Gdata_App_Extension_Published();
$published->transferFromDOM($child);
$this->_published = $published;
break;
case $this->lookupNamespace('atom') . ':' . 'source':
$source = new Zend_Gdata_App_Extension_Source();
$source->transferFromDOM($child);
$this->_source = $source;
break;
case $this->lookupNamespace('atom') . ':' . 'summary':
$summary = new Zend_Gdata_App_Extension_Summary();
$summary->transferFromDOM($child);
$this->_summary = $summary;
break;
case $this->lookupNamespace('app') . ':' . 'control':
$control = new Zend_Gdata_App_Extension_Control();
$control->transferFromDOM($child);
$this->_control = $control;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'etag':
// ETags are special, since they can be conveyed by either the
// HTTP ETag header or as an XML attribute.
$etag = $attribute->nodeValue;
if (is_null($this->_etag)) {
$this->_etag = $etag;
}
elseif ($this->_etag != $etag) {
require_once('Zend/Gdata/App/IOException.php');
throw new Zend_Gdata_App_IOException("ETag mismatch");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
break;
}
}
}
Gdata/Health.php 0000604 00000021561 15071256135 0007510 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Health_ProfileFeed
*/
require_once 'Zend/Gdata/Health/ProfileFeed.php';
/**
* @see Zend_Gdata_Health_ProfileListFeed
*/
require_once 'Zend/Gdata/Health/ProfileListFeed.php';
/**
* @see Zend_Gdata_Health_ProfileListEntry
*/
require_once 'Zend/Gdata/Health/ProfileListEntry.php';
/**
* @see Zend_Gdata_Health_ProfileEntry
*/
require_once 'Zend/Gdata/Health/ProfileEntry.php';
/**
* Service class for interacting with the Google Health Data API
*
* @link http://code.google.com/apis/health
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health extends Zend_Gdata
{
/**
* URIs of the AuthSub/OAuth feeds.
*/
const AUTHSUB_PROFILE_FEED_URI =
'https://www.google.com/health/feeds/profile/default';
const AUTHSUB_REGISTER_FEED_URI =
'https://www.google.com/health/feeds/register/default';
/**
* URIs of the ClientLogin feeds.
*/
const CLIENTLOGIN_PROFILELIST_FEED_URI =
'https://www.google.com/health/feeds/profile/list';
const CLIENTLOGIN_PROFILE_FEED_URI =
'https://www.google.com/health/feeds/profile/ui';
const CLIENTLOGIN_REGISTER_FEED_URI =
'https://www.google.com/health/feeds/register/ui';
/**
* Authentication service names for Google Health and the H9 Sandbox.
*/
const HEALTH_SERVICE_NAME = 'health';
const H9_SANDBOX_SERVICE_NAME = 'weaver';
/**
* Profile ID used for all API interactions. This can only be set when
* using ClientLogin for authentication.
*
* @var string
*/
private $_profileID = null;
/**
* True if API calls should be made to the H9 developer sandbox at /h9
* rather than /health
*
* @var bool
*/
private $_useH9Sandbox = false;
public static $namespaces =
array('ccr' => 'urn:astm-org:CCR',
'batch' => 'http://schemas.google.com/gdata/batch',
'h9m' => 'http://schemas.google.com/health/metadata',
'gAcl' => 'http://schemas.google.com/acl/2007',
'gd' => 'http://schemas.google.com/g/2005');
/**
* Create Zend_Gdata_Health object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google Health servers.
* @param string $applicationId The identity of the application in the form
* of Company-AppName-Version
* @param bool $useH9Sandbox True if the H9 Developer's Sandbox should be
* used instead of production Google Health.
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0', $useH9Sandbox = false)
{
$this->registerPackage('Zend_Gdata_Health');
$this->registerPackage('Zend_Gdata_Health_Extension_Ccr');
parent::__construct($client, $applicationId);
$this->_useH9Sandbox = $useH9Sandbox;
}
/**
* Gets the id of the user's profile
*
* @return string The profile id
*/
public function getProfileID()
{
return $this->_profileID;
}
/**
* Sets which of the user's profiles will be used
*
* @param string $id The profile ID
* @return Zend_Gdata_Health Provides a fluent interface
*/
public function setProfileID($id) {
$this->_profileID = $id;
return $this;
}
/**
* Retrieves the list of profiles associated with the user's ClientLogin
* credentials.
*
* @param string $query The query of the feed as a URL or Query object
* @return Zend_Gdata_Feed
*/
public function getHealthProfileListFeed($query = null)
{
if ($this->_httpClient->getClientLoginToken() === null) {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Profiles list feed is only available when using ClientLogin');
}
if($query === null) {
$uri = self::CLIENTLOGIN_PROFILELIST_FEED_URI;
} else if ($query instanceof Zend_Gdata_Query) {
$uri = $query->getQueryUrl();
} else {
$uri = $query;
}
// use correct feed for /h9 or /health
if ($this->_useH9Sandbox) {
$uri = preg_replace('/\/health\//', '/h9/', $uri);
}
return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileListFeed');
}
/**
* Retrieve a user's profile as a feed object. If ClientLogin is used, the
* profile associated with $this->_profileID is returned, otherwise
* the profile associated with the AuthSub token is read.
*
* @param mixed $query The query for the feed, as a URL or Query
* @return Zend_Gdata_Health_ProfileFeed
*/
public function getHealthProfileFeed($query = null)
{
if ($this->_httpClient->getClientLoginToken() !== null &&
$this->getProfileID() == null) {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Profile ID must not be null. Did you call setProfileID()?');
}
if ($query instanceof Zend_Gdata_Query) {
$uri = $query->getQueryUrl();
} else if ($this->_httpClient->getClientLoginToken() !== null &&
$query == null) {
$uri = self::CLIENTLOGIN_PROFILE_FEED_URI . '/' . $this->getProfileID();
} else if ($query === null) {
$uri = self::AUTHSUB_PROFILE_FEED_URI;
} else {
$uri = $query;
}
// use correct feed for /h9 or /health
if ($this->_useH9Sandbox) {
$uri = preg_replace('/\/health\//', '/h9/', $uri);
}
return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileFeed');
}
/**
* Retrieve a profile entry object
*
* @param mixed $query The query for the feed, as a URL or Query
* @return Zend_Gdata_Health_ProfileEntry
*/
public function getHealthProfileEntry($query = null)
{
if ($query === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Query must not be null');
} else if ($query instanceof Zend_Gdata_Query) {
$uri = $query->getQueryUrl();
} else {
$uri = $query;
}
return parent::getEntry($uri, 'Zend_Gdata_Health_ProfileEntry');
}
/**
* Posts a new notice using the register feed. This function constructs
* the atom profile entry.
*
* @param string $subject The subject line of the notice
* @param string $body The message body of the notice
* @param string $bodyType The (optional) type of message body
* (text, xhtml, html, etc.)
* @param string $ccrXML The (optional) CCR to add to the user's profile
* @return Zend_Gdata_Health_ProfileEntry
*/
public function sendHealthNotice($subject, $body, $bodyType = null, $ccrXML = null)
{
if ($this->_httpClient->getClientLoginToken()) {
$profileID = $this->getProfileID();
if ($profileID !== null) {
$uri = self::CLIENTLOGIN_REGISTER_FEED_URI . '/' . $profileID;
} else {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Profile ID must not be null. Did you call setProfileID()?');
}
} else {
$uri = self::AUTHSUB_REGISTER_FEED_URI;
}
$entry = new Zend_Gdata_Health_ProfileEntry();
$entry->title = $this->newTitle($subject);
$entry->content = $this->newContent($body);
$entry->content->type = $bodyType ? $bodyType : 'text';
$entry->setCcr($ccrXML);
// use correct feed for /h9 or /health
if ($this->_useH9Sandbox) {
$uri = preg_replace('/\/health\//', '/h9/', $uri);
}
return $this->insertEntry($entry, $uri, 'Zend_Gdata_Health_ProfileEntry');
}
}
Gdata/YouTube.php 0000604 00000056062 15071256135 0007703 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media
*/
require_once 'Zend/Gdata/Media.php';
/**
* @see Zend_Gdata_YouTube_VideoEntry
*/
require_once 'Zend/Gdata/YouTube/VideoEntry.php';
/**
* @see Zend_Gdata_YouTube_VideoFeed
*/
require_once 'Zend/Gdata/YouTube/VideoFeed.php';
/**
* @see Zend_Gdata_YouTube_CommentFeed
*/
require_once 'Zend/Gdata/YouTube/CommentFeed.php';
/**
* @see Zend_Gdata_YouTube_PlaylistListFeed
*/
require_once 'Zend/Gdata/YouTube/PlaylistListFeed.php';
/**
* @see Zend_Gdata_YouTube_SubscriptionFeed
*/
require_once 'Zend/Gdata/YouTube/SubscriptionFeed.php';
/**
* @see Zend_Gdata_YouTube_ContactFeed
*/
require_once 'Zend/Gdata/YouTube/ContactFeed.php';
/**
* @see Zend_Gdata_YouTube_PlaylistVideoFeed
*/
require_once 'Zend/Gdata/YouTube/PlaylistVideoFeed.php';
/**
* Service class for interacting with the YouTube Data API.
* @link http://code.google.com/apis/youtube/
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube extends Zend_Gdata_Media
{
const AUTH_SERVICE_NAME = 'youtube';
const CLIENTLOGIN_URL = 'https://www.google.com/youtube/accounts/ClientLogin';
const STANDARD_TOP_RATED_URI = 'http://gdata.youtube.com/feeds/standardfeeds/top_rated';
const STANDARD_MOST_VIEWED_URI = 'http://gdata.youtube.com/feeds/standardfeeds/most_viewed';
const STANDARD_RECENTLY_FEATURED_URI = 'http://gdata.youtube.com/feeds/standardfeeds/recently_featured';
const STANDARD_WATCH_ON_MOBILE_URI = 'http://gdata.youtube.com/feeds/standardfeeds/watch_on_mobile';
const STANDARD_TOP_RATED_URI_V2 =
'http://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
const STANDARD_MOST_VIEWED_URI_V2 =
'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
const STANDARD_RECENTLY_FEATURED_URI_V2 =
'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
const STANDARD_WATCH_ON_MOBILE_URI_V2 =
'http://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
const USER_URI = 'http://gdata.youtube.com/feeds/api/users';
const VIDEO_URI = 'http://gdata.youtube.com/feeds/api/videos';
const PLAYLIST_REL = 'http://gdata.youtube.com/schemas/2007#playlist';
const USER_UPLOADS_REL = 'http://gdata.youtube.com/schemas/2007#user.uploads';
const USER_PLAYLISTS_REL = 'http://gdata.youtube.com/schemas/2007#user.playlists';
const USER_SUBSCRIPTIONS_REL = 'http://gdata.youtube.com/schemas/2007#user.subscriptions';
const USER_CONTACTS_REL = 'http://gdata.youtube.com/schemas/2007#user.contacts';
const USER_FAVORITES_REL = 'http://gdata.youtube.com/schemas/2007#user.favorites';
const VIDEO_RESPONSES_REL = 'http://gdata.youtube.com/schemas/2007#video.responses';
const VIDEO_RATINGS_REL = 'http://gdata.youtube.com/schemas/2007#video.ratings';
const VIDEO_COMPLAINTS_REL = 'http://gdata.youtube.com/schemas/2007#video.complaints';
const FAVORITES_URI_SUFFIX = 'favorites';
const UPLOADS_URI_SUFFIX = 'uploads';
const RESPONSES_URI_SUFFIX = 'responses';
const RELATED_URI_SUFFIX = 'related';
/**
* Namespaces used for Zend_Gdata_YouTube
*
* @var array
*/
public static $namespaces = array(
array('yt', 'http://gdata.youtube.com/schemas/2007', 1, 0),
array('georss', 'http://www.georss.org/georss', 1, 0),
array('gml', 'http://www.opengis.net/gml', 1, 0),
array('media', 'http://search.yahoo.com/mrss/', 1, 0)
);
/**
* Create Zend_Gdata_YouTube object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
* @param string $clientId The clientId issued by the YouTube dashboard
* @param string $developerKey The developerKey issued by the YouTube dashboard
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0', $clientId = null, $developerKey = null)
{
$this->registerPackage('Zend_Gdata_YouTube');
$this->registerPackage('Zend_Gdata_YouTube_Extension');
$this->registerPackage('Zend_Gdata_Media');
$this->registerPackage('Zend_Gdata_Media_Extension');
// NOTE This constructor no longer calls the parent constructor
$this->setHttpClient($client, $applicationId, $clientId, $developerKey);
}
/**
* Set the Zend_Http_Client object used for communication
*
* @param Zend_Http_Client $client The client to use for communication
* @throws Zend_Gdata_App_HttpException
* @return Zend_Gdata_App Provides a fluent interface
*/
public function setHttpClient($client, $applicationId = 'MyCompany-MyApp-1.0', $clientId = null, $developerKey = null)
{
if ($client === null) {
$client = new Zend_Http_Client();
}
if (!$client instanceof Zend_Http_Client) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException('Argument is not an instance of Zend_Http_Client.');
}
if ($clientId != null) {
$client->setHeaders('X-GData-Client', $clientId);
}
if ($developerKey != null) {
$client->setHeaders('X-GData-Key', 'key='. $developerKey);
}
return parent::setHttpClient($client, $applicationId);
}
/**
* Retrieves a feed of videos.
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getVideoFeed($location = null)
{
if ($location == null) {
$uri = self::VIDEO_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a specific video entry.
*
* @param mixed $videoId The ID of the video to retrieve.
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined.
* @param boolean $fullEntry (optional) Retrieve the full metadata for the
* entry. Only possible if entry belongs to currently authenticated
* user. An exception will be thrown otherwise.
* @throws Zend_Gdata_App_HttpException
* @return Zend_Gdata_YouTube_VideoEntry The video entry found at the
* specified URL.
*/
public function getVideoEntry($videoId = null, $location = null,
$fullEntry = false)
{
if ($videoId !== null) {
if ($fullEntry) {
return $this->getFullVideoEntry($videoId);
} else {
$uri = self::VIDEO_URI . "/" . $videoId;
}
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry');
}
/**
* Retrieves a video entry from the user's upload feed.
*
* @param mixed $videoID The ID of the video to retrieve.
* @throws Zend_Gdata_App_HttpException
* @return Zend_Gdata_YouTube_VideoEntry|null The video entry to be
* retrieved, or null if it was not found or the user requesting it
* did not have the appropriate permissions.
*/
public function getFullVideoEntry($videoId)
{
$uri = self::USER_URI . "/default/" .
self::UPLOADS_URI_SUFFIX . "/$videoId";
return parent::getEntry($uri, 'Zend_Gdata_YouTube_VideoEntry');
}
/**
* Retrieves a feed of videos related to the specified video ID.
*
* @param string $videoId The videoId of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getRelatedVideoFeed($videoId = null, $location = null)
{
if ($videoId !== null) {
$uri = self::VIDEO_URI . "/" . $videoId . "/" . self::RELATED_URI_SUFFIX;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed of video responses related to the specified video ID.
*
* @param string $videoId The videoId of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getVideoResponseFeed($videoId = null, $location = null)
{
if ($videoId !== null) {
$uri = self::VIDEO_URI . "/" . $videoId . "/" . self::RESPONSES_URI_SUFFIX;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed of comments related to the specified video ID.
*
* @param string $videoId The videoId of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the
* specified URL.
*/
public function getVideoCommentFeed($videoId = null, $location = null)
{
if ($videoId !== null) {
$uri = self::VIDEO_URI . "/" . $videoId . "/comments";
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_CommentFeed');
}
/**
* Retrieves a feed of comments related to the specified video ID.
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_CommentFeed The feed of videos found at the
* specified URL.
*/
public function getTopRatedVideoFeed($location = null)
{
$standardFeedUri = self::STANDARD_TOP_RATED_URI;
if ($this->getMajorProtocolVersion() == 2) {
$standardFeedUri = self::STANDARD_TOP_RATED_URI_V2;
}
if ($location == null) {
$uri = $standardFeedUri;
} else if ($location instanceof Zend_Gdata_Query) {
if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
if (!isset($location->url)) {
$location->setFeedType('top rated');
}
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed of the most viewed videos.
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getMostViewedVideoFeed($location = null)
{
$standardFeedUri = self::STANDARD_MOST_VIEWED_URI;
if ($this->getMajorProtocolVersion() == 2) {
$standardFeedUri = self::STANDARD_MOST_VIEWED_URI_V2;
}
if ($location == null) {
$uri = $standardFeedUri;
} else if ($location instanceof Zend_Gdata_Query) {
if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
if (!isset($location->url)) {
$location->setFeedType('most viewed');
}
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed of recently featured videos.
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getRecentlyFeaturedVideoFeed($location = null)
{
$standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI;
if ($this->getMajorProtocolVersion() == 2) {
$standardFeedUri = self::STANDARD_RECENTLY_FEATURED_URI_V2;
}
if ($location == null) {
$uri = $standardFeedUri;
} else if ($location instanceof Zend_Gdata_Query) {
if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
if (!isset($location->url)) {
$location->setFeedType('recently featured');
}
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed of videos recently featured for mobile devices.
* These videos will have RTSP links in the $entry->mediaGroup->content
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The feed of videos found at the
* specified URL.
*/
public function getWatchOnMobileVideoFeed($location = null)
{
$standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI;
if ($this->getMajorProtocolVersion() == 2) {
$standardFeedUri = self::STANDARD_WATCH_ON_MOBILE_URI_V2;
}
if ($location == null) {
$uri = $standardFeedUri;
} else if ($location instanceof Zend_Gdata_Query) {
if ($location instanceof Zend_Gdata_YouTube_VideoQuery) {
if (!isset($location->url)) {
$location->setFeedType('watch on mobile');
}
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a feed which lists a user's playlist
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_PlaylistListFeed The feed of playlists
*/
public function getPlaylistListFeed($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user . '/playlists';
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistListFeed');
}
/**
* Retrieves a feed of videos in a particular playlist
*
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_PlaylistVideoFeed The feed of videos found at
* the specified URL.
*/
public function getPlaylistVideoFeed($location)
{
if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_PlaylistVideoFeed');
}
/**
* Retrieves a feed of a user's subscriptions
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_SubscriptionListFeed The feed of subscriptions
*/
public function getSubscriptionFeed($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user . '/subscriptions';
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_SubscriptionFeed');
}
/**
* Retrieves a feed of a user's contacts
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_ContactFeed The feed of contacts
*/
public function getContactFeed($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user . '/contacts';
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_ContactFeed');
}
/**
* Retrieves a user's uploads
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The videos uploaded by the user
*/
public function getUserUploads($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user . '/' .
self::UPLOADS_URI_SUFFIX;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a user's favorites
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_VideoFeed The videos favorited by the user
*/
public function getUserFavorites($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user . '/' .
self::FAVORITES_URI_SUFFIX;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_YouTube_VideoFeed');
}
/**
* Retrieves a user's profile as an entry
*
* @param string $user (optional) The username of interest
* @param mixed $location (optional) The URL to query or a
* Zend_Gdata_Query object from which a URL can be determined
* @return Zend_Gdata_YouTube_UserProfileEntry The user profile entry
*/
public function getUserProfile($user = null, $location = null)
{
if ($user !== null) {
$uri = self::USER_URI . '/' . $user;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_YouTube_UserProfileEntry');
}
/**
* Helper function for parsing a YouTube token response
*
* @param string $response The service response
* @throws Zend_Gdata_App_Exception
* @return array An array containing the token and URL
*/
public static function parseFormUploadTokenResponse($response)
{
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($response);
@ini_restore('track_errors');
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("Zend_Gdata_YouTube::parseFormUploadTokenResponse - " .
"DOMDocument cannot parse XML: $php_errormsg");
}
$responseElement = $doc->getElementsByTagName('response')->item(0);
$urlText = null;
$tokenText = null;
if ($responseElement != null) {
$urlElement = $responseElement->getElementsByTagName('url')->item(0);
$tokenElement = $responseElement->getElementsByTagName('token')->item(0);
if ($urlElement && $urlElement->hasChildNodes() &&
$tokenElement && $tokenElement->hasChildNodes()) {
$urlText = $urlElement->firstChild->nodeValue;
$tokenText = $tokenElement->firstChild->nodeValue;
}
}
if ($tokenText != null && $urlText != null) {
return array('token' => $tokenText, 'url' => $urlText);
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("form upload token not found in response");
}
}
/**
* Retrieves a YouTube token
*
* @param Zend_Gdata_YouTube_VideoEntry $videoEntry The video entry
* @param string $url The location as a string URL
* @throws Zend_Gdata_App_Exception
* @return array An array containing a token and URL
*/
public function getFormUploadToken($videoEntry, $url='http://gdata.youtube.com/action/GetUploadToken')
{
if ($url != null && is_string($url)) {
// $response is a Zend_Http_response object
$response = $this->post($videoEntry, $url);
return self::parseFormUploadTokenResponse($response->getBody());
} else {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_Exception('Url must be provided as a string URL');
}
}
}
Gdata/Kind/EventEntry.php 0000604 00000030062 15071256135 0011267 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* @see Zend_Gdata_Extension_Where
*/
require_once 'Zend/Gdata/Extension/Where.php';
/**
* @see Zend_Gdata_Extension_When
*/
require_once 'Zend/Gdata/Extension/When.php';
/**
* @see Zend_Gdata_Extension_Who
*/
require_once 'Zend/Gdata/Extension/Who.php';
/**
* @see Zend_Gdata_Extension_Recurrence
*/
require_once 'Zend/Gdata/Extension/Recurrence.php';
/**
* @see Zend_Gdata_Extension_EventStatus
*/
require_once 'Zend/Gdata/Extension/EventStatus.php';
/**
* @see Zend_Gdata_Extension_Comments
*/
require_once 'Zend/Gdata/Extension/Comments.php';
/**
* @see Zend_Gdata_Extension_Transparency
*/
require_once 'Zend/Gdata/Extension/Transparency.php';
/**
* @see Zend_Gdata_Extension_Visibility
*/
require_once 'Zend/Gdata/Extension/Visibility.php';
/**
* @see Zend_Gdata_Extension_RecurrenceException
*/
require_once 'Zend/Gdata/Extension/RecurrenceException.php';
/**
* @see Zend_Gdata_Extension_ExtendedProperty
*/
require_once 'Zend/Gdata/Extension/ExtendedProperty.php';
/**
* @see Zend_Gdata_Extension_OriginalEvent
*/
require_once 'Zend/Gdata/Extension/OriginalEvent.php';
/**
* @see Zend_Gdata_Extension_EntryLink
*/
require_once 'Zend/Gdata/Extension/EntryLink.php';
/**
* Data model for the Gdata Event "Kind". Google Calendar has a separate
* EventEntry class which extends this.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Kind_EventEntry extends Zend_Gdata_Entry
{
protected $_who = array();
protected $_when = array();
protected $_where = array();
protected $_recurrence = null;
protected $_eventStatus = null;
protected $_comments = null;
protected $_transparency = null;
protected $_visibility = null;
protected $_recurrenceException = array();
protected $_extendedProperty = array();
protected $_originalEvent = null;
protected $_entryLink = null;
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_who != null) {
foreach ($this->_who as $who) {
$element->appendChild($who->getDOM($element->ownerDocument));
}
}
if ($this->_when != null) {
foreach ($this->_when as $when) {
$element->appendChild($when->getDOM($element->ownerDocument));
}
}
if ($this->_where != null) {
foreach ($this->_where as $where) {
$element->appendChild($where->getDOM($element->ownerDocument));
}
}
if ($this->_recurrenceException != null) {
foreach ($this->_recurrenceException as $recurrenceException) {
$element->appendChild($recurrenceException->getDOM($element->ownerDocument));
}
}
if ($this->_extendedProperty != null) {
foreach ($this->_extendedProperty as $extProp) {
$element->appendChild($extProp->getDOM($element->ownerDocument));
}
}
if ($this->_recurrence != null) {
$element->appendChild($this->_recurrence->getDOM($element->ownerDocument));
}
if ($this->_eventStatus != null) {
$element->appendChild($this->_eventStatus->getDOM($element->ownerDocument));
}
if ($this->_comments != null) {
$element->appendChild($this->_comments->getDOM($element->ownerDocument));
}
if ($this->_transparency != null) {
$element->appendChild($this->_transparency->getDOM($element->ownerDocument));
}
if ($this->_visibility != null) {
$element->appendChild($this->_visibility->getDOM($element->ownerDocument));
}
if ($this->_originalEvent != null) {
$element->appendChild($this->_originalEvent->getDOM($element->ownerDocument));
}
if ($this->_entryLink != null) {
$element->appendChild($this->_entryLink->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'where';
$where = new Zend_Gdata_Extension_Where();
$where->transferFromDOM($child);
$this->_where[] = $where;
break;
case $this->lookupNamespace('gd') . ':' . 'when';
$when = new Zend_Gdata_Extension_When();
$when->transferFromDOM($child);
$this->_when[] = $when;
break;
case $this->lookupNamespace('gd') . ':' . 'who';
$who = new Zend_Gdata_Extension_Who();
$who ->transferFromDOM($child);
$this->_who[] = $who;
break;
case $this->lookupNamespace('gd') . ':' . 'recurrence';
$recurrence = new Zend_Gdata_Extension_Recurrence();
$recurrence->transferFromDOM($child);
$this->_recurrence = $recurrence;
break;
case $this->lookupNamespace('gd') . ':' . 'eventStatus';
$eventStatus = new Zend_Gdata_Extension_EventStatus();
$eventStatus->transferFromDOM($child);
$this->_eventStatus = $eventStatus;
break;
case $this->lookupNamespace('gd') . ':' . 'comments';
$comments = new Zend_Gdata_Extension_Comments();
$comments->transferFromDOM($child);
$this->_comments = $comments;
break;
case $this->lookupNamespace('gd') . ':' . 'transparency';
$transparency = new Zend_Gdata_Extension_Transparency();
$transparency ->transferFromDOM($child);
$this->_transparency = $transparency;
break;
case $this->lookupNamespace('gd') . ':' . 'visibility';
$visiblity = new Zend_Gdata_Extension_Visibility();
$visiblity ->transferFromDOM($child);
$this->_visibility = $visiblity;
break;
case $this->lookupNamespace('gd') . ':' . 'recurrenceException';
$recurrenceException = new Zend_Gdata_Extension_RecurrenceException();
$recurrenceException ->transferFromDOM($child);
$this->_recurrenceException[] = $recurrenceException;
break;
case $this->lookupNamespace('gd') . ':' . 'originalEvent';
$originalEvent = new Zend_Gdata_Extension_OriginalEvent();
$originalEvent ->transferFromDOM($child);
$this->_originalEvent = $originalEvent;
break;
case $this->lookupNamespace('gd') . ':' . 'extendedProperty';
$extProp = new Zend_Gdata_Extension_ExtendedProperty();
$extProp->transferFromDOM($child);
$this->_extendedProperty[] = $extProp;
break;
case $this->lookupNamespace('gd') . ':' . 'entryLink':
$entryLink = new Zend_Gdata_Extension_EntryLink();
$entryLink->transferFromDOM($child);
$this->_entryLink = $entryLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getWhen()
{
return $this->_when;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setWhen($value)
{
$this->_when = $value;
return $this;
}
public function getWhere()
{
return $this->_where;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setWhere($value)
{
$this->_where = $value;
return $this;
}
public function getWho()
{
return $this->_who;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setWho($value)
{
$this->_who = $value;
return $this;
}
public function getRecurrence()
{
return $this->_recurrence;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setRecurrence($value)
{
$this->_recurrence = $value;
return $this;
}
public function getEventStatus()
{
return $this->_eventStatus;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setEventStatus($value)
{
$this->_eventStatus = $value;
return $this;
}
public function getComments()
{
return $this->_comments;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setComments($value)
{
$this->_comments = $value;
return $this;
}
public function getTransparency()
{
return $this->_transparency;
}
/**
* @param Zend_Gdata_Transparency $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setTransparency($value)
{
$this->_transparency = $value;
return $this;
}
public function getVisibility()
{
return $this->_visibility;
}
/**
* @param Zend_Gdata_Visibility $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
public function getRecurrenceExcption()
{
return $this->_recurrenceException;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setRecurrenceException($value)
{
$this->_recurrenceException = $value;
return $this;
}
public function getExtendedProperty()
{
return $this->_extendedProperty;
}
/**
* @param array $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setExtendedProperty($value)
{
$this->_extendedProperty = $value;
return $this;
}
public function getOriginalEvent()
{
return $this->_originalEvent;
}
/**
* @param Zend_Gdata_Extension_OriginalEvent $value
* @return Zend_Gdata_Kind_EventEntry Provides a fluent interface
*/
public function setOriginalEvent($value)
{
$this->_originalEvent = $value;
return $this;
}
/**
* Get this entry's EntryLink element.
*
* @return Zend_Gdata_Extension_EntryLink The requested entry.
*/
public function getEntryLink()
{
return $this->_entryLink;
}
/**
* Set the child's EntryLink element.
*
* @param Zend_Gdata_Extension_EntryLink $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setEntryLink($value)
{
$this->_entryLink = $value;
return $this;
}
}
Gdata/Exif.php 0000604 00000003666 15071256135 0007204 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* Service class for interacting with the services which use the EXIF extensions
* @link http://code.google.com/apis/picasaweb/reference.html#exif_reference
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif extends Zend_Gdata
{
/**
* Namespaces used for Zend_Gdata_Exif
*
* @var array
*/
public static $namespaces = array(
array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0)
);
/**
* Create Zend_Gdata_Exif object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Exif');
$this->registerPackage('Zend_Gdata_Exif_Extension');
parent::__construct($client, $applicationId);
}
}
Gdata/Gapps/EmailListFeed.php 0000604 00000003025 15071256135 0012017 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Gapps_EmailListEntry
*/
require_once 'Zend/Gdata/Gapps/EmailListEntry.php';
/**
* Data model for a collection of Google Apps email list entries, usually
* provided by the Google Apps servers.
*
* For information on requesting this feed from a server, see the Google
* Apps service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListFeed extends Zend_Gdata_Feed
{
protected $_entryClassName = 'Zend_Gdata_Gapps_EmailListEntry';
protected $_feedClassName = 'Zend_Gdata_Gapps_EmailListFeed';
}
Gdata/Gapps/ServiceException.php 0000604 00000015441 15071256135 0012634 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Zend_Gdata_Gapps_Error
*/
require_once 'Zend/Gdata/Gapps/Error.php';
/**
* Gdata Gapps Exception class. This is thrown when an
* AppsForYourDomainErrors message is received from the Google Apps
* servers.
*
* Several different errors may be represented by this exception. For a list
* of error codes available, see getErrorCode.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_ServiceException extends Zend_Exception
{
protected $_rootElement = "AppsForYourDomainErrors";
/**
* Array of Zend_Gdata_Error objects indexed by error code.
*
* @var array
*/
protected $_errors = array();
/**
* Create a new ServiceException.
*
* @return array An array containing a collection of
* Zend_Gdata_Gapps_Error objects.
*/
public function __construct($errors = null) {
parent::__construct("Server errors encountered");
if ($errors !== null) {
$this->setErrors($errors);
}
}
/**
* Add a single Error object to the list of errors received by the
* server.
*
* @param Zend_Gdata_Gapps_Error $error An instance of an error returned
* by the server. The error's errorCode must be set.
* @throws Zend_Gdata_App_Exception
*/
public function addError($error) {
// Make sure that we don't try to index an error that doesn't
// contain an index value.
if ($error->getErrorCode() == null) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("Error encountered without corresponding error code.");
}
$this->_errors[$error->getErrorCode()] = $error;
}
/**
* Set the list of errors as sent by the server inside of an
* AppsForYourDomainErrors tag.
*
* @param array $array An associative array containing a collection of
* Zend_Gdata_Gapps_Error objects. All errors must have their
* errorCode value set.
* @throws Zend_Gdata_App_Exception
*/
public function setErrors($array) {
$this->_errors = array();
foreach ($array as $error) {
$this->addError($error);
}
}
/**
* Get the list of errors as sent by the server inside of an
* AppsForYourDomainErrors tag.
*
* @return array An associative array containing a collection of
* Zend_Gdata_Gapps_Error objects, indexed by error code.
*/
public function getErrors() {
return $this->_errors;
}
/**
* Return the Error object associated with a specific error code.
*
* @return Zend_Gdata_Gapps_Error The Error object requested, or null
* if not found.
*/
public function getError($errorCode) {
if (array_key_exists($errorCode, $this->_errors)) {
$result = $this->_errors[$errorCode];
return $result;
} else {
return null;
}
}
/**
* Check whether or not a particular error code was returned by the
* server.
*
* @param integer $errorCode The error code to check against.
* @return boolean Whether or not the supplied error code was returned
* by the server.
*/
public function hasError($errorCode) {
return array_key_exists($errorCode, $this->_errors);
}
/**
* Import an AppsForYourDomain error from XML.
*
* @param string $string The XML data to be imported
* @return Zend_Gdata_Gapps_ServiceException Provides a fluent interface.
* @throws Zend_Gdata_App_Exception
*/
public function importFromString($string) {
if ($string) {
// Check to see if an AppsForYourDomainError exists
//
// track_errors is temporarily enabled so that if an error
// occurs while parsing the XML we can append it to an
// exception by referencing $php_errormsg
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($string);
@ini_restore('track_errors');
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
// $php_errormsg is automatically generated by PHP if
// an error occurs while calling loadXML(), above.
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
// Ensure that the outermost node is an AppsForYourDomain error.
// If it isn't, something has gone horribly wrong.
$rootElement = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$rootElement) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
foreach ($rootElement->childNodes as $errorNode) {
if (!($errorNode instanceof DOMText)) {
$error = new Zend_Gdata_Gapps_Error();
$error->transferFromDom($errorNode);
$this->addError($error);
}
}
return $this;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
}
}
/**
* Get a human readable version of this exception.
*
* @return string
*/
public function __toString() {
$result = "The server encountered the following errors processing the request:";
foreach ($this->_errors as $error) {
$result .= "\n" . $error->__toString();
}
return $result;
}
}
Gdata/Gapps/EmailListRecipientFeed.php 0000604 00000003114 15071256135 0013661 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Gapps_EmailListRecipientEntry
*/
require_once 'Zend/Gdata/Gapps/EmailListRecipientEntry.php';
/**
* Data model for a collection of Google Apps email list recipient entries,
* usually provided by the Google Apps servers.
*
* For information on requesting this feed from a server, see the Google
* Apps service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListRecipientFeed extends Zend_Gdata_Feed
{
protected $_entryClassName = 'Zend_Gdata_Gapps_EmailListRecipientEntry';
protected $_feedClassName = 'Zend_Gdata_Gapps_EmailListRecipientFeed';
}
Gdata/Gapps/NicknameFeed.php 0000604 00000003016 15071256135 0011661 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Gapps_NicknameEntry
*/
require_once 'Zend/Gdata/Gapps/NicknameEntry.php';
/**
* Data model for a collection of Google Apps nickname entries, usually
* provided by the Google Apps servers.
*
* For information on requesting this feed from a server, see the Google
* Apps service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_NicknameFeed extends Zend_Gdata_Feed
{
protected $_entryClassName = 'Zend_Gdata_Gapps_NicknameEntry';
protected $_feedClassName = 'Zend_Gdata_Gapps_NicknameFeed';
}
Gdata/Gapps/Extension/Login.php 0000604 00000041412 15071256135 0012376 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* Represents the apps:login element used by the Apps data API. This
* class is used to describe properties of a user, and is usually contained
* within instances of Zene_Gdata_Gapps_UserEntry or any other class
* which is linked to a particular username.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Extension_Login extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'apps';
protected $_rootElement = 'login';
/**
* The username for this user. This is used as the user's email address
* and when logging in to Google Apps-hosted services.
*
* @var string
*/
protected $_username = null;
/**
* The password for the user. May be in cleartext or as an SHA-1
* digest, depending on the value of _hashFunctionName.
*
* @var string
*/
protected $_password = null;
/**
* Specifies whether the password stored in _password is in cleartext
* or is an SHA-1 digest of a password. If the password is cleartext,
* then this should be null. If the password is an SHA-1 digest, then
* this should be set to 'SHA-1'.
*
* At the time of writing, no other hash functions are supported
*
* @var string
*/
protected $_hashFunctionName = null;
/**
* True if the user has administrative rights for this domain, false
* otherwise.
*
* @var boolean
*/
protected $_admin = null;
/**
* True if the user has agreed to the terms of service for Google Apps,
* false otherwise.
*
* @var boolean.
*/
protected $_agreedToTerms = null;
/**
* True if this user has been suspended, false otherwise.
*
* @var boolean
*/
protected $_suspended = null;
/**
* True if the user will be required to change their password at
* their next login, false otherwise.
*
* @var boolean
*/
protected $_changePasswordAtNextLogin = null;
/**
* Constructs a new Zend_Gdata_Gapps_Extension_Login object.
*
* @param string $username (optional) The username to be used for this
* login.
* @param string $password (optional) The password to be used for this
* login.
* @param string $hashFunctionName (optional) The name of the hash
* function used to protect the password, or null if no
* has function has been applied. As of this writing,
* the only valid values are 'SHA-1' or null.
* @param boolean $admin (optional) Whether the user is an administrator
* or not.
* @param boolean $suspended (optional) Whether this login is suspended or not.
* @param boolean $changePasswordAtNextLogin (optional) Whether
* the user is required to change their password at their
* next login.
* @param boolean $agreedToTerms (optional) Whether the user has
* agreed to the terms of service.
*/
public function __construct($username = null, $password = null,
$hashFunctionName = null, $admin = null, $suspended = null,
$changePasswordAtNextLogin = null, $agreedToTerms = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct();
$this->_username = $username;
$this->_password = $password;
$this->_hashFunctionName = $hashFunctionName;
$this->_admin = $admin;
$this->_agreedToTerms = $agreedToTerms;
$this->_suspended = $suspended;
$this->_changePasswordAtNextLogin = $changePasswordAtNextLogin;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_username !== null) {
$element->setAttribute('userName', $this->_username);
}
if ($this->_password !== null) {
$element->setAttribute('password', $this->_password);
}
if ($this->_hashFunctionName !== null) {
$element->setAttribute('hashFunctionName', $this->_hashFunctionName);
}
if ($this->_admin !== null) {
$element->setAttribute('admin', ($this->_admin ? "true" : "false"));
}
if ($this->_agreedToTerms !== null) {
$element->setAttribute('agreedToTerms', ($this->_agreedToTerms ? "true" : "false"));
}
if ($this->_suspended !== null) {
$element->setAttribute('suspended', ($this->_suspended ? "true" : "false"));
}
if ($this->_changePasswordAtNextLogin !== null) {
$element->setAttribute('changePasswordAtNextLogin', ($this->_changePasswordAtNextLogin ? "true" : "false"));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
* @throws Zend_Gdata_App_InvalidArgumentException
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'userName':
$this->_username = $attribute->nodeValue;
break;
case 'password':
$this->_password = $attribute->nodeValue;
break;
case 'hashFunctionName':
$this->_hashFunctionName = $attribute->nodeValue;
break;
case 'admin':
if ($attribute->nodeValue == "true") {
$this->_admin = true;
}
else if ($attribute->nodeValue == "false") {
$this->_admin = false;
}
else {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#admin.");
}
break;
case 'agreedToTerms':
if ($attribute->nodeValue == "true") {
$this->_agreedToTerms = true;
}
else if ($attribute->nodeValue == "false") {
$this->_agreedToTerms = false;
}
else {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#agreedToTerms.");
}
break;
case 'suspended':
if ($attribute->nodeValue == "true") {
$this->_suspended = true;
}
else if ($attribute->nodeValue == "false") {
$this->_suspended = false;
}
else {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#suspended.");
}
break;
case 'changePasswordAtNextLogin':
if ($attribute->nodeValue == "true") {
$this->_changePasswordAtNextLogin = true;
}
else if ($attribute->nodeValue == "false") {
$this->_changePasswordAtNextLogin = false;
}
else {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for apps:login#changePasswordAtNextLogin.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's username attribute.
*
* @see setUsername
* @return string The attribute being modified.
*/
public function getUsername()
{
return $this->_username;
}
/**
* Set the value for this element's username attribute. This string
* is used to uniquely identify the user in this domian and is used
* to form this user's email address.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
*/
public function setUsername($value)
{
$this->_username = $value;
return $this;
}
/**
* Get the value for this element's password attribute.
*
* @see setPassword
* @return string The requested attribute.
*/
public function getPassword()
{
return $this->_password;
}
/**
* Set the value for this element's password attribute. As of this
* writing, this can be either be provided as plaintext or hashed using
* the SHA-1 algorithm for protection. If using a hash function,
* this must be indicated by calling setHashFunctionName().
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
*/
public function setPassword($value)
{
$this->_password = $value;
return $this;
}
/**
* Get the value for this element's hashFunctionName attribute.
*
* @see setHashFunctionName
* @return string The requested attribute.
*/
public function getHashFunctionName()
{
return $this->_hashFunctionName;
}
/**
* Set the value for this element's hashFunctionName attribute. This
* indicates whether the password supplied with setPassword() is in
* plaintext or has had a hash function applied to it. If null,
* plaintext is assumed. As of this writing, the only valid hash
* function is 'SHA-1'.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
*/
public function setHashFunctionName($value)
{
$this->_hashFunctionName = $value;
return $this;
}
/**
* Get the value for this element's admin attribute.
*
* @see setAdmin
* @return boolean The requested attribute.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getAdmin()
{
if (!(is_bool($this->_admin))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for admin.');
}
return $this->_admin;
}
/**
* Set the value for this element's admin attribute. This indicates
* whether this user is an administrator for this domain.
*
* @param boolean $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setAdmin($value)
{
if (!(is_bool($value))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
}
$this->_admin = $value;
return $this;
}
/**
* Get the value for this element's agreedToTerms attribute.
*
* @see setAgreedToTerms
* @return boolean The requested attribute.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getAgreedToTerms()
{
if (!(is_bool($this->_agreedToTerms))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for agreedToTerms.');
}
return $this->_agreedToTerms;
}
/**
* Set the value for this element's agreedToTerms attribute. This
* indicates whether this user has agreed to the terms of service.
*
* @param boolean $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setAgreedToTerms($value)
{
if (!(is_bool($value))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
}
$this->_agreedToTerms = $value;
return $this;
}
/**
* Get the value for this element's suspended attribute.
*
* @see setSuspended
* @return boolean The requested attribute.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getSuspended()
{
if (!(is_bool($this->_suspended))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for suspended.');
}
return $this->_suspended;
}
/**
* Set the value for this element's suspended attribute. If true, the
* user will not be able to login to this domain until unsuspended.
*
* @param boolean $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setSuspended($value)
{
if (!(is_bool($value))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
}
$this->_suspended = $value;
return $this;
}
/**
* Get the value for this element's changePasswordAtNextLogin attribute.
*
* @see setChangePasswordAtNextLogin
* @return boolean The requested attribute.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getChangePasswordAtNextLogin()
{
if (!(is_bool($this->_changePasswordAtNextLogin))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for changePasswordAtNextLogin.');
}
return $this->_changePasswordAtNextLogin;
}
/**
* Set the value for this element's changePasswordAtNextLogin attribute.
* If true, the user will be forced to set a new password the next
* time they login.
*
* @param boolean $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Login Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setChangePasswordAtNextLogin($value)
{
if (!(is_bool($value))) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException('Expected boolean for $value.');
}
$this->_changePasswordAtNextLogin = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return "Username: " . $this->getUsername() .
"\nPassword: " . (is_null($this->getPassword()) ? "NOT SET" : "SET") .
"\nPassword Hash Function: " . $this->getHashFunctionName() .
"\nAdministrator: " . ($this->getAdmin() ? "Yes" : "No") .
"\nAgreed To Terms: " . ($this->getAgreedToTerms() ? "Yes" : "No") .
"\nSuspended: " . ($this->getSuspended() ? "Yes" : "No");
}
}
Gdata/Gapps/Extension/Nickname.php 0000604 00000010146 15071256135 0013053 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* Represents the apps:nickname element used by the Apps data API. This
* is used to describe a nickname's properties, and is usually contained
* within instances of Zend_Gdata_Gapps_NicknameEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Extension_Nickname extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'apps';
protected $_rootElement = 'nickname';
/**
* The name of the nickname. This name is used as the email address
* for this nickname.
*
* @var string
*/
protected $_name = null;
/**
* Constructs a new Zend_Gdata_Gapps_Extension_Nickname object.
* @param string $name (optional) The nickname being represented.
*/
public function __construct($name = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct();
$this->_name = $name;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_name !== null) {
$element->setAttribute('name', $this->_name);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'name':
$this->_name = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's name attribute.
*
* @see setName
* @return string The requested attribute.
*/
public function getName()
{
return $this->_name;
}
/**
* Set the value for this element's name attribute. This name uniquely
* describes this nickname within the domain. Emails addressed to this
* name will be delivered to the user who owns this nickname.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Nickname Provides a fluent
* interface.
*/
public function setName($value)
{
$this->_name = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getName();
}
}
Gdata/Gapps/Extension/Name.php 0000604 00000012237 15071256135 0012211 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* Represents the apps:name element used by the Apps data API. This is used
* to represent a user's full name. This class is usually contained within
* instances of Zend_Gdata_Gapps_UserEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Extension_Name extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'apps';
protected $_rootElement = 'name';
/**
* The associated user's family name.
*
* @var string
*/
protected $_familyName = null;
/**
* The associated user's given name.
*
* @var string
*/
protected $_givenName = null;
/**
* Constructs a new Zend_Gdata_Gapps_Extension_Name object.
*
* @param string $familyName (optional) The familyName to be set for this
* object.
* @param string $givenName (optional) The givenName to be set for this
* object.
*/
public function __construct($familyName = null, $givenName = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct();
$this->_familyName = $familyName;
$this->_givenName = $givenName;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_familyName !== null) {
$element->setAttribute('familyName', $this->_familyName);
}
if ($this->_givenName !== null) {
$element->setAttribute('givenName', $this->_givenName);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'familyName':
$this->_familyName = $attribute->nodeValue;
break;
case 'givenName':
$this->_givenName = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's familyName attribute.
*
* @see setFamilyName
* @return string The requested attribute.
*/
public function getFamilyName()
{
return $this->_familyName;
}
/**
* Set the value for this element's familyName attribute. This
* represents a user's family name.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface..
*/
public function setFamilyName($value)
{
$this->_familyName = $value;
return $this;
}
/**
* Get the value for this element's givenName attribute.
*
* @see setGivenName
* @return string The requested attribute.
*/
public function getGivenName()
{
return $this->_givenName;
}
/**
* Set the value for this element's givenName attribute. This
* represents a user's given name.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface.
*/
public function setGivenName($value)
{
$this->_givenName = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getGivenName() . ' ' . $this->getFamilyName();
}
}
Gdata/Gapps/Extension/Quota.php 0000604 00000010176 15071256135 0012422 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* Represents the apps:quota element used by the Apps data API. This is
* used to indicate the amount of storage space available to a user. Quotas
* may not be able to be set, depending on the domain used. This class
* is usually contained within an instance of Zend_Gdata_Gapps_UserEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Extension_Quota extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'apps';
protected $_rootElement = 'quota';
/**
* The amount of storage space available to the user in megabytes.
*
* @var integer
*/
protected $_limit = null;
/**
* Constructs a new Zend_Gdata_Gapps_Extension_Quota object.
*
* @param string $limit (optional) The limit, in bytes, for this quota.
*/
public function __construct($limit = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct();
$this->_limit = $limit;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_limit !== null) {
$element->setAttribute('limit', $this->_limit);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'limit':
$this->_limit = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's limit attribute.
*
* @see setLimit
* @return string The requested attribute.
*/
public function getLimit()
{
return $this->_limit;
}
/**
* Set the value for this element's limit attribute. This is the amount
* of storage space, in bytes, that should be made available to
* the associated user.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_Quota Provides a fluent interface.
*/
public function setLimit($value)
{
$this->_limit = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getLimit();
}
}
Gdata/Gapps/Extension/EmailList.php 0000604 00000010213 15071256135 0013204 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* Represents the apps:emailList element used by the Apps data API. This
* class represents properties of an email list and is usually contained
* within an instance of Zend_Gdata_Gapps_EmailListEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Extension_EmailList extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'apps';
protected $_rootElement = 'emailList';
/**
* The name of the email list. This name is used as the email address
* for this list.
*
* @var string
*/
protected $_name = null;
/**
* Constructs a new Zend_Gdata_Gapps_Extension_EmailList object.
*
* @param string $name (optional) The name to be used for this email list.
*/
public function __construct($name = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct();
$this->_name = $name;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_name !== null) {
$element->setAttribute('name', $this->_name);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'name':
$this->_name = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's name attribute.
*
* @see setName
* @return string The requested attribute.
*/
public function getName()
{
return $this->_name;
}
/**
* Set the value for this element's name attribute. This is the unique
* name which will be used to identify this email list within this
* domain, and will be used to form this email list's email address.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Gapps_Extension_EmailList The element being modified.
*/
public function setName($value)
{
$this->_name = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string
*/
public function __toString()
{
return $this->getName();
}
}
Gdata/Gapps/EmailListRecipientQuery.php 0000604 00000011233 15071256135 0014124 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Gapps_Query
*/
require_once('Zend/Gdata/Gapps/Query.php');
/**
* Assists in constructing queries for Google Apps email list recipient
* entries. Instances of this class can be provided in many places where a
* URL is required.
*
* For information on submitting queries to a server, see the Google Apps
* service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListRecipientQuery extends Zend_Gdata_Gapps_Query
{
/**
* If not null, specifies the name of the email list which
* should be requested by this query.
*
* @var string
*/
protected $_emailListName = null;
/**
* Create a new instance.
*
* @param string $domain (optional) The Google Apps-hosted domain to use
* when constructing query URIs.
* @param string $emailListName (optional) Value for the emailListName
* property.
* @param string $startRecipient (optional) Value for the
* startRecipient property.
*/
public function __construct($domain = null, $emailListName = null,
$startRecipient = null)
{
parent::__construct($domain);
$this->setEmailListName($emailListName);
$this->setStartRecipient($startRecipient);
}
/**
* Set the email list name to query for. When set, only lists with a name
* matching this value will be returned in search results. Set to
* null to disable filtering by list name.
*
* @param string $value The email list name to filter search results by,
* or null to disable.
*/
public function setEmailListName($value)
{
$this->_emailListName = $value;
}
/**
* Get the email list name to query for. If no name is set, null will be
* returned.
*
* @param string $value The email list name to filter search results by,
* or null if disabled.
*/
public function getEmailListName()
{
return $this->_emailListName;
}
/**
* Set the first recipient which should be displayed when retrieving
* a list of email list recipients.
*
* @param string $value The first recipient to be returned, or null to
* disable.
*/
public function setStartRecipient($value)
{
if ($value !== null) {
$this->_params['startRecipient'] = $value;
} else {
unset($this->_params['startRecipient']);
}
}
/**
* Get the first recipient which should be displayed when retrieving
* a list of email list recipients.
*
* @return string The first recipient to be returned, or null if
* disabled.
*/
public function getStartRecipient()
{
if (array_key_exists('startRecipient', $this->_params)) {
return $this->_params['startRecipient'];
} else {
return null;
}
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getQueryUrl()
{
$uri = $this->getBaseUrl();
$uri .= Zend_Gdata_Gapps::APPS_EMAIL_LIST_PATH;
if ($this->_emailListName !== null) {
$uri .= '/' . $this->_emailListName;
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'EmailListName must not be null');
}
$uri .= Zend_Gdata_Gapps::APPS_EMAIL_LIST_RECIPIENT_POSTFIX . '/';
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gapps/UserQuery.php 0000604 00000010222 15071256135 0011311 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Gapps_Query
*/
require_once('Zend/Gdata/Gapps/Query.php');
/**
* Assists in constructing queries for Google Apps user entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the Google Apps
* service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_UserQuery extends Zend_Gdata_Gapps_Query
{
/**
* If not null, specifies the username of the user who should be
* retrieved by this query.
*
* @var string
*/
protected $_username = null;
/**
* Create a new instance.
*
* @param string $domain (optional) The Google Apps-hosted domain to use
* when constructing query URIs.
* @param string $username (optional) Value for the username
* property.
* @param string $startUsername (optional) Value for the
* startUsername property.
*/
public function __construct($domain = null, $username = null,
$startUsername = null)
{
parent::__construct($domain);
$this->setUsername($username);
$this->setStartUsername($startUsername);
}
/**
* Set the username to query for. When set, only users with a username
* matching this value will be returned in search results. Set to
* null to disable filtering by username.
*
* @see getUsername
* @param string $value The username to filter search results by, or null to
* disable.
*/
public function setUsername($value)
{
$this->_username = $value;
}
/**
* Get the username to query for. If no username is set, null will be
* returned.
*
* @param string $value The username to filter search results by, or
* null if disabled.
*/
public function getUsername()
{
return $this->_username;
}
/**
* Set the first username which should be displayed when retrieving
* a list of users.
*
* @param string $value The first username to be returned, or null to
* disable.
*/
public function setStartUsername($value)
{
if ($value !== null) {
$this->_params['startUsername'] = $value;
} else {
unset($this->_params['startUsername']);
}
}
/**
* Get the first username which should be displayed when retrieving
* a list of users.
*
* @see setStartUsername
* @return string The first username to be returned, or null if
* disabled.
*/
public function getStartUsername()
{
if (array_key_exists('startUsername', $this->_params)) {
return $this->_params['startUsername'];
} else {
return null;
}
}
/**
* Returns the query URL generated by this query instance.
*
* @return string The query URL for this instance.
*/
public function getQueryUrl()
{
$uri = $this->getBaseUrl();
$uri .= Zend_Gdata_Gapps::APPS_USER_PATH;
if ($this->_username !== null) {
$uri .= '/' . $this->_username;
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gapps/UserFeed.php 0000604 00000002766 15071256135 0011065 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Gapps_UserEntry
*/
require_once 'Zend/Gdata/Gapps/UserEntry.php';
/**
* Data model for a collection of Google Apps user entries, usually
* provided by the Google Apps servers.
*
* For information on requesting this feed from a server, see the Google
* Apps service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_UserFeed extends Zend_Gdata_Feed
{
protected $_entryClassName = 'Zend_Gdata_Gapps_UserEntry';
protected $_feedClassName = 'Zend_Gdata_Gapps_UserFeed';
}
Gdata/Gapps/Query.php 0000604 00000007273 15071256135 0010466 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Zend_Gdata_Gapps
*/
require_once('Zend/Gdata/Gapps.php');
/**
* Assists in constructing queries for Google Apps entries. This class
* provides common methods used by all other Google Apps query classes.
*
* This class should never be instantiated directly. Instead, instantiate a
* class which inherits from this class.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_Gapps_Query extends Zend_Gdata_Query
{
/**
* The domain which is being administered via the Provisioning API.
*
* @var string
*/
protected $_domain = null;
/**
* Create a new instance.
*
* @param string $domain (optional) The Google Apps-hosted domain to use
* when constructing query URIs.
*/
public function __construct($domain = null)
{
parent::__construct();
$this->_domain = $domain;
}
/**
* Set domain for this service instance. This should be a fully qualified
* domain, such as 'foo.example.com'.
*
* This value is used when calculating URLs for retrieving and posting
* entries. If no value is specified, a URL will have to be manually
* constructed prior to using any methods which interact with the Google
* Apps provisioning service.
*
* @param string $value The domain to be used for this session.
*/
public function setDomain($value)
{
$this->_domain = $value;
}
/**
* Get domain for this service instance. This should be a fully qualified
* domain, such as 'foo.example.com'. If no domain is set, null will be
* returned.
*
* @see setDomain
* @return string The domain to be used for this session, or null if not
* set.
*/
public function getDomain()
{
return $this->_domain;
}
/**
* Returns the base URL used to access the Google Apps service, based
* on the current domain. The current domain can be temporarily
* overridden by providing a fully qualified domain as $domain.
*
* @see setDomain
* @param string $domain (optional) A fully-qualified domain to use
* instead of the default domain for this service instance.
*/
public function getBaseUrl($domain = null)
{
if ($domain !== null) {
return Zend_Gdata_Gapps::APPS_BASE_FEED_URI . '/' . $domain;
}
else if ($this->_domain !== null) {
return Zend_Gdata_Gapps::APPS_BASE_FEED_URI . '/' . $this->_domain;
}
else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Domain must be specified.');
}
}
}
Gdata/Gapps/NicknameQuery.php 0000604 00000012500 15071256135 0012121 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Gapps_Query
*/
require_once('Zend/Gdata/Gapps/Query.php');
/**
* Assists in constructing queries for Google Apps nickname entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the Google Apps
* service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_NicknameQuery extends Zend_Gdata_Gapps_Query
{
/**
* If not null, indicates the name of the nickname entry which
* should be returned by this query.
*
* @var string
*/
protected $_nickname = null;
/**
* Create a new instance.
*
* @param string $domain (optional) The Google Apps-hosted domain to use
* when constructing query URIs.
* @param string $nickname (optional) Value for the nickname
* property.
* @param string $username (optional) Value for the username
* property.
* @param string $startNickname (optional) Value for the
* startNickname property.
*/
public function __construct($domain = null, $nickname = null,
$username = null, $startNickname = null)
{
parent::__construct($domain);
$this->setNickname($nickname);
$this->setUsername($username);
$this->setStartNickname($startNickname);
}
/**
* Set the nickname to query for. When set, only users with a nickname
* matching this value will be returned in search results. Set to
* null to disable filtering by username.
*
* @param string $value The nickname to filter search results by, or null
* to disable.
*/
public function setNickname($value)
{
$this->_nickname = $value;
}
/**
* Get the nickname to query for. If no nickname is set, null will be
* returned.
*
* @see setNickname
* @return string The nickname to filter search results by, or null if
* disabled.
*/
public function getNickname()
{
return $this->_nickname;
}
/**
* Set the username to query for. When set, only users with a username
* matching this value will be returned in search results. Set to
* null to disable filtering by username.
*
* @param string $value The username to filter search results by, or null
* to disable.
*/
public function setUsername($value)
{
if ($value !== null) {
$this->_params['username'] = $value;
}
else {
unset($this->_params['username']);
}
}
/**
* Get the username to query for. If no username is set, null will be
* returned.
*
* @see setUsername
* @return string The username to filter search results by, or null if
* disabled.
*/
public function getUsername()
{
if (array_key_exists('username', $this->_params)) {
return $this->_params['username'];
} else {
return null;
}
}
/**
* Set the first nickname which should be displayed when retrieving
* a list of nicknames.
*
* @param string $value The first nickname to be returned, or null to
* disable.
*/
public function setStartNickname($value)
{
if ($value !== null) {
$this->_params['startNickname'] = $value;
} else {
unset($this->_params['startNickname']);
}
}
/**
* Get the first nickname which should be displayed when retrieving
* a list of nicknames.
*
* @return string The first nickname to be returned, or null to
* disable.
*/
public function getStartNickname()
{
if (array_key_exists('startNickname', $this->_params)) {
return $this->_params['startNickname'];
} else {
return null;
}
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
*/
public function getQueryUrl()
{
$uri = $this->getBaseUrl();
$uri .= Zend_Gdata_Gapps::APPS_NICKNAME_PATH;
if ($this->_nickname !== null) {
$uri .= '/' . $this->_nickname;
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gapps/EmailListEntry.php 0000604 00000015623 15071256135 0012264 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_Gapps_Extension_EmailList
*/
require_once 'Zend/Gdata/Gapps/Extension/EmailList.php';
/**
* Data model class for a Google Apps Email List Entry.
*
* Each email list entry describes a single email list within a Google Apps
* hosted domain. Email lists may contain multiple recipients, as
* described by instances of Zend_Gdata_Gapps_EmailListRecipient. Multiple
* entries are contained within instances of Zend_Gdata_Gapps_EmailListFeed.
*
* To transfer email list entries to and from the Google Apps servers,
* including creating new entries, refer to the Google Apps service class,
* Zend_Gdata_Gapps.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Gapps_EmailListEntry';
/**
* <apps:emailList> child element containing general information about
* this email list.
*
* @var Zend_Gdata_Gapps_Extension_EmailList
*/
protected $_emailList = null;
/**
* <gd:feedLink> element containing information about other feeds
* relevant to this entry.
*
* @var Zend_Gdata_Extension_FeedLink
*/
protected $_feedLink = array();
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_emailList !== null) {
$element->appendChild($this->_emailList->getDOM($element->ownerDocument));
}
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('apps') . ':' . 'emailList';
$emailList = new Zend_Gdata_Gapps_Extension_EmailList();
$emailList->transferFromDOM($child);
$this->_emailList = $emailList;
break;
case $this->lookupNamespace('gd') . ':' . 'feedLink';
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Retrieve the email list property for this entry.
*
* @see setEmailList
* @return Zend_Gdata_Gapps_Extension_EmailList The requested object
* or null if not set.
*/
public function getEmailList()
{
return $this->_emailList;
}
/**
* Set the email list property for this entry. This property contains
* information such as the name of this email list.
*
* This corresponds to the <apps:emailList> property in the Google Data
* protocol.
*
* @param Zend_Gdata_Gapps_Extension_EmailList $value The desired value
* this element, or null to unset.
* @return Zend_Gdata_Gapps_EventEntry Provides a fluent interface
*/
public function setEmailList($value)
{
$this->_emailList = $value;
return $this;
}
/**
* Get the feed link property for this entry.
*
* @see setFeedLink
* @param string $rel (optional) The rel value of the link to be found.
* If null, the array of links is returned.
* @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
* object corresponding to the requested rel value is returned
* if found, or null if the requested value is not found. If
* $rel is null or not specified, an array of all available
* feed links for this entry is returned, or null if no feed
* links are set.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Set the feed link property for this entry. Feed links provide
* information about other feeds associated with this entry.
*
* This corresponds to the <gd:feedLink> property in the Google Data
* protocol.
*
* @param array $value A collection of Zend_Gdata_Gapps_Extension_FeedLink
* instances representing all feed links for this entry, or
* null to unset.
* @return Zend_Gdata_Gapps_EventEntry Provides a fluent interface
*/
public function setFeedLink($value)
{
$this->_feedLink = $value;
return $this;
}
}
Gdata/Gapps/Error.php 0000604 00000017314 15071256135 0010447 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Base
*/
require_once 'Zend/Gdata/App/Base.php';
/**
* Gdata Gapps Error class. This class is used to represent errors returned
* within an AppsForYourDomainErrors message received from the Google Apps
* servers.
*
* Several different errors may be represented by this class, determined by
* the error code returned by the server. For a list of error codes
* available at the time of this writing, see getErrorCode.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_Error extends Zend_Gdata_App_Base
{
// Error codes as defined at
// http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d
const UNKNOWN_ERROR = 1000;
const USER_DELETED_RECENTLY = 1100;
const USER_SUSPENDED = 1101;
const DOMAIN_USER_LIMIT_EXCEEDED = 1200;
const DOMAIN_ALIAS_LIMIT_EXCEEDED = 1201;
const DOMAIN_SUSPENDED = 1202;
const DOMAIN_FEATURE_UNAVAILABLE = 1203;
const ENTITY_EXISTS = 1300;
const ENTITY_DOES_NOT_EXIST = 1301;
const ENTITY_NAME_IS_RESERVED = 1302;
const ENTITY_NAME_NOT_VALID = 1303;
const INVALID_GIVEN_NAME = 1400;
const INVALID_FAMILY_NAME = 1401;
const INVALID_PASSWORD = 1402;
const INVALID_USERNAME = 1403;
const INVALID_HASH_FUNCTION_NAME = 1404;
const INVALID_HASH_DIGEST_LENGTH = 1405;
const INVALID_EMAIL_ADDRESS = 1406;
const INVALID_QUERY_PARAMETER_VALUE = 1407;
const TOO_MANY_RECIPIENTS_ON_EMAIL_LIST = 1500;
protected $_errorCode = null;
protected $_reason = null;
protected $_invalidInput = null;
public function __construct($errorCode = null, $reason = null,
$invalidInput = null) {
parent::__construct("Google Apps error received: $errorCode ($reason)");
$this->_errorCode = $errorCode;
$this->_reason = $reason;
$this->_invalidInput = $invalidInput;
}
/**
* Set the error code for this exception. For more information about
* error codes, see getErrorCode.
*
* @see getErrorCode
* @param integer $value The new value for the error code.
*/
public function setErrorCode($value) {
$this->_errorCode = $value;
}
/**
* Get the error code for this exception. Currently valid values are
* available as constants within this class. These values are:
*
* UNKNOWN_ERROR (1000)
* USER_DELETED_RECENTLY (1100)
* USER_SUSPENDED (1101)
* DOMAIN_USER_LIMIT_EXCEEDED (1200)
* DOMAIN_ALIAS_LIMIT_EXCEEDED (1201)
* DOMAIN_SUSPENDED (1202)
* DOMAIN_FEATURE_UNAVAILABLE (1203)
* ENTITY_EXISTS (1300)
* ENTITY_DOES_NOT_EXIST (1301)
* ENTITY_NAME_IS_RESERVED (1302)
* ENTITY_NAME_NOT_VALID (1303)
* INVALID_GIVEN_NAME (1400)
* INVALID_FAMILY_NAME (1401)
* INVALID_PASSWORD (1402)
* INVALID_USERNAME (1403)
* INVALID_HASH_FUNCTION_NAME (1404)
* INVALID_HASH_DIGEST_LENGTH (1405)
* INVALID_EMAIL_ADDRESS (1406)
* INVALID_QUERY_PARAMETER_VALUE (1407)
* TOO_MANY_RECIPIENTS_ON_EMAIL_LIST (1500)
*
* Numbers in parenthesis indicate the actual integer value of the
* constant. This list should not be treated as exhaustive, as additional
* error codes may be added at any time.
*
* For more information about these codes and their meaning, please
* see Appendix D of the Google Apps Provisioning API Reference.
*
* @link http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d Google Apps Provisioning API Reference: Appendix D - Gdata Error Codes
* @see setErrorCode
* @return integer The error code returned by the Google Apps server.
*/
public function getErrorCode() {
return $this->_errorCode;
}
/**
* Set human-readable text describing the reason this exception occurred.
*
* @see getReason
* @param string $value The reason this exception occurred.
*/
public function setReason($value) {
$this->_reason = $value;
}
/**
* Get human-readable text describing the reason this exception occurred.
*
* @see setReason
* @return string The reason this exception occurred.
*/
public function getReason() {
return $this->_reason;
}
/**
* Set the invalid input which caused this exception.
*
* @see getInvalidInput
* @param string $value The invalid input that triggered this exception.
*/
public function setInvalidInput($value) {
$this->_invalidInput = $value;
}
/**
* Set the invalid input which caused this exception.
*
* @see setInvalidInput
* @return string The reason this exception occurred.
*/
public function getInvalidInput() {
return $this->_invalidInput;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_errorCode !== null) {
$element->setAttribute('errorCode', $this->_errorCode);
}
if ($this->_reason !== null) {
$element->setAttribute('reason', $this->_reason);
}
if ($this->_invalidInput !== null) {
$element->setAttribute('invalidInput', $this->_invalidInput);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'errorCode':
$this->_errorCode = $attribute->nodeValue;
break;
case 'reason':
$this->_reason = $attribute->nodeValue;
break;
case 'invalidInput':
$this->_invalidInput = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get a human readable version of this exception.
*
* @return string
*/
public function __toString() {
return "Error " . $this->getErrorCode() . ": " . $this->getReason() .
"\n\tInvalid Input: \"" . $this->getInvalidInput() . "\"";
}
}
Gdata/Gapps/EmailListQuery.php 0000604 00000013134 15071256135 0012263 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Gapps_Query
*/
require_once('Zend/Gdata/Gapps/Query.php');
/**
* Assists in constructing queries for Google Apps email list entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the Google Apps
* service class, Zend_Gdata_Gapps.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListQuery extends Zend_Gdata_Gapps_Query
{
/**
* A string which, if not null, indicates which email list should
* be retrieved by this query.
*
* @var string
*/
protected $_emailListName = null;
/**
* Create a new instance.
*
* @param string $domain (optional) The Google Apps-hosted domain to use
* when constructing query URIs.
* @param string $emailListName (optional) Value for the emailListName
* property.
* @param string $recipient (optional) Value for the recipient
* property.
* @param string $startEmailListName (optional) Value for the
* startEmailListName property.
*/
public function __construct($domain = null, $emailListName = null,
$recipient = null, $startEmailListName = null)
{
parent::__construct($domain);
$this->setEmailListName($emailListName);
$this->setRecipient($recipient);
$this->setStartEmailListName($startEmailListName);
}
/**
* Set the email list name to query for. When set, only lists with a name
* matching this value will be returned in search results. Set to
* null to disable filtering by list name.
*
* @param string $value The email list name to filter search results by,
* or null to disable.
*/
public function setEmailListName($value)
{
$this->_emailListName = $value;
}
/**
* Get the email list name to query for. If no name is set, null will be
* returned.
*
* @see setEmailListName
* @return string The email list name to filter search results by, or null
* if disabled.
*/
public function getEmailListName()
{
return $this->_emailListName;
}
/**
* Set the recipient to query for. When set, only subscribers with an
* email address matching this value will be returned in search results.
* Set to null to disable filtering by username.
*
* @param string $value The recipient email address to filter search
* results by, or null to disable.
*/
public function setRecipient($value)
{
if ($value !== null) {
$this->_params['recipient'] = $value;
}
else {
unset($this->_params['recipient']);
}
}
/**
* Get the recipient email address to query for. If no recipient is set,
* null will be returned.
*
* @see setRecipient
* @return string The recipient email address to filter search results by,
* or null if disabled.
*/
public function getRecipient()
{
if (array_key_exists('recipient', $this->_params)) {
return $this->_params['recipient'];
} else {
return null;
}
}
/**
* Set the first email list which should be displayed when retrieving
* a list of email lists.
*
* @param string $value The first email list to be returned, or null to
* disable.
*/
public function setStartEmailListName($value)
{
if ($value !== null) {
$this->_params['startEmailListName'] = $value;
} else {
unset($this->_params['startEmailListName']);
}
}
/**
* Get the first email list which should be displayed when retrieving
* a list of email lists.
*
* @return string The first email list to be returned, or null to
* disable.
*/
public function getStartEmailListName()
{
if (array_key_exists('startEmailListName', $this->_params)) {
return $this->_params['startEmailListName'];
} else {
return null;
}
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getQueryUrl()
{
$uri = $this->getBaseUrl();
$uri .= Zend_Gdata_Gapps::APPS_EMAIL_LIST_PATH;
if ($this->_emailListName !== null) {
$uri .= '/' . $this->_emailListName;
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gapps/NicknameEntry.php 0000604 00000013532 15071256135 0012123 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Gapps_Extension_Login
*/
require_once 'Zend/Gdata/Gapps/Extension/Login.php';
/**
* @see Zend_Gdata_Gapps_Extension_Nickname
*/
require_once 'Zend/Gdata/Gapps/Extension/Nickname.php';
/**
* Data model class for a Google Apps Nickname Entry.
*
* Each nickname entry describes a single nickname within a Google Apps
* hosted domain. Each user may own several nicknames, but each nickname may
* only belong to one user. Multiple entries are contained within instances
* of Zend_Gdata_Gapps_NicknameFeed.
*
* To transfer nickname entries to and from the Google Apps servers,
* including creating new entries, refer to the Google Apps service class,
* Zend_Gdata_Gapps.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_NicknameEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Gapps_NicknameEntry';
/**
* <apps:login> element used to hold information about the owner
* of this nickname, including their username.
*
* @var Zend_Gdata_Gapps_Extension_Login
*/
protected $_login = null;
/**
* <apps:nickname> element used to hold the name of this nickname.
*
* @var Zend_Gdata_Gapps_Extension_Nickname
*/
protected $_nickname = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_login !== null) {
$element->appendChild($this->_login->getDOM($element->ownerDocument));
}
if ($this->_nickname !== null) {
$element->appendChild($this->_nickname->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('apps') . ':' . 'login';
$login = new Zend_Gdata_Gapps_Extension_Login();
$login->transferFromDOM($child);
$this->_login = $login;
break;
case $this->lookupNamespace('apps') . ':' . 'nickname';
$nickname = new Zend_Gdata_Gapps_Extension_Nickname();
$nickname->transferFromDOM($child);
$this->_nickname = $nickname;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value of the login property for this object.
*
* @see setLogin
* @return Zend_Gdata_Gapps_Extension_Login The requested object.
*/
public function getLogin()
{
return $this->_login;
}
/**
* Set the value of the login property for this object. This property
* is used to store the username address of the current user.
*
* @param Zend_Gdata_Gapps_Extension_Login $value The desired value for
* this instance's login property.
* @return Zend_Gdata_Gapps_NicknameEntry Provides a fluent interface.
*/
public function setLogin($value)
{
$this->_login = $value;
return $this;
}
/**
* Get the value of the nickname property for this object.
*
* @see setNickname
* @return Zend_Gdata_Gapps_Extension_Nickname The requested object.
*/
public function getNickname()
{
return $this->_nickname;
}
/**
* Set the value of the nickname property for this object. This property
* is used to store the the name of the current nickname.
*
* @param Zend_Gdata_Gapps_Extension_Nickname $value The desired value for
* this instance's nickname property.
* @return Zend_Gdata_Gapps_NicknameEntry Provides a fluent interface.
*/
public function setNickname($value)
{
$this->_nickname = $value;
return $this;
}
}
Gdata/Gapps/UserEntry.php 0000604 00000022045 15071256135 0011313 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_Gapps_Extension_Login
*/
require_once 'Zend/Gdata/Gapps/Extension/Login.php';
/**
* @see Zend_Gdata_Gapps_Extension_Name
*/
require_once 'Zend/Gdata/Gapps/Extension/Name.php';
/**
* @see Zend_Gdata_Gapps_Extension_Quota
*/
require_once 'Zend/Gdata/Gapps/Extension/Quota.php';
/**
* Data model class for a Google Apps User Entry.
*
* Each user entry describes a single user within a Google Apps hosted
* domain.
*
* To transfer user entries to and from the Google Apps servers, including
* creating new entries, refer to the Google Apps service class,
* Zend_Gdata_Gapps.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_UserEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Gapps_UserEntry';
/**
* <apps:login> element containing information about this user's
* account, including their username and permissions.
*
* @var Zend_Gdata_Gapps_Extension_Login
*/
protected $_login = null;
/**
* <apps:name> element containing the user's actual name.
*
* @var Zend_Gdata_Gapps_Extension_Name
*/
protected $_name = null;
/**
* <apps:quotq> element describing any storage quotas in place for
* this user.
*
* @var Zend_Gdata_Gapps_Extension_Quota
*/
protected $_quota = null;
/**
* <gd:feedLink> element containing information about other feeds
* relevant to this entry.
*
* @var Zend_Gdata_Extension_FeedLink
*/
protected $_feedLink = array();
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_login !== null) {
$element->appendChild($this->_login->getDOM($element->ownerDocument));
}
if ($this->_name !== null) {
$element->appendChild($this->_name->getDOM($element->ownerDocument));
}
if ($this->_quota !== null) {
$element->appendChild($this->_quota->getDOM($element->ownerDocument));
}
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('apps') . ':' . 'login';
$login = new Zend_Gdata_Gapps_Extension_Login();
$login->transferFromDOM($child);
$this->_login = $login;
break;
case $this->lookupNamespace('apps') . ':' . 'name';
$name = new Zend_Gdata_Gapps_Extension_Name();
$name->transferFromDOM($child);
$this->_name = $name;
break;
case $this->lookupNamespace('apps') . ':' . 'quota';
$quota = new Zend_Gdata_Gapps_Extension_Quota();
$quota->transferFromDOM($child);
$this->_quota = $quota;
break;
case $this->lookupNamespace('gd') . ':' . 'feedLink';
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value of the login property for this object.
*
* @see setLogin
* @return Zend_Gdata_Gapps_Extension_Login The requested object.
*/
public function getLogin()
{
return $this->_login;
}
/**
* Set the value of the login property for this object. This property
* is used to store the username address of the current user.
*
* @param Zend_Gdata_Gapps_Extension_Login $value The desired value for
* this instance's login property.
* @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
*/
public function setLogin($value)
{
$this->_login = $value;
return $this;
}
/**
* Get the value of the name property for this object.
*
* @see setName
* @return Zend_Gdata_Gapps_Extension_Name The requested object.
*/
public function getName()
{
return $this->_name;
}
/**
* Set the value of the name property for this object. This property
* is used to store the full name of the current user.
*
* @param Zend_Gdata_Gapps_Extension_Name $value The desired value for
* this instance's name property.
* @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
*/
public function setName($value)
{
$this->_name = $value;
return $this;
}
/**
* Get the value of the quota property for this object.
*
* @see setQuota
* @return Zend_Gdata_Gapps_Extension_Quota The requested object.
*/
public function getQuota()
{
return $this->_quota;
}
/**
* Set the value of the quota property for this object. This property
* is used to store the amount of storage available for the current
* user. Quotas may not be modifiable depending on the domain used.
*
* @param Zend_Gdata_Gapps_Extension_Quota $value The desired value for
* this instance's quota property.
* @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
*/
public function setQuota($value)
{
$this->_quota = $value;
return $this;
}
/**
* Returns all feed links for this entry, or if a rel value is
* specified, the feed link associated with that value is returned.
*
* @param string $rel The rel value of the link to be found. If null,
* the array of links is returned instead.
* @return mixed Either an array of Zend_Gdata_Extension_FeedLink
* objects if $rel is null, a single
* Zend_Gdata_Extension_FeedLink object if $rel is specified
* and a matching feed link is found, or null if $rel is
* specified and no matching feed link is found.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Set the value of the feed link property for this object. This property
* is used to provide links to alternative feeds relevant to this entry.
*
* @param array $value A collection of
* Zend_Gdata_Gapps_Extension_FeedLink objects.
* @return Zend_Gdata_Gapps_EventEntry Provides a fluent interface.
*/
public function setFeedLink($value)
{
$this->_feedLink = $value;
return $this;
}
}
Gdata/Gapps/EmailListRecipientEntry.php 0000604 00000011015 15071256135 0014116 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_Who
*/
require_once 'Zend/Gdata/Extension/Who.php';
/**
* Data model class for a Google Apps Email List Recipient Entry.
*
* Each instance of this class represents a recipient of an email list
* hosted on a Google Apps domain. Each email list may contain multiple
* recipients. Email lists themselves are described by
* Zend_Gdata_EmailListEntry. Multiple recipient entries are contained within
* instances of Zend_Gdata_Gapps_EmailListRecipientFeed.
*
* To transfer email list recipients to and from the Google Apps servers,
* including creating new recipients, refer to the Google Apps service class,
* Zend_Gdata_Gapps.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps_EmailListRecipientEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Gapps_EmailListRecipientEntry';
/**
* <gd:who> element used to store the email address of the current
* recipient. Only the email property of this element should be
* populated.
*
* @var Zend_Gdata_Extension_Who
*/
protected $_who = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_who !== null) {
$element->appendChild($this->_who->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'who';
$who = new Zend_Gdata_Extension_Who();
$who->transferFromDOM($child);
$this->_who = $who;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value of the who property for this object.
*
* @see setWho
* @return Zend_Gdata_Extension_Who The requested object.
*/
public function getWho()
{
return $this->_who;
}
/**
* Set the value of the who property for this object. This property
* is used to store the email address of the current recipient.
*
* @param Zend_Gdata_Extension_Who $value The desired value for this
* instance's who property.
* @return Zend_Gdata_Gapps_EventEntry Provides a fluent interface.
*/
public function setWho($value)
{
$this->_who = $value;
return $this;
}
}
Gdata/ClientLogin.php 0000604 00000015135 15071256135 0010512 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_HttpClient
*/
require_once 'Zend/Gdata/HttpClient.php';
/**
* Zend_Version
*/
require_once 'Zend/Version.php';
/**
* Class to facilitate Google's "Account Authentication
* for Installed Applications" also known as "ClientLogin".
* @see http://code.google.com/apis/accounts/AuthForInstalledApps.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_ClientLogin
{
/**
* The Google client login URI
*
*/
const CLIENTLOGIN_URI = 'https://www.google.com/accounts/ClientLogin';
/**
* The default 'source' parameter to send to Google
*
*/
const DEFAULT_SOURCE = 'Zend-ZendFramework';
/**
* Set Google authentication credentials.
* Must be done before trying to do any Google Data operations that
* require authentication.
* For example, viewing private data, or posting or deleting entries.
*
* @param string $email
* @param string $password
* @param string $service
* @param Zend_Gdata_HttpClient $client
* @param string $source
* @param string $loginToken The token identifier as provided by the server.
* @param string $loginCaptcha The user's response to the CAPTCHA challenge.
* @param string $accountType An optional string to identify whether the
* account to be authenticated is a google or a hosted account. Defaults to
* 'HOSTED_OR_GOOGLE'. See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request
* @throws Zend_Gdata_App_AuthException
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_CaptchaRequiredException
* @return Zend_Gdata_HttpClient
*/
public static function getHttpClient($email, $password, $service = 'xapi',
$client = null,
$source = self::DEFAULT_SOURCE,
$loginToken = null,
$loginCaptcha = null,
$loginUri = self::CLIENTLOGIN_URI,
$accountType = 'HOSTED_OR_GOOGLE')
{
if (! ($email && $password)) {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Please set your Google credentials before trying to ' .
'authenticate');
}
if ($client == null) {
$client = new Zend_Gdata_HttpClient();
}
if (!$client instanceof Zend_Http_Client) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException(
'Client is not an instance of Zend_Http_Client.');
}
// Build the HTTP client for authentication
$client->setUri($loginUri);
$useragent = $source . ' Zend_Framework_Gdata/' . Zend_Version::VERSION;
$client->setConfig(array(
'maxredirects' => 0,
'strictredirects' => true,
'useragent' => $useragent
)
);
$client->setParameterPost('accountType', $accountType);
$client->setParameterPost('Email', (string) $email);
$client->setParameterPost('Passwd', (string) $password);
$client->setParameterPost('service', (string) $service);
$client->setParameterPost('source', (string) $source);
if ($loginToken || $loginCaptcha) {
if($loginToken && $loginCaptcha) {
$client->setParameterPost('logintoken', (string) $loginToken);
$client->setParameterPost('logincaptcha',
(string) $loginCaptcha);
}
else {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Please provide both a token ID and a user\'s response ' .
'to the CAPTCHA challenge.');
}
}
// Send the authentication request
// For some reason Google's server causes an SSL error. We use the
// output buffer to supress an error from being shown. Ugly - but works!
ob_start();
try {
$response = $client->request('POST');
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
ob_end_clean();
// Parse Google's response
$goog_resp = array();
foreach (explode("\n", $response->getBody()) as $l) {
$l = chop($l);
if ($l) {
list($key, $val) = explode('=', chop($l), 2);
$goog_resp[$key] = $val;
}
}
if ($response->getStatus() == 200) {
$client = new Zend_Gdata_HttpClient();
$client->setClientLoginToken($goog_resp['Auth']);
$useragent = $source . ' Zend_Framework_Gdata/' . Zend_Version::VERSION;
$client->setConfig(array(
'strictredirects' => true,
'useragent' => $useragent
)
);
return $client;
} elseif ($response->getStatus() == 403) {
// Check if the server asked for a CAPTCHA
if (array_key_exists('Error', $goog_resp) &&
$goog_resp['Error'] == 'CaptchaRequired') {
require_once 'Zend/Gdata/App/CaptchaRequiredException.php';
throw new Zend_Gdata_App_CaptchaRequiredException(
$goog_resp['CaptchaToken'], $goog_resp['CaptchaUrl']);
}
else {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException('Authentication with Google failed. Reason: ' .
(isset($goog_resp['Error']) ? $goog_resp['Error'] : 'Unspecified.'));
}
}
}
}
Gdata/Photos.php 0000604 00000047303 15071256135 0007561 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Photos_UserFeed
*/
require_once 'Zend/Gdata/Photos/UserFeed.php';
/**
* @see Zend_Gdata_Photos_AlbumFeed
*/
require_once 'Zend/Gdata/Photos/AlbumFeed.php';
/**
* @see Zend_Gdata_Photos_PhotoFeed
*/
require_once 'Zend/Gdata/Photos/PhotoFeed.php';
/**
* Service class for interacting with the Google Photos Data API.
*
* Like other service classes in this module, this class provides access via
* an HTTP client to Google servers for working with entries and feeds.
*
* @link http://code.google.com/apis/picasaweb/gdata.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos extends Zend_Gdata
{
const PICASA_BASE_URI = 'http://picasaweb.google.com/data';
const PICASA_BASE_FEED_URI = 'http://picasaweb.google.com/data/feed';
const AUTH_SERVICE_NAME = 'lh2';
/**
* Default projection when interacting with the Picasa server.
*/
const DEFAULT_PROJECTION = 'api';
/**
* The default visibility to filter events by.
*/
const DEFAULT_VISIBILITY = 'all';
/**
* The default user to retrieve feeds for.
*/
const DEFAULT_USER = 'default';
/**
* Path to the user feed on the Picasa server.
*/
const USER_PATH = 'user';
/**
* Path to album feeds on the Picasa server.
*/
const ALBUM_PATH = 'albumid';
/**
* Path to photo feeds on the Picasa server.
*/
const PHOTO_PATH = 'photoid';
/**
* The path to the community search feed on the Picasa server.
*/
const COMMUNITY_SEARCH_PATH = 'all';
/**
* The path to use for finding links to feeds within entries
*/
const FEED_LINK_PATH = 'http://schemas.google.com/g/2005#feed';
/**
* The path to use for the determining type of an entry
*/
const KIND_PATH = 'http://schemas.google.com/g/2005#kind';
/**
* Namespaces used for Zend_Gdata_Photos
*
* @var array
*/
public static $namespaces = array(
array('gphoto', 'http://schemas.google.com/photos/2007', 1, 0),
array('photo', 'http://www.pheed.com/pheed/', 1, 0),
array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0),
array('georss', 'http://www.georss.org/georss', 1, 0),
array('gml', 'http://www.opengis.net/gml', 1, 0),
array('media', 'http://search.yahoo.com/mrss/', 1, 0)
);
/**
* Create Zend_Gdata_Photos object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Photos');
$this->registerPackage('Zend_Gdata_Photos_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Retrieve a UserFeed containing AlbumEntries, PhotoEntries and
* TagEntries associated with a given user.
*
* @param string $userName The userName of interest
* @param mixed $location (optional) The location for the feed, as a URL
* or Query. If not provided, a default URL will be used instead.
* @return Zend_Gdata_Photos_UserFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getUserFeed($userName = null, $location = null)
{
if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('feed');
if ($userName !== null) {
$location->setUser($userName);
}
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
if ($userName !== null) {
$location->setUser($userName);
}
$uri = $location->getQueryUrl();
} else if ($location !== null) {
$uri = $location;
} else if ($userName !== null) {
$uri = self::PICASA_BASE_FEED_URI . '/' .
self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
$userName;
} else {
$uri = self::PICASA_BASE_FEED_URI . '/' .
self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
self::DEFAULT_USER;
}
return parent::getFeed($uri, 'Zend_Gdata_Photos_UserFeed');
}
/**
* Retreive AlbumFeed object containing multiple PhotoEntry or TagEntry
* objects.
*
* @param mixed $location (optional) The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_AlbumFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getAlbumFeed($location = null)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('feed');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Photos_AlbumFeed');
}
/**
* Retreive PhotoFeed object containing comments and tags associated
* with a given photo.
*
* @param mixed $location (optional) The location for the feed, as a URL
* or Query. If not specified, the community search feed will
* be returned instead.
* @return Zend_Gdata_Photos_PhotoFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getPhotoFeed($location = null)
{
if ($location === null) {
$uri = self::PICASA_BASE_FEED_URI . '/' .
self::DEFAULT_PROJECTION . '/' .
self::COMMUNITY_SEARCH_PATH;
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('feed');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Photos_PhotoFeed');
}
/**
* Retreive a single UserEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_UserEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getUserEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('entry');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Photos_UserEntry');
}
/**
* Retreive a single AlbumEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_AlbumEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getAlbumEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('entry');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Photos_AlbumEntry');
}
/**
* Retreive a single PhotoEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_PhotoEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getPhotoEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('entry');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Photos_PhotoEntry');
}
/**
* Retreive a single TagEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_TagEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getTagEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('entry');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Photos_TagEntry');
}
/**
* Retreive a single CommentEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Photos_CommentEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function getCommentEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
$location->setType('entry');
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Photos_CommentEntry');
}
/**
* Create a new album from a AlbumEntry.
*
* @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
* insert.
* @param string $url (optional) The URI that the album should be
* uploaded to. If null, the default album creation URI for
* this domain will be used.
* @return Zend_Gdata_Photos_AlbumEntry The inserted album entry as
* returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function insertAlbumEntry($album, $uri = null)
{
if ($uri === null) {
$uri = self::PICASA_BASE_FEED_URI . '/' .
self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
self::DEFAULT_USER;
}
$newEntry = $this->insertEntry($album, $uri, 'Zend_Gdata_Photos_AlbumEntry');
return $newEntry;
}
/**
* Create a new photo from a PhotoEntry.
*
* @param Zend_Gdata_Photos_PhotoEntry $photo The photo to insert.
* @param string $url The URI that the photo should be uploaded
* to. Alternatively, an AlbumEntry can be provided and the
* photo will be added to that album.
* @return Zend_Gdata_Photos_PhotoEntry The inserted photo entry
* as returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function insertPhotoEntry($photo, $uri = null)
{
if ($uri instanceof Zend_Gdata_Photos_AlbumEntry) {
$uri = $uri->getLink(self::FEED_LINK_PATH)->href;
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'URI must not be null');
}
$newEntry = $this->insertEntry($photo, $uri, 'Zend_Gdata_Photos_PhotoEntry');
return $newEntry;
}
/**
* Create a new tag from a TagEntry.
*
* @param Zend_Gdata_Photos_TagEntry $tag The tag entry to insert.
* @param string $url The URI where the tag should be
* uploaded to. Alternatively, a PhotoEntry can be provided and
* the tag will be added to that photo.
* @return Zend_Gdata_Photos_TagEntry The inserted tag entry as returned
* by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function insertTagEntry($tag, $uri = null)
{
if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) {
$uri = $uri->getLink(self::FEED_LINK_PATH)->href;
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'URI must not be null');
}
$newEntry = $this->insertEntry($tag, $uri, 'Zend_Gdata_Photos_TagEntry');
return $newEntry;
}
/**
* Create a new comment from a CommentEntry.
*
* @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
* insert.
* @param string $url The URI where the comment should be uploaded to.
* Alternatively, a PhotoEntry can be provided and
* the comment will be added to that photo.
* @return Zend_Gdata_Photos_CommentEntry The inserted comment entry
* as returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function insertCommentEntry($comment, $uri = null)
{
if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) {
$uri = $uri->getLink(self::FEED_LINK_PATH)->href;
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'URI must not be null');
}
$newEntry = $this->insertEntry($comment, $uri, 'Zend_Gdata_Photos_CommentEntry');
return $newEntry;
}
/**
* Delete an AlbumEntry.
*
* @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
* delete.
* @param boolean $catch Whether to catch an exception when
* modified and re-delete or throw
* @return void.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function deleteAlbumEntry($album, $catch)
{
if ($catch) {
try {
$this->delete($album);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() === 409) {
$entry = new Zend_Gdata_Photos_AlbumEntry($e->getResponse()->getBody());
$this->delete($entry->getLink('edit')->href);
} else {
throw $e;
}
}
} else {
$this->delete($album);
}
}
/**
* Delete a PhotoEntry.
*
* @param Zend_Gdata_Photos_PhotoEntry $photo The photo entry to
* delete.
* @param boolean $catch Whether to catch an exception when
* modified and re-delete or throw
* @return void.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function deletePhotoEntry($photo, $catch)
{
if ($catch) {
try {
$this->delete($photo);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() === 409) {
$entry = new Zend_Gdata_Photos_PhotoEntry($e->getResponse()->getBody());
$this->delete($entry->getLink('edit')->href);
} else {
throw $e;
}
}
} else {
$this->delete($photo);
}
}
/**
* Delete a CommentEntry.
*
* @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
* delete.
* @param boolean $catch Whether to catch an exception when
* modified and re-delete or throw
* @return void.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function deleteCommentEntry($comment, $catch)
{
if ($catch) {
try {
$this->delete($comment);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() === 409) {
$entry = new Zend_Gdata_Photos_CommentEntry($e->getResponse()->getBody());
$this->delete($entry->getLink('edit')->href);
} else {
throw $e;
}
}
} else {
$this->delete($comment);
}
}
/**
* Delete a TagEntry.
*
* @param Zend_Gdata_Photos_TagEntry $tag The tag entry to
* delete.
* @param boolean $catch Whether to catch an exception when
* modified and re-delete or throw
* @return void.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
*/
public function deleteTagEntry($tag, $catch)
{
if ($catch) {
try {
$this->delete($tag);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() === 409) {
$entry = new Zend_Gdata_Photos_TagEntry($e->getResponse()->getBody());
$this->delete($entry->getLink('edit')->href);
} else {
throw $e;
}
}
} else {
$this->delete($tag);
}
}
}
Gdata/Extension.php 0000604 00000003303 15071256135 0010251 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents a Gdata extension
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension extends Zend_Gdata_App_Extension
{
protected $_rootNamespace = 'gd';
public function __construct()
{
/* NOTE: namespaces must be registered before calling parent */
$this->registerNamespace('gd',
'http://schemas.google.com/g/2005');
$this->registerNamespace('openSearch',
'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0);
$this->registerNamespace('openSearch',
'http://a9.com/-/spec/opensearch/1.1/', 2, 0);
$this->registerNamespace('rss',
'http://blogs.law.harvard.edu/tech/rss');
parent::__construct();
}
}
Gdata/Gapps.php 0000604 00000120554 15071256135 0007357 0 ustar 00 <?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_Gdata
* @subpackage Gapps
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Gapps_UserFeed
*/
require_once 'Zend/Gdata/Gapps/UserFeed.php';
/**
* @see Zend_Gdata_Gapps_NicknameFeed
*/
require_once 'Zend/Gdata/Gapps/NicknameFeed.php';
/**
* @see Zend_Gdata_Gapps_EmailListFeed
*/
require_once 'Zend/Gdata/Gapps/EmailListFeed.php';
/**
* @see Zend_Gdata_Gapps_EmailListRecipientFeed
*/
require_once 'Zend/Gdata/Gapps/EmailListRecipientFeed.php';
/**
* Service class for interacting with the Google Apps Provisioning API.
*
* Like other service classes in this module, this class provides access via
* an HTTP client to Google servers for working with entries and feeds.
*
* Because of the nature of this API, all access must occur over an
* authenticated connection.
*
* @link http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gapps
* @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_Gdata_Gapps extends Zend_Gdata
{
const APPS_BASE_FEED_URI = 'https://apps-apis.google.com/a/feeds';
const AUTH_SERVICE_NAME = 'apps';
/**
* Path to user feeds on the Google Apps server.
*/
const APPS_USER_PATH = '/user/2.0';
/**
* Path to nickname feeds on the Google Apps server.
*/
const APPS_NICKNAME_PATH = '/nickname/2.0';
/**
* Path to email list feeds on the Google Apps server.
*/
const APPS_EMAIL_LIST_PATH = '/emailList/2.0';
/**
* Path to email list recipient feeds on the Google Apps server.
*/
const APPS_EMAIL_LIST_RECIPIENT_POSTFIX = '/recipient';
/**
* The domain which is being administered via the Provisioning API.
*
* @var string
*/
protected $_domain = null;
/**
* Namespaces used for Zend_Gdata_Gapps
*
* @var array
*/
public static $namespaces = array(
array('apps', 'http://schemas.google.com/apps/2006', 1, 0)
);
/**
* Create Gdata_Gapps object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google Apps servers.
* @param string $domain (optional) The Google Apps domain which is to be
* accessed.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $domain = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Gapps');
$this->registerPackage('Zend_Gdata_Gapps_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
$this->_domain = $domain;
}
/**
* Convert an exception to an ServiceException if an AppsForYourDomain
* XML document is contained within the original exception's HTTP
* response. If conversion fails, throw the original error.
*
* @param Zend_Gdata_Exception $e The exception to convert.
* @throws Zend_Gdata_Gapps_ServiceException
* @throws mixed
*/
public static function throwServiceExceptionIfDetected($e) {
try {
// Check to see if there is an AppsForYourDomainErrors
// datastructure in the response. If so, convert it to
// an exception and throw it.
require_once 'Zend/Gdata/Gapps/ServiceException.php';
$error = new Zend_Gdata_Gapps_ServiceException();
$error->importFromString($e->getResponse()->getBody());
throw $error;
} catch (Zend_Gdata_App_Exception $e2) {
// Unable to convert the response to a ServiceException,
// most likely because the server didn't return an
// AppsForYourDomainErrors document. Throw the original
// exception.
throw $e;
}
}
/**
* Imports a feed located at $uri.
* This method overrides the default behavior of Zend_Gdata_App,
* providing support for Zend_Gdata_Gapps_ServiceException.
*
* @param string $uri
* @param Zend_Http_Client $client (optional) The client used for
* communication
* @param string $className (optional) The class which is used as the
* return type
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
* @return Zend_Gdata_App_Feed
*/
public static function import($uri, $client = null, $className='Zend_Gdata_App_Feed')
{
try {
return parent::import($uri, $client, $className);
} catch (Zend_Gdata_App_HttpException $e) {
self::throwServiceExceptionIfDetected($e);
}
}
/**
* GET a URI using client object.
* This method overrides the default behavior of Zend_Gdata_App,
* providing support for Zend_Gdata_Gapps_ServiceException.
*
* @param string $uri GET URI
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
* @return Zend_Http_Response
*/
public function get($uri, $extraHeaders = array())
{
try {
return parent::get($uri, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
self::throwServiceExceptionIfDetected($e);
}
}
/**
* POST data with client object.
* This method overrides the default behavior of Zend_Gdata_App,
* providing support for Zend_Gdata_Gapps_ServiceException.
*
* @param mixed $data The Zend_Gdata_App_Entry or XML to post
* @param string $uri (optional) POST URI
* @param integer $remainingRedirects (optional)
* @param string $contentType Content-type of the data
* @param array $extraHaders Extra headers to add tot he request
* @return Zend_Http_Response
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function post($data, $uri = null, $remainingRedirects = null,
$contentType = null, $extraHeaders = null)
{
try {
return parent::post($data, $uri, $remainingRedirects, $contentType, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
self::throwServiceExceptionIfDetected($e);
}
}
/**
* PUT data with client object
* This method overrides the default behavior of Zend_Gdata_App,
* providing support for Zend_Gdata_Gapps_ServiceException.
*
* @param mixed $data The Zend_Gdata_App_Entry or XML to post
* @param string $uri (optional) PUT URI
* @param integer $remainingRedirects (optional)
* @param string $contentType Content-type of the data
* @param array $extraHaders Extra headers to add tot he request
* @return Zend_Http_Response
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function put($data, $uri = null, $remainingRedirects = null,
$contentType = null, $extraHeaders = null)
{
try {
return parent::put($data, $uri, $remainingRedirects, $contentType, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
self::throwServiceExceptionIfDetected($e);
}
}
/**
* DELETE entry with client object
* This method overrides the default behavior of Zend_Gdata_App,
* providing support for Zend_Gdata_Gapps_ServiceException.
*
* @param mixed $data The Zend_Gdata_App_Entry or URL to delete
* @param integer $remainingRedirects (optional)
* @return void
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function delete($data, $remainingRedirects = null)
{
try {
return parent::delete($data, $remainingRedirects);
} catch (Zend_Gdata_App_HttpException $e) {
self::throwServiceExceptionIfDetected($e);
}
}
/**
* Set domain for this service instance. This should be a fully qualified
* domain, such as 'foo.example.com'.
*
* This value is used when calculating URLs for retrieving and posting
* entries. If no value is specified, a URL will have to be manually
* constructed prior to using any methods which interact with the Google
* Apps provisioning service.
*
* @param string $value The domain to be used for this session.
*/
public function setDomain($value)
{
$this->_domain = $value;
}
/**
* Get domain for this service instance. This should be a fully qualified
* domain, such as 'foo.example.com'. If no domain is set, null will be
* returned.
*
* @return string The domain to be used for this session, or null if not
* set.
*/
public function getDomain()
{
return $this->_domain;
}
/**
* Returns the base URL used to access the Google Apps service, based
* on the current domain. The current domain can be temporarily
* overridden by providing a fully qualified domain as $domain.
*
* @param string $domain (optional) A fully-qualified domain to use
* instead of the default domain for this service instance.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getBaseUrl($domain = null)
{
if ($domain !== null) {
return self::APPS_BASE_FEED_URI . '/' . $domain;
} else if ($this->_domain !== null) {
return self::APPS_BASE_FEED_URI . '/' . $this->_domain;
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Domain must be specified.');
}
}
/**
* Retrieve a UserFeed containing multiple UserEntry objects.
*
* @param mixed $location (optional) The location for the feed, as a URL
* or Query.
* @return Zend_Gdata_Gapps_UserFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getUserFeed($location = null)
{
if ($location === null) {
$uri = $this->getBaseUrl() . self::APPS_USER_PATH;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gapps_UserFeed');
}
/**
* Retreive NicknameFeed object containing multiple NicknameEntry objects.
*
* @param mixed $location (optional) The location for the feed, as a URL
* or Query.
* @return Zend_Gdata_Gapps_NicknameFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getNicknameFeed($location = null)
{
if ($location === null) {
$uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gapps_NicknameFeed');
}
/**
* Retreive EmailListFeed object containing multiple EmailListEntry
* objects.
*
* @param mixed $location (optional) The location for the feed, as a URL
* or Query.
* @return Zend_Gdata_Gapps_EmailListFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getEmailListFeed($location = null)
{
if ($location === null) {
$uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gapps_EmailListFeed');
}
/**
* Retreive EmailListRecipientFeed object containing multiple
* EmailListRecipientEntry objects.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Gapps_EmailListRecipientFeed
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getEmailListRecipientFeed($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gapps_EmailListRecipientFeed');
}
/**
* Retreive a single UserEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Gapps_UserEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getUserEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Gapps_UserEntry');
}
/**
* Retreive a single NicknameEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Gapps_NicknameEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getNicknameEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Gapps_NicknameEntry');
}
/**
* Retreive a single EmailListEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Gapps_EmailListEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getEmailListEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Gapps_EmailListEntry');
}
/**
* Retreive a single EmailListRecipientEntry object.
*
* @param mixed $location The location for the feed, as a URL or Query.
* @return Zend_Gdata_Gapps_EmailListRecipientEntry
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function getEmailListRecipientEntry($location)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Gapps_EmailListRecipientEntry');
}
/**
* Create a new user from a UserEntry.
*
* @param Zend_Gdata_Gapps_UserEntry $user The user entry to insert.
* @param string $uri (optional) The URI where the user should be
* uploaded to. If null, the default user creation URI for
* this domain will be used.
* @return Zend_Gdata_Gapps_UserEntry The inserted user entry as
* returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function insertUser($user, $uri = null)
{
if ($uri === null) {
$uri = $this->getBaseUrl() . self::APPS_USER_PATH;
}
$newEntry = $this->insertEntry($user, $uri, 'Zend_Gdata_Gapps_UserEntry');
return $newEntry;
}
/**
* Create a new nickname from a NicknameEntry.
*
* @param Zend_Gdata_Gapps_NicknameEntry $nickname The nickname entry to
* insert.
* @param string $uri (optional) The URI where the nickname should be
* uploaded to. If null, the default nickname creation URI for
* this domain will be used.
* @return Zend_Gdata_Gapps_NicknameEntry The inserted nickname entry as
* returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function insertNickname($nickname, $uri = null)
{
if ($uri === null) {
$uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
}
$newEntry = $this->insertEntry($nickname, $uri, 'Zend_Gdata_Gapps_NicknameEntry');
return $newEntry;
}
/**
* Create a new email list from an EmailListEntry.
*
* @param Zend_Gdata_Gapps_EmailListEntry $emailList The email list entry
* to insert.
* @param string $uri (optional) The URI where the email list should be
* uploaded to. If null, the default email list creation URI for
* this domain will be used.
* @return Zend_Gdata_Gapps_EmailListEntry The inserted email list entry
* as returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function insertEmailList($emailList, $uri = null)
{
if ($uri === null) {
$uri = $this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH;
}
$newEntry = $this->insertEntry($emailList, $uri, 'Zend_Gdata_Gapps_EmailListEntry');
return $newEntry;
}
/**
* Create a new email list recipient from an EmailListRecipientEntry.
*
* @param Zend_Gdata_Gapps_EmailListRecipientEntry $recipient The recipient
* entry to insert.
* @param string $uri (optional) The URI where the recipient should be
* uploaded to. If null, the default recipient creation URI for
* this domain will be used.
* @return Zend_Gdata_Gapps_EmailListRecipientEntry The inserted
* recipient entry as returned by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function insertEmailListRecipient($recipient, $uri = null)
{
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'URI must not be null');
} elseif ($uri instanceof Zend_Gdata_Gapps_EmailListEntry) {
$uri = $uri->getLink('edit')->href;
}
$newEntry = $this->insertEntry($recipient, $uri, 'Zend_Gdata_Gapps_EmailListRecipientEntry');
return $newEntry;
}
/**
* Provides a magic factory method to instantiate new objects with
* shorter syntax than would otherwise be required by the Zend Framework
* naming conventions. For more information, see Zend_Gdata_App::__call().
*
* This overrides the default behavior of __call() so that query classes
* do not need to have their domain manually set when created with
* a magic factory method.
*
* @see Zend_Gdata_App::__call()
* @param string $method The method name being called
* @param array $args The arguments passed to the call
* @throws Zend_Gdata_App_Exception
*/
public function __call($method, $args) {
if (preg_match('/^new(\w+Query)/', $method, $matches)) {
$class = $matches[1];
$foundClassName = null;
foreach ($this->_registeredPackages as $name) {
try {
require_once 'Zend/Loader.php';
@Zend_Loader::loadClass("${name}_${class}");
$foundClassName = "${name}_${class}";
break;
} catch (Zend_Exception $e) {
// package wasn't here- continue searching
}
}
if ($foundClassName != null) {
$reflectionObj = new ReflectionClass($foundClassName);
// Prepend the domain to the query
$args = array_merge(array($this->getDomain()), $args);
return $reflectionObj->newInstanceArgs($args);
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
"Unable to find '${class}' in registered packages");
}
} else {
return parent::__call($method, $args);
}
}
// Convenience methods
// Specified at http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_e
/**
* Create a new user entry and send it to the Google Apps servers.
*
* @param string $username The username for the new user.
* @param string $givenName The given name for the new user.
* @param string $familyName The family name for the new user.
* @param string $password The password for the new user as a plaintext string
* (if $passwordHashFunction is null) or a SHA-1 hashed
* value (if $passwordHashFunction = 'SHA-1').
* @param string $quotaLimitInMB (optional) The quota limit for the new user in MB.
* @return Zend_Gdata_Gapps_UserEntry (optional) The new user entry as returned by
* server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function createUser ($username, $givenName, $familyName, $password,
$passwordHashFunction = null, $quotaLimitInMB = null) {
$user = $this->newUserEntry();
$user->login = $this->newLogin();
$user->login->username = $username;
$user->login->password = $password;
$user->login->hashFunctionName = $passwordHashFunction;
$user->name = $this->newName();
$user->name->givenName = $givenName;
$user->name->familyName = $familyName;
if ($quotaLimitInMB !== null) {
$user->quota = $this->newQuota();
$user->quota->limit = $quotaLimitInMB;
}
return $this->insertUser($user);
}
/**
* Retrieve a user based on their username.
*
* @param string $username The username to search for.
* @return Zend_Gdata_Gapps_UserEntry The username to search for, or null
* if no match found.
* @throws Zend_Gdata_App_InvalidArgumentException
* @throws Zend_Gdata_App_HttpException
*/
public function retrieveUser ($username) {
$query = $this->newUserQuery($username);
try {
$user = $this->getUserEntry($query);
} catch (Zend_Gdata_Gapps_ServiceException $e) {
// Set the user to null if not found
if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
$user = null;
} else {
throw $e;
}
}
return $user;
}
/**
* Retrieve a page of users in alphabetical order, starting with the
* provided username.
*
* @param string $startUsername (optional) The first username to retrieve.
* If null or not declared, the page will begin with the first
* user in the domain.
* @return Zend_Gdata_Gapps_UserFeed Collection of Zend_Gdata_UserEntry
* objects representing all users in the domain.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrievePageOfUsers ($startUsername = null) {
$query = $this->newUserQuery();
$query->setStartUsername($startUsername);
return $this->getUserFeed($query);
}
/**
* Retrieve all users in the current domain. Be aware that
* calling this function on a domain with many users will take a
* signifigant amount of time to complete. On larger domains this may
* may cause execution to timeout without proper precautions in place.
*
* @return Zend_Gdata_Gapps_UserFeed Collection of Zend_Gdata_UserEntry
* objects representing all users in the domain.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveAllUsers () {
return $this->retrieveAllEntriesForFeed($this->retrievePageOfUsers());
}
/**
* Overwrite a specified username with the provided UserEntry. The
* UserEntry does not need to contain an edit link.
*
* This method is provided for compliance with the Google Apps
* Provisioning API specification. Normally users will instead want to
* call UserEntry::save() instead.
*
* @see Zend_Gdata_App_Entry::save
* @param string $username The username whose data will be overwritten.
* @param Zend_Gdata_Gapps_UserEntry $userEntry The user entry which
* will be overwritten.
* @return Zend_Gdata_Gapps_UserEntry The UserEntry returned by the
* server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function updateUser($username, $userEntry) {
return $this->updateEntry($userEntry, $this->getBaseUrl() .
self::APPS_USER_PATH . '/' . $username);
}
/**
* Mark a given user as suspended.
*
* @param string $username The username associated with the user who
* should be suspended.
* @return Zend_Gdata_Gapps_UserEntry The UserEntry for the modified
* user.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function suspendUser($username) {
$user = $this->retrieveUser($username);
$user->login->suspended = true;
return $user->save();
}
/**
* Mark a given user as not suspended.
*
* @param string $username The username associated with the user who
* should be restored.
* @return Zend_Gdata_Gapps_UserEntry The UserEntry for the modified
* user.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function restoreUser($username) {
$user = $this->retrieveUser($username);
$user->login->suspended = false;
return $user->save();
}
/**
* Delete a user by username.
*
* @param string $username The username associated with the user who
* should be deleted.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function deleteUser($username) {
$this->delete($this->getBaseUrl() . self::APPS_USER_PATH . '/' .
$username);
}
/**
* Create a nickname for a given user.
*
* @param string $username The username to which the new nickname should
* be associated.
* @param string $nickname The new nickname to be created.
* @return Zend_Gdata_Gapps_NicknameEntry The nickname entry which was
* created by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function createNickname($username, $nickname) {
$entry = $this->newNicknameEntry();
$nickname = $this->newNickname($nickname);
$login = $this->newLogin($username);
$entry->nickname = $nickname;
$entry->login = $login;
return $this->insertNickname($entry);
}
/**
* Retrieve the entry for a specified nickname.
*
* @param string $nickname The nickname to be retrieved.
* @return Zend_Gdata_Gapps_NicknameEntry The requested nickname entry.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveNickname($nickname) {
$query = $this->newNicknameQuery();
$query->setNickname($nickname);
try {
$nickname = $this->getNicknameEntry($query);
} catch (Zend_Gdata_Gapps_ServiceException $e) {
// Set the nickname to null if not found
if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
$nickname = null;
} else {
throw $e;
}
}
return $nickname;
}
/**
* Retrieve all nicknames associated with a specific username.
*
* @param string $username The username whose nicknames should be
* returned.
* @return Zend_Gdata_Gapps_NicknameFeed A feed containing all nicknames
* for the given user, or null if
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveNicknames($username) {
$query = $this->newNicknameQuery();
$query->setUsername($username);
$nicknameFeed = $this->retrieveAllEntriesForFeed(
$this->getNicknameFeed($query));
return $nicknameFeed;
}
/**
* Retrieve a page of nicknames in alphabetical order, starting with the
* provided nickname.
*
* @param string $startNickname (optional) The first nickname to
* retrieve. If null or not declared, the page will begin with
* the first nickname in the domain.
* @return Zend_Gdata_Gapps_NicknameFeed Collection of Zend_Gdata_NicknameEntry
* objects representing all nicknames in the domain.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrievePageOfNicknames ($startNickname = null) {
$query = $this->newNicknameQuery();
$query->setStartNickname($startNickname);
return $this->getNicknameFeed($query);
}
/**
* Retrieve all nicknames in the current domain. Be aware that
* calling this function on a domain with many nicknames will take a
* signifigant amount of time to complete. On larger domains this may
* may cause execution to timeout without proper precautions in place.
*
* @return Zend_Gdata_Gapps_NicknameFeed Collection of Zend_Gdata_NicknameEntry
* objects representing all nicknames in the domain.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveAllNicknames () {
return $this->retrieveAllEntriesForFeed($this->retrievePageOfNicknames());
}
/**
* Delete a specified nickname.
*
* @param string $nickname The name of the nickname to be deleted.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function deleteNickname($nickname) {
$this->delete($this->getBaseUrl() . self::APPS_NICKNAME_PATH . '/' . $nickname);
}
/**
* Create a new email list.
*
* @param string $emailList The name of the email list to be created.
* @return Zend_Gdata_Gapps_EmailListEntry The email list entry
* as created on the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function createEmailList($emailList) {
$entry = $this->newEmailListEntry();
$list = $this->newEmailList();
$list->name = $emailList;
$entry->emailList = $list;
return $this->insertEmailList($entry);
}
/**
* Retrieve all email lists associated with a recipient.
*
* @param string $username The recipient whose associated email lists
* should be returned.
* @return Zend_Gdata_Gapps_EmailListFeed The list of email lists found as
* Zend_Gdata_EmailListEntry objects.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveEmailLists($recipient) {
$query = $this->newEmailListQuery();
$query->recipient = $recipient;
return $this->getEmailListFeed($query);
}
/**
* Retrieve a page of email lists in alphabetical order, starting with the
* provided email list.
*
* @param string $startEmailListName (optional) The first list to
* retrieve. If null or not defined, the page will begin
* with the first email list in the domain.
* @return Zend_Gdata_Gapps_EmailListFeed Collection of Zend_Gdata_EmailListEntry
* objects representing all nicknames in the domain.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrievePageOfEmailLists ($startNickname = null) {
$query = $this->newEmailListQuery();
$query->setStartEmailListName($startNickname);
return $this->getEmailListFeed($query);
}
/**
* Retrieve all email lists associated with the curent domain. Be aware that
* calling this function on a domain with many email lists will take a
* signifigant amount of time to complete. On larger domains this may
* may cause execution to timeout without proper precautions in place.
*
* @return Zend_Gdata_Gapps_EmailListFeed The list of email lists found
* as Zend_Gdata_Gapps_EmailListEntry objects.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveAllEmailLists() {
return $this->retrieveAllEntriesForFeed($this->retrievePageOfEmailLists());
}
/**
* Delete a specified email list.
*
* @param string $emailList The name of the emailList to be deleted.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function deleteEmailList($emailList) {
$this->delete($this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH . '/'
. $emailList);
}
/**
* Add a specified recipient to an existing emailList.
*
* @param string $recipientAddress The address of the recipient to be
* added to the email list.
* @param string $emailList The name of the email address to which the
* recipient should be added.
* @return Zend_Gdata_Gapps_EmailListRecipientEntry The recipient entry
* created by the server.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function addRecipientToEmailList($recipientAddress, $emailList) {
$entry = $this->newEmailListRecipientEntry();
$who = $this->newWho();
$who->email = $recipientAddress;
$entry->who = $who;
$address = $this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH . '/' .
$emailList . self::APPS_EMAIL_LIST_RECIPIENT_POSTFIX . '/';
return $this->insertEmailListRecipient($entry, $address);
}
/**
* Retrieve a page of email list recipients in alphabetical order,
* starting with the provided email list recipient.
*
* @param string $emaiList The email list which should be searched.
* @param string $startRecipient (optinal) The address of the first
* recipient, or null to start with the first recipient in
* the list.
* @return Zend_Gdata_Gapps_EmailListRecipientFeed Collection of
* Zend_Gdata_EmailListRecipientEntry objects representing all
* recpients in the specified list.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrievePageOfRecipients ($emailList,
$startRecipient = null) {
$query = $this->newEmailListRecipientQuery();
$query->setEmailListName($emailList);
$query->setStartRecipient($startRecipient);
return $this->getEmailListRecipientFeed($query);
}
/**
* Retrieve all recipients associated with an email list. Be aware that
* calling this function on a domain with many email lists will take a
* signifigant amount of time to complete. On larger domains this may
* may cause execution to timeout without proper precautions in place.
*
* @param string $emaiList The email list which should be searched.
* @return Zend_Gdata_Gapps_EmailListRecipientFeed The list of email lists
* found as Zend_Gdata_Gapps_EmailListRecipientEntry objects.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function retrieveAllRecipients($emailList) {
return $this->retrieveAllEntriesForFeed(
$this->retrievePageOfRecipients($emailList));
}
/**
* Remove a specified recipient from an email list.
*
* @param string $recipientAddress The recipient to be removed.
* @param string $emailList The list from which the recipient should
* be removed.
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_Gapps_ServiceException
*/
public function removeRecipientFromEmailList($recipientAddress, $emailList) {
$this->delete($this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH . '/'
. $emailList . self::APPS_EMAIL_LIST_RECIPIENT_POSTFIX . '/'
. $recipientAddress);
}
}
Gdata/AuthSub.php 0000604 00000021745 15071256135 0007662 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_HttpClient
*/
require_once 'Zend/Gdata/HttpClient.php';
/**
* Zend_Version
*/
require_once 'Zend/Version.php';
/**
* Wrapper around Zend_Http_Client to facilitate Google's "Account Authentication
* Proxy for Web-Based Applications".
*
* @see http://code.google.com/apis/accounts/AuthForWebApps.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_AuthSub
{
const AUTHSUB_REQUEST_URI = 'https://www.google.com/accounts/AuthSubRequest';
const AUTHSUB_SESSION_TOKEN_URI = 'https://www.google.com/accounts/AuthSubSessionToken';
const AUTHSUB_REVOKE_TOKEN_URI = 'https://www.google.com/accounts/AuthSubRevokeToken';
const AUTHSUB_TOKEN_INFO_URI = 'https://www.google.com/accounts/AuthSubTokenInfo';
/**
* Creates a URI to request a single-use AuthSub token.
*
* @param string $next (required) URL identifying the service to be
* accessed.
* The resulting token will enable access to the specified service only.
* Some services may limit scope further, such as read-only access.
* @param string $scope (required) URL identifying the service to be
* accessed. The resulting token will enable
* access to the specified service only.
* Some services may limit scope further, such
* as read-only access.
* @param int $secure (optional) Boolean flag indicating whether the
* authentication transaction should issue a secure
* token (1) or a non-secure token (0). Secure tokens
* are available to registered applications only.
* @param int $session (optional) Boolean flag indicating whether
* the one-time-use token may be exchanged for
* a session token (1) or not (0).
* @param string $request_uri (optional) URI to which to direct the
* authentication request.
*/
public static function getAuthSubTokenUri($next, $scope, $secure=0, $session=0,
$request_uri = self::AUTHSUB_REQUEST_URI)
{
$querystring = '?next=' . urlencode($next)
. '&scope=' . urldecode($scope)
. '&secure=' . urlencode($secure)
. '&session=' . urlencode($session);
return $request_uri . $querystring;
}
/**
* Upgrades a single use token to a session token
*
* @param string $token The single use token which is to be upgraded
* @param Zend_Http_Client $client (optional) HTTP client to use to
* make the request
* @param string $request_uri (optional) URI to which to direct
* the session token upgrade
* @return string The upgraded token value
* @throws Zend_Gdata_App_AuthException
* @throws Zend_Gdata_App_HttpException
*/
public static function getAuthSubSessionToken(
$token, $client = null,
$request_uri = self::AUTHSUB_SESSION_TOKEN_URI)
{
$client = self::getHttpClient($token, $client);
if ($client instanceof Zend_Gdata_HttpClient) {
$filterResult = $client->filterHttpRequest('GET', $request_uri);
$url = $filterResult['url'];
$headers = $filterResult['headers'];
$client->setHeaders($headers);
$client->setUri($url);
} else {
$client->setUri($request_uri);
}
try {
$response = $client->request('GET');
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
// Parse Google's response
if ($response->isSuccessful()) {
$goog_resp = array();
foreach (explode("\n", $response->getBody()) as $l) {
$l = chop($l);
if ($l) {
list($key, $val) = explode('=', chop($l), 2);
$goog_resp[$key] = $val;
}
}
return $goog_resp['Token'];
} else {
require_once 'Zend/Gdata/App/AuthException.php';
throw new Zend_Gdata_App_AuthException(
'Token upgrade failed. Reason: ' . $response->getBody());
}
}
/**
* Revoke a token
*
* @param string $token The token to revoke
* @param Zend_Http_Client $client (optional) HTTP client to use to make the request
* @param string $request_uri (optional) URI to which to direct the revokation request
* @return boolean Whether the revokation was successful
* @throws Zend_Gdata_App_HttpException
*/
public static function AuthSubRevokeToken($token, $client = null,
$request_uri = self::AUTHSUB_REVOKE_TOKEN_URI)
{
$client = self::getHttpClient($token, $client);
if ($client instanceof Zend_Gdata_HttpClient) {
$filterResult = $client->filterHttpRequest('GET', $request_uri);
$url = $filterResult['url'];
$headers = $filterResult['headers'];
$client->setHeaders($headers);
$client->setUri($url);
$client->resetParameters();
} else {
$client->setUri($request_uri);
}
ob_start();
try {
$response = $client->request('GET');
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
ob_end_clean();
// Parse Google's response
if ($response->isSuccessful()) {
return true;
} else {
return false;
}
}
/**
* get token information
*
* @param string $token The token to retrieve information about
* @param Zend_Http_Client $client (optional) HTTP client to use to
* make the request
* @param string $request_uri (optional) URI to which to direct
* the information request
*/
public static function getAuthSubTokenInfo(
$token, $client = null, $request_uri = self::AUTHSUB_TOKEN_INFO_URI)
{
$client = self::getHttpClient($token, $client);
if ($client instanceof Zend_Gdata_HttpClient) {
$filterResult = $client->filterHttpRequest('GET', $request_uri);
$url = $filterResult['url'];
$headers = $filterResult['headers'];
$client->setHeaders($headers);
$client->setUri($url);
} else {
$client->setUri($request_uri);
}
ob_start();
try {
$response = $client->request('GET');
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
ob_end_clean();
return $response->getBody();
}
/**
* Retrieve a HTTP client object with AuthSub credentials attached
* as the Authorization header
*
* @param string $token The token to retrieve information about
* @param Zend_Gdata_HttpClient $client (optional) HTTP client to use to make the request
*/
public static function getHttpClient($token, $client = null)
{
if ($client == null) {
$client = new Zend_Gdata_HttpClient();
}
if (!$client instanceof Zend_Http_Client) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException('Client is not an instance of Zend_Http_Client.');
}
$useragent = 'Zend_Framework_Gdata/' . Zend_Version::VERSION;
$client->setConfig(array(
'strictredirects' => true,
'useragent' => $useragent
)
);
$client->setAuthSubToken($token);
return $client;
}
}
Gdata/HttpClient.php 0000604 00000020540 15071256135 0010355 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* Gdata Http Client object.
*
* Class to extend the generic Zend Http Client with the ability to perform
* secure AuthSub requests
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_HttpClient extends Zend_Http_Client
{
/**
* OpenSSL private key resource id
* This key is used for AuthSub authentication. If this value is set,
* it is assuemd that secure AuthSub is desired.
*
* @var resource
*/
private $_authSubPrivateKeyId = null;
/**
* Token for AuthSub authentication.
* If this token is set, AuthSub authentication is used.
*
* @var string
*/
private $_authSubToken = null;
/**
* Token for ClientLogin authentication.
* If only this token is set, ClientLogin authentication is used.
*
* @var string
*/
private $_clientLoginToken = null;
/**
* Token for ClientLogin authentication.
* If this token is set, and the AuthSub key is not set,
* ClientLogin authentication is used
*
* @var string
*/
private $_clientLoginKey = null;
/**
* Sets the PEM formatted private key, as read from a file.
*
* This method reads the file and then calls setAuthSubPrivateKey()
* with the file contents.
*
* @param string $file The location of the file containing the PEM key
* @param string $passphrase The optional private key passphrase
* @param bool $useIncludePath Whether to search the include_path
* for the file
* @return void
*/
public function setAuthSubPrivateKeyFile($file, $passphrase = null,
$useIncludePath = false) {
$fp = fopen($file, "r", $useIncludePath);
$key = '';
while (!feof($fp)) {
$key .= fread($fp, 8192);
}
$this->setAuthSubPrivateKey($key, $passphrase);
fclose($fp);
}
/**
* Sets the PEM formatted private key to be used for secure AuthSub auth.
*
* In order to call this method, openssl must be enabled in your PHP
* installation. Otherwise, a Zend_Gdata_App_InvalidArgumentException
* will be thrown.
*
* @param string $key The private key
* @param string $passphrase The optional private key passphrase
* @throws Zend_Gdata_App_InvalidArgumentException
* @return Zend_Gdata_HttpClient Provides a fluent interface
*/
public function setAuthSubPrivateKey($key, $passphrase = null) {
if ($key != null && !function_exists('openssl_pkey_get_private')) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You cannot enable secure AuthSub if the openssl module ' .
'is not enabled in your PHP installation.');
}
$this->_authSubPrivateKeyId = openssl_pkey_get_private(
$key, $passphrase);
return $this;
}
/**
* Gets the openssl private key id
*
* @return string The private key
*/
public function getAuthSubPrivateKeyId() {
return $this->_authSubPrivateKeyId;
}
/**
* Gets the AuthSub token used for authentication
*
* @return string The token
*/
public function getAuthSubToken() {
return $this->_authSubToken;
}
/**
* Sets the AuthSub token used for authentication
*
* @param string $token The token
* @return Zend_Gdata_HttpClient Provides a fluent interface
*/
public function setAuthSubToken($token) {
$this->_authSubToken = $token;
return $this;
}
/**
* Gets the ClientLogin token used for authentication
*
* @return string The token
*/
public function getClientLoginToken() {
return $this->_clientLoginToken;
}
/**
* Sets the ClientLogin token used for authentication
*
* @param string $token The token
* @return Zend_Gdata_HttpClient Provides a fluent interface
*/
public function setClientLoginToken($token) {
$this->_clientLoginToken = $token;
return $this;
}
/**
* Filters the HTTP requests being sent to add the Authorization header.
*
* If both AuthSub and ClientLogin tokens are set,
* AuthSub takes precedence. If an AuthSub key is set, then
* secure AuthSub authentication is used, and the request is signed.
* Requests must be signed only with the private key corresponding to the
* public key registered with Google. If an AuthSub key is set, but
* openssl support is not enabled in the PHP installation, an exception is
* thrown.
*
* @param string $method The HTTP method
* @param string $url The URL
* @param array $headers An associate array of headers to be
* sent with the request or null
* @param string $body The body of the request or null
* @param string $contentType The MIME content type of the body or null
* @throws Zend_Gdata_App_Exception if there was a signing failure
* @return array The processed values in an associative array,
* using the same names as the params
*/
public function filterHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null) {
if ($this->getAuthSubToken() != null) {
// AuthSub authentication
if ($this->getAuthSubPrivateKeyId() != null) {
// secure AuthSub
$time = time();
$nonce = mt_rand(0, 999999999);
$dataToSign = $method . ' ' . $url . ' ' . $time . ' ' . $nonce;
// compute signature
$pKeyId = $this->getAuthSubPrivateKeyId();
$signSuccess = openssl_sign($dataToSign, $signature, $pKeyId,
OPENSSL_ALGO_SHA1);
if (!$signSuccess) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'openssl_signing failure - returned false');
}
// encode signature
$encodedSignature = base64_encode($signature);
// final header
$headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '" ' .
'data="' . $dataToSign . '" ' .
'sig="' . $encodedSignature . '" ' .
'sigalg="rsa-sha1"';
} else {
// AuthSub without secure tokens
$headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '"';
}
} elseif ($this->getClientLoginToken() != null) {
$headers['authorization'] = 'GoogleLogin auth=' . $this->getClientLoginToken();
}
return array('method' => $method, 'url' => $url, 'body' => $body, 'headers' => $headers, 'contentType' => $contentType);
}
/**
* Method for filtering the HTTP response, though no filtering is
* currently done.
*
* @param Zend_Http_Response $response The response object to filter
* @return Zend_Http_Response The filterd response object
*/
public function filterHttpResponse($response) {
return $response;
}
}
Gdata/Gbase.php 0000604 00000013723 15071256135 0007325 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Gbase_ItemFeed
*/
require_once 'Zend/Gdata/Gbase/ItemFeed.php';
/**
* @see Zend_Gdata_Gbase_ItemEntry
*/
require_once 'Zend/Gdata/Gbase/ItemEntry.php';
/**
* @see Zend_Gdata_Gbase_SnippetEntry
*/
require_once 'Zend/Gdata/Gbase/SnippetEntry.php';
/**
* @see Zend_Gdata_Gbase_SnippetFeed
*/
require_once 'Zend/Gdata/Gbase/SnippetFeed.php';
/**
* Service class for interacting with the Google Base data API
*
* @link http://code.google.com/apis/base
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase extends Zend_Gdata
{
/**
* Path to the customer items feeds on the Google Base server.
*/
const GBASE_ITEM_FEED_URI = 'http://www.google.com/base/feeds/items';
/**
* Path to the snippets feeds on the Google Base server.
*/
const GBASE_SNIPPET_FEED_URI = 'http://www.google.com/base/feeds/snippets';
/**
* Authentication service name for Google Base
*/
const AUTH_SERVICE_NAME = 'gbase';
/**
* The default URI for POST methods
*
* @var string
*/
protected $_defaultPostUri = self::GBASE_ITEM_FEED_URI;
/**
* Namespaces used for Zend_Gdata_Gbase
*
* @var array
*/
public static $namespaces = array(
array('g', 'http://base.google.com/ns/1.0', 1, 0),
array('batch', 'http://schemas.google.com/gdata/batch', 1, 0)
);
/**
* Create Zend_Gdata_Gbase object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google Apps servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Gbase');
$this->registerPackage('Zend_Gdata_Gbase_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Retreive feed object
*
* @param mixed $location The location for the feed, as a URL or Query
* @return Zend_Gdata_Gbase_ItemFeed
*/
public function getGbaseItemFeed($location = null)
{
if ($location === null) {
$uri = self::GBASE_ITEM_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gbase_ItemFeed');
}
/**
* Retreive entry object
*
* @param mixed $location The location for the feed, as a URL or Query
* @return Zend_Gdata_Gbase_ItemEntry
*/
public function getGbaseItemEntry($location = null)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Gbase_ItemEntry');
}
/**
* Insert an entry
*
* @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to upload
* @param boolean $dryRun Flag for the 'dry-run' parameter
* @return Zend_Gdata_Gbase_ItemFeed
*/
public function insertGbaseItem($entry, $dryRun = false)
{
if ($dryRun == false) {
$uri = $this->_defaultPostUri;
} else {
$uri = $this->_defaultPostUri . '?dry-run=true';
}
$newitem = $this->insertEntry($entry, $uri, 'Zend_Gdata_Gbase_ItemEntry');
return $newitem;
}
/**
* Update an entry
*
* @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to be updated
* @param boolean $dryRun Flag for the 'dry-run' parameter
* @return Zend_Gdata_Gbase_ItemEntry
*/
public function updateGbaseItem($entry, $dryRun = false)
{
$returnedEntry = $entry->save($dryRun);
return $returnedEntry;
}
/**
* Delete an entry
*
* @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to remove
* @param boolean $dryRun Flag for the 'dry-run' parameter
* @return Zend_Gdata_Gbase_ItemFeed
*/
public function deleteGbaseItem($entry, $dryRun = false)
{
$entry->delete($dryRun);
return $this;
}
/**
* Retrieve feed object
*
* @param mixed $location The location for the feed, as a URL or Query
* @return Zend_Gdata_Gbase_SnippetFeed
*/
public function getGbaseSnippetFeed($location = null)
{
if ($location === null) {
$uri = self::GBASE_SNIPPET_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Gbase_SnippetFeed');
}
}
Gdata/Geo/Entry.php 0000604 00000004754 15071256135 0010123 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Geo
*/
require_once 'Zend/Gdata/Geo.php';
/**
* @see Zend_Gdata_Geo_Extension_GeoRssWhere
*/
require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
/**
* An Atom entry containing Geograpic data.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo_Entry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Geo_Entry';
protected $_where = null;
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Geo::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_where != null) {
$element->appendChild($this->_where->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('georss') . ':' . 'where':
$where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$where->transferFromDOM($child);
$this->_where = $where;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getWhere()
{
return $this->_where;
}
public function setWhere($value)
{
$this->_where = $value;
return $this;
}
}
Gdata/Geo/Extension/GmlPoint.php 0000604 00000007440 15071256135 0012522 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Geo
*/
require_once 'Zend/Gdata/Geo.php';
/**
* @see Zend_Gdata_Geo_Extension_GmlPos
*/
require_once 'Zend/Gdata/Geo/Extension/GmlPos.php';
/**
* Represents the gml:point element used by the Gdata Geo extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo_Extension_GmlPoint extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gml';
protected $_rootElement = 'Point';
/**
* The position represented by this GmlPoint
*
* @var Zend_Gdata_Geo_Extension_GmlPos
*/
protected $_pos = null;
/**
* Create a new instance.
*
* @param Zend_Gdata_Geo_Extension_GmlPos $pos (optional) Pos to which this
* object should be initialized.
*/
public function __construct($pos = null)
{
$this->registerAllNamespaces(Zend_Gdata_Geo::$namespaces);
parent::__construct();
$this->setPos($pos);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_pos !== null) {
$element->appendChild($this->_pos->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gml') . ':' . 'pos';
$pos = new Zend_Gdata_Geo_Extension_GmlPos();
$pos->transferFromDOM($child);
$this->_pos = $pos;
break;
}
}
/**
* Get the value for this element's pos attribute.
*
* @see setPos
* @return Zend_Gdata_Geo_Extension_GmlPos The requested attribute.
*/
public function getPos()
{
return $this->_pos;
}
/**
* Set the value for this element's distance attribute.
*
* @param Zend_Gdata_Geo_Extension_GmlPos $value The desired value for this attribute
* @return Zend_Gdata_Geo_Extension_GmlPoint Provides a fluent interface
*/
public function setPos($value)
{
$this->_pos = $value;
return $this;
}
}
Gdata/Geo/Extension/GeoRssWhere.php 0000604 00000007526 15071256135 0013173 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Geo
*/
require_once 'Zend/Gdata/Geo.php';
/**
* @see Zend_Gdata_Geo_Extension_GmlPoint
*/
require_once 'Zend/Gdata/Geo/Extension/GmlPoint.php';
/**
* Represents the georss:where element used by the Gdata Geo extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo_Extension_GeoRssWhere extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'georss';
protected $_rootElement = 'where';
/**
* The point location for this geo element
*
* @var Zend_Gdata_Geo_Extension_GmlPoint
*/
protected $_point = null;
/**
* Create a new instance.
*
* @param Zend_Gdata_Geo_Extension_GmlPoint $point (optional) Point to which
* object should be initialized.
*/
public function __construct($point = null)
{
$this->registerAllNamespaces(Zend_Gdata_Geo::$namespaces);
parent::__construct();
$this->setPoint($point);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_point !== null) {
$element->appendChild($this->_point->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gml') . ':' . 'Point';
$point = new Zend_Gdata_Geo_Extension_GmlPoint();
$point->transferFromDOM($child);
$this->_point = $point;
break;
}
}
/**
* Get the value for this element's point attribute.
*
* @see setPoint
* @return Zend_Gdata_Geo_Extension_GmlPoint The requested attribute.
*/
public function getPoint()
{
return $this->_point;
}
/**
* Set the value for this element's point attribute.
*
* @param Zend_Gdata_Geo_Extension_GmlPoint $value The desired value for this attribute.
* @return Zend_Gdata_Geo_Extension_GeoRssWhere Provides a fluent interface
*/
public function setPoint($value)
{
$this->_point = $value;
return $this;
}
}
Gdata/Geo/Extension/GmlPos.php 0000604 00000003163 15071256135 0012170 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Geo
*/
require_once 'Zend/Gdata/Geo.php';
/**
* Represents the gml:pos element used by the Gdata Geo extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo_Extension_GmlPos extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gml';
protected $_rootElement = 'pos';
/**
* Constructs a new Zend_Gdata_Geo_Extension_GmlPos object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Geo::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Geo/Feed.php 0000604 00000003043 15071256135 0007653 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata_eed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Geo
*/
require_once 'Zend/Gdata/Geo.php';
/**
* @see Zend_Gdata_Geo_Entry
*/
require_once 'Zend/Gdata/Geo/Entry.php';
/**
* Feed for Gdata Geographic data entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo_Feed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Geo_Entry';
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Geo::$namespaces);
parent::__construct($element);
}
}
Gdata/Extension/Visibility.php 0000604 00000006712 15071256135 0012407 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent an entry's visibility
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Visibility extends Zend_Gdata_Extension
{
protected $_rootElement = 'visibility';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_Visibility object.
* @param bool $value (optional) Visibility value as URI.
*/
public function __construct($value = null)
{
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return bool The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Visibility The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Extension/Where.php 0000604 00000010630 15071256135 0011324 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension_EntryLink
*/
require_once 'Zend/Gdata/Extension/EntryLink.php';
/**
* Data model class to represent a location (gd:where element)
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Where extends Zend_Gdata_Extension
{
protected $_rootElement = 'where';
protected $_label = null;
protected $_rel = null;
protected $_valueString = null;
protected $_entryLink = null;
public function __construct($valueString = null, $label = null, $rel = null, $entryLink = null)
{
parent::__construct();
$this->_valueString = $valueString;
$this->_label = $label;
$this->_rel = $rel;
$this->_entryLink = $entryLink;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_label !== null) {
$element->setAttribute('label', $this->_label);
}
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_valueString !== null) {
$element->setAttribute('valueString', $this->_valueString);
}
if ($this->entryLink !== null) {
$element->appendChild($this->_entryLink->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'label':
$this->_label = $attribute->nodeValue;
break;
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
case 'valueString':
$this->_valueString = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'entryLink':
$entryLink = new Zend_Gdata_Extension_EntryLink();
$entryLink->transferFromDOM($child);
$this->_entryLink = $entryLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function __toString()
{
if ($this->_valueString != null) {
return $this->_valueString;
}
else {
return parent::__toString();
}
}
public function getLabel()
{
return $this->_label;
}
public function setLabel($value)
{
$this->_label = $value;
return $this;
}
public function getRel()
{
return $this->_rel;
}
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
public function getValueString()
{
return $this->_valueString;
}
public function setValueString($value)
{
$this->_valueString = $value;
return $this;
}
public function getEntryLink()
{
return $this->_entryLink;
}
public function setEntryLink($value)
{
$this->_entryLink = $value;
return $this;
}
}
Gdata/Extension/Comments.php 0000604 00000006037 15071256135 0012045 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* Represents the gd:comments element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Comments extends Zend_Gdata_Extension
{
protected $_rootElement = 'comments';
protected $_rel = null;
protected $_feedLink = null;
public function __construct($rel = null, $feedLink = null)
{
parent::__construct();
$this->_rel = $rel;
$this->_feedLink = $feedLink;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_feedLink !== null) {
$element->appendChild($this->_feedLink->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'feedLink';
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink = $feedLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
public function getRel()
{
return $this->_rel;
}
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
public function getFeedLink()
{
return $this->_feedLink;
}
public function setFeedLink($value)
{
$this->_feedLink = $value;
return $this;
}
}
Gdata/Extension/AttendeeType.php 0000604 00000006754 15071256135 0012661 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent an attendee's type (gd:attendeeType)
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_AttendeeType extends Zend_Gdata_Extension
{
protected $_rootElement = 'attendeeType';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_AttendeeType object.
* @param string $value (optional) This entry's 'value' attribute.
*/
public function __construct($value = null)
{
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return string The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Visibility The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Extension/ExtendedProperty.php 0000604 00000005260 15071256135 0013562 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model for gd:extendedProperty element, used by some Gdata
* services to implement arbitrary name/value pair storage
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_ExtendedProperty extends Zend_Gdata_Extension
{
protected $_rootElement = 'extendedProperty';
protected $_name = null;
protected $_value = null;
public function __construct($name = null, $value = null)
{
parent::__construct();
$this->_name = $name;
$this->_value = $value;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_name !== null) {
$element->setAttribute('name', $this->_name);
}
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'name':
$this->_name = $attribute->nodeValue;
break;
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
public function __toString()
{
return $this->getName() . '=' . $this->getValue();
}
public function getName()
{
return $this->_name;
}
public function setName($value)
{
$this->_name = $value;
return $this;
}
public function getValue()
{
return $this->_value;
}
public function setValue($value)
{
$this->_value = $value;
return $this;
}
}
Gdata/Extension/Rating.php 0000604 00000015261 15071256135 0011503 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Implements the gd:rating element
*
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Rating extends Zend_Gdata_Extension
{
protected $_rootElement = 'rating';
protected $_min = null;
protected $_max = null;
protected $_numRaters = null;
protected $_average = null;
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_Rating object.
*
* @param integer $average (optional) Average rating.
* @param integer $min (optional) Minimum rating.
* @param integer $max (optional) Maximum rating.
* @param integer $numRaters (optional) Number of raters.
* @param integer $value (optional) The value of the rating.
*/
public function __construct($average = null, $min = null,
$max = null, $numRaters = null, $value = null)
{
parent::__construct();
$this->_average = $average;
$this->_min = $min;
$this->_max = $max;
$this->_numRaters = $numRaters;
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_min !== null) {
$element->setAttribute('min', $this->_min);
}
if ($this->_max !== null) {
$element->setAttribute('max', $this->_max);
}
if ($this->_numRaters !== null) {
$element->setAttribute('numRaters', $this->_numRaters);
}
if ($this->_average !== null) {
$element->setAttribute('average', $this->_average);
}
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'min':
$this->_min = $attribute->nodeValue;
break;
case 'max':
$this->_max = $attribute->nodeValue;
break;
case 'numRaters':
$this->_numRaters = $attribute->nodeValue;
break;
case 'average':
$this->_average = $attribute->nodeValue;
break;
case 'value':
$this->_value = $atttribute->nodeValue;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's min attribute.
*
* @return integer The requested attribute.
*/
public function getMin()
{
return $this->_min;
}
/**
* Set the value for this element's min attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Rating The element being modified.
*/
public function setMin($value)
{
$this->_min = $value;
return $this;
}
/**
* Get the value for this element's numRaters attribute.
*
* @return integer The requested attribute.
*/
public function getNumRaters()
{
return $this->_numRaters;
}
/**
* Set the value for this element's numRaters attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Rating The element being modified.
*/
public function setNumRaters($value)
{
$this->_numRaters = $value;
return $this;
}
/**
* Get the value for this element's average attribute.
*
* @return integer The requested attribute.
*/
public function getAverage()
{
return $this->_average;
}
/**
* Set the value for this element's average attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Rating The element being modified.
*/
public function setAverage($value)
{
$this->_average = $value;
return $this;
}
/**
* Get the value for this element's max attribute.
*
* @return integer The requested attribute.
*/
public function getMax()
{
return $this->_max;
}
/**
* Set the value for this element's max attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Rating The element being modified.
*/
public function setMax($value)
{
$this->_max = $value;
return $this;
}
/**
* Get the value for this element's value attribute.
*
* @return integer The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Rating The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
}
Gdata/Extension/AttendeeStatus.php 0000604 00000006757 15071256135 0013226 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent an attendee's status (gd:attendeeStatus)
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_AttendeeStatus extends Zend_Gdata_Extension
{
protected $_rootElement = 'attendeeStatus';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_AttendeeStatus object.
* @param string $value (optional) Visibility value as URI.
*/
public function __construct($value = null)
{
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return string The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Visibility The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Extension/Who.php 0000604 00000021777 15071256135 0011025 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension_AttendeeStatus
*/
require_once 'Zend/Gdata/Extension/AttendeeStatus.php';
/**
* @see Zend_Gdata_Extension_AttendeeType
*/
require_once 'Zend/Gdata/Extension/AttendeeType.php';
/**
* @see Zend_Gdata_Extension_EntryLink
*/
require_once 'Zend/Gdata/Extension/EntryLink.php';
/**
* Data model class to represent a participant
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Who extends Zend_Gdata_Extension
{
protected $_rootElement = 'who';
protected $_email = null;
protected $_rel = null;
protected $_valueString = null;
protected $_attendeeStatus = null;
protected $_attendeeType = null;
protected $_entryLink = null;
/**
* Constructs a new Zend_Gdata_Extension_Who object.
* @param string $email (optional) Email address.
* @param string $rel (optional) Relationship description.
* @param string $valueString (optional) Simple string describing this person.
* @param Zend_Gdata_Extension_AttendeeStatus $attendeeStatus (optional) The status of the attendee.
* @param Zend_Gdata_Extension_AttendeeType $attendeeType (optional) The type of the attendee.
* @param string $entryLink URL pointing to an associated entry (Contact kind) describing this person.
*/
public function __construct($email = null, $rel = null, $valueString = null,
$attendeeStatus = null, $attendeeType = null, $entryLink = null)
{
parent::__construct();
$this->_email = $email;
$this->_rel = $rel;
$this->_valueString = $valueString;
$this->_attendeeStatus = $attendeeStatus;
$this->_attendeeType = $attendeeType;
$this->_entryLink = $entryLink;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_email !== null) {
$element->setAttribute('email', $this->_email);
}
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_valueString !== null) {
$element->setAttribute('valueString', $this->_valueString);
}
if ($this->_attendeeStatus !== null) {
$element->appendChild($this->_attendeeStatus->getDOM($element->ownerDocument));
}
if ($this->_attendeeType !== null) {
$element->appendChild($this->_attendeeType->getDOM($element->ownerDocument));
}
if ($this->_entryLink !== null) {
$element->appendChild($this->_entryLink->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'email':
$this->_email = $attribute->nodeValue;
break;
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
case 'valueString':
$this->_valueString = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'attendeeStatus':
$attendeeStatus = new Zend_Gdata_Extension_AttendeeStatus();
$attendeeStatus->transferFromDOM($child);
$this->_attendeeStatus = $attendeeStatus;
break;
case $this->lookupNamespace('gd') . ':' . 'attendeeType':
$attendeeType = new Zend_Gdata_Extension_AttendeeType();
$attendeeType->transferFromDOM($child);
$this->_attendeeType = $attendeeType;
break;
case $this->lookupNamespace('gd') . ':' . 'entryLink':
$entryLink = new Zend_Gdata_Extension_EntryLink();
$entryLink->transferFromDOM($child);
$this->_entryLink = $entryLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Retrieves a human readable string describing this attribute's value.
*
* @return string The attribute value.
*/
public function __toString()
{
if ($this->_valueString != null) {
return $this->_valueString;
}
else {
return parent::__toString();
}
}
/**
* Get the value for this element's ValueString attribute.
*
* @return string The requested attribute.
*/
public function getValueString()
{
return $this->_valueString;
}
/**
* Set the value for this element's ValueString attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setValueString($value)
{
$this->_valueString = $value;
return $this;
}
/**
* Get the value for this element's Email attribute.
*
* @return string The requested attribute.
*/
public function getEmail()
{
return $this->_email;
}
/**
* Set the value for this element's Email attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setEmail($value)
{
$this->_email = $value;
return $this;
}
/**
* Get the value for this element's Rel attribute.
*
* @return string The requested attribute.
*/
public function getRel()
{
return $this->_rel;
}
/**
* Set the value for this element's Rel attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
/**
* Get this entry's AttendeeStatus element.
*
* @return Zend_Gdata_Extension_AttendeeStatus The requested entry.
*/
public function getAttendeeStatus()
{
return $this->_attendeeStatus;
}
/**
* Set the child's AttendeeStatus element.
*
* @param Zend_Gdata_Extension_AttendeeStatus $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setAttendeeStatus($value)
{
$this->_attendeeStatus = $value;
return $this;
}
/**
* Get this entry's AttendeeType element.
*
* @return Zend_Gdata_Extension_AttendeeType The requested entry.
*/
public function getAttendeeType()
{
return $this->_attendeeType;
}
/**
* Set the child's AttendeeType element.
*
* @param Zend_Gdata_Extension_AttendeeType $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Who The element being modified.
*/
public function setAttendeeType($value)
{
$this->_attendeeType = $value;
return $this;
}
}
Gdata/Extension/OpenSearchItemsPerPage.php 0000604 00000002532 15071256135 0014551 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the openSearch:itemsPerPage element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_OpenSearchItemsPerPage extends Zend_Gdata_Extension
{
protected $_rootElement = 'itemsPerPage';
protected $_rootNamespace = 'openSearch';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/Extension/FeedLink.php 0000604 00000011027 15071256135 0011734 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Represents the gd:feedLink element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_FeedLink extends Zend_Gdata_Extension
{
protected $_rootElement = 'feedLink';
protected $_countHint = null;
protected $_href = null;
protected $_readOnly = null;
protected $_rel = null;
protected $_feed = null;
public function __construct($href = null, $rel = null,
$countHint = null, $readOnly = null, $feed = null)
{
parent::__construct();
$this->_countHint = $countHint;
$this->_href = $href;
$this->_readOnly = $readOnly;
$this->_rel = $rel;
$this->_feed = $feed;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_countHint !== null) {
$element->setAttribute('countHint', $this->_countHint);
}
if ($this->_href !== null) {
$element->setAttribute('href', $this->_href);
}
if ($this->_readOnly !== null) {
$element->setAttribute('readOnly', ($this->_readOnly ? "true" : "false"));
}
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_feed !== null) {
$element->appendChild($this->_feed->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'feed';
$feed = new Zend_Gdata_Feed();
$feed->transferFromDOM($child);
$this->_feed = $feed;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'countHint':
$this->_countHint = $attribute->nodeValue;
break;
case 'href':
$this->_href = $attribute->nodeValue;
break;
case 'readOnly':
if ($attribute->nodeValue == "true") {
$this->_readOnly = true;
}
else if ($attribute->nodeValue == "false") {
$this->_readOnly = false;
}
else {
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getHref()
{
return $this->_href;
}
public function setHref($value)
{
$this->_href = $value;
return $this;
}
public function getReadOnly()
{
return $this->_readOnly;
}
public function setReadOnly($value)
{
$this->_readOnly = $value;
return $this;
}
public function getRel()
{
return $this->_rel;
}
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
public function getFeed()
{
return $this->_feed;
}
public function setFeed($value)
{
$this->_feed = $value;
return $this;
}
}
Gdata/Extension/RecurrenceException.php 0000604 00000015463 15071256135 0014237 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension_EntryLink
*/
require_once 'Zend/Gdata/Extension/EntryLink.php';
/**
* @see Zend_Gdata_Extension_OriginalEvent
*/
require_once 'Zend/Gdata/Extension/OriginalEvent.php';
/**
* Data model class to represent an entry's recurrenceException
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_RecurrenceException extends Zend_Gdata_Extension
{
protected $_rootElement = 'recurrenceException';
protected $_specialized = null;
protected $_entryLink = null;
protected $_originalEvent = null;
/**
* Constructs a new Zend_Gdata_Extension_RecurrenceException object.
* @param bool $specialized (optional) Whether this is a specialized exception or not.
* @param Zend_Gdata_EntryLink (optional) An Event entry with details about the exception.
* @param Zend_Gdata_OriginalEvent (optional) The origianl recurrent event this is an exeption to.
*/
public function __construct($specialized = null, $entryLink = null,
$originalEvent = null)
{
parent::__construct();
$this->_specialized = $specialized;
$this->_entryLink = $entryLink;
$this->_originalEvent = $originalEvent;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_specialized !== null) {
$element->setAttribute('specialized', ($this->_specialized ? "true" : "false"));
}
if ($this->_entryLink !== null) {
$element->appendChild($this->_entryLink->getDOM($element->ownerDocument));
}
if ($this->_originalEvent !== null) {
$element->appendChild($this->_originalEvent->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'specialized':
if ($attribute->nodeValue == "true") {
$this->_specialized = true;
}
else if ($attribute->nodeValue == "false") {
$this->_specialized = false;
}
else {
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'entryLink':
$entryLink = new Zend_Gdata_Extension_EntryLink();
$entryLink->transferFromDOM($child);
$this->_entryLink = $entryLink;
break;
case $this->lookupNamespace('gd') . ':' . 'originalEvent':
$originalEvent = new Zend_Gdata_Extension_OriginalEvent();
$originalEvent->transferFromDOM($child);
$this->_originalEvent = $originalEvent;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's Specialized attribute.
*
* @return bool The requested attribute.
*/
public function getSpecialized()
{
return $this->_specialized;
}
/**
* Set the value for this element's Specialized attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_RecurrenceException The element being modified.
*/
public function setSpecialized($value)
{
$this->_specialized = $value;
return $this;
}
/**
* Get the value for this element's EntryLink attribute.
*
* @return Zend_Gdata_Extension_EntryLink The requested attribute.
*/
public function getEntryLink()
{
return $this->_entryLink;
}
/**
* Set the value for this element's EntryLink attribute.
*
* @param Zend_Gdata_Extension_EntryLink $value The desired value for this attribute.
* @return Zend_Gdata_Extension_RecurrenceException The element being modified.
*/
public function setEntryLink($value)
{
$this->_entryLink = $value;
return $this;
}
/**
* Get the value for this element's Specialized attribute.
*
* @return Zend_Gdata_Extension_OriginalEvent The requested attribute.
*/
public function getOriginalEvent()
{
return $this->_originalEvent;
}
/**
* Set the value for this element's Specialized attribute.
*
* @param Zend_Gdata_Extension_OriginalEvent $value The desired value for this attribute.
* @return Zend_Gdata_Extension_RecurrenceException The element being modified.
*/
public function setOriginalEvent($value)
{
$this->_originalEvent = $value;
return $this;
}
}
Gdata/Extension/Recurrence.php 0000604 00000002424 15071256135 0012351 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gd:recurrence element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Recurrence extends Zend_Gdata_Extension
{
protected $_rootElement = 'recurrence';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/Extension/OpenSearchStartIndex.php 0000604 00000002523 15071256135 0014311 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the openSeach:startIndex element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_OpenSearchStartIndex extends Zend_Gdata_Extension
{
protected $_rootElement = 'startIndex';
protected $_rootNamespace = 'openSearch';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/Extension/Reminder.php 0000604 00000010616 15071256135 0012023 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Implements the gd:reminder element used to set/retrieve notifications
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Reminder extends Zend_Gdata_Extension
{
protected $_rootElement = 'reminder';
protected $_absoluteTime = null;
protected $_method = null;
protected $_days = null;
protected $_hours = null;
protected $_minutes = null;
public function __construct($absoluteTime = null, $method = null, $days = null,
$hours = null, $minutes = null)
{
parent::__construct();
$this->_absoluteTime = $absoluteTime;
$this->_method = $method;
$this->_days = $days;
$this->_hours = $hours;
$this->_minutes = $minutes;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_absoluteTime !== null) {
$element->setAttribute('absoluteTime', $this->_absoluteTime);
}
if ($this->_method !== null) {
$element->setAttribute('method', $this->_method);
}
if ($this->_days !== null) {
$element->setAttribute('days', $this->_days);
}
if ($this->_hours !== null) {
$element->setAttribute('hours', $this->_hours);
}
if ($this->_minutes !== null) {
$element->setAttribute('minutes', $this->_minutes);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'absoluteTime':
$this->_absoluteTime = $attribute->nodeValue;
break;
case 'method':
$this->_method = $attribute->nodeValue;
break;
case 'days':
$this->_days = $attribute->nodeValue;
break;
case 'hours':
$this->_hours = $attribute->nodeValue;
break;
case 'minutes':
$this->_minutes = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
public function __toString()
{
$s;
if ($absoluteTime)
$s = "at" . $absoluteTime;
else if ($days)
$s = "in" . $days . "days";
else if ($hours)
$s = "in" . $hours . "hours";
else if ($minutes)
$s = "in" . $minutes . "minutes";
return $method . $s;
}
public function getAbsoluteTime()
{
return $this->_absoluteTime;
}
public function setAbsoluteTime($value)
{
$this->_absoluteTime = $value;
return $this;
}
public function getDays()
{
return $this->_days;
}
public function setDays($value)
{
$this->_days = $value;
return $this;
}
public function getHours()
{
return $this->_hours;
}
public function setHours($value)
{
$this->_hours = $value;
return $this;
}
public function getMinutes()
{
return $this->_minutes;
}
public function setMinutes($value)
{
$this->_minutes = $value;
return $this;
}
public function getMethod()
{
return $this->_method;
}
public function setMethod($value)
{
$this->_method = $value;
return $this;
}
}
Gdata/Extension/EventStatus.php 0000604 00000005116 15071256135 0012542 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gd:eventStatus element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_EventStatus extends Zend_Gdata_Extension
{
protected $_rootElement = 'eventStatus';
protected $_value = null;
public function __construct($value = null)
{
parent::__construct();
$this->_value = $value;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return string The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Visibility The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Extension/When.php 0000604 00000010741 15071256135 0011156 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension_Reminder
*/
require_once 'Zend/Gdata/Extension/Reminder.php';
/**
* Represents the gd:when element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_When extends Zend_Gdata_Extension
{
protected $_rootElement = 'when';
protected $_reminders = array();
protected $_startTime = null;
protected $_valueString = null;
protected $_endTime = null;
public function __construct($startTime = null, $endTime = null,
$valueString = null, $reminders = null)
{
parent::__construct();
$this->_startTime = $startTime;
$this->_endTime = $endTime;
$this->_valueString = $valueString;
$this->_reminders = $reminders;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_startTime !== null) {
$element->setAttribute('startTime', $this->_startTime);
}
if ($this->_endTime !== null) {
$element->setAttribute('endTime', $this->_endTime);
}
if ($this->_valueString !== null) {
$element->setAttribute('valueString', $this->_valueString);
}
if ($this->_reminders !== null) {
foreach ($this->_reminders as $reminder) {
$element->appendChild(
$reminder->getDOM($element->ownerDocument));
}
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'reminder';
$reminder = new Zend_Gdata_Extension_Reminder();
$reminder->transferFromDOM($child);
$this->_reminders[] = $reminder;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'startTime':
$this->_startTime = $attribute->nodeValue;
break;
case 'endTime':
$this->_endTime = $attribute->nodeValue;
break;
case 'valueString':
$this->_valueString = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
public function __toString()
{
if ($valueString)
return $valueString;
else {
return 'Starts: ' . $this->getStartTime() . ' ' .
'Ends: ' . $this->getEndTime();
}
}
public function getStartTime()
{
return $this->_startTime;
}
public function setStartTime($value)
{
$this->_startTime = $value;
return $this;
}
public function getEndTime()
{
return $this->_endTime;
}
public function setEndTime($value)
{
$this->_endTime = $value;
return $this;
}
public function getValueString()
{
return $this->_valueString;
}
public function setValueString($value)
{
$this->_valueString = $value;
return $this;
}
public function getReminders()
{
return $this->_reminders;
}
public function setReminders($value)
{
$this->_reminders = $value;
return $this;
}
}
Gdata/Extension/Transparency.php 0000604 00000006725 15071256135 0012735 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent an entry's transparency
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_Transparency extends Zend_Gdata_Extension
{
protected $_rootElement = 'transparency';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_Transparency object.
* @param bool $value (optional) Transparency value as URI
*/
public function __construct($value = null)
{
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return bool The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Extension_Transparency The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Extension/OpenSearchTotalResults.php 0000604 00000002532 15071256135 0014671 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the openSearch:totalResults element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_OpenSearchTotalResults extends Zend_Gdata_Extension
{
protected $_rootElement = 'totalResults';
protected $_rootNamespace = 'openSearch';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/Extension/OriginalEvent.php 0000604 00000006703 15071256135 0013026 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_When
*/
require_once 'Zend/Gdata/Extension/When.php';
/**
* Represents the gd:originalEvent element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_OriginalEvent extends Zend_Gdata_Extension
{
protected $_rootElement = 'originalEvent';
protected $_id = null;
protected $_href = null;
protected $_when = null;
public function __construct($id = null, $href = null, $when = null)
{
parent::__construct();
$this->_id = $id;
$this->_href = $href;
$this->_when = $when;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_id !== null) {
$element->setAttribute('id', $this->_id);
}
if ($this->_href !== null) {
$element->setAttribute('href', $this->_href);
}
if ($this->_when !== null) {
$element->appendChild($this->_when->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'id':
$this->_id = $attribute->nodeValue;
break;
case 'href':
$this->_href = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'when';
$when = new Zend_Gdata_Extension_When();
$when->transferFromDOM($child);
$this->_when = $when;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getId()
{
return $this->_id;
}
public function setId($value)
{
$this->_id = $value;
return $this;
}
public function getHref()
{
return $this->_href;
}
public function setHref($value)
{
$this->_href = $value;
return $this;
}
public function getWhen()
{
return $this->_when;
}
public function setWhen($value)
{
$this->_when = $value;
return $this;
}
}
Gdata/Extension/EntryLink.php 0000604 00000010363 15071256135 0012174 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* Represents the gd:entryLink element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Extension_EntryLink extends Zend_Gdata_Extension
{
protected $_rootElement = 'entryLink';
protected $_href = null;
protected $_readOnly = null;
protected $_rel = null;
protected $_entry = null;
public function __construct($href = null, $rel = null,
$readOnly = null, $entry = null)
{
parent::__construct();
$this->_href = $href;
$this->_readOnly = $readOnly;
$this->_rel = $rel;
$this->_entry = $entry;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_href !== null) {
$element->setAttribute('href', $this->_href);
}
if ($this->_readOnly !== null) {
$element->setAttribute('readOnly', ($this->_readOnly ? "true" : "false"));
}
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_entry !== null) {
$element->appendChild($this->_entry->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'entry';
$entry = new Zend_Gdata_Entry();
$entry->transferFromDOM($child);
$this->_entry = $entry;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'href':
$this->_href = $attribute->nodeValue;
break;
case 'readOnly':
if ($attribute->nodeValue == "true") {
$this->_readOnly = true;
}
else if ($attribute->nodeValue == "false") {
$this->_readOnly = false;
}
else {
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getHref()
{
return $this->_href;
}
public function setHref($value)
{
$this->_href = $value;
return $this;
}
public function getReadOnly()
{
return $this->_readOnly;
}
public function setReadOnly($value)
{
$this->_readOnly = $value;
return $this;
}
public function getRel()
{
return $this->_rel;
}
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
public function getEntry()
{
return $this->_entry;
}
public function setEntry($value)
{
$this->_entry = $value;
return $this;
}
}
Gdata/Health/ProfileEntry.php 0000604 00000007777 15071256135 0012147 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Health_Extension_Ccr
*/
require_once 'Zend/Gdata/Health/Extension/Ccr.php';
/**
* Concrete class for working with Health profile entries.
*
* @link http://code.google.com/apis/health/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_ProfileEntry extends Zend_Gdata_Entry
{
/**
* The classname for individual profile entry elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Health_ProfileEntry';
/**
* Google Health CCR data
*
* @var Zend_Gdata_Health_Extension_Ccr
*/
protected $_ccrData = null;
/**
* Constructs a new Zend_Gdata_Health_ProfileEntry object.
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) {
$this->registerNamespace($nsPrefix, $nsUri);
}
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_ccrData !== null) {
$element->appendChild($this->_ccrData->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
if (strstr($absoluteNodeName, $this->lookupNamespace('ccr') . ':')) {
$ccrElement = new Zend_Gdata_Health_Extension_Ccr();
$ccrElement->transferFromDOM($child);
$this->_ccrData = $ccrElement;
} else {
parent::takeChildFromDOM($child);
}
}
/**
* Sets the profile entry's CCR data
* @param string $ccrXMLStr The CCR as an xml string
* @return Zend_Gdata_Health_Extension_Ccr
*/
public function setCcr($ccrXMLStr) {
$ccrElement = null;
if ($ccrXMLStr != null) {
$ccrElement = new Zend_Gdata_Health_Extension_Ccr();
$ccrElement->transferFromXML($ccrXMLStr);
$this->_ccrData = $ccrElement;
}
return $ccrElement;
}
/**
* Returns all the CCR data in a profile entry
* @return Zend_Gdata_Health_Extension_Ccr
*/
public function getCcr() {
return $this->_ccrData;
}
}
Gdata/Health/ProfileFeed.php 0000604 00000003533 15071256135 0011673 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Represents a Google Health user's Profile Feed
*
* @link http://code.google.com/apis/health/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_ProfileFeed extends Zend_Gdata_Feed
{
/**
* The class name for individual profile feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Health_ProfileEntry';
/**
* Creates a Health Profile feed, representing a user's Health profile
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) {
$this->registerNamespace($nsPrefix, $nsUri);
}
parent::__construct($element);
}
public function getEntries()
{
return $this->entry;
}
}
Gdata/Health/Extension/Ccr.php 0000604 00000010253 15071256135 0012167 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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: Ccr.php 13122 2008-12-10 02:45:49Z tjohns $
*/
/**
* @see Zend_Gdata_App_Extension_Element
*/
require_once 'Zend/Gdata/App/Extension/Element.php';
/**
* Concrete class for working with CCR elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_Extension_Ccr extends Zend_Gdata_App_Extension_Element
{
protected $_rootNamespace = 'ccr';
protected $_rootElement = 'ContinuityOfCareRecord';
protected $_ccrDom = null;
/**
* Creates a Zend_Gdata_Health_Extension_Ccr entry, representing CCR data
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) {
$this->registerNamespace($nsPrefix, $nsUri);
}
}
/**
* Transfers each child and attribute into member variables.
* This is called when XML is received over the wire and the data
* model needs to be built to represent this XML.
*
* @param DOMNode $node The DOMNode that represents this object's data
*/
public function transferFromDOM($node)
{
$this->_ccrDom = $node;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
if (is_null($doc)) {
$doc = new DOMDocument('1.0', 'utf-8');
}
$domElement = $doc->importNode($this->_ccrDom, true);
return $domElement;
}
/**
* Magic helper that allows drilling down and returning specific elements
* in the CCR. For example, to retrieve the users medications
* (/ContinuityOfCareRecord/Body/Medications) from the entry's CCR, call
* $entry->getCcr()->getMedications(). Similarly, getConditions() would
* return extract the user's conditions.
*
* @param string $name Name of the function to call
* @return array.<DOMElement> A list of the appropriate CCR data
*/
public function __call($name, $args)
{
$matches = array();
if (substr($name, 0, 3) === 'get') {
$category = substr($name, 3);
switch ($category) {
case 'Conditions':
$category = 'Problems';
break;
case 'Allergies':
$category = 'Alerts';
break;
case 'TestResults':
// TestResults is an alias for LabResults
case 'LabResults':
$category = 'Results';
break;
default:
// $category is already well formatted
}
return $this->_ccrDom->getElementsByTagNameNS($this->lookupNamespace('ccr'), $category);
} else {
return null;
}
}
}
Gdata/Health/ProfileListFeed.php 0000604 00000002636 15071256135 0012532 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Represents a Google Health user's Profile List Feed
*
* @link http://code.google.com/apis/health/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_ProfileListFeed extends Zend_Gdata_Feed
{
/**
* The class name for individual profile feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Health_ProfileListEntry';
public function getEntries()
{
return $this->entry;
}
}
Gdata/Health/Query.php 0000604 00000020565 15071256135 0010620 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Health
*
* @link http://code.google.com/apis/health
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_Query extends Zend_Gdata_Query
{
/**
* URI of a user's profile feed.
*/
const HEALTH_PROFILE_FEED_URI =
'https://www.google.com/health/feeds/profile/default';
/**
* URI of register (notices) feed.
*/
const HEALTH_REGISTER_FEED_URI =
'https://www.google.com/health/feeds/register/default';
/**
* Namespace for an item category
*/
const ITEM_CATEGORY_NS = 'http://schemas.google.com/health/item';
/**
* The default URI for POST methods
*
* @var string
*/
protected $_defaultFeedUri = self::HEALTH_PROFILE_FEED_URI;
/**
* Sets the digest parameter's value.
*
* @param string $value
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setDigest($value)
{
if ($value !== null) {
$this->_params['digest'] = $value;
}
return $this;
}
/**
* Returns the digest parameter's value.
*
* @return string The value set for the digest parameter.
*/
public function getDigest()
{
if (array_key_exists('digest', $this->_params)) {
return $this->_params['digest'];
} else {
return null;
}
}
/**
* Setter for category queries.
*
* @param string $item A category to query.
* @param string $name (optional) A specific item to search a category for.
* An example would be 'Lipitor' if $item is set to 'medication'.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setCategory($item, $name = null)
{
$this->_category = $item .
($name ? '/' . urlencode('{' . self::ITEM_CATEGORY_NS . '}' . $name) : null);
return $this;
}
/**
* Returns the query object's category.
*
* @return string id
*/
public function getCategory()
{
return $this->_category;
}
/**
* Setter for the grouped parameter.
*
* @param string $value setting a count of results per group.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setGrouped($value)
{
if ($value !== null) {
$this->_params['grouped'] = $value;
}
return $this;
}
/**
* Returns the value set for the grouped parameter.
*
* @return string grouped parameter.
*/
public function getGrouped()
{
if (array_key_exists('grouped', $this->_params)) {
return $this->_params['grouped'];
} else {
return null;
}
}
/**
* Setter for the max-results-group parameter.
*
* @param int $value Specifies the maximum number of groups to be
* retrieved. Must be an integer value greater than zero. This parameter
* is only valid if grouped=true.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setMaxResultsGroup($value)
{
if ($value !== null) {
if ($value <= 0 || $this->getGrouped() !== 'true') {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'The max-results-group parameter must be set to a value
greater than 0 and can only be used if grouped=true');
} else {
$this->_params['max-results-group'] = $value;
}
}
return $this;
}
/**
* Returns the value set for max-results-group.
*
* @return int Returns max-results-group parameter.
*/
public function getMaxResultsGroup()
{
if (array_key_exists('max-results-group', $this->_params)) {
return $this->_params['max-results-group'];
} else {
return null;
}
}
/**
* Setter for the max-results-group parameter.
*
* @param int $value Specifies the maximum number of records to be
* retrieved from each group. The limits that you specify with this
* parameter apply to all groups. Must be an integer value greater than
* zero. This parameter is only valid if grouped=true.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setMaxResultsInGroup($value)
{
if ($value !== null) {
if ($value <= 0 || $this->getGrouped() !== 'true') {
throw new Zend_Gdata_App_InvalidArgumentException(
'The max-results-in-group parameter must be set to a value
greater than 0 and can only be used if grouped=true');
} else {
$this->_params['max-results-in-group'] = $value;
}
}
return $this;
}
/**
* Returns the value set for max-results-in-group.
*
* @return int Returns max-results-in-group parameter.
*/
public function getMaxResultsInGroup()
{
if (array_key_exists('max-results-in-group', $this->_params)) {
return $this->_params['max-results-in-group'];
} else {
return null;
}
}
/**
* Setter for the start-index-group parameter.
*
* @param int $value Retrieves only items whose group ranking is at
* least start-index-group. This should be set to a 1-based index of the
* first group to be retrieved. The range is applied per category.
* This parameter is only valid if grouped=true.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setStartIndexGroup($value)
{
if ($value !== null && $this->getGrouped() !== 'true') {
throw new Zend_Gdata_App_InvalidArgumentException(
'The start-index-group can only be used if grouped=true');
} else {
$this->_params['start-index-group'] = $value;
}
return $this;
}
/**
* Returns the value set for start-index-group.
*
* @return int Returns start-index-group parameter.
*/
public function getStartIndexGroup()
{
if (array_key_exists('start-index-group', $this->_params)) {
return $this->_params['start-index-group'];
} else {
return null;
}
}
/**
* Setter for the start-index-in-group parameter.
*
* @param int $value A 1-based index of the records to be retrieved from
* each group. This parameter is only valid if grouped=true.
* @return Zend_Gdata_Health_Query Provides a fluent interface
*/
public function setStartIndexInGroup($value)
{
if ($value !== null && $this->getGrouped() !== 'true') {
throw new Zend_Gdata_App_InvalidArgumentException('start-index-in-group');
} else {
$this->_params['start-index-in-group'] = $value;
}
return $this;
}
/**
* Returns the value set for start-index-in-group.
*
* @return int Returns start-index-in-group parameter.
*/
public function getStartIndexInGroup()
{
if (array_key_exists('start-index-in-group', $this->_params)) {
return $this->_params['start-index-in-group'];
} else {
return null;
}
}
}
Gdata/Health/ProfileListEntry.php 0000604 00000005722 15071256135 0012767 0 ustar 00 <?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_Gdata
* @subpackage Health
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* Concrete class for working with Health profile list entries.
*
* @link http://code.google.com/apis/health/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Health
* @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_Gdata_Health_ProfileListEntry extends Zend_Gdata_Entry
{
/**
* The classname for individual profile list entry elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Health_ProfileListEntry';
/**
* Constructs a new Zend_Gdata_Health_ProfileListEntry object.
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
parent::takeChildFromDOM($child);
}
/**
* Retrieves the profile ID for the entry, which is contained in <atom:content>
* @return string The profile id
*/
public function getProfileID() {
return $this->getContent()->text;
}
/**
* Retrieves the profile's title, which is contained in <atom:title>
* @return string The profile name
*/
public function getProfileName() {
return $this->getTitle()->text;
}
}
Gdata/Media/Entry.php 0000604 00000007403 15071256135 0010422 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Media
*/
require_once 'Zend/Gdata/Media.php';
/**
* @see Zend_Gdata_Media_Extension_MediaGroup
*/
require_once 'Zend/Gdata/Media/Extension/MediaGroup.php';
/**
* Represents the Gdata flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Entry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Media_Entry';
/**
* media:group element
*
* @var Zend_Gdata_Media_Extension_MediaGroup
*/
protected $_mediaGroup = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_mediaGroup != null) {
$element->appendChild($this->_mediaGroup->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('media') . ':' . 'group':
$mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup();
$mediaGroup->transferFromDOM($child);
$this->_mediaGroup = $mediaGroup;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Returns the entry's mediaGroup object.
*
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function getMediaGroup()
{
return $this->_mediaGroup;
}
/**
* Sets the entry's mediaGroup object.
*
* @param Zend_Gdata_Media_Extension_MediaGroup $mediaGroup
* @return Zend_Gdata_Media_Entry Provides a fluent interface
*/
public function setMediaGroup($mediaGroup)
{
$this->_mediaGroup = $mediaGroup;
return $this;
}
}
Gdata/Media/Extension/MediaDescription.php 0000604 00000006312 15071256135 0014516 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:description element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaDescription extends Zend_Gdata_Extension
{
protected $_rootElement = 'description';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_type = null;
/**
* @param string $text
* @param string $type
*/
public function __construct($text = null, $type = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_type = $type;
$this->_text = $text;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'type':
$this->_type = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaDescription Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
}
Gdata/Media/Extension/MediaCategory.php 0000604 00000010543 15071256135 0014011 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:category element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaCategory extends Zend_Gdata_Extension
{
protected $_rootElement = 'category';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_scheme = null;
protected $_label = null;
/**
* Creates an individual MediaCategory object.
*
* @param string $text Indication of the type and content of the media
* @param string $scheme URI that identifies the categorization scheme
* @param string $label Human-readable label to be displayed in applications
*/
public function __construct($text = null, $scheme = null, $label = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_scheme = $scheme;
$this->_label = $label;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
if ($this->_label !== null) {
$element->setAttribute('label', $this->_label);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
case 'label':
$this->_label = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the URI that identifies the categorization scheme
* Optional.
*
* @return string URI that identifies the categorization scheme
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string $value URI that identifies the categorization scheme
* @return Zend_Gdata_Media_Extension_MediaCategory Provides a fluent interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
/**
* @return string Human-readable label to be displayed in applications
*/
public function getLabel()
{
return $this->_label;
}
/**
* @param string $value Human-readable label to be displayed in applications
* @return Zend_Gdata_Media_Extension_MediaCategory Provides a fluent interface
*/
public function setLabel($value)
{
$this->_label = $value;
return $this;
}
}
Gdata/Media/Extension/MediaPlayer.php 0000604 00000010740 15071256135 0013467 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:player element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaPlayer extends Zend_Gdata_Extension
{
protected $_rootElement = 'player';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_url = null;
/**
* @var int
*/
protected $_width = null;
/**
* @var int
*/
protected $_height = null;
/**
* Constructs a new MediaPlayer element
*
* @param string $url
* @param int $width
* @param int $height
*/
public function __construct($url = null, $width = null, $height = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_url = $url;
$this->_width = $width;
$this->_height = $height;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_url !== null) {
$element->setAttribute('url', $this->_url);
}
if ($this->_width !== null) {
$element->setAttribute('width', $this->_width);
}
if ($this->_height !== null) {
$element->setAttribute('height', $this->_height);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'url':
$this->_url = $attribute->nodeValue;
break;
case 'width':
$this->_width = $attribute->nodeValue;
break;
case 'height':
$this->_height = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getUrl()
{
return $this->_url;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaPlayer Provides a fluent interface
*/
public function setUrl($value)
{
$this->_url = $value;
return $this;
}
/**
* @return int
*/
public function getWidth()
{
return $this->_width;
}
/**
* @param int $value
* @return Zend_Gdata_Media_Extension_MediaPlayer Provides a fluent interface
*/
public function setWidth($value)
{
$this->_width = $value;
return $this;
}
/**
* @return int
*/
public function getHeight()
{
return $this->_height;
}
/**
* @param int $value
* @return Zend_Gdata_Media_Extension_MediaPlayer Provides a fluent interface
*/
public function setHeight($value)
{
$this->_height = $value;
return $this;
}
}
Gdata/Media/Extension/MediaContent.php 0000604 00000030726 15071256135 0013653 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the media:content element of Media RSS.
* Represents media objects. Multiple media objects representing
* the same content can be represented using a
* media:group (Zend_Gdata_Media_Extension_MediaGroup) element.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaContent extends Zend_Gdata_Extension
{
protected $_rootElement = 'content';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_url = null;
/**
* @var int
*/
protected $_fileSize = null;
/**
* @var string
*/
protected $_type = null;
/**
* @var string
*/
protected $_medium = null;
/**
* @var string
*/
protected $_isDefault = null;
/**
* @var string
*/
protected $_expression = null;
/**
* @var int
*/
protected $_bitrate = null;
/**
* @var int
*/
protected $_framerate = null;
/**
* @var int
*/
protected $_samplingrate = null;
/**
* @var int
*/
protected $_channels = null;
/**
* @var int
*/
protected $_duration = null;
/**
* @var int
*/
protected $_height = null;
/**
* @var int
*/
protected $_width = null;
/**
* @var string
*/
protected $_lang = null;
/**
* Creates an individual MediaContent object.
*/
public function __construct($url = null, $fileSize = null, $type = null,
$medium = null, $isDefault = null, $expression = null,
$bitrate = null, $framerate = null, $samplingrate = null,
$channels = null, $duration = null, $height = null, $width = null,
$lang = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_url = $url;
$this->_fileSize = $fileSize;
$this->_type = $type;
$this->_medium = $medium;
$this->_isDefault = $isDefault;
$this->_expression = $expression;
$this->_bitrate = $bitrate;
$this->_framerate = $framerate;
$this->_samplingrate = $samplingrate;
$this->_channels = $channels;
$this->_duration = $duration;
$this->_height = $height;
$this->_width = $width;
$this->_lang = $lang;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_url !== null) {
$element->setAttribute('url', $this->_url);
}
if ($this->_fileSize !== null) {
$element->setAttribute('fileSize', $this->_fileSize);
}
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
if ($this->_medium !== null) {
$element->setAttribute('medium', $this->_medium);
}
if ($this->_isDefault !== null) {
$element->setAttribute('isDefault', $this->_isDefault);
}
if ($this->_expression !== null) {
$element->setAttribute('expression', $this->_expression);
}
if ($this->_bitrate !== null) {
$element->setAttribute('bitrate', $this->_bitrate);
}
if ($this->_framerate !== null) {
$element->setAttribute('framerate', $this->_framerate);
}
if ($this->_samplingrate !== null) {
$element->setAttribute('samplingrate', $this->_samplingrate);
}
if ($this->_channels !== null) {
$element->setAttribute('channels', $this->_channels);
}
if ($this->_duration !== null) {
$element->setAttribute('duration', $this->_duration);
}
if ($this->_height !== null) {
$element->setAttribute('height', $this->_height);
}
if ($this->_width !== null) {
$element->setAttribute('width', $this->_width);
}
if ($this->_lang !== null) {
$element->setAttribute('lang', $this->_lang);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'url':
$this->_url = $attribute->nodeValue;
break;
case 'fileSize':
$this->_fileSize = $attribute->nodeValue;
break;
case 'type':
$this->_type = $attribute->nodeValue;
break;
case 'medium':
$this->_medium = $attribute->nodeValue;
break;
case 'isDefault':
$this->_isDefault = $attribute->nodeValue;
break;
case 'expression':
$this->_expression = $attribute->nodeValue;
break;
case 'bitrate':
$this->_bitrate = $attribute->nodeValue;
break;
case 'framerate':
$this->_framerate = $attribute->nodeValue;
break;
case 'samplingrate':
$this->_samplingrate = $attribute->nodeValue;
break;
case 'channels':
$this->_channels = $attribute->nodeValue;
break;
case 'duration':
$this->_duration = $attribute->nodeValue;
break;
case 'height':
$this->_height = $attribute->nodeValue;
break;
case 'width':
$this->_width = $attribute->nodeValue;
break;
case 'lang':
$this->_lang = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the URL representing this MediaContent object
*
* @return string The URL representing this MediaContent object.
*/
public function __toString()
{
return $this->getUrl();
}
/**
* @return string The direct URL to the media object
*/
public function getUrl()
{
return $this->_url;
}
/**
* @param string $value The direct URL to the media object
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setUrl($value)
{
$this->_url = $value;
return $this;
}
/**
* @return int The size of the media in bytes
*/
public function getFileSize()
{
return $this->_fileSize;
}
/**
* @param int $value
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setFileSize($value)
{
$this->_fileSize = $value;
return $this;
}
/**
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
/**
* @return string
*/
public function getMedium()
{
return $this->_medium;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setMedium($value)
{
$this->_medium = $value;
return $this;
}
/**
* @return bool
*/
public function getIsDefault()
{
return $this->_isDefault;
}
/**
* @param bool $value
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setIsDefault($value)
{
$this->_isDefault = $value;
return $this;
}
/**
* @return string
*/
public function getExpression()
{
return $this->_expression;
}
/**
* @param string
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setExpression($value)
{
$this->_expression = $value;
return $this;
}
/**
* @return int
*/
public function getBitrate()
{
return $this->_bitrate;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setBitrate($value)
{
$this->_bitrate = $value;
return $this;
}
/**
* @return int
*/
public function getFramerate()
{
return $this->_framerate;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setFramerate($value)
{
$this->_framerate = $value;
return $this;
}
/**
* @return int
*/
public function getSamplingrate()
{
return $this->_samplingrate;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setSamplingrate($value)
{
$this->_samplingrate = $value;
return $this;
}
/**
* @return int
*/
public function getChannels()
{
return $this->_channels;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setChannels($value)
{
$this->_channels = $value;
return $this;
}
/**
* @return int
*/
public function getDuration()
{
return $this->_duration;
}
/**
*
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setDuration($value)
{
$this->_duration = $value;
return $this;
}
/**
* @return int
*/
public function getHeight()
{
return $this->_height;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setHeight($value)
{
$this->_height = $value;
return $this;
}
/**
* @return int
*/
public function getWidth()
{
return $this->_width;
}
/**
* @param int
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setWidth($value)
{
$this->_width = $value;
return $this;
}
/**
* @return string
*/
public function getLang()
{
return $this->_lang;
}
/**
* @param string
* @return Zend_Gdata_Media_Extension_MediaContent Provides a fluent interface
*/
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
}
Gdata/Media/Extension/MediaRestriction.php 0000604 00000010025 15071256135 0014534 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:restriction element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaRestriction extends Zend_Gdata_Extension
{
protected $_rootElement = 'restriction';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_relationship = null;
/**
* @var string
*/
protected $_type = null;
/**
* Constructs a new MediaRestriction element
*
* @param string $text
* @param string $relationship
* @param string $type
*/
public function __construct($text = null, $relationship = null, $type = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_relationship = $relationship;
$this->_type = $type;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_relationship !== null) {
$element->setAttribute('relationship', $this->_relationship);
}
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'relationship':
$this->_relationship = $attribute->nodeValue;
break;
case 'type':
$this->_type = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getRelationship()
{
return $this->_relationship;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaRestriction Provides a fluent interface
*/
public function setRelationship($value)
{
$this->_relationship = $value;
return $this;
}
/**
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaRestriction Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
}
Gdata/Media/Extension/MediaTitle.php 0000604 00000006354 15071256135 0013322 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:title element in MediaRSS
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaTitle extends Zend_Gdata_Extension
{
protected $_rootElement = 'title';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_type = null;
/**
* Constructs a MediaTitle element
*
* @param string $text
* @param string $type
*/
public function __construct($text = null, $type = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_type = $type;
$this->_text = $text;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'type':
$this->_type = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaTitle Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
}
Gdata/Media/Extension/MediaHash.php 0000604 00000006373 15071256135 0013125 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:hash element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaHash extends Zend_Gdata_Extension
{
protected $_rootElement = 'hash';
protected $_rootNamespace = 'media';
protected $_algo = null;
/**
* Constructs a new MediaHash element
*
* @param string $text
* @param string $algo
*/
public function __construct($text = null, $algo = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_algo = $algo;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_algo !== null) {
$element->setAttribute('algo', $this->_algo);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
* @throws Zend_Gdata_App_InvalidArgumentException
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'algo':
$this->_algo = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string The algo
*/
public function getAlgo()
{
return $this->_algo;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaHash Provides a fluent interface
*/
public function setAlgo($value)
{
$this->_algo = $value;
return $this;
}
}
Gdata/Media/Extension/MediaGroup.php 0000604 00000035403 15071256135 0013332 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Media_Extension_MediaContent
*/
require_once 'Zend/Gdata/Media/Extension/MediaContent.php';
/**
* @see Zend_Gdata_Media_Extension_MediaCategory
*/
require_once 'Zend/Gdata/Media/Extension/MediaCategory.php';
/**
* @see Zend_Gdata_Media_Extension_MediaCopyright
*/
require_once 'Zend/Gdata/Media/Extension/MediaCopyright.php';
/**
* @see Zend_Gdata_Media_Extension_MediaCredit
*/
require_once 'Zend/Gdata/Media/Extension/MediaCredit.php';
/**
* @see Zend_Gdata_Media_Extension_MediaDescription
*/
require_once 'Zend/Gdata/Media/Extension/MediaDescription.php';
/**
* @see Zend_Gdata_Media_Extension_MediaHash
*/
require_once 'Zend/Gdata/Media/Extension/MediaHash.php';
/**
* @see Zend_Gdata_Media_Extension_MediaKeywords
*/
require_once 'Zend/Gdata/Media/Extension/MediaKeywords.php';
/**
* @see Zend_Gdata_Media_Extension_MediaPlayer
*/
require_once 'Zend/Gdata/Media/Extension/MediaPlayer.php';
/**
* @see Zend_Gdata_Media_Extension_MediaRating
*/
require_once 'Zend/Gdata/Media/Extension/MediaRating.php';
/**
* @see Zend_Gdata_Media_Extension_MediaRestriction
*/
require_once 'Zend/Gdata/Media/Extension/MediaRestriction.php';
/**
* @see Zend_Gdata_Media_Extension_MediaText
*/
require_once 'Zend/Gdata/Media/Extension/MediaText.php';
/**
* @see Zend_Gdata_Media_Extension_MediaThumbnail
*/
require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
/**
* @see Zend_Gdata_Media_Extension_MediaTitle
*/
require_once 'Zend/Gdata/Media/Extension/MediaTitle.php';
/**
* This class represents the media:group element of Media RSS.
* It allows the grouping of media:content elements that are
* different representations of the same content. When it exists,
* it is a child of an Entry (Atom) or Item (RSS).
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaGroup extends Zend_Gdata_Extension
{
protected $_rootElement = 'group';
protected $_rootNamespace = 'media';
/**
* @var array
*/
protected $_content = array();
/**
* @var array
*/
protected $_category = array();
/**
* @var Zend_Gdata_Media_Extension_MediaCopyright
*/
protected $_copyright = null;
/**
* @var array
*/
protected $_credit = array();
/**
* @var Zend_Gdata_Media_Extension_MediaDescription
*/
protected $_description = null;
/**
* @var array
*/
protected $_hash = array();
/**
* @var Zend_Gdata_Media_Extension_MediaKeywords
*/
protected $_keywords = null;
/**
* @var array
*/
protected $_player = array();
/**
* @var array
*/
protected $_rating = array();
/**
* @var array
*/
protected $_restriction = array();
/**
* @var array
*/
protected $_mediaText = array();
/**
* @var array
*/
protected $_thumbnail = array();
/**
* @var string
*/
protected $_title = null;
/**
* Creates an individual MediaGroup object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
foreach ($this->_content as $content) {
$element->appendChild($content->getDOM($element->ownerDocument));
}
foreach ($this->_category as $category) {
$element->appendChild($category->getDOM($element->ownerDocument));
}
foreach ($this->_credit as $credit) {
$element->appendChild($credit->getDOM($element->ownerDocument));
}
foreach ($this->_player as $player) {
$element->appendChild($player->getDOM($element->ownerDocument));
}
foreach ($this->_rating as $rating) {
$element->appendChild($rating->getDOM($element->ownerDocument));
}
foreach ($this->_restriction as $restriction) {
$element->appendChild($restriction->getDOM($element->ownerDocument));
}
foreach ($this->_mediaText as $text) {
$element->appendChild($text->getDOM($element->ownerDocument));
}
foreach ($this->_thumbnail as $thumbnail) {
$element->appendChild($thumbnail->getDOM($element->ownerDocument));
}
if ($this->_copyright != null) {
$element->appendChild(
$this->_copyright->getDOM($element->ownerDocument));
}
if ($this->_description != null) {
$element->appendChild(
$this->_description->getDOM($element->ownerDocument));
}
foreach ($this->_hash as $hash) {
$element->appendChild($hash->getDOM($element->ownerDocument));
}
if ($this->_keywords != null) {
$element->appendChild(
$this->_keywords->getDOM($element->ownerDocument));
}
if ($this->_title != null) {
$element->appendChild(
$this->_title->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('media') . ':' . 'content';
$content = new Zend_Gdata_Media_Extension_MediaContent();
$content->transferFromDOM($child);
$this->_content[] = $content;
break;
case $this->lookupNamespace('media') . ':' . 'category';
$category = new Zend_Gdata_Media_Extension_MediaCategory();
$category->transferFromDOM($child);
$this->_category[] = $category;
break;
case $this->lookupNamespace('media') . ':' . 'copyright';
$copyright = new Zend_Gdata_Media_Extension_MediaCopyright();
$copyright->transferFromDOM($child);
$this->_copyright = $copyright;
break;
case $this->lookupNamespace('media') . ':' . 'credit';
$credit = new Zend_Gdata_Media_Extension_MediaCredit();
$credit->transferFromDOM($child);
$this->_credit[] = $credit;
break;
case $this->lookupNamespace('media') . ':' . 'description';
$description = new Zend_Gdata_Media_Extension_MediaDescription();
$description->transferFromDOM($child);
$this->_description = $description;
break;
case $this->lookupNamespace('media') . ':' . 'hash';
$hash = new Zend_Gdata_Media_Extension_MediaHash();
$hash->transferFromDOM($child);
$this->_hash[] = $hash;
break;
case $this->lookupNamespace('media') . ':' . 'keywords';
$keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
$keywords->transferFromDOM($child);
$this->_keywords = $keywords;
break;
case $this->lookupNamespace('media') . ':' . 'player';
$player = new Zend_Gdata_Media_Extension_MediaPlayer();
$player->transferFromDOM($child);
$this->_player[] = $player;
break;
case $this->lookupNamespace('media') . ':' . 'rating';
$rating = new Zend_Gdata_Media_Extension_MediaRating();
$rating->transferFromDOM($child);
$this->_rating[] = $rating;
break;
case $this->lookupNamespace('media') . ':' . 'restriction';
$restriction = new Zend_Gdata_Media_Extension_MediaRestriction();
$restriction->transferFromDOM($child);
$this->_restriction[] = $restriction;
break;
case $this->lookupNamespace('media') . ':' . 'text';
$text = new Zend_Gdata_Media_Extension_MediaText();
$text->transferFromDOM($child);
$this->_mediaText[] = $text;
break;
case $this->lookupNamespace('media') . ':' . 'thumbnail';
$thumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
$thumbnail->transferFromDOM($child);
$this->_thumbnail[] = $thumbnail;
break;
case $this->lookupNamespace('media') . ':' . 'title';
$title = new Zend_Gdata_Media_Extension_MediaTitle();
$title->transferFromDOM($child);
$this->_title = $title;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @return array
*/
public function getContent()
{
return $this->_content;
}
/**
* @param array $value
* @return Zend_Gdata_Media_MediaGroup Provides a fluent interface
*/
public function setContent($value)
{
$this->_content = $value;
return $this;
}
/**
* @return array
*/
public function getCategory()
{
return $this->_category;
}
/**
* @param array $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setCategory($value)
{
$this->_category = $value;
return $this;
}
/**
* @return Zend_Gdata_Media_Extension_MediaCopyright
*/
public function getCopyright()
{
return $this->_copyright;
}
/**
* @param Zend_Gdata_Media_Extension_MediaCopyright $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setCopyright($value)
{
$this->_copyright = $value;
return $this;
}
/**
* @return array
*/
public function getCredit()
{
return $this->_credit;
}
/**
* @param array $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setCredit($value)
{
$this->_credit = $value;
return $this;
}
/**
* @return Zend_Gdata_Media_Extension_MediaTitle
*/
public function getTitle()
{
return $this->_title;
}
/**
* @param Zend_Gdata_Media_Extension_MediaTitle $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
/**
* @return Zend_Gdata_Media_Extension_MediaDescription
*/
public function getDescription()
{
return $this->_description;
}
/**
* @param Zend_Gdata_Media_Extension_MediaDescription $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setDescription($value)
{
$this->_description = $value;
return $this;
}
/**
* @return array
*/
public function getHash()
{
return $this->_hash;
}
/**
* @param array $value
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setHash($value)
{
$this->_hash = $value;
return $this;
}
/**
* @return Zend_Gdata_Media_Extension_MediaKeywords
*/
public function getKeywords()
{
return $this->_keywords;
}
/**
* @param array $value
* @return Zend_Gdata_Media_Extension_MediaGroup Provides a fluent interface
*/
public function setKeywords($value)
{
$this->_keywords = $value;
return $this;
}
/**
* @return array
*/
public function getPlayer()
{
return $this->_player;
}
/**
* @param array
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setPlayer($value)
{
$this->_player = $value;
return $this;
}
/**
* @return array
*/
public function getRating()
{
return $this->_rating;
}
/**
* @param array
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setRating($value)
{
$this->_rating = $value;
return $this;
}
/**
* @return array
*/
public function getRestriction()
{
return $this->_restriction;
}
/**
* @param array
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setRestriction($value)
{
$this->_restriction = $value;
return $this;
}
/**
* @return array
*/
public function getThumbnail()
{
return $this->_thumbnail;
}
/**
* @param array
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setThumbnail($value)
{
$this->_thumbnail = $value;
return $this;
}
/**
* @return array
*/
public function getMediaText()
{
return $this->_mediaText;
}
/**
* @param array
* @return Zend_Gdata_Media_Extension_MediaGroup
*/
public function setMediaText($value)
{
$this->_mediaText = $value;
return $this;
}
}
Gdata/Media/Extension/MediaKeywords.php 0000604 00000002645 15071256135 0014047 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:keywords element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaKeywords extends Zend_Gdata_Extension
{
protected $_rootElement = 'keywords';
protected $_rootNamespace = 'media';
/**
* Constructs a new MediaKeywords element
*/
public function __construct()
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
}
}
Gdata/Media/Extension/MediaThumbnail.php 0000604 00000012242 15071256135 0014155 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:thumbnail element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaThumbnail extends Zend_Gdata_Extension
{
protected $_rootElement = 'thumbnail';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_url = null;
/**
* @var int
*/
protected $_width = null;
/**
* @var int
*/
protected $_height = null;
/**
* @var string
*/
protected $_time = null;
/**
* Constructs a new MediaThumbnail element
*
* @param string $url
* @param int $width
* @param int $height
* @param string $time
*/
public function __construct($url = null, $width = null, $height = null,
$time = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_url = $url;
$this->_width = $width;
$this->_height = $height;
$this->_time = $time ;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_url !== null) {
$element->setAttribute('url', $this->_url);
}
if ($this->_width !== null) {
$element->setAttribute('width', $this->_width);
}
if ($this->_height !== null) {
$element->setAttribute('height', $this->_height);
}
if ($this->_time !== null) {
$element->setAttribute('time', $this->_time);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'url':
$this->_url = $attribute->nodeValue;
break;
case 'width':
$this->_width = $attribute->nodeValue;
break;
case 'height':
$this->_height = $attribute->nodeValue;
break;
case 'time':
$this->_time = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getUrl()
{
return $this->_url;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaThumbnail Provides a fluent interface
*/
public function setUrl($value)
{
$this->_url = $value;
return $this;
}
/**
* @return int
*/
public function getWidth()
{
return $this->_width;
}
/**
* @param int $value
* @return Zend_Gdata_Media_Extension_MediaThumbnail Provides a fluent interface
*/
public function setWidth($value)
{
$this->_width = $value;
return $this;
}
/**
* @return int
*/
public function getHeight()
{
return $this->_height;
}
/**
* @param int $value
* @return Zend_Gdata_Media_Extension_MediaThumbnail Provides a fluent interface
*/
public function setHeight($value)
{
$this->_height = $value;
return $this;
}
/**
* @return string
*/
public function getTime()
{
return $this->_time;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaThumbnail Provides a fluent interface
*/
public function setTime($value)
{
$this->_time = $value;
return $this;
}
}
Gdata/Media/Extension/MediaCopyright.php 0000604 00000006264 15071256135 0014211 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:copyright element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaCopyright extends Zend_Gdata_Extension
{
protected $_rootElement = 'copyright';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_url = null;
/**
* @param string $text
* @param string $url
*/
public function __construct($text = null, $url = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_url = $url;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_url !== null) {
$element->setAttribute('url', $this->_url);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'url':
$this->_url = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getUrl()
{
return $this->_url;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCopyright Provides a fluent interface
*/
public function setUrl($value)
{
$this->_url = $value;
return $this;
}
}
Gdata/Media/Extension/MediaRating.php 0000604 00000006405 15071256135 0013462 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:rating element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaRating extends Zend_Gdata_Extension
{
protected $_rootElement = 'rating';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_scheme = null;
/**
* Constructs a new MediaRating element
*
* @param string $text
* @param string $scheme
*/
public function __construct($text = null, $scheme = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_scheme = $scheme;
$this->_text = $text;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaRating Provides a fluent interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
}
Gdata/Media/Extension/MediaCredit.php 0000604 00000007650 15071256135 0013453 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:credit element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaCredit extends Zend_Gdata_Extension
{
protected $_rootElement = 'credit';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_role = null;
/**
* @var string
*/
protected $_scheme = null;
/**
* Creates an individual MediaCredit object.
*
* @param string $text
* @param string $role
* @param string $scheme
*/
public function __construct($text = null, $role = null, $scheme = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_role = $role;
$this->_scheme = $scheme;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_role !== null) {
$element->setAttribute('role', $this->_role);
}
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'role':
$this->_role = $attribute->nodeValue;
break;
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getRole()
{
return $this->_role;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCredit Provides a fluent interface
*/
public function setRole($value)
{
$this->_role = $value;
return $this;
}
/**
* @return string
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCredit Provides a fluent interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
}
Gdata/Media/Extension/MediaText.php 0000604 00000012273 15071256135 0013162 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the media:text element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Extension_MediaText extends Zend_Gdata_Extension
{
protected $_rootElement = 'text';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_type = null;
/**
* @var string
*/
protected $_lang = null;
/**
* @var string
*/
protected $_start = null;
/**
* @var string
*/
protected $_end = null;
/**
* Constructs a new MediaText element
*
* @param $text string
* @param $type string
* @param $lang string
* @param $start string
* @param $end string
*/
public function __construct($text = null, $type = null, $lang = null,
$start = null, $end = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_type = $type;
$this->_lang = $lang;
$this->_start = $start;
$this->_end = $end;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
if ($this->_lang !== null) {
$element->setAttribute('lang', $this->_lang);
}
if ($this->_start !== null) {
$element->setAttribute('start', $this->_start);
}
if ($this->_end !== null) {
$element->setAttribute('end', $this->_end);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'type':
$this->_type = $attribute->nodeValue;
break;
case 'lang':
$this->_lang = $attribute->nodeValue;
break;
case 'start':
$this->_start = $attribute->nodeValue;
break;
case 'end':
$this->_end = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaText Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
/**
* @return string
*/
public function getLang()
{
return $this->_lang;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaText Provides a fluent interface
*/
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
/**
* @return string
*/
public function getStart()
{
return $this->_start;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaText Provides a fluent interface
*/
public function setStart($value)
{
$this->_start = $value;
return $this;
}
/**
* @return string
*/
public function getEnd()
{
return $this->_end;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaText Provides a fluent interface
*/
public function setEnd($value)
{
$this->_end = $value;
return $this;
}
}
Gdata/Media/Feed.php 0000604 00000003354 15071256135 0010165 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_eed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Media
*/
require_once 'Zend/Gdata/Media.php';
/**
* @see Zend_Gdata_Media_Entry
*/
require_once 'Zend/Gdata/Media/Entry.php';
/**
* The Gdata flavor of an Atom Feed with media support
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media_Feed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Media_Entry';
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct($element);
}
}
Gdata/Docs.php 0000604 00000022274 15071256135 0007175 0 ustar 00 <?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_Gdata
* @subpackage Docs
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Docs_DocumentListFeed
*/
require_once 'Zend/Gdata/Docs/DocumentListFeed.php';
/**
* @see Zend_Gdata_Docs_DocumentListEntry
*/
require_once 'Zend/Gdata/Docs/DocumentListEntry.php';
/**
* Service class for interacting with the Google Document List data API
* @link http://code.google.com/apis/documents/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Docs
* @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_Gdata_Docs extends Zend_Gdata
{
const DOCUMENTS_LIST_FEED_URI = 'http://docs.google.com/feeds/documents/private/full';
const AUTH_SERVICE_NAME = 'writely';
protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI;
private static $SUPPORTED_FILETYPES = array(
'CSV'=>'text/csv',
'DOC'=>'application/msword',
'ODS'=>'application/vnd.oasis.opendocument.spreadsheet',
'ODT'=>'application/vnd.oasis.opendocument.text',
'RTF'=>'application/rtf',
'SXW'=>'application/vnd.sun.xml.writer',
'TXT'=>'text/plain',
'XLS'=>'application/vnd.ms-excel');
/**
* Create Gdata_Docs object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Docs');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Looks up the mime type based on the file name extension. For example,
* calling this method with 'csv' would return
* 'text/comma-separated-values'. The Mime type is sent as a header in
* the upload HTTP POST request.
*
* @param string $fileExtension
* @return string The mime type to be sent to the server to tell it how the
* multipart mime data should be interpreted.
*/
public static function lookupMimeType($fileExtension) {
return self::$SUPPORTED_FILETYPES[strtoupper($fileExtension)];
}
/**
* Retreive feed object containing entries for the user's documents.
*
* @param mixed $location The location for the feed, as a URL or Query
* @return Zend_Gdata_Docs_DocumentListFeed
*/
public function getDocumentListFeed($location = null)
{
if ($location === null) {
$uri = self::DOCUMENTS_LIST_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Docs_DocumentListFeed');
}
/**
* Retreive entry object representing a single document.
*
* @param mixed $location The location for the entry, as a URL or Query
* @return Zend_Gdata_Docs_DocumentListEntry
*/
public function getDocumentListEntry($location = null)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Docs_DocumentListEntry');
}
/**
* Retreive entry object representing a single document.
*
* This method builds the URL where this item is stored using the type
* and the id of the document.
* @param string $docId The URL key for the document. Examples:
* dcmg89gw_62hfjj8m, pKq0CzjiF3YmGd0AIlHKqeg
* @param string $docType The type of the document as used in the Google
* Document List URLs. Examples: document, spreadsheet, presentation
* @return Zend_Gdata_Docs_DocumentListEntry
*/
public function getDoc($docId, $docType) {
$location = 'http://docs.google.com/feeds/documents/private/full/' .
$docType . '%3A' . $docId;
return $this->getDocumentListEntry($location);
}
/**
* Retreive entry object for the desired word processing document.
*
* @param string $id The URL id for the document. Example:
* dcmg89gw_62hfjj8m
*/
public function getDocument($id) {
return $this->getDoc($id, 'document');
}
/**
* Retreive entry object for the desired spreadsheet.
*
* @param string $id The URL id for the document. Example:
* pKq0CzjiF3YmGd0AIlHKqeg
*/
public function getSpreadsheet($id) {
return $this->getDoc($id, 'spreadsheet');
}
/**
* Retreive entry object for the desired presentation.
*
* @param string $id The URL id for the document. Example:
* dcmg89gw_21gtrjcn
*/
public function getPresentation($id) {
return $this->getDoc($id, 'presentation');
}
/**
* Upload a local file to create a new Google Document entry.
*
* @param string $fileLocation The full or relative path of the file to
* be uploaded.
* @param string $title The name that this document should have on the
* server. If set, the title is used as the slug header in the
* POST request. If no title is provided, the location of the
* file will be used as the slug header in the request. If no
* mimeType is provided, this method attempts to determine the
* mime type based on the slugHeader by looking for .doc,
* .csv, .txt, etc. at the end of the file name.
* Example value: 'test.doc'.
* @param string $mimeType Describes the type of data which is being sent
* to the server. This must be one of the accepted mime types
* which are enumerated in SUPPORTED_FILETYPES.
* @param string $uri (optional) The URL to which the upload should be
* made.
* Example: 'http://docs.google.com/feeds/documents/private/full'.
* @return Zend_Gdata_Docs_DocumentListEntry The entry for the newly
* created Google Document.
*/
public function uploadFile($fileLocation, $title=null, $mimeType=null,
$uri=null)
{
// Set the URI to which the file will be uploaded.
if ($uri === null) {
$uri = $this->_defaultPostUri;
}
// Create the media source which describes the file.
$fs = $this->newMediaFileSource($fileLocation);
if ($title !== null) {
$slugHeader = $title;
} else {
$slugHeader = $fileLocation;
}
// Set the slug header to tell the Google Documents server what the
// title of the document should be and what the file extension was
// for the original file.
$fs->setSlug($slugHeader);
// Set the mime type of the data.
if ($mimeType === null) {
$slugHeader = $fs->getSlug();
$filenameParts = explode('.', $slugHeader);
$fileExtension = end($filenameParts);
$mimeType = self::lookupMimeType($fileExtension);
}
// Set the mime type for the upload request.
$fs->setContentType($mimeType);
// Send the data to the server.
return $this->insertDocument($fs, $uri);
}
/**
* Inserts an entry to a given URI and returns the response as an Entry.
*
* @param mixed $data The Zend_Gdata_Docs_DocumentListEntry or media
* source to post. If it is a DocumentListEntry, the mediaSource
* should already have been set. If $data is a mediaSource, it
* should have the correct slug header and mime type.
* @param string $uri POST URI
* @param string $className (optional) The class of entry to be returned.
* The default is a 'Zend_Gdata_Docs_DocumentListEntry'.
* @return Zend_Gdata_Docs_DocumentListEntry The entry returned by the
* service after insertion.
*/
public function insertDocument($data, $uri,
$className='Zend_Gdata_Docs_DocumentListEntry')
{
return $this->insertEntry($data, $uri, $className);
}
}
Gdata/Query.php 0000604 00000022740 15071256135 0007410 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Util
*/
require_once 'Zend/Gdata/App/Util.php';
/**
* Provides a mechanism to build a query URL for Gdata services.
* Queries are not defined for APP, but are provided by Gdata services
* as an extension.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Query
{
/**
* Query parameters.
*
* @var array
*/
protected $_params = array();
/**
* Default URL
*
* @var string
*/
protected $_defaultFeedUri = null;
/**
* Base URL
* TODO: Add setters and getters
*
* @var string
*/
protected $_url = null;
/**
* Category for the query
*
* @var string
*/
protected $_category = null;
/**
* Create Gdata_Query object
*/
public function __construct($url = null)
{
$this->_url = $url;
}
/**
* @return string querystring
*/
public function getQueryString()
{
$queryArray = array();
foreach ($this->_params as $name => $value) {
if (substr($name, 0, 1) == '_') {
continue;
}
$queryArray[] = urlencode($name) . '=' . urlencode($value);
}
if (count($queryArray) > 0) {
return '?' . implode('&', $queryArray);
} else {
return '';
}
}
/**
*
*/
public function resetParameters()
{
$this->_params = array();
}
/**
* @return string url
*/
public function getQueryUrl()
{
if ($this->_url == null) {
$url = $this->_defaultFeedUri;
} else {
$url = $this->_url;
}
if ($this->getCategory() !== null) {
$url .= '/-/' . $this->getCategory();
}
$url .= $this->getQueryString();
return $url;
}
/**
* @param string $name
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setParam($name, $value)
{
$this->_params[$name] = $value;
return $this;
}
/**
* @param string $name
*/
public function getParam($name)
{
return $this->_params[$name];
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setAlt($value)
{
if ($value != null) {
$this->_params['alt'] = $value;
} else {
unset($this->_params['alt']);
}
return $this;
}
/**
* @param int $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setMaxResults($value)
{
if ($value != null) {
$this->_params['max-results'] = $value;
} else {
unset($this->_params['max-results']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setQuery($value)
{
if ($value != null) {
$this->_params['q'] = $value;
} else {
unset($this->_params['q']);
}
return $this;
}
/**
* @param int $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setStartIndex($value)
{
if ($value != null) {
$this->_params['start-index'] = $value;
} else {
unset($this->_params['start-index']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setUpdatedMax($value)
{
if ($value != null) {
$this->_params['updated-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['updated-max']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setUpdatedMin($value)
{
if ($value != null) {
$this->_params['updated-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['updated-min']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setPublishedMax($value)
{
if ($value !== null) {
$this->_params['published-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['published-max']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setPublishedMin($value)
{
if ($value != null) {
$this->_params['published-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['published-min']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setAuthor($value)
{
if ($value != null) {
$this->_params['author'] = $value;
} else {
unset($this->_params['author']);
}
return $this;
}
/**
* @return string rss or atom
*/
public function getAlt()
{
if (array_key_exists('alt', $this->_params)) {
return $this->_params['alt'];
} else {
return null;
}
}
/**
* @return int maxResults
*/
public function getMaxResults()
{
if (array_key_exists('max-results', $this->_params)) {
return intval($this->_params['max-results']);
} else {
return null;
}
}
/**
* @return string query
*/
public function getQuery()
{
if (array_key_exists('q', $this->_params)) {
return $this->_params['q'];
} else {
return null;
}
}
/**
* @return int startIndex
*/
public function getStartIndex()
{
if (array_key_exists('start-index', $this->_params)) {
return intval($this->_params['start-index']);
} else {
return null;
}
}
/**
* @return string updatedMax
*/
public function getUpdatedMax()
{
if (array_key_exists('updated-max', $this->_params)) {
return $this->_params['updated-max'];
} else {
return null;
}
}
/**
* @return string updatedMin
*/
public function getUpdatedMin()
{
if (array_key_exists('updated-min', $this->_params)) {
return $this->_params['updated-min'];
} else {
return null;
}
}
/**
* @return string publishedMax
*/
public function getPublishedMax()
{
if (array_key_exists('published-max', $this->_params)) {
return $this->_params['published-max'];
} else {
return null;
}
}
/**
* @return string publishedMin
*/
public function getPublishedMin()
{
if (array_key_exists('published-min', $this->_params)) {
return $this->_params['published-min'];
} else {
return null;
}
}
/**
* @return string author
*/
public function getAuthor()
{
if (array_key_exists('author', $this->_params)) {
return $this->_params['author'];
} else {
return null;
}
}
/**
* @param string $value
* @return Zend_Gdata_Query Provides a fluent interface
*/
public function setCategory($value)
{
$this->_category = $value;
return $this;
}
/*
* @return string id
*/
public function getCategory()
{
return $this->_category;
}
public function __get($name)
{
$method = 'get'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method));
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
}
}
public function __set($name, $val)
{
$method = 'set'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method), $val);
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist');
}
}
}
Gdata/Exif/Extension/Time.php 0000604 00000003173 15071256135 0012047 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:time element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Time extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'time';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Time object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Iso.php 0000604 00000003167 15071256135 0011706 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:iso element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Iso extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'iso';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Iso object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/FStop.php 0000604 00000003177 15071256135 0012210 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:fStop element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_FStop extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'fstop';
/**
* Constructs a new Zend_Gdata_Exif_Extension_FStop object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Model.php 0000604 00000003177 15071256135 0012215 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:model element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Model extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'model';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Model object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Exposure.php 0000604 00000003213 15071256135 0012756 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:exposure element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Exposure extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'exposure';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Exposure object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Distance.php 0000604 00000003213 15071256135 0012676 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:distance element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Distance extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'distance';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Distance object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Tags.php 0000604 00000040626 15071256135 0012053 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* @see Zend_Gdata_Exif_Extension_Distance
*/
require_once 'Zend/Gdata/Exif/Extension/Distance.php';
/**
* @see Zend_Gdata_Exif_Extension_Exposure
*/
require_once 'Zend/Gdata/Exif/Extension/Exposure.php';
/**
* @see Zend_Gdata_Exif_Extension_Flash
*/
require_once 'Zend/Gdata/Exif/Extension/Flash.php';
/**
* @see Zend_Gdata_Exif_Extension_FocalLength
*/
require_once 'Zend/Gdata/Exif/Extension/FocalLength.php';
/**
* @see Zend_Gdata_Exif_Extension_FStop
*/
require_once 'Zend/Gdata/Exif/Extension/FStop.php';
/**
* @see Zend_Gdata_Exif_Extension_ImageUniqueId
*/
require_once 'Zend/Gdata/Exif/Extension/ImageUniqueId.php';
/**
* @see Zend_Gdata_Exif_Extension_Iso
*/
require_once 'Zend/Gdata/Exif/Extension/Iso.php';
/**
* @see Zend_Gdata_Exif_Extension_Make
*/
require_once 'Zend/Gdata/Exif/Extension/Make.php';
/**
* @see Zend_Gdata_Exif_Extension_Model
*/
require_once 'Zend/Gdata/Exif/Extension/Model.php';
/**
* @see Zend_Gdata_Exif_Extension_Time
*/
require_once 'Zend/Gdata/Exif/Extension/Time.php';
/**
* Represents the exif:tags element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Tags extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'tags';
/**
* exif:distance value
*
* @var Zend_Gdata_Exif_Extension_Distance
*/
protected $_distance = null;
/**
* exif:exposure value
*
* @var Zend_Gdata_Exif_Extension_Exposure
*/
protected $_exposure = null;
/**
* exif:flash value
*
* @var Zend_Gdata_Exif_Extension_Flash
*/
protected $_flash = null;
/**
* exif:focalLength value
*
* @var Zend_Gdata_Exif_Extension_FocalLength
*/
protected $_focalLength = null;
/**
* exif:fStop value
*
* @var Zend_Gdata_Exif_Extension_FStop
*/
protected $_fStop = null;
/**
* exif:imageUniqueID value
*
* @var Zend_Gdata_Exif_Extension_ImageUniqueId
*/
protected $_imageUniqueId = null;
/**
* exif:iso value
*
* @var Zend_Gdata_Exif_Extension_Iso
*/
protected $_iso = null;
/**
* exif:make value
*
* @var Zend_Gdata_Exif_Extension_Make
*/
protected $_make = null;
/**
* exif:model value
*
* @var Zend_Gdata_Exif_Extension_Model
*/
protected $_model = null;
/**
* exif:time value
*
* @var Zend_Gdata_Exif_Extension_Time
*/
protected $_time = null;
/**
* Constructs a new Zend_Gdata_Exif_Extension_Tags object.
*
* @param Zend_Gdata_Exif_Extension_Distance $distance (optional) The exif:distance
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Exposure $exposure (optional) The exif:exposure
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Flash $flash (optional) The exif:flash
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_FocalLength$focalLength (optional) The exif:focallength
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_FStop $fStop (optional) The exif:fstop
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_ImageUniqueId $imageUniqueId (optional) The exif:imageUniqueID
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Iso $iso (optional) The exif:iso
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Make $make (optional) The exif:make
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Model $model (optional) The exif:model
* value to be set in the constructed object.
* @param Zend_Gdata_Exif_Extension_Time $time (optional) The exif:time
* value to be set in the constructed object.
*/
public function __construct($distance = null, $exposure = null,
$flash = null, $focalLength = null, $fStop = null,
$imageUniqueId = null, $iso = null, $make = null,
$model = null, $time = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setDistance($distance);
$this->setExposure($exposure);
$this->setFlash($flash);
$this->setFocalLength($focalLength);
$this->setFStop($fStop);
$this->setImageUniqueId($imageUniqueId);
$this->setIso($iso);
$this->setMake($make);
$this->setModel($model);
$this->setTime($time);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_distance !== null) {
$element->appendChild($this->_distance->getDOM($element->ownerDocument));
}
if ($this->_exposure !== null) {
$element->appendChild($this->_exposure->getDOM($element->ownerDocument));
}
if ($this->_flash !== null) {
$element->appendChild($this->_flash->getDOM($element->ownerDocument));
}
if ($this->_focalLength !== null) {
$element->appendChild($this->_focalLength->getDOM($element->ownerDocument));
}
if ($this->_fStop !== null) {
$element->appendChild($this->_fStop->getDOM($element->ownerDocument));
}
if ($this->_imageUniqueId !== null) {
$element->appendChild($this->_imageUniqueId->getDOM($element->ownerDocument));
}
if ($this->_iso !== null) {
$element->appendChild($this->_iso->getDOM($element->ownerDocument));
}
if ($this->_make !== null) {
$element->appendChild($this->_make->getDOM($element->ownerDocument));
}
if ($this->_model !== null) {
$element->appendChild($this->_model->getDOM($element->ownerDocument));
}
if ($this->_time !== null) {
$element->appendChild($this->_time->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('exif') . ':' . 'distance';
$distance = new Zend_Gdata_Exif_Extension_Distance();
$distance->transferFromDOM($child);
$this->_distance = $distance;
break;
case $this->lookupNamespace('exif') . ':' . 'exposure';
$exposure = new Zend_Gdata_Exif_Extension_Exposure();
$exposure->transferFromDOM($child);
$this->_exposure = $exposure;
break;
case $this->lookupNamespace('exif') . ':' . 'flash';
$flash = new Zend_Gdata_Exif_Extension_Flash();
$flash->transferFromDOM($child);
$this->_flash = $flash;
break;
case $this->lookupNamespace('exif') . ':' . 'focallength';
$focalLength = new Zend_Gdata_Exif_Extension_FocalLength();
$focalLength->transferFromDOM($child);
$this->_focalLength = $focalLength;
break;
case $this->lookupNamespace('exif') . ':' . 'fstop';
$fStop = new Zend_Gdata_Exif_Extension_FStop();
$fStop->transferFromDOM($child);
$this->_fStop = $fStop;
break;
case $this->lookupNamespace('exif') . ':' . 'imageUniqueID';
$imageUniqueId = new Zend_Gdata_Exif_Extension_ImageUniqueId();
$imageUniqueId->transferFromDOM($child);
$this->_imageUniqueId = $imageUniqueId;
break;
case $this->lookupNamespace('exif') . ':' . 'iso';
$iso = new Zend_Gdata_Exif_Extension_Iso();
$iso->transferFromDOM($child);
$this->_iso = $iso;
break;
case $this->lookupNamespace('exif') . ':' . 'make';
$make = new Zend_Gdata_Exif_Extension_Make();
$make->transferFromDOM($child);
$this->_make = $make;
break;
case $this->lookupNamespace('exif') . ':' . 'model';
$model = new Zend_Gdata_Exif_Extension_Model();
$model->transferFromDOM($child);
$this->_model = $model;
break;
case $this->lookupNamespace('exif') . ':' . 'time';
$time = new Zend_Gdata_Exif_Extension_Time();
$time->transferFromDOM($child);
$this->_time = $time;
break;
}
}
/**
* Get the value for this element's distance attribute.
*
* @see setDistance
* @return Zend_Gdata_Exif_Extension_Distance The requested attribute.
*/
public function getDistance()
{
return $this->_distance;
}
/**
* Set the value for this element's distance attribute.
*
* @param Zend_Gdata_Exif_Extension_Distance $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setDistance($value)
{
$this->_distance = $value;
return $this;
}
/**
* Get the value for this element's exposure attribute.
*
* @see setExposure
* @return Zend_Gdata_Exif_Extension_Exposure The requested attribute.
*/
public function getExposure()
{
return $this->_exposure;
}
/**
* Set the value for this element's exposure attribute.
*
* @param Zend_Gdata_Exif_Extension_Exposure $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setExposure($value)
{
$this->_exposure = $value;
return $this;
}
/**
* Get the value for this element's flash attribute.
*
* @see setFlash
* @return Zend_Gdata_Exif_Extension_Flash The requested attribute.
*/
public function getFlash()
{
return $this->_flash;
}
/**
* Set the value for this element's flash attribute.
*
* @param Zend_Gdata_Exif_Extension_Flash $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setFlash($value)
{
$this->_flash = $value;
return $this;
}
/**
* Get the value for this element's name attribute.
*
* @see setFocalLength
* @return Zend_Gdata_Exif_Extension_FocalLength The requested attribute.
*/
public function getFocalLength()
{
return $this->_focalLength;
}
/**
* Set the value for this element's focalLength attribute.
*
* @param Zend_Gdata_Exif_Extension_FocalLength $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setFocalLength($value)
{
$this->_focalLength = $value;
return $this;
}
/**
* Get the value for this element's fStop attribute.
*
* @see setFStop
* @return Zend_Gdata_Exif_Extension_FStop The requested attribute.
*/
public function getFStop()
{
return $this->_fStop;
}
/**
* Set the value for this element's fStop attribute.
*
* @param Zend_Gdata_Exif_Extension_FStop $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setFStop($value)
{
$this->_fStop = $value;
return $this;
}
/**
* Get the value for this element's imageUniqueId attribute.
*
* @see setImageUniqueId
* @return Zend_Gdata_Exif_Extension_ImageUniqueId The requested attribute.
*/
public function getImageUniqueId()
{
return $this->_imageUniqueId;
}
/**
* Set the value for this element's imageUniqueId attribute.
*
* @param Zend_Gdata_Exif_Extension_ImageUniqueId $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setImageUniqueId($value)
{
$this->_imageUniqueId = $value;
return $this;
}
/**
* Get the value for this element's iso attribute.
*
* @see setIso
* @return Zend_Gdata_Exif_Extension_Iso The requested attribute.
*/
public function getIso()
{
return $this->_iso;
}
/**
* Set the value for this element's iso attribute.
*
* @param Zend_Gdata_Exif_Extension_Iso $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setIso($value)
{
$this->_iso = $value;
return $this;
}
/**
* Get the value for this element's make attribute.
*
* @see setMake
* @return Zend_Gdata_Exif_Extension_Make The requested attribute.
*/
public function getMake()
{
return $this->_make;
}
/**
* Set the value for this element's make attribute.
*
* @param Zend_Gdata_Exif_Extension_Make $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setMake($value)
{
$this->_make = $value;
return $this;
}
/**
* Get the value for this element's model attribute.
*
* @see setModel
* @return Zend_Gdata_Exif_Extension_Model The requested attribute.
*/
public function getModel()
{
return $this->_model;
}
/**
* Set the value for this element's model attribute.
*
* @param Zend_Gdata_Exif_Extension_Model $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setModel($value)
{
$this->_model = $value;
return $this;
}
/**
* Get the value for this element's time attribute.
*
* @see setTime
* @return Zend_Gdata_Exif_Extension_Time The requested attribute.
*/
public function getTime()
{
return $this->_time;
}
/**
* Set the value for this element's time attribute.
*
* @param Zend_Gdata_Exif_Extension_Time $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags Provides a fluent interface
*/
public function setTime($value)
{
$this->_time = $value;
return $this;
}
}
Gdata/Exif/Extension/Make.php 0000604 00000003173 15071256135 0012026 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:make element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Make extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'make';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Make object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/Flash.php 0000604 00000003177 15071256135 0012212 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:flash element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_Flash extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'flash';
/**
* Constructs a new Zend_Gdata_Exif_Extension_Flash object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/ImageUniqueId.php 0000604 00000003237 15071256135 0013640 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:imageUniqueId element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_ImageUniqueId extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'imageUniqueID';
/**
* Constructs a new Zend_Gdata_Exif_Extension_ImageUniqueId object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Extension/FocalLength.php 0000604 00000003227 15071256135 0013337 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* Represents the exif:focalLength element used by the Gdata Exif extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Extension_FocalLength extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'exif';
protected $_rootElement = 'focallength';
/**
* Constructs a new Zend_Gdata_Exif_Extension_FocalLength object.
*
* @param string $text (optional) The value to use for this element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Exif/Entry.php 0000604 00000010036 15071256135 0010272 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* @see Zend_Gdata_Exif_Extension_Tags
*/
require_once 'Zend/Gdata/Exif/Extension/Tags.php';
/**
* An Atom entry containing EXIF metadata.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Entry extends Zend_Gdata_Entry
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Exif_Entry';
/**
* The tags that belong to the Exif group.
*
* @var string
*/
protected $_tags = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_tags != null) {
$element->appendChild($this->_tags->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('exif') . ':' . 'tags':
$tags = new Zend_Gdata_Exif_Extension_Tags();
$tags->transferFromDOM($child);
$this->_tags = $tags;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Retrieve the tags for this entry.
*
* @see setTags
* @return Zend_Gdata_Exif_Extension_Tags The requested object
* or null if not set.
*/
public function getTags()
{
return $this->_tags;
}
/**
* Set the tags property for this entry. This property contains
* various Exif data.
*
* This corresponds to the <exif:tags> property in the Google Data
* protocol.
*
* @param Zend_Gdata_Exif_Extension_Tags $value The desired value
* this element, or null to unset.
* @return Zend_Gdata_Exif_Entry Provides a fluent interface
*/
public function setTags($value)
{
$this->_tags = $value;
return $this;
}
}
Gdata/Exif/Feed.php 0000604 00000003321 15071256135 0010033 0 ustar 00 <?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_Gdata
* @subpackage Exif
* @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 Zend_Gdata_eed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Exif
*/
require_once 'Zend/Gdata/Exif.php';
/**
* @see Zend_Gdata_Exif_Entry
*/
require_once 'Zend/Gdata/Exif/Entry.php';
/**
* Feed for Gdata EXIF data entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Exif
* @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_Gdata_Exif_Feed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Exif_Entry';
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Exif::$namespaces);
parent::__construct($element);
}
}
Gdata/Calendar.php 0000604 00000011645 15071256135 0010016 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Calendar_EventFeed
*/
require_once 'Zend/Gdata/Calendar/EventFeed.php';
/**
* @see Zend_Gdata_Calendar_EventEntry
*/
require_once 'Zend/Gdata/Calendar/EventEntry.php';
/**
* @see Zend_Gdata_Calendar_ListFeed
*/
require_once 'Zend/Gdata/Calendar/ListFeed.php';
/**
* @see Zend_Gdata_Calendar_ListEntry
*/
require_once 'Zend/Gdata/Calendar/ListEntry.php';
/**
* Service class for interacting with the Google Calendar data API
* @link http://code.google.com/apis/gdata/calendar.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar extends Zend_Gdata
{
const CALENDAR_FEED_URI = 'http://www.google.com/calendar/feeds';
const CALENDAR_EVENT_FEED_URI = 'http://www.google.com/calendar/feeds/default/private/full';
const AUTH_SERVICE_NAME = 'cl';
protected $_defaultPostUri = self::CALENDAR_EVENT_FEED_URI;
/**
* Namespaces used for Zend_Gdata_Calendar
*
* @var array
*/
public static $namespaces = array(
array('gCal', 'http://schemas.google.com/gCal/2005', 1, 0)
);
/**
* Create Gdata_Calendar object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Calendar');
$this->registerPackage('Zend_Gdata_Calendar_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Retreive feed object
*
* @param mixed $location The location for the feed, as a URL or Query
* @return Zend_Gdata_Calendar_EventFeed
*/
public function getCalendarEventFeed($location = null)
{
if ($location == null) {
$uri = self::CALENDAR_EVENT_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Calendar_EventFeed');
}
/**
* Retreive entry object
*
* @return Zend_Gdata_Calendar_EventEntry
*/
public function getCalendarEventEntry($location = null)
{
if ($location == null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Calendar_EventEntry');
}
/**
* Retrieve feed object
*
* @return Zend_Gdata_Calendar_ListFeed
*/
public function getCalendarListFeed()
{
$uri = self::CALENDAR_FEED_URI . '/default';
return parent::getFeed($uri,'Zend_Gdata_Calendar_ListFeed');
}
/**
* Retreive entryobject
*
* @return Zend_Gdata_Calendar_ListEntry
*/
public function getCalendarListEntry($location = null)
{
if ($location == null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null');
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri,'Zend_Gdata_Calendar_ListEntry');
}
public function insertEvent($event, $uri=null)
{
if ($uri == null) {
$uri = $this->_defaultPostUri;
}
$newEvent = $this->insertEntry($event, $uri, 'Zend_Gdata_Calendar_EventEntry');
return $newEvent;
}
}
Gdata/DublinCore/Extension/Format.php 0000604 00000003304 15071256135 0013530 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* File format, physical medium, or dimensions of the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Format extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'format';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Format which
* File format, physical medium, or dimensions of the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Creator.php 0000604 00000003271 15071256135 0013702 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Entity primarily responsible for making the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Creator extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'creator';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Creator which
* Entity primarily responsible for making the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Description.php 0000604 00000003213 15071256135 0014562 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Account of the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Description extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'description';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Description which
* Account of the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Publisher.php 0000604 00000003277 15071256135 0014246 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Entity responsible for making the resource available
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Publisher extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'publisher';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Publisher which
* Entity responsible for making the resource available
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Identifier.php 0000604 00000003330 15071256135 0014361 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* An unambiguous reference to the resource within a given context
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Identifier extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'identifier';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Identifier which
* An unambiguous reference to the resource within a given context
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Subject.php 0000604 00000003173 15071256135 0013703 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Topic of the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Subject extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'subject';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Subject which
* Topic of the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Date.php 0000604 00000003364 15071256135 0013163 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Point or period of time associated with an event in the lifecycle of the
* resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Date extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'date';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Date which
* Point or period of time associated with an event in the lifecycle of the
* resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Language.php 0000604 00000003204 15071256135 0014022 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Language of the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Language extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'language';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Language which
* Language of the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Title.php 0000604 00000003177 15071256135 0013371 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Name given to the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Title extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'title';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Title which
* Name given to the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/DublinCore/Extension/Rights.php 0000604 00000003272 15071256135 0013544 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Information about rights held in and over the resource
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore_Extension_Rights extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'dc';
protected $_rootElement = 'rights';
/**
* Constructor for Zend_Gdata_DublinCore_Extension_Rights which
* Information about rights held in and over the resource
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_DublinCore::$namespaces);
parent::__construct();
$this->_text = $value;
}
}
Gdata/Geo.php 0000604 00000004062 15071256135 0007012 0 ustar 00 <?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_Gdata
* @subpackage Geo
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* Service class for interacting with the services which use the
* GeoRSS + GML extensions.
* @link http://georss.org/
* @link http://www.opengis.net/gml/
* @link http://code.google.com/apis/picasaweb/reference.html#georss_reference
*
* @category Zend
* @package Zend_Gdata
* @subpackage Geo
* @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_Gdata_Geo extends Zend_Gdata
{
/**
* Namespaces used for Zend_Gdata_Geo
*
* @var array
*/
public static $namespaces = array(
array('georss', 'http://www.georss.org/georss', 1, 0),
array('gml', 'http://www.opengis.net/gml', 1, 0)
);
/**
* Create Zend_Gdata_Geo object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google Apps servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Geo');
$this->registerPackage('Zend_Gdata_Geo_Extension');
parent::__construct($client, $applicationId);
}
}
Gdata/DublinCore.php 0000604 00000003611 15071256135 0010325 0 ustar 00 <?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_Gdata
* @subpackage DublinCore
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* Service class for interacting with the services which use the
* DublinCore extensions.
*
* @category Zend
* @package Zend_Gdata
* @subpackage DublinCore
* @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_Gdata_DublinCore extends Zend_Gdata
{
/**
* Namespaces used for Zend_Gdata_DublinCore
*
* @var array
*/
public static $namespaces = array(
array('dc', 'http://purl.org/dc/terms', 1, 0)
);
/**
* Create Zend_Gdata_DublinCore object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_DublinCore');
$this->registerPackage('Zend_Gdata_DublinCore_Extension');
parent::__construct($client, $applicationId);
}
}
Gdata/Media.php 0000604 00000003637 15071256135 0007326 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* Service class for interacting with the services which use the media extensions
* @link http://code.google.com/apis/gdata/calendar.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_Media extends Zend_Gdata
{
/**
* Namespaces used for Zend_Gdata_Photos
*
* @var array
*/
public static $namespaces = array(
array('media', 'http://search.yahoo.com/mrss/', 1, 0)
);
/**
* Create Gdata_Media object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google Apps servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Media');
$this->registerPackage('Zend_Gdata_Media_Extension');
parent::__construct($client, $applicationId);
}
}
Gdata/YouTube/CommentEntry.php 0000604 00000002434 15071256135 0012321 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* The YouTube comments flavor of an Atom Entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_CommentEntry extends Zend_Gdata_Entry
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_CommentEntry';
}
Gdata/YouTube/Extension/MediaGroup.php 0000604 00000023230 15071256135 0013702 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Extension_MediaGroup
*/
require_once 'Zend/Gdata/Media/Extension/MediaGroup.php';
/**
* @see Zend_Gdata_YouTube_Extension_MediaContent
*/
require_once 'Zend/Gdata/YouTube/Extension/MediaContent.php';
/**
* @see Zend_Gdata_YouTube_Extension_Duration
*/
require_once 'Zend/Gdata/YouTube/Extension/Duration.php';
/**
* @see Zend_Gdata_YouTube_Extension_MediaRating
*/
require_once 'Zend/Gdata/YouTube/Extension/MediaRating.php';
/**
* @see Zend_Gdata_YouTube_Extension_MediaCredit
*/
require_once 'Zend/Gdata/YouTube/Extension/MediaCredit.php';
/**
* @see Zend_Gdata_YouTube_Extension_Private
*/
require_once 'Zend/Gdata/YouTube/Extension/Private.php';
/**
* @see Zend_Gdata_YouTube_Extension_VideoId
*/
require_once 'Zend/Gdata/YouTube/Extension/VideoId.php';
/**
* @see Zend_Gdata_YouTube_Extension_Uploaded
*/
require_once 'Zend/Gdata/YouTube/Extension/Uploaded.php';
/**
* This class represents the media:group element of Media RSS.
* It allows the grouping of media:content elements that are
* different representations of the same content. When it exists,
* it is a child of an Entry (Atom) or Item (RSS).
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_MediaGroup extends Zend_Gdata_Media_Extension_MediaGroup
{
protected $_rootElement = 'group';
protected $_rootNamespace = 'media';
/**
* @var Zend_Gdata_YouTube_Extension_Duration
*/
protected $_duration = null;
/**
* @var Zend_Gdata_YouTube_Extension_Private
*/
protected $_private = null;
/**
* @var Zend_Gdata_YouTube_Extension_VideoId
*/
protected $_videoid = null;
/**
* @var Zend_Gdata_YouTube_Extension_MediaRating
*/
protected $_mediarating = null;
/**
* @var Zend_Gdata_YouTube_Extension_MediaCredit
*/
protected $_mediacredit = null;
/**
* @var Zend_Gdata_YouTube_Extension_Uploaded
*/
protected $_uploaded = null;
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_duration !== null) {
$element->appendChild(
$this->_duration->getDOM($element->ownerDocument));
}
if ($this->_private !== null) {
$element->appendChild(
$this->_private->getDOM($element->ownerDocument));
}
if ($this->_videoid != null) {
$element->appendChild(
$this->_videoid->getDOM($element->ownerDocument));
}
if ($this->_uploaded != null) {
$element->appendChild(
$this->_uploaded->getDOM($element->ownerDocument));
}
if ($this->_mediacredit != null) {
$element->appendChild(
$this->_mediacredit->getDOM($element->ownerDocument));
}
if ($this->_mediarating != null) {
$element->appendChild(
$this->_mediarating->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('media') . ':' . 'content':
$content = new Zend_Gdata_YouTube_Extension_MediaContent();
$content->transferFromDOM($child);
$this->_content[] = $content;
break;
case $this->lookupNamespace('media') . ':' . 'rating':
$mediarating = new Zend_Gdata_YouTube_Extension_MediaRating();
$mediarating->transferFromDOM($child);
$this->_mediarating = $mediarating;
break;
case $this->lookupNamespace('media') . ':' . 'credit':
$mediacredit = new Zend_Gdata_YouTube_Extension_MediaCredit();
$mediacredit->transferFromDOM($child);
$this->_mediacredit = $mediacredit;
break;
case $this->lookupNamespace('yt') . ':' . 'duration':
$duration = new Zend_Gdata_YouTube_Extension_Duration();
$duration->transferFromDOM($child);
$this->_duration = $duration;
break;
case $this->lookupNamespace('yt') . ':' . 'private':
$private = new Zend_Gdata_YouTube_Extension_Private();
$private->transferFromDOM($child);
$this->_private = $private;
break;
case $this->lookupNamespace('yt') . ':' . 'videoid':
$videoid = new Zend_Gdata_YouTube_Extension_VideoId();
$videoid ->transferFromDOM($child);
$this->_videoid = $videoid;
break;
case $this->lookupNamespace('yt') . ':' . 'uploaded':
$uploaded = new Zend_Gdata_YouTube_Extension_Uploaded();
$uploaded ->transferFromDOM($child);
$this->_uploaded = $uploaded;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Returns the duration value of this element
*
* @return Zend_Gdata_YouTube_Extension_Duration
*/
public function getDuration()
{
return $this->_duration;
}
/**
* Sets the duration value of this element
*
* @param Zend_Gdata_YouTube_Extension_Duration $value The duration value
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setDuration($value)
{
$this->_duration = $value;
return $this;
}
/**
* Returns the videoid value of this element
*
* @return Zend_Gdata_YouTube_Extension_VideoId
*/
public function getVideoId()
{
return $this->_videoid;
}
/**
* Sets the videoid value of this element
*
* @param Zend_Gdata_YouTube_Extension_VideoId $value The video id value
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setVideoId($value)
{
$this->_videoid = $value;
return $this;
}
/**
* Returns the yt:uploaded element
*
* @return Zend_Gdata_YouTube_Extension_Uploaded
*/
public function getUploaded()
{
return $this->_uploaded;
}
/**
* Sets the yt:uploaded element
*
* @param Zend_Gdata_YouTube_Extension_Uploaded $value The uploaded value
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setUploaded($value)
{
$this->_uploaded = $value;
return $this;
}
/**
* Returns the private value of this element
*
* @return Zend_Gdata_YouTube_Extension_Private
*/
public function getPrivate()
{
return $this->_private;
}
/**
* Sets the private value of this element
*
* @param Zend_Gdata_YouTube_Extension_Private $value The private value
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setPrivate($value)
{
$this->_private = $value;
return $this;
}
/**
* Returns the rating value of this element
*
* @return Zend_Gdata_YouTube_Extension_MediaRating
*/
public function getMediaRating()
{
return $this->_mediarating;
}
/**
* Sets the media:rating value of this element
*
* @param Zend_Gdata_YouTube_Extension_MediaRating $value The rating element
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setMediaRating($value)
{
$this->_mediarating = $value;
return $this;
}
/**
* Returns the media:credit value of this element
*
* @return Zend_Gdata_YouTube_Extension_MediaCredit
*/
public function getMediaCredit()
{
return $this->_mediacredit;
}
/**
* Sets the media:credit value of this element
*
* @param Zend_Gdata_YouTube_Extension_MediaCredit $value The credit element
* @return Zend_Gdata_YouTube_Extension_MediaGroup Provides a fluent
* interface
*/
public function setMediaCredit($value)
{
$this->_mediacredit = $value;
return $this;
}
}
Gdata/YouTube/Extension/Status.php 0000604 00000002601 15071256135 0013130 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:status element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Status extends Zend_Gdata_Extension
{
protected $_rootElement = 'status';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Control.php 0000604 00000010003 15071256135 0013260 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_App_Extension_Control
*/
require_once 'Zend/Gdata/App/Extension/Control.php';
/**
* @see Zend_Gdata_YouTube_Extension_State
*/
require_once 'Zend/Gdata/YouTube/Extension/State.php';
/**
* Specialized Control class for use with YouTube. Enables use of yt extension elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Control extends Zend_Gdata_App_Extension_Control
{
protected $_state = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Control object.
* @see Zend_Gdata_App_Extension_Control#__construct
* @param Zend_Gdata_App_Extension_Draft $draft
* @param Zend_Gdata_YouTube_Extension_State $state
*/
public function __construct($draft = null, $state = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($draft);
$this->_state = $state;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_state != null) {
$element->appendChild($this->_state->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'state':
$state = new Zend_Gdata_YouTube_Extension_State();
$state->transferFromDOM($child);
$this->_state = $state;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's state attribute.
*
* @return Zend_Gdata_YouTube_Extension_State The state element.
*/
public function getState()
{
return $this->_state;
}
/**
* Set the value for this element's state attribute.
*
* @param Zend_Gdata_YouTube_Extension_State $value The desired value for this attribute.
* @return Zend_YouTube_Extension_Control The element being modified.
*/
public function setState($value)
{
$this->_state = $value;
return $this;
}
/**
* Get the value of this element's state attribute.
*
* @return string The state's text value
*/
public function getStateValue()
{
return $this->getState()->getText();
}
}
Gdata/YouTube/Extension/Token.php 0000604 00000004177 15071256135 0012737 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:token element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Token extends Zend_Gdata_App_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'token';
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Token object.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
return $element;
}
}
Gdata/YouTube/Extension/NoEmbed.php 0000604 00000003046 15071256135 0013162 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:noembed element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_NoEmbed extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'noembed';
/**
* Constructs a new Zend_Gdata_YouTube_Extension_VideoShare object.
* @param bool $enabled(optional) The enabled value of the element.
*/
public function __construct($enabled = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
}
}
Gdata/YouTube/Extension/Relationship.php 0000604 00000002623 15071256135 0014312 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:relationship element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Relationship extends Zend_Gdata_Extension
{
protected $_rootElement = 'relationship';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Description.php 0000604 00000002620 15071256135 0014131 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:description element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Description extends Zend_Gdata_Extension
{
protected $_rootElement = 'description';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/State.php 0000604 00000013167 15071256135 0012736 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:state element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_State extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'state';
protected $_name = null;
protected $_reasonCode = null;
protected $_helpUrl = null;
/**
* Constructs a new Zend_Gdata_YouTube_Extension_State object.
*
* @param string $explanation(optional) The explanation of this state
* @param string $name(optional) The name value
* @param string $reasonCode(optional) The reasonCode value
* @param string $helpUrl(optional) The helpUrl value
*/
public function __construct($explanation = null, $name = null,
$reasonCode = null, $helpUrl = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $explanation;
$this->_name = $name;
$this->_reasonCode = $reasonCode;
$this->_helpUrl = $reasonCode;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_name !== null) {
$element->setAttribute('name', $this->_name);
}
if ($this->_reasonCode !== null) {
$element->setAttribute('reasonCode', $this->_reasonCode);
}
if ($this->_helpUrl !== null) {
$element->setAttribute('helpUrl', $this->_helpUrl);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and valueare
* stored in an array.
* TODO: Convert attributes to proper types
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'name':
$this->_name = $attribute->nodeValue;
break;
case 'reasonCode':
$this->_reasonCode = $attribute->nodeValue;
break;
case 'helpUrl':
$this->_helpUrl = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's name attribute.
*
* @return int The value associated with this attribute.
*/
public function getName()
{
return $this->_name;
}
/**
* Set the value for this element's name attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_State The element being modified.
*/
public function setName($value)
{
$this->_name = $value;
return $this;
}
/**
* Get the value for this element's reasonCode attribute.
*
* @return int The value associated with this attribute.
*/
public function getReasonCode()
{
return $this->_reasonCode;
}
/**
* Set the value for this element's reasonCode attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_State The element being modified.
*/
public function setReasonCode($value)
{
$this->_reasonCode = $value;
return $this;
}
/**
* Get the value for this element's helpUrl attribute.
*
* @return int The value associated with this attribute.
*/
public function getHelpUrl()
{
return $this->_helpUrl;
}
/**
* Set the value for this element's helpUrl attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_State The element being modified.
*/
public function setHelpUrl($value)
{
$this->_helpUrl = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string
*/
public function __toString()
{
return $this->_text;
}
}
Gdata/YouTube/Extension/PlaylistId.php 0000604 00000002615 15071256135 0013730 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:playlistId element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_PlaylistId extends Zend_Gdata_Extension
{
protected $_rootElement = 'playlistId';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Position.php 0000604 00000004515 15071256135 0013457 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent a playlist item's position in the list (yt:position)
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Position extends Zend_Gdata_Extension
{
protected $_rootElement = 'position';
protected $_rootNamespace = 'yt';
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Position object.
*
* @param string $value (optional) The 1-based position in the playlist
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $value;
}
/**
* Get the value for the position in the playlist
*
* @return int The 1-based position in the playlist
*/
public function getValue()
{
return $this->_text;
}
/**
* Set the value for the position in the playlist
*
* @param int $value The 1-based position in the playlist
* @return Zend_Gdata_Extension_Visibility The element being modified
*/
public function setValue($value)
{
$this->_text = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/YouTube/Extension/Uploaded.php 0000604 00000002607 15071256135 0013410 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:uploaded element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Uploaded extends Zend_Gdata_Extension
{
protected $_rootElement = 'uploaded';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/FirstName.php 0000604 00000002612 15071256135 0013537 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:firstName element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_FirstName extends Zend_Gdata_Extension
{
protected $_rootElement = 'firstName';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Movies.php 0000604 00000002601 15071256135 0013107 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:movies element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Movies extends Zend_Gdata_Extension
{
protected $_rootElement = 'movies';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Gender.php 0000604 00000002601 15071256135 0013051 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:gender element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Gender extends Zend_Gdata_Extension
{
protected $_rootElement = 'gender';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Link.php 0000604 00000010066 15071256135 0012546 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_App_Extension_Link
*/
require_once 'Zend/Gdata/App/Extension/Link.php';
/**
* @see Zend_Gdata_YouTube_Extension_Token
*/
require_once 'Zend/Gdata/YouTube/Extension/Token.php';
/**
* Specialized Link class for use with YouTube. Enables use of yt extension elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Link extends Zend_Gdata_App_Extension_Link
{
protected $_token = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Link object.
* @see Zend_Gdata_App_Extension_Link#__construct
* @param Zend_Gdata_YouTube_Extension_Token $token
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null, $token = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
$this->_token = $token;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_token != null) {
$element->appendChild($this->_token->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'token':
$token = new Zend_Gdata_YouTube_Extension_Token();
$token->transferFromDOM($child);
$this->_token = $token;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's token attribute.
*
* @return Zend_Gdata_YouTube_Extension_Token The token element.
*/
public function getToken()
{
return $this->_token;
}
/**
* Set the value for this element's token attribute.
*
* @param Zend_Gdata_YouTube_Extension_Token $value The desired value for this attribute.
* @return Zend_YouTube_Extension_Link The element being modified.
*/
public function setToken($value)
{
$this->_token = $value;
return $this;
}
/**
* Get the value of this element's token attribute.
*
* @return string The token's text value
*/
public function getTokenValue()
{
return $this->getToken()->getText();
}
}
Gdata/YouTube/Extension/Company.php 0000604 00000002604 15071256135 0013256 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:company element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Company extends Zend_Gdata_Extension
{
protected $_rootElement = 'company';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/CountHint.php 0000604 00000002612 15071256135 0013562 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:countHint element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_CountHint extends Zend_Gdata_Extension
{
protected $_rootElement = 'countHint';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Recorded.php 0000604 00000002607 15071256135 0013402 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:recorded element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Recorded extends Zend_Gdata_Extension
{
protected $_rootElement = 'recorded';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Age.php 0000604 00000002570 15071256135 0012346 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:age element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Age extends Zend_Gdata_Extension
{
protected $_rootElement = 'age';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/MediaRating.php 0000604 00000007751 15071256135 0014044 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the media:rating element specific to YouTube.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_MediaRating extends Zend_Gdata_Extension
{
protected $_rootElement = 'rating';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_scheme = null;
/**
* @var string
*/
protected $_country = null;
/**
* Constructs a new MediaRating element
*
* @param string $text
* @param string $scheme
* @param string $country
*/
public function __construct($text = null, $scheme = null, $country = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_scheme = $scheme;
$this->_country = $country;
$this->_text = $text;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
if ($this->_country != null) {
$element->setAttribute('country', $this->_country);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
case 'country':
$this->_country = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string $value
* @return Zend_Gdata_YouTube_Extension_MediaRating Provides a fluent interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
/**
* @return string
*/
public function getCountry()
{
return $this->_country;
}
/**
* @param string $value
* @return Zend_Gdata_YouTube_Extension_MediaRating Provides a fluent interface
*/
public function setCountry($value)
{
$this->_country = $value;
return $this;
}
}
Gdata/YouTube/Extension/AboutMe.php 0000604 00000002604 15071256135 0013204 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:aboutMe element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_AboutMe extends Zend_Gdata_Extension
{
protected $_rootElement = 'aboutMe';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Hometown.php 0000604 00000002607 15071256135 0013453 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:hometown element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Hometown extends Zend_Gdata_Extension
{
protected $_rootElement = 'hometown';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/MediaCredit.php 0000604 00000011610 15071256135 0014017 0 ustar 00 <?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_Gdata
* @subpackage Media
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the YouTube specific media:credit element
*
* @category Zend
* @package Zend_Gdata
* @subpackage Media
* @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_Gdata_YouTube_Extension_MediaCredit extends Zend_Gdata_Extension
{
protected $_rootElement = 'credit';
protected $_rootNamespace = 'media';
/**
* @var string
*/
protected $_role = null;
/**
* @var string
*/
protected $_scheme = null;
/**
* Represents the value of the yt:type attribute.
*
* Set to 'partner' if the uploader of this video is a YouTube
* partner.
*
* @var string
*/
protected $_yttype = null;
/**
* Creates an individual MediaCredit object.
*
* @param string $text
* @param string $role
* @param string $scheme
*/
public function __construct($text = null, $role = null, $scheme = null,
$yttype = null)
{
$this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_role = $role;
$this->_scheme = $scheme;
$this->_yttype = $yttype;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_role !== null) {
$element->setAttribute('role', $this->_role);
}
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
if ($this->_yttype !== null) {
$element->setAttributeNS('http://gdata.youtube.com/schemas/2007',
'yt:type', $this->_yttype);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'role':
$this->_role = $attribute->nodeValue;
break;
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
case 'type':
$this->_yttype = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getRole()
{
return $this->_role;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCredit Provides a fluent
* interface
*/
public function setRole($value)
{
$this->_role = $value;
return $this;
}
/**
* @return string
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCredit Provides a fluent
* interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
/**
* @return string
*/
public function getYTtype()
{
return $this->_yttype;
}
/**
* @param string $value
* @return Zend_Gdata_Media_Extension_MediaCredit Provides a fluent
* interface
*/
public function setYTtype($value)
{
$this->_yttype = $value;
return $this;
}
} Gdata/YouTube/Extension/Duration.php 0000604 00000007277 15071256135 0013450 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:duration element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Duration extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'duration';
protected $_seconds = null;
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Duration object.
* @param bool $seconds(optional) The seconds value of the element.
*/
public function __construct($seconds = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_seconds = $seconds;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_seconds !== null) {
$element->setAttribute('seconds', $this->_seconds);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and valueare
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'seconds':
$this->_seconds = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's seconds attribute.
*
* @return int The value associated with this attribute.
*/
public function getSeconds()
{
return $this->_seconds;
}
/**
* Set the value for this element's seconds attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_Duration The element being modified.
*/
public function setSeconds($value)
{
$this->_seconds = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string The duration in seconds
*/
public function __toString()
{
return $this->_seconds;
}
}
Gdata/YouTube/Extension/MediaContent.php 0000604 00000007140 15071256135 0014222 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Extension_MediaContent
*/
require_once 'Zend/Gdata/Media/Extension/MediaContent.php';
/**
* Represents the media:content element of Media RSS.
* Represents media objects. Multiple media objects representing
* the same content can be represented using a
* media:group (Zend_Gdata_Media_Extension_MediaGroup) element.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_MediaContent extends Zend_Gdata_Media_Extension_MediaContent
{
protected $_rootElement = 'content';
protected $_rootNamespace = 'media';
/*
* Format of the video
* Optional.
*
* @var int
*/
protected $_format = null;
function __construct() {
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_format!= null) {
$element->setAttributeNS($this->lookupNamespace('yt'), 'yt:format', $this->_format);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
$absoluteAttrName = $attribute->namespaceURI . ':' . $attribute->localName;
if ($absoluteAttrName == $this->lookupNamespace('yt') . ':' . 'format') {
$this->_format = $attribute->nodeValue;
} else {
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the format of the media
* Optional.
*
* @return int The format of the media
*/
public function getFormat()
{
return $this->_format;
}
/**
* Sets the format of the media
*
* @param int $value Format of the media
* @return Zend_Gdata_YouTube_Extension_MediaContent Provides a fluent interface
*
*/
public function setFormat($value)
{
$this->_format = $value;
return $this;
}
}
Gdata/YouTube/Extension/Username.php 0000604 00000002607 15071256135 0013432 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:username element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Username extends Zend_Gdata_Extension
{
protected $_rootElement = 'username';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/ReleaseDate.php 0000604 00000002620 15071256135 0014024 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:releaseDate element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_ReleaseDate extends Zend_Gdata_Extension
{
protected $_rootElement = 'releaseDate';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Music.php 0000604 00000002576 15071256135 0012740 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:music element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Music extends Zend_Gdata_Extension
{
protected $_rootElement = 'music';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/LastName.php 0000604 00000002607 15071256135 0013357 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:lastName element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_LastName extends Zend_Gdata_Extension
{
protected $_rootElement = 'lastName';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Racy.php 0000604 00000007125 15071256135 0012551 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:racy element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Racy extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'racy';
protected $_state = null;
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Racy object.
* @param bool $state(optional) The state value of the element.
*/
public function __construct($state = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_state = $state;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_state !== null) {
$element->setAttribute('state', $this->_state);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'state':
$this->_state = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's state attribute.
*
* @return bool The value associated with this attribute.
*/
public function getState()
{
return $this->_state;
}
/**
* Set the value for this element's state attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_Racy The element being modified.
*/
public function setState($value)
{
$this->_state = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->_state;
}
}
Gdata/YouTube/Extension/Occupation.php 0000604 00000002615 15071256135 0013756 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:occupation element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Occupation extends Zend_Gdata_Extension
{
protected $_rootElement = 'occupation';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/PlaylistTitle.php 0000604 00000002626 15071256135 0014457 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:playlistTitle element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_PlaylistTitle extends Zend_Gdata_Extension
{
protected $_rootElement = 'playlistTitle';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/QueryString.php 0000604 00000002620 15071256135 0014142 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:queryString element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_QueryString extends Zend_Gdata_Extension
{
protected $_rootElement = 'queryString';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Location.php 0000604 00000002607 15071256135 0013423 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:location element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Location extends Zend_Gdata_Extension
{
protected $_rootElement = 'location';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Private.php 0000604 00000004745 15071256135 0013272 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:private element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Private extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'private';
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Private object.
*/
public function __construct()
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and valueare
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
parent::takeAttributeFromDOM($attribute);
}
}
Gdata/YouTube/Extension/School.php 0000604 00000002601 15071256135 0013074 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:school element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_School extends Zend_Gdata_Extension
{
protected $_rootElement = 'school';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Statistics.php 0000604 00000011310 15071256135 0013774 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:statistics element used by the YouTube data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Statistics extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'yt';
protected $_rootElement = 'statistics';
protected $_viewCount = null;
protected $_watchCount = null;
/**
* Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
* @param string $viewCount(optional) The viewCount value
* @param string $watchCount(optional) The watchCount value
*/
public function __construct($viewCount = null, $watchCount = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_viewCount = $viewCount;
$this->_watchCount = $watchCount;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_viewCount !== null) {
$element->setAttribute('viewCount', $this->_viewCount);
}
if ($this->_watchCount !== null) {
$element->setAttribute('watchCount', $this->_watchCount);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and valueare
* stored in an array.
* TODO: Convert attributes to proper types
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'viewCount':
$this->_viewCount = $attribute->nodeValue;
break;
case 'watchCount':
$this->_watchCount = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's viewCount attribute.
*
* @return int The value associated with this attribute.
*/
public function getViewCount()
{
return $this->_viewCount;
}
/**
* Set the value for this element's viewCount attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_Statistics The element being modified.
*/
public function setViewCount($value)
{
$this->_viewCount = $value;
return $this;
}
/**
* Get the value for this element's watchCount attribute.
*
* @return int The value associated with this attribute.
*/
public function getWatchCount()
{
return $this->_watchCount;
}
/**
* Set the value for this element's watchCount attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_YouTube_Extension_Statistics The element being modified.
*/
public function setWatchCount($value)
{
$this->_watchCount = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string
*/
public function __toString()
{
return 'View Count=' . $this->_viewCount;
}
}
Gdata/YouTube/Extension/VideoId.php 0000604 00000002604 15071256135 0013173 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:videoid element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_VideoId extends Zend_Gdata_Extension
{
protected $_rootElement = 'videoid';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Hobbies.php 0000604 00000002604 15071256135 0013223 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:hobbies element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Hobbies extends Zend_Gdata_Extension
{
protected $_rootElement = 'hobbies';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/Extension/Books.php 0000604 00000002576 15071256135 0012735 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the yt:books element
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_Extension_Books extends Zend_Gdata_Extension
{
protected $_rootElement = 'books';
protected $_rootNamespace = 'yt';
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/YouTube/PlaylistVideoEntry.php 0000604 00000010127 15071256135 0013505 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_YouTube_VideoEntry
*/
require_once 'Zend/Gdata/YouTube/VideoEntry.php';
/**
* @see Zend_Gdata_YouTube_Extension_Position
*/
require_once 'Zend/Gdata/YouTube/Extension/Position.php';
/**
* Represents the YouTube video playlist flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_PlaylistVideoEntry extends Zend_Gdata_YouTube_VideoEntry
{
protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistVideoEntry';
/**
* Position of the entry in the feed, as specified by the user
*
* @var Zend_Gdata_YouTube_Extension_Position
*/
protected $_position = null;
/**
* Creates a Playlist video entry, representing an individual video
* in a list of videos contained within a specific playlist
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_position !== null) {
$element->appendChild($this->_position->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'position':
$position = new Zend_Gdata_YouTube_Extension_Position();
$position->transferFromDOM($child);
$this->_position = $position;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets the array of embedded feeds related to the video
*
* @param Zend_Gdata_YouTube_Extension_Position $position
* The position of the entry in the feed, as specified by the user.
* @return Zend_Gdata_YouTube_PlaylistVideoEntry Provides a fluent interface
*/
public function setPosition($position = null)
{
$this->_position = $position;
return $this;
}
/**
* Returns the position of the entry in the feed, as specified by the user
*
* @return Zend_Gdata_YouTube_Extension_Position The position
*/
public function getPosition()
{
return $this->_position;
}
}
Gdata/YouTube/CommentFeed.php 0000604 00000003436 15071256135 0012066 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_YouTube_CommentEntry
*/
require_once 'Zend/Gdata/YouTube/CommentEntry.php';
/**
* The YouTube comments flavor of an Atom Feed
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_CommentFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_CommentEntry';
/**
* Constructs a new YouTube Comment Feed object, to represent
* a feed of comments for an individual video
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/YouTube/SubscriptionFeed.php 0000604 00000003722 15071256135 0013146 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* @see Zend_Gdata_YouTube_SubscriptionEntry
*/
require_once 'Zend/Gdata/YouTube/SubscriptionEntry.php';
/**
* The YouTube video subscription list flavor of an Atom Feed with media support
* Represents a list of individual subscriptions, where each contained entry is
* a subscription.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_SubscriptionFeed extends Zend_Gdata_Media_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_SubscriptionEntry';
/**
* Creates a Subscription feed, representing a list of subscriptions,
* usually associated with an individual user.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/YouTube/VideoFeed.php 0000604 00000003377 15071256135 0011536 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* @see Zend_Gdata_YouTube_VideoEntry
*/
require_once 'Zend/Gdata/YouTube/VideoEntry.php';
/**
* The YouTube video flavor of an Atom Feed with media support
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_VideoFeed extends Zend_Gdata_Media_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_VideoEntry';
/**
* Creates a Video feed, representing a list of videos
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/YouTube/ContactEntry.php 0000604 00000007665 15071256135 0012325 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_YouTube_UserProfileEntry
*/
require_once 'Zend/Gdata/YouTube/UserProfileEntry.php';
/**
* @see Zend_Gdata_YouTube_Extension_Status
*/
require_once 'Zend/Gdata/YouTube/Extension/Status.php';
/**
* The YouTube contacts flavor of an Atom Entry with media support
* Represents a an individual contact
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_ContactEntry extends Zend_Gdata_YouTube_UserProfileEntry
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_ContactEntry';
/**
* Status of the user as a contact
*
* @var string
*/
protected $_status = null;
/**
* Constructs a new Contact Entry object, to represent
* an individual contact for a user
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_status != null) {
$element->appendChild($this->_status->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'status':
$status = new Zend_Gdata_YouTube_Extension_Status();
$status->transferFromDOM($child);
$this->_status = $status;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets the status
*
* @param Zend_Gdata_YouTube_Extension_Status $status The status
* @return Zend_Gdata_YouTube_ContactEntry Provides a fluent interface
*/
public function setStatus($status = null)
{
$this->_status = $status;
return $this;
}
/**
* Returns the status
*
* @return Zend_Gdata_YouTube_Extension_Status The status
*/
public function getStatus()
{
return $this->_status;
}
}
Gdata/YouTube/PlaylistListFeed.php 0000604 00000003676 15071256135 0013127 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* @see Zend_Gdata_YouTube_PlaylistListEntry
*/
require_once 'Zend/Gdata/YouTube/PlaylistListEntry.php';
/**
* The YouTube video playlist flavor of an Atom Feed with media support
* Represents a list of individual playlists, where each contained entry is
* a playlist.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_PlaylistListFeed extends Zend_Gdata_Media_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistListEntry';
/**
* Creates a Playlist list feed, representing a list of playlists,
* usually associated with an individual user.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/YouTube/PlaylistVideoFeed.php 0000604 00000003714 15071256135 0013253 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* @see Zend_Gdata_YouTube_PlaylistVideoEntry
*/
require_once 'Zend/Gdata/YouTube/PlaylistVideoEntry.php';
/**
* The YouTube video playlist flavor of an Atom Feed with media support
* Represents a list of videos contained in a playlist. Each entry in this
* feed represents an individual video.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_PlaylistVideoFeed extends Zend_Gdata_Media_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistVideoEntry';
/**
* Creates a Play Video feed, representing a list of videos contained
* within a single playlist.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/YouTube/MediaEntry.php 0000604 00000004344 15071256135 0011740 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media
*/
require_once 'Zend/Gdata/Media.php';
/**
* @see Zend_Gdata_Media_Entry
*/
require_once 'Zend/Gdata/Media/Entry.php';
/**
* @see Zend_Gdata_YouTube_Extension_MediaGroup
*/
require_once 'Zend/Gdata/YouTube/Extension/MediaGroup.php';
/**
* Represents the YouTube flavor of a Gdata Media Entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_MediaEntry extends Zend_Gdata_Media_Entry
{
protected $_entryClassName = 'Zend_Gdata_YouTube_MediaEntry';
/**
* media:group element
*
* @var Zend_Gdata_YouTube_Extension_MediaGroup
*/
protected $_mediaGroup = null;
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('media') . ':' . 'group':
$mediaGroup = new Zend_Gdata_YouTube_Extension_MediaGroup();
$mediaGroup->transferFromDOM($child);
$this->_mediaGroup = $mediaGroup;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
}
Gdata/YouTube/UserProfileEntry.php 0000604 00000072313 15071256135 0013161 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_YouTube_Extension_Description
*/
require_once 'Zend/Gdata/YouTube/Extension/Description.php';
/**
* @see Zend_Gdata_YouTube_Extension_AboutMe
*/
require_once 'Zend/Gdata/YouTube/Extension/AboutMe.php';
/**
* @see Zend_Gdata_YouTube_Extension_Age
*/
require_once 'Zend/Gdata/YouTube/Extension/Age.php';
/**
* @see Zend_Gdata_YouTube_Extension_Username
*/
require_once 'Zend/Gdata/YouTube/Extension/Username.php';
/**
* @see Zend_Gdata_YouTube_Extension_Books
*/
require_once 'Zend/Gdata/YouTube/Extension/Books.php';
/**
* @see Zend_Gdata_YouTube_Extension_Company
*/
require_once 'Zend/Gdata/YouTube/Extension/Company.php';
/**
* @see Zend_Gdata_YouTube_Extension_Hobbies
*/
require_once 'Zend/Gdata/YouTube/Extension/Hobbies.php';
/**
* @see Zend_Gdata_YouTube_Extension_Hometown
*/
require_once 'Zend/Gdata/YouTube/Extension/Hometown.php';
/**
* @see Zend_Gdata_YouTube_Extension_Location
*/
require_once 'Zend/Gdata/YouTube/Extension/Location.php';
/**
* @see Zend_Gdata_YouTube_Extension_Movies
*/
require_once 'Zend/Gdata/YouTube/Extension/Movies.php';
/**
* @see Zend_Gdata_YouTube_Extension_Music
*/
require_once 'Zend/Gdata/YouTube/Extension/Music.php';
/**
* @see Zend_Gdata_YouTube_Extension_Occupation
*/
require_once 'Zend/Gdata/YouTube/Extension/Occupation.php';
/**
* @see Zend_Gdata_YouTube_Extension_School
*/
require_once 'Zend/Gdata/YouTube/Extension/School.php';
/**
* @see Zend_Gdata_YouTube_Extension_Gender
*/
require_once 'Zend/Gdata/YouTube/Extension/Gender.php';
/**
* @see Zend_Gdata_YouTube_Extension_Relationship
*/
require_once 'Zend/Gdata/YouTube/Extension/Relationship.php';
/**
* @see Zend_Gdata_YouTube_Extension_FirstName
*/
require_once 'Zend/Gdata/YouTube/Extension/FirstName.php';
/**
* @see Zend_Gdata_YouTube_Extension_LastName
*/
require_once 'Zend/Gdata/YouTube/Extension/LastName.php';
/**
* @see Zend_Gdata_YouTube_Extension_Statistics
*/
require_once 'Zend/Gdata/YouTube/Extension/Statistics.php';
/**
* @see Zend_Gdata_Media_Extension_MediaThumbnail
*/
require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
/**
* Represents the YouTube video playlist flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_UserProfileEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_YouTube_UserProfileEntry';
/**
* Nested feed links
*
* @var array
*/
protected $_feedLink = array();
/**
* The username for this profile entry
*
* @var string
*/
protected $_username = null;
/**
* The description of the user
*
* @var string
*/
protected $_description = null;
/**
* The contents of the 'About Me' field.
*
* @var string
*/
protected $_aboutMe = null;
/**
* The age of the user
*
* @var int
*/
protected $_age = null;
/**
* Books of interest to the user
*
* @var string
*/
protected $_books = null;
/**
* Company
*
* @var string
*/
protected $_company = null;
/**
* Hobbies
*
* @var string
*/
protected $_hobbies = null;
/**
* Hometown
*
* @var string
*/
protected $_hometown = null;
/**
* Location
*
* @var string
*/
protected $_location = null;
/**
* Movies
*
* @var string
*/
protected $_movies = null;
/**
* Music
*
* @var string
*/
protected $_music = null;
/**
* Occupation
*
* @var string
*/
protected $_occupation = null;
/**
* School
*
* @var string
*/
protected $_school = null;
/**
* Gender
*
* @var string
*/
protected $_gender = null;
/**
* Relationship
*
* @var string
*/
protected $_relationship = null;
/**
* First name
*
* @var string
*/
protected $_firstName = null;
/**
* Last name
*
* @var string
*/
protected $_lastName = null;
/**
* Statistics
*
* @var Zend_Gdata_YouTube_Extension_Statistics
*/
protected $_statistics = null;
/**
* Thumbnail
*
* @var Zend_Gdata_Media_Extension_MediaThumbnail
*/
protected $_thumbnail = null;
/**
* Creates a User Profile entry, representing an individual user
* and their attributes.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_description != null) {
$element->appendChild($this->_description->getDOM($element->ownerDocument));
}
if ($this->_aboutMe != null) {
$element->appendChild($this->_aboutMe->getDOM($element->ownerDocument));
}
if ($this->_age != null) {
$element->appendChild($this->_age->getDOM($element->ownerDocument));
}
if ($this->_username != null) {
$element->appendChild($this->_username->getDOM($element->ownerDocument));
}
if ($this->_books != null) {
$element->appendChild($this->_books->getDOM($element->ownerDocument));
}
if ($this->_company != null) {
$element->appendChild($this->_company->getDOM($element->ownerDocument));
}
if ($this->_hobbies != null) {
$element->appendChild($this->_hobbies->getDOM($element->ownerDocument));
}
if ($this->_hometown != null) {
$element->appendChild($this->_hometown->getDOM($element->ownerDocument));
}
if ($this->_location != null) {
$element->appendChild($this->_location->getDOM($element->ownerDocument));
}
if ($this->_movies != null) {
$element->appendChild($this->_movies->getDOM($element->ownerDocument));
}
if ($this->_music != null) {
$element->appendChild($this->_music->getDOM($element->ownerDocument));
}
if ($this->_occupation != null) {
$element->appendChild($this->_occupation->getDOM($element->ownerDocument));
}
if ($this->_school != null) {
$element->appendChild($this->_school->getDOM($element->ownerDocument));
}
if ($this->_gender != null) {
$element->appendChild($this->_gender->getDOM($element->ownerDocument));
}
if ($this->_relationship != null) {
$element->appendChild($this->_relationship->getDOM($element->ownerDocument));
}
if ($this->_firstName != null) {
$element->appendChild($this->_firstName->getDOM($element->ownerDocument));
}
if ($this->_lastName != null) {
$element->appendChild($this->_lastName->getDOM($element->ownerDocument));
}
if ($this->_statistics != null) {
$element->appendChild($this->_statistics->getDOM($element->ownerDocument));
}
if ($this->_thumbnail != null) {
$element->appendChild($this->_thumbnail->getDOM($element->ownerDocument));
}
if ($this->_feedLink != null) {
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM($element->ownerDocument));
}
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'description':
$description = new Zend_Gdata_YouTube_Extension_Description();
$description->transferFromDOM($child);
$this->_description = $description;
break;
case $this->lookupNamespace('yt') . ':' . 'aboutMe':
$aboutMe = new Zend_Gdata_YouTube_Extension_AboutMe();
$aboutMe->transferFromDOM($child);
$this->_aboutMe = $aboutMe;
break;
case $this->lookupNamespace('yt') . ':' . 'age':
$age = new Zend_Gdata_YouTube_Extension_Age();
$age->transferFromDOM($child);
$this->_age = $age;
break;
case $this->lookupNamespace('yt') . ':' . 'username':
$username = new Zend_Gdata_YouTube_Extension_Username();
$username->transferFromDOM($child);
$this->_username = $username;
break;
case $this->lookupNamespace('yt') . ':' . 'books':
$books = new Zend_Gdata_YouTube_Extension_Books();
$books->transferFromDOM($child);
$this->_books = $books;
break;
case $this->lookupNamespace('yt') . ':' . 'company':
$company = new Zend_Gdata_YouTube_Extension_Company();
$company->transferFromDOM($child);
$this->_company = $company;
break;
case $this->lookupNamespace('yt') . ':' . 'hobbies':
$hobbies = new Zend_Gdata_YouTube_Extension_Hobbies();
$hobbies->transferFromDOM($child);
$this->_hobbies = $hobbies;
break;
case $this->lookupNamespace('yt') . ':' . 'hometown':
$hometown = new Zend_Gdata_YouTube_Extension_Hometown();
$hometown->transferFromDOM($child);
$this->_hometown = $hometown;
break;
case $this->lookupNamespace('yt') . ':' . 'location':
$location = new Zend_Gdata_YouTube_Extension_Location();
$location->transferFromDOM($child);
$this->_location = $location;
break;
case $this->lookupNamespace('yt') . ':' . 'movies':
$movies = new Zend_Gdata_YouTube_Extension_Movies();
$movies->transferFromDOM($child);
$this->_movies = $movies;
break;
case $this->lookupNamespace('yt') . ':' . 'music':
$music = new Zend_Gdata_YouTube_Extension_Music();
$music->transferFromDOM($child);
$this->_music = $music;
break;
case $this->lookupNamespace('yt') . ':' . 'occupation':
$occupation = new Zend_Gdata_YouTube_Extension_Occupation();
$occupation->transferFromDOM($child);
$this->_occupation = $occupation;
break;
case $this->lookupNamespace('yt') . ':' . 'school':
$school = new Zend_Gdata_YouTube_Extension_School();
$school->transferFromDOM($child);
$this->_school = $school;
break;
case $this->lookupNamespace('yt') . ':' . 'gender':
$gender = new Zend_Gdata_YouTube_Extension_Gender();
$gender->transferFromDOM($child);
$this->_gender = $gender;
break;
case $this->lookupNamespace('yt') . ':' . 'relationship':
$relationship = new Zend_Gdata_YouTube_Extension_Relationship();
$relationship->transferFromDOM($child);
$this->_relationship = $relationship;
break;
case $this->lookupNamespace('yt') . ':' . 'firstName':
$firstName = new Zend_Gdata_YouTube_Extension_FirstName();
$firstName->transferFromDOM($child);
$this->_firstName = $firstName;
break;
case $this->lookupNamespace('yt') . ':' . 'lastName':
$lastName = new Zend_Gdata_YouTube_Extension_LastName();
$lastName->transferFromDOM($child);
$this->_lastName = $lastName;
break;
case $this->lookupNamespace('yt') . ':' . 'statistics':
$statistics = new Zend_Gdata_YouTube_Extension_Statistics();
$statistics->transferFromDOM($child);
$this->_statistics = $statistics;
break;
case $this->lookupNamespace('media') . ':' . 'thumbnail':
$thumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
$thumbnail->transferFromDOM($child);
$this->_thumbnail = $thumbnail;
break;
case $this->lookupNamespace('gd') . ':' . 'feedLink':
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets the content of the 'about me' field.
*
* @param Zend_Gdata_YouTube_Extension_AboutMe $aboutMe The 'about me'
* information.
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setAboutMe($aboutMe = null)
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The setAboutMe ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
$this->_aboutMe = $aboutMe;
return $this;
}
}
/**
* Returns the contents of the 'about me' field.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_AboutMe The 'about me' information
*/
public function getAboutMe()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getAboutMe ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_aboutMe;
}
}
/**
* Sets the content of the 'first name' field.
*
* @param Zend_Gdata_YouTube_Extension_FirstName $firstName The first name
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setFirstName($firstName = null)
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The setFirstName ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
$this->_firstName = $firstName;
return $this;
}
}
/**
* Returns the first name
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_FirstName The first name
*/
public function getFirstName()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getFirstName ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_firstName;
}
}
/**
* Sets the content of the 'last name' field.
*
* @param Zend_Gdata_YouTube_Extension_LastName $lastName The last name
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setLastName($lastName = null)
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The setLastName ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
$this->_lastName = $lastName;
return $this;
}
}
/**
* Returns the last name
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_LastName The last name
*/
public function getLastName()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getLastName ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_lastName;
}
}
/**
* Returns the statistics
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_Statistics The profile statistics
*/
public function getStatistics()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getStatistics ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_statistics;
}
}
/**
* Returns the thumbnail
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_Media_Extension_MediaThumbnail The profile thumbnail
*/
public function getThumbnail()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getThumbnail ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_thumbnail;
}
}
/**
* Sets the age
*
* @param Zend_Gdata_YouTube_Extension_Age $age The age
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setAge($age = null)
{
$this->_age = $age;
return $this;
}
/**
* Returns the age
*
* @return Zend_Gdata_YouTube_Extension_Age The age
*/
public function getAge()
{
return $this->_age;
}
/**
* Sets the username
*
* @param Zend_Gdata_YouTube_Extension_Username $username The username
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setUsername($username = null)
{
$this->_username = $username;
return $this;
}
/**
* Returns the username
*
* @return Zend_Gdata_YouTube_Extension_Username The username
*/
public function getUsername()
{
return $this->_username;
}
/**
* Sets the books
*
* @param Zend_Gdata_YouTube_Extension_Books $books The books
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setBooks($books = null)
{
$this->_books = $books;
return $this;
}
/**
* Returns the books
*
* @return Zend_Gdata_YouTube_Extension_Books The books
*/
public function getBooks()
{
return $this->_books;
}
/**
* Sets the company
*
* @param Zend_Gdata_YouTube_Extension_Company $company The company
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setCompany($company = null)
{
$this->_company = $company;
return $this;
}
/**
* Returns the company
*
* @return Zend_Gdata_YouTube_Extension_Company The company
*/
public function getCompany()
{
return $this->_company;
}
/**
* Sets the hobbies
*
* @param Zend_Gdata_YouTube_Extension_Hobbies $hobbies The hobbies
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setHobbies($hobbies = null)
{
$this->_hobbies = $hobbies;
return $this;
}
/**
* Returns the hobbies
*
* @return Zend_Gdata_YouTube_Extension_Hobbies The hobbies
*/
public function getHobbies()
{
return $this->_hobbies;
}
/**
* Sets the hometown
*
* @param Zend_Gdata_YouTube_Extension_Hometown $hometown The hometown
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setHometown($hometown = null)
{
$this->_hometown = $hometown;
return $this;
}
/**
* Returns the hometown
*
* @return Zend_Gdata_YouTube_Extension_Hometown The hometown
*/
public function getHometown()
{
return $this->_hometown;
}
/**
* Sets the location
*
* @param Zend_Gdata_YouTube_Extension_Location $location The location
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setLocation($location = null)
{
$this->_location = $location;
return $this;
}
/**
* Returns the location
*
* @return Zend_Gdata_YouTube_Extension_Location The location
*/
public function getLocation()
{
return $this->_location;
}
/**
* Sets the movies
*
* @param Zend_Gdata_YouTube_Extension_Movies $movies The movies
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setMovies($movies = null)
{
$this->_movies = $movies;
return $this;
}
/**
* Returns the movies
*
* @return Zend_Gdata_YouTube_Extension_Movies The movies
*/
public function getMovies()
{
return $this->_movies;
}
/**
* Sets the music
*
* @param Zend_Gdata_YouTube_Extension_Music $music The music
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setMusic($music = null)
{
$this->_music = $music;
return $this;
}
/**
* Returns the music
*
* @return Zend_Gdata_YouTube_Extension_Music The music
*/
public function getMusic()
{
return $this->_music;
}
/**
* Sets the occupation
*
* @param Zend_Gdata_YouTube_Extension_Occupation $occupation The occupation
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setOccupation($occupation = null)
{
$this->_occupation = $occupation;
return $this;
}
/**
* Returns the occupation
*
* @return Zend_Gdata_YouTube_Extension_Occupation The occupation
*/
public function getOccupation()
{
return $this->_occupation;
}
/**
* Sets the school
*
* @param Zend_Gdata_YouTube_Extension_School $school The school
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setSchool($school = null)
{
$this->_school = $school;
return $this;
}
/**
* Returns the school
*
* @return Zend_Gdata_YouTube_Extension_School The school
*/
public function getSchool()
{
return $this->_school;
}
/**
* Sets the gender
*
* @param Zend_Gdata_YouTube_Extension_Gender $gender The gender
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setGender($gender = null)
{
$this->_gender = $gender;
return $this;
}
/**
* Returns the gender
*
* @return Zend_Gdata_YouTube_Extension_Gender The gender
*/
public function getGender()
{
return $this->_gender;
}
/**
* Sets the relationship
*
* @param Zend_Gdata_YouTube_Extension_Relationship $relationship The relationship
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setRelationship($relationship = null)
{
$this->_relationship = $relationship;
return $this;
}
/**
* Returns the relationship
*
* @return Zend_Gdata_YouTube_Extension_Relationship The relationship
*/
public function getRelationship()
{
return $this->_relationship;
}
/**
* Sets the array of embedded feeds related to the video
*
* @param array $feedLink The array of embedded feeds relating to the video
* @return Zend_Gdata_YouTube_UserProfileEntry Provides a fluent interface
*/
public function setFeedLink($feedLink = null)
{
$this->_feedLink = $feedLink;
return $this;
}
/**
* Get the feed link property for this entry.
*
* @see setFeedLink
* @param string $rel (optional) The rel value of the link to be found.
* If null, the array of links is returned.
* @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
* object corresponding to the requested rel value is returned
* if found, or null if the requested value is not found. If
* $rel is null or not specified, an array of all available
* feed links for this entry is returned, or null if no feed
* links are set.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Returns the URL in the gd:feedLink with the provided rel value
*
* @param string $rel The rel value to find
* @return mixed Either the URL as a string or null if a feedLink wasn't
* found with the provided rel value
*/
public function getFeedLinkHref($rel)
{
$feedLink = $this->getFeedLink($rel);
if ($feedLink !== null) {
return $feedLink->href;
} else {
return null;
}
}
/**
* Returns the URL of the playlist list feed
*
* @return string The URL of the playlist video feed
*/
public function getPlaylistListFeedUrl()
{
return getFeedLinkHref(Zend_Gdata_YouTube::USER_PLAYLISTS_REL);
}
/**
* Returns the URL of the uploads feed
*
* @return string The URL of the uploads video feed
*/
public function getUploadsFeedUrl()
{
return getFeedLinkHref(Zend_Gdata_YouTube::USER_UPLOADS_REL);
}
/**
* Returns the URL of the subscriptions feed
*
* @return string The URL of the subscriptions feed
*/
public function getSubscriptionsFeedUrl()
{
return getFeedLinkHref(Zend_Gdata_YouTube::USER_SUBSCRIPTIONS_REL);
}
/**
* Returns the URL of the contacts feed
*
* @return string The URL of the contacts feed
*/
public function getContactsFeedUrl()
{
return getFeedLinkHref(Zend_Gdata_YouTube::USER_CONTACTS_REL);
}
/**
* Returns the URL of the favorites feed
*
* @return string The URL of the favorites feed
*/
public function getFavoritesFeedUrl()
{
return getFeedLinkHref(Zend_Gdata_YouTube::USER_FAVORITES_REL);
}
}
Gdata/YouTube/VideoQuery.php 0000604 00000041272 15071256135 0011774 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_YouTube
*/
require_once('Zend/Gdata/YouTube.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for YouTube videos
*
* @link http://code.google.com/apis/youtube/
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
{
/**
* Create Gdata_YouTube_VideoQuery object
*/
public function __construct($url = null)
{
parent::__construct($url);
}
/**
* Sets the type of feed this query should be used to search
*
* @param string $feedType The type of feed
* @param string $videoId The ID of the video associated with this query
* @param string $entry The ID of the entry associated with this query
*/
public function setFeedType($feedType, $videoId = null, $entry = null)
{
switch ($feedType) {
case 'top rated':
$this->_url = Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI;
break;
case 'most viewed':
$this->_url = Zend_Gdata_YouTube::STANDARD_MOST_VIEWED_URI;
break;
case 'recently featured':
$this->_url = Zend_Gdata_YouTube::STANDARD_RECENTLY_FEATURED_URI;
break;
case 'mobile':
$this->_url = Zend_Gdata_YouTube::STANDARD_WATCH_ON_MOBILE_URI;
break;
case 'related':
if ($videoId === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Video ID must be set for feed of type: ' . $feedType);
} else {
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId .
'/related';
}
break;
case 'responses':
if ($videoId === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_Exception(
'Video ID must be set for feed of type: ' . $feedType);
} else {
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId .
'responses';
}
break;
case 'comments':
if ($videoId === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_Exception(
'Video ID must be set for feed of type: ' . $feedType);
} else {
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' .
$videoId . 'comments';
if ($entry !== null) {
$this->_url .= '/' . $entry;
}
}
break;
default:
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Unknown feed type');
break;
}
}
/**
* Sets the location parameter for the query
*
* @param string $value
* @throws Zend_Gdata_App_InvalidArgumentException
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setLocation($value)
{
switch($value) {
case null:
unset($this->_params['location']);
default:
$parameters = explode(',', $value);
if (count($parameters) != 2) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You must provide 2 coordinates to the location ' .
'URL parameter');
}
foreach($parameters as $param) {
$temp = trim($param);
// strip off the optional exclamation mark for numeric check
if (substr($temp, -1) == '!') {
$temp = substr($temp, -1);
}
if (!is_numeric($temp)) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Value provided to location parameter must' .
' be in the form of two coordinates');
}
}
$this->_params['location'] = $value;
}
}
/**
* Get the value of the location parameter
*
* @return string|null Return the location if it exists, null otherwise.
*/
public function getLocation()
{
if (array_key_exists('location', $this->_params)) {
return $this->_params['location'];
} else {
return null;
}
}
/**
* Sets the location-radius parameter for the query
*
* @param string $value
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setLocationRadius($value)
{
switch($value) {
case null:
unset($this->_params['location-radius']);
default:
$this->_params['location-radius'] = $value;
}
}
/**
* Get the value of the location-radius parameter
*
* @return string|null Return the location-radius if it exists,
* null otherwise.
*/
public function getLocationRadius()
{
if (array_key_exists('location-radius', $this->_params)) {
return $this->_params['location-radius'];
} else {
return null;
}
}
/**
* Sets the time period over which this query should apply
*
* @param string $value
* @throws Zend_Gdata_App_InvalidArgumentException
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setTime($value = null)
{
switch ($value) {
case 'today':
$this->_params['time'] = 'today';
break;
case 'this_week':
$this->_params['time'] = 'this_week';
break;
case 'this_month':
$this->_params['time'] = 'this_month';
break;
case 'all_time':
$this->_params['time'] = 'all_time';
break;
case null:
unset($this->_params['time']);
default:
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Unknown time value');
break;
}
return $this;
}
/**
* Sets the value of the uploader parameter
*
* @param string $value The value of the uploader parameter. Currently this
* can only be set to the value of 'partner'.
* @throws Zend_Gdata_App_InvalidArgumentException
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setUploader($value = null)
{
switch ($value) {
case 'partner':
$this->_params['uploader'] = 'partner';
break;
case null:
unset($this->_params['uploader']);
break;
default:
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Unknown value for uploader');
}
return $this;
}
/**
* Sets the formatted video query (vq) URL param value
*
* @param string $value
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setVideoQuery($value = null)
{
if ($value != null) {
$this->_params['vq'] = $value;
} else {
unset($this->_params['vq']);
}
return $this;
}
/**
* Sets the param to return videos of a specific format
*
* @param string $value
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setFormat($value = null)
{
if ($value != null) {
$this->_params['format'] = $value;
} else {
unset($this->_params['format']);
}
return $this;
}
/**
* Sets whether or not to include racy videos in the search results
*
* @param string $value
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setRacy($value = null)
{
switch ($value) {
case 'include':
$this->_params['racy'] = $value;
break;
case 'exclude':
$this->_params['racy'] = $value;
break;
case null:
unset($this->_params['racy']);
break;
}
return $this;
}
/**
* Whether or not to include racy videos in the search results
*
* @return string|null The value of racy if it exists, null otherwise.
*/
public function getRacy()
{
if (array_key_exists('racy', $this->_params)) {
return $this->_params['racy'];
} else {
return null;
}
}
/**
* Set the safeSearch parameter
*
* @param string $value The value of the parameter, currently only 'none',
* 'moderate' or 'strict' are allowed values.
* @throws Zend_Gdata_App_InvalidArgumentException
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
*/
public function setSafeSearch($value)
{
switch ($value) {
case 'none':
$this->_params['safeSearch'] = 'none';
break;
case 'moderate':
$this->_params['safeSearch'] = 'moderate';
break;
case 'strict':
$this->_params['safeSearch'] = 'strict';
break;
case null:
unset($this->_params['safeSearch']);
default:
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'The safeSearch parameter only supports the values '.
'\'none\', \'moderate\' or \'strict\'.');
}
}
/**
* Return the value of the safeSearch parameter
*
* @return string|null The value of the safeSearch parameter if it has been
* set, null otherwise.
*/
public function getSafeSearch()
{
if (array_key_exists('safeSearch', $this->_params)) {
return $this->_params['safeSearch'];
}
return $this;
}
/**
* Set the value of the orderby parameter
*
* @param string $value
* @return Zend_Gdata_YouTube_Query Provides a fluent interface
*/
public function setOrderBy($value)
{
if ($value != null) {
$this->_params['orderby'] = $value;
} else {
unset($this->_params['orderby']);
}
return $this;
}
/**
* Return the value of the format parameter
*
* @return string|null The value of format if it exists, null otherwise.
*/
public function getFormat()
{
if (array_key_exists('format', $this->_params)) {
return $this->_params['format'];
} else {
return null;
}
}
/**
* Return the value of the video query that has been set
*
* @return string|null The value of the video query if it exists,
* null otherwise.
*/
public function getVideoQuery()
{
if (array_key_exists('vq', $this->_params)) {
return $this->_params['vq'];
} else {
return null;
}
}
/**
* Return the value of the time parameter
*
* @return string|null The time parameter if it exists, null otherwise.
*/
public function getTime()
{
if (array_key_exists('time', $this->_params)) {
return $this->_params['time'];
} else {
return null;
}
}
/**
* Return the value of the orderby parameter if it exists
*
* @return string|null The value of orderby if it exists, null otherwise.
*/
public function getOrderBy()
{
if (array_key_exists('orderby', $this->_params)) {
return $this->_params['orderby'];
} else {
return null;
}
}
/**
* Generate the query string from the URL parameters, optionally modifying
* them based on protocol version.
*
* @param integer $majorProtocolVersion The major protocol version
* @param integer $minorProtocolVersion The minor protocol version
* @throws Zend_Gdata_App_VersionException
* @return string querystring
*/
public function getQueryString($majorProtocolVersion = null,
$minorProtocolVersion = null)
{
$queryArray = array();
foreach ($this->_params as $name => $value) {
if (substr($name, 0, 1) == '_') {
continue;
}
switch($name) {
case 'location-radius':
if ($majorProtocolVersion == 1) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException("The $name " .
"parameter is only supported in version 2.");
}
break;
case 'racy':
if ($majorProtocolVersion == 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException("The $name " .
"parameter is not supported in version 2. " .
"Please use 'safeSearch'.");
}
break;
case 'safeSearch':
if ($majorProtocolVersion == 1) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException("The $name " .
"parameter is only supported in version 2. " .
"Please use 'racy'.");
}
break;
case 'uploader':
if ($majorProtocolVersion == 1) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException("The $name " .
"parameter is only supported in version 2.");
}
break;
case 'vq':
if ($majorProtocolVersion == 2) {
$name = 'q';
}
break;
}
$queryArray[] = urlencode($name) . '=' . urlencode($value);
}
if (count($queryArray) > 0) {
return '?' . implode('&', $queryArray);
} else {
return '';
}
}
/**
* Returns the generated full query URL, optionally modifying it based on
* the protocol version.
*
* @param integer $majorProtocolVersion The major protocol version
* @param integer $minorProtocolVersion The minor protocol version
* @return string The URL
*/
public function getQueryUrl($majorProtocolVersion = null,
$minorProtocolVersion = null)
{
if (isset($this->_url)) {
$url = $this->_url;
} else {
$url = Zend_Gdata_YouTube::VIDEO_URI;
}
if ($this->getCategory() !== null) {
$url .= '/-/' . $this->getCategory();
}
$url = $url . $this->getQueryString($majorProtocolVersion,
$minorProtocolVersion);
return $url;
}
}
Gdata/YouTube/SubscriptionEntry.php 0000604 00000034677 15071256135 0013421 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_YouTube_Extension_Description
*/
require_once 'Zend/Gdata/YouTube/Extension/Description.php';
/**
* @see Zend_Gdata_YouTube_Extension_PlaylistTitle
*/
require_once 'Zend/Gdata/YouTube/Extension/PlaylistTitle.php';
/**
* @see Zend_Gdata_YouTube_Extension_PlaylistId
*/
require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
/**
* @see Zend_Gdata_Media_Extension_MediaThumbnail
*/
require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
/**
* @see Zend_Gdata_YouTube_Extension_Username
*/
require_once 'Zend/Gdata/YouTube/Extension/Username.php';
/**
* @see Zend_Gdata_YouTube_Extension_CountHint
*/
require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
/**
* @see Zend_Gdata_YouTube_Extension_QueryString
*/
require_once 'Zend/Gdata/YouTube/Extension/QueryString.php';
/**
* Represents the YouTube video subscription flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_SubscriptionEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_YouTube_SubscriptionEntry';
/**
* Nested feed links
*
* @var array
*/
protected $_feedLink = array();
/**
* The username of this entry.
*
* @var Zend_Gdata_YouTube_Extension_Username
*/
protected $_username = null;
/**
* The playlist title for this entry.
*
* This element is only used on subscriptions to playlists.
*
* @var Zend_Gdata_YouTube_Extension_PlaylistTitle
*/
protected $_playlistTitle = null;
/**
* The playlist id for this entry.
*
* This element is only used on subscriptions to playlists.
*
* @var Zend_Gdata_YouTube_Extension_PlaylistId
*/
protected $_playlistId = null;
/**
* The media:thumbnail element for this entry.
*
* This element is only used on subscriptions to playlists.
*
* @var Zend_Gdata_Media_Extension_MediaThumbnail
*/
protected $_mediaThumbnail = null;
/**
* The countHint for this entry.
*
* @var Zend_Gdata_YouTube_Extension_CountHint
*/
protected $_countHint = null;
/**
* The queryString for this entry.
*
* @var Zend_Gdata_YouTube_Extension_QueryString
*/
protected $_queryString = null;
/**
* Creates a subscription entry, representing an individual subscription
* in a list of subscriptions, usually associated with an individual user.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_countHint != null) {
$element->appendChild($this->_countHint->getDOM($element->ownerDocument));
}
if ($this->_playlistTitle != null) {
$element->appendChild($this->_playlistTitle->getDOM($element->ownerDocument));
}
if ($this->_playlistId != null) {
$element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
}
if ($this->_mediaThumbnail != null) {
$element->appendChild($this->_mediaThumbnail->getDOM($element->ownerDocument));
}
if ($this->_username != null) {
$element->appendChild($this->_username->getDOM($element->ownerDocument));
}
if ($this->_queryString != null) {
$element->appendChild($this->_queryString->getDOM($element->ownerDocument));
}
if ($this->_feedLink != null) {
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM($element->ownerDocument));
}
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gd') . ':' . 'feedLink':
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
case $this->lookupNamespace('media') . ':' . 'thumbnail':
$mediaThumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
$mediaThumbnail->transferFromDOM($child);
$this->_mediaThumbnail = $mediaThumbnail;
break;
case $this->lookupNamespace('yt') . ':' . 'countHint':
$countHint = new Zend_Gdata_YouTube_Extension_CountHint();
$countHint->transferFromDOM($child);
$this->_countHint = $countHint;
break;
case $this->lookupNamespace('yt') . ':' . 'playlistTitle':
$playlistTitle = new Zend_Gdata_YouTube_Extension_PlaylistTitle();
$playlistTitle->transferFromDOM($child);
$this->_playlistTitle = $playlistTitle;
break;
case $this->lookupNamespace('yt') . ':' . 'playlistId':
$playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
$playlistId->transferFromDOM($child);
$this->_playlistId = $playlistId;
break;
case $this->lookupNamespace('yt') . ':' . 'queryString':
$queryString = new Zend_Gdata_YouTube_Extension_QueryString();
$queryString->transferFromDOM($child);
$this->_queryString = $queryString;
break;
case $this->lookupNamespace('yt') . ':' . 'username':
$username = new Zend_Gdata_YouTube_Extension_Username();
$username->transferFromDOM($child);
$this->_username = $username;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets the array of embedded feeds related to the video
*
* @param array $feedLink The array of embedded feeds relating to the video
* @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
*/
public function setFeedLink($feedLink = null)
{
$this->_feedLink = $feedLink;
return $this;
}
/**
* Get the feed link property for this entry.
*
* @see setFeedLink
* @param string $rel (optional) The rel value of the link to be found.
* If null, the array of links is returned.
* @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
* object corresponding to the requested rel value is returned
* if found, or null if the requested value is not found. If
* $rel is null or not specified, an array of all available
* feed links for this entry is returned, or null if no feed
* links are set.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Get the playlist title for a 'playlist' subscription.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_PlaylistId
*/
public function getPlaylistId()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getPlaylistId ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_playlistId;
}
}
/**
* Sets the yt:playlistId element for a new playlist subscription.
*
* @param Zend_Gdata_YouTube_Extension_PlaylistId $id The id of
* the playlist to which to subscribe to.
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
*/
public function setPlaylistId($id = null)
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
$this->_playlistId = $id;
return $this;
}
}
/**
* Get the queryString of the subscription
*
* @return Zend_Gdata_YouTube_Extension_QueryString
*/
public function getQueryString()
{
return $this->_queryString;
}
/**
* Sets the yt:queryString element for a new keyword subscription.
*
* @param Zend_Gdata_YouTube_Extension_QueryString $queryString The query
* string to subscribe to
* @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
*/
public function setQueryString($queryString = null)
{
$this->_queryString = $queryString;
return $this;
}
/**
* Get the playlist title for a 'playlist' subscription.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_PlaylistTitle
*/
public function getPlaylistTitle()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getPlaylistTitle ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_playlistTitle;
}
}
/**
* Sets the yt:playlistTitle element for a new playlist subscription.
*
* @param Zend_Gdata_YouTube_Extension_PlaylistTitle $title The title of
* the playlist to which to subscribe to.
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
*/
public function setPlaylistTitle($title = null)
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
$this->_playlistTitle = $title;
return $this;
}
}
/**
* Get the counthint for a subscription.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_CountHint
*/
public function getCountHint()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getCountHint ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_countHint;
}
}
/**
* Get the thumbnail for a subscription.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_Media_Extension_MediaThumbnail
*/
public function getMediaThumbnail()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The getMediaThumbnail ' .
' method is only supported as of version 2 of the YouTube ' .
'API.');
} else {
return $this->_mediaThumbnail;
}
}
/**
* Get the username for a channel subscription.
*
* @return Zend_Gdata_YouTube_Extension_Username
*/
public function getUsername()
{
return $this->_username;
}
/**
* Sets the username for a new channel subscription.
*
* @param Zend_Gdata_YouTube_Extension_Username $username The username of
* the channel to which to subscribe to.
* @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
*/
public function setUsername($username = null)
{
$this->_username = $username;
return $this;
}
}
Gdata/YouTube/PlaylistListEntry.php 0000604 00000022711 15071256135 0013354 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_YouTube
*/
require_once 'Zend/Gdata/YouTube.php';
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_YouTube_Extension_Description
*/
require_once 'Zend/Gdata/YouTube/Extension/Description.php';
/**
* @see Zend_Gdata_YouTube_Extension_PlaylistId
*/
require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
/**
* @see Zend_Gdata_YouTube_Extension_CountHint
*/
require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
/**
* Represents the YouTube video playlist flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_PlaylistListEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistListEntry';
/**
* Nested feed links
*
* @var array
*/
protected $_feedLink = array();
/**
* Description of this playlist
*
* @deprecated Deprecated as of version 2 of the YouTube API.
* @var Zend_Gdata_YouTube_Extension_Description
*/
protected $_description = null;
/**
* Id of this playlist
*
* @var Zend_Gdata_YouTube_Extension_PlaylistId
*/
protected $_playlistId = null;
/**
* CountHint for this playlist.
*
* @var Zend_Gdata_YouTube_Extension_CountHint
*/
protected $_countHint = null;
/**
* Creates a Playlist list entry, representing an individual playlist
* in a list of playlists, usually associated with an individual user.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_description != null) {
$element->appendChild($this->_description->getDOM($element->ownerDocument));
}
if ($this->_countHint != null) {
$element->appendChild($this->_countHint->getDOM($element->ownerDocument));
}
if ($this->_playlistId != null) {
$element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
}
if ($this->_feedLink != null) {
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM($element->ownerDocument));
}
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'description':
$description = new Zend_Gdata_YouTube_Extension_Description();
$description->transferFromDOM($child);
$this->_description = $description;
break;
case $this->lookupNamespace('yt') . ':' . 'countHint':
$countHint = new Zend_Gdata_YouTube_Extension_CountHint();
$countHint->transferFromDOM($child);
$this->_countHint = $countHint;
break;
case $this->lookupNamespace('yt') . ':' . 'playlistId':
$playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
$playlistId->transferFromDOM($child);
$this->_playlistId = $playlistId;
break;
case $this->lookupNamespace('gd') . ':' . 'feedLink':
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets the description relating to the playlist.
*
* @deprecated Deprecated as of version 2 of the YouTube API.
* @param Zend_Gdata_YouTube_Extension_Description $description The description relating to the video
* @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
*/
public function setDescription($description = null)
{
if ($this->getMajorProtocolVersion() >= 2) {
$this->setSummary($description);
} else {
$this->_description = $description;
}
return $this;
}
/**
* Returns the description relating to the video.
*
* @return Zend_Gdata_YouTube_Extension_Description The description
* relating to the video
*/
public function getDescription()
{
if ($this->getMajorProtocolVersion() >= 2) {
return $this->getSummary();
} else {
return $this->_description;
}
}
/**
* Returns the countHint relating to the playlist.
*
* The countHint is the number of videos on a playlist.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_CountHint The count of videos on
* a playlist.
*/
public function getCountHint()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:countHint ' .
'element is not supported in versions earlier than 2.');
} else {
return $this->_countHint;
}
}
/**
* Returns the Id relating to the playlist.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
*/
public function getPlaylistId()
{
if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {
return $this->_playlistId;
}
}
/**
* Sets the array of embedded feeds related to the playlist
*
* @param array $feedLink The array of embedded feeds relating to the video
* @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
*/
public function setFeedLink($feedLink = null)
{
$this->_feedLink = $feedLink;
return $this;
}
/**
* Get the feed link property for this entry.
*
* @see setFeedLink
* @param string $rel (optional) The rel value of the link to be found.
* If null, the array of links is returned.
* @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
* object corresponding to the requested rel value is returned
* if found, or null if the requested value is not found. If
* $rel is null or not specified, an array of all available
* feed links for this entry is returned, or null if no feed
* links are set.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Returns the URL of the playlist video feed
*
* @return string The URL of the playlist video feed
*/
public function getPlaylistVideoFeedUrl()
{
if ($this->getMajorProtocolVersion() >= 2) {
return $this->getContent()->getSrc();
} else {
return $this->getFeedLink(Zend_Gdata_YouTube::PLAYLIST_REL)->href;
}
}
}
Gdata/YouTube/VideoEntry.php 0000604 00000101744 15071256135 0011771 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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: VideoEntry.php 13360 2008-12-18 22:54:14Z jhartmann $
*/
/**
* @see Zend_Gdata_Extension_Comments
*/
require_once 'Zend/Gdata/Extension/Comments.php';
/**
* @see Zend_Gdata_Extension_FeedLink
*/
require_once 'Zend/Gdata/Extension/FeedLink.php';
/**
* @see Zend_Gdata_YouTube_MediaEntry
*/
require_once 'Zend/Gdata/YouTube/MediaEntry.php';
/**
* @see Zend_Gdata_YouTube_Extension_MediaGroup
*/
require_once 'Zend/Gdata/YouTube/Extension/MediaGroup.php';
/**
* @see Zend_Gdata_YouTube_Extension_NoEmbed
*/
require_once 'Zend/Gdata/YouTube/Extension/NoEmbed.php';
/**
* @see Zend_Gdata_YouTube_Extension_Statistics
*/
require_once 'Zend/Gdata/YouTube/Extension/Statistics.php';
/**
* @see Zend_Gdata_YouTube_Extension_Link
*/
require_once 'Zend/Gdata/YouTube/Extension/Link.php';
/**
* @see Zend_Gdata_YouTube_Extension_Racy
*/
require_once 'Zend/Gdata/YouTube/Extension/Racy.php';
/**
* @see Zend_Gdata_Extension_Rating
*/
require_once 'Zend/Gdata/Extension/Rating.php';
/**
* @see Zend_Gdata_Geo_Extension_GeoRssWhere
*/
require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
/**
* @see Zend_Gdata_YouTube_Extension_Control
*/
require_once 'Zend/Gdata/YouTube/Extension/Control.php';
/**
* @see Zend_Gdata_YouTube_Extension_Recorded
*/
require_once 'Zend/Gdata/YouTube/Extension/Recorded.php';
/**
* @see Zend_Gdata_YouTube_Extension_Location
*/
require_once 'Zend/Gdata/YouTube/Extension/Location.php';
/**
* Represents the YouTube video flavor of an Atom entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_VideoEntry extends Zend_Gdata_YouTube_MediaEntry
{
const YOUTUBE_DEVELOPER_TAGS_SCHEMA = 'http://gdata.youtube.com/schemas/2007/developertags.cat';
const YOUTUBE_CATEGORY_SCHEMA = 'http://gdata.youtube.com/schemas/2007/categories.cat';
protected $_entryClassName = 'Zend_Gdata_YouTube_VideoEntry';
/**
* If null, the video can be embedded
*
* @var Zend_Gdata_YouTube_Extension_NoEmbed|null
*/
protected $_noEmbed = null;
/**
* Specifies the statistics relating to the video.
*
* @var Zend_Gdata_YouTube_Extension_Statistics
*/
protected $_statistics = null;
/**
* If not null, specifies that the video has racy content.
*
* @var Zend_Gdata_YouTube_Extension_Racy|null
*/
protected $_racy = null;
/**
* If not null, specifies that the video is private.
*
* @var Zend_Gdata_YouTube_Extension_Private|null
*/
protected $_private = null;
/**
* Specifies the video's rating.
*
* @var Zend_Gdata_Extension_Rating
*/
protected $_rating = null;
/**
* Specifies the comments associated with a video.
*
* @var Zend_Gdata_Extensions_Comments
*/
protected $_comments = null;
/**
* Nested feed links
*
* @var array
*/
protected $_feedLink = array();
/**
* Geo location for the video
*
* @var Zend_Gdata_Geo_Extension_GeoRssWhere
*/
protected $_where = null;
/**
* Recording date for the video
*
* @var Zend_Gdata_YouTube_Extension_Recorded|null
*/
protected $_recorded = null;
/**
* Location informtion for the video
*
* @var Zend_Gdata_YouTube_Extension_Location|null
*/
protected $_location = null;
/**
* Creates a Video entry, representing an individual video
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_noEmbed != null) {
$element->appendChild($this->_noEmbed->getDOM(
$element->ownerDocument));
}
if ($this->_statistics != null) {
$element->appendChild($this->_statistics->getDOM(
$element->ownerDocument));
}
if ($this->_racy != null) {
$element->appendChild($this->_racy->getDOM(
$element->ownerDocument));
}
if ($this->_recorded != null) {
$element->appendChild($this->_recorded->getDOM(
$element->ownerDocument));
}
if ($this->_location != null) {
$element->appendChild($this->_location->getDOM(
$element->ownerDocument));
}
if ($this->_rating != null) {
$element->appendChild($this->_rating->getDOM(
$element->ownerDocument));
}
if ($this->_comments != null) {
$element->appendChild($this->_comments->getDOM(
$element->ownerDocument));
}
if ($this->_feedLink != null) {
foreach ($this->_feedLink as $feedLink) {
$element->appendChild($feedLink->getDOM(
$element->ownerDocument));
}
}
if ($this->_where != null) {
$element->appendChild($this->_where->getDOM(
$element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('yt') . ':' . 'statistics':
$statistics = new Zend_Gdata_YouTube_Extension_Statistics();
$statistics->transferFromDOM($child);
$this->_statistics = $statistics;
break;
case $this->lookupNamespace('yt') . ':' . 'racy':
$racy = new Zend_Gdata_YouTube_Extension_Racy();
$racy->transferFromDOM($child);
$this->_racy = $racy;
break;
case $this->lookupNamespace('yt') . ':' . 'recorded':
$recorded = new Zend_Gdata_YouTube_Extension_Recorded();
$recorded->transferFromDOM($child);
$this->_recorded = $recorded;
break;
case $this->lookupNamespace('yt') . ':' . 'location':
$location = new Zend_Gdata_YouTube_Extension_Location();
$location->transferFromDOM($child);
$this->_location = $location;
break;
case $this->lookupNamespace('gd') . ':' . 'rating':
$rating = new Zend_Gdata_Extension_Rating();
$rating->transferFromDOM($child);
$this->_rating = $rating;
break;
case $this->lookupNamespace('gd') . ':' . 'comments':
$comments = new Zend_Gdata_Extension_Comments();
$comments->transferFromDOM($child);
$this->_comments = $comments;
break;
case $this->lookupNamespace('yt') . ':' . 'noembed':
$noEmbed = new Zend_Gdata_YouTube_Extension_NoEmbed();
$noEmbed->transferFromDOM($child);
$this->_noEmbed = $noEmbed;
break;
case $this->lookupNamespace('gd') . ':' . 'feedLink':
$feedLink = new Zend_Gdata_Extension_FeedLink();
$feedLink->transferFromDOM($child);
$this->_feedLink[] = $feedLink;
break;
case $this->lookupNamespace('georss') . ':' . 'where':
$where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$where->transferFromDOM($child);
$this->_where = $where;
break;
case $this->lookupNamespace('atom') . ':' . 'link';
$link = new Zend_Gdata_YouTube_Extension_Link();
$link->transferFromDOM($child);
$this->_link[] = $link;
break;
case $this->lookupNamespace('app') . ':' . 'control':
$control = new Zend_Gdata_YouTube_Extension_Control();
$control->transferFromDOM($child);
$this->_control = $control;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Sets when the video was recorded.
*
* @param Zend_Gdata_YouTube_Extension_Recorded $recorded When the video was recorded
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setRecorded($recorded = null)
{
$this->_recorded = $recorded;
return $this;
}
/**
* Gets the date that the video was recorded.
*
* @return Zend_Gdata_YouTube_Extension_Recorded|null
*/
public function getRecorded()
{
return $this->_recorded;
}
/**
* Sets the location information.
*
* @param Zend_Gdata_YouTube_Extension_Location $location Where the video
* was recorded
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setLocation($location = null)
{
$this->_location = $location;
return $this;
}
/**
* Gets the location where the video was recorded.
*
* @return Zend_Gdata_YouTube_Extension_Location|null
*/
public function getLocation()
{
return $this->_location;
}
/**
* If an instance of Zend_Gdata_YouTube_Extension_NoEmbed is passed in,
* the video cannot be embedded. Otherwise, if null is passsed in, the
* video is able to be embedded.
*
* @param Zend_Gdata_YouTube_Extension_NoEmbed $noEmbed Whether or not the
* video can be embedded.
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setNoEmbed($noEmbed = null)
{
$this->_noEmbed = $noEmbed;
return $this;
}
/**
* If the return value is an instance of
* Zend_Gdata_YouTube_Extension_NoEmbed, this video cannot be embedded.
*
* @return Zend_Gdata_YouTube_Extension_NoEmbed|null Whether or not the video can be embedded
*/
public function getNoEmbed()
{
return $this->_noEmbed;
}
/**
* Checks whether the video is embeddable.
*
* @return bool Returns true if the video is embeddable.
*/
public function isVideoEmbeddable()
{
if ($this->getNoEmbed() == null) {
return true;
} else {
return false;
}
}
/**
* Sets the statistics relating to the video.
*
* @param Zend_Gdata_YouTube_Extension_Statistics $statistics The statistics relating to the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setStatistics($statistics = null)
{
$this->_statistics = $statistics;
return $this;
}
/**
* Returns the statistics relating to the video.
*
* @return Zend_Gdata_YouTube_Extension_Statistics The statistics relating to the video
*/
public function getStatistics()
{
return $this->_statistics;
}
/**
* Specifies that the video has racy content.
*
* @param Zend_Gdata_YouTube_Extension_Racy $racy The racy flag object
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setRacy($racy = null)
{
if ($this->getMajorProtocolVersion() == 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException(
'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
'as of version 2 of the API.');
}
$this->_racy = $racy;
return $this;
}
/**
* Returns the racy flag object.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_Racy|null The racy flag object
*/
public function getRacy()
{
if ($this->getMajorProtocolVersion() == 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException(
'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
'as of version 2 of the API.');
}
return $this->_racy;
}
/**
* Sets the rating relating to the video.
*
* @param Zend_Gdata_Extension_Rating $rating The rating relating to the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setRating($rating = null)
{
$this->_rating = $rating;
return $this;
}
/**
* Returns the rating relating to the video.
*
* @return Zend_Gdata_Extension_Rating The rating relating to the video
*/
public function getRating()
{
return $this->_rating;
}
/**
* Sets the comments relating to the video.
*
* @param Zend_Gdata_Extension_Comments $comments The comments relating to the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setComments($comments = null)
{
$this->_comments = $comments;
return $this;
}
/**
* Returns the comments relating to the video.
*
* @return Zend_Gdata_Extension_Comments The comments relating to the video
*/
public function getComments()
{
return $this->_comments;
}
/**
* Sets the array of embedded feeds related to the video
*
* @param array $feedLink The array of embedded feeds relating to the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setFeedLink($feedLink = null)
{
$this->_feedLink = $feedLink;
return $this;
}
/**
* Get the feed link property for this entry.
*
* @see setFeedLink
* @param string $rel (optional) The rel value of the link to be found.
* If null, the array of links is returned.
* @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
* object corresponding to the requested rel value is returned
* if found, or null if the requested value is not found. If
* $rel is null or not specified, an array of all available
* feed links for this entry is returned, or null if no feed
* links are set.
*/
public function getFeedLink($rel = null)
{
if ($rel == null) {
return $this->_feedLink;
} else {
foreach ($this->_feedLink as $feedLink) {
if ($feedLink->rel == $rel) {
return $feedLink;
}
}
return null;
}
}
/**
* Returns the link element relating to video responses.
*
* @return Zend_Gdata_App_Extension_Link
*/
public function getVideoResponsesLink()
{
return $this->getLink(Zend_Gdata_YouTube::VIDEO_RESPONSES_REL);
}
/**
* Returns the link element relating to video ratings.
*
* @return Zend_Gdata_App_Extension_Link
*/
public function getVideoRatingsLink()
{
return $this->getLink(Zend_Gdata_YouTube::VIDEO_RATINGS_REL);
}
/**
* Returns the link element relating to video complaints.
*
* @return Zend_Gdata_App_Extension_Link
*/
public function getVideoComplaintsLink()
{
return $this->getLink(Zend_Gdata_YouTube::VIDEO_COMPLAINTS_REL);
}
/**
* Gets the YouTube video ID based upon the atom:id value
*
* @return string The video ID
*/
public function getVideoId()
{
if ($this->getMajorProtocolVersion() == 2) {
$videoId = $this->getMediaGroup()->getVideoId()->text;
} else {
$fullId = $this->getId()->getText();
$position = strrpos($fullId, '/');
if ($position === false) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'Slash not found in atom:id of ' . $fullId);
} else {
$videoId = substr($fullId, $position + 1);
}
}
return $videoId;
}
/**
* Gets the date that the video was recorded.
*
* @return string|null The date that the video was recorded
*/
public function getVideoRecorded()
{
$recorded = $this->getRecorded();
if ($recorded != null) {
return $recorded->getText();
} else {
return null;
}
}
/**
* Sets the date that the video was recorded.
*
* @param string $recorded The date that the video was recorded, in the
* format of '2001-06-19'
*/
public function setVideoRecorded($recorded)
{
$this->setRecorded(
new Zend_Gdata_YouTube_Extension_Recorded($recorded));
return $this;
}
/**
* Gets the georss:where element
*
* @return Zend_Gdata_Geo_Extension_GeoRssWhere
*/
public function getWhere()
{
return $this->_where;
}
/**
* Sets the georss:where element
*
* @param Zend_Gdata_Geo_Extension_GeoRssWhere $value The georss:where class value
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setWhere($value)
{
$this->_where = $value;
return $this;
}
/**
* Gets the title of the video as a string. null is returned
* if the video title is not available.
*
* @return string|null The title of the video
*/
public function getVideoTitle()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getTitle() != null) {
return $this->getMediaGroup()->getTitle()->getText();
} else {
return null;
}
}
/**
* Sets the title of the video as a string.
*
* @param string $title Title for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoTitle($title)
{
$this->ensureMediaGroupIsNotNull();
$this->getMediaGroup()->setTitle(
new Zend_Gdata_Media_Extension_MediaTitle($title));
return $this;
}
/**
* Sets the description of the video as a string.
*
* @param string $description Description for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoDescription($description)
{
$this->ensureMediaGroupIsNotNull();
$this->getMediaGroup()->setDescription(
new Zend_Gdata_Media_Extension_MediaDescription($description));
return $this;
}
/**
* Gets the description of the video as a string. null is returned
* if the video description is not available.
*
* @return string|null The description of the video
*/
public function getVideoDescription()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getDescription() != null) {
return $this->getMediaGroup()->getDescription()->getText();
} else {
return null;
}
}
/**
* Gets the URL of the YouTube video watch page. null is returned
* if the video watch page URL is not available.
*
* @return string|null The URL of the YouTube video watch page
*/
public function getVideoWatchPageUrl()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getPlayer() != null &&
array_key_exists(0, $this->getMediaGroup()->getPlayer())) {
$players = $this->getMediaGroup()->getPlayer();
return $players[0]->getUrl();
} else {
return null;
}
}
/**
* Gets an array of the thumbnails representing the video.
* Each thumbnail is an element of the array, and is an
* array of the thumbnail properties - time, height, width,
* and url. For convient usage inside a foreach loop, an
* empty array is returned if there are no thumbnails.
*
* @return array An array of video thumbnails.
*/
public function getVideoThumbnails()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getThumbnail() != null) {
$thumbnailArray = array();
foreach ($this->getMediaGroup()->getThumbnail() as $thumbnailObj) {
$thumbnail = array();
$thumbnail['time'] = $thumbnailObj->time;
$thumbnail['height'] = $thumbnailObj->height;
$thumbnail['width'] = $thumbnailObj->width;
$thumbnail['url'] = $thumbnailObj->url;
$thumbnailArray[] = $thumbnail;
}
return $thumbnailArray;
} else {
return array();
}
}
/**
* Gets the URL of the flash player SWF. null is returned if the
* duration value is not available.
*
* @return string|null The URL of the flash player SWF
*/
public function getFlashPlayerUrl()
{
$this->ensureMediaGroupIsNotNull();
foreach ($this->getMediaGroup()->getContent() as $content) {
if ($content->getType() === 'application/x-shockwave-flash') {
return $content->getUrl();
}
}
return null;
}
/**
* Gets the duration of the video, in seconds. null is returned
* if the duration value is not available.
*
* @return string|null The duration of the video, in seconds.
*/
public function getVideoDuration()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getDuration() != null) {
return $this->getMediaGroup()->getDuration()->getSeconds();
} else {
return null;
}
}
/**
* Checks whether the video is private.
*
* @return bool Return true if video is private
*/
public function isVideoPrivate()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getPrivate() != null) {
return true;
} else {
return false;
}
}
/**
* Sets video to private.
*
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoPrivate()
{
$this->ensureMediaGroupIsNotNull();
$this->getMediaGroup()->setPrivate(new Zend_Gdata_YouTube_Extension_Private());
return $this;
}
/**
* Sets a private video to be public.
*
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoPublic()
{
$this->ensureMediaGroupIsNotNull();
$this->getMediaGroup()->private = null;
return $this;
}
/**
* Gets an array of the tags assigned to this video. For convient
* usage inside a foreach loop, an empty array is returned when there
* are no tags assigned.
*
* @return array An array of the tags assigned to this video
*/
public function getVideoTags()
{
$this->ensureMediaGroupIsNotNull();
if ($this->getMediaGroup()->getKeywords() != null) {
$keywords = $this->getMediaGroup()->getKeywords();
$keywordsString = $keywords->getText();
if (strlen(trim($keywordsString)) > 0) {
return split('(, *)|,', $keywordsString);
}
}
return array();
}
/**
* Sets the keyword tags for a video.
*
* @param mixed $tags Either a comma-separated string or an array
* of tags for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoTags($tags)
{
$this->ensureMediaGroupIsNotNull();
$keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
if (is_array($tags)) {
$tags = implode(', ', $tags);
}
$keywords->setText($tags);
$this->getMediaGroup()->setKeywords($keywords);
return $this;
}
/**
* Gets the number of views for this video. null is returned if the
* number of views is not available.
*
* @return string|null The number of views for this video
*/
public function getVideoViewCount()
{
if ($this->getStatistics() != null) {
return $this->getStatistics()->getViewCount();
} else {
return null;
}
}
/**
* Gets the location specified for this video, if available. The location
* is returned as an array containing the keys 'longitude' and 'latitude'.
* null is returned if the location is not available.
*
* @return array|null The location specified for this video
*/
public function getVideoGeoLocation()
{
if ($this->getWhere() != null &&
$this->getWhere()->getPoint() != null &&
($position = $this->getWhere()->getPoint()->getPos()) != null) {
$positionString = $position->__toString();
if (strlen(trim($positionString)) > 0) {
$positionArray = explode(' ', trim($positionString));
if (count($positionArray) == 2) {
$returnArray = array();
$returnArray['latitude'] = $positionArray[0];
$returnArray['longitude'] = $positionArray[1];
return $returnArray;
}
}
}
return null;
}
/**
* Gets the rating information for this video, if available. The rating
* is returned as an array containing the keys 'average' and 'numRaters'.
* null is returned if the rating information is not available.
*
* @return array|null The rating information for this video
*/
public function getVideoRatingInfo()
{
if ($this->getRating() != null) {
$returnArray = array();
$returnArray['average'] = $this->getRating()->getAverage();
$returnArray['numRaters'] = $this->getRating()->getNumRaters();
return $returnArray;
} else {
return null;
}
}
/**
* Gets the category of this video, if available. The category is returned
* as a string. Valid categories are found at:
* http://gdata.youtube.com/schemas/2007/categories.cat
* If the category is not set, null is returned.
*
* @return string|null The category of this video
*/
public function getVideoCategory()
{
$this->ensureMediaGroupIsNotNull();
$categories = $this->getMediaGroup()->getCategory();
if ($categories != null) {
foreach($categories as $category) {
if ($category->getScheme() == self::YOUTUBE_CATEGORY_SCHEMA) {
return $category->getText();
}
}
}
return null;
}
/**
* Sets the category of the video as a string.
*
* @param string $category Categories for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoCategory($category)
{
$this->ensureMediaGroupIsNotNull();
$this->getMediaGroup()->setCategory(array(new Zend_Gdata_Media_Extension_MediaCategory($category, self::YOUTUBE_CATEGORY_SCHEMA)));
return $this;
}
/**
* Gets the developer tags for the video, if available and if client is
* authenticated with a valid developerKey. The tags are returned
* as an array.
* If no tags are set, null is returned.
*
* @return array|null The developer tags for this video or null if none were set.
*/
public function getVideoDeveloperTags()
{
$developerTags = null;
$this->ensureMediaGroupIsNotNull();
$categoryArray = $this->getMediaGroup()->getCategory();
if ($categoryArray != null) {
foreach ($categoryArray as $category) {
if ($category instanceof Zend_Gdata_Media_Extension_MediaCategory) {
if ($category->getScheme() == self::YOUTUBE_DEVELOPER_TAGS_SCHEMA) {
$developerTags[] = $category->getText();
}
}
}
return $developerTags;
}
return null;
}
/**
* Adds a developer tag to array of tags for the video.
*
* @param string $developerTag DeveloperTag for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function addVideoDeveloperTag($developerTag)
{
$this->ensureMediaGroupIsNotNull();
$newCategory = new Zend_Gdata_Media_Extension_MediaCategory($developerTag, self::YOUTUBE_DEVELOPER_TAGS_SCHEMA);
if ($this->getMediaGroup()->getCategory() == null) {
$this->getMediaGroup()->setCategory($newCategory);
} else {
$categories = $this->getMediaGroup()->getCategory();
$categories[] = $newCategory;
$this->getMediaGroup()->setCategory($categories);
}
return $this;
}
/**
* Set multiple developer tags for the video as strings.
*
* @param array $developerTags Array of developerTag for the video
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
*/
public function setVideoDeveloperTags($developerTags)
{
foreach($developerTags as $developerTag) {
$this->addVideoDeveloperTag($developerTag);
}
return $this;
}
/**
* Get the current publishing state of the video.
*
* @return Zend_Gdata_YouTube_Extension_State|null The publishing state of this video
*/
public function getVideoState()
{
$control = $this->getControl();
if ($control != null &&
$control->getDraft() != null &&
$control->getDraft()->getText() == 'yes') {
return $control->getState();
}
return null;
}
/**
* Get the VideoEntry's Zend_Gdata_YouTube_Extension_MediaGroup object.
* If the mediaGroup does not exist, then set it.
*
* @return void
*/
public function ensureMediaGroupIsNotNull()
{
if ($this->getMediagroup() == null) {
$this->setMediagroup(new Zend_Gdata_YouTube_Extension_MediaGroup());
}
}
/**
* Helper function to conveniently set a video's rating.
*
* @param integer $ratingValue A number representing the rating. Must
* be between 1 and 5 inclusive.
* @throws Zend_Gdata_Exception
* @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface.
*/
public function setVideoRating($ratingValue)
{
if ($ratingValue < 1 || $ratingValue > 5) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Rating for video entry must be between 1 and 5 inclusive.');
}
require_once 'Zend/Gdata/Extension/Rating.php';
$rating = new Zend_Gdata_Extension_Rating(null, 1, 5, null,
$ratingValue);
$this->setRating($rating);
return $this;
}
/**
* Retrieve the URL for a video's comment feed.
*
* @return string|null The URL if found, or null if not found.
*/
public function getVideoCommentFeedUrl()
{
$commentsExtension = $this->getComments();
$commentsFeedUrl = null;
if ($commentsExtension) {
$commentsFeedLink = $commentsExtension->getFeedLink();
if ($commentsFeedLink) {
$commentsFeedUrl = $commentsFeedLink->getHref();
}
}
return $commentsFeedUrl;
}
}
Gdata/YouTube/ContactFeed.php 0000604 00000003617 15071256135 0012060 0 ustar 00 <?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_Gdata
* @subpackage YouTube
* @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 Zend_Gdata_Media_Feed
*/
require_once 'Zend/Gdata/Media/Feed.php';
/**
* @see Zend_Gdata_YouTube_ContactEntry
*/
require_once 'Zend/Gdata/YouTube/ContactEntry.php';
/**
* The YouTube contacts flavor of an Atom Feed with media support
* Represents a list of individual contacts, where each contained entry is
* a contact.
*
* @category Zend
* @package Zend_Gdata
* @subpackage YouTube
* @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_Gdata_YouTube_ContactFeed extends Zend_Gdata_Media_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_YouTube_ContactEntry';
/**
* Constructs a new YouTube Contact Feed object, to represent
* a feed of contacts for a user
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
parent::__construct($element);
}
}
Gdata/App.php 0000604 00000113707 15071256135 0007027 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Zend_Gdata_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* Zend_Version
*/
require_once 'Zend/Version.php';
/**
* Zend_Gdata_App_MediaSource
*/
require_once 'Zend/Gdata/App/MediaSource.php';
/**
* Provides Atom Publishing Protocol (APP) functionality. This class and all
* other components of Zend_Gdata_App are designed to work independently from
* other Zend_Gdata components in order to interact with generic APP services.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App
{
/** Default major protocol version.
*
* @see _majorProtocolVersion
*/
const DEFAULT_MAJOR_PROTOCOL_VERSION = 1;
/** Default minor protocol version.
*
* @see _minorProtocolVersion
*/
const DEFAULT_MINOR_PROTOCOL_VERSION = null;
/**
* Client object used to communicate
*
* @var Zend_Http_Client
*/
protected $_httpClient;
/**
* Client object used to communicate in static context
*
* @var Zend_Http_Client
*/
protected static $_staticHttpClient = null;
/**
* Override HTTP PUT and DELETE request methods?
*
* @var boolean
*/
protected static $_httpMethodOverride = false;
/**
* Enable gzipped responses?
*
* @var boolean
*/
protected static $_gzipEnabled = false;
/**
* Use verbose exception messages. In the case of HTTP errors,
* use the body of the HTTP response in the exception message.
*
* @var boolean
*/
protected static $_verboseExceptionMessages = true;
/**
* Default URI to which to POST.
*
* @var string
*/
protected $_defaultPostUri = null;
/**
* Packages to search for classes when using magic __call method, in order.
*
* @var array
*/
protected $_registeredPackages = array(
'Zend_Gdata_App_Extension',
'Zend_Gdata_App');
/**
* Maximum number of redirects to follow during HTTP operations
*
* @var int
*/
protected static $_maxRedirects = 5;
/**
* Indicates the major protocol version that should be used.
* At present, recognized values are either 1 or 2. However, any integer
* value >= 1 is considered valid.
*
* Under most circumtances, this will be automatically set by
* Zend_Gdata_App subclasses.
*
* @see setMajorProtocolVersion()
* @see getMajorProtocolVersion()
*/
protected $_majorProtocolVersion;
/**
* Indicates the minor protocol version that should be used. Can be set
* to either an integer >= 0, or NULL if no minor version should be sent
* to the server.
*
* At present, this field is not used by any Google services, but may be
* used in the future.
*
* Under most circumtances, this will be automatically set by
* Zend_Gdata_App subclasses.
*
* @see setMinorProtocolVersion()
* @see getMinorProtocolVersion()
*/
protected $_minorProtocolVersion;
/**
* Create Gdata object
*
* @param Zend_Http_Client $client
* @param string $applicationId
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->setHttpClient($client, $applicationId);
// Set default protocol version. Subclasses should override this as
// needed once a given service supports a new version.
$this->setMajorProtocolVersion(self::DEFAULT_MAJOR_PROTOCOL_VERSION);
$this->setMinorProtocolVersion(self::DEFAULT_MINOR_PROTOCOL_VERSION);
}
/**
* Adds a Zend Framework package to the $_registeredPackages array.
* This array is searched when using the magic __call method below
* to instantiante new objects.
*
* @param string $name The name of the package (eg Zend_Gdata_App)
* @return void
*/
public function registerPackage($name)
{
array_unshift($this->_registeredPackages, $name);
}
/**
* Retreive feed object
*
* @param string $uri The uri from which to retrieve the feed
* @param string $className The class which is used as the return type
* @return Zend_Gdata_App_Feed
*/
public function getFeed($uri, $className='Zend_Gdata_App_Feed')
{
return $this->importUrl($uri, $className);
}
/**
* Retreive entry object
*
* @param string $uri
* @param string $className The class which is used as the return type
* @return Zend_Gdata_App_Entry
*/
public function getEntry($uri, $className='Zend_Gdata_App_Entry')
{
return $this->importUrl($uri, $className);
}
/**
* Get the Zend_Http_Client object used for communication
*
* @return Zend_Http_Client
*/
public function getHttpClient()
{
return $this->_httpClient;
}
/**
* Set the Zend_Http_Client object used for communication
*
* @param Zend_Http_Client $client The client to use for communication
* @throws Zend_Gdata_App_HttpException
* @return Zend_Gdata_App Provides a fluent interface
*/
public function setHttpClient($client, $applicationId = 'MyCompany-MyApp-1.0')
{
if ($client === null) {
$client = new Zend_Http_Client();
}
if (!$client instanceof Zend_Http_Client) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException('Argument is not an instance of Zend_Http_Client.');
}
$userAgent = $applicationId . ' Zend_Framework_Gdata/' . Zend_Version::VERSION;
$client->setHeaders('User-Agent', $userAgent);
$client->setConfig(array(
'strictredirects' => true
)
);
$this->_httpClient = $client;
Zend_Gdata::setStaticHttpClient($client);
return $this;
}
/**
* Set the static HTTP client instance
*
* Sets the static HTTP client object to use for retrieving the feed.
*
* @param Zend_Http_Client $httpClient
* @return void
*/
public static function setStaticHttpClient(Zend_Http_Client $httpClient)
{
self::$_staticHttpClient = $httpClient;
}
/**
* Gets the HTTP client object. If none is set, a new Zend_Http_Client will be used.
*
* @return Zend_Http_Client
*/
public static function getStaticHttpClient()
{
if (!self::$_staticHttpClient instanceof Zend_Http_Client) {
$client = new Zend_Http_Client();
$userAgent = 'Zend_Framework_Gdata/' . Zend_Version::VERSION;
$client->setHeaders('User-Agent', $userAgent);
$client->setConfig(array(
'strictredirects' => true
)
);
self::$_staticHttpClient = $client;
}
return self::$_staticHttpClient;
}
/**
* Toggle using POST instead of PUT and DELETE HTTP methods
*
* Some feed implementations do not accept PUT and DELETE HTTP
* methods, or they can't be used because of proxies or other
* measures. This allows turning on using POST where PUT and
* DELETE would normally be used; in addition, an
* X-Method-Override header will be sent with a value of PUT or
* DELETE as appropriate.
*
* @param boolean $override Whether to override PUT and DELETE with POST.
* @return void
*/
public static function setHttpMethodOverride($override = true)
{
self::$_httpMethodOverride = $override;
}
/**
* Get the HTTP override state
*
* @return boolean
*/
public static function getHttpMethodOverride()
{
return self::$_httpMethodOverride;
}
/**
* Toggle requesting gzip encoded responses
*
* @param boolean $enabled Whether or not to enable gzipped responses
* @return void
*/
public static function setGzipEnabled($enabled = false)
{
if ($enabled && !function_exists('gzinflate')) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You cannot enable gzipped responses if the zlib module ' .
'is not enabled in your PHP installation.');
}
self::$_gzipEnabled = $enabled;
}
/**
* Get the HTTP override state
*
* @return boolean
*/
public static function getGzipEnabled()
{
return self::$_gzipEnabled;
}
/**
* Get whether to use verbose exception messages
*
* In the case of HTTP errors, use the body of the HTTP response
* in the exception message.
*
* @return boolean
*/
public static function getVerboseExceptionMessages()
{
return self::$_verboseExceptionMessages;
}
/**
* Set whether to use verbose exception messages
*
* In the case of HTTP errors, use the body of the HTTP response
* in the exception message.
*
* @param boolean $verbose Whether to use verbose exception messages
*/
public static function setVerboseExceptionMessages($verbose)
{
self::$_verboseExceptionMessages = $verbose;
}
/**
* Set the maximum number of redirects to follow during HTTP operations
*
* @param int $maxRedirects Maximum number of redirects to follow
* @return void
*/
public static function setMaxRedirects($maxRedirects)
{
self::$_maxRedirects = $maxRedirects;
}
/**
* Get the maximum number of redirects to follow during HTTP operations
*
* @return int Maximum number of redirects to follow
*/
public static function getMaxRedirects()
{
return self::$_maxRedirects;
}
/**
* Set the major protocol version that should be used. Values < 1 will
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
*
* @see _majorProtocolVersion
* @param int $value The major protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMajorProtocolVersion($value)
{
if (!($value >= 1)) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException(
'Major protocol version must be >= 1');
}
$this->_majorProtocolVersion = $value;
}
/**
* Get the major protocol version that is in use.
*
* @see _majorProtocolVersion
* @return int The major protocol version in use.
*/
public function getMajorProtocolVersion()
{
return $this->_majorProtocolVersion;
}
/**
* Set the minor protocol version that should be used. If set to NULL, no
* minor protocol version will be sent to the server. Values < 0 will
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
*
* @see _minorProtocolVersion
* @param (int|NULL) $value The minor protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMinorProtocolVersion($value)
{
if (!($value >= 0)) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException(
'Minor protocol version must be >= 0');
}
$this->_minorProtocolVersion = $value;
}
/**
* Get the minor protocol version that is in use.
*
* @see _minorProtocolVersion
* @return (int|NULL) The major protocol version in use, or NULL if no
* minor version is specified.
*/
public function getMinorProtocolVersion()
{
return $this->_minorProtocolVersion;
}
/**
* Provides pre-processing for HTTP requests to APP services.
*
* 1. Checks the $data element and, if it's an entry, extracts the XML,
* multipart data, edit link (PUT,DELETE), etc.
* 2. If $data is a string, sets the default content-type header as
* 'application/atom+xml' if it's not already been set.
* 3. Adds a x-http-method override header and changes the HTTP method
* to 'POST' if necessary as per getHttpMethodOverride()
*
* @param string $method The HTTP method for the request - 'GET', 'POST',
* 'PUT', 'DELETE'
* @param string $url The URL to which this request is being performed,
* or null if found in $data
* @param array $headers An associative array of HTTP headers for this
* request
* @param mixed $data The Zend_Gdata_App_Entry or XML for the
* body of the request
* @param string $contentTypeOverride The override value for the
* content type of the request body
* @return array An associative array containing the determined
* 'method', 'url', 'data', 'headers', 'contentType'
*/
public function prepareRequest($method,
$url = null,
$headers = array(),
$data = null,
$contentTypeOverride = null)
{
// As a convenience, if $headers is null, we'll convert it back to
// an empty array.
if (is_null($headers)) {
$headers = array();
}
$rawData = null;
$finalContentType = null;
if ($url == null) {
$url = $this->_defaultPostUri;
}
if (is_string($data)) {
$rawData = $data;
if ($contentTypeOverride === null) {
$finalContentType = 'application/atom+xml';
}
} elseif ($data instanceof Zend_Gdata_App_MediaEntry) {
$rawData = $data->encode();
if ($data->getMediaSource() !== null) {
$finalContentType = 'multipart/related; boundary="' . $data->getBoundary() . '"';
$headers['MIME-version'] = '1.0';
$headers['Slug'] = $data->getMediaSource()->getSlug();
} else {
$finalContentType = 'application/atom+xml';
}
if ($method == 'PUT' || $method == 'DELETE') {
$editLink = $data->getEditLink();
if ($editLink != null) {
$url = $editLink->getHref();
}
}
} elseif ($data instanceof Zend_Gdata_App_Entry) {
$rawData = $data->saveXML();
$finalContentType = 'application/atom+xml';
if ($method == 'PUT' || $method == 'DELETE') {
$editLink = $data->getEditLink();
if ($editLink != null) {
$url = $editLink->getHref();
}
}
} elseif ($data instanceof Zend_Gdata_App_MediaSource) {
$rawData = $data->encode();
if ($data->getSlug() !== null) {
$headers['Slug'] = $data->getSlug();
}
$finalContentType = $data->getContentType();
}
if ($method == 'DELETE') {
$rawData = null;
}
// Set an If-Match header if:
// - This isn't a DELETE
// - If this isn't a GET, the Etag isn't weak
// - A similar header (If-Match/If-None-Match) hasn't already been
// set.
if ($method != 'DELETE' && (
!array_key_exists('If-Match', $headers) &&
!array_key_exists('If-None-Match', $headers)
) ) {
$allowWeak = $method == 'GET';
if ($ifMatchHeader = $this->generateIfMatchHeaderData(
$data, $allowWeak)) {
$headers['If-Match'] = $ifMatchHeader;
}
}
if ($method != 'POST' && $method != 'GET' && Zend_Gdata_App::getHttpMethodOverride()) {
$headers['x-http-method-override'] = $method;
$method = 'POST';
} else {
$headers['x-http-method-override'] = null;
}
if ($contentTypeOverride != null) {
$finalContentType = $contentTypeOverride;
}
return array('method' => $method, 'url' => $url, 'data' => $rawData, 'headers' => $headers, 'contentType' => $finalContentType);
}
/**
* Performs a HTTP request using the specified method
*
* @param string $method The HTTP method for the request - 'GET', 'POST',
* 'PUT', 'DELETE'
* @param string $url The URL to which this request is being performed
* @param array $headers An associative array of HTTP headers
* for this request
* @param string $body The body of the HTTP request
* @param string $contentType The value for the content type
* of the request body
* @param int $remainingRedirects Number of redirects to follow if request
* s results in one
* @return Zend_Http_Response The response object
*/
public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null)
{
require_once 'Zend/Http/Client/Exception.php';
if ($remainingRedirects === null) {
$remainingRedirects = self::getMaxRedirects();
}
if ($headers === null) {
$headers = array();
}
// Append a Gdata version header if protocol v2 or higher is in use.
// (Protocol v1 does not use this header.)
$major = $this->getMajorProtocolVersion();
$minor = $this->getMinorProtocolVersion();
if ($major >= 2) {
$headers['GData-Version'] = $major +
(is_null($minor) ? '.' + $minor : '');
}
// check the overridden method
if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You must specify the data to post as either a ' .
'string or a child of Zend_Gdata_App_Entry');
}
if ($url === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to post.');
}
$headers['Content-Type'] = $contentType;
if (Zend_Gdata_App::getGzipEnabled()) {
// some services require the word 'gzip' to be in the user-agent header
// in addition to the accept-encoding header
if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) {
$headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)';
}
$headers['Accept-encoding'] = 'gzip, deflate';
} else {
$headers['Accept-encoding'] = 'identity';
}
// Make sure the HTTP client object is 'clean' before making a request
// In addition to standard headers to reset via resetParameters(),
// also reset the Slug header
$this->_httpClient->resetParameters();
$this->_httpClient->setHeaders('Slug', null);
// Set the params for the new request to be performed
$this->_httpClient->setHeaders($headers);
$this->_httpClient->setUri($url);
$this->_httpClient->setConfig(array('maxredirects' => 0));
$this->_httpClient->setRawData($body, $contentType);
try {
$response = $this->_httpClient->request($method);
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
if ($response->isRedirect() && $response->getStatus() != '304') {
if ($remainingRedirects > 0) {
$newUrl = $response->getHeader('Location');
$response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects);
} else {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException(
'Number of redirects exceeds maximum', null, $response);
}
}
if (!$response->isSuccessful()) {
require_once 'Zend/Gdata/App/HttpException.php';
$exceptionMessage = 'Expected response code 200, got ' . $response->getStatus();
if (self::getVerboseExceptionMessages()) {
$exceptionMessage .= "\n" . $response->getBody();
}
$exception = new Zend_Gdata_App_HttpException($exceptionMessage);
$exception->setResponse($response);
throw $exception;
}
return $response;
}
/**
* Imports a feed located at $uri.
*
* @param string $uri
* @param Zend_Http_Client $client The client used for communication
* @param string $className The class which is used as the return type
* @throws Zend_Gdata_App_Exception
* @return Zend_Gdata_App_Feed
*/
public static function import($uri, $client = null, $className='Zend_Gdata_App_Feed')
{
$app = new Zend_Gdata_App($client);
$requestData = $app->prepareRequest('GET', $uri);
$response = $app->performHttpRequest($requestData['method'], $requestData['url']);
$feedContent = $response->getBody();
$feed = self::importString($feedContent, $className);
if ($client != null) {
$feed->setHttpClient($client);
}
return $feed;
}
/**
* Imports the specified URL (non-statically).
*
* @param string $url The URL to import
* @param string $className The class which is used as the return type
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @throws Zend_Gdata_App_Exception
* @return Zend_Gdata_App_Feed
*/
public function importUrl($url, $className='Zend_Gdata_App_Feed', $extraHeaders = array())
{
$response = $this->get($url, $extraHeaders);
$feedContent = $response->getBody();
$feed = self::importString($feedContent, $className);
$etag = $response->getHeader('ETag');
if (!is_null($etag)) {
$feed->setEtag($etag);
}
$protocolVersionStr = $response->getHeader('GData-Version');
if (!is_null($protocolVersionStr)) {
// Extract protocol major and minor version from header
$delimiterPos = strpos($protocolVersionStr, '.');
$length = strlen($protocolVersionStr);
$major = substr($protocolVersionStr,
0,
$delimiterPos);
$minor = substr($protocolVersionStr,
$delimiterPos + 1,
$length);
$feed->setMajorProtocolVersion($major);
$feed->setMinorProtocolVersion($minor);
} else {
$feed->setMajorProtocolVersion(null);
$feed->setMinorProtocolVersion(null);
}
if ($this->getHttpClient() != null) {
$feed->setHttpClient($this->getHttpClient());
}
return $feed;
}
/**
* Imports a feed represented by $string.
*
* @param string $string
* @param string $className The class which is used as the return type
* @throws Zend_Gdata_App_Exception
* @return Zend_Gdata_App_Feed
*/
public static function importString($string, $className='Zend_Gdata_App_Feed')
{
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($string);
@ini_restore('track_errors');
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$feed = new $className($string);
$feed->setHttpClient(self::getstaticHttpClient());
return $feed;
}
/**
* Imports a feed from a file located at $filename.
*
* @param string $filename
* @param string $className The class which is used as the return type
* @param string $useIncludePath Whether the include_path should be searched
* @throws Zend_Gdata_App_Exception
* @return Zend_Gdata_Feed
*/
public static function importFile($filename,
$className='Zend_Gdata_App_Feed', $useIncludePath = false)
{
@ini_set('track_errors', 1);
$feed = @file_get_contents($filename, $useIncludePath);
@ini_restore('track_errors');
if ($feed === false) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("File could not be loaded: $php_errormsg");
}
return self::importString($feed, $className);
}
/**
* GET a URI using client object.
*
* @param string $uri GET URI
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @throws Zend_Gdata_App_HttpException
* @return Zend_Http_Response
*/
public function get($uri, $extraHeaders = array())
{
$requestData = $this->prepareRequest('GET', $uri, $extraHeaders);
return $this->performHttpRequest($requestData['method'], $requestData['url'], $requestData['headers']);
}
/**
* POST data with client object
*
* @param mixed $data The Zend_Gdata_App_Entry or XML to post
* @param string $uri POST URI
* @param array $headers Additional HTTP headers to insert.
* @param string $contentType Content-type of the data
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Http_Response
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function post($data, $uri = null, $remainingRedirects = null,
$contentType = null, $extraHeaders = null)
{
$requestData = $this->prepareRequest('POST', $uri, $extraHeaders,
$data, $contentType);
return $this->performHttpRequest(
$requestData['method'], $requestData['url'],
$requestData['headers'], $requestData['data'],
$requestData['contentType']);
}
/**
* PUT data with client object
*
* @param mixed $data The Zend_Gdata_App_Entry or XML to post
* @param string $uri PUT URI
* @param array $headers Additional HTTP headers to insert.
* @param string $contentType Content-type of the data
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Http_Response
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function put($data, $uri = null, $remainingRedirects = null,
$contentType = null, $extraHeaders = null)
{
$requestData = $this->prepareRequest('PUT', $uri, $extraHeaders, $data, $contentType);
return $this->performHttpRequest(
$requestData['method'], $requestData['url'],
$requestData['headers'], $requestData['data'],
$requestData['contentType']);
}
/**
* DELETE entry with client object
*
* @param mixed $data The Zend_Gdata_App_Entry or URL to delete
* @return void
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function delete($data, $remainingRedirects = null)
{
if (is_string($data)) {
$requestData = $this->prepareRequest('DELETE', $data);
} else {
$headers = array();
$requestData = $this->prepareRequest('DELETE', null, $headers, $data);
}
return $this->performHttpRequest($requestData['method'],
$requestData['url'],
$requestData['headers'],
'',
$requestData['contentType'],
$remainingRedirects);
}
/**
* Inserts an entry to a given URI and returns the response as a fully formed Entry.
* @param mixed $data The Zend_Gdata_App_Entry or XML to post
* @param string $uri POST URI
* @param string $className The class of entry to be returned.
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Gdata_App_Entry The entry returned by the service after insertion.
*/
public function insertEntry($data, $uri, $className='Zend_Gdata_App_Entry', $extraHeaders = array())
{
$response = $this->post($data, $uri, null, null, $extraHeaders);
$returnEntry = new $className($response->getBody());
$returnEntry->setHttpClient(self::getstaticHttpClient());
$etag = $response->getHeader('ETag');
if (!is_null($etag)) {
$returnEntry->setEtag($etag);
}
return $returnEntry;
}
/**
* Update an entry
*
* @param mixed $data Zend_Gdata_App_Entry or XML (w/ID and link rel='edit')
* @param string|null The URI to send requests to, or null if $data
* contains the URI.
* @param string|null The name of the class that should be deserialized
* from the server response. If null, then 'Zend_Gdata_App_Entry'
* will be used.
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Gdata_App_Entry The entry returned from the server
* @throws Zend_Gdata_App_Exception
*/
public function updateEntry($data, $uri = null, $className = null, $extraHeaders = array())
{
if ($className === null && $data instanceof Zend_Gdata_App_Entry) {
$className = get_class($data);
} elseif ($className === null) {
$className = 'Zend_Gdata_App_Entry';
}
$response = $this->put($data, $uri, null, null, $extraHeaders);
$returnEntry = new $className($response->getBody());
$returnEntry->setHttpClient(self::getstaticHttpClient());
$etag = $response->getHeader('ETag');
if (!is_null($etag)) {
$returnEntry->setEtag($etag);
}
return $returnEntry;
}
/**
* Provides a magic factory method to instantiate new objects with
* shorter syntax than would otherwise be required by the Zend Framework
* naming conventions. For instance, to construct a new
* Zend_Gdata_Calendar_Extension_Color, a developer simply needs to do
* $gCal->newColor(). For this magic constructor, packages are searched
* in the same order as which they appear in the $_registeredPackages
* array
*
* @param string $method The method name being called
* @param array $args The arguments passed to the call
* @throws Zend_Gdata_App_Exception
*/
public function __call($method, $args)
{
if (preg_match('/^new(\w+)/', $method, $matches)) {
$class = $matches[1];
$foundClassName = null;
foreach ($this->_registeredPackages as $name) {
try {
@Zend_Loader::loadClass("${name}_${class}");
$foundClassName = "${name}_${class}";
break;
} catch (Zend_Exception $e) {
// package wasn't here- continue searching
}
}
if ($foundClassName != null) {
$reflectionObj = new ReflectionClass($foundClassName);
$instance = $reflectionObj->newInstanceArgs($args);
if ($instance instanceof Zend_Gdata_App_FeedEntryParent) {
$instance->setHttpClient($this->_httpClient);
}
return $instance;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
"Unable to find '${class}' in registered packages");
}
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("No such method ${method}");
}
}
/**
* Retrieve all entries for a feed, iterating through pages as necessary.
* Be aware that calling this function on a large dataset will take a
* significant amount of time to complete. In some cases this may cause
* execution to timeout without proper precautions in place.
*
* @param $feed The feed to iterate through.
* @return mixed A new feed of the same type as the one originally
* passed in, containing all relevent entries.
*/
public function retrieveAllEntriesForFeed($feed) {
$feedClass = get_class($feed);
$reflectionObj = new ReflectionClass($feedClass);
$result = $reflectionObj->newInstance();
do {
foreach ($feed as $entry) {
$result->addEntry($entry);
}
$next = $feed->getLink('next');
if ($next !== null) {
$feed = $this->getFeed($next->href, $feedClass);
} else {
$feed = null;
}
}
while ($feed != null);
return $result;
}
/**
* This method enables logging of requests by changing the
* Zend_Http_Client_Adapter used for performing the requests.
* NOTE: This will not work if you have customized the adapter
* already to use a proxy server or other interface.
*
* @param $logfile The logfile to use when logging the requests
*/
public function enableRequestDebugLogging($logfile)
{
$this->_httpClient->setConfig(array(
'adapter' => 'Zend_Gdata_App_LoggingHttpClientAdapterSocket',
'logfile' => $logfile
));
}
/**
* Retrieve next set of results based on a given feed.
*
* @param Zend_Gdata_App_Feed $feed The feed from which to
* retreive the next set of results.
* @param string $className (optional) The class of feed to be returned.
* If null, the next feed (if found) will be the same class as
* the feed that was given as the first argument.
* @return Zend_Gdata_App_Feed|null Returns a
* Zend_Gdata_App_Feed or null if no next set of results
* exists.
*/
public function getNextFeed($feed, $className = null)
{
$nextLink = $feed->getNextLink();
if (!$nextLink) {
return null;
}
$nextLinkHref = $nextLink->getHref();
if (is_null($className)) {
$className = get_class($feed);
}
return $this->getFeed($nextLinkHref, $className);
}
/**
* Retrieve previous set of results based on a given feed.
*
* @param Zend_Gdata_App_Feed $feed The feed from which to
* retreive the previous set of results.
* @param string $className (optional) The class of feed to be returned.
* If null, the previous feed (if found) will be the same class as
* the feed that was given as the first argument.
* @return Zend_Gdata_App_Feed|null Returns a
* Zend_Gdata_App_Feed or null if no previous set of results
* exists.
*/
public function getPreviousFeed($feed, $className = null)
{
$previousLink = $feed->getPreviousLink();
if (!$previousLink) {
return null;
}
$previousLinkHref = $previousLink->getHref();
if (is_null($className)) {
$className = get_class($feed);
}
return $this->getFeed($previousLinkHref, $className);
}
/**
* Returns the data for an If-Match header based on the current Etag
* property. If Etags are not supported by the server or cannot be
* extracted from the data, then null will be returned.
*
* @param boolean $allowWeak If false, then if a weak Etag is detected,
* then return null rather than the Etag.
* @return string|null $data
*/
public function generateIfMatchHeaderData($data, $allowWeek)
{
$result = '';
// Set an If-Match header if an ETag has been set (version >= 2 only)
if ($this->_majorProtocolVersion >= 2 &&
$data instanceof Zend_Gdata_App_Entry) {
$etag = $data->getEtag();
if (!is_null($etag) &&
($allowWeek || substr($etag, 0, 2) != 'W/')) {
$result = $data->getEtag();
}
}
return $result;
}
}
Gdata/App/Extension.php 0000604 00000002131 15071256135 0010767 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Base
*/
require_once 'Zend/Gdata/App/Base.php';
/**
* Gdata App extensions
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_Extension extends Zend_Gdata_App_Base
{
}
Gdata/App/InvalidArgumentException.php 0000604 00000002255 15071256135 0013772 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Gdata exceptions
*
* Class to represent exceptions that occur during Gdata operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_InvalidArgumentException extends Zend_Gdata_App_Exception
{
}
Gdata/App/Extension/Title.php 0000604 00000002252 15071256135 0012054 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Text
*/
require_once 'Zend/Gdata/App/Extension/Text.php';
/**
* Represents the atom:title element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Title extends Zend_Gdata_App_Extension_Text
{
protected $_rootElement = 'title';
}
Gdata/App/Extension/Icon.php 0000604 00000002420 15071256135 0011660 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:icon element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Icon extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'icon';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Uri.php 0000604 00000002413 15071256135 0011531 0 ustar 00 <?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 uri
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:uri element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Uri extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'uri';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Email.php 0000604 00000002423 15071256135 0012022 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:email element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Email extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'email';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Summary.php 0000604 00000002260 15071256135 0012427 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Text
*/
require_once 'Zend/Gdata/App/Extension/Text.php';
/**
* Represents the atom:summary element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Summary extends Zend_Gdata_App_Extension_Text
{
protected $_rootElement = 'summary';
}
Gdata/App/Extension/Content.php 0000604 00000004342 15071256135 0012407 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Text
*/
require_once 'Zend/Gdata/App/Extension/Text.php';
/**
* Represents the atom:content element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Content extends Zend_Gdata_App_Extension_Text
{
protected $_rootElement = 'content';
protected $_src = null;
public function __construct($text = null, $type = 'text', $src = null)
{
parent::__construct($text, $type);
$this->_src = $src;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_src !== null) {
$element->setAttribute('src', $this->_src);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'src':
$this->_src = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string
*/
public function getSrc()
{
return $this->_src;
}
/**
* @param string $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setSrc($value)
{
$this->_src = $value;
return $this;
}
}
Gdata/App/Extension/Subtitle.php 0000604 00000002263 15071256135 0012570 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Text
*/
require_once 'Zend/Gdata/App/Extension/Text.php';
/**
* Represents the atom:subtitle element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Subtitle extends Zend_Gdata_App_Extension_Text
{
protected $_rootElement = 'subtitle';
}
Gdata/App/Extension/Control.php 0000604 00000005134 15071256135 0012415 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* @see Zend_Gdata_App_Extension_Draft
*/
require_once 'Zend/Gdata/App/Extension/Draft.php';
/**
* Represents the app:control element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Control extends Zend_Gdata_App_Extension
{
protected $_rootNamespace = 'app';
protected $_rootElement = 'control';
protected $_draft = null;
public function __construct($draft = null)
{
parent::__construct();
$this->_draft = $draft;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_draft != null) {
$element->appendChild($this->_draft->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('app') . ':' . 'draft':
$draft = new Zend_Gdata_App_Extension_Draft();
$draft->transferFromDOM($child);
$this->_draft = $draft;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @return Zend_Gdata_App_Extension_Draft
*/
public function getDraft()
{
return $this->_draft;
}
/**
* @param Zend_Gdata_App_Extension_Draft $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setDraft($value)
{
$this->_draft = $value;
return $this;
}
}
Gdata/App/Extension/Author.php 0000604 00000002254 15071256135 0012237 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension/Person.php';
/**
* Represents the atom:author element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Author extends Zend_Gdata_App_Extension_Person
{
protected $_rootElement = 'author';
}
Gdata/App/Extension/Person.php 0000604 00000010474 15071256135 0012246 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* @see Zend_Gdata_App_Extension_Name
*/
require_once 'Zend/Gdata/App/Extension/Name.php';
/**
* @see Zend_Gdata_App_Extension_Email
*/
require_once 'Zend/Gdata/App/Extension/Email.php';
/**
* @see Zend_Gdata_App_Extension_Uri
*/
require_once 'Zend/Gdata/App/Extension/Uri.php';
/**
* Base class for people (currently used by atom:author, atom:contributor)
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_Extension_Person extends Zend_Gdata_App_Extension
{
protected $_rootElement = null;
protected $_name = null;
protected $_email = null;
protected $_uri = null;
public function __construct($name = null, $email = null, $uri = null)
{
parent::__construct();
$this->_name = $name;
$this->_email = $email;
$this->_uri = $uri;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_name != null) {
$element->appendChild($this->_name->getDOM($element->ownerDocument));
}
if ($this->_email != null) {
$element->appendChild($this->_email->getDOM($element->ownerDocument));
}
if ($this->_uri != null) {
$element->appendChild($this->_uri->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'name':
$name = new Zend_Gdata_App_Extension_Name();
$name->transferFromDOM($child);
$this->_name = $name;
break;
case $this->lookupNamespace('atom') . ':' . 'email':
$email = new Zend_Gdata_App_Extension_Email();
$email->transferFromDOM($child);
$this->_email = $email;
break;
case $this->lookupNamespace('atom') . ':' . 'uri':
$uri = new Zend_Gdata_App_Extension_Uri();
$uri->transferFromDOM($child);
$this->_uri = $uri;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @return Zend_Gdata_App_Extension_Name
*/
public function getName()
{
return $this->_name;
}
/**
* @param Zend_Gdata_App_Extension_Name $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setName($value)
{
$this->_name = $value;
return $this;
}
/**
* @return Zend_Gdata_App_Extension_Email
*/
public function getEmail()
{
return $this->_email;
}
/**
* @param Zend_Gdata_App_Extension_Email $value
* @return Zend_Gdata_App_Extension_Person Provides a fluent interface
*/
public function setEmail($value)
{
$this->_email = $value;
return $this;
}
/**
* @return Zend_Gdata_App_Extension_Uri
*/
public function getUri()
{
return $this->_uri;
}
/**
* @param Zend_Gdata_App_Extension_Uri $value
* @return Zend_Gdata_App_Extension_Person Provides a fluent interface
*/
public function setUri($value)
{
$this->_uri = $value;
return $this;
}
}
Gdata/App/Extension/Category.php 0000604 00000006673 15071256135 0012563 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:category element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Category extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'category';
protected $_term = null;
protected $_scheme = null;
protected $_label = null;
public function __construct($term = null, $scheme = null, $label=null)
{
parent::__construct();
$this->_term = $term;
$this->_scheme = $scheme;
$this->_label = $label;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_term !== null) {
$element->setAttribute('term', $this->_term);
}
if ($this->_scheme !== null) {
$element->setAttribute('scheme', $this->_scheme);
}
if ($this->_label !== null) {
$element->setAttribute('label', $this->_label);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'term':
$this->_term = $attribute->nodeValue;
break;
case 'scheme':
$this->_scheme = $attribute->nodeValue;
break;
case 'label':
$this->_label = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string|null
*/
public function getTerm()
{
return $this->_term;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
*/
public function setTerm($value)
{
$this->_term = $value;
return $this;
}
/**
* @return string|null
*/
public function getScheme()
{
return $this->_scheme;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
*/
public function setScheme($value)
{
$this->_scheme = $value;
return $this;
}
/**
* @return string|null
*/
public function getLabel()
{
return $this->_label;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
*/
public function setLabel($value)
{
$this->_label = $value;
return $this;
}
}
Gdata/App/Extension/Link.php 0000604 00000012307 15071256135 0011672 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model for representing an atom:link element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Link extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'link';
protected $_href = null;
protected $_rel = null;
protected $_type = null;
protected $_hrefLang = null;
protected $_title = null;
protected $_length = null;
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
parent::__construct();
$this->_href = $href;
$this->_rel = $rel;
$this->_type = $type;
$this->_hrefLang = $hrefLang;
$this->_title = $title;
$this->_length = $length;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_href !== null) {
$element->setAttribute('href', $this->_href);
}
if ($this->_rel !== null) {
$element->setAttribute('rel', $this->_rel);
}
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
if ($this->_hrefLang !== null) {
$element->setAttribute('hreflang', $this->_hrefLang);
}
if ($this->_title !== null) {
$element->setAttribute('title', $this->_title);
}
if ($this->_length !== null) {
$element->setAttribute('length', $this->_length);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'href':
$this->_href = $attribute->nodeValue;
break;
case 'rel':
$this->_rel = $attribute->nodeValue;
break;
case 'type':
$this->_type = $attribute->nodeValue;
break;
case 'hreflang':
$this->_hrefLang = $attribute->nodeValue;
break;
case 'title':
$this->_title = $attribute->nodeValue;
break;
case 'length':
$this->_length = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return string|null
*/
public function getHref()
{
return $this->_href;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setHref($value)
{
$this->_href = $value;
return $this;
}
/**
* @return string|null
*/
public function getRel()
{
return $this->_rel;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setRel($value)
{
$this->_rel = $value;
return $this;
}
/**
* @return string|null
*/
public function getType()
{
return $this->_type;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
/**
* @return string|null
*/
public function getHrefLang()
{
return $this->_hrefLang;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setHrefLang($value)
{
$this->_hrefLang = $value;
return $this;
}
/**
* @return string|null
*/
public function getTitle()
{
return $this->_title;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
/**
* @return string|null
*/
public function getLength()
{
return $this->_length;
}
/**
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setLength($value)
{
$this->_length = $value;
return $this;
}
}
Gdata/App/Extension/Source.php 0000604 00000002331 15071256135 0012231 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Entry
*/
require_once 'Zend/Gdata/App/Entry.php';
/**
* @see Zend_Gdata_App_FeedSourceParent
*/
require_once 'Zend/Gdata/App/FeedSourceParent.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Source extends Zend_Gdata_App_FeedSourceParent
{
protected $_rootElement = 'source';
}
Gdata/App/Extension/Name.php 0000604 00000002417 15071256135 0011656 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:name element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Name extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'name';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Logo.php 0000604 00000002420 15071256135 0011670 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:logo element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Logo extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'logo';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Published.php 0000604 00000002437 15071256135 0012717 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:published element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Published extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'published';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Id.php 0000604 00000002412 15071256135 0011325 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:id element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Id extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'id';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Updated.php 0000604 00000002431 15071256135 0012360 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:updated element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Updated extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'updated';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Draft.php 0000604 00000002471 15071256135 0012036 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the app:draft element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Draft extends Zend_Gdata_App_Extension
{
protected $_rootNamespace = 'app';
protected $_rootElement = 'draft';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Rights.php 0000604 00000002445 15071256135 0012237 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Text
*/
require_once 'Zend/Gdata/App/Extension/Text.php';
/**
* Represents the atom:rights element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Rights extends Zend_Gdata_App_Extension_Text
{
protected $_rootElement = 'rights';
public function __construct($text = null)
{
parent::__construct();
$this->_text = $text;
}
}
Gdata/App/Extension/Text.php 0000604 00000004503 15071256135 0011720 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Abstract class for data models that require only text and type-- such as:
* title, summary, etc.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_Extension_Text extends Zend_Gdata_App_Extension
{
protected $_rootElement = null;
protected $_type = 'text';
public function __construct($text = null, $type = 'text')
{
parent::__construct();
$this->_text = $text;
$this->_type = $type;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'type':
$this->_type = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/*
* @return Zend_Gdata_App_Extension_Type
*/
public function getType()
{
return $this->_type;
}
/*
* @param string $value
* @return Zend_Gdata_App_Extension_Text Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
}
Gdata/App/Extension/Generator.php 0000604 00000005655 15071256135 0012733 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Represents the atom:generator element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Generator extends Zend_Gdata_App_Extension
{
protected $_rootElement = 'generator';
protected $_uri = null;
protected $_version = null;
public function __construct($text = null, $uri = null, $version = null)
{
parent::__construct();
$this->_text = $text;
$this->_uri = $uri;
$this->_version = $version;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_uri !== null) {
$element->setAttribute('uri', $this->_uri);
}
if ($this->_version !== null) {
$element->setAttribute('version', $this->_version);
}
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'uri':
$this->_uri = $attribute->nodeValue;
break;
case 'version':
$this->_version= $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* @return Zend_Gdata_App_Extension_Uri
*/
public function getUri()
{
return $this->_uri;
}
/**
* @param Zend_Gdata_App_Extension_Uri $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setUri($value)
{
$this->_uri = $value;
return $this;
}
/**
* @return Zend_Gdata_App_Extension_Version
*/
public function getVersion()
{
return $this->_version;
}
/**
* @param Zend_Gdata_App_Extension_Version $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setVersion($value)
{
$this->_version = $value;
return $this;
}
}
Gdata/App/Extension/Contributor.php 0000604 00000002273 15071256135 0013310 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension/Person.php';
/**
* Represents the atom:contributor element
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Contributor extends Zend_Gdata_App_Extension_Person
{
protected $_rootElement = 'contributor';
}
Gdata/App/Extension/Element.php 0000604 00000003343 15071256135 0012366 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension
*/
require_once 'Zend/Gdata/App/Extension.php';
/**
* Class that represents elements which were not handled by other parsing
* code in the library.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Extension_Element extends Zend_Gdata_App_Extension
{
public function __construct($rootElement=null, $rootNamespace=null, $rootNamespaceURI=null, $text=null){
parent::__construct();
$this->_rootElement = $rootElement;
$this->_rootNamespace = $rootNamespace;
$this->_rootNamespaceURI = $rootNamespaceURI;
$this->_text = $text;
}
public function transferFromDOM($node)
{
parent::transferFromDOM($node);
$this->_rootNamespace = null;
$this->_rootNamespaceURI = $node->namespaceURI;
$this->_rootElement = $node->localName;
}
}
Gdata/App/CaptchaRequiredException.php 0000604 00000005203 15071256135 0013741 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_CaptchaRequiredException
*/
require_once 'Zend/Gdata/App/AuthException.php';
/**
* Gdata exceptions
*
* Class to represent an exception that occurs during the use of ClientLogin.
* This particular exception happens when a CAPTCHA challenge is issued. This
* challenge is a visual puzzle presented to the user to prove that they are
* not an automated system.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_CaptchaRequiredException extends Zend_Gdata_App_AuthException
{
/**
* The Google Accounts URL prefix.
*/
const ACCOUNTS_URL = 'https://www.google.com/accounts/';
/**
* The token identifier from the server.
*
* @var string
*/
private $captchaToken;
/**
* The URL of the CAPTCHA image.
*
* @var string
*/
private $captchaUrl;
/**
* Constructs the exception to handle a CAPTCHA required response.
*
* @param string $captchaToken The CAPTCHA token ID provided by the server.
* @param string $captchaUrl The URL to the CAPTCHA challenge image.
*/
public function __construct($captchaToken, $captchaUrl) {
$this->captchaToken = $captchaToken;
$this->captchaUrl = Zend_Gdata_App_CaptchaRequiredException::ACCOUNTS_URL . $captchaUrl;
parent::__construct('CAPTCHA challenge issued by server');
}
/**
* Retrieves the token identifier as provided by the server.
*
* @return string
*/
public function getCaptchaToken() {
return $this->captchaToken;
}
/**
* Retrieves the URL CAPTCHA image as provided by the server.
*
* @return string
*/
public function getCaptchaUrl() {
return $this->captchaUrl;
}
}
Gdata/App/AuthException.php 0000604 00000002246 15071256135 0011602 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Gdata exceptions
*
* Class to represent exceptions that occur during Gdata operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_AuthException extends Zend_Gdata_App_Exception
{
}
Gdata/App/Util.php 0000604 00000007674 15071256135 0007751 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Utility class for static functions needed by Zend_Gdata_App
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Util
{
/**
* Convert timestamp into RFC 3339 date string.
* 2005-04-19T15:30:00
*
* @param int $timestamp
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public static function formatTimestamp($timestamp)
{
$rfc3339 = '/^(\d{4})\-?(\d{2})\-?(\d{2})((T|t)(\d{2})\:?(\d{2})' .
'\:?(\d{2})(\.\d{1,})?((Z|z)|([\+\-])(\d{2})\:?(\d{2})))?$/';
if (ctype_digit($timestamp)) {
return gmdate('Y-m-d\TH:i:sP', $timestamp);
} elseif (preg_match($rfc3339, $timestamp) > 0) {
// timestamp is already properly formatted
return $timestamp;
} else {
$ts = strtotime($timestamp);
if ($ts === false) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException("Invalid timestamp: $timestamp.");
}
return date('Y-m-d\TH:i:s', $ts);
}
}
/** Find the greatest key that is less than or equal to a given upper
* bound, and return the value associated with that key.
*
* @param integer|null $maximumKey The upper bound for keys. If null, the
* maxiumum valued key will be found.
* @param array $collection An two-dimensional array of key/value pairs
* to search through.
* @returns mixed The value corresponding to the located key.
* @throws Zend_Gdata_App_Exception Thrown if $collection is empty.
*/
public static function findGreatestBoundedValue($maximumKey, $collection)
{
$found = false;
$foundKey = $maximumKey;
// Sanity check: Make sure that the collection isn't empty
if (sizeof($collection) == 0) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("Empty namespace collection encountered.");
}
if (is_null($maximumKey)) {
// If the key is null, then we return the maximum available
$keys = array_keys($collection);
sort($keys);
$found = true;
$foundKey = end($keys);
} else {
// Otherwise, we optimistically guess that the current version
// will have a matching namespce. If that fails, we decrement the
// version until we find a match.
while (!$found && $foundKey >= 0) {
if (array_key_exists($foundKey, $collection))
$found = true;
else
$foundKey--;
}
}
// Guard: A namespace wasn't found. Either none were registered, or
// the current protcol version is lower than the maximum namespace.
if (!$found) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("Namespace compatible with current protocol not found.");
}
return $foundKey;
}
}
Gdata/App/Entry.php 0000604 00000025225 15071256135 0010125 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_FeedEntryParent
*/
require_once 'Zend/Gdata/App/FeedEntryParent.php';
/**
* @see Zend_Gdata_App_Extension_Content
*/
require_once 'Zend/Gdata/App/Extension/Content.php';
/**
* @see Zend_Gdata_App_Extension_Published
*/
require_once 'Zend/Gdata/App/Extension/Published.php';
/**
* @see Zend_Gdata_App_Extension_Source
*/
require_once 'Zend/Gdata/App/Extension/Source.php';
/**
* @see Zend_Gdata_App_Extension_Summary
*/
require_once 'Zend/Gdata/App/Extension/Summary.php';
/**
* @see Zend_Gdata_App_Extension_Control
*/
require_once 'Zend/Gdata/App/Extension/Control.php';
/**
* Concrete class for working with Atom entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
{
/**
* Root XML element for Atom entries.
*
* @var string
*/
protected $_rootElement = 'entry';
/**
* Class name for each entry in this feed*
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_App_Entry';
/**
* atom:content element
*
* @var Zend_Gdata_App_Extension_Content
*/
protected $_content = null;
/**
* atom:published element
*
* @var Zend_Gdata_App_Extension_Published
*/
protected $_published = null;
/**
* atom:source element
*
* @var Zend_Gdata_App_Extension_Source
*/
protected $_source = null;
/**
* atom:summary element
*
* @var Zend_Gdata_App_Extension_Summary
*/
protected $_summary = null;
/**
* app:control element
*
* @var Zend_Gdata_App_Extension_Control
*/
protected $_control = null;
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_content != null) {
$element->appendChild($this->_content->getDOM($element->ownerDocument));
}
if ($this->_published != null) {
$element->appendChild($this->_published->getDOM($element->ownerDocument));
}
if ($this->_source != null) {
$element->appendChild($this->_source->getDOM($element->ownerDocument));
}
if ($this->_summary != null) {
$element->appendChild($this->_summary->getDOM($element->ownerDocument));
}
if ($this->_control != null) {
$element->appendChild($this->_control->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'content':
$content = new Zend_Gdata_App_Extension_Content();
$content->transferFromDOM($child);
$this->_content = $content;
break;
case $this->lookupNamespace('atom') . ':' . 'published':
$published = new Zend_Gdata_App_Extension_Published();
$published->transferFromDOM($child);
$this->_published = $published;
break;
case $this->lookupNamespace('atom') . ':' . 'source':
$source = new Zend_Gdata_App_Extension_Source();
$source->transferFromDOM($child);
$this->_source = $source;
break;
case $this->lookupNamespace('atom') . ':' . 'summary':
$summary = new Zend_Gdata_App_Extension_Summary();
$summary->transferFromDOM($child);
$this->_summary = $summary;
break;
case $this->lookupNamespace('app') . ':' . 'control':
$control = new Zend_Gdata_App_Extension_Control();
$control->transferFromDOM($child);
$this->_control = $control;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Uploads changes in this entry to the server using Zend_Gdata_App
*
* @param string|null $uri The URI to send requests to, or null if $data
* contains the URI.
* @param string|null $className The name of the class that should we
* deserializing the server response. If null, then
* 'Zend_Gdata_App_Entry' will be used.
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Gdata_App_Entry The updated entry.
* @throws Zend_Gdata_App_Exception
*/
public function save($uri = null, $className = null, $extraHeaders = array())
{
return $this->getService()->updateEntry($this,
$uri,
$className,
$extraHeaders);
}
/**
* Deletes this entry to the server using the referenced
* Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
* entry's link collection.
*
* @return void
* @throws Zend_Gdata_App_Exception
*/
public function delete()
{
$this->getService()->delete($this);
}
/**
* Reload the current entry. Returns a new copy of the entry as returned
* by the server, or null if no changes exist. This does not
* modify the current entry instance.
*
* @param string|null The URI to send requests to, or null if $data
* contains the URI.
* @param string|null The name of the class that should we deserializing
* the server response. If null, then 'Zend_Gdata_App_Entry' will
* be used.
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return mixed A new instance of the current entry with updated data, or
* null if the server reports that no changes have been made.
* @throws Zend_Gdata_App_Exception
*/
public function reload($uri = null, $className = null, $extraHeaders = array())
{
// Get URI
$editLink = $this->getEditLink();
if (is_null($uri) && $editLink != null) {
$uri = $editLink->getHref();
}
// Set classname to current class, if not otherwise set
if (is_null($className)) {
$className = get_class($this);
}
// Append ETag, if present (Gdata v2 and above, only) and doesn't
// conflict with existing headers
if ($this->_etag != null
&& !array_key_exists('If-Match', $extraHeaders)
&& !array_key_exists('If-None-Match', $extraHeaders)) {
$extraHeaders['If-None-Match'] = $this->_etag;
}
// If an HTTP 304 status (Not Modified)is returned, then we return
// null.
$result = null;
try {
$result = $this->service->importUrl($uri, $className, $extraHeaders);
} catch (Zend_Gdata_App_HttpException $e) {
if ($e->getResponse()->getStatus() != '304')
throw $e;
}
return $result;
}
/**
* Gets the value of the atom:content element
*
* @return Zend_Gdata_App_Extension_Content
*/
public function getContent()
{
return $this->_content;
}
/**
* Sets the value of the atom:content element
*
* @param Zend_Gdata_App_Extension_Content $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setContent($value)
{
$this->_content = $value;
return $this;
}
/**
* Sets the value of the atom:published element
* This represents the publishing date for an entry
*
* @return Zend_Gdata_App_Extension_Published
*/
public function getPublished()
{
return $this->_published;
}
/**
* Sets the value of the atom:published element
* This represents the publishing date for an entry
*
* @param Zend_Gdata_App_Extension_Published $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setPublished($value)
{
$this->_published = $value;
return $this;
}
/**
* Gets the value of the atom:source element
*
* @return Zend_Gdata_App_Extension_Source
*/
public function getSource()
{
return $this->_source;
}
/**
* Sets the value of the atom:source element
*
* @param Zend_Gdata_App_Extension_Source $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setSource($value)
{
$this->_source = $value;
return $this;
}
/**
* Gets the value of the atom:summary element
* This represents a textual summary of this entry's content
*
* @return Zend_Gdata_App_Extension_Summary
*/
public function getSummary()
{
return $this->_summary;
}
/**
* Sets the value of the atom:summary element
* This represents a textual summary of this entry's content
*
* @param Zend_Gdata_App_Extension_Summary $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setSummary($value)
{
$this->_summary = $value;
return $this;
}
/**
* Gets the value of the app:control element
*
* @return Zend_Gdata_App_Extension_Control
*/
public function getControl()
{
return $this->_control;
}
/**
* Sets the value of the app:control element
*
* @param Zend_Gdata_App_Extension_Control $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setControl($value)
{
$this->_control = $value;
return $this;
}
}
Gdata/App/MediaFileSource.php 0000604 00000007560 15071256135 0012026 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_MediaData
*/
require_once 'Zend/Gdata/App/BaseMediaSource.php';
/**
* Concrete class to use a file handle as an attachment within a MediaEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
{
/**
* The filename which is represented
*
* @var string
*/
protected $_filename = null;
/**
* The content type for the file attached (example image/png)
*
* @var string
*/
protected $_contentType = null;
/**
* Create a new Zend_Gdata_App_MediaFileSource object.
*
* @param string $filename The name of the file to read from.
*/
public function __construct($filename)
{
$this->setFilename($filename);
}
/**
* Return the MIME multipart representation of this MediaEntry.
*
* @return string
* @throws Zend_Gdata_App_IOException
*/
public function encode()
{
if ($this->getFilename() !== null &&
is_readable($this->getFilename())) {
// Retrieves the file, using the include path
$fileHandle = fopen($this->getFilename(), 'r', true);
$result = fread($fileHandle, filesize($this->getFilename()));
if ($result === false) {
require_once 'Zend/Gdata/App/IOException.php';
throw new Zend_Gdata_App_IOException("Error reading file - " .
$this->getFilename() . '. Read failed.');
}
fclose($fileHandle);
return $result;
} else {
require_once 'Zend/Gdata/App/IOException.php';
throw new Zend_Gdata_App_IOException("Error reading file - " .
$this->getFilename() . '. File is not readable.');
}
}
/**
* Get the filename associated with this reader.
*
* @return string
*/
public function getFilename()
{
return $this->_filename;
}
/**
* Set the filename which is to be read.
*
* @param string $value The desired file handle.
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
*/
public function setFilename($value)
{
$this->_filename = $value;
return $this;
}
/**
* The content type for the file attached (example image/png)
*
* @return string The content type
*/
public function getContentType()
{
return $this->_contentType;
}
/**
* Set the content type for the file attached (example image/png)
*
* @param string $value The content type
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
*/
public function setContentType($value)
{
$this->_contentType = $value;
return $this;
}
/**
* Alias for getFilename().
*
* @return string
*/
public function __toString()
{
return $this->getFilename();
}
}
Gdata/App/LoggingHttpClientAdapterSocket.php 0000604 00000006417 15071256135 0015065 0 ustar 00 <?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_Gdata
* @subpackage App
* @version $Id: Socket.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Http/Client/Adapter/Socket.php';
/**
* Overrides the traditional socket-based adapter class for Zend_Http_Client to
* enable logging of requests. All requests are logged to a location specified
* in the config as $config['logfile']. Requests and responses are logged after
* they are sent and received/processed, thus an error could prevent logging.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_LoggingHttpClientAdapterSocket extends Zend_Http_Client_Adapter_Socket
{
/**
* The file handle for writing logs
*
* @var resource|null
*/
protected $log_handle = null;
/**
* Log the given message to the log file. The log file is configured
* as the config param 'logfile'. This method opens the file for
* writing if necessary.
*
* @param string $message The message to log
*/
protected function log($message)
{
if ($this->log_handle == null) {
$this->log_handle = fopen($this->config['logfile'], 'a');
}
fwrite($this->log_handle, $message);
}
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{
$this->log("Connecting to: ${host}:${port}");
return parent::connect($host, $port, $secure);
}
/**
* Send request to the remote server
*
* @param string $method
* @param Zend_Uri_Http $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
$request = parent::write($method, $uri, $http_ver, $headers, $body);
$this->log("\n\n" . $request);
return $request;
}
/**
* Read response from server
*
* @return string
*/
public function read()
{
$response = parent::read();
$this->log("${response}\n\n");
return $response;
}
/**
* Close the connection to the server
*
*/
public function close()
{
$this->log("Closing socket\n\n");
parent::close();
}
}
Gdata/App/MediaEntry.php 0000604 00000011034 15071256135 0011056 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Entry
*/
require_once 'Zend/Gdata/App/Entry.php';
/**
* @see Zend_Gdata_App_MediaSource
*/
require_once 'Zend/Gdata/App/MediaSource.php';
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* @see Zend_Mime_Message
*/
require_once 'Zend/Mime/Message.php';
/**
* Concrete class for working with Atom entries containing multi-part data.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_MediaEntry extends Zend_Gdata_App_Entry
{
/**
* The attached MediaSource/file
*
* @var Zend_Gdata_App_MediaSource
*/
protected $_mediaSource = null;
/**
* The Zend_Mime object used to generate the boundary
*
* @var Zend_Mime
*/
protected $_mime = null;
/**
* Constructs a new MediaEntry, representing XML data and optional
* file to upload
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null, $mediaSource = null)
{
parent::__construct($element);
$this->_mime = new Zend_Mime();
$this->_mediaSource = $mediaSource;
}
/**
* Return the Zend_Mime object associated with this MediaEntry. This
* object is used to generate the media boundaries.
*
* @return Zend_Mime The Zend_Mime object associated with this MediaEntry.
*/
public function getMime()
{
return $this->_mime;
}
/**
* Return the MIME multipart representation of this MediaEntry.
*
* @return string The MIME multipart representation of this MediaEntry
*/
public function encode()
{
$xmlData = $this->saveXML();
if ($this->getMediaSource() === null) {
// No attachment, just send XML for entry
return $xmlData;
} else {
$mimeMessage = new Zend_Mime_Message();
$mimeMessage->setMime($this->_mime);
$xmlPart = new Zend_Mime_Part($xmlData);
$xmlPart->type = 'application/atom+xml';
$xmlPart->encoding = null;
$mimeMessage->addPart($xmlPart);
$binaryPart = new Zend_Mime_Part($this->getMediaSource()->encode());
$binaryPart->type = $this->getMediaSource()->getContentType();
$binaryPart->encoding = null;
$mimeMessage->addPart($binaryPart);
return $mimeMessage->generateMessage();
}
}
/**
* Return the MediaSource object representing the file attached to this
* MediaEntry.
*
* @return Zend_Gdata_App_MediaSource The attached MediaSource/file
*/
public function getMediaSource()
{
return $this->_mediaSource;
}
/**
* Set the MediaSource object (file) for this MediaEntry
*
* @param Zend_Gdata_App_MediaSource $value The attached MediaSource/file
* @return Zend_Gdata_App_MediaEntry Provides a fluent interface
*/
public function setMediaSource($value)
{
if ($value instanceof Zend_Gdata_App_MediaSource) {
$this->_mediaSource = $value;
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You must specify the media data as a class that conforms to Zend_Gdata_App_MediaSource.');
}
return $this;
}
/**
* Return the boundary used in the MIME multipart message
*
* @return string The boundary used in the MIME multipart message
*/
public function getBoundary()
{
return $this->_mime->boundary();
}
}
Gdata/App/BaseMediaSource.php 0000604 00000012507 15071256135 0012016 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_MediaSource
*/
require_once 'Zend/Gdata/App/MediaSource.php';
/**
* Concrete class to use a file handle as an attachment within a MediaEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_BaseMediaSource implements Zend_Gdata_App_MediaSource
{
/**
* The content type for the attached file (example image/png)
*
* @var string
*/
protected $_contentType = null;
/**
* The slug header value representing the attached file title, or null if
* no slug should be used. The slug header is only necessary in some cases,
* usually when a multipart upload is not being performed.
*
* @var string
*/
protected $_slug = null;
/**
* The content type for the attached file (example image/png)
*
* @return string The content type
*/
public function getContentType()
{
return $this->_contentType;
}
/**
* Set the content type for the file attached (example image/png)
*
* @param string $value The content type
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
*/
public function setContentType($value)
{
$this->_contentType = $value;
return $this;
}
/**
* Returns the Slug header value. Used by some services to determine the
* title for the uploaded file. Returns null if no slug should be used.
*
* @return string
*/
public function getSlug(){
return $this->_slug;
}
/**
* Sets the Slug header value. Used by some services to determine the
* title for the uploaded file. A null value indicates no slug header.
*
* @var string The slug value
* @return Zend_Gdata_App_MediaSource Provides a fluent interface
*/
public function setSlug($value){
$this->_slug = $value;
return $this;
}
/**
* Magic getter to allow acces like $source->foo to call $source->getFoo()
* Alternatively, if no getFoo() is defined, but a $_foo protected variable
* is defined, this is returned.
*
* TODO Remove ability to bypass getFoo() methods??
*
* @param string $name The variable name sought
*/
public function __get($name)
{
$method = 'get'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method));
} else if (property_exists($this, "_${name}")) {
return $this->{'_' . $name};
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
}
}
/**
* Magic setter to allow acces like $source->foo='bar' to call
* $source->setFoo('bar') automatically.
*
* Alternatively, if no setFoo() is defined, but a $_foo protected variable
* is defined, this is returned.
*
* @param string $name
* @param string $value
*/
public function __set($name, $val)
{
$method = 'set'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method), $val);
} else if (isset($this->{'_' . $name}) || is_null($this->{'_' . $name})) {
$this->{'_' . $name} = $val;
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
}
}
/**
* Magic __isset method
*
* @param string $name
*/
public function __isset($name)
{
$rc = new ReflectionClass(get_class($this));
$privName = '_' . $name;
if (!($rc->hasProperty($privName))) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
} else {
if (isset($this->{$privName})) {
if (is_array($this->{$privName})) {
if (count($this->{$privName}) > 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
}
}
Gdata/App/FeedEntryParent.php 0000604 00000052737 15071256135 0012073 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Extension_Element
*/
require_once 'Zend/Gdata/App/Extension/Element.php';
/**
* @see Zend_Gdata_App_Extension_Author
*/
require_once 'Zend/Gdata/App/Extension/Author.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* @see Zend_Gdata_App_Extension_Contributor
*/
require_once 'Zend/Gdata/App/Extension/Contributor.php';
/**
* @see Zend_Gdata_App_Extension_Id
*/
require_once 'Zend/Gdata/App/Extension/Id.php';
/**
* @see Zend_Gdata_App_Extension_Link
*/
require_once 'Zend/Gdata/App/Extension/Link.php';
/**
* @see Zend_Gdata_App_Extension_Rights
*/
require_once 'Zend/Gdata/App/Extension/Rights.php';
/**
* @see Zend_Gdata_App_Extension_Title
*/
require_once 'Zend/Gdata/App/Extension/Title.php';
/**
* @see Zend_Gdata_App_Extension_Updated
*/
require_once 'Zend/Gdata/App/Extension/Updated.php';
/**
* Zend_Version
*/
require_once 'Zend/Version.php';
/**
* Abstract class for common functionality in entries and feeds
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_FeedEntryParent extends Zend_Gdata_App_Base
{
/**
* Service instance used to make network requests.
*
* @see setService(), getService()
*/
protected $_service = null;
/**
* The HTTP ETag associated with this entry. Used for optimistic
* concurrency in protoco v2 or greater.
*
* @var string|null
*/
protected $_etag = NULL;
protected $_author = array();
protected $_category = array();
protected $_contributor = array();
protected $_id = null;
protected $_link = array();
protected $_rights = null;
protected $_title = null;
protected $_updated = null;
/**
* Indicates the major protocol version that should be used.
* At present, recognized values are either 1 or 2. However, any integer
* value >= 1 is considered valid.
*
* @see setMajorProtocolVersion()
* @see getMajorProtocolVersion()
*/
protected $_majorProtocolVersion = 1;
/**
* Indicates the minor protocol version that should be used. Can be set
* to either an integer >= 0, or NULL if no minor version should be sent
* to the server.
*
* @see setMinorProtocolVersion()
* @see getMinorProtocolVersion()
*/
protected $_minorProtocolVersion = null;
/**
* Constructs a Feed or Entry
*/
public function __construct($element = null)
{
if (!($element instanceof DOMElement)) {
if ($element) {
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($element);
@ini_restore('track_errors');
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$element) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
$this->transferFromDOM($element);
}
} else {
$this->transferFromDOM($element);
}
}
/**
* Set the HTTP client instance
*
* Sets the HTTP client object to use for retrieving the feed.
*
* @deprecated Deprecated as of Zend Framework 1.7. Use
* setService() instead.
* @param Zend_Http_Client $httpClient
* @return Zend_Gdata_App_Feed Provides a fluent interface
*/
public function setHttpClient(Zend_Http_Client $httpClient)
{
if (!$this->_service) {
$this->_service = new Zend_Gdata_App();
}
$this->_service->setHttpClient($httpClient);
return $this;
}
/**
* Gets the HTTP client object. If none is set, a new Zend_Http_Client
* will be used.
*
* @deprecated Deprecated as of Zend Framework 1.7. Use
* getService() instead.
* @return Zend_Http_Client_Abstract
*/
public function getHttpClient()
{
if (!$this->_service) {
$this->_service = new Zend_Gdata_App();
}
$client = $this->_service->getHttpClient();
return $client;
}
/**
* Set the active service instance for this object. This will be used to
* perform network requests, such as when calling save() and delete().
*
* @param Zend_Gdata_App $instance The new service instance.
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
*/
public function setService($instance)
{
$this->_service = $instance;
return $this;
}
/**
* Get the active service instance for this object. This will be used to
* perform network requests, such as when calling save() and delete().
*
* @return Zend_Gdata_App|null The current service instance, or null if
* not set.
*/
public function getService()
{
return $this->_service;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
foreach ($this->_author as $author) {
$element->appendChild($author->getDOM($element->ownerDocument));
}
foreach ($this->_category as $category) {
$element->appendChild($category->getDOM($element->ownerDocument));
}
foreach ($this->_contributor as $contributor) {
$element->appendChild($contributor->getDOM($element->ownerDocument));
}
if ($this->_id != null) {
$element->appendChild($this->_id->getDOM($element->ownerDocument));
}
foreach ($this->_link as $link) {
$element->appendChild($link->getDOM($element->ownerDocument));
}
if ($this->_rights != null) {
$element->appendChild($this->_rights->getDOM($element->ownerDocument));
}
if ($this->_title != null) {
$element->appendChild($this->_title->getDOM($element->ownerDocument));
}
if ($this->_updated != null) {
$element->appendChild($this->_updated->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'author':
$author = new Zend_Gdata_App_Extension_Author();
$author->transferFromDOM($child);
$this->_author[] = $author;
break;
case $this->lookupNamespace('atom') . ':' . 'category':
$category = new Zend_Gdata_App_Extension_Category();
$category->transferFromDOM($child);
$this->_category[] = $category;
break;
case $this->lookupNamespace('atom') . ':' . 'contributor':
$contributor = new Zend_Gdata_App_Extension_Contributor();
$contributor->transferFromDOM($child);
$this->_contributor[] = $contributor;
break;
case $this->lookupNamespace('atom') . ':' . 'id':
$id = new Zend_Gdata_App_Extension_Id();
$id->transferFromDOM($child);
$this->_id = $id;
break;
case $this->lookupNamespace('atom') . ':' . 'link':
$link = new Zend_Gdata_App_Extension_Link();
$link->transferFromDOM($child);
$this->_link[] = $link;
break;
case $this->lookupNamespace('atom') . ':' . 'rights':
$rights = new Zend_Gdata_App_Extension_Rights();
$rights->transferFromDOM($child);
$this->_rights = $rights;
break;
case $this->lookupNamespace('atom') . ':' . 'title':
$title = new Zend_Gdata_App_Extension_Title();
$title->transferFromDOM($child);
$this->_title = $title;
break;
case $this->lookupNamespace('atom') . ':' . 'updated':
$updated = new Zend_Gdata_App_Extension_Updated();
$updated->transferFromDOM($child);
$this->_updated = $updated;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @return Zend_Gdata_App_Extension_Author
*/
public function getAuthor()
{
return $this->_author;
}
/**
* Sets the list of the authors of this feed/entry. In an atom feed, each
* author is represented by an atom:author element
*
* @param array $value
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setAuthor($value)
{
$this->_author = $value;
return $this;
}
/**
* Returns the array of categories that classify this feed/entry. Each
* category is represented in an atom feed by an atom:category element.
*
* @return array Array of Zend_Gdata_App_Extension_Category
*/
public function getCategory()
{
return $this->_category;
}
/**
* Sets the array of categories that classify this feed/entry. Each
* category is represented in an atom feed by an atom:category element.
*
* @param array $value Array of Zend_Gdata_App_Extension_Category
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setCategory($value)
{
$this->_category = $value;
return $this;
}
/**
* Returns the array of contributors to this feed/entry. Each contributor
* is represented in an atom feed by an atom:contributor XML element
*
* @return array An array of Zend_Gdata_App_Extension_Contributor
*/
public function getContributor()
{
return $this->_contributor;
}
/**
* Sets the array of contributors to this feed/entry. Each contributor
* is represented in an atom feed by an atom:contributor XML element
*
* @param array $value
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setContributor($value)
{
$this->_contributor = $value;
return $this;
}
/**
* @return Zend_Gdata_App_Extension_Id
*/
public function getId()
{
return $this->_id;
}
/**
* @param Zend_Gdata_App_Extension_Id $value
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setId($value)
{
$this->_id = $value;
return $this;
}
/**
* Given a particular 'rel' value, this method returns a matching
* Zend_Gdata_App_Extension_Link element. If the 'rel' value
* is not provided, the full array of Zend_Gdata_App_Extension_Link
* elements is returned. In an atom feed, each link is represented
* by an atom:link element. The 'rel' value passed to this function
* is the atom:link/@rel attribute. Example rel values include 'self',
* 'edit', and 'alternate'.
*
* @param string $rel The rel value of the link to be found. If null,
* the array of Zend_Gdata_App_Extension_link elements is returned
* @return mixed Either a single Zend_Gdata_App_Extension_link element,
* an array of the same or null is returned depending on the rel value
* supplied as the argument to this function
*/
public function getLink($rel = null)
{
if ($rel == null) {
return $this->_link;
} else {
foreach ($this->_link as $link) {
if ($link->rel == $rel) {
return $link;
}
}
return null;
}
}
/**
* Returns the Zend_Gdata_App_Extension_Link element which represents
* the URL used to edit this resource. This link is in the atom feed/entry
* as an atom:link with a rel attribute value of 'edit'.
*
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
*/
public function getEditLink()
{
return $this->getLink('edit');
}
/**
* Returns the Zend_Gdata_App_Extension_Link element which represents
* the URL used to retrieve the next chunk of results when paging through
* a feed. This link is in the atom feed as an atom:link with a
* rel attribute value of 'next'.
*
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
*/
public function getNextLink()
{
return $this->getLink('next');
}
/**
* Returns the Zend_Gdata_App_Extension_Link element which represents
* the URL used to retrieve the previous chunk of results when paging
* through a feed. This link is in the atom feed as an atom:link with a
* rel attribute value of 'previous'.
*
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
*/
public function getPreviousLink()
{
return $this->getLink('previous');
}
/**
* @return Zend_Gdata_App_Extension_Link
*/
public function getLicenseLink()
{
return $this->getLink('license');
}
/**
* Returns the Zend_Gdata_App_Extension_Link element which represents
* the URL used to retrieve the entry or feed represented by this object
* This link is in the atom feed/entry as an atom:link with a
* rel attribute value of 'self'.
*
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
*/
public function getSelfLink()
{
return $this->getLink('self');
}
/**
* Returns the Zend_Gdata_App_Extension_Link element which represents
* the URL for an alternate view of the data represented by this feed or
* entry. This alternate view is commonly a user-facing webpage, blog
* post, etc. The MIME type for the data at the URL is available from the
* returned Zend_Gdata_App_Extension_Link element.
* This link is in the atom feed/entry as an atom:link with a
* rel attribute value of 'self'.
*
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
*/
public function getAlternateLink()
{
return $this->getLink('alternate');
}
/**
* @param array $value The array of Zend_Gdata_App_Extension_Link elements
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setLink($value)
{
$this->_link = $value;
return $this;
}
/**
* @return Zend_Gdata_AppExtension_Rights
*/
public function getRights()
{
return $this->_rights;
}
/**
* @param Zend_Gdata_App_Extension_Rights $value
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
*/
public function setRights($value)
{
$this->_rights = $value;
return $this;
}
/**
* Returns the title of this feed or entry. The title is an extremely
* short textual representation of this resource and is found as
* an atom:title element in a feed or entry
*
* @return Zend_Gdata_App_Extension_Title
*/
public function getTitle()
{
return $this->_title;
}
/**
* Returns a string representation of the title of this feed or entry.
* The title is an extremely short textual representation of this
* resource and is found as an atom:title element in a feed or entry
*
* @return string
*/
public function getTitleValue()
{
if (($titleObj = $this->getTitle()) != null) {
return $titleObj->getText();
} else {
return null;
}
}
/**
* Returns the title of this feed or entry. The title is an extremely
* short textual representation of this resource and is found as
* an atom:title element in a feed or entry
*
* @param Zend_Gdata_App_Extension_Title $value
* @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
*/
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
/**
* @return Zend_Gdata_App_Extension_Updated
*/
public function getUpdated()
{
return $this->_updated;
}
/**
* @param Zend_Gdata_App_Extension_Updated $value
* @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
*/
public function setUpdated($value)
{
$this->_updated = $value;
return $this;
}
/**
* Set the Etag for the current entry to $value. Setting $value to null
* unsets the Etag.
*
* @param string|null $value
* @return Zend_Gdata_App_Entry Provides a fluent interface
*/
public function setEtag($value) {
$this->_etag = $value;
return $this;
}
/**
* Return the Etag for the current entry, or null if not set.
*
* @return string|null
*/
public function getEtag() {
return $this->_etag;
}
/**
* Set the major protocol version that should be used. Values < 1
* (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
* to be thrown.
*
* @see _majorProtocolVersion
* @param (int|NULL) $value The major protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMajorProtocolVersion($value)
{
if (!($value >= 1) && !is_null($value)) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException(
'Major protocol version must be >= 1');
}
$this->_majorProtocolVersion = $value;
}
/**
* Get the major protocol version that is in use.
*
* @see _majorProtocolVersion
* @return (int|NULL) The major protocol version in use.
*/
public function getMajorProtocolVersion()
{
return $this->_majorProtocolVersion;
}
/**
* Set the minor protocol version that should be used. If set to NULL, no
* minor protocol version will be sent to the server. Values < 0 will
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
*
* @see _minorProtocolVersion
* @param (int|NULL) $value The minor protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMinorProtocolVersion($value)
{
if (!($value >= 0)) {
require_once('Zend/Gdata/App/InvalidArgumentException.php');
throw new Zend_Gdata_App_InvalidArgumentException(
'Minor protocol version must be >= 0 or null');
}
$this->_minorProtocolVersion = $value;
}
/**
* Get the minor protocol version that is in use.
*
* @see _minorProtocolVersion
* @return (int|NULL) The major protocol version in use, or NULL if no
* minor version is specified.
*/
public function getMinorProtocolVersion()
{
return $this->_minorProtocolVersion;
}
/**
* Get the full version of a namespace prefix
*
* Looks up a prefix (atom:, etc.) in the list of registered
* namespaces and returns the full namespace URI if
* available. Returns the prefix, unmodified, if it's not
* registered.
*
* The current entry or feed's version will be used when performing the
* namespace lookup unless overridden using $majorVersion and
* $minorVersion. If the entry/fee has a null version, then the latest
* protocol version will be used by default.
*
* @param string $prefix The namespace prefix to lookup.
* @param integer $majorVersion The major protocol version in effect.
* Defaults to null (auto-select).
* @param integer $minorVersion The minor protocol version in effect.
* Defaults to null (auto-select).
* @return string
*/
public function lookupNamespace($prefix,
$majorVersion = null,
$minorVersion = null)
{
// Auto-select current version
if (is_null($majorVersion)) {
$majorVersion = $this->getMajorProtocolVersion();
}
if (is_null($minorVersion)) {
$minorVersion = $this->getMinorProtocolVersion();
}
// Perform lookup
return parent::lookupNamespace($prefix, $majorVersion, $minorVersion);
}
}
Gdata/App/MediaSource.php 0000604 00000004210 15071256135 0011213 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Interface for defining data that can be encoded and sent over the network.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Gdata_App_MediaSource
{
/**
* Return a byte stream representation of this object.
*
* @return string
*/
public function encode();
/**
* Set the content type for the file attached (example image/png)
*
* @param string $value The content type
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
*/
public function setContentType($value);
/**
* The content type for the file attached (example image/png)
*
* @return string The content type
*/
public function getContentType();
/**
* Sets the Slug header value. Used by some services to determine the
* title for the uploaded file. A null value indicates no slug header.
*
* @var string The slug value
* @return Zend_Gdata_App_MediaSource Provides a fluent interface
*/
public function setSlug($value);
/**
* Returns the Slug header value. Used by some services to determine the
* title for the uploaded file. Returns null if no slug should be used.
*
* @return string The slug value
*/
public function getSlug();
}
Gdata/App/VersionException.php 0000604 00000002265 15071256135 0012327 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Gdata APP exceptions
*
* Class to represent version exceptions that occur during Gdata APP operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_VersionException extends Zend_Gdata_App_Exception
{
}
Gdata/App/HttpException.php 0000604 00000005666 15071256135 0011631 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Zend_Http_Client_Exception
*/
require_once 'Zend/Http/Client/Exception.php';
/**
* Gdata exceptions
*
* Class to represent exceptions that occur during Gdata operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_HttpException extends Zend_Gdata_App_Exception
{
protected $_httpClientException = null;
protected $_response = null;
/**
* Create a new Zend_Gdata_App_HttpException
*
* @param string $message Optionally set a message
* @param Zend_Http_Client_Exception Optionally pass in a Zend_Http_Client_Exception
* @param Zend_Http_Response Optionally pass in a Zend_Http_Response
*/
public function __construct($message = null, $e = null, $response = null)
{
$this->_httpClientException = $e;
$this->_response = $response;
parent::__construct($message);
}
/**
* Get the Zend_Http_Client_Exception.
*
* @return Zend_Http_Client_Exception
*/
public function getHttpClientException()
{
return $this->_httpClientException;
}
/**
* Set the Zend_Http_Client_Exception.
*
* @param Zend_Http_Client_Exception $value
*/
public function setHttpClientException($value)
{
$this->_httpClientException = $value;
return $this;
}
/**
* Set the Zend_Http_Response.
*
* @param Zend_Http_Response $response
*/
public function setResponse($response)
{
$this->_response = $response;
return $this;
}
/**
* Get the Zend_Http_Response.
*
* @return Zend_Http_Response
*/
public function getResponse()
{
return $this->_response;
}
/**
* Get the body of the Zend_Http_Response
*
* @return string
*/
public function getRawResponseBody()
{
if ($this->getResponse()) {
$response = $this->getResponse();
return $response->getRawBody();
}
return null;
}
}
Gdata/App/Base.php 0000604 00000042561 15071256135 0007700 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Util
*/
require_once 'Zend/Gdata/App/Util.php';
/**
* Abstract class for all XML elements
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_Base
{
/**
* @var string The XML element name, including prefix if desired
*/
protected $_rootElement = null;
/**
* @var string The XML namespace prefix
*/
protected $_rootNamespace = 'atom';
/**
* @var string The XML namespace URI - takes precedence over lookup up the
* corresponding URI for $_rootNamespace
*/
protected $_rootNamespaceURI = null;
/**
* @var array Leftover elements which were not handled
*/
protected $_extensionElements = array();
/**
* @var array Leftover attributes which were not handled
*/
protected $_extensionAttributes = array();
/**
* @var string XML child text node content
*/
protected $_text = null;
/**
* List of namespaces, as a three-dimensional array. The first dimension
* represents the namespace prefix, the second dimension represents the
* minimum major protocol version, and the third dimension is the minimum
* minor protocol version. Null keys are NOT allowed.
*
* When looking up a namespace for a given prefix, the greatest version
* number (both major and minor) which is less than the effective version
* should be used.
*
* @see lookupNamespace()
* @see registerNamespace()
* @see registerAllNamespaces()
* @var array
*/
protected $_namespaces = array(
'atom' => array(
1 => array(
0 => 'http://www.w3.org/2005/Atom'
)
),
'app' => array(
1 => array(
0 => 'http://purl.org/atom/app#'
),
2 => array(
0 => 'http://www.w3.org/2007/app'
)
)
);
public function __construct()
{
}
/**
* Returns the child text node of this element
* This represents any raw text contained within the XML element
*
* @return string Child text node
*/
public function getText($trim = true)
{
if ($trim) {
return trim($this->_text);
} else {
return $this->_text;
}
}
/**
* Sets the child text node of this element
* This represents any raw text contained within the XML element
*
* @param string $value Child text node
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
*/
public function setText($value)
{
$this->_text = $value;
return $this;
}
/**
* Returns an array of all elements not matched to data model classes
* during the parsing of the XML
*
* @return array All elements not matched to data model classes during parsing
*/
public function getExtensionElements()
{
return $this->_extensionElements;
}
/**
* Sets an array of all elements not matched to data model classes
* during the parsing of the XML. This method can be used to add arbitrary
* child XML elements to any data model class.
*
* @param array $value All extension elements
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
*/
public function setExtensionElements($value)
{
$this->_extensionElements = $value;
return $this;
}
/**
* Returns an array of all extension attributes not transformed into data
* model properties during parsing of the XML. Each element of the array
* is a hashed array of the format:
* array('namespaceUri' => string, 'name' => string, 'value' => string);
*
* @return array All extension attributes
*/
public function getExtensionAttributes()
{
return $this->_extensionAttributes;
}
/**
* Sets an array of all extension attributes not transformed into data
* model properties during parsing of the XML. Each element of the array
* is a hashed array of the format:
* array('namespaceUri' => string, 'name' => string, 'value' => string);
* This can be used to add arbitrary attributes to any data model element
*
* @param array $value All extension attributes
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
*/
public function setExtensionAttributes($value)
{
$this->_extensionAttributes = $value;
return $this;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
if (is_null($doc)) {
$doc = new DOMDocument('1.0', 'utf-8');
}
if ($this->_rootNamespaceURI != null) {
$element = $doc->createElementNS($this->_rootNamespaceURI, $this->_rootElement);
} elseif ($this->_rootNamespace !== null) {
if (strpos($this->_rootElement, ':') === false) {
$elementName = $this->_rootNamespace . ':' . $this->_rootElement;
} else {
$elementName = $this->_rootElement;
}
$element = $doc->createElementNS($this->lookupNamespace($this->_rootNamespace), $elementName);
} else {
$element = $doc->createElement($this->_rootElement);
}
if ($this->_text != null) {
$element->appendChild($element->ownerDocument->createTextNode($this->_text));
}
foreach ($this->_extensionElements as $extensionElement) {
$element->appendChild($extensionElement->getDOM($element->ownerDocument));
}
foreach ($this->_extensionAttributes as $attribute) {
$element->setAttribute($attribute['name'], $attribute['value']);
}
return $element;
}
/**
* Given a child DOMNode, tries to determine how to map the data into
* object instance members. If no mapping is defined, Extension_Element
* objects are created and stored in an array.
*
* @param DOMNode $child The DOMNode needed to be handled
*/
protected function takeChildFromDOM($child)
{
if ($child->nodeType == XML_TEXT_NODE) {
$this->_text = $child->nodeValue;
} else {
$extensionElement = new Zend_Gdata_App_Extension_Element();
$extensionElement->transferFromDOM($child);
$this->_extensionElements[] = $extensionElement;
}
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
$arrayIndex = ($attribute->namespaceURI != '')?(
$attribute->namespaceURI . ':' . $attribute->name):
$attribute->name;
$this->_extensionAttributes[$arrayIndex] =
array('namespaceUri' => $attribute->namespaceURI,
'name' => $attribute->localName,
'value' => $attribute->nodeValue);
}
/**
* Transfers each child and attribute into member variables.
* This is called when XML is received over the wire and the data
* model needs to be built to represent this XML.
*
* @param DOMNode $node The DOMNode that represents this object's data
*/
public function transferFromDOM($node)
{
foreach ($node->childNodes as $child) {
$this->takeChildFromDOM($child);
}
foreach ($node->attributes as $attribute) {
$this->takeAttributeFromDOM($attribute);
}
}
/**
* Parses the provided XML text and generates data model classes for
* each know element by turning the XML text into a DOM tree and calling
* transferFromDOM($element). The first data model element with the same
* name as $this->_rootElement is used and the child elements are
* recursively parsed.
*
* @param string $xml The XML text to parse
*/
public function transferFromXML($xml)
{
if ($xml) {
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($xml);
@ini_restore('track_errors');
if (!$success) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$element) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element');
}
$this->transferFromDOM($element);
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
}
}
/**
* Converts this element and all children into XML text using getDOM()
*
* @return string XML content
*/
public function saveXML()
{
$element = $this->getDOM();
return $element->ownerDocument->saveXML($element);
}
/**
* Alias for saveXML() returns XML content for this element and all
* children
*
* @return string XML content
*/
public function getXML()
{
return $this->saveXML();
}
/**
* Alias for saveXML()
*
* Can be overridden by children to provide more complex representations
* of entries.
*
* @return string Encoded string content
*/
public function encode()
{
return $this->saveXML();
}
/**
* Get the full version of a namespace prefix
*
* Looks up a prefix (atom:, etc.) in the list of registered
* namespaces and returns the full namespace URI if
* available. Returns the prefix, unmodified, if it's not
* registered.
*
* @param string $prefix The namespace prefix to lookup.
* @param integer $majorVersion The major protocol version in effect.
* Defaults to '1'.
* @param integer $minorVersion The minor protocol version in effect.
* Defaults to null (use latest).
* @return string
*/
public function lookupNamespace($prefix,
$majorVersion = 1,
$minorVersion = null)
{
// If no match, return the prefix by default
$result = $prefix;
// Find tuple of keys that correspond to the namespace we should use
if (isset($this->_namespaces[$prefix])) {
// Major version search
$nsData = $this->_namespaces[$prefix];
$foundMajorV = Zend_Gdata_App_Util::findGreatestBoundedValue(
$majorVersion, $nsData);
// Minor version search
$nsData = $nsData[$foundMajorV];
$foundMinorV = Zend_Gdata_App_Util::findGreatestBoundedValue(
$minorVersion, $nsData);
// Extract NS
$result = $nsData[$foundMinorV];
}
return $result;
}
/**
* Add a namespace and prefix to the registered list
*
* Takes a prefix and a full namespace URI and adds them to the
* list of registered namespaces for use by
* $this->lookupNamespace().
*
* @param string $prefix The namespace prefix
* @param string $namespaceUri The full namespace URI
* @param integer $majorVersion The major protocol version in effect.
* Defaults to '1'.
* @param integer $minorVersion The minor protocol version in effect.
* Defaults to null (use latest).
* @return void
*/
public function registerNamespace($prefix,
$namespaceUri,
$majorVersion = 1,
$minorVersion = 0)
{
$this->_namespaces[$prefix][$majorVersion][$minorVersion] =
$namespaceUri;
}
/**
* Add an array of namespaces to the registered list.
*
* Takes an array in the format of:
* namespace prefix, namespace URI, major protocol version,
* minor protocol version and adds them with calls to ->registerNamespace()
*
* @param array $namespaceArray An array of namespaces.
* @return void
*/
public function registerAllNamespaces($namespaceArray)
{
foreach($namespaceArray as $namespace) {
$this->registerNamespace(
$namespace[0], $namespace[1], $namespace[2], $namespace[3]);
}
}
/**
* Magic getter to allow access like $entry->foo to call $entry->getFoo()
* Alternatively, if no getFoo() is defined, but a $_foo protected variable
* is defined, this is returned.
*
* TODO Remove ability to bypass getFoo() methods??
*
* @param string $name The variable name sought
*/
public function __get($name)
{
$method = 'get'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method));
} else if (property_exists($this, "_${name}")) {
return $this->{'_' . $name};
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
}
}
/**
* Magic setter to allow acces like $entry->foo='bar' to call
* $entry->setFoo('bar') automatically.
*
* Alternatively, if no setFoo() is defined, but a $_foo protected variable
* is defined, this is returned.
*
* TODO Remove ability to bypass getFoo() methods??
*
* @param string $name
* @param string $value
*/
public function __set($name, $val)
{
$method = 'set'.ucfirst($name);
if (method_exists($this, $method)) {
return call_user_func(array(&$this, $method), $val);
} else if (isset($this->{'_' . $name}) || is_null($this->{'_' . $name})) {
$this->{'_' . $name} = $val;
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
}
}
/**
* Magic __isset method
*
* @param string $name
*/
public function __isset($name)
{
$rc = new ReflectionClass(get_class($this));
$privName = '_' . $name;
if (!($rc->hasProperty($privName))) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Property ' . $name . ' does not exist');
} else {
if (isset($this->{$privName})) {
if (is_array($this->{$privName})) {
if (count($this->{$privName}) > 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
}
/**
* Magic __unset method
*
* @param string $name
*/
public function __unset($name)
{
if (isset($this->{'_' . $name})) {
if (is_array($this->{'_' . $name})) {
$this->{'_' . $name} = array();
} else {
$this->{'_' . $name} = null;
}
}
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*
* @return string The text representation of this object
*/
public function __toString()
{
return $this->getText();
}
}
Gdata/App/FeedSourceParent.php 0000604 00000016352 15071256135 0012223 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Entry
*/
require_once 'Zend/Gdata/App/Entry.php';
/**
* @see Zend_Gdata_App_FeedSourceParent
*/
require_once 'Zend/Gdata/App/FeedEntryParent.php';
/**
* @see Zend_Gdata_App_Extension_Generator
*/
require_once 'Zend/Gdata/App/Extension/Generator.php';
/**
* @see Zend_Gdata_App_Extension_Icon
*/
require_once 'Zend/Gdata/App/Extension/Icon.php';
/**
* @see Zend_Gdata_App_Extension_Logo
*/
require_once 'Zend/Gdata/App/Extension/Logo.php';
/**
* @see Zend_Gdata_App_Extension_Subtitle
*/
require_once 'Zend/Gdata/App/Extension/Subtitle.php';
/**
* Atom feed class
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Gdata_App_FeedSourceParent extends Zend_Gdata_App_FeedEntryParent
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_App_Entry';
/**
* Root XML element for Atom entries.
*
* @var string
*/
protected $_rootElement = null;
protected $_generator = null;
protected $_icon = null;
protected $_logo = null;
protected $_subtitle = null;
/**
* Set the HTTP client instance
*
* Sets the HTTP client object to use for retrieving the feed.
*
* @deprecated Deprecated as of Zend Framework 1.7. Use
* setService() instead.
* @param Zend_Http_Client $httpClient
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
*/
public function setHttpClient(Zend_Http_Client $httpClient)
{
parent::setHttpClient($httpClient);
foreach ($this->_entry as $entry) {
$entry->setHttpClient($httpClient);
}
return $this;
}
/**
* Set the active service instance for this feed and all enclosed entries.
* This will be used to perform network requests, such as when calling
* save() and delete().
*
* @param Zend_Gdata_App $instance The new service instance.
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
*/
public function setService($instance)
{
parent::setService($instance);
foreach ($this->_entry as $entry) {
$entry->setService($instance);
}
return $this;
}
/**
* Make accessing some individual elements of the feed easier.
*
* Special accessors 'entry' and 'entries' are provided so that if
* you wish to iterate over an Atom feed's entries, you can do so
* using foreach ($feed->entries as $entry) or foreach
* ($feed->entry as $entry).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
default:
return parent::__get($var);
}
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_generator != null) {
$element->appendChild($this->_generator->getDOM($element->ownerDocument));
}
if ($this->_icon != null) {
$element->appendChild($this->_icon->getDOM($element->ownerDocument));
}
if ($this->_logo != null) {
$element->appendChild($this->_logo->getDOM($element->ownerDocument));
}
if ($this->_subtitle != null) {
$element->appendChild($this->_subtitle->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'generator':
$generator = new Zend_Gdata_App_Extension_Generator();
$generator->transferFromDOM($child);
$this->_generator = $generator;
break;
case $this->lookupNamespace('atom') . ':' . 'icon':
$icon = new Zend_Gdata_App_Extension_Icon();
$icon->transferFromDOM($child);
$this->_icon = $icon;
break;
case $this->lookupNamespace('atom') . ':' . 'logo':
$logo = new Zend_Gdata_App_Extension_Logo();
$logo->transferFromDOM($child);
$this->_logo = $logo;
break;
case $this->lookupNamespace('atom') . ':' . 'subtitle':
$subtitle = new Zend_Gdata_App_Extension_Subtitle();
$subtitle->transferFromDOM($child);
$this->_subtitle = $subtitle;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @return Zend_Gdata_AppExtension_Generator
*/
public function getGenerator()
{
return $this->_generator;
}
/**
* @param Zend_Gdata_App_Extension_Generator $value
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
*/
public function setGenerator($value)
{
$this->_generator = $value;
return $this;
}
/**
* @return Zend_Gdata_AppExtension_Icon
*/
public function getIcon()
{
return $this->_icon;
}
/**
* @param Zend_Gdata_App_Extension_Icon $value
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
*/
public function setIcon($value)
{
$this->_icon = $value;
return $this;
}
/**
* @return Zend_Gdata_AppExtension_logo
*/
public function getlogo()
{
return $this->_logo;
}
/**
* @param Zend_Gdata_App_Extension_logo $value
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
*/
public function setlogo($value)
{
$this->_logo = $value;
return $this;
}
/**
* @return Zend_Gdata_AppExtension_Subtitle
*/
public function getSubtitle()
{
return $this->_subtitle;
}
/**
* @param Zend_Gdata_App_Extension_Subtitle $value
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
*/
public function setSubtitle($value)
{
$this->_subtitle = $value;
return $this;
}
}
Gdata/App/Feed.php 0000604 00000022750 15071256135 0007667 0 ustar 00 <?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_Gdata
* @subpackage App
* @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 Zend_Gdata_App_Entry
*/
require_once 'Zend/Gdata/App/Entry.php';
/**
* @see Zend_Gdata_App_FeedSourceParent
*/
require_once 'Zend/Gdata/App/FeedSourceParent.php';
/**
* Atom feed class
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent
implements Iterator, ArrayAccess
{
/**
* The root xml element of this data element
*
* @var string
*/
protected $_rootElement = 'feed';
/**
* Cache of feed entries.
*
* @var array
*/
protected $_entry = array();
/**
* Current location in $_entry array
*
* @var int
*/
protected $_entryIndex = 0;
/**
* Make accessing some individual elements of the feed easier.
*
* Special accessors 'entry' and 'entries' are provided so that if
* you wish to iterate over an Atom feed's entries, you can do so
* using foreach ($feed->entries as $entry) or foreach
* ($feed->entry as $entry).
*
* @param string $var The property to get.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'entries':
return $this;
default:
return parent::__get($var);
}
}
/**
* Retrieves the DOM model representing this object and all children
*
* @param DOMDocument $doc
* @return DOMElement
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
foreach ($this->_entry as $entry) {
$element->appendChild($entry->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('atom') . ':' . 'entry':
$newEntry = new $this->_entryClassName($child);
$newEntry->setHttpClient($this->getHttpClient());
$newEntry->setMajorProtocolVersion($this->getMajorProtocolVersion());
$newEntry->setMinorProtocolVersion($this->getMinorProtocolVersion());
$this->_entry[] = $newEntry;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the number of entries in this feed object.
*
* @return integer Entry count.
*/
public function count()
{
return count($this->_entry);
}
/**
* Required by the Iterator interface.
*
* @return void
*/
public function rewind()
{
$this->_entryIndex = 0;
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row, or null if no rows.
*/
public function current()
{
return $this->_entry[$this->_entryIndex];
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row number (starts at 0), or NULL if no rows
*/
public function key()
{
return $this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return mixed The next row, or null if no more rows.
*/
public function next()
{
++$this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return boolean Whether the iteration is valid
*/
public function valid()
{
return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count();
}
/**
* Gets the array of atom:entry elements contained within this
* atom:feed representation
*
* @return array Zend_Gdata_App_Entry array
*/
public function getEntry()
{
return $this->_entry;
}
/**
* Sets the array of atom:entry elements contained within this
* atom:feed representation
*
* @param array $value The array of Zend_Gdata_App_Entry elements
* @return Zend_Gdata_App_Feed Provides a fluent interface
*/
public function setEntry($value)
{
$this->_entry = $value;
return $this;
}
/**
* Adds an entry representation to the array of entries
* contained within this feed
*
* @param Zend_Gdata_App_Entry An individual entry to add.
* @return Zend_Gdata_App_Feed Provides a fluent interface
*/
public function addEntry($value)
{
$this->_entry[] = $value;
return $this;
}
/**
* Required by the ArrayAccess interface
*
* @param int $key The index to set
* @param Zend_Gdata_App_Entry $value The value to set
* @return void
*/
public function offsetSet($key, $value)
{
$this->_entry[$key] = $value;
}
/**
* Required by the ArrayAccess interface
*
* @param int $key The index to get
* @param Zend_Gdata_App_Entry $value The value to set
*/
public function offsetGet($key)
{
if (array_key_exists($key, $this->_entry)) {
return $this->_entry[$key];
}
}
/**
* Required by the ArrayAccess interface
*
* @param int $key The index to set
* @param Zend_Gdata_App_Entry $value The value to set
*/
public function offsetUnset($key)
{
if (array_key_exists($key, $this->_entry)) {
unset($this->_entry[$key]);
}
}
/**
* Required by the ArrayAccess interface
*
* @param int $key The index to check for existence
* @return boolean
*/
public function offsetExists($key)
{
return (array_key_exists($key, $this->_entry));
}
/**
* Retrieve the next set of results from this feed.
*
* @throws Zend_Gdata_App_Exception
* @return mixed|null Returns the next set of results as a feed of the same
* class as this feed, or null if no results exist.
*/
public function getNextFeed()
{
$nextLink = $this->getNextLink();
if (!$nextLink) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_Exception('No link to next set ' .
'of results found.');
}
$nextLinkHref = $nextLink->getHref();
$service = new Zend_Gdata_App($this->getHttpClient());
return $service->getFeed($nextLinkHref, get_class($this));
}
/**
* Retrieve the previous set of results from this feed.
*
* @throws Zend_Gdata_App_Exception
* @return mixed|null Returns the previous set of results as a feed of
* the same class as this feed, or null if no results exist.
*/
public function getPreviousFeed()
{
$previousLink = $this->getPreviousLink();
if (!$previousLink) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_Exception('No link to previous set ' .
'of results found.');
}
$previousLinkHref = $previousLink->getHref();
$service = new Zend_Gdata_App($this->getHttpClient());
return $service->getFeed($previousLinkHref, get_class($this));
}
/**
* Set the major protocol version that should be used. Values < 1 will
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
*
* This value will be propogated to all child entries.
*
* @see _majorProtocolVersion
* @param (int|NULL) $value The major protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMajorProtocolVersion($value)
{
parent::setMajorProtocolVersion($value);
foreach ($this->entries as $entry) {
$entry->setMajorProtocolVersion($value);
}
}
/**
* Set the minor protocol version that should be used. If set to NULL, no
* minor protocol version will be sent to the server. Values < 0 will
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
*
* This value will be propogated to all child entries.
*
* @see _minorProtocolVersion
* @param (int|NULL) $value The minor protocol version to use.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function setMinorProtocolVersion($value)
{
parent::setMinorProtocolVersion($value);
foreach ($this->entries as $entry) {
$entry->setMinorProtocolVersion($value);
}
}
}
Gdata/App/IOException.php 0000604 00000002260 15071256135 0011204 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Gdata App IO exceptions.
*
* Class to represent IO exceptions that occur during Gdata App operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_IOException extends Zend_Gdata_App_Exception
{
}
Gdata/App/BadMethodCallException.php 0000604 00000002263 15071256135 0013323 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_Exception
*/
require_once 'Zend/Gdata/App/Exception.php';
/**
* Gdata APP exceptions
*
* Class to represent exceptions that occur during Gdata APP operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_BadMethodCallException extends Zend_Gdata_App_Exception
{
}
Gdata/App/Exception.php 0000604 00000002211 15071256135 0010750 0 ustar 00 <?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_Gdata
* @subpackage App
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Gdata App exceptions
*
* Class to represent exceptions that occur during Gdata App operations.
*
* @category Zend
* @package Zend_Gdata
* @subpackage App
* @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_Gdata_App_Exception extends Zend_Exception
{
}
Gdata/Docs/Query.php 0000604 00000013300 15071256135 0010270 0 ustar 00 <?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_Gdata
* @subpackage Docs
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Document List documents
*
* @link http://code.google.com/apis/gdata/spreadsheets/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Docs
* @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_Gdata_Docs_Query extends Zend_Gdata_Query
{
/**
* The base URL for retrieving a document list
*
* @var string
*/
const DOCUMENTS_LIST_FEED_URI = 'http://docs.google.com/feeds/documents';
/**
* The generic base URL used by some inherited methods
*
* @var string
*/
protected $_defaultFeedUri = self::DOCUMENTS_LIST_FEED_URI;
/**
* The visibility to be used when querying for the feed. A request for a
* feed with private visbility requires the user to be authenricated.
* Private is the only avilable visibility for the documents list.
*
* @var string
*/
protected $_visibility = 'private';
/**
* The projection determines how much detail should be given in the
* result of the query. Full is the only valid projection for the
* documents list.
*
* @var string
*/
protected $_projection = 'full';
/**
* Constructs a new instance of a Zend_Gdata_Docs_Query object.
*/
public function __construct()
{
parent::__construct();
}
/**
* Sets the projection for this query. Common values for projection
* include 'full'.
*
* @param string $value
* @return Zend_Gdata_Docs_Query Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* Sets the visibility for this query. Common values for visibility
* include 'private'.
*
* @return Zend_Gdata_Docs_Query Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
/**
* Gets the projection for this query.
*
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* Gets the visibility for this query.
*
* @return string visibility
*/
public function getVisibility()
{
return $this->_visibility;
}
/**
* Sets the title attribute for this query. The title parameter is used
* to restrict the results to documents whose titles either contain or
* completely match the title.
*
* @param string $value
* @return Zend_Gdata_Docs_Query Provides a fluent interface
*/
public function setTitle($value)
{
if ($value !== null) {
$this->_params['title'] = $value;
} else {
unset($this->_params['title']);
}
return $this;
}
/**
* Gets the title attribute for this query.
*
* @return string title
*/
public function getTitle()
{
if (array_key_exists('title', $this->_params)) {
return $this->_params['title'];
} else {
return null;
}
}
/**
* Sets the title-exact attribute for this query.
* If title-exact is set to true, the title query parameter will be used
* in an exact match. Only documents with a title identical to the
* title parameter will be returned.
*
* @param boolean $value Use either true or false
* @return Zend_Gdata_Docs_Query Provides a fluent interface
*/
public function setTitleExact($value)
{
if ($value) {
$this->_params['title-exact'] = $value;
} else {
unset($this->_params['title-exact']);
}
return $this;
}
/**
* Gets the title-exact attribute for this query.
*
* @return string title-exact
*/
public function getTitleExact()
{
if (array_key_exists('title-exact', $this->_params)) {
return $this->_params['title-exact'];
} else {
return false;
}
}
/**
* Gets the full query URL for this query.
*
* @return string url
*/
public function getQueryUrl()
{
$uri = $this->_defaultFeedUri;
if ($this->_visibility !== null) {
$uri .= '/' . $this->_visibility;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'A visibility must be provided for cell queries.');
}
if ($this->_projection !== null) {
$uri .= '/' . $this->_projection;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'A projection must be provided for cell queries.');
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Docs/DocumentListFeed.php 0000604 00000003440 15071256135 0012365 0 ustar 00 <?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_Gdata
* @subpackage Docs
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Data model for a Google Documents List feed of documents
*
* @category Zend
* @package Zend_Gdata
* @subpackage Docs
* @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_Gdata_Docs_DocumentListFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Docs_DocumentListEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Docs_DocumentListFeed';
/**
* Create a new instance of a feed for a list of documents.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Docs::$namespaces);
parent::__construct($element);
}
}
Gdata/Docs/DocumentListEntry.php 0000604 00000003037 15071256135 0012625 0 ustar 00 <?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_Gdata
* @subpackage Docs
* @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 Zend_Gdata_EntryAtom
*/
require_once 'Zend/Gdata/Entry.php';
/**
* Represents a Documents List entry in the Documents List data API meta feed
* of a user's documents.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Docs
* @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_Gdata_Docs_DocumentListEntry extends Zend_Gdata_Entry
{
/**
* Create a new instance of an entry representing a document.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Docs::$namespaces);
parent::__construct($element);
}
}
Gdata/Calendar/ListFeed.php 0000604 00000005546 15071256135 0011520 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Extension_Timezone
*/
require_once 'Zend/Gdata/Calendar/Extension/Timezone.php';
/**
* Represents the meta-feed list of calendars
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_ListFeed extends Zend_Gdata_Feed
{
protected $_timezone = null;
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Calendar_ListEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Calendar_ListFeed';
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_timezone != null) {
$element->appendChild($this->_timezone->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gCal') . ':' . 'timezone';
$timezone = new Zend_Gdata_Calendar_Extension_Timezone();
$timezone->transferFromDOM($child);
$this->_timezone = $timezone;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getTimezone()
{
return $this->_timezone;
}
/**
* @param Zend_Gdata_Calendar_Extension_Timezone $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setTimezone($value)
{
$this->_timezone = $value;
return $this;
}
}
Gdata/Calendar/EventEntry.php 0000604 00000011637 15071256135 0012122 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Kind_EventEntry
*/
require_once 'Zend/Gdata/Kind/EventEntry.php';
/**
* @see Zend_Gdata_Calendar_Extension_SendEventNotifications
*/
require_once 'Zend/Gdata/Calendar/Extension/SendEventNotifications.php';
/**
* @see Zend_Gdata_Calendar_Extension_Timezone
*/
require_once 'Zend/Gdata/Calendar/Extension/Timezone.php';
/**
* @see Zend_Gdata_Calendar_Extension_Link
*/
require_once 'Zend/Gdata/Calendar/Extension/Link.php';
/**
* @see Zend_Gdata_Calendar_Extension_QuickAdd
*/
require_once 'Zend/Gdata/Calendar/Extension/QuickAdd.php';
/**
* Data model class for a Google Calendar Event Entry
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_EventEntry extends Zend_Gdata_Kind_EventEntry
{
protected $_entryClassName = 'Zend_Gdata_Calendar_EventEntry';
protected $_sendEventNotifications = null;
protected $_timezone = null;
protected $_quickadd = null;
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_sendEventNotifications != null) {
$element->appendChild($this->_sendEventNotifications->getDOM($element->ownerDocument));
}
if ($this->_timezone != null) {
$element->appendChild($this->_timezone->getDOM($element->ownerDocument));
}
if ($this->_quickadd != null) {
$element->appendChild($this->_quickadd->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gCal') . ':' . 'sendEventNotifications';
$sendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
$sendEventNotifications->transferFromDOM($child);
$this->_sendEventNotifications = $sendEventNotifications;
break;
case $this->lookupNamespace('gCal') . ':' . 'timezone';
$timezone = new Zend_Gdata_Calendar_Extension_Timezone();
$timezone->transferFromDOM($child);
$this->_timezone = $timezone;
break;
case $this->lookupNamespace('atom') . ':' . 'link';
$link = new Zend_Gdata_Calendar_Extension_Link();
$link->transferFromDOM($child);
$this->_link[] = $link;
break;
case $this->lookupNamespace('gCal') . ':' . 'quickadd';
$quickadd = new Zend_Gdata_Calendar_Extension_QuickAdd();
$quickadd->transferFromDOM($child);
$this->_quickadd = $quickadd;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getSendEventNotifications()
{
return $this->_sendEventNotifications;
}
public function setSendEventNotifications($value)
{
$this->_sendEventNotifications = $value;
return $this;
}
public function getTimezone()
{
return $this->_timezone;
}
/**
* @param Zend_Gdata_Calendar_Extension_Timezone $value
* @return Zend_Gdata_Extension_EventEntry Provides a fluent interface
*/
public function setTimezone($value)
{
$this->_timezone = $value;
return $this;
}
public function getQuickAdd()
{
return $this->_quickadd;
}
/**
* @param Zend_Gdata_Calendar_Extension_QuickAdd $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setQuickAdd($value)
{
$this->_quickadd = $value;
return $this;
}
}
Gdata/Calendar/ListEntry.php 0000604 00000015550 15071256135 0011752 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Calendar_Extension_AccessLevel
*/
require_once 'Zend/Gdata/Calendar/Extension/AccessLevel.php';
/**
* @see Zend_Calendar_Extension_Color
*/
require_once 'Zend/Gdata/Calendar/Extension/Color.php';
/**
* @see Zend_Calendar_Extension_Hidden
*/
require_once 'Zend/Gdata/Calendar/Extension/Hidden.php';
/**
* @see Zend_Calendar_Extension_Selected
*/
require_once 'Zend/Gdata/Calendar/Extension/Selected.php';
/**
* @see Zend_Gdata_Extension_EventStatus
*/
require_once 'Zend/Gdata/Extension/EventStatus.php';
/**
* @see Zend_Gdata_Extension_Visibility
*/
require_once 'Zend/Gdata/Extension/Visibility.php';
/**
* @see Zend_Extension_Where
*/
require_once 'Zend/Gdata/Extension/Where.php';
/**
* Represents a Calendar entry in the Calendar data API meta feed of a user's
* calendars.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_ListEntry extends Zend_Gdata_Entry
{
protected $_color = null;
protected $_accessLevel = null;
protected $_hidden = null;
protected $_selected = null;
protected $_timezone = null;
protected $_where = array();
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_accessLevel != null) {
$element->appendChild($this->_accessLevel->getDOM($element->ownerDocument));
}
if ($this->_color != null) {
$element->appendChild($this->_color->getDOM($element->ownerDocument));
}
if ($this->_hidden != null) {
$element->appendChild($this->_hidden->getDOM($element->ownerDocument));
}
if ($this->_selected != null) {
$element->appendChild($this->_selected->getDOM($element->ownerDocument));
}
if ($this->_timezone != null) {
$element->appendChild($this->_timezone->getDOM($element->ownerDocument));
}
if ($this->_where != null) {
foreach ($this->_where as $where) {
$element->appendChild($where->getDOM($element->ownerDocument));
}
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gCal') . ':' . 'accesslevel';
$accessLevel = new Zend_Gdata_Calendar_Extension_AccessLevel();
$accessLevel->transferFromDOM($child);
$this->_accessLevel = $accessLevel;
break;
case $this->lookupNamespace('gCal') . ':' . 'color';
$color = new Zend_Gdata_Calendar_Extension_Color();
$color->transferFromDOM($child);
$this->_color = $color;
break;
case $this->lookupNamespace('gCal') . ':' . 'hidden';
$hidden = new Zend_Gdata_Calendar_Extension_Hidden();
$hidden->transferFromDOM($child);
$this->_hidden = $hidden;
break;
case $this->lookupNamespace('gCal') . ':' . 'selected';
$selected = new Zend_Gdata_Calendar_Extension_Selected();
$selected->transferFromDOM($child);
$this->_selected = $selected;
break;
case $this->lookupNamespace('gCal') . ':' . 'timezone';
$timezone = new Zend_Gdata_Calendar_Extension_Timezone();
$timezone->transferFromDOM($child);
$this->_timezone = $timezone;
break;
case $this->lookupNamespace('gd') . ':' . 'where';
$where = new Zend_Gdata_Extension_Where();
$where->transferFromDOM($child);
$this->_where[] = $where;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getAccessLevel()
{
return $this->_accessLevel;
}
/**
* @param Zend_Gdata_Calendar_Extension_AccessLevel $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setAccessLevel($value)
{
$this->_accessLevel = $value;
return $this;
}
public function getColor()
{
return $this->_color;
}
/**
* @param Zend_Gdata_Calendar_Extension_Color $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setColor($value)
{
$this->_color = $value;
return $this;
}
public function getHidden()
{
return $this->_hidden;
}
/**
* @param Zend_Gdata_Calendar_Extension_Hidden $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setHidden($value)
{
$this->_hidden = $value;
return $this;
}
public function getSelected()
{
return $this->_selected;
}
/**
* @param Zend_Gdata_Calendar_Extension_Selected $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setSelected($value)
{
$this->_selected = $value;
return $this;
}
public function getTimezone()
{
return $this->_timezone;
}
/**
* @param Zend_Gdata_Calendar_Extension_Timezone $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setTimezone($value)
{
$this->_timezone = $value;
return $this;
}
public function getWhere()
{
return $this->_where;
}
/**
* @param Zend_Gdata_Extension_Where $value
* @return Zend_Gdata_Extension_ListEntry Provides a fluent interface
*/
public function setWhere($value)
{
$this->_where = $value;
return $this;
}
}
Gdata/Calendar/Extension/SendEventNotifications.php 0000604 00000007746 15071256135 0016426 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Data model class to represent an entry's sendEventNotifications
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_SendEventNotifications extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'sendEventNotifications';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Extension_SendEventNotifications object.
* @param bool $value (optional) SendEventNotifications value as URI.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', ($this->_value ? "true" : "false"));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
if ($attribute->nodeValue == "true") {
$this->_value = true;
}
else if ($attribute->nodeValue == "false") {
$this->_value = false;
}
else {
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's Value attribute.
*
* @return string The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's Value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Extension_SendEventNotifications The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Calendar/Extension/QuickAdd.php 0000604 00000007722 15071256135 0013460 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:quickAdd element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_QuickAdd extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'quickadd';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_QuickAdd object.
* @param string $value (optional) The text content of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', ($this->_value ? "true" : "false"));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
if ($attribute->nodeValue == "true") {
$this->_value = true;
}
else if ($attribute->nodeValue == "false") {
$this->_value = false;
}
else {
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return string The value associated with this attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_QuickAdd The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Calendar/Extension/Color.php 0000604 00000007234 15071256135 0013047 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:color element used by the Calendar data API
* to define the color of a calendar in the UI.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_Color extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'color';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Color object.
* @param string $value (optional) The text content of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value != null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return string The value associated with this attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_Color The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->_value;
}
}
Gdata/Calendar/Extension/Link.php 0000604 00000010047 15071256135 0012662 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/App/Extension/Link.php';
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Calendar/Extension/WebContent.php';
/**
* Specialized Link class for use with Calendar. Enables use of gCal extension elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_Link extends Zend_Gdata_App_Extension_Link
{
protected $_webContent = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Link object.
* @see Zend_Gdata_App_Extension_Link#__construct
* @param Zend_Gdata_Calendar_Extension_Webcontent $webContent
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null, $webContent = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
$this->_webContent = $webContent;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_webContent != null) {
$element->appendChild($this->_webContent->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gCal') . ':' . 'webContent':
$webContent = new Zend_Gdata_Calendar_Extension_WebContent();
$webContent->transferFromDOM($child);
$this->_webContent = $webContent;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's WebContent attribute.
*
* @return Zend_Gdata_Calendar_Extension_Webcontent The WebContent value
*/
public function getWebContent()
{
return $this->_webContent;
}
/**
* Set the value for this element's WebContent attribute.
*
* @param Zend_Gdata_Calendar_Extension_WebContent $value The desired value for this attribute.
* @return Zend_Calendar_Extension_Link The element being modified. Provides a fluent interface.
*/
public function setWebContent($value)
{
$this->_webContent = $value;
return $this;
}
}
Gdata/Calendar/Extension/Hidden.php 0000604 00000007765 15071256135 0013175 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:hidden element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_Hidden extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'hidden';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Hidden object.
* @param bool $value (optional) The value of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', ($this->_value ? "true" : "false"));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
if ($attribute->nodeValue == "true") {
$this->_value = true;
}
else if ($attribute->nodeValue == "false") {
$this->_value = false;
}
else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return string The requested attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_Hidden The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->_value;
}
}
Gdata/Calendar/Extension/Selected.php 0000604 00000010015 15071256135 0013510 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:selected element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_Selected extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'selected';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Selected object.
* @param bool $value (optional) The value of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value !== null) {
$element->setAttribute('value', ($this->_value ? "true" : "false"));
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
if ($attribute->nodeValue == "true") {
$this->_value = true;
}
else if ($attribute->nodeValue == "false") {
$this->_value = false;
}
else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return bool The value associated with this attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_Selected The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->_value;
}
}
Gdata/Calendar/Extension/AccessLevel.php 0000604 00000007316 15071256135 0014163 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Calendar.php';
/**
* Represents the gCal:accessLevel element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_AccessLevel extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'accesslevel';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_AccessLevel object.
* @param string $value (optional) The text content of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value != null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return string The attribute being modified.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_Selected The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Calendar/Extension/WebContent.php 0000604 00000012455 15071256135 0014042 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:webContent element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_WebContent extends Zend_Gdata_App_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'webContent';
protected $_url = null;
protected $_height = null;
protected $_width = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_WebContent object.
* @param string $url (optional) The value for this element's URL attribute.
* @param string $height (optional) The value for this element's height attribute.
* @param string $width (optional) The value for this element's width attribute.
*/
public function __construct($url = null, $height = null, $width = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_url = $url;
$this->_height = $height;
$this->_width = $width;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->url != null) {
$element->setAttribute('url', $this->_url);
}
if ($this->height != null) {
$element->setAttribute('height', $this->_height);
}
if ($this->width != null) {
$element->setAttribute('width', $this->_width);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'url':
$this->_url = $attribute->nodeValue;
break;
case 'height':
$this->_height = $attribute->nodeValue;
break;
case 'width':
$this->_width = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's URL attribute.
*
* @return string The desired value for this attribute.
*/
public function getURL()
{
return $this->_url;
}
/**
* Set the value for this element's URL attribute.
*
* @param bool $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_WebContent The element being modified.
*/
public function setURL($value)
{
$this->_url = $value;
return $this;
}
/**
* Get the value for this element's height attribute.
*
* @return int The desired value for this attribute.
*/
public function getHeight()
{
return $this->_height;
}
/**
* Set the value for this element's height attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_WebContent The element being modified.
*/
public function setHeight($value)
{
$this->_height = $value;
return $this;
}
/**
* Get the value for this element's height attribute.
*
* @return int The desired value for this attribute.
*/
public function getWidth()
{
return $this->_width;
}
/**
* Set the value for this element's height attribute.
*
* @param int $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_WebContent The element being modified.
*/
public function setWidth($value)
{
$this->_width = $value;
return $this;
}
}
Gdata/Calendar/Extension/Timezone.php 0000604 00000007177 15071256135 0013571 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Represents the gCal:timezone element used by the Calendar data API
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_Extension_Timezone extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gCal';
protected $_rootElement = 'timezone';
protected $_value = null;
/**
* Constructs a new Zend_Gdata_Calendar_Extension_Timezone object.
* @param string $value (optional) The text content of the element.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_value != null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Get the value for this element's value attribute.
*
* @return string The value associated with this attribute.
*/
public function getValue()
{
return $this->_value;
}
/**
* Set the value for this element's value attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Calendar_Extension_Timezone The element being modified.
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Magic toString method allows using this directly via echo
* Works best in PHP >= 4.2.0
*/
public function __toString()
{
return $this->getValue();
}
}
Gdata/Calendar/EventFeed.php 0000604 00000005374 15071256135 0011665 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Extension_Timezone
*/
require_once 'Zend/Gdata/Calendar/Extension/Timezone.php';
/**
* Data model for a Google Calendar feed of events
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_EventFeed extends Zend_Gdata_Feed
{
protected $_timezone = null;
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Calendar_EventEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Calendar_EventFeed';
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_timezone != null) {
$element->appendChild($this->_timezone->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gCal') . ':' . 'timezone';
$timezone = new Zend_Gdata_Calendar_Extension_Timezone();
$timezone->transferFromDOM($child);
$this->_timezone = $timezone;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getTimezone()
{
return $this->_timezone;
}
public function setTimezone($value)
{
$this->_timezone = $value;
return $this;
}
}
Gdata/Calendar/EventQuery.php 0000604 00000027426 15071256135 0012131 0 ustar 00 <?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_Gdata
* @subpackage Calendar
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_util
*/
require_once('Zend/Gdata/App/Util.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Calendar events
*
* @link http://code.google.com/apis/gdata/calendar/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Calendar
* @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_Gdata_Calendar_EventQuery extends Zend_Gdata_Query
{
const CALENDAR_FEED_URI = 'http://www.google.com/calendar/feeds';
protected $_defaultFeedUri = self::CALENDAR_FEED_URI;
protected $_comments = null;
protected $_user = null;
protected $_visibility = null;
protected $_projection = null;
protected $_event = null;
/**
* Create Gdata_Calendar_EventQuery object. If a URL is provided,
* it becomes the base URL, and additional URL components may be
* appended. For instance, if $url is 'http://www.foo.com', the
* default URL constructed will be 'http://www.foo.com/default/public/full'
*
* @param string $url The URL to use as the base path for requests
*/
public function __construct($url = null)
{
parent::__construct($url);
}
/**
* @param string $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setComments($value)
{
$this->_comments = $value;
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setEvent($value)
{
$this->_event = $value;
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setUser($value)
{
$this->_user = $value;
return $this;
}
/**
* @param bool $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
/**
* @return string comments
*/
public function getComments()
{
return $this->_comments;
}
/**
* @return string event
*/
public function getEvent()
{
return $this->_event;
}
/**
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* @return string user
*/
public function getUser()
{
return $this->_user;
}
/**
* @return string visibility
*/
public function getVisibility()
{
return $this->_visibility;
}
/**
* @param int $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setStartMax($value)
{
if ($value != null) {
$this->_params['start-max'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['start-max']);
}
return $this;
}
/**
* @param int $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setStartMin($value)
{
if ($value != null) {
$this->_params['start-min'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['start-min']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setOrderBy($value)
{
if ($value != null) {
$this->_params['orderby'] = $value;
} else {
unset($this->_params['orderby']);
}
return $this;
}
/**
* @return int start-max
*/
public function getStartMax()
{
if (array_key_exists('start-max', $this->_params)) {
return $this->_params['start-max'];
} else {
return null;
}
}
/**
* @return int start-min
*/
public function getStartMin()
{
if (array_key_exists('start-min', $this->_params)) {
return $this->_params['start-min'];
} else {
return null;
}
}
/**
* @return string orderby
*/
public function getOrderBy()
{
if (array_key_exists('orderby', $this->_params)) {
return $this->_params['orderby'];
} else {
return null;
}
}
/**
* @return string sortorder
*/
public function getSortOrder()
{
if (array_key_exists('sortorder', $this->_params)) {
return $this->_params['sortorder'];
} else {
return null;
}
}
/**
* @return string sortorder
*/
public function setSortOrder($value)
{
if ($value != null) {
$this->_params['sortorder'] = $value;
} else {
unset($this->_params['sortorder']);
}
return $this;
}
/**
* @return string recurrence-expansion-start
*/
public function getRecurrenceExpansionStart()
{
if (array_key_exists('recurrence-expansion-start', $this->_params)) {
return $this->_params['recurrence-expansion-start'];
} else {
return null;
}
}
/**
* @return string recurrence-expansion-start
*/
public function setRecurrenceExpansionStart($value)
{
if ($value != null) {
$this->_params['recurrence-expansion-start'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['recurrence-expansion-start']);
}
return $this;
}
/**
* @return string recurrence-expansion-end
*/
public function getRecurrenceExpansionEnd()
{
if (array_key_exists('recurrence-expansion-end', $this->_params)) {
return $this->_params['recurrence-expansion-end'];
} else {
return null;
}
}
/**
* @return string recurrence-expansion-end
*/
public function setRecurrenceExpansionEnd($value)
{
if ($value != null) {
$this->_params['recurrence-expansion-end'] = Zend_Gdata_App_Util::formatTimestamp($value);
} else {
unset($this->_params['recurrence-expansion-end']);
}
return $this;
}
/**
* @param string $value Also accepts bools.
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function getSingleEvents()
{
if (array_key_exists('singleevents', $this->_params)) {
$value = $this->_params['singleevents'];
switch ($value) {
case 'true':
return true;
break;
case 'false':
return false;
break;
default:
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'Invalid query param value for futureevents: ' .
$value . ' It must be a boolean.');
}
} else {
return null;
}
}
/**
* @param string $value Also accepts bools. If using a string, must be either "true" or "false".
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setSingleEvents($value)
{
if (!is_null($value)) {
if (is_bool($value)) {
$this->_params['singleevents'] = ($value?'true':'false');
} elseif ($value == 'true' | $value == 'false') {
$this->_params['singleevents'] = $value;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'Invalid query param value for futureevents: ' .
$value . ' It must be a boolean.');
}
} else {
unset($this->_params['singleevents']);
}
return $this;
}
/**
* @return string futureevents
*/
public function getFutureEvents()
{
if (array_key_exists('futureevents', $this->_params)) {
$value = $this->_params['futureevents'];
switch ($value) {
case 'true':
return true;
break;
case 'false':
return false;
break;
default:
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'Invalid query param value for futureevents: ' .
$value . ' It must be a boolean.');
}
} else {
return null;
}
}
/**
* @param string $value Also accepts bools. If using a string, must be either "true" or "false" or
* an exception will be thrown on retrieval.
* @return Zend_Gdata_Calendar_EventQuery Provides a fluent interface
*/
public function setFutureEvents($value)
{
if (!is_null($value)) {
if (is_bool($value)) {
$this->_params['futureevents'] = ($value?'true':'false');
} elseif ($value == 'true' | $value == 'false') {
$this->_params['futureevents'] = $value;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception(
'Invalid query param value for futureevents: ' .
$value . ' It must be a boolean.');
}
} else {
unset($this->_params['futureevents']);
}
return $this;
}
/**
* @return string url
*/
public function getQueryUrl()
{
if (isset($this->_url)) {
$uri = $this->_url;
} else {
$uri = $this->_defaultFeedUri;
}
if ($this->getUser() != null) {
$uri .= '/' . $this->getUser();
} else {
$uri .= '/default';
}
if ($this->getVisibility() != null) {
$uri .= '/' . $this->getVisibility();
} else {
$uri .= '/public';
}
if ($this->getProjection() != null) {
$uri .= '/' . $this->getProjection();
} else {
$uri .= '/full';
}
if ($this->getEvent() != null) {
$uri .= '/' . $this->getEvent();
if ($this->getComments() != null) {
$uri .= '/comments/' . $this->getComments();
}
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gbase/SnippetFeed.php 0000604 00000002501 15071256135 0011523 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Gbase_Feed
*/
require_once 'Zend/Gdata/Gbase/Feed.php';
/**
* Represents the Google Base Snippets Feed
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_SnippetFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual snippet feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Gbase_SnippetEntry';
}
Gdata/Gbase/ItemEntry.php 0000604 00000013122 15071256135 0011236 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Gbase_Entry
*/
require_once 'Zend/Gdata/Gbase/Entry.php';
/**
* Concrete class for working with Item entries.
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_ItemEntry extends Zend_Gdata_Gbase_Entry
{
/**
* The classname for individual item entry elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Gbase_ItemEntry';
/**
* Set the value of the itme_type
*
* @param Zend_Gdata_Gbase_Extension_ItemType $value The desired value for the item_type
* @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
*/
public function setItemType($value)
{
$this->addGbaseAttribute('item_type', $value, 'text');
return $this;
}
/**
* Adds a custom attribute to the entry in the following format:
* <g:[$name] type='[$type]'>[$value]</g:[$name]>
*
* @param string $name The name of the attribute
* @param string $value The text value of the attribute
* @param string $type (optional) The type of the attribute.
* e.g.: 'text', 'number', 'floatUnit'
* @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
*/
public function addGbaseAttribute($name, $text, $type = null) {
$newBaseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute($name, $text, $type);
$this->_baseAttributes[] = $newBaseAttribute;
return $this;
}
/**
* Removes a Base attribute from the current list of Base attributes
*
* @param Zend_Gdata_Gbase_Extension_BaseAttribute $baseAttribute The attribute to be removed
* @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
*/
public function removeGbaseAttribute($baseAttribute) {
$baseAttributes = $this->_baseAttributes;
for ($i = 0; $i < count($this->_baseAttributes); $i++) {
if ($this->_baseAttributes[$i] == $baseAttribute) {
array_splice($baseAttributes, $i, 1);
break;
}
}
$this->_baseAttributes = $baseAttributes;
return $this;
}
/**
* Uploads changes in this entry to the server using Zend_Gdata_App
*
* @param boolean $dryRun Whether the transaction is dry run or not.
* @param string|null $uri The URI to send requests to, or null if $data
* contains the URI.
* @param string|null $className The name of the class that should we
* deserializing the server response. If null, then
* 'Zend_Gdata_App_Entry' will be used.
* @param array $extraHeaders Extra headers to add to the request, as an
* array of string-based key/value pairs.
* @return Zend_Gdata_App_Entry The updated entry
* @throws Zend_Gdata_App_Exception
*/
public function save($dryRun = false,
$uri = null,
$className = null,
$extraHeaders = array())
{
if ($dryRun == true) {
$editLink = $this->getEditLink();
if ($uri == null && $editLink !== null) {
$uri = $editLink->getHref() . '?dry-run=true';
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
}
$service = new Zend_Gdata_App($this->getHttpClient());
return $service->updateEntry($this,
$uri,
$className,
$extraHeaders);
} else {
parent::save($uri, $className, $extraHeaders);
}
}
/**
* Deletes this entry to the server using the referenced
* Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
* entry's link collection.
*
* @param boolean $dyrRun Whether the transaction is dry run or not
* @return void
* @throws Zend_Gdata_App_Exception
*/
public function delete($dryRun = false)
{
$uri = null;
if ($dryRun == true) {
$editLink = $this->getEditLink();
if ($editLink !== null) {
$uri = $editLink->getHref() . '?dry-run=true';
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
}
parent::delete($uri);
} else {
parent::delete();
}
}
}
Gdata/Gbase/SnippetQuery.php 0000604 00000003665 15071256135 0012001 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Zend_Gdata_Gbase_Query
*/
require_once('Zend/Gdata/Gbase/Query.php');
/**
* Assists in constructing queries for Google Base Snippets Feed
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_SnippetQuery extends Zend_Gdata_Gbase_Query
{
/**
* Path to the snippets feeds on the Google Base server.
*/
const BASE_SNIPPET_FEED_URI = 'http://www.google.com/base/feeds/snippets';
/**
* The default URI for POST methods
*
* @var string
*/
protected $_defaultFeedUri = self::BASE_SNIPPET_FEED_URI;
/**
* Returns the query URL generated by this query instance.
*
* @return string The query URL for this instance.
*/
public function getQueryUrl()
{
$uri = $this->_defaultFeedUri;
if ($this->getCategory() !== null) {
$uri .= '/-/' . $this->getCategory();
}
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Gbase/ItemQuery.php 0000604 00000004554 15071256135 0011253 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* @see Zend_Gdata_Gbase_Query
*/
require_once('Zend/Gdata/Gbase/Query.php');
/**
* Assists in constructing queries for Google Base Customer Items Feed
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_ItemQuery extends Zend_Gdata_Gbase_Query
{
/**
* Path to the customer items feeds on the Google Base server.
*/
const GBASE_ITEM_FEED_URI = 'http://www.google.com/base/feeds/items';
/**
* The default URI for POST methods
*
* @var string
*/
protected $_defaultFeedUri = self::GBASE_ITEM_FEED_URI;
/**
* The id of an item
*
* @var string
*/
protected $_id = null;
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setId($value)
{
$this->_id = $value;
return $this;
}
/*
* @return string id
*/
public function getId()
{
return $this->_id;
}
/**
* Returns the query URL generated by this query instance.
*
* @return string The query URL for this instance.
*/
public function getQueryUrl()
{
$uri = $this->_defaultFeedUri;
if ($this->getId() !== null) {
$uri .= '/' . $this->getId();
} else {
$uri .= $this->getQueryString();
}
return $uri;
}
}
Gdata/Gbase/SnippetEntry.php 0000604 00000002524 15071256135 0011766 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Gbase_Entry
*/
require_once 'Zend/Gdata/Gbase/Entry.php';
/**
* Concrete class for working with Snippet entries.
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_SnippetEntry extends Zend_Gdata_Gbase_Entry
{
/**
* The classname for individual snippet entry elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Gbase_SnippetEntry';
}
Gdata/Gbase/ItemFeed.php 0000604 00000002476 15071256135 0011012 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Gbase_Feed
*/
require_once 'Zend/Gdata/Gbase/Feed.php';
/**
* Represents the Google Base Customer Items Feed
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_ItemFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual item feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Gbase_ItemEntry';
}
Gdata/Gbase/Entry.php 0000604 00000011043 15071256135 0010417 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Gbase_Extension_BaseAttribute
*/
require_once 'Zend/Gdata/Gbase/Extension/BaseAttribute.php';
/**
* Base class for working with Google Base entries.
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_Entry extends Zend_Gdata_Entry
{
/**
* Name of the base class for Google Base entries
*
* var @string
*/
protected $_entryClassName = 'Zend_Gdata_Gbase_Entry';
/**
* Google Base attribute elements in the 'g' namespace
*
* @var array
*/
protected $_baseAttributes = array();
/**
* Constructs a new Zend_Gdata_Gbase_ItemEntry object.
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gbase::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
foreach ($this->_baseAttributes as $baseAttribute) {
$element->appendChild($baseAttribute->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
if (strstr($absoluteNodeName, $this->lookupNamespace('g') . ':')) {
$baseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute();
$baseAttribute->transferFromDOM($child);
$this->_baseAttributes[] = $baseAttribute;
} else {
parent::takeChildFromDOM($child);
}
}
/**
* Get the value of the itme_type
*
* @return Zend_Gdata_Gbase_Extension_ItemType The requested object.
*/
public function getItemType()
{
$itemType = $this->getGbaseAttribute('item_type');
if (is_object($itemType[0])) {
return $itemType[0];
} else {
return null;
}
}
/**
* Return all the Base attributes
* @return Zend_Gdata_Gbase_Extension_BaseAttribute
*/
public function getGbaseAttributes() {
return $this->_baseAttributes;
}
/**
* Return an array of Base attributes that match the given attribute name
*
* @param string $name The name of the Base attribute to look for
* @return array $matches Array that contains the matching list of Base attributes
*/
public function getGbaseAttribute($name)
{
$matches = array();
for ($i = 0; $i < count($this->_baseAttributes); $i++) {
$baseAttribute = $this->_baseAttributes[$i];
if ($baseAttribute->rootElement == $name &&
$baseAttribute->rootNamespaceURI == $this->lookupNamespace('g')) {
$matches[] = &$this->_baseAttributes[$i];
}
}
return $matches;
}
}
Gdata/Gbase/Extension/BaseAttribute.php 0000604 00000007077 15071256135 0014044 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_App_Extension_Element
*/
require_once 'Zend/Gdata/App/Extension/Element.php';
/**
* Concrete class for working with ItemType elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_Extension_BaseAttribute extends Zend_Gdata_App_Extension_Element
{
/**
* Namespace for Google Base elements
*
* var @string
*/
protected $_rootNamespace = 'g';
/**
* Create a new instance.
*
* @param string $name (optional) The name of the Base attribute
* @param string $text (optional) The text value of the Base attribute
* @param string $text (optional) The type of the Base attribute
*/
public function __construct($name = null, $text = null, $type = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gbase::$namespaces);
if ($type !== null) {
$attr = array('name' => 'type', 'value' => $type);
$typeAttr = array('type' => $attr);
$this->setExtensionAttributes($typeAttr);
}
parent::__construct($name,
$this->_rootNamespace,
$this->lookupNamespace($this->_rootNamespace),
$text);
}
/**
* Get the name of the attribute
*
* @return attribute name The requested object.
*/
public function getName() {
return $this->_rootElement;
}
/**
* Get the type of the attribute
*
* @return attribute type The requested object.
*/
public function getType() {
$typeAttr = $this->getExtensionAttributes();
return $typeAttr['type']['value'];
}
/**
* Set the 'name' of the Base attribute object:
* <g:[$name] type='[$type]'>[$value]</g:[$name]>
*
* @param Zend_Gdata_App_Extension_Element $attribute The attribute object
* @param string $name The name of the Base attribute
* @return Zend_Gdata_Extension_ItemEntry Provides a fluent interface
*/
public function setName($name) {
$this->_rootElement = $name;
return $this;
}
/**
* Set the 'type' of the Base attribute object:
* <g:[$name] type='[$type]'>[$value]</g:[$name]>
*
* @param Zend_Gdata_App_Extension_Element $attribute The attribute object
* @param string $type The type of the Base attribute
* @return Zend_Gdata_Extension_ItemEntry Provides a fluent interface
*/
public function setType($type) {
$attr = array('name' => 'type', 'value' => $type);
$typeAttr = array('type' => $attr);
$this->setExtensionAttributes($typeAttr);
return $this;
}
}
Gdata/Gbase/Feed.php 0000604 00000003135 15071256135 0010164 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Base class for the Google Base Feed
*
* @link http://code.google.com/apis/base/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_Feed extends Zend_Gdata_Feed
{
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Gbase_Feed';
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Gbase::$namespaces);
parent::__construct($element);
}
}
Gdata/Gbase/Query.php 0000604 00000014207 15071256135 0010430 0 ustar 00 <?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_Gdata
* @subpackage Gbase
* @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 Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Base
*
* @link http://code.google.com/apis/base
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gbase
* @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_Gdata_Gbase_Query extends Zend_Gdata_Query
{
/**
* Path to the customer items feeds on the Google Base server.
*/
const GBASE_ITEM_FEED_URI = 'http://www.google.com/base/feeds/items';
/**
* Path to the snippets feeds on the Google Base server.
*/
const GBASE_SNIPPET_FEED_URI = 'http://www.google.com/base/feeds/snippets';
/**
* The default URI for POST methods
*
* @var string
*/
protected $_defaultFeedUri = self::GBASE_ITEM_FEED_URI;
/**
* @param string $value
* @return Zend_Gdata_Gbase_Query Provides a fluent interface
*/
public function setKey($value)
{
if ($value !== null) {
$this->_params['key'] = $value;
} else {
unset($this->_params['key']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setBq($value)
{
if ($value !== null) {
$this->_params['bq'] = $value;
} else {
unset($this->_params['bq']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setRefine($value)
{
if ($value !== null) {
$this->_params['refine'] = $value;
} else {
unset($this->_params['refine']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setContent($value)
{
if ($value !== null) {
$this->_params['content'] = $value;
} else {
unset($this->_params['content']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setOrderBy($value)
{
if ($value !== null) {
$this->_params['orderby'] = $value;
} else {
unset($this->_params['orderby']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setSortOrder($value)
{
if ($value !== null) {
$this->_params['sortorder'] = $value;
} else {
unset($this->_params['sortorder']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setCrowdBy($value)
{
if ($value !== null) {
$this->_params['crowdby'] = $value;
} else {
unset($this->_params['crowdby']);
}
return $this;
}
/**
* @param string $value
* @return Zend_Gdata_Gbase_ItemQuery Provides a fluent interface
*/
public function setAdjust($value)
{
if ($value !== null) {
$this->_params['adjust'] = $value;
} else {
unset($this->_params['adjust']);
}
return $this;
}
/**
* @return string key
*/
public function getKey()
{
if (array_key_exists('key', $this->_params)) {
return $this->_params['key'];
} else {
return null;
}
}
/**
* @return string bq
*/
public function getBq()
{
if (array_key_exists('bq', $this->_params)) {
return $this->_params['bq'];
} else {
return null;
}
}
/**
* @return string refine
*/
public function getRefine()
{
if (array_key_exists('refine', $this->_params)) {
return $this->_params['refine'];
} else {
return null;
}
}
/**
* @return string content
*/
public function getContent()
{
if (array_key_exists('content', $this->_params)) {
return $this->_params['content'];
} else {
return null;
}
}
/**
* @return string orderby
*/
public function getOrderBy()
{
if (array_key_exists('orderby', $this->_params)) {
return $this->_params['orderby'];
} else {
return null;
}
}
/**
* @return string sortorder
*/
public function getSortOrder()
{
if (array_key_exists('sortorder', $this->_params)) {
return $this->_params['sortorder'];
} else {
return null;
}
}
/**
* @return string crowdby
*/
public function getCrowdBy()
{
if (array_key_exists('crowdby', $this->_params)) {
return $this->_params['crowdby'];
} else {
return null;
}
}
/**
* @return string adjust
*/
public function getAdjust()
{
if (array_key_exists('adjust', $this->_params)) {
return $this->_params['adjust'];
} else {
return null;
}
}
}
Gdata/Feed.php 0000604 00000016012 15071256135 0007141 0 ustar 00 <?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_Gdata
* @subpackage Gdata
* @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 Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_App_Feed
*/
require_once 'Zend/Gdata/App/Feed.php';
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_OpenSearchTotalResults
*/
require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
/**
* @see Zend_Gdata_Extension_OpenSearchStartIndex
*/
require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
/**
* @see Zend_Gdata_Extension_OpenSearchItemsPerPage
*/
require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
/**
* The Gdata flavor of an Atom Feed
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @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_Gdata_Feed extends Zend_Gdata_App_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Entry';
/**
* The openSearch:totalResults element
*
* @var string
*/
protected $_totalResults = null;
/**
* The openSearch:startIndex element
*
* @var string
*/
protected $_startIndex = null;
/**
* The openSearch:itemsPerPage element
*
* @var string
*/
protected $_itemsPerPage = null;
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_totalResults != null) {
$element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
}
if ($this->_startIndex != null) {
$element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
}
if ($this->_itemsPerPage != null) {
$element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
}
// ETags are special. We only support them in protocol >= 2.X.
// This will be duplicated by the HTTP ETag header.
if ($majorVersion >= 2) {
if ($this->_etag != null) {
$element->setAttributeNS($this->lookupNamespace('gd'),
'gd:etag',
$this->_etag);
}
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
$totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
$totalResults->transferFromDOM($child);
$this->_totalResults = $totalResults;
break;
case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
$startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
$startIndex->transferFromDOM($child);
$this->_startIndex = $startIndex;
break;
case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
$itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
$itemsPerPage->transferFromDOM($child);
$this->_itemsPerPage = $itemsPerPage;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Given a DOMNode representing an attribute, tries to map the data into
* instance members. If no mapping is defined, the name and value are
* stored in an array.
*
* @param DOMNode $attribute The DOMNode attribute needed to be handled
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'etag':
// ETags are special, since they can be conveyed by either the
// HTTP ETag header or as an XML attribute.
$etag = $attribute->nodeValue;
if (is_null($this->_etag)) {
$this->_etag = $etag;
}
elseif ($this->_etag != $etag) {
require_once('Zend/Gdata/App/IOException.php');
throw new Zend_Gdata_App_IOException("ETag mismatch");
}
break;
default:
parent::takeAttributeFromDOM($attribute);
break;
}
}
/**
* Set the value of the totalResults property.
*
* @param integer $value The value of the totalResults property.
* @return Zend_Gdata_Feed Provides a fluent interface.
*/
function setTotalResults($value) {
$this->_totalResults = $value;
return $this;
}
/**
* Get the value of the totalResults property.
*
* @return integer|null The value of the totalResults property, or null.
*/
function getTotalResults() {
return $this->_totalResults;
}
/**
* Set the start index property for feed paging.
*
* @param integer $value The value for the startIndex property.
* @return Zend_Gdata_Feed Provides a fluent interface.
*/
function setStartIndex($value) {
$this->_startIndex = $value;
return $this;
}
/**
* Get the value of the startIndex property.
*
* @return integer|null The value of the startIndex property, or null.
*/
function getStartIndex() {
return $this->_startIndex;
}
/**
* Set the itemsPerPage property.
*
* @param integer $value The value for the itemsPerPage property.
* @return Zend_Gdata_Feed Provides a fluent interface.
*/
function setItemsPerPage($value) {
$this->_itemsPerPage = $value;
return $this;
}
/**
* Get the value of the itemsPerPage property.
*
* @return integer|null The value of the itemsPerPage property, or null.
*/
function getItemsPerPage() {
return $this->_itemsPerPage;
}
}
Gdata/Spreadsheets.php 0000604 00000034750 15071256135 0010741 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata
*/
require_once('Zend/Gdata.php');
/**
* Zend_Gdata_Spreadsheets_SpreadsheetFeed
*/
require_once('Zend/Gdata/Spreadsheets/SpreadsheetFeed.php');
/**
* Zend_Gdata_Spreadsheets_WorksheetFeed
*/
require_once('Zend/Gdata/Spreadsheets/WorksheetFeed.php');
/**
* Zend_Gdata_Spreadsheets_CellFeed
*/
require_once('Zend/Gdata/Spreadsheets/CellFeed.php');
/**
* Zend_Gdata_Spreadsheets_ListFeed
*/
require_once('Zend/Gdata/Spreadsheets/ListFeed.php');
/**
* Zend_Gdata_Spreadsheets_SpreadsheetEntry
*/
require_once('Zend/Gdata/Spreadsheets/SpreadsheetEntry.php');
/**
* Zend_Gdata_Spreadsheets_WorksheetEntry
*/
require_once('Zend/Gdata/Spreadsheets/WorksheetEntry.php');
/**
* Zend_Gdata_Spreadsheets_CellEntry
*/
require_once('Zend/Gdata/Spreadsheets/CellEntry.php');
/**
* Zend_Gdata_Spreadsheets_ListEntry
*/
require_once('Zend/Gdata/Spreadsheets/ListEntry.php');
/**
* Zend_Gdata_Spreadsheets_DocumentQuery
*/
require_once('Zend/Gdata/Spreadsheets/DocumentQuery.php');
/**
* Zend_Gdata_Spreadsheets_ListQuery
*/
require_once('Zend/Gdata/Spreadsheets/ListQuery.php');
/**
* Zend_Gdata_Spreadsheets_CellQuery
*/
require_once('Zend/Gdata/Spreadsheets/CellQuery.php');
/**
* Gdata Spreadsheets
*
* @link http://code.google.com/apis/gdata/spreadsheets.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets extends Zend_Gdata
{
const SPREADSHEETS_FEED_URI = 'http://spreadsheets.google.com/feeds/spreadsheets';
const SPREADSHEETS_POST_URI = 'http://spreadsheets.google.com/feeds/spreadsheets/private/full';
const WORKSHEETS_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#worksheetsfeed';
const LIST_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#listfeed';
const CELL_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#cellsfeed';
const AUTH_SERVICE_NAME = 'wise';
/**
* Namespaces used for Zend_Gdata_Photos
*
* @var array
*/
public static $namespaces = array(
array('gs', 'http://schemas.google.com/spreadsheets/2006', 1, 0),
array(
'gsx', 'http://schemas.google.com/spreadsheets/2006/extended', 1, 0)
);
/**
* Create Gdata_Spreadsheets object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Spreadsheets');
$this->registerPackage('Zend_Gdata_Spreadsheets_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
$this->_server = 'spreadsheets.google.com';
}
/**
* Gets a spreadsheet feed.
*
* @param mixed $location A DocumentQuery or a string URI specifying the feed location.
* @return Zend_Gdata_Spreadsheets_SpreadsheetFeed
*/
public function getSpreadsheetFeed($location = null)
{
if ($location == null) {
$uri = self::SPREADSHEETS_FEED_URI;
} else if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
if ($location->getDocumentType() == null) {
$location->setDocumentType('spreadsheets');
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_SpreadsheetFeed');
}
/**
* Gets a spreadsheet entry.
*
* @param string $location A DocumentQuery or a URI specifying the entry location.
* @return SpreadsheetEntry
*/
public function getSpreadsheetEntry($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
if ($location->getDocumentType() == null) {
$location->setDocumentType('spreadsheets');
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_SpreadsheetEntry');
}
/**
* Gets a worksheet feed.
*
* @param mixed $location A DocumentQuery, SpreadsheetEntry, or a string URI
* @return Zend_Gdata_Spreadsheets_WorksheetFeed The feed of worksheets
*/
public function getWorksheetFeed($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
if ($location->getDocumentType() == null) {
$location->setDocumentType('worksheets');
}
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Spreadsheets_SpreadsheetEntry) {
$uri = $location->getLink(self::WORKSHEETS_FEED_LINK_URI)->href;
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_WorksheetFeed');
}
/**
* Gets a worksheet entry.
*
* @param string $location A DocumentQuery or a URI specifying the entry location.
* @return WorksheetEntry
*/
public function GetWorksheetEntry($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
if ($location->getDocumentType() == null) {
$location->setDocumentType('worksheets');
}
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_WorksheetEntry');
}
/**
* Gets a cell feed.
*
* @param string $location A CellQuery, WorksheetEntry or a URI specifying the feed location.
* @return CellFeed
*/
public function getCellFeed($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
$uri = $location->getLink(self::CELL_FEED_LINK_URI)->href;
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_CellFeed');
}
/**
* Gets a cell entry.
*
* @param string $location A CellQuery or a URI specifying the entry location.
* @return CellEntry
*/
public function getCellEntry($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_CellEntry');
}
/**
* Gets a list feed.
*
* @param mixed $location A ListQuery, WorksheetEntry or string URI specifying the feed location.
* @return ListFeed
*/
public function getListFeed($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_ListQuery) {
$uri = $location->getQueryUrl();
} else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
$uri = $location->getLink(self::LIST_FEED_LINK_URI)->href;
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_ListFeed');
}
/**
* Gets a list entry.
*
* @param string $location A ListQuery or a URI specifying the entry location.
* @return ListEntry
*/
public function getListEntry($location)
{
if ($location instanceof Zend_Gdata_Spreadsheets_ListQuery) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_ListEntry');
}
/**
* Updates an existing cell.
*
* @param int $row The row containing the cell to update
* @param int $col The column containing the cell to update
* @param int $inputValue The new value for the cell
* @param string $key The key for the spreadsheet to be updated
* @param string $wkshtId (optional) The worksheet to be updated
* @return CellEntry The updated cell entry.
*/
public function updateCell($row, $col, $inputValue, $key, $wkshtId = 'default')
{
$cell = 'R'.$row.'C'.$col;
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($key);
$query->setWorksheetId($wkshtId);
$query->setCellId($cell);
$entry = $this->getCellEntry($query);
$entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
$response = $entry->save();
return $response;
}
/**
* Inserts a new row with provided data.
*
* @param array $rowData An array of column header to row data
* @param string $key The key of the spreadsheet to modify
* @param string $wkshtId (optional) The worksheet to modify
* @return ListEntry The inserted row
*/
public function insertRow($rowData, $key, $wkshtId = 'default')
{
$newEntry = new Zend_Gdata_Spreadsheets_ListEntry();
$newCustomArr = array();
foreach ($rowData as $k => $v) {
$newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom();
$newCustom->setText($v)->setColumnName($k);
$newEntry->addCustom($newCustom);
}
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($key);
$query->setWorksheetId($wkshtId);
$feed = $this->getListFeed($query);
$editLink = $feed->getLink('http://schemas.google.com/g/2005#post');
return $this->insertEntry($newEntry->saveXML(), $editLink->href, 'Zend_Gdata_Spreadsheets_ListEntry');
}
/**
* Updates an existing row with provided data.
*
* @param ListEntry $entry The row entry to update
* @param array $newRowData An array of column header to row data
*/
public function updateRow($entry, $newRowData)
{
$newCustomArr = array();
foreach ($newRowData as $k => $v) {
$newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom();
$newCustom->setText($v)->setColumnName($k);
$newCustomArr[] = $newCustom;
}
$entry->setCustom($newCustomArr);
return $entry->save();
}
/**
* Deletes an existing row .
*
* @param ListEntry $entry The row to delete
*/
public function deleteRow($entry)
{
$entry->delete();
}
/**
* Returns the content of all rows as an associative array
*
* @param mixed $location A ListQuery or string URI specifying the feed location.
* @return array An array of rows. Each element of the array is an associative array of data
*/
public function getSpreadsheetListFeedContents($location)
{
$listFeed = $this->getListFeed($location);
$listFeed = $this->retrieveAllEntriesForFeed($listFeed);
$spreadsheetContents = array();
foreach ($listFeed as $listEntry) {
$rowContents = array();
$customArray = $listEntry->getCustom();
foreach ($customArray as $custom) {
$rowContents[$custom->getColumnName()] = $custom->getText();
}
$spreadsheetContents[] = $rowContents;
}
return $spreadsheetContents;
}
/**
* Returns the content of all cells as an associative array, indexed
* off the cell location (ie 'A1', 'D4', etc). Each element of
* the array is an associative array with a 'value' and a 'function'.
* Only non-empty cells are returned by default. 'range' is the
* value of the 'range' query parameter specified at:
* http://code.google.com/apis/spreadsheets/reference.html#cells_Parameters
*
* @param mixed $location A CellQuery, WorksheetEntry or a URL (w/o query string) specifying the feed location.
* @param string $range The range of cells to retrieve
* @param boolean $empty Whether to retrieve empty cells
* @return array An associative array of cells
*/
public function getSpreadsheetCellFeedContents($location, $range = null, $empty = false)
{
$cellQuery = null;
if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
$cellQuery = $location;
} else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
$url = $location->getLink(self::CELL_FEED_LINK_URI)->href;
$cellQuery = new Zend_Gdata_Spreadsheets_CellQuery($url);
} else {
$url = $location;
$cellQuery = new Zend_Gdata_Spreadsheets_CellQuery($url);
}
if ($range != null) {
$cellQuery->setRange($range);
}
$cellQuery->setReturnEmpty($empty);
$cellFeed = $this->getCellFeed($cellQuery);
$cellFeed = $this->retrieveAllEntriesForFeed($cellFeed);
$spreadsheetContents = array();
foreach ($cellFeed as $cellEntry) {
$cellContents = array();
$cell = $cellEntry->getCell();
$cellContents['formula'] = $cell->getInputValue();
$cellContents['value'] = $cell->getText();
$spreadsheetContents[$cellEntry->getTitle()->getText()] = $cellContents;
}
return $spreadsheetContents;
}
/**
* Alias for getSpreadsheetFeed
*
* @param mixed $location A DocumentQuery or a string URI specifying the feed location.
* @return Zend_Gdata_Spreadsheets_SpreadsheetFeed
*/
public function getSpreadsheets($location = null)
{
return $this->getSpreadsheetFeed($location = null);
}
}
Gdata/Spreadsheets/CellQuery.php 0000604 00000024353 15071256135 0012644 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_util
*/
require_once('Zend/Gdata/App/Util.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Spreadsheets cells
*
* @link http://code.google.com/apis/gdata/spreadsheets/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_CellQuery extends Zend_Gdata_Query
{
const SPREADSHEETS_CELL_FEED_URI = 'http://spreadsheets.google.com/feeds/cells';
protected $_defaultFeedUri = self::SPREADSHEETS_CELL_FEED_URI;
protected $_visibility = 'private';
protected $_projection = 'full';
protected $_spreadsheetKey = null;
protected $_worksheetId = 'default';
protected $_cellId = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_CellQuery object.
*
* @param string $url Base URL to use for queries
*/
public function __construct($url = null)
{
parent::__construct($url);
}
/**
* Sets the spreadsheet key for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setSpreadsheetKey($value)
{
$this->_spreadsheetKey = $value;
return $this;
}
/**
* Gets the spreadsheet key for this query.
*
* @return string spreadsheet key
*/
public function getSpreadsheetKey()
{
return $this->_spreadsheetKey;
}
/**
* Sets the worksheet id for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setWorksheetId($value)
{
$this->_worksheetId = $value;
return $this;
}
/**
* Gets the worksheet id for this query.
*
* @return string worksheet id
*/
public function getWorksheetId()
{
return $this->_worksheetId;
}
/**
* Sets the cell id for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setCellId($value)
{
$this->_cellId = $value;
return $this;
}
/**
* Gets the cell id for this query.
*
* @return string cell id
*/
public function getCellId()
{
return $this->_cellId;
}
/**
* Sets the projection for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* Sets the visibility for this query.
*
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
/**
* Gets the projection for this query.
*
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* Gets the visibility for this query.
*
* @return string visibility
*/
public function getVisibility()
{
return $this->_visibility;
}
/**
* Sets the min-row attribute for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setMinRow($value)
{
if ($value != null) {
$this->_params['min-row'] = $value;
} else {
unset($this->_params['min-row']);
}
return $this;
}
/**
* Gets the min-row attribute for this query.
*
* @return string min-row
*/
public function getMinRow()
{
if (array_key_exists('min-row', $this->_params)) {
return $this->_params['min-row'];
} else {
return null;
}
}
/**
* Sets the max-row attribute for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setMaxRow($value)
{
if ($value != null) {
$this->_params['max-row'] = $value;
} else {
unset($this->_params['max-row']);
}
return $this;
}
/**
* Gets the max-row attribute for this query.
*
* @return string max-row
*/
public function getMaxRow()
{
if (array_key_exists('max-row', $this->_params)) {
return $this->_params['max-row'];
} else {
return null;
}
}
/**
* Sets the min-col attribute for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setMinCol($value)
{
if ($value != null) {
$this->_params['min-col'] = $value;
} else {
unset($this->_params['min-col']);
}
return $this;
}
/**
* Gets the min-col attribute for this query.
*
* @return string min-col
*/
public function getMinCol()
{
if (array_key_exists('min-col', $this->_params)) {
return $this->_params['min-col'];
} else {
return null;
}
}
/**
* Sets the max-col attribute for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setMaxCol($value)
{
if ($value != null) {
$this->_params['max-col'] = $value;
} else {
unset($this->_params['max-col']);
}
return $this;
}
/**
* Gets the max-col attribute for this query.
*
* @return string max-col
*/
public function getMaxCol()
{
if (array_key_exists('max-col', $this->_params)) {
return $this->_params['max-col'];
} else {
return null;
}
}
/**
* Sets the range attribute for this query.
*
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setRange($value)
{
if ($value != null) {
$this->_params['range'] = $value;
} else {
unset($this->_params['range']);
}
return $this;
}
/**
* Gets the range attribute for this query.
*
* @return string range
*/
public function getRange()
{
if (array_key_exists('range', $this->_params)) {
return $this->_params['range'];
} else {
return null;
}
}
/**
* Sets the return-empty attribute for this query.
*
* @param mixed $value String or bool value for whether to return empty cells
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setReturnEmpty($value)
{
if (is_bool($value)) {
$this->_params['return-empty'] = ($value?'true':'false');
} else if ($value != null) {
$this->_params['return-empty'] = $value;
} else {
unset($this->_params['return-empty']);
}
return $this;
}
/**
* Gets the return-empty attribute for this query.
*
* @return string return-empty
*/
public function getReturnEmpty()
{
if (array_key_exists('return-empty', $this->_params)) {
return $this->_params['return-empty'];
} else {
return null;
}
}
/**
* Gets the full query URL for this query.
*
* @return string url
*/
public function getQueryUrl()
{
if ($this->_url == null) {
$uri = $this->_defaultFeedUri;
if ($this->_spreadsheetKey != null) {
$uri .= '/'.$this->_spreadsheetKey;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A spreadsheet key must be provided for cell queries.');
}
if ($this->_worksheetId != null) {
$uri .= '/'.$this->_worksheetId;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A worksheet id must be provided for cell queries.');
}
if ($this->_visibility != null) {
$uri .= '/'.$this->_visibility;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A visibility must be provided for cell queries.');
}
if ($this->_projection != null) {
$uri .= '/'.$this->_projection;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A projection must be provided for cell queries.');
}
if ($this->_cellId != null) {
$uri .= '/'.$this->_cellId;
}
} else {
$uri = $this->_url;
}
$uri .= $this->getQueryString();
return $uri;
}
/**
* Gets the attribute query string for this query.
*
* @return string query string
*/
public function getQueryString()
{
return parent::getQueryString();
}
}
Gdata/Spreadsheets/ListFeed.php 0000604 00000003333 15071256135 0012431 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_ListFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Spreadsheets_ListFeed';
/**
* Constructs a new Zend_Gdata_Spreadsheets_ListFeed object.
* @param DOMElement $element An existing XML element on which to base this new object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
}
Gdata/Spreadsheets/WorksheetEntry.php 0000604 00000013525 15071256135 0013733 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_RowCount
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/RowCount.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_ColCount
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/ColCount.php';
/**
* Concrete class for working with Worksheet entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_WorksheetEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_WorksheetEntry';
protected $_rowCount = null;
protected $_colCount = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_WorksheetEntry object.
*
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_rowCount != null) {
$element->appendChild($this->_rowCount->getDOM($element->ownerDocument));
}
if ($this->_colCount != null) {
$element->appendChild($this->_colCount->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gs') . ':' . 'rowCount';
$rowCount = new Zend_Gdata_Spreadsheets_Extension_RowCount();
$rowCount->transferFromDOM($child);
$this->_rowCount = $rowCount;
break;
case $this->lookupNamespace('gs') . ':' . 'colCount';
$colCount = new Zend_Gdata_Spreadsheets_Extension_ColCount();
$colCount->transferFromDOM($child);
$this->_colCount = $colCount;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Gets the row count for this entry.
*
* @return string The row count for the entry.
*/
public function getRowCount()
{
return $this->_rowCount;
}
/**
* Gets the column count for this entry.
*
* @return string The column count for the entry.
*/
public function getColumnCount()
{
return $this->_colCount;
}
/**
* Sets the row count for this entry.
*
* @param string $rowCount The new row count for the entry.
*/
public function setRowCount($rowCount)
{
$this->_rowCount = $rowCount;
return $this;
}
/**
* Sets the column count for this entry.
*
* @param string $colCount The new column count for the entry.
*/
public function setColumnCount($colCount)
{
$this->_colCount = $colCount;
return $this;
}
/**
* Returns the content of all rows as an associative array
*
* @return array An array of rows. Each element of the array is an associative array of data
*/
public function getContentsAsRows()
{
$service = new Zend_Gdata_Spreadsheets($this->getHttpClient());
return $service->getSpreadsheetListFeedContents($this);
}
/**
* Returns the content of all cells as an associative array, indexed
* off the cell location (ie 'A1', 'D4', etc). Each element of
* the array is an associative array with a 'value' and a 'function'.
* Only non-empty cells are returned by default. 'range' is the
* value of the 'range' query parameter specified at:
* http://code.google.com/apis/spreadsheets/reference.html#cells_Parameters
*
* @param string $range The range of cells to retrieve
* @param boolean $empty Whether to retrieve empty cells
* @return array An associative array of cells
*/
public function getContentsAsCells($range = null, $empty = false)
{
$service = new Zend_Gdata_Spreadsheets($this->getHttpClient());
return $service->getSpreadsheetCellFeedContents($this, $range, $empty);
}
}
Gdata/Spreadsheets/SpreadsheetEntry.php 0000604 00000003555 15071256135 0014231 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* Concrete class for working with Atom entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_SpreadsheetEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_SpreadsheetEntry';
/**
* Constructs a new Zend_Gdata_Spreadsheets_SpreadsheetEntry object.
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
/**
* Returns the worksheets in this spreadsheet
*
* @return Zend_Gdata_Spreadsheets_WorksheetFeed The worksheets
*/
public function getWorksheets()
{
$service = new Zend_Gdata_Spreadsheets($this->getHttpClient());
return $service->getWorksheetFeed($this);
}
}
Gdata/Spreadsheets/Extension/RowCount.php 0000604 00000003324 15071256135 0014466 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Concrete class for working with RowCount elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_Extension_RowCount extends Zend_Gdata_Extension
{
protected $_rootElement = 'rowCount';
protected $_rootNamespace = 'gs';
/**
* Constructs a new Zend_Gdata_Spreadsheets_Extension_RowCount object.
* @param string $text (optional) The text content of the element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/Spreadsheets/Extension/Cell.php 0000604 00000012577 15071256135 0013577 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Concrete class for working with cell elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_Extension_Cell extends Zend_Gdata_Extension
{
protected $_rootElement = 'cell';
protected $_rootNamespace = 'gs';
/**
* The row attribute of this cell
*
* @var string
*/
protected $_row = null;
/**
* The column attribute of this cell
*
* @var string
*/
protected $_col = null;
/**
* The inputValue attribute of this cell
*
* @var string
*/
protected $_inputValue = null;
/**
* The numericValue attribute of this cell
*
* @var string
*/
protected $_numericValue = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_Extension_Cell element.
*
* @param string $text (optional) Text contents of the element.
* @param string $row (optional) Row attribute of the element.
* @param string $col (optional) Column attribute of the element.
* @param string $inputValue (optional) Input value attribute of the element.
* @param string $numericValue (optional) Numeric value attribute of the element.
*/
public function __construct($text = null, $row = null, $col = null, $inputValue = null, $numericValue = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct();
$this->_text = $text;
$this->_row = $row;
$this->_col = $col;
$this->_inputValue = $inputValue;
$this->_numericValue = $numericValue;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
$element->setAttribute('row', $this->_row);
$element->setAttribute('col', $this->_col);
if ($this->_inputValue) $element->setAttribute('inputValue', $this->_inputValue);
if ($this->_numericValue) $element->setAttribute('numericValue', $this->_numericValue);
return $element;
}
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'row':
$this->_row = $attribute->nodeValue;
break;
case 'col':
$this->_col = $attribute->nodeValue;
break;
case 'inputValue':
$this->_inputValue = $attribute->nodeValue;
break;
case 'numericValue':
$this->_numericValue = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Gets the row attribute of the Cell element.
* @return string Row of the Cell.
*/
public function getRow()
{
return $this->_row;
}
/**
* Gets the column attribute of the Cell element.
* @return string Column of the Cell.
*/
public function getColumn()
{
return $this->_col;
}
/**
* Gets the input value attribute of the Cell element.
* @return string Input value of the Cell.
*/
public function getInputValue()
{
return $this->_inputValue;
}
/**
* Gets the numeric value attribute of the Cell element.
* @return string Numeric value of the Cell.
*/
public function getNumericValue()
{
return $this->_numericValue;
}
/**
* Sets the row attribute of the Cell element.
* @param string $row New row of the Cell.
*/
public function setRow($row)
{
$this->_row = $row;
return $this;
}
/**
* Sets the column attribute of the Cell element.
* @param string $col New column of the Cell.
*/
public function setColumn($col)
{
$this->_col = $col;
return $this;
}
/**
* Sets the input value attribute of the Cell element.
* @param string $inputValue New input value of the Cell.
*/
public function setInputValue($inputValue)
{
$this->_inputValue = $inputValue;
return $this;
}
/**
* Sets the numeric value attribute of the Cell element.
* @param string $numericValue New numeric value of the Cell.
*/
public function setNumericValue($numericValue)
{
$this->_numericValue = $numericValue;
}
}
Gdata/Spreadsheets/Extension/ColCount.php 0000604 00000003321 15071256135 0014431 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Concrete class for working with colCount elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_Extension_ColCount extends Zend_Gdata_Extension
{
protected $_rootElement = 'colCount';
protected $_rootNamespace = 'gs';
/**
* Constructs a new Zend_Gdata_Spreadsheets_Extension_ColCount element.
* @param string $text (optional) Text contents of the element.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct();
$this->_text = $text;
}
}
Gdata/Spreadsheets/Extension/Custom.php 0000604 00000005641 15071256135 0014164 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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: Entry.php 3941 2007-03-14 21:36:13Z darby $
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Concrete class for working with custom gsx elements.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_Extension_Custom extends Zend_Gdata_Extension
{
// custom elements have custom names.
protected $_rootElement = null; // The name of the column
protected $_rootNamespace = 'gsx';
/**
* Constructs a new Zend_Gdata_Spreadsheets_Extension_Custom object.
* @param string $column (optional) The column/tag name of the element.
* @param string $value (optional) The text content of the element.
*/
public function __construct($column = null, $value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct();
$this->_text = $value;
$this->_rootElement = $column;
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
return $element;
}
/**
* Transfers each child and attribute into member variables.
* This is called when XML is received over the wire and the data
* model needs to be built to represent this XML.
*
* @param DOMNode $node The DOMNode that represents this object's data
*/
public function transferFromDOM($node)
{
parent::transferFromDOM($node);
$this->_rootElement = $node->localName;
}
/**
* Sets the column/tag name of the element.
* @param string $column The new column name.
*/
public function setColumnName($column)
{
$this->_rootElement = $column;
return $this;
}
/**
* Gets the column name of the element
* @return string The column name.
*/
public function getColumnName()
{
return $this->_rootElement;
}
}
Gdata/Spreadsheets/CellEntry.php 0000604 00000005650 15071256135 0012637 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_Cell
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/Cell.php';
/**
* Concrete class for working with Cell entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_CellEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_CellEntry';
protected $_cell;
/**
* Constructs a new Zend_Gdata_Spreadsheets_CellEntry object.
* @param string $uri (optional)
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_cell != null) {
$element->appendChild($this->_cell->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gs') . ':' . 'cell';
$cell = new Zend_Gdata_Spreadsheets_Extension_Cell();
$cell->transferFromDOM($child);
$this->_cell = $cell;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Gets the Cell element of this Cell Entry.
* @return Zend_Gdata_Spreadsheets_Extension_Cell
*/
public function getCell()
{
return $this->_cell;
}
/**
* Sets the Cell element of this Cell Entry.
* @param $cell Zend_Gdata_Spreadsheets_Extension_Cell $cell
*/
public function setCell($cell)
{
$this->_cell = $cell;
return $this;
}
}
Gdata/Spreadsheets/SpreadsheetFeed.php 0000604 00000003365 15071256135 0013772 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_SpreadsheetFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_SpreadsheetEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Spreadsheets_SpreadsheetFeed';
/**
* Constructs a new Zend_Gdata_Spreadsheets_SpreadsheetFeed object.
* @param DOMElement $element (optional) The DOMElement on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
}
Gdata/Spreadsheets/CellFeed.php 0000604 00000010477 15071256135 0012404 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_RowCount
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/RowCount.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_ColCount
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/ColCount.php';
/**
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_CellFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_CellEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Spreadsheets_CellFeed';
/**
* The row count for the feed.
*
* @var Zend_Gdata_Spreadsheets_Extension_RowCount
*/
protected $_rowCount = null;
/**
* The column count for the feed.
*
* @var Zend_Gdata_Spreadsheets_Extension_ColCount
*/
protected $_colCount = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_CellFeed object.
* @param DOMElement $element (optional) The XML Element on which to base this object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->rowCount != null) {
$element->appendChild($this->_rowCount->getDOM($element->ownerDocument));
}
if ($this->colCount != null) {
$element->appendChild($this->_colCount->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gs') . ':' . 'rowCount';
$rowCount = new Zend_Gdata_Spreadsheets_Extension_RowCount();
$rowCount->transferFromDOM($child);
$this->_rowCount = $rowCount;
break;
case $this->lookupNamespace('gs') . ':' . 'colCount';
$colCount = new Zend_Gdata_Spreadsheets_Extension_ColCount();
$colCount->transferFromDOM($child);
$this->_colCount = $colCount;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Gets the row count for this feed.
* @return string The row count for the feed.
*/
public function getRowCount()
{
return $this->_rowCount;
}
/**
* Gets the column count for this feed.
* @return string The column count for the feed.
*/
public function getColumnCount()
{
return $this->_colCount;
}
/**
* Sets the row count for this feed.
* @param string $rowCount The new row count for the feed.
*/
public function setRowCount($rowCount)
{
$this->_rowCount = $rowCount;
return $this;
}
/**
* Sets the column count for this feed.
* @param string $colCount The new column count for the feed.
*/
public function setColumnCount($colCount)
{
$this->_colCount = $colCount;
return $this;
}
}
Gdata/Spreadsheets/ListQuery.php 0000604 00000017211 15071256135 0012673 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_util
*/
require_once('Zend/Gdata/App/Util.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Spreadsheets lists
*
* @link http://code.google.com/apis/gdata/calendar/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_ListQuery extends Zend_Gdata_Query
{
const SPREADSHEETS_LIST_FEED_URI = 'http://spreadsheets.google.com/feeds/list';
protected $_defaultFeedUri = self::SPREADSHEETS_LIST_FEED_URI;
protected $_visibility = 'private';
protected $_projection = 'full';
protected $_spreadsheetKey = null;
protected $_worksheetId = 'default';
protected $_rowId = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_ListQuery object.
*/
public function __construct()
{
parent::__construct();
}
/**
* Sets the spreadsheet key for the query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setSpreadsheetKey($value)
{
$this->_spreadsheetKey = $value;
return $this;
}
/**
* Gets the spreadsheet key for the query.
* @return string spreadsheet key
*/
public function getSpreadsheetKey()
{
return $this->_spreadsheetKey;
}
/**
* Sets the worksheet id for the query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setWorksheetId($value)
{
$this->_worksheetId = $value;
return $this;
}
/**
* Gets the worksheet id for the query.
* @return string worksheet id
*/
public function getWorksheetId()
{
return $this->_worksheetId;
}
/**
* Sets the row id for the query.
* @param string $value row id
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setRowId($value)
{
$this->_rowId = $value;
return $this;
}
/**
* Gets the row id for the query.
* @return string row id
*/
public function getRowId()
{
return $this->_rowId;
}
/**
* Sets the projection for the query.
* @param string $value Projection
* @return Zend_Gdata_Spreadsheets_ListQuery Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* Sets the visibility for this query.
* @param string $value visibility
* @return Zend_Gdata_Spreadsheets_ListQuery Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
/**
* Gets the projection for this query.
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* Gets the visibility for this query.
* @return string visibility
*/
public function getVisibility()
{
return $this->_visibility;
}
/**
* Sets the spreadsheet key for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setSpreadsheetQuery($value)
{
if ($value != null) {
$this->_params['sq'] = $value;
} else {
unset($this->_params['sq']);
}
return $this;
}
/**
* Gets the spreadsheet key for this query.
* @return string spreadsheet query
*/
public function getSpreadsheetQuery()
{
if (array_key_exists('sq', $this->_params)) {
return $this->_params['sq'];
} else {
return null;
}
}
/**
* Sets the orderby attribute for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setOrderBy($value)
{
if ($value != null) {
$this->_params['orderby'] = $value;
} else {
unset($this->_params['orderby']);
}
return $this;
}
/**
* Gets the orderby attribute for this query.
* @return string orderby
*/
public function getOrderBy()
{
if (array_key_exists('orderby', $this->_params)) {
return $this->_params['orderby'];
} else {
return null;
}
}
/**
* Sets the reverse attribute for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setReverse($value)
{
if ($value != null) {
$this->_params['reverse'] = $value;
} else {
unset($this->_params['reverse']);
}
return $this;
}
/**
* Gets the reverse attribute for this query.
* @return string reverse
*/
public function getReverse()
{
if (array_key_exists('reverse', $this->_params)) {
return $this->_params['reverse'];
} else {
return null;
}
}
/**
* Gets the full query URL for this query.
* @return string url
*/
public function getQueryUrl()
{
$uri = $this->_defaultFeedUri;
if ($this->_spreadsheetKey != null) {
$uri .= '/'.$this->_spreadsheetKey;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A spreadsheet key must be provided for list queries.');
}
if ($this->_worksheetId != null) {
$uri .= '/'.$this->_worksheetId;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A worksheet id must be provided for list queries.');
}
if ($this->_visibility != null) {
$uri .= '/'.$this->_visibility;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A visibility must be provided for list queries.');
}
if ($this->_projection != null) {
$uri .= '/'.$this->_projection;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A projection must be provided for list queries.');
}
if ($this->_rowId != null) {
$uri .= '/'.$this->_rowId;
}
$uri .= $this->getQueryString();
return $uri;
}
/**
* Gets the attribute query string for this query.
* @return string query string
*/
public function getQueryString()
{
return parent::getQueryString();
}
}
Gdata/Spreadsheets/WorksheetFeed.php 0000604 00000003356 15071256135 0013476 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_WorksheetFeed extends Zend_Gdata_Feed
{
/**
* Constructs a new Zend_Gdata_Spreadsheets_WorksheetFeed object.
* @param DOMElement $element (optional) The DOMElement on whick to base this element.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_WorksheetEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Spreadsheets_WorksheetFeed';
}
Gdata/Spreadsheets/ListEntry.php 0000604 00000015540 15071256135 0012672 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Spreadsheets_Extension_Custom
*/
require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
/**
* Concrete class for working with List entries.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
/**
* List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
* indexed by order added to this entry.
* @var array
*/
protected $_custom = array();
/**
* List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
* indexed by element name.
* @var array
*/
protected $_customByName = array();
/**
* Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
* @param DOMElement $element An existing XML element on which to base this new object.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if (!empty($this->_custom)) {
foreach ($this->_custom as $custom) {
$element->appendChild($custom->getDOM($element->ownerDocument));
}
}
return $element;
}
protected function takeChildFromDOM($child)
{
switch ($child->namespaceURI) {
case $this->lookupNamespace('gsx');
$custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName);
$custom->transferFromDOM($child);
$this->addCustom($custom);
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Gets the row elements contained by this list entry.
* @return array The custom row elements in this list entry
*/
public function getCustom()
{
return $this->_custom;
}
/**
* Gets a single row element contained by this list entry using its name.
* @param string $name The name of a custom element to return. If null
* or not defined, an array containing all custom elements
* indexed by name will be returned.
* @return mixed If a name is specified, the
* Zend_Gdata_Spreadsheets_Extension_Custom element requested,
* is returned or null if not found. Otherwise, an array of all
* Zend_Gdata_Spreadsheets_Extension_Custom elements is returned
* indexed by name.
*/
public function getCustomByName($name = null)
{
if ($name === null) {
return $this->_customByName;
} else {
if (array_key_exists($name, $this->customByName)) {
return $this->_customByName[$name];
} else {
return null;
}
}
}
/**
* Sets the row elements contained by this list entry. If any
* custom row elements were previously stored, they will be overwritten.
* @param array $custom The custom row elements to be contained in this
* list entry.
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
*/
public function setCustom($custom)
{
$this->_custom = array();
foreach ($custom as $c) {
$this->addCustom($c);
}
return $this;
}
/**
* Add an individual custom row element to this list entry.
* @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom
* element to be added.
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
*/
public function addCustom($custom)
{
$this->_custom[] = $custom;
$this->_customByName[$custom->getColumnName()] = $custom;
return $this;
}
/**
* Remove an individual row element from this list entry by index. This
* will cause the array to be re-indexed.
* @param int $index The index of the custom element to be deleted.
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function removeCustom($index)
{
if (array_key_exists($index, $this->_custom)) {
$element = $this->_custom[$index];
// Remove element
unset($this->_custom[$index]);
// Re-index the array
$this->_custom = array_values($this->_custom);
// Be sure to delete form both arrays!
$key = array_search($element, $this->_customByName);
unset($this->_customByName[$key]);
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Element does not exist.');
}
return $this;
}
/**
* Remove an individual row element from this list entry by name.
* @param string $name The name of the custom element to be deleted.
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function removeCustomByName($name)
{
if (array_key_exists($name, $this->_customByName)) {
$element = $this->_customByName[$name];
// Remove element
unset($this->_customByName[$name]);
// Be sure to delete from both arrays!
$key = array_search($element, $this->_custom);
unset($this->_custom[$key]);
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Element does not exist.');
}
return $this;
}
}
Gdata/Spreadsheets/DocumentQuery.php 0000604 00000017021 15071256135 0013535 0 ustar 00 <?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_Gdata
* @subpackage Spreadsheets
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_App_util
*/
require_once('Zend/Gdata/App/Util.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Google Spreadsheets documents
*
* @link http://code.google.com/apis/gdata/spreadsheets/
*
* @category Zend
* @package Zend_Gdata
* @subpackage Spreadsheets
* @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_Gdata_Spreadsheets_DocumentQuery extends Zend_Gdata_Query
{
const SPREADSHEETS_FEED_URI = 'http://spreadsheets.google.com/feeds';
protected $_defaultFeedUri = self::SPREADSHEETS_FEED_URI;
protected $_documentType;
protected $_visibility = 'private';
protected $_projection = 'full';
protected $_spreadsheetKey = null;
protected $_worksheetId = null;
/**
* Constructs a new Zend_Gdata_Spreadsheets_DocumentQuery object.
*/
public function __construct()
{
parent::__construct();
}
/**
* Sets the spreadsheet key for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setSpreadsheetKey($value)
{
$this->_spreadsheetKey = $value;
return $this;
}
/**
* Gets the spreadsheet key for this query.
* @return string spreadsheet key
*/
public function getSpreadsheetKey()
{
return $this->_spreadsheetKey;
}
/**
* Sets the worksheet id for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
*/
public function setWorksheetId($value)
{
$this->_worksheetId = $value;
return $this;
}
/**
* Gets the worksheet id for this query.
* @return string worksheet id
*/
public function getWorksheetId()
{
return $this->_worksheetId;
}
/**
* Sets the document type for this query.
* @param string $value spreadsheets or worksheets
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setDocumentType($value)
{
$this->_documentType = $value;
return $this;
}
/**
* Gets the document type for this query.
* @return string document type
*/
public function getDocumentType()
{
return $this->_documentType;
}
/**
* Sets the projection for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* Sets the visibility for this query.
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setVisibility($value)
{
$this->_visibility = $value;
return $this;
}
/**
* Gets the projection for this query.
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* Gets the visibility for this query.
* @return string visibility
*/
public function getVisibility()
{
return $this->_visibility;
}
/**
* Sets the title attribute for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setTitle($value)
{
if ($value != null) {
$this->_params['title'] = $value;
} else {
unset($this->_params['title']);
}
return $this;
}
/**
* Sets the title-exact attribute for this query.
* @param string $value
* @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
*/
public function setTitleExact($value)
{
if ($value != null) {
$this->_params['title-exact'] = $value;
} else {
unset($this->_params['title-exact']);
}
return $this;
}
/**
* Gets the title attribute for this query.
* @return string title
*/
public function getTitle()
{
if (array_key_exists('title', $this->_params)) {
return $this->_params['title'];
} else {
return null;
}
}
/**
* Gets the title-exact attribute for this query.
* @return string title-exact
*/
public function getTitleExact()
{
if (array_key_exists('title-exact', $this->_params)) {
return $this->_params['title-exact'];
} else {
return null;
}
}
private function appendVisibilityProjection()
{
$uri = '';
if ($this->_visibility != null) {
$uri .= '/'.$this->_visibility;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A visibility must be provided for document queries.');
}
if ($this->_projection != null) {
$uri .= '/'.$this->_projection;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A projection must be provided for document queries.');
}
return $uri;
}
/**
* Gets the full query URL for this query.
* @return string url
*/
public function getQueryUrl()
{
$uri = $this->_defaultFeedUri;
if ($this->_documentType != null) {
$uri .= '/'.$this->_documentType;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A document type must be provided for document queries.');
}
if ($this->_documentType == 'spreadsheets') {
$uri .= $this->appendVisibilityProjection();
if ($this->_spreadsheetKey != null) {
$uri .= '/'.$this->_spreadsheetKey;
}
} else if ($this->_documentType == 'worksheets') {
if ($this->_spreadsheetKey != null) {
$uri .= '/'.$this->_spreadsheetKey;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('A spreadsheet key must be provided for worksheet document queries.');
}
$uri .= $this->appendVisibilityProjection();
if ($this->_worksheetId != null) {
$uri .= '/'.$this->_worksheetId;
}
}
$uri .= $this->getQueryString();
return $uri;
}
/**
* Gets the attribute query string for this query.
* @return string query string
*/
public function getQueryString()
{
return parent::getQueryString();
}
}
Gdata/Books/VolumeQuery.php 0000604 00000005701 15071256135 0011653 0 ustar 00 <?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_Gdata
* @subpackage Books
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Gdata_Books
*/
require_once('Zend/Gdata/Books.php');
/**
* Zend_Gdata_Query
*/
require_once('Zend/Gdata/Query.php');
/**
* Assists in constructing queries for Books volumes
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_VolumeQuery extends Zend_Gdata_Query
{
/**
* Create Gdata_Books_VolumeQuery object
*
* @param string|null $url If non-null, pre-initializes the instance to
* use a given URL.
*/
public function __construct($url = null)
{
parent::__construct($url);
}
/**
* Sets the minimum level of viewability of volumes to return in the search results
*
* @param string|null $value The minimum viewability - 'full' or 'partial'
* @return Zend_Gdata_Books_VolumeQuery Provides a fluent interface
*/
public function setMinViewability($value = null)
{
switch ($value) {
case 'full_view':
$this->_params['min-viewability'] = 'full';
break;
case 'partial_view':
$this->_params['min-viewability'] = 'partial';
break;
case null:
unset($this->_params['min-viewability']);
break;
}
return $this;
}
/**
* Minimum viewability of volumes to include in search results
*
* @return string|null min-viewability
*/
public function getMinViewability()
{
if (array_key_exists('min-viewability', $this->_params)) {
return $this->_params['min-viewability'];
} else {
return null;
}
}
/**
* Returns the generated full query URL
*
* @return string The URL
*/
public function getQueryUrl()
{
if (isset($this->_url)) {
$url = $this->_url;
} else {
$url = Zend_Gdata_Books::VOLUME_FEED_URI;
}
if ($this->getCategory() !== null) {
$url .= '/-/' . $this->getCategory();
}
$url = $url . $this->getQueryString();
return $url;
}
}
Gdata/Books/VolumeFeed.php 0000604 00000003242 15071256135 0011407 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Describes a Book Search volume feed
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_VolumeFeed extends Zend_Gdata_Feed
{
/**
* Constructor for Zend_Gdata_Books_VolumeFeed which
* Describes a Book Search volume feed
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($element);
}
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Books_VolumeEntry';
}
Gdata/Books/Extension/BooksCategory.php 0000604 00000003507 15071256135 0014107 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Describes a books category
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_BooksCategory extends
Zend_Gdata_App_Extension_Category
{
/**
* Constructor for Zend_Gdata_Books_Extension_BooksCategory which
* Describes a books category
*
* @param string|null $term An identifier representing the category within
* the categorization scheme.
* @param string|null $scheme A string containing a URI identifying the
* categorization scheme.
* @param string|null $label A human-readable label for display in
* end-user applications.
*/
public function __construct($term = null, $scheme = null, $label = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($term, $scheme, $label);
}
}
Gdata/Books/Extension/PreviewLink.php 0000604 00000003620 15071256135 0013567 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Books_Extension_BooksLink
*/
require_once 'Zend/Gdata/Books/Extension/BooksLink.php';
/**
* Describes a preview link
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_PreviewLink extends
Zend_Gdata_Books_Extension_BooksLink
{
/**
* Constructor for Zend_Gdata_Books_Extension_PreviewLink which
* Describes a preview link
*
* @param string|null $href Linked resource URI
* @param string|null $rel Forward relationship
* @param string|null $type Resource MIME type
* @param string|null $hrefLang Resource language
* @param string|null $title Human-readable resource title
* @param string|null $length Resource length in octets
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
}
}
Gdata/Books/Extension/Viewability.php 0000604 00000006770 15071256135 0013631 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Describes a viewability
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_Viewability extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gbs';
protected $_rootElement = 'viewability';
protected $_value = null;
/**
* Constructor for Zend_Gdata_Books_Extension_Viewability which
* Describes a viewability
*
* @param string|null $value A programmatic value representing the book's
* viewability mode.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves DOMElement which corresponds to this element and all
* child properties. This is used to build this object back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistance.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Extracts XML attributes from the DOM and converts them to the
* appropriate object members.
*
* @param DOMNode $attribute The DOMNode attribute to be handled.
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the programmatic value that describes the viewability of a volume
* in Google Book Search
*
* @return string The value
*/
public function getValue()
{
return $this->_value;
}
/**
* Sets the programmatic value that describes the viewability of a volume in
* Google Book Search
*
* @param string $value programmatic value that describes the viewability
* of a volume in Googl eBook Search
* @return Zend_Gdata_Books_Extension_Viewability Provides a fluent
* interface
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
}
Gdata/Books/Extension/AnnotationLink.php 0000604 00000004025 15071256135 0014260 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Books_Extension_BooksLink
*/
require_once 'Zend/Gdata/Books/Extension/BooksLink.php';
/**
* Describes an annotation link
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_AnnotationLink extends
Zend_Gdata_Books_Extension_BooksLink
{
/**
* Constructor for Zend_Gdata_Books_Extension_AnnotationLink which
* Describes an annotation link
*
* @param string|null $href Linked resource URI
* @param string|null $rel Forward relationship
* @param string|null $type Resource MIME type
* @param string|null $hrefLang Resource language
* @param string|null $title Human-readable resource title
* @param string|null $length Resource length in octets
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
}
}
Gdata/Books/Extension/ThumbnailLink.php 0000604 00000003630 15071256135 0014072 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Books_Extension_BooksLink
*/
require_once 'Zend/Gdata/Books/Extension/BooksLink.php';
/**
* Describes a thumbnail link
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_ThumbnailLink extends
Zend_Gdata_Books_Extension_BooksLink
{
/**
* Constructor for Zend_Gdata_Books_Extension_ThumbnailLink which
* Describes a thumbnail link
*
* @param string|null $href Linked resource URI
* @param string|null $rel Forward relationship
* @param string|null $type Resource MIME type
* @param string|null $hrefLang Resource language
* @param string|null $title Human-readable resource title
* @param string|null $length Resource length in octets
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
}
}
Gdata/Books/Extension/BooksLink.php 0000604 00000003647 15071256135 0013234 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_App_Extension_Link
*/
require_once 'Zend/Gdata/App/Extension/Link.php';
/**
* Extends the base Link class with Books extensions
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_BooksLink extends Zend_Gdata_App_Extension_Link
{
/**
* Constructor for Zend_Gdata_Books_Extension_BooksLink which
* Extends the base Link class with Books extensions
*
* @param string|null $href Linked resource URI
* @param string|null $rel Forward relationship
* @param string|null $type Resource MIME type
* @param string|null $hrefLang Resource language
* @param string|null $title Human-readable resource title
* @param string|null $length Resource length in octets
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
}
}
Gdata/Books/Extension/InfoLink.php 0000604 00000003606 15071256135 0013045 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Books_Extension_BooksLink
*/
require_once 'Zend/Gdata/Books/Extension/BooksLink.php';
/**
* Describes an info link
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_InfoLink extends
Zend_Gdata_Books_Extension_BooksLink
{
/**
* Constructor for Zend_Gdata_Books_Extension_InfoLink which
* Describes an info link
*
* @param string|null $href Linked resource URI
* @param string|null $rel Forward relationship
* @param string|null $type Resource MIME type
* @param string|null $hrefLang Resource language
* @param string|null $title Human-readable resource title
* @param string|null $length Resource length in octets
*/
public function __construct($href = null, $rel = null, $type = null,
$hrefLang = null, $title = null, $length = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($href, $rel, $type, $hrefLang, $title, $length);
}
}
Gdata/Books/Extension/Review.php 0000604 00000010316 15071256135 0012571 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* User-provided review
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_Review extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gbs';
protected $_rootElement = 'review';
protected $_lang = null;
protected $_type = null;
/**
* Constructor for Zend_Gdata_Books_Extension_Review which
* User-provided review
*
* @param string|null $lang Review language.
* @param string|null $type Type of text construct (typically text, html,
* or xhtml).
* @param string|null $value Text content of the review.
*/
public function __construct($lang = null, $type = null, $value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct();
$this->_lang = $lang;
$this->_type = $type;
$this->_text = $value;
}
/**
* Retrieves DOMElement which corresponds to this element and all
* child properties. This is used to build this object back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistance.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc);
if ($this->_lang !== null) {
$element->setAttribute('lang', $this->_lang);
}
if ($this->_type !== null) {
$element->setAttribute('type', $this->_type);
}
return $element;
}
/**
* Extracts XML attributes from the DOM and converts them to the
* appropriate object members.
*
* @param DOMNode $attribute The DOMNode attribute to be handled.
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'lang':
$this->_lang = $attribute->nodeValue;
break;
case 'type':
$this->_type = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the language of link title
*
* @return string The lang
*/
public function getLang()
{
return $this->_lang;
}
/**
* Returns the type of text construct (typically 'text', 'html' or 'xhtml')
*
* @return string The type
*/
public function getType()
{
return $this->_type;
}
/**
* Sets the language of link title
*
* @param string $lang language of link title
* @return Zend_Gdata_Books_Extension_Review Provides a fluent interface
*/
public function setLang($lang)
{
$this->_lang = $lang;
return $this;
}
/**
* Sets the type of text construct (typically 'text', 'html' or 'xhtml')
*
* @param string $type type of text construct (typically 'text', 'html' or 'xhtml')
* @return Zend_Gdata_Books_Extension_Review Provides a fluent interface
*/
public function setType($type)
{
$this->_type = $type;
return $this;
}
}
Gdata/Books/Extension/Embeddability.php 0000604 00000007026 15071256135 0014072 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* Describes an embeddability
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_Extension_Embeddability extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gbs';
protected $_rootElement = 'embeddability';
protected $_value = null;
/**
* Constructor for Zend_Gdata_Books_Extension_Embeddability which
* Describes an embeddability.
*
* @param string|null $value A programmatic value representing the book's
* embeddability.
*/
public function __construct($value = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct();
$this->_value = $value;
}
/**
* Retrieves DOMElement which corresponds to this element and all
* child properties. This is used to build this object back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistance.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc);
if ($this->_value !== null) {
$element->setAttribute('value', $this->_value);
}
return $element;
}
/**
* Extracts XML attributes from the DOM and converts them to the
* appropriate object members.
*
* @param DOMNode $attribute The DOMNode attribute to be handled.
*/
protected function takeAttributeFromDOM($attribute)
{
switch ($attribute->localName) {
case 'value':
$this->_value = $attribute->nodeValue;
break;
default:
parent::takeAttributeFromDOM($attribute);
}
}
/**
* Returns the programmatic value that describes the embeddability of a
* volume in Google Book Search
*
* @return string|null The value
*/
public function getValue()
{
return $this->_value;
}
/**
* Sets the programmatic value that describes the embeddability of a
* volume in Google Book Search
*
* @param string|null $value Programmatic value that describes the
* embeddability of a volume in Google Book Search
* @return Zend_Gdata_Books_Extension_Embeddability Provides a fluent
* interface
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
}
Gdata/Books/VolumeEntry.php 0000604 00000045563 15071256135 0011661 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Extension_Comments
*/
require_once 'Zend/Gdata/Extension/Comments.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Creator
*/
require_once 'Zend/Gdata/DublinCore/Extension/Creator.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Date
*/
require_once 'Zend/Gdata/DublinCore/Extension/Date.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Description
*/
require_once 'Zend/Gdata/DublinCore/Extension/Description.php';
/**
* @see Zend_Gdata_Books_Extension_Embeddability
*/
require_once 'Zend/Gdata/Books/Extension/Embeddability.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Format
*/
require_once 'Zend/Gdata/DublinCore/Extension/Format.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Identifier
*/
require_once 'Zend/Gdata/DublinCore/Extension/Identifier.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Language
*/
require_once 'Zend/Gdata/DublinCore/Extension/Language.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Publisher
*/
require_once 'Zend/Gdata/DublinCore/Extension/Publisher.php';
/**
* @see Zend_Gdata_Extension_Rating
*/
require_once 'Zend/Gdata/Extension/Rating.php';
/**
* @see Zend_Gdata_Books_Extension_Review
*/
require_once 'Zend/Gdata/Books/Extension/Review.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Subject
*/
require_once 'Zend/Gdata/DublinCore/Extension/Subject.php';
/**
* @see Zend_Gdata_DublinCore_Extension_Title
*/
require_once 'Zend/Gdata/DublinCore/Extension/Title.php';
/**
* @see Zend_Gdata_Books_Extension_Viewability
*/
require_once 'Zend/Gdata/Books/Extension/Viewability.php';
/**
* Describes an entry in a feed of Book Search volumes
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_VolumeEntry extends Zend_Gdata_Entry
{
const THUMBNAIL_LINK_REL = 'http://schemas.google.com/books/2008/thumbnail';
const PREVIEW_LINK_REL = 'http://schemas.google.com/books/2008/preview';
const INFO_LINK_REL = 'http://schemas.google.com/books/2008/info';
const ANNOTATION_LINK_REL = 'http://schemas.google.com/books/2008/annotation';
protected $_comments = null;
protected $_creators = array();
protected $_dates = array();
protected $_descriptions = array();
protected $_embeddability = null;
protected $_formats = array();
protected $_identifiers = array();
protected $_languages = array();
protected $_publishers = array();
protected $_rating = null;
protected $_review = null;
protected $_subjects = array();
protected $_titles = array();
protected $_viewability = null;
/**
* Constructor for Zend_Gdata_Books_VolumeEntry which
* Describes an entry in a feed of Book Search volumes
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($element);
}
/**
* Retrieves DOMElement which corresponds to this element and all
* child properties. This is used to build this object back into a DOM
* and eventually XML text for sending to the server upon updates, or
* for application storage/persistance.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc);
if ($this->_creators !== null) {
foreach ($this->_creators as $creators) {
$element->appendChild($creators->getDOM(
$element->ownerDocument));
}
}
if ($this->_dates !== null) {
foreach ($this->_dates as $dates) {
$element->appendChild($dates->getDOM($element->ownerDocument));
}
}
if ($this->_descriptions !== null) {
foreach ($this->_descriptions as $descriptions) {
$element->appendChild($descriptions->getDOM(
$element->ownerDocument));
}
}
if ($this->_formats !== null) {
foreach ($this->_formats as $formats) {
$element->appendChild($formats->getDOM(
$element->ownerDocument));
}
}
if ($this->_identifiers !== null) {
foreach ($this->_identifiers as $identifiers) {
$element->appendChild($identifiers->getDOM(
$element->ownerDocument));
}
}
if ($this->_languages !== null) {
foreach ($this->_languages as $languages) {
$element->appendChild($languages->getDOM(
$element->ownerDocument));
}
}
if ($this->_publishers !== null) {
foreach ($this->_publishers as $publishers) {
$element->appendChild($publishers->getDOM(
$element->ownerDocument));
}
}
if ($this->_subjects !== null) {
foreach ($this->_subjects as $subjects) {
$element->appendChild($subjects->getDOM(
$element->ownerDocument));
}
}
if ($this->_titles !== null) {
foreach ($this->_titles as $titles) {
$element->appendChild($titles->getDOM($element->ownerDocument));
}
}
if ($this->_comments !== null) {
$element->appendChild($this->_comments->getDOM(
$element->ownerDocument));
}
if ($this->_embeddability !== null) {
$element->appendChild($this->_embeddability->getDOM(
$element->ownerDocument));
}
if ($this->_rating !== null) {
$element->appendChild($this->_rating->getDOM(
$element->ownerDocument));
}
if ($this->_review !== null) {
$element->appendChild($this->_review->getDOM(
$element->ownerDocument));
}
if ($this->_viewability !== null) {
$element->appendChild($this->_viewability->getDOM(
$element->ownerDocument));
}
return $element;
}
/**
* Creates individual objects of the appropriate type and stores
* them in this object based upon DOM data.
*
* @param DOMNode $child The DOMNode to process.
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('dc') . ':' . 'creator':
$creators = new Zend_Gdata_DublinCore_Extension_Creator();
$creators->transferFromDOM($child);
$this->_creators[] = $creators;
break;
case $this->lookupNamespace('dc') . ':' . 'date':
$dates = new Zend_Gdata_DublinCore_Extension_Date();
$dates->transferFromDOM($child);
$this->_dates[] = $dates;
break;
case $this->lookupNamespace('dc') . ':' . 'description':
$descriptions = new Zend_Gdata_DublinCore_Extension_Description();
$descriptions->transferFromDOM($child);
$this->_descriptions[] = $descriptions;
break;
case $this->lookupNamespace('dc') . ':' . 'format':
$formats = new Zend_Gdata_DublinCore_Extension_Format();
$formats->transferFromDOM($child);
$this->_formats[] = $formats;
break;
case $this->lookupNamespace('dc') . ':' . 'identifier':
$identifiers = new Zend_Gdata_DublinCore_Extension_Identifier();
$identifiers->transferFromDOM($child);
$this->_identifiers[] = $identifiers;
break;
case $this->lookupNamespace('dc') . ':' . 'language':
$languages = new Zend_Gdata_DublinCore_Extension_Language();
$languages->transferFromDOM($child);
$this->_languages[] = $languages;
break;
case $this->lookupNamespace('dc') . ':' . 'publisher':
$publishers = new Zend_Gdata_DublinCore_Extension_Publisher();
$publishers->transferFromDOM($child);
$this->_publishers[] = $publishers;
break;
case $this->lookupNamespace('dc') . ':' . 'subject':
$subjects = new Zend_Gdata_DublinCore_Extension_Subject();
$subjects->transferFromDOM($child);
$this->_subjects[] = $subjects;
break;
case $this->lookupNamespace('dc') . ':' . 'title':
$titles = new Zend_Gdata_DublinCore_Extension_Title();
$titles->transferFromDOM($child);
$this->_titles[] = $titles;
break;
case $this->lookupNamespace('gd') . ':' . 'comments':
$comments = new Zend_Gdata_Extension_Comments();
$comments->transferFromDOM($child);
$this->_comments = $comments;
break;
case $this->lookupNamespace('gbs') . ':' . 'embeddability':
$embeddability = new Zend_Gdata_Books_Extension_Embeddability();
$embeddability->transferFromDOM($child);
$this->_embeddability = $embeddability;
break;
case $this->lookupNamespace('gd') . ':' . 'rating':
$rating = new Zend_Gdata_Extension_Rating();
$rating->transferFromDOM($child);
$this->_rating = $rating;
break;
case $this->lookupNamespace('gbs') . ':' . 'review':
$review = new Zend_Gdata_Books_Extension_Review();
$review->transferFromDOM($child);
$this->_review = $review;
break;
case $this->lookupNamespace('gbs') . ':' . 'viewability':
$viewability = new Zend_Gdata_Books_Extension_Viewability();
$viewability->transferFromDOM($child);
$this->_viewability = $viewability;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Returns the Comments class
*
* @return Zend_Gdata_Extension_Comments|null The comments
*/
public function getComments()
{
return $this->_comments;
}
/**
* Returns the creators
*
* @return array The creators
*/
public function getCreators()
{
return $this->_creators;
}
/**
* Returns the dates
*
* @return array The dates
*/
public function getDates()
{
return $this->_dates;
}
/**
* Returns the descriptions
*
* @return array The descriptions
*/
public function getDescriptions()
{
return $this->_descriptions;
}
/**
* Returns the embeddability
*
* @return Zend_Gdata_Books_Extension_Embeddability|null The embeddability
*/
public function getEmbeddability()
{
return $this->_embeddability;
}
/**
* Returns the formats
*
* @return array The formats
*/
public function getFormats()
{
return $this->_formats;
}
/**
* Returns the identifiers
*
* @return array The identifiers
*/
public function getIdentifiers()
{
return $this->_identifiers;
}
/**
* Returns the languages
*
* @return array The languages
*/
public function getLanguages()
{
return $this->_languages;
}
/**
* Returns the publishers
*
* @return array The publishers
*/
public function getPublishers()
{
return $this->_publishers;
}
/**
* Returns the rating
*
* @return Zend_Gdata_Extension_Rating|null The rating
*/
public function getRating()
{
return $this->_rating;
}
/**
* Returns the review
*
* @return Zend_Gdata_Books_Extension_Review|null The review
*/
public function getReview()
{
return $this->_review;
}
/**
* Returns the subjects
*
* @return array The subjects
*/
public function getSubjects()
{
return $this->_subjects;
}
/**
* Returns the titles
*
* @return array The titles
*/
public function getTitles()
{
return $this->_titles;
}
/**
* Returns the viewability
*
* @return Zend_Gdata_Books_Extension_Viewability|null The viewability
*/
public function getViewability()
{
return $this->_viewability;
}
/**
* Sets the Comments class
*
* @param Zend_Gdata_Extension_Comments|null $comments Comments class
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setComments($comments)
{
$this->_comments = $comments;
return $this;
}
/**
* Sets the creators
*
* @param array $creators Creators|null
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setCreators($creators)
{
$this->_creators = $creators;
return $this;
}
/**
* Sets the dates
*
* @param array $dates dates
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setDates($dates)
{
$this->_dates = $dates;
return $this;
}
/**
* Sets the descriptions
*
* @param array $descriptions descriptions
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setDescriptions($descriptions)
{
$this->_descriptions = $descriptions;
return $this;
}
/**
* Sets the embeddability
*
* @param Zend_Gdata_Books_Extension_Embeddability|null $embeddability
* embeddability
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setEmbeddability($embeddability)
{
$this->_embeddability = $embeddability;
return $this;
}
/**
* Sets the formats
*
* @param array $formats formats
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setFormats($formats)
{
$this->_formats = $formats;
return $this;
}
/**
* Sets the identifiers
*
* @param array $identifiers identifiers
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setIdentifiers($identifiers)
{
$this->_identifiers = $identifiers;
return $this;
}
/**
* Sets the languages
*
* @param array $languages languages
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setLanguages($languages)
{
$this->_languages = $languages;
return $this;
}
/**
* Sets the publishers
*
* @param array $publishers publishers
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setPublishers($publishers)
{
$this->_publishers = $publishers;
return $this;
}
/**
* Sets the rating
*
* @param Zend_Gdata_Extension_Rating|null $rating rating
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setRating($rating)
{
$this->_rating = $rating;
return $this;
}
/**
* Sets the review
*
* @param Zend_Gdata_Books_Extension_Review|null $review review
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setReview($review)
{
$this->_review = $review;
return $this;
}
/**
* Sets the subjects
*
* @param array $subjects subjects
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setSubjects($subjects)
{
$this->_subjects = $subjects;
return $this;
}
/**
* Sets the titles
*
* @param array $titles titles
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setTitles($titles)
{
$this->_titles = $titles;
return $this;
}
/**
* Sets the viewability
*
* @param Zend_Gdata_Books_Extension_Viewability|null $viewability
* viewability
* @return Zend_Gdata_Books_VolumeEntry Provides a fluent interface
*/
public function setViewability($viewability)
{
$this->_viewability = $viewability;
return $this;
}
/**
* Gets the volume ID based upon the atom:id value
*
* @return string The volume ID
* @throws Zend_Gdata_App_Exception
*/
public function getVolumeId()
{
$fullId = $this->getId()->getText();
$position = strrpos($fullId, '/');
if ($position === false) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Slash not found in atom:id');
} else {
return substr($fullId, strrpos($fullId,'/') + 1);
}
}
/**
* Gets the thumbnail link
*
* @return Zend_Gdata_App_Extension_link|null The thumbnail link
*/
public function getThumbnailLink()
{
return $this->getLink(self::THUMBNAIL_LINK_REL);
}
/**
* Gets the preview link
*
* @return Zend_Gdata_App_Extension_Link|null The preview link
*/
public function getPreviewLink()
{
return $this->getLink(self::PREVIEW_LINK_REL);
}
/**
* Gets the info link
*
* @return Zend_Gdata_App_Extension_Link|null The info link
*/
public function getInfoLink()
{
return $this->getLink(self::INFO_LINK_REL);
}
/**
* Gets the annotations link
*
* @return Zend_Gdata_App_Extension_Link|null The annotations link
*/
public function getAnnotationLink()
{
return $this->getLink(self::ANNOTATION_LINK_REL);
}
}
Gdata/Books/CollectionFeed.php 0000604 00000003260 15071256135 0012233 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* Describes a Book Search collection feed
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_CollectionFeed extends Zend_Gdata_Feed
{
/**
* Constructor for Zend_Gdata_Books_CollectionFeed which
* Describes a Book Search collection feed
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($element);
}
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Books_CollectionEntry';
}
Gdata/Books/CollectionEntry.php 0000604 00000003033 15071256135 0012467 0 ustar 00 <?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_Gdata
* @subpackage Books
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* Describes an entry in a feed of collections
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books_CollectionEntry extends Zend_Gdata_Entry
{
/**
* Constructor for Zend_Gdata_Books_CollectionEntry which
* Describes an entry in a feed of collections
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
parent::__construct($element);
}
}
Gdata/Books.php 0000604 00000014114 15071256135 0007354 0 ustar 00 <?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_Gdata
* @subpackage Books
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_DublinCore
*/
require_once 'Zend/Gdata/DublinCore.php';
/**
* @see Zend_Gdata_Books_CollectionEntry
*/
require_once 'Zend/Gdata/Books/CollectionEntry.php';
/**
* @see Zend_Gdata_Books_CollectionFeed
*/
require_once 'Zend/Gdata/Books/CollectionFeed.php';
/**
* @see Zend_Gdata_Books_VolumeEntry
*/
require_once 'Zend/Gdata/Books/VolumeEntry.php';
/**
* @see Zend_Gdata_Books_VolumeFeed
*/
require_once 'Zend/Gdata/Books/VolumeFeed.php';
/**
* Service class for interacting with the Books service
*
* @category Zend
* @package Zend_Gdata
* @subpackage Books
* @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_Gdata_Books extends Zend_Gdata
{
const VOLUME_FEED_URI = 'http://books.google.com/books/feeds/volumes';
const MY_LIBRARY_FEED_URI = 'http://books.google.com/books/feeds/users/me/collections/library/volumes';
const MY_ANNOTATION_FEED_URI = 'http://books.google.com/books/feeds/users/me/volumes';
const AUTH_SERVICE_NAME = 'print';
/**
* Namespaces used for Zend_Gdata_Books
*
* @var array
*/
public static $namespaces = array(
array('gbs', 'http://schemas.google.com/books/2008', 1, 0),
array('dc', 'http://purl.org/dc/terms', 1, 0)
);
/**
* Create Zend_Gdata_Books object
*
* @param Zend_Http_Client $client (optional) The HTTP client to use when
* when communicating with the Google servers.
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Books');
$this->registerPackage('Zend_Gdata_Books_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Retrieves a feed of volumes.
*
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
* query or a Zend_Gdata_Query object from which a URL can be
* determined.
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
* specified URL.
*/
public function getVolumeFeed($location = null)
{
if ($location == null) {
$uri = self::VOLUME_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
}
/**
* Retrieves a specific volume entry.
*
* @param string|null $volumeId The volumeId of interest.
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
* query or a Zend_Gdata_Query object from which a URL can be
* determined.
* @return Zend_Gdata_Books_VolumeEntry The feed of volumes found at the
* specified URL.
*/
public function getVolumeEntry($volumeId = null, $location = null)
{
if ($volumeId !== null) {
$uri = self::VOLUME_FEED_URI . "/" . $volumeId;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Books_VolumeEntry');
}
/**
* Retrieves a feed of volumes, by default the User library feed.
*
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
* query.
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
* specified URL.
*/
public function getUserLibraryFeed($location = null)
{
if ($location == null) {
$uri = self::MY_LIBRARY_FEED_URI;
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
}
/**
* Retrieves a feed of volumes, by default the User annotation feed
*
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
* query.
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
* specified URL.
*/
public function getUserAnnotationFeed($location = null)
{
if ($location == null) {
$uri = self::MY_ANNOTATION_FEED_URI;
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
}
/**
* Insert a Volume / Annotation
*
* @param Zend_Gdata_Books_VolumeEntry $entry
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
* query
* @return Zend_Gdata_Books_VolumeEntry The inserted volume entry.
*/
public function insertVolume($entry, $location = null)
{
if ($location == null) {
$uri = self::MY_LIBRARY_FEED_URI;
} else {
$uri = $location;
}
return parent::insertEntry(
$entry, $uri, 'Zend_Gdata_Books_VolumeEntry');
}
/**
* Delete a Volume
*
* @param Zend_Gdata_Books_VolumeEntry $entry
* @return void
*/
public function deleteVolume($entry)
{
$entry->delete();
}
}
Gdata/Photos/UserQuery.php 0000604 00000023466 15071256135 0011531 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Gapps_Query
*/
require_once('Zend/Gdata/Gapps/Query.php');
/**
* Assists in constructing queries for user entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the
* service class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_UserQuery extends Zend_Gdata_Query
{
/**
* Indicates the format of data returned in Atom feeds. Can be either
* 'api' or 'base'. Default value is 'api'.
*
* @var string
*/
protected $_projection = 'api';
/**
* Indicates whether to request a feed or entry in queries. Default
* value is 'feed';
*
* @var string
*/
protected $_type = 'feed';
/**
* A string which, if not null, indicates which user should
* be retrieved by this query. If null, the default user will be used
* instead.
*
* @var string
*/
protected $_user = Zend_Gdata_Photos::DEFAULT_USER;
/**
* Create a new Query object with default values.
*/
public function __construct()
{
parent::__construct();
}
/**
* Set's the format of data returned in Atom feeds. Can be either
* 'api' or 'base'. Normally, 'api' will be desired. Default is 'api'.
*
* @param string $value
* @return Zend_Gdata_Photos_UserQuery Provides a fluent interface
*/
public function setProjection($value)
{
$this->_projection = $value;
return $this;
}
/**
* Gets the format of data in returned in Atom feeds.
*
* @see setProjection
* @return string projection
*/
public function getProjection()
{
return $this->_projection;
}
/**
* Set's the type of data returned in queries. Can be either
* 'feed' or 'entry'. Normally, 'feed' will be desired. Default is 'feed'.
*
* @param string $value
* @return Zend_Gdata_Photos_UserQuery Provides a fluent interface
*/
public function setType($value)
{
$this->_type = $value;
return $this;
}
/**
* Gets the type of data in returned in queries.
*
* @see setType
* @return string type
*/
public function getType()
{
return $this->_type;
}
/**
* Set the user to query for. When set, this user's feed will be
* returned. If not set or null, the default user's feed will be returned
* instead.
*
* @param string $value The user to retrieve, or null for the default
* user.
*/
public function setUser($value)
{
if ($value !== null) {
$this->_user = $value;
} else {
$this->_user = Zend_Gdata_Photos::DEFAULT_USER;
}
}
/**
* Get the user which is to be returned.
*
* @see setUser
* @return string The visibility to retrieve.
*/
public function getUser()
{
return $this->_user;
}
/**
* Set the visibility filter for entries returned. Only entries which
* match this value will be returned. If null or unset, the default
* value will be used instead.
*
* Valid values are 'all' (default), 'public', and 'private'.
*
* @param string $value The visibility to filter by, or null to use the
* default value.
*/
public function setAccess($value)
{
if ($value !== null) {
$this->_params['access'] = $value;
} else {
unset($this->_params['access']);
}
}
/**
* Get the visibility filter for entries returned.
*
* @see setAccess
* @return string The visibility to filter by, or null for the default
* user.
*/
public function getAccess()
{
return $this->_params['access'];
}
/**
* Set the tag for entries that are returned. Only entries which
* match this value will be returned. If null or unset, this filter will
* not be applied.
*
* See http://code.google.com/apis/picasaweb/reference.html#Parameters
* for a list of valid values.
*
* @param string $value The tag to filter by, or null if no
* filter is to be applied.
*/
public function setTag($value)
{
if ($value !== null) {
$this->_params['tag'] = $value;
} else {
unset($this->_params['tag']);
}
}
/**
* Get the tag filter for entries returned.
*
* @see setTag
* @return string The tag to filter by, or null if no filter
* is to be applied.
*/
public function getTag()
{
return $this->_params['tag'];
}
/**
* Set the kind of entries that are returned. Only entries which
* match this value will be returned. If null or unset, this filter will
* not be applied.
*
* See http://code.google.com/apis/picasaweb/reference.html#Parameters
* for a list of valid values.
*
* @param string $value The kind to filter by, or null if no
* filter is to be applied.
*/
public function setKind($value)
{
if ($value !== null) {
$this->_params['kind'] = $value;
} else {
unset($this->_params['kind']);
}
}
/**
* Get the kind of entries to be returned.
*
* @see setKind
* @return string The kind to filter by, or null if no filter
* is to be applied.
*/
public function getKind()
{
return $this->_params['kind'];
}
/**
* Set the maximum image size for entries returned. Only entries which
* match this value will be returned. If null or unset, this filter will
* not be applied.
*
* See http://code.google.com/apis/picasaweb/reference.html#Parameters
* for a list of valid values.
*
* @param string $value The image size to filter by, or null if no
* filter is to be applied.
*/
public function setImgMax($value)
{
if ($value !== null) {
$this->_params['imgmax'] = $value;
} else {
unset($this->_params['imgmax']);
}
}
/**
* Get the maximum image size filter for entries returned.
*
* @see setImgMax
* @return string The image size size to filter by, or null if no filter
* is to be applied.
*/
public function getImgMax()
{
return $this->_params['imgmax'];
}
/**
* Set the thumbnail size filter for entries returned. Only entries which
* match this value will be returned. If null or unset, this filter will
* not be applied.
*
* See http://code.google.com/apis/picasaweb/reference.html#Parameters
* for a list of valid values.
*
* @param string $value The thumbnail size to filter by, or null if no
* filter is to be applied.
*/
public function setThumbsize($value)
{
if ($value !== null) {
$this->_params['thumbsize'] = $value;
} else {
unset($this->_params['thumbsize']);
}
}
/**
* Get the thumbnail size filter for entries returned.
*
* @see setThumbsize
* @return string The thumbnail size to filter by, or null if no filter
* is to be applied.
*/
public function getThumbsize()
{
return $this->_params['thumbsize'];
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getQueryUrl($incomingUri = null)
{
$uri = Zend_Gdata_Photos::PICASA_BASE_URI;
if ($this->getType() !== null) {
$uri .= '/' . $this->getType();
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Type must be feed or entry, not null');
}
if ($this->getProjection() !== null) {
$uri .= '/' . $this->getProjection();
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Projection must not be null');
}
if ($this->getUser() !== null) {
$uri .= '/user/' . $this->getUser();
} else {
// Should never occur due to setter behavior
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'User must not be null');
}
$uri .= $incomingUri;
$uri .= $this->getQueryString();
return $uri;
}
}
Gdata/Photos/AlbumQuery.php 0000604 00000010772 15071256135 0011647 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Photos_UserQuery
*/
require_once('Zend/Gdata/Photos/UserQuery.php');
/**
* Assists in constructing album queries for various entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the service
* class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_AlbumQuery extends Zend_Gdata_Photos_UserQuery
{
/**
* The name of the album to query for. Mutually exclusive with AlbumId.
*
* @var string
*/
protected $_albumName = null;
/**
* The ID of the album to query for. Mutually exclusive with AlbumName.
*
* @var string
*/
protected $_albumId = null;
/**
* Set the album name to query for. When set, this album's photographs
* be returned. If not set or null, the default user's feed will be
* returned instead.
*
* NOTE: AlbumName and AlbumId are mutually exclusive. Setting one will
* automatically set the other to null.
*
* @param string $value The name of the album to retrieve, or null to
* clear.
* @return Zend_Gdata_Photos_AlbumQuery The query object.
*/
public function setAlbumName($value)
{
$this->_albumId = null;
$this->_albumName = $value;
return $this;
}
/**
* Get the album name which is to be returned.
*
* @see setAlbumName
* @return string The name of the album to retrieve.
*/
public function getAlbumName()
{
return $this->_albumName;
}
/**
* Set the album ID to query for. When set, this album's photographs
* be returned. If not set or null, the default user's feed will be
* returned instead.
*
* NOTE: Album and AlbumId are mutually exclusive. Setting one will
* automatically set the other to null.
*
* @param string $value The ID of the album to retrieve, or null to
* clear.
* @return Zend_Gdata_Photos_AlbumQuery The query object.
*/
public function setAlbumId($value)
{
$this->_albumName = null;
$this->_albumId = $value;
return $this;
}
/**
* Get the album ID which is to be returned.
*
* @see setAlbum
* @return string The ID of the album to retrieve.
*/
public function getAlbumId()
{
return $this->_albumId;
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getQueryUrl($incomingUri = '')
{
$uri = '';
if ($this->getAlbumName() !== null && $this->getAlbumId() === null) {
$uri .= '/album/' . $this->getAlbumName();
} elseif ($this->getAlbumName() === null && $this->getAlbumId() !== null) {
$uri .= '/albumid/' . $this->getAlbumId();
} elseif ($this->getAlbumName() !== null && $this->getAlbumId() !== null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'AlbumName and AlbumId cannot both be non-null');
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'AlbumName and AlbumId cannot both be null');
}
$uri .= $incomingUri;
return parent::getQueryUrl($uri);
}
}
Gdata/Photos/CommentEntry.php 0000604 00000013364 15071256135 0012205 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Photos_Extension_Id
*/
require_once 'Zend/Gdata/Photos/Extension/Id.php';
/**
* @see Zend_Gdata_Photos_Extension_PhotoId
*/
require_once 'Zend/Gdata/Photos/Extension/PhotoId.php';
/**
* @see Zend_Gdata_Photos_Extension_Weight
*/
require_once 'Zend/Gdata/Photos/Extension/Weight.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Data model class for a Comment Entry.
*
* To transfer user entries to and from the servers, including
* creating new entries, refer to the service class,
* Zend_Gdata_Photos.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_CommentEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Photos_CommentEntry';
/**
* gphoto:id element
*
* @var Zend_Gdata_Photos_Extension_Id
*/
protected $_gphotoId = null;
/**
* gphoto:photoid element, differs from gphoto:id as this is an
* actual identification number unique exclusively to photo entries,
* whereas gphoto:id can refer to all gphoto objects
*
* @var Zend_Gdata_Photos_Extension_PhotoId
*/
protected $_gphotoPhotoId = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
$category = new Zend_Gdata_App_Extension_Category(
'http://schemas.google.com/photos/2007#comment',
'http://schemas.google.com/g/2005#kind');
$this->setCategory(array($category));
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoId !== null) {
$element->appendChild($this->_gphotoId->getDOM($element->ownerDocument));
}
if ($this->_gphotoPhotoId !== null) {
$element->appendChild($this->_gphotoPhotoId->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'id';
$id = new Zend_Gdata_Photos_Extension_Id();
$id->transferFromDOM($child);
$this->_gphotoId = $id;
break;
case $this->lookupNamespace('gphoto') . ':' . 'photoid';
$photoid = new Zend_Gdata_Photos_Extension_PhotoId();
$photoid->transferFromDOM($child);
$this->_gphotoPhotoId = $photoid;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:photoid attribute.
*
* @see setGphotoPhotoId
* @return string The requested attribute.
*/
public function getGphotoPhotoId()
{
return $this->_gphotoPhotoId;
}
/**
* Set the value for this element's gphoto:photoid attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_PhotoId The element being modified.
*/
public function setGphotoPhotoId($value)
{
$this->_gphotoPhotoId = $value;
return $this;
}
/**
* Get the value for this element's gphoto:id attribute.
*
* @see setGphotoId
* @return string The requested attribute.
*/
public function getGphotoId()
{
return $this->_gphotoId;
}
/**
* Set the value for this element's gphoto:id attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Id The element being modified.
*/
public function setGphotoId($value)
{
$this->_gphotoId = $value;
return $this;
}
}
Gdata/Photos/TagEntry.php 0000604 00000010316 15071256135 0011310 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Photos_Extension_Weight
*/
require_once 'Zend/Gdata/Photos/Extension/Weight.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Data model class for a Tag Entry.
*
* To transfer user entries to and from the servers, including
* creating new entries, refer to the service class,
* Zend_Gdata_Photos.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_TagEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Photos_TagEntry';
protected $_gphotoWeight = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
$category = new Zend_Gdata_App_Extension_Category(
'http://schemas.google.com/photos/2007#tag',
'http://schemas.google.com/g/2005#kind');
$this->setCategory(array($category));
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoWeight !== null) {
$element->appendChild($this->_gphotoWeight->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'weight';
$weight = new Zend_Gdata_Photos_Extension_Weight();
$weight->transferFromDOM($child);
$this->_gphotoWeight = $weight;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:weight attribute.
*
* @see setGphotoWeight
* @return string The requested attribute.
*/
public function getGphotoWeight()
{
return $this->_gphotoWeight;
}
/**
* Set the value for this element's gphoto:weight attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Weight The element being modified.
*/
public function setGphotoWeight($value)
{
$this->_gphotoWeight = $value;
return $this;
}
}
Gdata/Photos/AlbumEntry.php 0000604 00000043576 15071256135 0011653 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Photos_Extension_Access
*/
require_once 'Zend/Gdata/Photos/Extension/Access.php';
/**
* @see Zend_Gdata_Photos_Extension_BytesUsed
*/
require_once 'Zend/Gdata/Photos/Extension/BytesUsed.php';
/**
* @see Zend_Gdata_Photos_Extension_Location
*/
require_once 'Zend/Gdata/Photos/Extension/Location.php';
/**
* @see Zend_Gdata_Photos_Extension_Name
*/
require_once 'Zend/Gdata/Photos/Extension/Name.php';
/**
* @see Zend_Gdata_Photos_Extension_NumPhotos
*/
require_once 'Zend/Gdata/Photos/Extension/NumPhotos.php';
/**
* @see Zend_Gdata_Photos_Extension_NumPhotosRemaining
*/
require_once 'Zend/Gdata/Photos/Extension/NumPhotosRemaining.php';
/**
* @see Zend_Gdata_Photos_Extension_CommentCount
*/
require_once 'Zend/Gdata/Photos/Extension/CommentCount.php';
/**
* @see Zend_Gdata_Photos_Extension_CommentingEnabled
*/
require_once 'Zend/Gdata/Photos/Extension/CommentingEnabled.php';
/**
* @see Zend_Gdata_Photos_Extension_Id
*/
require_once 'Zend/Gdata/Photos/Extension/Id.php';
/**
* @see Zend_Gdata_Geo_Extension_GeoRssWhere
*/
require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
/**
* @see Zend_Gdata_Media_Extension_MediaGroup
*/
require_once 'Zend/Gdata/Media/Extension/MediaGroup.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Data model class for a Photo Album Entry.
*
* To transfer user entries to and from the servers, including
* creating new entries, refer to the service class,
* Zend_Gdata_Photos.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_AlbumEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Photos_AlbumEntry';
/**
* gphoto:id element
*
* @var Zend_Gdata_Photos_Extension_Id
*/
protected $_gphotoId = null;
/**
* gphoto:access element
*
* @var Zend_Gdata_Photos_Extension_Access
*/
protected $_gphotoAccess = null;
/**
* gphoto:location element
*
* @var Zend_Gdata_Photos_Extension_Location
*/
protected $_gphotoLocation = null;
/**
* gphoto:user element
*
* @var Zend_Gdata_Photos_Extension_User
*/
protected $_gphotoUser = null;
/**
* gphoto:nickname element
*
* @var Zend_Gdata_Photos_Extension_Nickname
*/
protected $_gphotoNickname = null;
/**
* gphoto:timestamp element
*
* @var Zend_Gdata_Photos_Extension_Timestamp
*/
protected $_gphotoTimestamp = null;
/**
* gphoto:name element
*
* @var Zend_Gdata_Photos_Extension_Name
*/
protected $_gphotoName = null;
/**
* gphoto:numphotos element
*
* @var Zend_Gdata_Photos_Extension_NumPhotos
*/
protected $_gphotoNumPhotos = null;
/**
* gphoto:commentCount element
*
* @var Zend_Gdata_Photos_Extension_CommentCount
*/
protected $_gphotoCommentCount = null;
/**
* gphoto:commentingEnabled element
*
* @var Zend_Gdata_Photos_Extension_CommentingEnabled
*/
protected $_gphotoCommentingEnabled = null;
/**
* media:group element
*
* @var Zend_Gdata_Media_MediaGroup
*/
protected $_mediaGroup = null;
/**
* georss:where element
*
* @var Zend_Gdata_Geo_Extension_GeoRssWhere
*/
protected $_geoRssWhere = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
$category = new Zend_Gdata_App_Extension_Category(
'http://schemas.google.com/photos/2007#album',
'http://schemas.google.com/g/2005#kind');
$this->setCategory(array($category));
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoTimestamp !== null) {
$element->appendChild($this->_gphotoTimestamp->getDOM($element->ownerDocument));
}
if ($this->_gphotoUser !== null) {
$element->appendChild($this->_gphotoUser->getDOM($element->ownerDocument));
}
if ($this->_gphotoNickname !== null) {
$element->appendChild($this->_gphotoNickname->getDOM($element->ownerDocument));
}
if ($this->_gphotoAccess !== null) {
$element->appendChild($this->_gphotoAccess->getDOM($element->ownerDocument));
}
if ($this->_gphotoLocation !== null) {
$element->appendChild($this->_gphotoLocation->getDOM($element->ownerDocument));
}
if ($this->_gphotoName !== null) {
$element->appendChild($this->_gphotoName->getDOM($element->ownerDocument));
}
if ($this->_gphotoNumPhotos !== null) {
$element->appendChild($this->_gphotoNumPhotos->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentCount !== null) {
$element->appendChild($this->_gphotoCommentCount->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentingEnabled !== null) {
$element->appendChild($this->_gphotoCommentingEnabled->getDOM($element->ownerDocument));
}
if ($this->_gphotoId !== null) {
$element->appendChild($this->_gphotoId->getDOM($element->ownerDocument));
}
if ($this->_mediaGroup !== null) {
$element->appendChild($this->_mediaGroup->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'access';
$access = new Zend_Gdata_Photos_Extension_Access();
$access->transferFromDOM($child);
$this->_gphotoAccess = $access;
break;
case $this->lookupNamespace('gphoto') . ':' . 'location';
$location = new Zend_Gdata_Photos_Extension_Location();
$location->transferFromDOM($child);
$this->_gphotoLocation = $location;
break;
case $this->lookupNamespace('gphoto') . ':' . 'name';
$name = new Zend_Gdata_Photos_Extension_Name();
$name->transferFromDOM($child);
$this->_gphotoName = $name;
break;
case $this->lookupNamespace('gphoto') . ':' . 'numphotos';
$numPhotos = new Zend_Gdata_Photos_Extension_NumPhotos();
$numPhotos->transferFromDOM($child);
$this->_gphotoNumPhotos = $numPhotos;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentCount';
$commentCount = new Zend_Gdata_Photos_Extension_CommentCount();
$commentCount->transferFromDOM($child);
$this->_gphotoCommentCount = $commentCount;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentingEnabled';
$commentingEnabled = new Zend_Gdata_Photos_Extension_CommentingEnabled();
$commentingEnabled->transferFromDOM($child);
$this->_gphotoCommentingEnabled = $commentingEnabled;
break;
case $this->lookupNamespace('gphoto') . ':' . 'id';
$id = new Zend_Gdata_Photos_Extension_Id();
$id->transferFromDOM($child);
$this->_gphotoId = $id;
break;
case $this->lookupNamespace('gphoto') . ':' . 'user';
$user = new Zend_Gdata_Photos_Extension_User();
$user->transferFromDOM($child);
$this->_gphotoUser = $user;
break;
case $this->lookupNamespace('gphoto') . ':' . 'timestamp';
$timestamp = new Zend_Gdata_Photos_Extension_Timestamp();
$timestamp->transferFromDOM($child);
$this->_gphotoTimestamp = $timestamp;
break;
case $this->lookupNamespace('gphoto') . ':' . 'nickname';
$nickname = new Zend_Gdata_Photos_Extension_Nickname();
$nickname->transferFromDOM($child);
$this->_gphotoNickname = $nickname;
break;
case $this->lookupNamespace('georss') . ':' . 'where';
$geoRssWhere = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$geoRssWhere->transferFromDOM($child);
$this->_geoRssWhere = $geoRssWhere;
break;
case $this->lookupNamespace('media') . ':' . 'group';
$mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup();
$mediaGroup->transferFromDOM($child);
$this->_mediaGroup = $mediaGroup;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:access attribute.
*
* @see setGphotoAccess
* @return string The requested attribute.
*/
public function getGphotoAccess()
{
return $this->_gphotoAccess;
}
/**
* Set the value for this element's gphoto:access attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Access The element being modified.
*/
public function setGphotoAccess($value)
{
$this->_gphotoAccess = $value;
return $this;
}
/**
* Get the value for this element's gphoto:location attribute.
*
* @see setGphotoLocation
* @return string The requested attribute.
*/
public function getGphotoLocation()
{
return $this->_gphotoLocation;
}
/**
* Set the value for this element's gphoto:location attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Location The element being modified.
*/
public function setGphotoLocation($value)
{
$this->_location = $value;
return $this;
}
/**
* Get the value for this element's gphoto:name attribute.
*
* @see setGphotoName
* @return string The requested attribute.
*/
public function getGphotoName()
{
return $this->_gphotoName;
}
/**
* Set the value for this element's gphoto:name attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Name The element being modified.
*/
public function setGphotoName($value)
{
$this->_gphotoName = $value;
return $this;
}
/**
* Get the value for this element's gphoto:numphotos attribute.
*
* @see setGphotoNumPhotos
* @return string The requested attribute.
*/
public function getGphotoNumPhotos()
{
return $this->_gphotoNumPhotos;
}
/**
* Set the value for this element's gphoto:numphotos attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_NumPhotos The element being modified.
*/
public function setGphotoNumPhotos($value)
{
$this->_gphotoNumPhotos = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentCount attribute.
*
* @see setGphotoCommentCount
* @return string The requested attribute.
*/
public function getGphotoCommentCount()
{
return $this->_gphotoCommentCount;
}
/**
* Set the value for this element's gphoto:commentCount attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentCount The element being modified.
*/
public function setGphotoCommentCount($value)
{
$this->_gphotoCommentCount = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentingEnabled attribute.
*
* @see setGphotoCommentingEnabled
* @return string The requested attribute.
*/
public function getGphotoCommentingEnabled()
{
return $this->_gphotoCommentingEnabled;
}
/**
* Set the value for this element's gphoto:commentingEnabled attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentingEnabled The element being modified.
*/
public function setGphotoCommentingEnabled($value)
{
$this->_gphotoCommentingEnabled = $value;
return $this;
}
/**
* Get the value for this element's gphoto:id attribute.
*
* @see setGphotoId
* @return string The requested attribute.
*/
public function getGphotoId()
{
return $this->_gphotoId;
}
/**
* Set the value for this element's gphoto:id attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Id The element being modified.
*/
public function setGphotoId($value)
{
$this->_gphotoId = $value;
return $this;
}
/**
* Get the value for this element's georss:where attribute.
*
* @see setGeoRssWhere
* @return string The requested attribute.
*/
public function getGeoRssWhere()
{
return $this->_geoRssWhere;
}
/**
* Set the value for this element's georss:where attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Geo_Extension_GeoRssWhere The element being modified.
*/
public function setGeoRssWhere($value)
{
$this->_geoRssWhere = $value;
return $this;
}
/**
* Get the value for this element's media:group attribute.
*
* @see setMediaGroup
* @return string The requested attribute.
*/
public function getMediaGroup()
{
return $this->_mediaGroup;
}
/**
* Set the value for this element's media:group attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Media_Extension_MediaGroup The element being modified.
*/
public function setMediaGroup($value)
{
$this->_mediaGroup = $value;
return $this;
}
/**
* Get the value for this element's gphoto:user attribute.
*
* @see setGphotoUser
* @return string The requested attribute.
*/
public function getGphotoUser()
{
return $this->_gphotoUser;
}
/**
* Set the value for this element's gphoto:user attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_User The element being modified.
*/
public function setGphotoUser($value)
{
$this->_gphotoUser = $value;
return $this;
}
/**
* Get the value for this element's gphoto:nickname attribute.
*
* @see setGphotoNickname
* @return string The requested attribute.
*/
public function getGphotoNickname()
{
return $this->_gphotoNickname;
}
/**
* Set the value for this element's gphoto:nickname attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Nickname The element being modified.
*/
public function setGphotoNickname($value)
{
$this->_gphotoNickname = $value;
return $this;
}
/**
* Get the value for this element's gphoto:timestamp attribute.
*
* @see setGphotoTimestamp
* @return string The requested attribute.
*/
public function getGphotoTimestamp()
{
return $this->_gphotoTimestamp;
}
/**
* Set the value for this element's gphoto:timestamp attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Timestamp The element being modified.
*/
public function setGphotoTimestamp($value)
{
$this->_gphotoTimestamp = $value;
return $this;
}
}
Gdata/Photos/UserFeed.php 0000604 00000017013 15071256135 0011256 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Photos_UserEntry
*/
require_once 'Zend/Gdata/Photos/UserEntry.php';
/**
* @see Zend_Gdata_Photos_AlbumEntry
*/
require_once 'Zend/Gdata/Photos/AlbumEntry.php';
/**
* @see Zend_Gdata_Photos_PhotoEntry
*/
require_once 'Zend/Gdata/Photos/PhotoEntry.php';
/**
* @see Zend_Gdata_Photos_TagEntry
*/
require_once 'Zend/Gdata/Photos/TagEntry.php';
/**
* @see Zend_Gdata_Photos_CommentEntry
*/
require_once 'Zend/Gdata/Photos/CommentEntry.php';
/**
* Data model for a collection of entries for a specific user, usually
* provided by the servers.
*
* For information on requesting this feed from a server, see the
* service class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_UserFeed extends Zend_Gdata_Feed
{
/**
* gphoto:user element
*
* @var Zend_Gdata_Photos_Extension_User
*/
protected $_gphotoUser = null;
/**
* gphoto:thumbnail element
*
* @var Zend_Gdata_Photos_Extension_Thumbnail
*/
protected $_gphotoThumbnail = null;
/**
* gphoto:nickname element
*
* @var Zend_Gdata_Photos_Extension_Nickname
*/
protected $_gphotoNickname = null;
protected $_entryClassName = 'Zend_Gdata_Photos_UserEntry';
protected $_feedClassName = 'Zend_Gdata_Photos_UserFeed';
protected $_entryKindClassMapping = array(
'http://schemas.google.com/photos/2007#album' => 'Zend_Gdata_Photos_AlbumEntry',
'http://schemas.google.com/photos/2007#photo' => 'Zend_Gdata_Photos_PhotoEntry',
'http://schemas.google.com/photos/2007#comment' => 'Zend_Gdata_Photos_CommentEntry',
'http://schemas.google.com/photos/2007#tag' => 'Zend_Gdata_Photos_TagEntry'
);
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them in the $_entry array based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'user';
$user = new Zend_Gdata_Photos_Extension_User();
$user->transferFromDOM($child);
$this->_gphotoUser = $user;
break;
case $this->lookupNamespace('gphoto') . ':' . 'nickname';
$nickname = new Zend_Gdata_Photos_Extension_Nickname();
$nickname->transferFromDOM($child);
$this->_gphotoNickname = $nickname;
break;
case $this->lookupNamespace('gphoto') . ':' . 'thumbnail';
$thumbnail = new Zend_Gdata_Photos_Extension_Thumbnail();
$thumbnail->transferFromDOM($child);
$this->_gphotoThumbnail = $thumbnail;
break;
case $this->lookupNamespace('atom') . ':' . 'entry':
$entryClassName = $this->_entryClassName;
$tmpEntry = new Zend_Gdata_App_Entry($child);
$categories = $tmpEntry->getCategory();
foreach ($categories as $category) {
if ($category->scheme == Zend_Gdata_Photos::KIND_PATH &&
$this->_entryKindClassMapping[$category->term] != "") {
$entryClassName = $this->_entryKindClassMapping[$category->term];
break;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Entry is missing kind declaration.');
}
}
$newEntry = new $entryClassName($child);
$newEntry->setHttpClient($this->getHttpClient());
$this->_entry[] = $newEntry;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoUser != null) {
$element->appendChild($this->_gphotoUser->getDOM($element->ownerDocument));
}
if ($this->_gphotoNickname != null) {
$element->appendChild($this->_gphotoNickname->getDOM($element->ownerDocument));
}
if ($this->_gphotoThumbnail != null) {
$element->appendChild($this->_gphotoThumbnail->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Get the value for this element's gphoto:user attribute.
*
* @see setGphotoUser
* @return string The requested attribute.
*/
public function getGphotoUser()
{
return $this->_gphotoUser;
}
/**
* Set the value for this element's gphoto:user attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_User The element being modified.
*/
public function setGphotoUser($value)
{
$this->_gphotoUser = $value;
return $this;
}
/**
* Get the value for this element's gphoto:nickname attribute.
*
* @see setGphotoNickname
* @return string The requested attribute.
*/
public function getGphotoNickname()
{
return $this->_gphotoNickname;
}
/**
* Set the value for this element's gphoto:nickname attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Nickname The element being modified.
*/
public function setGphotoNickname($value)
{
$this->_gphotoNickname = $value;
return $this;
}
/**
* Get the value for this element's gphoto:thumbnail attribute.
*
* @see setGphotoThumbnail
* @return string The requested attribute.
*/
public function getGphotoThumbnail()
{
return $this->_gphotoThumbnail;
}
/**
* Set the value for this element's gphoto:thumbnail attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Thumbnail The element being modified.
*/
public function setGphotoThumbnail($value)
{
$this->_gphotoThumbnail = $value;
return $this;
}
}
Gdata/Photos/UserEntry.php 0000604 00000025720 15071256135 0011520 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Gapps
*/
require_once 'Zend/Gdata/Gapps.php';
/**
* @see Zend_Gdata_Photos_Extension_Nickname
*/
require_once 'Zend/Gdata/Photos/Extension/Nickname.php';
/**
* @see Zend_Gdata_Photos_Extension_Thumbnail
*/
require_once 'Zend/Gdata/Photos/Extension/Thumbnail.php';
/**
* @see Zend_Gdata_Photos_Extension_QuotaCurrent
*/
require_once 'Zend/Gdata/Photos/Extension/QuotaCurrent.php';
/**
* @see Zend_Gdata_Photos_Extension_QuotaLimit
*/
require_once 'Zend/Gdata/Photos/Extension/QuotaLimit.php';
/**
* @see Zend_Gdata_Photos_Extension_MaxPhotosPerAlbum
*/
require_once 'Zend/Gdata/Photos/Extension/MaxPhotosPerAlbum.php';
/**
* @see Zend_Gdata_Photos_Extension_User
*/
require_once 'Zend/Gdata/Photos/Extension/User.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Data model class for a User Entry.
*
* To transfer user entries to and from the servers, including
* creating new entries, refer to the service class,
* Zend_Gdata_Photos.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_UserEntry extends Zend_Gdata_Entry
{
protected $_entryClassName = 'Zend_Gdata_Photos_UserEntry';
/**
* gphoto:nickname element
*
* @var Zend_Gdata_Photos_Extension_Nickname
*/
protected $_gphotoNickname = null;
/**
* gphoto:user element
*
* @var Zend_Gdata_Photos_Extension_User
*/
protected $_gphotoUser = null;
/**
* gphoto:thumbnail element
*
* @var Zend_Gdata_Photos_Extension_Thumbnail
*/
protected $_gphotoThumbnail = null;
/**
* gphoto:quotalimit element
*
* @var Zend_Gdata_Photos_Extension_QuotaLimit
*/
protected $_gphotoQuotaLimit = null;
/**
* gphoto:quotacurrent element
*
* @var Zend_Gdata_Photos_Extension_QuotaCurrent
*/
protected $_gphotoQuotaCurrent = null;
/**
* gphoto:maxPhotosPerAlbum element
*
* @var Zend_Gdata_Photos_Extension_MaxPhotosPerAlbum
*/
protected $_gphotoMaxPhotosPerAlbum = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
$category = new Zend_Gdata_App_Extension_Category(
'http://schemas.google.com/photos/2007#user',
'http://schemas.google.com/g/2005#kind');
$this->setCategory(array($category));
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoNickname !== null) {
$element->appendChild($this->_gphotoNickname->getDOM($element->ownerDocument));
}
if ($this->_gphotoThumbnail !== null) {
$element->appendChild($this->_gphotoThumbnail->getDOM($element->ownerDocument));
}
if ($this->_gphotoUser !== null) {
$element->appendChild($this->_gphotoUser->getDOM($element->ownerDocument));
}
if ($this->_gphotoQuotaCurrent !== null) {
$element->appendChild($this->_gphotoQuotaCurrent->getDOM($element->ownerDocument));
}
if ($this->_gphotoQuotaLimit !== null) {
$element->appendChild($this->_gphotoQuotaLimit->getDOM($element->ownerDocument));
}
if ($this->_gphotoMaxPhotosPerAlbum !== null) {
$element->appendChild($this->_gphotoMaxPhotosPerAlbum->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'nickname';
$nickname = new Zend_Gdata_Photos_Extension_Nickname();
$nickname->transferFromDOM($child);
$this->_gphotoNickname = $nickname;
break;
case $this->lookupNamespace('gphoto') . ':' . 'thumbnail';
$thumbnail = new Zend_Gdata_Photos_Extension_Thumbnail();
$thumbnail->transferFromDOM($child);
$this->_gphotoThumbnail = $thumbnail;
break;
case $this->lookupNamespace('gphoto') . ':' . 'user';
$user = new Zend_Gdata_Photos_Extension_User();
$user->transferFromDOM($child);
$this->_gphotoUser = $user;
break;
case $this->lookupNamespace('gphoto') . ':' . 'quotacurrent';
$quotaCurrent = new Zend_Gdata_Photos_Extension_QuotaCurrent();
$quotaCurrent->transferFromDOM($child);
$this->_gphotoQuotaCurrent = $quotaCurrent;
break;
case $this->lookupNamespace('gphoto') . ':' . 'quotalimit';
$quotaLimit = new Zend_Gdata_Photos_Extension_QuotaLimit();
$quotaLimit->transferFromDOM($child);
$this->_gphotoQuotaLimit = $quotaLimit;
break;
case $this->lookupNamespace('gphoto') . ':' . 'maxPhotosPerAlbum';
$maxPhotosPerAlbum = new Zend_Gdata_Photos_Extension_MaxPhotosPerAlbum();
$maxPhotosPerAlbum->transferFromDOM($child);
$this->_gphotoMaxPhotosPerAlbum = $maxPhotosPerAlbum;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:nickname attribute.
*
* @see setGphotoNickname
* @return string The requested attribute.
*/
public function getGphotoNickname()
{
return $this->_gphotoNickname;
}
/**
* Set the value for this element's gphoto:nickname attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Nickname The element being modified.
*/
public function setGphotoNickname($value)
{
$this->_gphotoNickname = $value;
return $this;
}
/**
* Get the value for this element's gphoto:thumbnail attribute.
*
* @see setGphotoThumbnail
* @return string The requested attribute.
*/
public function getGphotoThumbnail()
{
return $this->_gphotoThumbnail;
}
/**
* Set the value for this element's gphoto:thumbnail attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Thumbnail The element being modified.
*/
public function setGphotoThumbnail($value)
{
$this->_gphotoThumbnail = $value;
return $this;
}
/**
* Get the value for this element's gphoto:quotacurrent attribute.
*
* @see setGphotoQuotaCurrent
* @return string The requested attribute.
*/
public function getGphotoQuotaCurrent()
{
return $this->_gphotoQuotaCurrent;
}
/**
* Set the value for this element's gphoto:quotacurrent attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_QuotaCurrent The element being modified.
*/
public function setGphotoQuotaCurrent($value)
{
$this->_gphotoQuotaCurrent = $value;
return $this;
}
/**
* Get the value for this element's gphoto:quotalimit attribute.
*
* @see setGphotoQuotaLimit
* @return string The requested attribute.
*/
public function getGphotoQuotaLimit()
{
return $this->_gphotoQuotaLimit;
}
/**
* Set the value for this element's gphoto:quotalimit attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_QuotaLimit The element being modified.
*/
public function setGphotoQuotaLimit($value)
{
$this->_gphotoQuotaLimit = $value;
return $this;
}
/**
* Get the value for this element's gphoto:maxPhotosPerAlbum attribute.
*
* @see setGphotoMaxPhotosPerAlbum
* @return string The requested attribute.
*/
public function getGphotoMaxPhotosPerAlbum()
{
return $this->_gphotoMaxPhotosPerAlbum;
}
/**
* Set the value for this element's gphoto:maxPhotosPerAlbum attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_MaxPhotosPerAlbum The element being modified.
*/
public function setGphotoMaxPhotosPerAlbum($value)
{
$this->_gphotoMaxPhotosPerAlbum = $value;
return $this;
}
/**
* Get the value for this element's gphoto:user attribute.
*
* @see setGphotoUser
* @return string The requested attribute.
*/
public function getGphotoUser()
{
return $this->_gphotoUser;
}
/**
* Set the value for this element's gphoto:user attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_User The element being modified.
*/
public function setGphotoUser($value)
{
$this->_gphotoUser = $value;
return $this;
}
}
Gdata/Photos/Extension/Nickname.php 0000604 00000003267 15071256135 0013263 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:nickname element used by the API.
* This class represents the nickname for a user.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Nickname extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'nickname';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Nickname object.
*
* @param string $text (optional) The value being represented.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Thumbnail.php 0000604 00000003304 15071256135 0013451 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:thumbnail element used by the API.
* This class represents the URI for a thumbnail image.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Thumbnail extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'thumbnail';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Thumbnail object.
*
* @param string $text (optional) The thumbnail URI to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/PhotoId.php 0000604 00000003171 15071256135 0013076 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:id element used by the Picasa API.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_PhotoId extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'id';
/**
* Constructs a new Zend_Gdata_Photos_Extension_PhotoId object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/CommentCount.php 0000604 00000003473 15071256135 0014150 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:commentCount element used by the API. This
* class represents the number of comments attached to an entry and is usually contained
* within an instance of Zend_Gdata_Photos_PhotoEntry or AlbumEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_CommentCount extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'commentCount';
/**
* Constructs a new Zend_Gdata_Photos_Extension_CommentCount object.
*
* @param string $text (optional) The value to use for the count.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/QuotaCurrent.php 0000604 00000003335 15071256135 0014166 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:quotaCurrent element used by the API.
* This class represents the number of bytes of storage used by a user.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_QuotaCurrent extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'quotaCurrent';
/**
* Constructs a new Zend_Gdata_Photos_Extension_QuotaCurrent object.
*
* @param string $text (optional) The value being represented.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Version.php 0000604 00000003322 15071256135 0013153 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:version element used by the API.
* This number is used for optimistic concurrency, and does not
* increase linearly.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Version extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'version';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Version object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Access.php 0000604 00000003340 15071256135 0012727 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:access element used by the API.
* This determines the visibility for an album, and can be either
* the strings 'private' or 'public'.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Access extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'access';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Access object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Name.php 0000604 00000003244 15071256135 0012411 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:name element used by the API.
* This indicates the URL-usable name for an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Name extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'name';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Name object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/NumPhotosRemaining.php 0000604 00000003346 15071256135 0015322 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:numphotosremaining element used by the API.
* This indicates the number of photos remaining in an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_NumPhotosRemaining extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'numphotosremaining';
/**
* Constructs a new Zend_Gdata_Photos_Extension_NumPhotosRemaining object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Location.php 0000604 00000003303 15071256135 0013275 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:location element used by the API.
* This indicates the number of bytes of storage used by an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Location extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'location';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Location object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/BytesUsed.php 0000604 00000003307 15071256135 0013440 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:bytesUsed element used by the API.
* This indicates the number of bytes of storage used by an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_BytesUsed extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'bytesUsed';
/**
* Constructs a new Zend_Gdata_Photos_Extension_BytesUsed object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Timestamp.php 0000604 00000003404 15071256135 0013472 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:timestamp element used by the API.
* The timestamp of a photo in milliseconds since January 1, 1970.
* This date is either set externally or based on EXIF data.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Timestamp extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'timestamp';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Timestamp object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/CommentingEnabled.php 0000604 00000003426 15071256135 0015106 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:commentingEnabled element used by the API.
* This class represents whether commenting is enabled for a given
* entry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_CommentingEnabled extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'commentingEnabled';
/**
* Constructs a new Zend_Gdata_Photos_Extension_CommentingEnabled object.
*
* @param string $text (optional) Whether commenting should be enabled
* or not.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Size.php 0000604 00000003221 15071256135 0012436 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:size element used by the API.
* The size of a photo in bytes.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Size extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'size';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Size object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Weight.php 0000604 00000003357 15071256135 0012765 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:weight element used by the API.
* This indicates the weight of a tag, based on the number of times
* it appears in photos under the current element.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Weight extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'weight';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Weight object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/QuotaLimit.php 0000604 00000003336 15071256135 0013623 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:quotaLimit element used by the API.
* This class represents the number of bytes of storage available for
* a user.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_QuotaLimit extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'quotaLimit';
/**
* Constructs a new Zend_Gdata_Photos_Extension_QuotaLimit object.
*
* @param string $text (optional) The value being represented.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Id.php 0000604 00000003270 15071256135 0012064 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:id element used by the API. This class
* represents the unique ID assigned to an element by the servers.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Id extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'id';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Id object.
*
* @param string $text (optional) The ID being represented.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/AlbumId.php 0000604 00000003423 15071256135 0013045 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:albumid element used by the API. This
* class represents the ID of an album and is usually contained
* within an instance of Zend_Gdata_Photos_AlbumEntry or CommentEntry.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_AlbumId extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'albumid';
/**
* Constructs a new Zend_Gdata_Photos_Extension_AlbumId object.
*
* @param string $text (optional) The value to use for the Album ID.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Rotation.php 0000604 00000003370 15071256135 0013330 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:rotation element used by the API.
* The rotation of a photo in degrees. Will only be shown if the
* rotation has not already been applied to the image.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Rotation extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'rotation';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Rotation object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Position.php 0000604 00000003264 15071256135 0013337 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:position element used by the API.
* The ordinal position of a photo within an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Position extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'position';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Position object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Height.php 0000604 00000003234 15071256135 0012740 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:height element used by the API.
* The height of a photo in pixels.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Height extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'height';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Height object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Checksum.php 0000604 00000003351 15071256135 0013272 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:checksum element used by the API.
* This is an optional field that can be used to store a photo's
* checksum to ease duplicate checking.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Checksum extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'checksum';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Checksum object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/User.php 0000604 00000003245 15071256135 0012450 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:user element used by the API.
* This class represents the username for a user.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_User extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'user';
/**
* Constructs a new Zend_Gdata_Photos_Extension_User object.
*
* @param string $text (optional) The username to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/NumPhotos.php 0000604 00000003270 15071256135 0013464 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:numphotos element used by the API.
* This indicates the number of photos in an album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_NumPhotos extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'numphotos';
/**
* Constructs a new Zend_Gdata_Photos_Extension_NumPhotos object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/MaxPhotosPerAlbum.php 0000604 00000003367 15071256135 0015111 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:maxPhotosPerAlbum element used by the API.
* This class represents the maximum number of photos allowed in an
* album.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_MaxPhotosPerAlbum extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'maxPhotosPerAlbum';
/**
* Constructs a new Zend_Gdata_Photos_Extension_MaxPhotosPerAlbum object.
*
* @param string $text (optional) The value being represented.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Width.php 0000604 00000003246 15071256135 0012612 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:width element used by the API.
* This indicates the width of a photo in pixels.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Width extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'width';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Width object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/Extension/Client.php 0000604 00000003327 15071256135 0012751 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Extension
*/
require_once 'Zend/Gdata/Extension.php';
/**
* @see Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* Represents the gphoto:client element used by the API.
* This is an optional field that can be used to indicate the
* client which created a photo.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_Extension_Client extends Zend_Gdata_Extension
{
protected $_rootNamespace = 'gphoto';
protected $_rootElement = 'client';
/**
* Constructs a new Zend_Gdata_Photos_Extension_Client object.
*
* @param string $text (optional) The value to represent.
*/
public function __construct($text = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct();
$this->setText($text);
}
}
Gdata/Photos/PhotoEntry.php 0000604 00000047654 15071256135 0011705 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_MediaEntry
*/
require_once 'Zend/Gdata/Media/Entry.php';
/**
* @see Zend_Gdata_Photos_Extension_PhotoId
*/
require_once 'Zend/Gdata/Photos/Extension/PhotoId.php';
/**
* @see Zend_Gdata_Photos_Extension_Version
*/
require_once 'Zend/Gdata/Photos/Extension/Version.php';
/**
* @see Zend_Gdata_Photos_Extension_AlbumId
*/
require_once 'Zend/Gdata/Photos/Extension/AlbumId.php';
/**
* @see Zend_Gdata_Photos_Extension_Id
*/
require_once 'Zend/Gdata/Photos/Extension/Id.php';
/**
* @see Zend_Gdata_Photos_Extension_Width
*/
require_once 'Zend/Gdata/Photos/Extension/Width.php';
/**
* @see Zend_Gdata_Photos_Extension_Height
*/
require_once 'Zend/Gdata/Photos/Extension/Height.php';
/**
* @see Zend_Gdata_Photos_Extension_Size
*/
require_once 'Zend/Gdata/Photos/Extension/Size.php';
/**
* @see Zend_Gdata_Photos_Extension_Client
*/
require_once 'Zend/Gdata/Photos/Extension/Client.php';
/**
* @see Zend_Gdata_Photos_Extension_Checksum
*/
require_once 'Zend/Gdata/Photos/Extension/Checksum.php';
/**
* @see Zend_Gdata_Photos_Extension_Timestamp
*/
require_once 'Zend/Gdata/Photos/Extension/Timestamp.php';
/**
* @see Zend_Gdata_Photos_Extension_CommentingEnabled
*/
require_once 'Zend/Gdata/Photos/Extension/CommentingEnabled.php';
/**
* @see Zend_Gdata_Photos_Extension_CommentCount
*/
require_once 'Zend/Gdata/Photos/Extension/CommentCount.php';
/**
* @see Zend_Gdata_Exif_Extension_Tags
*/
require_once 'Zend/Gdata/Exif/Extension/Tags.php';
/**
* @see Zend_Gdata_Geo_Extension_GeoRssWhere
*/
require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
/**
* @see Zend_Gdata_App_Extension_Category
*/
require_once 'Zend/Gdata/App/Extension/Category.php';
/**
* Data model class for a Comment Entry.
*
* To transfer user entries to and from the servers, including
* creating new entries, refer to the service class,
* Zend_Gdata_Photos.
*
* This class represents <atom:entry> in the Google Data protocol.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_PhotoEntry extends Zend_Gdata_Media_Entry
{
protected $_entryClassName = 'Zend_Gdata_Photos_PhotoEntry';
/**
* gphoto:id element
*
* @var Zend_Gdata_Photos_Extension_Id
*/
protected $_gphotoId = null;
/**
* gphoto:albumid element
*
* @var Zend_Gdata_Photos_Extension_AlbumId
*/
protected $_gphotoAlbumId = null;
/**
* gphoto:version element
*
* @var Zend_Gdata_Photos_Extension_Version
*/
protected $_gphotoVersion = null;
/**
* gphoto:width element
*
* @var Zend_Gdata_Photos_Extension_Width
*/
protected $_gphotoWidth = null;
/**
* gphoto:height element
*
* @var Zend_Gdata_Photos_Extension_Height
*/
protected $_gphotoHeight = null;
/**
* gphoto:size element
*
* @var Zend_Gdata_Photos_Extension_Size
*/
protected $_gphotoSize = null;
/**
* gphoto:client element
*
* @var Zend_Gdata_Photos_Extension_Client
*/
protected $_gphotoClient = null;
/**
* gphoto:checksum element
*
* @var Zend_Gdata_Photos_Extension_Checksum
*/
protected $_gphotoChecksum = null;
/**
* gphoto:timestamp element
*
* @var Zend_Gdata_Photos_Extension_Timestamp
*/
protected $_gphotoTimestamp = null;
/**
* gphoto:commentCount element
*
* @var Zend_Gdata_Photos_Extension_CommentCount
*/
protected $_gphotoCommentCount = null;
/**
* gphoto:commentingEnabled element
*
* @var Zend_Gdata_Photos_Extension_CommentingEnabled
*/
protected $_gphotoCommentingEnabled = null;
/**
* exif:tags element
*
* @var Zend_Gdata_Exif_Extension_Tags
*/
protected $_exifTags = null;
/**
* georss:where element
*
* @var Zend_Gdata_Geo_Extension_GeoRssWhere
*/
protected $_geoRssWhere = null;
/**
* Create a new instance.
*
* @param DOMElement $element (optional) DOMElement from which this
* object should be constructed.
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
$category = new Zend_Gdata_App_Extension_Category(
'http://schemas.google.com/photos/2007#photo',
'http://schemas.google.com/g/2005#kind');
$this->setCategory(array($category));
}
/**
* Retrieves a DOMElement which corresponds to this element and all
* child properties. This is used to build an entry back into a DOM
* and eventually XML text for application storage/persistence.
*
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
* @return DOMElement The DOMElement representing this element and all
* child properties.
*/
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoAlbumId !== null) {
$element->appendChild($this->_gphotoAlbumId->getDOM($element->ownerDocument));
}
if ($this->_gphotoId !== null) {
$element->appendChild($this->_gphotoId->getDOM($element->ownerDocument));
}
if ($this->_gphotoVersion !== null) {
$element->appendChild($this->_gphotoVersion->getDOM($element->ownerDocument));
}
if ($this->_gphotoWidth !== null) {
$element->appendChild($this->_gphotoWidth->getDOM($element->ownerDocument));
}
if ($this->_gphotoHeight !== null) {
$element->appendChild($this->_gphotoHeight->getDOM($element->ownerDocument));
}
if ($this->_gphotoSize !== null) {
$element->appendChild($this->_gphotoSize->getDOM($element->ownerDocument));
}
if ($this->_gphotoClient !== null) {
$element->appendChild($this->_gphotoClient->getDOM($element->ownerDocument));
}
if ($this->_gphotoChecksum !== null) {
$element->appendChild($this->_gphotoChecksum->getDOM($element->ownerDocument));
}
if ($this->_gphotoTimestamp !== null) {
$element->appendChild($this->_gphotoTimestamp->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentingEnabled !== null) {
$element->appendChild($this->_gphotoCommentingEnabled->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentCount !== null) {
$element->appendChild($this->_gphotoCommentCount->getDOM($element->ownerDocument));
}
if ($this->_exifTags !== null) {
$element->appendChild($this->_exifTags->getDOM($element->ownerDocument));
}
if ($this->_geoRssWhere !== null) {
$element->appendChild($this->_geoRssWhere->getDOM($element->ownerDocument));
}
return $element;
}
/**
* Creates individual Entry objects of the appropriate type and
* stores them as members of this entry based upon DOM data.
*
* @param DOMNode $child The DOMNode to process
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'albumid';
$albumId = new Zend_Gdata_Photos_Extension_AlbumId();
$albumId->transferFromDOM($child);
$this->_gphotoAlbumId = $albumId;
break;
case $this->lookupNamespace('gphoto') . ':' . 'id';
$id = new Zend_Gdata_Photos_Extension_Id();
$id->transferFromDOM($child);
$this->_gphotoId = $id;
break;
case $this->lookupNamespace('gphoto') . ':' . 'version';
$version = new Zend_Gdata_Photos_Extension_Version();
$version->transferFromDOM($child);
$this->_gphotoVersion = $version;
break;
case $this->lookupNamespace('gphoto') . ':' . 'width';
$width = new Zend_Gdata_Photos_Extension_Width();
$width->transferFromDOM($child);
$this->_gphotoWidth = $width;
break;
case $this->lookupNamespace('gphoto') . ':' . 'height';
$height = new Zend_Gdata_Photos_Extension_Height();
$height->transferFromDOM($child);
$this->_gphotoHeight = $height;
break;
case $this->lookupNamespace('gphoto') . ':' . 'size';
$size = new Zend_Gdata_Photos_Extension_Size();
$size->transferFromDOM($child);
$this->_gphotoSize = $size;
break;
case $this->lookupNamespace('gphoto') . ':' . 'client';
$client = new Zend_Gdata_Photos_Extension_Client();
$client->transferFromDOM($child);
$this->_gphotoClient = $client;
break;
case $this->lookupNamespace('gphoto') . ':' . 'checksum';
$checksum = new Zend_Gdata_Photos_Extension_Checksum();
$checksum->transferFromDOM($child);
$this->_gphotoChecksum = $checksum;
break;
case $this->lookupNamespace('gphoto') . ':' . 'timestamp';
$timestamp = new Zend_Gdata_Photos_Extension_Timestamp();
$timestamp->transferFromDOM($child);
$this->_gphotoTimestamp = $timestamp;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentingEnabled';
$commentingEnabled = new Zend_Gdata_Photos_Extension_CommentingEnabled();
$commentingEnabled->transferFromDOM($child);
$this->_gphotoCommentingEnabled = $commentingEnabled;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentCount';
$commentCount = new Zend_Gdata_Photos_Extension_CommentCount();
$commentCount->transferFromDOM($child);
$this->_gphotoCommentCount = $commentCount;
break;
case $this->lookupNamespace('exif') . ':' . 'tags';
$exifTags = new Zend_Gdata_Exif_Extension_Tags();
$exifTags->transferFromDOM($child);
$this->_exifTags = $exifTags;
break;
case $this->lookupNamespace('georss') . ':' . 'where';
$geoRssWhere = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$geoRssWhere->transferFromDOM($child);
$this->_geoRssWhere = $geoRssWhere;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:albumid attribute.
*
* @see setGphotoAlbumId
* @return string The requested attribute.
*/
public function getGphotoAlbumId()
{
return $this->_gphotoAlbumId;
}
/**
* Set the value for this element's gphoto:albumid attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_AlbumId The element being modified.
*/
public function setGphotoAlbumId($value)
{
$this->_gphotoAlbumId = $value;
return $this;
}
/**
* Get the value for this element's gphoto:id attribute.
*
* @see setGphotoId
* @return string The requested attribute.
*/
public function getGphotoId()
{
return $this->_gphotoId;
}
/**
* Set the value for this element's gphoto:id attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Id The element being modified.
*/
public function setGphotoId($value)
{
$this->_gphotoId = $value;
return $this;
}
/**
* Get the value for this element's gphoto:version attribute.
*
* @see setGphotoVersion
* @return string The requested attribute.
*/
public function getGphotoVersion()
{
return $this->_gphotoVersion;
}
/**
* Set the value for this element's gphoto:version attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Version The element being modified.
*/
public function setGphotoVersion($value)
{
$this->_gphotoVersion = $value;
return $this;
}
/**
* Get the value for this element's gphoto:width attribute.
*
* @see setGphotoWidth
* @return string The requested attribute.
*/
public function getGphotoWidth()
{
return $this->_gphotoWidth;
}
/**
* Set the value for this element's gphoto:width attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Width The element being modified.
*/
public function setGphotoWidth($value)
{
$this->_gphotoWidth = $value;
return $this;
}
/**
* Get the value for this element's gphoto:height attribute.
*
* @see setGphotoHeight
* @return string The requested attribute.
*/
public function getGphotoHeight()
{
return $this->_gphotoHeight;
}
/**
* Set the value for this element's gphoto:height attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Height The element being modified.
*/
public function setGphotoHeight($value)
{
$this->_gphotoHeight = $value;
return $this;
}
/**
* Get the value for this element's gphoto:size attribute.
*
* @see setGphotoSize
* @return string The requested attribute.
*/
public function getGphotoSize()
{
return $this->_gphotoSize;
}
/**
* Set the value for this element's gphoto:size attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Size The element being modified.
*/
public function setGphotoSize($value)
{
$this->_gphotoSize = $value;
return $this;
}
/**
* Get the value for this element's gphoto:client attribute.
*
* @see setGphotoClient
* @return string The requested attribute.
*/
public function getGphotoClient()
{
return $this->_gphotoClient;
}
/**
* Set the value for this element's gphoto:client attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Client The element being modified.
*/
public function setGphotoClient($value)
{
$this->_gphotoClient = $value;
return $this;
}
/**
* Get the value for this element's gphoto:checksum attribute.
*
* @see setGphotoChecksum
* @return string The requested attribute.
*/
public function getGphotoChecksum()
{
return $this->_gphotoChecksum;
}
/**
* Set the value for this element's gphoto:checksum attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Checksum The element being modified.
*/
public function setGphotoChecksum($value)
{
$this->_gphotoChecksum = $value;
return $this;
}
/**
* Get the value for this element's gphoto:timestamp attribute.
*
* @see setGphotoTimestamp
* @return string The requested attribute.
*/
public function getGphotoTimestamp()
{
return $this->_gphotoTimestamp;
}
/**
* Set the value for this element's gphoto:timestamp attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Timestamp The element being modified.
*/
public function setGphotoTimestamp($value)
{
$this->_gphotoTimestamp = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentCount attribute.
*
* @see setGphotoCommentCount
* @return string The requested attribute.
*/
public function getGphotoCommentCount()
{
return $this->_gphotoCommentCount;
}
/**
* Set the value for this element's gphoto:commentCount attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentCount The element being modified.
*/
public function setGphotoCommentCount($value)
{
$this->_gphotoCommentCount = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentingEnabled attribute.
*
* @see setGphotoCommentingEnabled
* @return string The requested attribute.
*/
public function getGphotoCommentingEnabled()
{
return $this->_gphotoCommentingEnabled;
}
/**
* Set the value for this element's gphoto:commentingEnabled attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentingEnabled The element being modified.
*/
public function setGphotoCommentingEnabled($value)
{
$this->_gphotoCommentingEnabled = $value;
return $this;
}
/**
* Get the value for this element's exif:tags attribute.
*
* @see setExifTags
* @return string The requested attribute.
*/
public function getExifTags()
{
return $this->_exifTags;
}
/**
* Set the value for this element's exif:tags attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Exif_Extension_Tags The element being modified.
*/
public function setExifTags($value)
{
$this->_exifTags = $value;
return $this;
}
/**
* Get the value for this element's georss:where attribute.
*
* @see setGeoRssWhere
* @return string The requested attribute.
*/
public function getGeoRssWhere()
{
return $this->_geoRssWhere;
}
/**
* Set the value for this element's georss:where attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Geo_Extension_GeoRssWhere The element being modified.
*/
public function setGeoRssWhere($value)
{
$this->_geoRssWhere = $value;
return $this;
}
/**
* Get the value for this element's media:group attribute.
*
* @see setMediaGroup
* @return string The requested attribute.
*/
public function getMediaGroup()
{
return $this->_mediaGroup;
}
/**
* Set the value for this element's media:group attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Media_Extension_MediaGroup The element being modified.
*/
public function setMediaGroup($value)
{
$this->_mediaGroup = $value;
return $this;
}
}
Gdata/Photos/PhotoFeed.php 0000604 00000041616 15071256135 0011437 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Photos_PhotoEntry
*/
require_once 'Zend/Gdata/Photos/PhotoEntry.php';
/**
* Data model for a collection of photo entries, usually
* provided by the Picasa servers.
*
* For information on requesting this feed from a server, see the
* service class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_PhotoFeed extends Zend_Gdata_Feed
{
/**
* gphoto:id element
*
* @var Zend_Gdata_Photos_Extension_Id
*/
protected $_gphotoId = null;
/**
* gphoto:albumid element
*
* @var Zend_Gdata_Photos_Extension_AlbumId
*/
protected $_gphotoAlbumId = null;
/**
* gphoto:version element
*
* @var Zend_Gdata_Photos_Extension_Version
*/
protected $_gphotoVersion = null;
/**
* gphoto:width element
*
* @var Zend_Gdata_Photos_Extension_Width
*/
protected $_gphotoWidth = null;
/**
* gphoto:height element
*
* @var Zend_Gdata_Photos_Extension_Height
*/
protected $_gphotoHeight = null;
/**
* gphoto:size element
*
* @var Zend_Gdata_Photos_Extension_Size
*/
protected $_gphotoSize = null;
/**
* gphoto:client element
*
* @var Zend_Gdata_Photos_Extension_Client
*/
protected $_gphotoClient = null;
/**
* gphoto:checksum element
*
* @var Zend_Gdata_Photos_Extension_Checksum
*/
protected $_gphotoChecksum = null;
/**
* gphoto:timestamp element
*
* @var Zend_Gdata_Photos_Extension_Timestamp
*/
protected $_gphotoTimestamp = null;
/**
* gphoto:commentCount element
*
* @var Zend_Gdata_Photos_Extension_CommentCount
*/
protected $_gphotoCommentCount = null;
/**
* gphoto:commentingEnabled element
*
* @var Zend_Gdata_Photos_Extension_CommentingEnabled
*/
protected $_gphotoCommentingEnabled = null;
/**
* media:group element
*
* @var Zend_Gdata_Media_Extension_MediaGroup
*/
protected $_mediaGroup = null;
protected $_entryClassName = 'Zend_Gdata_Photos_PhotoEntry';
protected $_feedClassName = 'Zend_Gdata_Photos_PhotoFeed';
protected $_entryKindClassMapping = array(
'http://schemas.google.com/photos/2007#comment' => 'Zend_Gdata_Photos_CommentEntry',
'http://schemas.google.com/photos/2007#tag' => 'Zend_Gdata_Photos_TagEntry'
);
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoId != null) {
$element->appendChild($this->_gphotoId->getDOM($element->ownerDocument));
}
if ($this->_gphotoVersion != null) {
$element->appendChild($this->_gphotoVersion->getDOM($element->ownerDocument));
}
if ($this->_gphotoWidth != null) {
$element->appendChild($this->_gphotoWidth->getDOM($element->ownerDocument));
}
if ($this->_gphotoHeight != null) {
$element->appendChild($this->_gphotoHeight->getDOM($element->ownerDocument));
}
if ($this->_gphotoSize != null) {
$element->appendChild($this->_gphotoSize->getDOM($element->ownerDocument));
}
if ($this->_gphotoClient != null) {
$element->appendChild($this->_gphotoClient->getDOM($element->ownerDocument));
}
if ($this->_gphotoChecksum != null) {
$element->appendChild($this->_gphotoChecksum->getDOM($element->ownerDocument));
}
if ($this->_gphotoTimestamp != null) {
$element->appendChild($this->_gphotoTimestamp->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentingEnabled != null) {
$element->appendChild($this->_gphotoCommentingEnabled->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentCount != null) {
$element->appendChild($this->_gphotoCommentCount->getDOM($element->ownerDocument));
}
if ($this->_mediaGroup != null) {
$element->appendChild($this->_mediaGroup->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'id';
$id = new Zend_Gdata_Photos_Extension_Id();
$id->transferFromDOM($child);
$this->_gphotoId = $id;
break;
case $this->lookupNamespace('gphoto') . ':' . 'version';
$version = new Zend_Gdata_Photos_Extension_Version();
$version->transferFromDOM($child);
$this->_gphotoVersion = $version;
break;
case $this->lookupNamespace('gphoto') . ':' . 'albumid';
$albumid = new Zend_Gdata_Photos_Extension_AlbumId();
$albumid->transferFromDOM($child);
$this->_gphotoAlbumId = $albumid;
break;
case $this->lookupNamespace('gphoto') . ':' . 'width';
$width = new Zend_Gdata_Photos_Extension_Width();
$width->transferFromDOM($child);
$this->_gphotoWidth = $width;
break;
case $this->lookupNamespace('gphoto') . ':' . 'height';
$height = new Zend_Gdata_Photos_Extension_Height();
$height->transferFromDOM($child);
$this->_gphotoHeight = $height;
break;
case $this->lookupNamespace('gphoto') . ':' . 'size';
$size = new Zend_Gdata_Photos_Extension_Size();
$size->transferFromDOM($child);
$this->_gphotoSize = $size;
break;
case $this->lookupNamespace('gphoto') . ':' . 'client';
$client = new Zend_Gdata_Photos_Extension_Client();
$client->transferFromDOM($child);
$this->_gphotoClient = $client;
break;
case $this->lookupNamespace('gphoto') . ':' . 'checksum';
$checksum = new Zend_Gdata_Photos_Extension_Checksum();
$checksum->transferFromDOM($child);
$this->_gphotoChecksum = $checksum;
break;
case $this->lookupNamespace('gphoto') . ':' . 'timestamp';
$timestamp = new Zend_Gdata_Photos_Extension_Timestamp();
$timestamp->transferFromDOM($child);
$this->_gphotoTimestamp = $timestamp;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentingEnabled';
$commentingEnabled = new Zend_Gdata_Photos_Extension_CommentingEnabled();
$commentingEnabled->transferFromDOM($child);
$this->_gphotoCommentingEnabled = $commentingEnabled;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentCount';
$commentCount = new Zend_Gdata_Photos_Extension_CommentCount();
$commentCount->transferFromDOM($child);
$this->_gphotoCommentCount = $commentCount;
break;
case $this->lookupNamespace('media') . ':' . 'group';
$mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup();
$mediaGroup->transferFromDOM($child);
$this->_mediaGroup = $mediaGroup;
break;
case $this->lookupNamespace('atom') . ':' . 'entry':
$entryClassName = $this->_entryClassName;
$tmpEntry = new Zend_Gdata_App_Entry($child);
$categories = $tmpEntry->getCategory();
foreach ($categories as $category) {
if ($category->scheme == Zend_Gdata_Photos::KIND_PATH &&
$this->_entryKindClassMapping[$category->term] != "") {
$entryClassName = $this->_entryKindClassMapping[$category->term];
break;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Entry is missing kind declaration.');
}
}
$newEntry = new $entryClassName($child);
$newEntry->setHttpClient($this->getHttpClient());
$this->_entry[] = $newEntry;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:id attribute.
*
* @see setGphotoId
* @return string The requested attribute.
*/
public function getGphotoId()
{
return $this->_gphotoId;
}
/**
* Set the value for this element's gphoto:id attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Id The element being modified.
*/
public function setGphotoId($value)
{
$this->_gphotoId = $value;
return $this;
}
/**
* Get the value for this element's gphoto:version attribute.
*
* @see setGphotoVersion
* @return string The requested attribute.
*/
public function getGphotoVersion()
{
return $this->_gphotoVersion;
}
/**
* Set the value for this element's gphoto:version attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Version The element being modified.
*/
public function setGphotoVersion($value)
{
$this->_gphotoVersion = $value;
return $this;
}
/**
* Get the value for this element's gphoto:albumid attribute.
*
* @see setGphotoAlbumId
* @return string The requested attribute.
*/
public function getGphotoAlbumId()
{
return $this->_gphotoAlbumId;
}
/**
* Set the value for this element's gphoto:albumid attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_AlbumId The element being modified.
*/
public function setGphotoAlbumId($value)
{
$this->_gphotoAlbumId = $value;
return $this;
}
/**
* Get the value for this element's gphoto:width attribute.
*
* @see setGphotoWidth
* @return string The requested attribute.
*/
public function getGphotoWidth()
{
return $this->_gphotoWidth;
}
/**
* Set the value for this element's gphoto:width attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Width The element being modified.
*/
public function setGphotoWidth($value)
{
$this->_gphotoWidth = $value;
return $this;
}
/**
* Get the value for this element's gphoto:height attribute.
*
* @see setGphotoHeight
* @return string The requested attribute.
*/
public function getGphotoHeight()
{
return $this->_gphotoHeight;
}
/**
* Set the value for this element's gphoto:height attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Height The element being modified.
*/
public function setGphotoHeight($value)
{
$this->_gphotoHeight = $value;
return $this;
}
/**
* Get the value for this element's gphoto:size attribute.
*
* @see setGphotoSize
* @return string The requested attribute.
*/
public function getGphotoSize()
{
return $this->_gphotoSize;
}
/**
* Set the value for this element's gphoto:size attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Size The element being modified.
*/
public function setGphotoSize($value)
{
$this->_gphotoSize = $value;
return $this;
}
/**
* Get the value for this element's gphoto:client attribute.
*
* @see setGphotoClient
* @return string The requested attribute.
*/
public function getGphotoClient()
{
return $this->_gphotoClient;
}
/**
* Set the value for this element's gphoto:client attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Client The element being modified.
*/
public function setGphotoClient($value)
{
$this->_gphotoClient = $value;
return $this;
}
/**
* Get the value for this element's gphoto:checksum attribute.
*
* @see setGphotoChecksum
* @return string The requested attribute.
*/
public function getGphotoChecksum()
{
return $this->_gphotoChecksum;
}
/**
* Set the value for this element's gphoto:checksum attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Checksum The element being modified.
*/
public function setGphotoChecksum($value)
{
$this->_gphotoChecksum = $value;
return $this;
}
/**
* Get the value for this element's gphoto:timestamp attribute.
*
* @see setGphotoTimestamp
* @return string The requested attribute.
*/
public function getGphotoTimestamp()
{
return $this->_gphotoTimestamp;
}
/**
* Set the value for this element's gphoto:timestamp attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Timestamp The element being modified.
*/
public function setGphotoTimestamp($value)
{
$this->_gphotoTimestamp = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentCount attribute.
*
* @see setGphotoCommentCount
* @return string The requested attribute.
*/
public function getGphotoCommentCount()
{
return $this->_gphotoCommentCount;
}
/**
* Set the value for this element's gphoto:commentCount attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentCount The element being modified.
*/
public function setGphotoCommentCount($value)
{
$this->_gphotoCommentCount = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentingEnabled attribute.
*
* @see setGphotoCommentingEnabled
* @return string The requested attribute.
*/
public function getGphotoCommentingEnabled()
{
return $this->_gphotoCommentingEnabled;
}
/**
* Set the value for this element's gphoto:commentingEnabled attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentingEnabled The element being modified.
*/
public function setGphotoCommentingEnabled($value)
{
$this->_gphotoCommentingEnabled = $value;
return $this;
}
/**
* Get the value for this element's media:group attribute.
*
* @see setMediaGroup
* @return string The requested attribute.
*/
public function getMediaGroup()
{
return $this->_mediaGroup;
}
/**
* Set the value for this element's media:group attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Media_Extension_MediaGroup The element being modified.
*/
public function setMediaGroup($value)
{
$this->_mediaGroup = $value;
return $this;
}
}
Gdata/Photos/PhotoQuery.php 0000604 00000005363 15071256135 0011700 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Gapps_Picasa_AlbumQuery
*/
require_once('Zend/Gdata/Photos/AlbumQuery.php');
/**
* Assists in constructing queries for comment/tag entries.
* Instances of this class can be provided in many places where a URL is
* required.
*
* For information on submitting queries to a server, see the
* service class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_PhotoQuery extends Zend_Gdata_Photos_AlbumQuery
{
/**
* The ID of the photo to query for.
*
* @var string
*/
protected $_photoId = null;
/**
* Set the photo ID to query for. When set, this photo's comments/tags
* will be returned. If not set or null, the default user's feed will be
* returned instead.
*
* @param string $value The ID of the photo to retrieve, or null to
* clear.
*/
public function setPhotoId($value)
{
$this->_photoId = $value;
}
/**
* Get the photo ID which is to be returned.
*
* @see setPhoto
* @return string The ID of the photo to retrieve.
*/
public function getPhotoId()
{
return $this->_photoId;
}
/**
* Returns the URL generated for this query, based on it's current
* parameters.
*
* @return string A URL generated based on the state of this query.
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function getQueryUrl($incomingUri = '')
{
$uri = '';
if ($this->getPhotoId() !== null) {
$uri .= '/photoid/' . $this->getPhotoId();
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'PhotoId cannot be null');
}
$uri .= $incomingUri;
return parent::getQueryUrl($uri);
}
}
Gdata/Photos/AlbumFeed.php 0000604 00000037012 15071256135 0011401 0 ustar 00 <?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_Gdata
* @subpackage Photos
* @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 Zend_Gdata_Photos
*/
require_once 'Zend/Gdata/Photos.php';
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @see Zend_Gdata_Photos_AlbumEntry
*/
require_once 'Zend/Gdata/Photos/AlbumEntry.php';
/**
* Data model for a collection of album entries, usually
* provided by the servers.
*
* For information on requesting this feed from a server, see the
* service class, Zend_Gdata_Photos.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Photos
* @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_Gdata_Photos_AlbumFeed extends Zend_Gdata_Feed
{
protected $_entryClassName = 'Zend_Gdata_Photos_AlbumEntry';
protected $_feedClassName = 'Zend_Gdata_Photos_AlbumFeed';
/**
* gphoto:id element
*
* @var Zend_Gdata_Photos_Extension_Id
*/
protected $_gphotoId = null;
/**
* gphoto:user element
*
* @var Zend_Gdata_Photos_Extension_User
*/
protected $_gphotoUser = null;
/**
* gphoto:access element
*
* @var Zend_Gdata_Photos_Extension_Access
*/
protected $_gphotoAccess = null;
/**
* gphoto:location element
*
* @var Zend_Gdata_Photos_Extension_Location
*/
protected $_gphotoLocation = null;
/**
* gphoto:nickname element
*
* @var Zend_Gdata_Photos_Extension_Nickname
*/
protected $_gphotoNickname = null;
/**
* gphoto:timestamp element
*
* @var Zend_Gdata_Photos_Extension_Timestamp
*/
protected $_gphotoTimestamp = null;
/**
* gphoto:name element
*
* @var Zend_Gdata_Photos_Extension_Name
*/
protected $_gphotoName = null;
/**
* gphoto:numphotos element
*
* @var Zend_Gdata_Photos_Extension_NumPhotos
*/
protected $_gphotoNumPhotos = null;
/**
* gphoto:commentCount element
*
* @var Zend_Gdata_Photos_Extension_CommentCount
*/
protected $_gphotoCommentCount = null;
/**
* gphoto:commentingEnabled element
*
* @var Zend_Gdata_Photos_Extension_CommentingEnabled
*/
protected $_gphotoCommentingEnabled = null;
protected $_entryKindClassMapping = array(
'http://schemas.google.com/photos/2007#photo' => 'Zend_Gdata_Photos_PhotoEntry',
'http://schemas.google.com/photos/2007#comment' => 'Zend_Gdata_Photos_CommentEntry',
'http://schemas.google.com/photos/2007#tag' => 'Zend_Gdata_Photos_TagEntry'
);
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Photos::$namespaces);
parent::__construct($element);
}
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
{
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
if ($this->_gphotoId != null) {
$element->appendChild($this->_gphotoId->getDOM($element->ownerDocument));
}
if ($this->_gphotoUser != null) {
$element->appendChild($this->_gphotoUser->getDOM($element->ownerDocument));
}
if ($this->_gphotoNickname != null) {
$element->appendChild($this->_gphotoNickname->getDOM($element->ownerDocument));
}
if ($this->_gphotoName != null) {
$element->appendChild($this->_gphotoName->getDOM($element->ownerDocument));
}
if ($this->_gphotoLocation != null) {
$element->appendChild($this->_gphotoLocation->getDOM($element->ownerDocument));
}
if ($this->_gphotoAccess != null) {
$element->appendChild($this->_gphotoAccess->getDOM($element->ownerDocument));
}
if ($this->_gphotoTimestamp != null) {
$element->appendChild($this->_gphotoTimestamp->getDOM($element->ownerDocument));
}
if ($this->_gphotoNumPhotos != null) {
$element->appendChild($this->_gphotoNumPhotos->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentingEnabled != null) {
$element->appendChild($this->_gphotoCommentingEnabled->getDOM($element->ownerDocument));
}
if ($this->_gphotoCommentCount != null) {
$element->appendChild($this->_gphotoCommentCount->getDOM($element->ownerDocument));
}
return $element;
}
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('gphoto') . ':' . 'id';
$id = new Zend_Gdata_Photos_Extension_Id();
$id->transferFromDOM($child);
$this->_gphotoId = $id;
break;
case $this->lookupNamespace('gphoto') . ':' . 'user';
$user = new Zend_Gdata_Photos_Extension_User();
$user->transferFromDOM($child);
$this->_gphotoUser = $user;
break;
case $this->lookupNamespace('gphoto') . ':' . 'nickname';
$nickname = new Zend_Gdata_Photos_Extension_Nickname();
$nickname->transferFromDOM($child);
$this->_gphotoNickname = $nickname;
break;
case $this->lookupNamespace('gphoto') . ':' . 'name';
$name = new Zend_Gdata_Photos_Extension_Name();
$name->transferFromDOM($child);
$this->_gphotoName = $name;
break;
case $this->lookupNamespace('gphoto') . ':' . 'location';
$location = new Zend_Gdata_Photos_Extension_Location();
$location->transferFromDOM($child);
$this->_gphotoLocation = $location;
break;
case $this->lookupNamespace('gphoto') . ':' . 'access';
$access = new Zend_Gdata_Photos_Extension_Access();
$access->transferFromDOM($child);
$this->_gphotoAccess = $access;
break;
case $this->lookupNamespace('gphoto') . ':' . 'timestamp';
$timestamp = new Zend_Gdata_Photos_Extension_Timestamp();
$timestamp->transferFromDOM($child);
$this->_gphotoTimestamp = $timestamp;
break;
case $this->lookupNamespace('gphoto') . ':' . 'numphotos';
$numphotos = new Zend_Gdata_Photos_Extension_NumPhotos();
$numphotos->transferFromDOM($child);
$this->_gphotoNumPhotos = $numphotos;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentingEnabled';
$commentingEnabled = new Zend_Gdata_Photos_Extension_CommentingEnabled();
$commentingEnabled->transferFromDOM($child);
$this->_gphotoCommentingEnabled = $commentingEnabled;
break;
case $this->lookupNamespace('gphoto') . ':' . 'commentCount';
$commentCount = new Zend_Gdata_Photos_Extension_CommentCount();
$commentCount->transferFromDOM($child);
$this->_gphotoCommentCount = $commentCount;
break;
case $this->lookupNamespace('atom') . ':' . 'entry':
$entryClassName = $this->_entryClassName;
$tmpEntry = new Zend_Gdata_App_Entry($child);
$categories = $tmpEntry->getCategory();
foreach ($categories as $category) {
if ($category->scheme == Zend_Gdata_Photos::KIND_PATH &&
$this->_entryKindClassMapping[$category->term] != "") {
$entryClassName = $this->_entryKindClassMapping[$category->term];
break;
} else {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('Entry is missing kind declaration.');
}
}
$newEntry = new $entryClassName($child);
$newEntry->setHttpClient($this->getHttpClient());
$this->_entry[] = $newEntry;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* Get the value for this element's gphoto:user attribute.
*
* @see setGphotoUser
* @return string The requested attribute.
*/
public function getGphotoUser()
{
return $this->_gphotoUser;
}
/**
* Set the value for this element's gphoto:user attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_User The element being modified.
*/
public function setGphotoUser($value)
{
$this->_gphotoUser = $value;
return $this;
}
/**
* Get the value for this element's gphoto:access attribute.
*
* @see setGphotoAccess
* @return string The requested attribute.
*/
public function getGphotoAccess()
{
return $this->_gphotoAccess;
}
/**
* Set the value for this element's gphoto:access attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Access The element being modified.
*/
public function setGphotoAccess($value)
{
$this->_gphotoAccess = $value;
return $this;
}
/**
* Get the value for this element's gphoto:location attribute.
*
* @see setGphotoLocation
* @return string The requested attribute.
*/
public function getGphotoLocation()
{
return $this->_gphotoLocation;
}
/**
* Set the value for this element's gphoto:location attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Location The element being modified.
*/
public function setGphotoLocation($value)
{
$this->_gphotoLocation = $value;
return $this;
}
/**
* Get the value for this element's gphoto:name attribute.
*
* @see setGphotoName
* @return string The requested attribute.
*/
public function getGphotoName()
{
return $this->_gphotoName;
}
/**
* Set the value for this element's gphoto:name attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Name The element being modified.
*/
public function setGphotoName($value)
{
$this->_gphotoName = $value;
return $this;
}
/**
* Get the value for this element's gphoto:numphotos attribute.
*
* @see setGphotoNumPhotos
* @return string The requested attribute.
*/
public function getGphotoNumPhotos()
{
return $this->_gphotoNumPhotos;
}
/**
* Set the value for this element's gphoto:numphotos attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_NumPhotos The element being modified.
*/
public function setGphotoNumPhotos($value)
{
$this->_gphotoNumPhotos = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentCount attribute.
*
* @see setGphotoCommentCount
* @return string The requested attribute.
*/
public function getGphotoCommentCount()
{
return $this->_gphotoCommentCount;
}
/**
* Set the value for this element's gphoto:commentCount attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentCount The element being modified.
*/
public function setGphotoCommentCount($value)
{
$this->_gphotoCommentCount = $value;
return $this;
}
/**
* Get the value for this element's gphoto:commentingEnabled attribute.
*
* @see setGphotoCommentingEnabled
* @return string The requested attribute.
*/
public function getGphotoCommentingEnabled()
{
return $this->_gphotoCommentingEnabled;
}
/**
* Set the value for this element's gphoto:commentingEnabled attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_CommentingEnabled The element being modified.
*/
public function setGphotoCommentingEnabled($value)
{
$this->_gphotoCommentingEnabled = $value;
return $this;
}
/**
* Get the value for this element's gphoto:id attribute.
*
* @see setGphotoId
* @return string The requested attribute.
*/
public function getGphotoId()
{
return $this->_gphotoId;
}
/**
* Set the value for this element's gphoto:id attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Id The element being modified.
*/
public function setGphotoId($value)
{
$this->_gphotoId = $value;
return $this;
}
/**
* Get the value for this element's georss:where attribute.
*
* @see setGeoRssWhere
* @return string The requested attribute.
*/
public function getGeoRssWhere()
{
return $this->_geoRssWhere;
}
/**
* Set the value for this element's georss:where attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Geo_Extension_GeoRssWhere The element being modified.
*/
public function setGeoRssWhere($value)
{
$this->_geoRssWhere = $value;
return $this;
}
/**
* Get the value for this element's gphoto:nickname attribute.
*
* @see setGphotoNickname
* @return string The requested attribute.
*/
public function getGphotoNickname()
{
return $this->_gphotoNickname;
}
/**
* Set the value for this element's gphoto:nickname attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Nickname The element being modified.
*/
public function setGphotoNickname($value)
{
$this->_gphotoNickname = $value;
return $this;
}
/**
* Get the value for this element's gphoto:timestamp attribute.
*
* @see setGphotoTimestamp
* @return string The requested attribute.
*/
public function getGphotoTimestamp()
{
return $this->_gphotoTimestamp;
}
/**
* Set the value for this element's gphoto:timestamp attribute.
*
* @param string $value The desired value for this attribute.
* @return Zend_Gdata_Photos_Extension_Timestamp The element being modified.
*/
public function setGphotoTimestamp($value)
{
$this->_gphotoTimestamp = $value;
return $this;
}
}
Memory.php 0000604 00000004424 15071256135 0006532 0 ustar 00 <?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.
*
* @package Zend_Memory
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Memory_Exception */
require_once 'Zend/Memory/Manager.php';
/** Zend_Memory_Exception */
require_once 'Zend/Memory/Exception.php';
/** Zend_Memory_Value */
require_once 'Zend/Memory/Value.php';
/** Zend_Memory_Container */
require_once 'Zend/Memory/Container.php';
/** Zend_Memory_Exception */
require_once 'Zend/Cache.php';
/**
* @category Zend
* @package Zend_Memory
* @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_Memory
{
/**
* Factory
*
* @param string $backend backend name
* @param array $backendOptions associative array of options for the corresponding backend constructor
* @return Zend_Memory_Manager
* @throws Zend_Memory_Exception
*/
public static function factory($backend, $backendOptions = array())
{
if (strcasecmp($backend, 'none') == 0) {
return new Zend_Memory_Manager();
}
// because lowercase will fail
$backend = @ucfirst(strtolower($backend));
if (!in_array($backend, Zend_Cache::$availableBackends)) {
throw new Zend_Memory_Exception("Incorrect backend ($backend)");
}
$backendClass = 'Zend_Cache_Backend_' . $backend;
// For perfs reasons, we do not use the Zend_Loader::loadClass() method
// (security controls are explicit)
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
$backendObject = new $backendClass($backendOptions);
return new Zend_Memory_Manager($backendObject);
}
}
Translate/Adapter/Qt.php 0000604 00000013304 15071256135 0011160 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Qt extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_transunit = null;
private $_source = null;
private $_target = null;
private $_scontent = null;
private $_tcontent = null;
private $_stag = false;
private $_ttag = true;
/**
* Generates the Qt adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (QT file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename QT file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$this->_target = $locale;
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
switch(strtolower($name)) {
case 'message':
$this->_source = null;
$this->_stag = false;
$this->_ttag = false;
$this->_scontent = null;
$this->_tcontent = null;
break;
case 'source':
$this->_stag = true;
break;
case 'translation':
$this->_ttag = true;
break;
default:
break;
}
}
private function _endElement($file, $name)
{
switch (strtolower($name)) {
case 'source':
$this->_stag = false;
break;
case 'translation':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_target][$this->_scontent]) === false)) {
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
}
$this->_ttag = false;
break;
default:
break;
}
}
private function _contentElement($file, $data)
{
if ($this->_stag === true) {
$this->_scontent .= $data;
}
if ($this->_ttag === true) {
$this->_tcontent .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Qt";
}
}
Translate/Adapter/XmlTm.php 0000604 00000012207 15071256135 0011636 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_lang = null;
private $_content = null;
private $_tag = null;
/**
* Generates the xmltm adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (XMLTM file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename XMLTM file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
$this->_lang = $locale;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
switch(strtolower($name)) {
case 'tm:tu':
$this->_tag = $attrib['id'];
$this->_content = null;
break;
default:
break;
}
}
private function _endElement($file, $name)
{
switch (strtolower($name)) {
case 'tm:tu':
if (!empty($this->_tag) and !empty($this->_content) or
(isset($this->_translate[$this->_lang][$this->_tag]) === false)) {
$this->_translate[$this->_lang][$this->_tag] = $this->_content;
}
$this->_tag = null;
$this->_content = null;
break;
default:
break;
}
}
private function _contentElement($file, $data)
{
if (($this->_tag !== null)) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "XmlTm";
}
}
Translate/Adapter/Tmx.php 0000604 00000014307 15071256135 0011350 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_tu = null;
private $_tuv = null;
private $_seg = null;
private $_content = null;
/**
* Generates the tmx adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (TMX file reader)
*
* @param string $filename TMX file to add, full path must be given for access
* @param string $locale Locale has no effect for TMX because TMX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $this->_options + $options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_seg !== null) {
$this->_content .= "<".$name;
foreach($attrib as $key => $value) {
$this->_content .= " $key=\"$value\"";
}
$this->_content .= ">";
} else {
switch(strtolower($name)) {
case 'tu':
if (isset($attrib['tuid']) === true) {
$this->_tu = $attrib['tuid'];
}
break;
case 'tuv':
if (isset($attrib['xml:lang']) === true) {
$this->_tuv = $attrib['xml:lang'];
if (isset($this->_translate[$this->_tuv]) === false) {
$this->_translate[$this->_tuv] = array();
}
}
break;
case 'seg':
$this->_seg = true;
$this->_content = null;
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_seg !== null) and ($name !== 'seg')) {
$this->_content .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'tu':
$this->_tu = null;
break;
case 'tuv':
$this->_tuv = null;
break;
case 'seg':
$this->_seg = null;
if (!empty($this->_content) or (isset($this->_translate[$this->_tuv][$this->_tu]) === false)) {
$this->_translate[$this->_tuv][$this->_tu] = $this->_content;
}
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Tmx";
}
}
Translate/Adapter/Csv.php 0000604 00000006277 15071256135 0011342 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Csv extends Zend_Translate_Adapter {
/**
* Generates the adapter
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options Options for this adapter
*/
public function __construct($data, $locale = null, array $options = array())
{
$this->_options['delimiter'] = ";";
$this->_options['length'] = 0;
$this->_options['enclosure'] = '"';
parent::__construct($data, $locale, $options);
}
/**
* Load translation data
*
* @param string|array $filename Filename and full path to the translation source
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param array $option OPTIONAL Options to use
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_file = @fopen($filename, 'rb');
if (!$this->_file) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
}
while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (isset($data[1]) !== true) {
continue;
}
$this->_translate[$locale][$data[0]] = $data[1];
}
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Csv";
}
}
Translate/Adapter/Gettext.php 0000604 00000013203 15071256135 0012216 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
// Internal variables
private $_bigEndian = false;
private $_file = false;
private $_adapterInfo = array();
/**
* Generates the adapter
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Read values from the MO file
*
* @param string $bytes
*/
private function _readMOData($bytes)
{
if ($this->_bigEndian === false) {
return unpack('V' . $bytes, fread($this->_file, 4 * $bytes));
} else {
return unpack('N' . $bytes, fread($this->_file, 4 * $bytes));
}
}
/**
* Load translation data (MO file reader)
*
* @param string $filename MO file to add, full path must be given for access
* @param string $locale New Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_bigEndian = false;
$options = $options + $this->_options;
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_file = @fopen($filename, 'rb');
if (!$this->_file) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
}
if (@filesize($filename) < 10) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
}
// get Endian
$input = $this->_readMOData(1);
if (strtolower(substr(dechex($input[1]), -8)) == "950412de") {
$this->_bigEndian = false;
} else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") {
$this->_bigEndian = true;
} else {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
}
// read revision - not supported for now
$input = $this->_readMOData(1);
// number of bytes
$input = $this->_readMOData(1);
$total = $input[1];
// number of original strings
$input = $this->_readMOData(1);
$OOffset = $input[1];
// number of translation strings
$input = $this->_readMOData(1);
$TOffset = $input[1];
// fill the original table
fseek($this->_file, $OOffset);
$origtemp = $this->_readMOData(2 * $total);
fseek($this->_file, $TOffset);
$transtemp = $this->_readMOData(2 * $total);
for($count = 0; $count < $total; ++$count) {
if ($origtemp[$count * 2 + 1] != 0) {
fseek($this->_file, $origtemp[$count * 2 + 2]);
$original = @fread($this->_file, $origtemp[$count * 2 + 1]);
} else {
$original = '';
}
if ($transtemp[$count * 2 + 1] != 0) {
fseek($this->_file, $transtemp[$count * 2 + 2]);
$this->_translate[$locale][$original] = fread($this->_file, $transtemp[$count * 2 + 1]);
}
}
$this->_translate[$locale][''] = trim($this->_translate[$locale]['']);
if (empty($this->_translate[$locale][''])) {
$this->_adapterInfo[$filename] = 'No adapter information available';
} else {
$this->_adapterInfo[$filename] = $this->_translate[$locale][''];
}
unset($this->_translate[$locale]['']);
}
/**
* Returns the adapter informations
*
* @return array Each loaded adapter information as array value
*/
public function getAdapterInfo()
{
return $this->_adapterInfo;
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Gettext";
}
}
Translate/Adapter/Ini.php 0000604 00000005266 15071256135 0011323 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Ini extends Zend_Translate_Adapter
{
/**
* Generates the adapter
*
* @param array $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data
*
* @param string|array $data
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to use
*/
protected function _loadTranslationData($data, $locale, array $options = array())
{
if (!file_exists($data)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("Ini file '".$data."' not found");
}
$inidata = parse_ini_file($data, false);
$options = array_merge($this->_options, $options);
if (($options['clear'] == true) || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_translate[$locale] = array_merge($this->_translate[$locale], $inidata);
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Ini";
}
}
Translate/Adapter/Tbx.php 0000604 00000014234 15071256135 0011334 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_langset = null;
private $_termentry = null;
private $_content = null;
private $_term = null;
/**
* Generates the tbx adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (TBX file reader)
*
* @param string $filename TBX file to add, full path must be given for access
* @param string $locale Locale has no effect for TBX because TBX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_term !== null) {
$this->_content .= "<".$name;
foreach($attrib as $key => $value) {
$this->_content .= " $key=\"$value\"";
}
$this->_content .= ">";
} else {
switch(strtolower($name)) {
case 'termentry':
$this->_termentry = null;
break;
case 'langset':
if (isset($attrib['xml:lang']) === true) {
$this->_langset = $attrib['xml:lang'];
if (isset($this->_translate[$this->_langset]) === false) {
$this->_translate[$this->_langset] = array();
}
}
break;
case 'term':
$this->_term = true;
$this->_content = null;
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_term !== null) and ($name != "term")) {
$this->_content .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'langset':
$this->_langset = null;
break;
case 'term':
$this->_term = null;
if (empty($this->_termentry)) {
$this->_termentry = $this->_content;
}
if (!empty($this->_content) or (isset($this->_translate[$this->_langset][$this->_termentry]) === false)) {
$this->_translate[$this->_langset][$this->_termentry] = $this->_content;
}
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if ($this->_term !== null) {
$this->_content .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Tbx";
}
}
Translate/Adapter/Xliff.php 0000604 00000017322 15071256135 0011650 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
// Internal variables
private $_file = false;
private $_cleared = array();
private $_transunit = null;
private $_source = null;
private $_target = null;
private $_scontent = null;
private $_tcontent = null;
private $_stag = false;
private $_ttag = false;
/**
* Generates the xliff adapter
* This adapter reads with php's xml_parser
*
* @param string $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data (XLIFF file reader)
*
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param string $filename XLIFF file to add, full path must be given for access
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = $options + $this->_options;
if ($options['clear']) {
$this->_translate = array();
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$encoding = $this->_findEncoding($filename);
$this->_target = $locale;
$this->_file = xml_parser_create($encoding);
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_file)),
xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
private function _startElement($file, $name, $attrib)
{
if ($this->_stag === true) {
$this->_scontent .= "<".$name;
foreach($attrib as $key => $value) {
$this->_scontent .= " $key=\"$value\"";
}
$this->_scontent .= ">";
} else if ($this->_ttag === true) {
$this->_tcontent .= "<".$name;
foreach($attrib as $key => $value) {
$this->_tcontent .= " $key=\"$value\"";
}
$this->_tcontent .= ">";
} else {
switch(strtolower($name)) {
case 'file':
$this->_source = $attrib['source-language'];
if (isset($attrib['target-language'])) {
$this->_target = $attrib['target-language'];
}
$this->_translate[$this->_source] = array();
$this->_translate[$this->_target] = array();
break;
case 'trans-unit':
$this->_transunit = true;
break;
case 'source':
if ($this->_transunit === true) {
$this->_scontent = null;
$this->_stag = true;
$this->_ttag = false;
}
break;
case 'target':
if ($this->_transunit === true) {
$this->_tcontent = null;
$this->_ttag = true;
$this->_stag = false;
}
break;
default:
break;
}
}
}
private function _endElement($file, $name)
{
if (($this->_stag === true) and ($name !== 'source')) {
$this->_scontent .= "</".$name.">";
} else if (($this->_ttag === true) and ($name !== 'target')) {
$this->_tcontent .= "</".$name.">";
} else {
switch (strtolower($name)) {
case 'trans-unit':
$this->_transunit = null;
$this->_scontent = null;
$this->_tcontent = null;
break;
case 'source':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
$this->_translate[$this->_source][$this->_scontent] = $this->_scontent;
}
$this->_stag = false;
break;
case 'target':
if (!empty($this->_scontent) and !empty($this->_tcontent) or
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
}
$this->_ttag = false;
break;
default:
break;
}
}
}
private function _contentElement($file, $data)
{
if (($this->_transunit !== null) and ($this->_source !== null) and ($this->_stag === true)) {
$this->_scontent .= $data;
}
if (($this->_transunit !== null) and ($this->_target !== null) and ($this->_ttag === true)) {
$this->_tcontent .= $data;
}
}
private function _findEncoding($filename)
{
$file = file_get_contents($filename, null, null, 0, 100);
if (strpos($file, "encoding") !== false) {
$encoding = substr($file, strpos($file, "encoding") + 9);
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
return $encoding;
}
return 'UTF-8';
}
/**
* Returns the adapter name
*
* @return string
*/
public function toString()
{
return "Xliff";
}
}
Translate/Adapter/Array.php 0000604 00000005473 15071256135 0011662 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Locale */
require_once 'Zend/Locale.php';
/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Adapter_Array extends Zend_Translate_Adapter {
/**
* Generates the adapter
*
* @param array $data Translation data
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to set
*/
public function __construct($data, $locale = null, array $options = array())
{
parent::__construct($data, $locale, $options);
}
/**
* Load translation data
*
* @param string|array $data
* @param string $locale Locale/Language to add data for, identical with locale identifier,
* see Zend_Locale for more information
* @param array $options OPTIONAL Options to use
*/
protected function _loadTranslationData($data, $locale, array $options = array())
{
if (!is_array($data)) {
if (file_exists($data)) {
ob_start();
$data = include($data);
ob_end_clean();
}
}
if (!is_array($data)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("Error including array or file '".$data."'");
}
$options = $options + $this->_options;
if (($options['clear'] == true) || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$this->_translate[$locale] = $data + $this->_translate[$locale];
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Array";
}
}
Translate/Adapter.php 0000604 00000054052 15071256135 0010601 0 ustar 00 <?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_Translate
* @subpackage Zend_Translate_Adapter
* @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: Date.php 2498 2006-12-23 22:13:38Z thomas $
*/
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
/**
* Basic adapter class for each translation source adapter
*
* @category Zend
* @package Zend_Translate
* @subpackage Zend_Translate_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Translate_Adapter {
/**
* Shows if locale detection is in automatic level
* @var boolean
*/
private $_automatic = true;
/**
* Internal cache for all adapters
* @var Zend_Cache_Core
*/
protected static $_cache = null;
/**
* Scans for the locale within the name of the directory
* @constant integer
*/
const LOCALE_DIRECTORY = 'directory';
/**
* Scans for the locale within the name of the file
* @constant integer
*/
const LOCALE_FILENAME = 'filename';
/**
* Array with all options, each adapter can have own additional options
* 'clear' => clears already loaded data when adding new files
* 'scan' => searches for translation files using the LOCALE constants
* 'locale' => the actual set locale to use
* @var array
*/
protected $_options = array(
'clear' => false,
'scan' => null,
'locale' => 'auto',
'ignore' => '.',
'disableNotices' => false,
);
/**
* Translation table
* @var array
*/
protected $_translate = array();
/**
* Generates the adapter
*
* @param string|array $data Translation data or filename for this adapter
* @param string|Zend_Locale $locale (optional) Locale/Language to set, identical with Locale
* identifiers see Zend_Locale for more information
* @param array $options (optional) Options for the adaptor
* @throws Zend_Translate_Exception
* @return void
*/
public function __construct($data, $locale = null, array $options = array())
{
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
$result = self::$_cache->load($id);
if ($result) {
$this->_options = unserialize($result);
}
}
if (($locale === "auto") or ($locale === null)) {
$this->_automatic = true;
} else {
$this->_automatic = false;
}
$this->addTranslation($data, $locale, $options);
$this->setLocale($locale);
}
/**
* Add translation data
*
* It may be a new language or additional data for existing language
* If $clear parameter is true, then translation data for specified
* language is replaced and added otherwise
*
* @param array|string $data Translation data
* @param string|Zend_Locale $locale (optional) Locale/Language to add data for, identical
* with locale identifier, see Zend_Locale for more information
* @param array $options (optional) Option for this Adapter
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
public function addTranslation($data, $locale = null, array $options = array())
{
$locale = $this->_getRegistryLocale($locale);
$originate = (string) $locale;
$this->setOptions($options);
if (is_string($data) and is_dir($data)) {
$data = realpath($data);
$prev = '';
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
$file = $info->getFilename();
if (strpos($directory, DIRECTORY_SEPARATOR . $this->_options['ignore']) !== false) {
// ignore files matching first characters from option 'ignore' and all files below
continue;
}
if ($info->isDir()) {
// pathname as locale
if (($this->_options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) {
if (strlen($prev) <= strlen($file)) {
$locale = $file;
$prev = (string) $locale;
}
}
} else if ($info->isFile()) {
// filename as locale
if ($this->_options['scan'] === self::LOCALE_FILENAME) {
$filename = explode('.', $file);
array_pop($filename);
$filename = implode('.', $filename);
if (Zend_Locale::isLocale((string) $filename, true, false)) {
$locale = (string) $filename;
} else {
$parts = explode('.', $file);
$parts2 = array();
foreach($parts as $token) {
$parts2 += explode('_', $token);
}
$parts = array_merge($parts, $parts2);
$parts2 = array();
foreach($parts as $token) {
$parts2 += explode('-', $token);
}
$parts = array_merge($parts, $parts2);
$parts = array_unique($parts);
$prev = '';
foreach($parts as $token) {
if (Zend_Locale::isLocale($token, true, false)) {
if (strlen($prev) <= strlen($token)) {
$locale = $token;
$prev = $token;
}
}
}
}
}
try {
$this->_addTranslationData($info->getPathname(), (string) $locale, $this->_options);
if ((isset($this->_translate[(string) $locale]) === true) and (count($this->_translate[(string) $locale]) > 0)) {
$this->setLocale($locale);
}
} catch (Zend_Translate_Exception $e) {
// ignore failed sources while scanning
}
}
}
} else {
$this->_addTranslationData($data, (string) $locale, $this->_options);
if ((isset($this->_translate[(string) $locale]) === true) and (count($this->_translate[(string) $locale]) > 0)) {
$this->setLocale($locale);
}
}
if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
$this->setLocale($originate);
}
return $this;
}
/**
* Sets new adapter options
*
* @param array $options Adapter options
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
public function setOptions(array $options = array())
{
$change = false;
foreach ($options as $key => $option) {
if ($key == "locale") {
$this->setLocale($option);
} else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
!isset($this->_options[$key])) {
$this->_options[$key] = $option;
$change = true;
}
}
if (isset(self::$_cache) and ($change == true)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
self::$_cache->save( serialize($this->_options), $id);
}
return $this;
}
/**
* Returns the adapters name and it's options
*
* @param string|null $optionKey String returns this option
* null returns all options
* @return integer|string|array|null
*/
public function getOptions($optionKey = null)
{
if ($optionKey === null) {
return $this->_options;
}
if (isset($this->_options[$optionKey]) === true) {
return $this->_options[$optionKey];
}
return null;
}
/**
* Gets locale
*
* @return Zend_Locale|string|null
*/
public function getLocale()
{
return $this->_options['locale'];
}
/**
* Sets locale
*
* @param string|Zend_Locale $locale Locale to set
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
public function setLocale($locale)
{
$locale = $this->_getRegistryLocale($locale);
if (($locale === "auto") or ($locale === null)) {
$this->_automatic = true;
} else {
$this->_automatic = false;
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
/**
* @see Zend_Translate_Exception
*/
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("The given Language ({$locale }) does not exist");
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if (!isset($this->_translate[$locale])) {
$temp = explode('_', $locale);
if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
// Should we suppress notices ?
if ($this->_options['disableNotices'] === false) {
// throwing a notice due to possible problems on locale setting
trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
}
}
$locale = $temp[0];
}
if (empty($this->_translate[$locale])) {
// Should we suppress notices ?
if ($this->_options['disableNotices'] === false) {
// throwing a notice due to possible problems on locale setting
trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE);
}
}
if ($this->_options['locale'] != $locale) {
$this->_options['locale'] = $locale;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
self::$_cache->save( serialize($this->_options), $id);
}
}
return $this;
}
/**
* Returns the available languages from this adapter
*
* @return array
*/
public function getList()
{
$list = array_keys($this->_translate);
$result = null;
foreach($list as $value) {
if (!empty($this->_translate[$value])) {
$result[$value] = $value;
}
}
return $result;
}
/**
* Returns all available message ids from this adapter
* If no locale is given, the actual language will be used
*
* @param string|Zend_Locale $locale (optional) Language to return the message ids from
* @return array
*/
public function getMessageIds($locale = null)
{
if (empty($locale) or !$this->isAvailable($locale)) {
$locale = $this->_options['locale'];
}
return array_keys($this->_translate[(string) $locale]);
}
/**
* Returns all available translations from this adapter
* If no locale is given, the actual language will be used
* If 'all' is given the complete translation dictionary will be returned
*
* @param string|Zend_Locale $locale (optional) Language to return the messages from
* @return array
*/
public function getMessages($locale = null)
{
if ($locale === 'all') {
return $this->_translate;
}
if ((empty($locale) === true) or ($this->isAvailable($locale) === false)) {
$locale = $this->_options['locale'];
}
return $this->_translate[(string) $locale];
}
/**
* Is the wished language available ?
*
* @see Zend_Locale
* @param string|Zend_Locale $locale Language to search for, identical with locale identifier,
* @see Zend_Locale for more information
* @return boolean
*/
public function isAvailable($locale)
{
$return = isset($this->_translate[(string) $locale]);
return $return;
}
/**
* Load translation data
*
* @param mixed $data
* @param string|Zend_Locale $locale
* @param array $options (optional)
* @return void
*/
abstract protected function _loadTranslationData($data, $locale, array $options = array());
/**
* Internal function for adding translation data
*
* It may be a new language or additional data for existing language
* If $clear parameter is true, then translation data for specified
* language is replaced and added otherwise
*
* @see Zend_Locale
* @param array|string $data Translation data
* @param string|Zend_Locale $locale Locale/Language to add data for, identical with locale identifier,
* @see Zend_Locale for more information
* @param array $options (optional) Option for this Adapter
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
private function _addTranslationData($data, $locale, array $options = array())
{
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
/**
* @see Zend_Translate_Exception
*/
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if (isset($this->_translate[$locale]) === false) {
$this->_translate[$locale] = array();
}
$read = true;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
$result = self::$_cache->load($id);
if ($result) {
$this->_translate[$locale] = unserialize($result);
$read = false;
}
}
if ($read) {
$this->_loadTranslationData($data, $locale, $options);
}
if ($this->_automatic === true) {
$find = new Zend_Locale($locale);
$browser = $find->getEnvironment() + $find->getBrowser();
arsort($browser);
foreach($browser as $language => $quality) {
if (isset($this->_translate[$language]) === true) {
$this->_options['locale'] = $language;
break;
}
}
}
if (($read) and (isset(self::$_cache))) {
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
self::$_cache->save( serialize($this->_translate[$locale]), $id);
}
return $this;
}
/**
* Translates the given string
* returns the translation
*
* @see Zend_Locale
* @param string $messageId Translation string
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
* locale identifier, @see Zend_Locale for more information
* @return string
*/
public function translate($messageId, $locale = null)
{
if ($locale === null) {
$locale = $this->_options['locale'];
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
// language does not exist, return original string
return $messageId;
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if (isset($this->_translate[$locale][$messageId]) === true) {
// return original translation
return $this->_translate[$locale][$messageId];
} else if (strlen($locale) != 2) {
// faster than creating a new locale and separate the leading part
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
if (isset($this->_translate[$locale][$messageId]) === true) {
// return regionless translation (en_US -> en)
return $this->_translate[$locale][$messageId];
}
}
// no translation found, return original
return $messageId;
}
/**
* Translates the given string
* returns the translation
*
* @param string $messageId Translation string
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale
* identifier, @see Zend_Locale for more information
* @return string
*/
public function _($messageId, $locale = null)
{
return $this->translate($messageId, $locale);
}
/**
* Checks if a string is translated within the source or not
* returns boolean
*
* @param string $messageId Translation string
* @param boolean $original (optional) Allow translation only for original language
* when true, a translation for 'en_US' would give false when it can
* be translated with 'en' only
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier,
* see Zend_Locale for more information
* @return boolean
*/
public function isTranslated($messageId, $original = false, $locale = null)
{
if (($original !== false) and ($original !== true)) {
$locale = $original;
$original = false;
}
if ($locale === null) {
$locale = $this->_options['locale'];
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
// language does not exist, return original string
return false;
}
$locale = new Zend_Locale();
}
$locale = (string) $locale;
if (isset($this->_translate[$locale][$messageId]) === true) {
// return original translation
return true;
} else if ((strlen($locale) != 2) and ($original === false)) {
// faster than creating a new locale and separate the leading part
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
if (isset($this->_translate[$locale][$messageId]) === true) {
// return regionless translation (en_US -> en)
return true;
}
}
// No translation found, return original
return false;
}
/**
* Returns the set cache
*
* @return Zend_Cache_Core The set cache
*/
public static function getCache()
{
return self::$_cache;
}
/**
* Sets a cache for all Zend_Translate_Adapters
*
* @param Zend_Cache_Core $cache Cache to store to
*/
public static function setCache(Zend_Cache_Core $cache)
{
self::$_cache = $cache;
}
/**
* Returns true when a cache is set
*
* @return boolean
*/
public static function hasCache()
{
if (self::$_cache !== null) {
return true;
}
return false;
}
/**
* Removes any set cache
*
* @return void
*/
public static function removeCache()
{
self::$_cache = null;
}
/**
* Clears all set cache data
*
* @return void
*/
public static function clearCache()
{
self::$_cache->clean();
}
/**
* Evaluates the locale from registry or auto
*
* @param string|Zend_Locale $locale
* @return string
*/
private function _getRegistryLocale($locale)
{
if (empty($locale)) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale') === true) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
if ($locale === null) {
$locale = new Zend_Locale();
}
return $locale;
}
/**
* Returns the adapter name
*
* @return string
*/
abstract public function toString();
} Translate/Exception.php 0000604 00000002111 15071256135 0011144 0 ustar 00 <?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_Translate
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 1653 2006-11-16 19:53:38Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Translate
* @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_Translate_Exception extends Zend_Exception
{
}
Uri/Http.php 0000604 00000054605 15071256135 0006746 0 ustar 00 <?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_Uri
* @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: Http.php 12041 2008-10-20 22:13:01Z shahar $
*/
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* @see Zend_Validate_Hostname
*/
require_once 'Zend/Validate/Hostname.php';
/**
* HTTP(S) URI handler
*
* @category Zend
* @package Zend_Uri
* @uses Zend_Uri
* @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_Uri_Http extends Zend_Uri
{
/**
* Character classes for validation regular expressions
*/
const CHAR_ALNUM = 'A-Za-z0-9';
const CHAR_MARK = '-_.!~*\'()\[\]';
const CHAR_RESERVED = ';\/?:@&=+$,';
const CHAR_SEGMENT = ':@&=+$,;';
const CHAR_UNWISE = '{}|\\\\^`';
/**
* HTTP username
*
* @var string
*/
protected $_username = '';
/**
* HTTP password
*
* @var string
*/
protected $_password = '';
/**
* HTTP host
*
* @var string
*/
protected $_host = '';
/**
* HTTP post
*
* @var string
*/
protected $_port = '';
/**
* HTTP part
*
* @var string
*/
protected $_path = '';
/**
* HTTP query
*
* @var string
*/
protected $_query = '';
/**
* HTTP fragment
*
* @var string
*/
protected $_fragment = '';
/**
* Regular expression grammar rules for validation; values added by constructor
*
* @var array
*/
protected $_regex = array();
/**
* Constructor accepts a string $scheme (e.g., http, https) and a scheme-specific part of the URI
* (e.g., example.com/path/to/resource?query=param#fragment)
*
* @param string $scheme The scheme of the URI
* @param string $schemeSpecific The scheme-specific part of the URI
* @throws Zend_Uri_Exception When the URI is not valid
*/
protected function __construct($scheme, $schemeSpecific = '')
{
// Set the scheme
$this->_scheme = $scheme;
// Set up grammar rules for validation via regular expressions. These
// are to be used with slash-delimited regular expression strings.
// Escaped special characters (eg. '%25' for '%')
$this->_regex['escaped'] = '%[[:xdigit:]]{2}';
// Unreserved characters
$this->_regex['unreserved'] = '[' . self::CHAR_ALNUM . self::CHAR_MARK . ']';
// Segment can use escaped, unreserved or a set of additional chars
$this->_regex['segment'] = '(?:' . $this->_regex['escaped'] . '|[' .
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_SEGMENT . '])*';
// Path can be a series of segmets char strings seperated by '/'
$this->_regex['path'] = '(?:\/(?:' . $this->_regex['segment'] . ')?)+';
// URI characters can be escaped, alphanumeric, mark or reserved chars
$this->_regex['uric'] = '(?:' . $this->_regex['escaped'] . '|[' .
self::CHAR_ALNUM . self::CHAR_MARK . self::CHAR_RESERVED .
// If unwise chars are allowed, add them to the URI chars class
(self::$_config['allow_unwise'] ? self::CHAR_UNWISE : '') . '])';
// If no scheme-specific part was supplied, the user intends to create
// a new URI with this object. No further parsing is required.
if (strlen($schemeSpecific) === 0) {
return;
}
// Parse the scheme-specific URI parts into the instance variables.
$this->_parseUri($schemeSpecific);
// Validate the URI
if ($this->valid() === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Invalid URI supplied');
}
}
/**
* Creates a Zend_Uri_Http from the given string
*
* @param string $uri String to create URI from, must start with
* 'http://' or 'https://'
* @throws InvalidArgumentException When the given $uri is not a string or
* does not start with http:// or https://
* @throws Zend_Uri_Exception When the given $uri is invalid
* @return Zend_Uri_Http
*/
public static function fromString($uri)
{
if (is_string($uri) === false) {
throw new InvalidArgumentException('$uri is not a string');
}
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
if (in_array($scheme, array('http', 'https')) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Invalid scheme: '$scheme'");
}
$schemeHandler = new Zend_Uri_Http($scheme, $schemeSpecific);
return $schemeHandler;
}
/**
* Parse the scheme-specific portion of the URI and place its parts into instance variables.
*
* @param string $schemeSpecific The scheme-specific portion to parse
* @throws Zend_Uri_Exception When scheme-specific decoposition fails
* @throws Zend_Uri_Exception When authority decomposition fails
* @return void
*/
protected function _parseUri($schemeSpecific)
{
// High-level decomposition parser
$pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
$status = @preg_match($pattern, $schemeSpecific, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: scheme-specific decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save URI components that need no further decomposition
$this->_path = isset($matches[4]) === true ? $matches[4] : '';
$this->_query = isset($matches[6]) === true ? $matches[6] : '';
$this->_fragment = isset($matches[8]) === true ? $matches[8] : '';
// Additional decomposition to get username, password, host, and port
$combo = isset($matches[3]) === true ? $matches[3] : '';
$pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
$status = @preg_match($pattern, $combo, $matches);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: authority decomposition failed');
}
// Failed decomposition; no further processing needed
if ($status === false) {
return;
}
// Save remaining URI components
$this->_username = isset($matches[2]) === true ? $matches[2] : '';
$this->_password = isset($matches[4]) === true ? $matches[4] : '';
$this->_host = isset($matches[5]) === true ? $matches[5] : '';
$this->_port = isset($matches[7]) === true ? $matches[7] : '';
}
/**
* Returns a URI based on current values of the instance variables. If any
* part of the URI does not pass validation, then an exception is thrown.
*
* @throws Zend_Uri_Exception When one or more parts of the URI are invalid
* @return string
*/
public function getUri()
{
if ($this->valid() === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('One or more parts of the URI are invalid');
}
$password = strlen($this->_password) > 0 ? ":$this->_password" : '';
$auth = strlen($this->_username) > 0 ? "$this->_username$password@" : '';
$port = strlen($this->_port) > 0 ? ":$this->_port" : '';
$query = strlen($this->_query) > 0 ? "?$this->_query" : '';
$fragment = strlen($this->_fragment) > 0 ? "#$this->_fragment" : '';
return $this->_scheme
. '://'
. $auth
. $this->_host
. $port
. $this->_path
. $query
. $fragment;
}
/**
* Validate the current URI from the instance variables. Returns true if and only if all
* parts pass validation.
*
* @return boolean
*/
public function valid()
{
// Return true if and only if all parts of the URI have passed validation
return $this->validateUsername()
and $this->validatePassword()
and $this->validateHost()
and $this->validatePort()
and $this->validatePath()
and $this->validateQuery()
and $this->validateFragment();
}
/**
* Returns the username portion of the URL, or FALSE if none.
*
* @return string
*/
public function getUsername()
{
return strlen($this->_username) > 0 ? $this->_username : false;
}
/**
* Returns true if and only if the username passes validation. If no username is passed,
* then the username contained in the instance variable is used.
*
* @param string $username The HTTP username
* @throws Zend_Uri_Exception When username validation fails
* @return boolean
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
public function validateUsername($username = null)
{
if ($username === null) {
$username = $this->_username;
}
// If the username is empty, then it is considered valid
if (strlen($username) === 0) {
return true;
}
// Check the username against the allowed values
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $username);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: username validation failed');
}
return $status === 1;
}
/**
* Sets the username for the current URI, and returns the old username
*
* @param string $username The HTTP username
* @throws Zend_Uri_Exception When $username is not a valid HTTP username
* @return string
*/
public function setUsername($username)
{
if ($this->validateUsername($username) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Username \"$username\" is not a valid HTTP username");
}
$oldUsername = $this->_username;
$this->_username = $username;
return $oldUsername;
}
/**
* Returns the password portion of the URL, or FALSE if none.
*
* @return string
*/
public function getPassword()
{
return strlen($this->_password) > 0 ? $this->_password : false;
}
/**
* Returns true if and only if the password passes validation. If no password is passed,
* then the password contained in the instance variable is used.
*
* @param string $password The HTTP password
* @throws Zend_Uri_Exception When password validation fails
* @return boolean
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
public function validatePassword($password = null)
{
if ($password === null) {
$password = $this->_password;
}
// If the password is empty, then it is considered valid
if (strlen($password) === 0) {
return true;
}
// If the password is nonempty, but there is no username, then it is considered invalid
if (strlen($password) > 0 and strlen($this->_username) === 0) {
return false;
}
// Check the password against the allowed values
$status = @preg_match('/^(?:' . $this->_regex['escaped'] . '|[' .
self::CHAR_ALNUM . self::CHAR_MARK . ';:&=+$,' . '])+$/', $password);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: password validation failed.');
}
return $status == 1;
}
/**
* Sets the password for the current URI, and returns the old password
*
* @param string $password The HTTP password
* @throws Zend_Uri_Exception When $password is not a valid HTTP password
* @return string
*/
public function setPassword($password)
{
if ($this->validatePassword($password) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Password \"$password\" is not a valid HTTP password.");
}
$oldPassword = $this->_password;
$this->_password = $password;
return $oldPassword;
}
/**
* Returns the domain or host IP portion of the URL, or FALSE if none.
*
* @return string
*/
public function getHost()
{
return strlen($this->_host) > 0 ? $this->_host : false;
}
/**
* Returns true if and only if the host string passes validation. If no host is passed,
* then the host contained in the instance variable is used.
*
* @param string $host The HTTP host
* @return boolean
* @uses Zend_Filter
*/
public function validateHost($host = null)
{
if ($host === null) {
$host = $this->_host;
}
// If the host is empty, then it is considered invalid
if (strlen($host) === 0) {
return false;
}
// Check the host against the allowed values; delegated to Zend_Filter.
$validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
return $validate->isValid($host);
}
/**
* Sets the host for the current URI, and returns the old host
*
* @param string $host The HTTP host
* @throws Zend_Uri_Exception When $host is nota valid HTTP host
* @return string
*/
public function setHost($host)
{
if ($this->validateHost($host) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Host \"$host\" is not a valid HTTP host");
}
$oldHost = $this->_host;
$this->_host = $host;
return $oldHost;
}
/**
* Returns the TCP port, or FALSE if none.
*
* @return string
*/
public function getPort()
{
return strlen($this->_port) > 0 ? $this->_port : false;
}
/**
* Returns true if and only if the TCP port string passes validation. If no port is passed,
* then the port contained in the instance variable is used.
*
* @param string $port The HTTP port
* @return boolean
*/
public function validatePort($port = null)
{
if ($port === null) {
$port = $this->_port;
}
// If the port is empty, then it is considered valid
if (strlen($port) === 0) {
return true;
}
// Check the port against the allowed values
return ctype_digit((string) $port) and 1 <= $port and $port <= 65535;
}
/**
* Sets the port for the current URI, and returns the old port
*
* @param string $port The HTTP port
* @throws Zend_Uri_Exception When $port is not a valid HTTP port
* @return string
*/
public function setPort($port)
{
if ($this->validatePort($port) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Port \"$port\" is not a valid HTTP port.");
}
$oldPort = $this->_port;
$this->_port = $port;
return $oldPort;
}
/**
* Returns the path and filename portion of the URL, or FALSE if none.
*
* @return string
*/
public function getPath()
{
return strlen($this->_path) > 0 ? $this->_path : '/';
}
/**
* Returns true if and only if the path string passes validation. If no path is passed,
* then the path contained in the instance variable is used.
*
* @param string $path The HTTP path
* @throws Zend_Uri_Exception When path validation fails
* @return boolean
*/
public function validatePath($path = null)
{
if ($path === null) {
$path = $this->_path;
}
// If the path is empty, then it is considered valid
if (strlen($path) === 0) {
return true;
}
// Determine whether the path is well-formed
$pattern = '/^' . $this->_regex['path'] . '$/';
$status = @preg_match($pattern, $path);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: path validation failed');
}
return (boolean) $status;
}
/**
* Sets the path for the current URI, and returns the old path
*
* @param string $path The HTTP path
* @throws Zend_Uri_Exception When $path is not a valid HTTP path
* @return string
*/
public function setPath($path)
{
if ($this->validatePath($path) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Path \"$path\" is not a valid HTTP path");
}
$oldPath = $this->_path;
$this->_path = $path;
return $oldPath;
}
/**
* Returns the query portion of the URL (after ?), or FALSE if none.
*
* @return string
*/
public function getQuery()
{
return strlen($this->_query) > 0 ? $this->_query : false;
}
/**
* Returns true if and only if the query string passes validation. If no query is passed,
* then the query string contained in the instance variable is used.
*
* @param string $query The query to validate
* @throws Zend_Uri_Exception When query validation fails
* @return boolean
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
public function validateQuery($query = null)
{
if ($query === null) {
$query = $this->_query;
}
// If query is empty, it is considered to be valid
if (strlen($query) === 0) {
return true;
}
// Determine whether the query is well-formed
$pattern = '/^' . $this->_regex['uric'] . '*$/';
$status = @preg_match($pattern, $query);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: query validation failed');
}
return $status == 1;
}
/**
* Set the query string for the current URI, and return the old query
* string This method accepts both strings and arrays.
*
* @param string|array $query The query string or array
* @throws Zend_Uri_Exception When $query is not a valid query string
* @return string Old query string
*/
public function setQuery($query)
{
$oldQuery = $this->_query;
// If query is empty, set an empty string
if (empty($query) === true) {
$this->_query = '';
return $oldQuery;
}
// If query is an array, make a string out of it
if (is_array($query) === true) {
$query = http_build_query($query, '', '&');
} else {
// If it is a string, make sure it is valid. If not parse and encode it
$query = (string) $query;
if ($this->validateQuery($query) === false) {
parse_str($query, $queryArray);
$query = http_build_query($queryArray, '', '&');
}
}
// Make sure the query is valid, and set it
if ($this->validateQuery($query) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("'$query' is not a valid query string");
}
$this->_query = $query;
return $oldQuery;
}
/**
* Returns the fragment portion of the URL (after #), or FALSE if none.
*
* @return string|false
*/
public function getFragment()
{
return strlen($this->_fragment) > 0 ? $this->_fragment : false;
}
/**
* Returns true if and only if the fragment passes validation. If no fragment is passed,
* then the fragment contained in the instance variable is used.
*
* @param string $fragment Fragment of an URI
* @throws Zend_Uri_Exception When fragment validation fails
* @return boolean
* @link http://www.faqs.org/rfcs/rfc2396.html
*/
public function validateFragment($fragment = null)
{
if ($fragment === null) {
$fragment = $this->_fragment;
}
// If fragment is empty, it is considered to be valid
if (strlen($fragment) === 0) {
return true;
}
// Determine whether the fragment is well-formed
$pattern = '/^' . $this->_regex['uric'] . '*$/';
$status = @preg_match($pattern, $fragment);
if ($status === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Internal error: fragment validation failed');
}
return (boolean) $status;
}
/**
* Sets the fragment for the current URI, and returns the old fragment
*
* @param string $fragment Fragment of the current URI
* @throws Zend_Uri_Exception When $fragment is not a valid HTTP fragment
* @return string
*/
public function setFragment($fragment)
{
if ($this->validateFragment($fragment) === false) {
require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Fragment \"$fragment\" is not a valid HTTP fragment");
}
$oldFragment = $this->_fragment;
$this->_fragment = $fragment;
return $oldFragment;
}
}
Uri/Exception.php 0000604 00000002120 15071256135 0007746 0 ustar 00 <?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_Uri
* @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 9656 2008-06-10 16:21:13Z dasprid $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Exceptions for Zend_Uri
*
* @category Zend
* @package Zend_Uri
* @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_Uri_Exception extends Zend_Exception
{
}
Layout/Exception.php 0000604 00000001767 15071256135 0010504 0 ustar 00 <?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_Layout
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Layout
* @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_Layout_Exception extends Zend_Exception
{}
Layout/Controller/Plugin/Layout.php 0000604 00000010270 15071256135 0013371 0 ustar 00 <?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_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';
/**
* Render layouts
*
* @uses Zend_Controller_Plugin_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Plugins
* @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: Layout.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Layout_Controller_Plugin_Layout extends Zend_Controller_Plugin_Abstract
{
protected $_layoutActionHelper = null;
/**
* @var Zend_Layout
*/
protected $_layout;
/**
* Constructor
*
* @param Zend_Layout $layout
* @return void
*/
public function __construct(Zend_Layout $layout = null)
{
if (null !== $layout) {
$this->setLayout($layout);
}
}
/**
* Retrieve layout object
*
* @return Zend_Layout
*/
public function getLayout()
{
return $this->_layout;
}
/**
* Set layout object
*
* @param Zend_Layout $layout
* @return Zend_Layout_Controller_Plugin_Layout
*/
public function setLayout(Zend_Layout $layout)
{
$this->_layout = $layout;
return $this;
}
/**
* Set layout action helper
*
* @param Zend_Layout_Controller_Action_Helper_Layout $layoutActionHelper
* @return Zend_Layout_Controller_Plugin_Layout
*/
public function setLayoutActionHelper(Zend_Layout_Controller_Action_Helper_Layout $layoutActionHelper)
{
$this->_layoutActionHelper = $layoutActionHelper;
return $this;
}
/**
* Retrieve layout action helper
*
* @return Zend_Layout_Controller_Action_Helper_Layout
*/
public function getLayoutActionHelper()
{
return $this->_layoutActionHelper;
}
/**
* postDispatch() plugin hook -- render layout
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = $this->getLayout();
$helper = $this->getLayoutActionHelper();
// Return early if forward detected
if (!$request->isDispatched()
|| ($layout->getMvcSuccessfulActionOnly()
&& (!empty($helper) && !$helper->isActionControllerSuccessful())))
{
return;
}
// Return early if layout has been disabled
if (!$layout->isEnabled()) {
return;
}
$response = $this->getResponse();
$content = $response->getBody(true);
$contentKey = $layout->getContentKey();
if (isset($content['default'])) {
$content[$contentKey] = $content['default'];
}
if ('default' != $contentKey) {
unset($content['default']);
}
$layout->assign($content);
$fullContent = null;
$obStartLevel = ob_get_level();
try {
$fullContent = $layout->render();
$response->setBody($fullContent);
} catch (Exception $e) {
while (ob_get_level() > $obStartLevel) {
$fullContent .= ob_get_clean();
}
$request->setParam('layoutFullContent', $fullContent);
$request->setParam('layoutContent', $layout->content);
$response->setBody(null);
throw $e;
}
}
}
Layout/Controller/Action/Helper/Layout.php 0000604 00000011515 15071256135 0014572 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Layout.php 11508 2008-09-24 14:21:30Z doctorrock83 $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Action_Helper_Abstract */
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Helper for interacting with Zend_Layout objects
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action
* @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_Layout_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* @var Zend_Layout
*/
protected $_layout;
/**
* @var bool
*/
protected $_isActionControllerSuccessful = false;
/**
* Constructor
*
* @param Zend_Layout $layout
* @return void
*/
public function __construct(Zend_Layout $layout = null)
{
if (null !== $layout) {
$this->setLayoutInstance($layout);
} else {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
$layout = Zend_Layout::getMvcInstance();
}
if (null !== $layout) {
$pluginClass = $layout->getPluginClass();
$front = $this->getFrontController();
if ($front->hasPlugin($pluginClass)) {
$plugin = $front->getPlugin($pluginClass);
$plugin->setLayoutActionHelper($this);
}
}
}
public function init()
{
$this->_isActionControllerSuccessful = false;
}
/**
* Get front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_frontController) {
/**
* @see Zend_Controller_Front
*/
require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
/**
* Get layout object
*
* @return Zend_Layout
*/
public function getLayoutInstance()
{
if (null === $this->_layout) {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
if (null === ($this->_layout = Zend_Layout::getMvcInstance())) {
$this->_layout = new Zend_Layout();
}
}
return $this->_layout;
}
/**
* Set layout object
*
* @param Zend_Layout $layout
* @return Zend_Layout_Controller_Action_Helper_Layout
*/
public function setLayoutInstance(Zend_Layout $layout)
{
$this->_layout = $layout;
return $this;
}
/**
* Mark Action Controller (according to this plugin) as Running successfully
*
* @return Zend_Layout_Controller_Action_Helper_Layout
*/
public function postDispatch()
{
$this->_isActionControllerSuccessful = true;
return $this;
}
/**
* Did the previous action successfully complete?
*
* @return bool
*/
public function isActionControllerSuccessful()
{
return $this->_isActionControllerSuccessful;
}
/**
* Strategy pattern; call object as method
*
* Returns layout object
*
* @return Zend_Layout
*/
public function direct()
{
return $this->getLayoutInstance();
}
/**
* Proxy method calls to layout object
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
$layout = $this->getLayoutInstance();
if (method_exists($layout, $method)) {
return call_user_func_array(array($layout, $method), $args);
}
require_once 'Zend/Layout/Exception.php';
throw new Zend_Layout_Exception(sprintf("Invalid method '%s' called on layout action helper", $method));
}
}
Log.php 0000604 00000015535 15071256135 0006010 0 ustar 00 <?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_Log
* @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: Log.php 13459 2008-12-26 14:13:34Z yoshida@zend.co.jp $
*/
/**
* @category Zend
* @package Zend_Log
* @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: Log.php 13459 2008-12-26 14:13:34Z yoshida@zend.co.jp $
*/
class Zend_Log
{
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages
/**
* @var array of priorities where the keys are the
* priority numbers and the values are the priority names
*/
protected $_priorities = array();
/**
* @var array of Zend_Log_Writer_Abstract
*/
protected $_writers = array();
/**
* @var array of Zend_Log_Filter_Interface
*/
protected $_filters = array();
/**
* @var array of extra log event
*/
protected $_extras = array();
/**
* Class constructor. Create a new logger
*
* @param Zend_Log_Writer_Abstract|null $writer default writer
*/
public function __construct(Zend_Log_Writer_Abstract $writer = null)
{
$r = new ReflectionClass($this);
$this->_priorities = array_flip($r->getConstants());
if ($writer !== null) {
$this->addWriter($writer);
}
}
/**
* Class destructor. Shutdown log writers
*
* @return void
*/
public function __destruct()
{
foreach($this->_writers as $writer) {
$writer->shutdown();
}
}
/**
* Undefined method handler allows a shortcut:
* $log->priorityName('message')
* instead of
* $log->log('message', Zend_Log::PRIORITY_NAME)
*
* @param string $method priority name
* @param string $params message to log
* @return void
* @throws Zend_Log_Exception
*/
public function __call($method, $params)
{
$priority = strtoupper($method);
if (($priority = array_search($priority, $this->_priorities)) !== false) {
$this->log(array_shift($params), $priority);
} else {
/** @see Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Bad log priority');
}
}
/**
* Log a message at a priority
*
* @param string $message Message to log
* @param integer $priority Priority of message
* @return void
* @throws Zend_Log_Exception
*/
public function log($message, $priority)
{
// sanity checks
if (empty($this->_writers)) {
/** @see Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('No writers were added');
}
if (! isset($this->_priorities[$priority])) {
/** @see Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Bad log priority');
}
// pack into event required by filters and writers
$event = array_merge(array('timestamp' => date('c'),
'message' => $message,
'priority' => $priority,
'priorityName' => $this->_priorities[$priority]),
$this->_extras);
// abort if rejected by the global filters
foreach ($this->_filters as $filter) {
if (! $filter->accept($event)) {
return;
}
}
// send to each writer
foreach ($this->_writers as $writer) {
$writer->write($event);
}
}
/**
* Add a custom priority
*
* @param string $name Name of priority
* @param integer $priority Numeric priority
* @throws Zend_Log_InvalidArgumentException
*/
public function addPriority($name, $priority)
{
// Priority names must be uppercase for predictability.
$name = strtoupper($name);
if (isset($this->_priorities[$priority])
|| array_search($name, $this->_priorities)) {
/** @see Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Existing priorities cannot be overwritten');
}
$this->_priorities[$priority] = $name;
}
/**
* Add a filter that will be applied before all log writers.
* Before a message will be received by any of the writers, it
* must be accepted by all filters added with this method.
*
* @param int|Zend_Log_Filter_Interface $filter
* @return void
*/
public function addFilter($filter)
{
if (is_integer($filter)) {
/** @see Zend_Log_Filter_Priority */
require_once 'Zend/Log/Filter/Priority.php';
$filter = new Zend_Log_Filter_Priority($filter);
} elseif(!is_object($filter) || ! $filter instanceof Zend_Log_Filter_Interface) {
/** @see Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Invalid filter provided');
}
$this->_filters[] = $filter;
}
/**
* Add a writer. A writer is responsible for taking a log
* message and writing it out to storage.
*
* @param Zend_Log_Writer_Abstract $writer
* @return void
*/
public function addWriter(Zend_Log_Writer_Abstract $writer)
{
$this->_writers[] = $writer;
}
/**
* Set an extra item to pass to the log writers.
*
* @param $name Name of the field
* @param $value Value of the field
* @return void
*/
public function setEventItem($name, $value) {
$this->_extras = array_merge($this->_extras, array($name => $value));
}
}
Ldap/Exception.php 0000604 00000015265 15071256135 0010105 0 ustar 00 <?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_Ldap
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
class Zend_Ldap_Exception extends Zend_Exception
{
const LDAP_SUCCESS = 0x00;
const LDAP_OPERATIONS_ERROR = 0x01;
const LDAP_PROTOCOL_ERROR = 0x02;
const LDAP_TIMELIMIT_EXCEEDED = 0x03;
const LDAP_SIZELIMIT_EXCEEDED = 0x04;
const LDAP_COMPARE_FALSE = 0x05;
const LDAP_COMPARE_TRUE = 0x06;
const LDAP_AUTH_METHOD_NOT_SUPPORTED = 0x07;
const LDAP_STRONG_AUTH_REQUIRED = 0x08;
const LDAP_PARTIAL_RESULTS = 0x09;
const LDAP_REFERRAL = 0x0a;
const LDAP_ADMINLIMIT_EXCEEDED = 0x0b;
const LDAP_UNAVAILABLE_CRITICAL_EXTENSION = 0x0c;
const LDAP_CONFIDENTIALITY_REQUIRED = 0x0d;
const LDAP_SASL_BIND_IN_PROGRESS = 0x0e;
const LDAP_NO_SUCH_ATTRIBUTE = 0x10;
const LDAP_UNDEFINED_TYPE = 0x11;
const LDAP_INAPPROPRIATE_MATCHING = 0x12;
const LDAP_CONSTRAINT_VIOLATION = 0x13;
const LDAP_TYPE_OR_VALUE_EXISTS = 0x14;
const LDAP_INVALID_SYNTAX = 0x15;
const LDAP_NO_SUCH_OBJECT = 0x20;
const LDAP_ALIAS_PROBLEM = 0x21;
const LDAP_INVALID_DN_SYNTAX = 0x22;
const LDAP_IS_LEAF = 0x23;
const LDAP_ALIAS_DEREF_PROBLEM = 0x24;
const LDAP_PROXY_AUTHZ_FAILURE = 0x2F;
const LDAP_INAPPROPRIATE_AUTH = 0x30;
const LDAP_INVALID_CREDENTIALS = 0x31;
const LDAP_INSUFFICIENT_ACCESS = 0x32;
const LDAP_BUSY = 0x33;
const LDAP_UNAVAILABLE = 0x34;
const LDAP_UNWILLING_TO_PERFORM = 0x35;
const LDAP_LOOP_DETECT = 0x36;
const LDAP_NAMING_VIOLATION = 0x40;
const LDAP_OBJECT_CLASS_VIOLATION = 0x41;
const LDAP_NOT_ALLOWED_ON_NONLEAF = 0x42;
const LDAP_NOT_ALLOWED_ON_RDN = 0x43;
const LDAP_ALREADY_EXISTS = 0x44;
const LDAP_NO_OBJECT_CLASS_MODS = 0x45;
const LDAP_RESULTS_TOO_LARGE = 0x46;
const LDAP_AFFECTS_MULTIPLE_DSAS = 0x47;
const LDAP_OTHER = 0x50;
const LDAP_SERVER_DOWN = 0x51;
const LDAP_LOCAL_ERROR = 0x52;
const LDAP_ENCODING_ERROR = 0x53;
const LDAP_DECODING_ERROR = 0x54;
const LDAP_TIMEOUT = 0x55;
const LDAP_AUTH_UNKNOWN = 0x56;
const LDAP_FILTER_ERROR = 0x57;
const LDAP_USER_CANCELLED = 0x58;
const LDAP_PARAM_ERROR = 0x59;
const LDAP_NO_MEMORY = 0x5a;
const LDAP_CONNECT_ERROR = 0x5b;
const LDAP_NOT_SUPPORTED = 0x5c;
const LDAP_CONTROL_NOT_FOUND = 0x5d;
const LDAP_NO_RESULTS_RETURNED = 0x5e;
const LDAP_MORE_RESULTS_TO_RETURN = 0x5f;
const LDAP_CLIENT_LOOP = 0x60;
const LDAP_REFERRAL_LIMIT_EXCEEDED = 0x61;
const LDAP_CUP_RESOURCES_EXHAUSTED = 0x71;
const LDAP_CUP_SECURITY_VIOLATION = 0x72;
const LDAP_CUP_INVALID_DATA = 0x73;
const LDAP_CUP_UNSUPPORTED_SCHEME = 0x74;
const LDAP_CUP_RELOAD_REQUIRED = 0x75;
const LDAP_CANCELLED = 0x76;
const LDAP_NO_SUCH_OPERATION = 0x77;
const LDAP_TOO_LATE = 0x78;
const LDAP_CANNOT_CANCEL = 0x79;
const LDAP_ASSERTION_FAILED = 0x7A;
const LDAP_SYNC_REFRESH_REQUIRED = 0x1000;
const LDAP_X_SYNC_REFRESH_REQUIRED = 0x4100;
const LDAP_X_NO_OPERATION = 0x410e;
const LDAP_X_ASSERTION_FAILED = 0x410f;
const LDAP_X_NO_REFERRALS_FOUND = 0x4110;
const LDAP_X_CANNOT_CHAIN = 0x4111;
/* internal error code constants */
const LDAP_X_DOMAIN_MISMATCH = 0x7001;
/**
* @param mixed $ldap A Zend_Ldap object or raw LDAP context resource
* @param string $str An informtive exception message
* @param int $code An LDAP error code
*/
public function __construct($ldap = null, $str = null, $code = 0)
{
$resource = null;
if (is_resource($ldap)) {
$resource = $ldap;
} else if (is_object($ldap)) {
$resource = $ldap->getResource();
}
$message = '';
if ($code === 0)
$code = Zend_Ldap_Exception::getLdapCode($resource);
if ($code)
$message .= '0x' . dechex($code);
if (is_resource($resource)) {
/* The various error retrieval functions can return
* different things so we just try to collect what we
* can and eliminate dupes.
*/
$estr1 = @ldap_error($resource);
if ($code !== 0 && $estr1 === 'Success')
$estr1 = @ldap_err2str($code);
if ($estr1 !== $str)
$this->_append($message, $estr1);
@ldap_get_option($resource, LDAP_OPT_ERROR_STRING, $estr2);
if ($estr2 !== $str && $estr2 !== $estr1)
$this->_append($message, $estr2);
}
$this->_append($message, $str);
parent::__construct($message, $code);
}
private function _append(&$message, $estr)
{
if ($estr) {
if ($message)
$message .= ': ';
$message .= $estr;
}
}
/**
* @param mixed $ldap A Zend_Ldap object or raw LDAP context resource
* @return int The current error code for the resource
*/
public static function getLdapCode($ldap)
{
$resource = null;
if (is_resource($ldap)) {
$resource = $ldap;
} else if (is_object($ldap)) {
$resource = $ldap->getResource();
}
if (is_resource($resource)) {
$ret = @ldap_get_option($resource, LDAP_OPT_ERROR_NUMBER, $err);
if ($ret === true) {
if ($err <= -1 && $err >= -17) {
/* For some reason draft-ietf-ldapext-ldap-c-api-xx.txt error
* codes in OpenLDAP are negative values from -1 to -17.
*/
$err = Zend_Ldap_Exception::LDAP_SERVER_DOWN + (-$err - 1);
}
return $err;
}
}
return 0;
}
/**
* @param string $message An informtive exception message
*
*/
public function setMessage($message)
{
$this->_message = $message;
}
/**
* @return int The current error code for this exception
*/
public function getErrorCode()
{
return $this->getCode();
}
}
Config/Writer.php 0000604 00000004722 15071256135 0007744 0 ustar 00 <?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_Config
* @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: Writer.php 12220 2008-10-31 20:13:55Z dasprid $
*/
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Config_Writer
{
/**
* Option keys to skip when calling setOptions()
*
* @var array
*/
protected $_skipOptions = array(
'options'
);
/**
* Config object to write
*
* @var Zend_Config
*/
protected $_config = null;
/**
* Create a new adapter
*
* $options can only be passed as array or be omitted
*
* @param null|array $options
*/
public function __construct(array $options = null)
{
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Set options via a Zend_Config instance
*
* @param Zend_Config $config
* @return Zend_Config_Writer
*/
public function setConfig(Zend_Config $config)
{
$this->_config = $config;
return $this;
}
/**
* Set options via an array
*
* @param array $options
* @return Zend_Config_Writer
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->_skipOptions)) {
continue;
}
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Write a Zend_Config object to it's target
*
* @return void
*/
abstract public function write();
}
Config/Exception.php 0000604 00000001775 15071256135 0010433 0 ustar 00 <?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_Config
* @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 Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Config
* @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_Config_Exception extends Zend_Exception {}
Config/Xml.php 0000604 00000020475 15071256135 0007233 0 ustar 00 <?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_Config
* @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: Xml.php 11427 2008-09-18 16:11:43Z doctorrock83 $
*/
/**
* @see Zend_Config
*/
require_once 'Zend/Config.php';
/**
* XML Adapter for Zend_Config
*
* @category Zend
* @package Zend_Config
* @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_Config_Xml extends Zend_Config
{
/**
* Loads the section $section from the config file $filename for
* access facilitated by nested object properties.
*
* Sections are defined in the XML as children of the root element.
*
* In order to extend another section, a section defines the "extends"
* attribute having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "extends".
*
* @param string $filename File to process
* @param mixed $section Section to process
* @param boolean $allowModifications Wether modifiacations are allowed at runtime
* @throws Zend_Config_Exception When filename is not set
* @throws Zend_Config_Exception When section $sectionName cannot be found in $filename
*/
public function __construct($filename, $section = null, $allowModifications = false)
{
if (empty($filename)) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Filename is not set');
}
set_error_handler(array($this, '_loadFileErrorHandler'));
$config = simplexml_load_file($filename); // Warnings and errors are suppressed
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
if ($section === null) {
$dataArray = array();
foreach ($config as $sectionName => $sectionData) {
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
}
parent::__construct($dataArray, $allowModifications);
} else if (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($config->$sectionName)) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
}
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($config->$section)) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$section' cannot be found in $filename");
}
$dataArray = $this->_processExtends($config, $section);
if (!is_array($dataArray)) {
// Section in the XML file contains just one top level string
$dataArray = array($section => $dataArray);
}
parent::__construct($dataArray, $allowModifications);
}
$this->_loadedSection = $section;
}
/**
* Helper function to process each element in the section and handle
* the "extends" inheritance attribute.
*
* @param SimpleXMLElement $element XML Element to process
* @param string $section Section to process
* @param array $config Configuration which was parsed yet
* @throws Zend_Config_Exception When $section cannot be found
* @return array
*/
protected function _processExtends(SimpleXMLElement $element, $section, array $config = array())
{
if (!isset($element->$section)) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$section' cannot be found");
}
$thisSection = $element->$section;
if (isset($thisSection['extends'])) {
$extendedSection = (string) $thisSection['extends'];
$this->_assertValidExtend($section, $extendedSection);
$config = $this->_processExtends($element, $extendedSection, $config);
}
$config = $this->_arrayMergeRecursive($config, $this->_toArray($thisSection));
return $config;
}
/**
* Returns a string or an associative and possibly multidimensional array from
* a SimpleXMLElement.
*
* @param SimpleXMLElement $xmlObject Convert a SimpleXMLElement into an array
* @return array|string
*/
protected function _toArray(SimpleXMLElement $xmlObject)
{
$config = array();
// Search for parent node values
if (count($xmlObject->attributes()) > 0) {
foreach ($xmlObject->attributes() as $key => $value) {
if ($key === 'extends') {
continue;
}
$value = (string) $value;
if (array_key_exists($key, $config)) {
if (!is_array($config[$key])) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
}
}
// Search for children
if (count($xmlObject->children()) > 0) {
foreach ($xmlObject->children() as $key => $value) {
if (count($value->children()) > 0) {
$value = $this->_toArray($value);
} else if (count($value->attributes()) > 0) {
$attributes = $value->attributes();
if (isset($attributes['value'])) {
$value = (string) $attributes['value'];
} else {
$value = $this->_toArray($value);
}
} else {
$value = (string) $value;
}
if (array_key_exists($key, $config)) {
if (!is_array($config[$key]) || !array_key_exists(0, $config[$key])) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
}
} else if (!isset($xmlObject['extends']) && (count($config) === 0)) {
// Object has no children nor attributes and doesn't use the extends
// attribute: it's a string
$config = (string) $xmlObject;
}
return $config;
}
/**
* Merge two arrays recursively, overwriting keys of the same name
* in $array1 with the value in $array2.
*
* @param mixed $firstArray First array
* @param mixed $secondArray Second array to merge into first array
* @return array
*/
protected function _arrayMergeRecursive($firstArray, $secondArray)
{
if (is_array($firstArray) && is_array($secondArray)) {
foreach ($secondArray as $key => $value) {
if (isset($firstArray[$key])) {
$firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
} else {
$firstArray[$key] = $value;
}
}
} else {
$firstArray = $secondArray;
}
return $firstArray;
}
}
Config/Writer/Array.php 0000604 00000005653 15071256135 0011026 0 ustar 00 <?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_Config
* @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: Array.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @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_Config_Writer_Array extends Zend_Config_Writer
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Array
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
if ($this->_filename === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No filename was set');
}
if ($this->_config === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No config was set');
}
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
$arrayString = "<?php\n"
. "return " . var_export($data, true) . ";\n";
$result = @file_put_contents($this->_filename, $arrayString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
}
Config/Writer/Ini.php 0000604 00000011607 15071256135 0010463 0 ustar 00 <?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_Config
* @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: Ini.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @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_Config_Writer_Ini extends Zend_Config_Writer
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* String that separates nesting levels of configuration data identifiers
*
* @var string
*/
protected $_nestSeparator = '.';
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Xml
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Set the nest separator
*
* @param string $filename
* @return Zend_Config_Writer_Ini
*/
public function setNestSeparator($separator)
{
$this->_nestSeparator = $separator;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
if ($this->_filename === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No filename was set');
}
if ($this->_config === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No config was set');
}
$iniString = '';
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$iniString .= '[' . $sectionName . ']' . "\n"
. $this->_addBranch($this->_config)
. "\n";
} else {
foreach ($this->_config as $sectionName => $data) {
if (isset($extends[$sectionName])) {
$sectionName .= ' : ' . $extends[$sectionName];
}
$iniString .= '[' . $sectionName . ']' . "\n"
. $this->_addBranch($data)
. "\n";
}
}
$result = @file_put_contents($this->_filename, $iniString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
/**
* Add a branch to an INI string recursively
*
* @param Zend_Config $config
* @return void
*/
protected function _addBranch(Zend_Config $config, $parents = array())
{
$iniString = '';
foreach ($config as $key => $value) {
$group = array_merge($parents, array($key));
if ($value instanceof Zend_Config) {
$iniString .= $this->_addBranch($value, $group);
} else {
$iniString .= implode($this->_nestSeparator, $group)
. ' = '
. $this->_prepareValue($value)
. "\n";
}
}
return $iniString;
}
/**
* Prepare a value for INI
*
* @param mixed $value
* @return string
*/
protected function _prepareValue($value)
{
if (is_integer($value) || is_float($value)) {
return $value;
} elseif (is_bool($value)) {
return ($value ? 'true' : 'false');
} else {
return '"' . addslashes($value) . '"';
}
}
}
Config/Writer/Xml.php 0000604 00000010141 15071256135 0010474 0 ustar 00 <?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_Config
* @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: Xml.php 12221 2008-10-31 20:32:43Z dasprid $
*/
/**
* @see Zend_Config_Writer
*/
require_once 'Zend/Config/Writer.php';
/**
* @category Zend
* @package Zend_Config
* @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_Config_Writer_Xml extends Zend_Config_Writer
{
/**
* Filename to write to
*
* @var string
*/
protected $_filename = null;
/**
* Set the target filename
*
* @param string $filename
* @return Zend_Config_Writer_Xml
*/
public function setFilename($filename)
{
$this->_filename = $filename;
return $this;
}
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
if ($this->_filename === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No filename was set');
}
if ($this->_config === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No config was set');
}
$xml = new SimpleXMLElement('<zend-config/>');
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$child = $xml->addChild($sectionName);
$this->_addBranch($this->_config, $child);
} else {
foreach ($this->_config as $sectionName => $data) {
if (!($data instanceof Zend_Config)) {
continue;
}
$child = $xml->addChild($sectionName);
if (isset($extends[$sectionName])) {
$child->addAttribute('extends', $extends[$sectionName]);
}
$this->_addBranch($data, $child);
}
}
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
$xmlString = $dom->saveXML();
$result = @file_put_contents($this->_filename, $xmlString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
/**
* Add a branch to an XML object recursively
*
* @param Zend_Config $config
* @param SimpleXMLElement $xml
* @return void
*/
protected function _addBranch(Zend_Config $config, SimpleXMLElement $xml)
{
foreach ($config as $key => $value) {
if ($value instanceof Zend_Config) {
$child = $xml->addChild($key);
$this->_addBranch($value, $child);
} else {
$xml->addChild($key, (string) $value);
}
}
}
}
Config/Ini.php 0000604 00000022244 15071256135 0007206 0 ustar 00 <?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_Config
* @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: Ini.php 11206 2008-09-03 14:36:32Z ralph $
*/
/**
* @see Zend_Config
*/
require_once 'Zend/Config.php';
/**
* @category Zend
* @package Zend_Config
* @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_Config_Ini extends Zend_Config
{
/**
* String that separates nesting levels of configuration data identifiers
*
* @var string
*/
protected $_nestSeparator = '.';
/**
* Loads the section $section from the config file $filename for
* access facilitated by nested object properties.
*
* If the section name contains a ":" then the section name to the right
* is loaded and included into the properties. Note that the keys in
* this $section will override any keys of the same
* name in the sections that have been included via ":".
*
* If the $section is null, then all sections in the ini file are loaded.
*
* If any key includes a ".", then this will act as a separator to
* create a sub-property.
*
* example ini file:
* [all]
* db.connection = database
* hostname = live
*
* [staging : all]
* hostname = staging
*
* after calling $data = new Zend_Config_Ini($file, 'staging'); then
* $data->hostname === "staging"
* $data->db->connection === "database"
*
* The $options parameter may be provided as either a boolean or an array.
* If provided as a boolean, this sets the $allowModifications option of
* Zend_Config. If provided as an array, there are two configuration
* directives that may be set. For example:
*
* $options = array(
* 'allowModifications' => false,
* 'nestSeparator' => '->'
* );
*
* @param string $filename
* @param string|null $section
* @param boolean|array $options
* @throws Zend_Config_Exception
* @return void
*/
public function __construct($filename, $section = null, $options = false)
{
if (empty($filename)) {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Filename is not set');
}
$allowModifications = false;
if (is_bool($options)) {
$allowModifications = $options;
} elseif (is_array($options)) {
if (isset($options['allowModifications'])) {
$allowModifications = (bool) $options['allowModifications'];
}
if (isset($options['nestSeparator'])) {
$this->_nestSeparator = (string) $options['nestSeparator'];
}
}
set_error_handler(array($this, '_loadFileErrorHandler'));
$iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
$preProcessedArray = array();
foreach ($iniArray as $key => $data)
{
$bits = explode(':', $key);
$thisSection = trim($bits[0]);
switch (count($bits)) {
case 1:
$preProcessedArray[$thisSection] = $data;
break;
case 2:
$extendedSection = trim($bits[1]);
$preProcessedArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data);
break;
default:
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections in $filename");
}
}
if (null === $section) {
$dataArray = array();
foreach ($preProcessedArray as $sectionName => $sectionData) {
if(!is_array($sectionData)) {
$dataArray = array_merge_recursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
} else {
$dataArray[$sectionName] = $this->_processExtends($preProcessedArray, $sectionName);
}
}
parent::__construct($dataArray, $allowModifications);
} elseif (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($preProcessedArray[$sectionName])) {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
}
$dataArray = array_merge($this->_processExtends($preProcessedArray, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($preProcessedArray[$section])) {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$section' cannot be found in $filename");
}
parent::__construct($this->_processExtends($preProcessedArray, $section), $allowModifications);
}
$this->_loadedSection = $section;
}
/**
* Helper function to process each element in the section and handle
* the "extends" inheritance keyword. Passes control to _processKey()
* to handle the "dot" sub-property syntax in each key.
*
* @param array $iniArray
* @param string $section
* @param array $config
* @throws Zend_Config_Exception
* @return array
*/
protected function _processExtends($iniArray, $section, $config = array())
{
$thisSection = $iniArray[$section];
foreach ($thisSection as $key => $value) {
if (strtolower($key) == ';extends') {
if (isset($iniArray[$value])) {
$this->_assertValidExtend($section, $value);
$config = $this->_processExtends($iniArray, $value, $config);
} else {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Section '$section' cannot be found");
}
} else {
$config = $this->_processKey($config, $key, $value);
}
}
return $config;
}
/**
* Assign the key's value to the property list. Handle the "dot"
* notation for sub-properties by passing control to
* processLevelsInKey().
*
* @param array $config
* @param string $key
* @param string $value
* @throws Zend_Config_Exception
* @return array
*/
protected function _processKey($config, $key, $value)
{
if (strpos($key, $this->_nestSeparator) !== false) {
$pieces = explode($this->_nestSeparator, $key, 2);
if (strlen($pieces[0]) && strlen($pieces[1])) {
if (!isset($config[$pieces[0]])) {
$config[$pieces[0]] = array();
} elseif (!is_array($config[$pieces[0]])) {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");
}
$config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
} else {
/**
* @see Zend_Config_Exception
*/
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception("Invalid key '$key'");
}
} else {
$config[$key] = $value;
}
return $config;
}
}
Http/CookieJar.php 0000604 00000030007 15071256135 0010043 0 ustar 00 <?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_Http
* @subpackage CookieJar
* @version $Id: CookieJar.php 9098 2008-03-30 19:29:10Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com/)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once "Zend/Uri.php";
require_once "Zend/Http/Cookie.php";
require_once "Zend/Http/Response.php";
/**
* A Zend_Http_CookieJar object is designed to contain and maintain HTTP cookies, and should
* be used along with Zend_Http_Client in order to manage cookies across HTTP requests and
* responses.
*
* The class contains an array of Zend_Http_Cookie objects. Cookies can be added to the jar
* automatically from a request or manually. Then, the jar can find and return the cookies
* needed for a specific HTTP request.
*
* A special parameter can be passed to all methods of this class that return cookies: Cookies
* can be returned either in their native form (as Zend_Http_Cookie objects) or as strings -
* the later is suitable for sending as the value of the "Cookie" header in an HTTP request.
* You can also choose, when returning more than one cookie, whether to get an array of strings
* (by passing Zend_Http_CookieJar::COOKIE_STRING_ARRAY) or one unified string for all cookies
* (by passing Zend_Http_CookieJar::COOKIE_STRING_CONCAT).
*
* @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
*
* @category Zend
* @package Zend_Http
* @subpackage CookieJar
* @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_Http_CookieJar
{
/**
* Return cookie(s) as a Zend_Http_Cookie object
*
*/
const COOKIE_OBJECT = 0;
/**
* Return cookie(s) as a string (suitable for sending in an HTTP request)
*
*/
const COOKIE_STRING_ARRAY = 1;
/**
* Return all cookies as one long string (suitable for sending in an HTTP request)
*
*/
const COOKIE_STRING_CONCAT = 2;
/**
* Array storing cookies
*
* Cookies are stored according to domain and path:
* $cookies
* + www.mydomain.com
* + /
* - cookie1
* - cookie2
* + /somepath
* - othercookie
* + www.otherdomain.net
* + /
* - alsocookie
*
* @var array
*/
protected $cookies = array();
/**
* Construct a new CookieJar object
*
*/
public function __construct()
{ }
/**
* Add a cookie to the jar. Cookie should be passed either as a Zend_Http_Cookie object
* or as a string - in which case an object is created from the string.
*
* @param Zend_Http_Cookie|string $cookie
* @param Zend_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure)
*/
public function addCookie($cookie, $ref_uri = null)
{
if (is_string($cookie)) {
$cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri);
}
if ($cookie instanceof Zend_Http_Cookie) {
$domain = $cookie->getDomain();
$path = $cookie->getPath();
if (! isset($this->cookies[$domain])) $this->cookies[$domain] = array();
if (! isset($this->cookies[$domain][$path])) $this->cookies[$domain][$path] = array();
$this->cookies[$domain][$path][$cookie->getName()] = $cookie;
} else {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Supplient argument is not a valid cookie string or object');
}
}
/**
* Parse an HTTP response, adding all the cookies set in that response
* to the cookie jar.
*
* @param Zend_Http_Response $response
* @param Zend_Uri_Http|string $ref_uri Requested URI
*/
public function addCookiesFromResponse($response, $ref_uri)
{
if (! $response instanceof Zend_Http_Response) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('$response is expected to be a Response object, ' .
gettype($response) . ' was passed');
}
$cookie_hdrs = $response->getHeader('Set-Cookie');
if (is_array($cookie_hdrs)) {
foreach ($cookie_hdrs as $cookie) {
$this->addCookie($cookie, $ref_uri);
}
} elseif (is_string($cookie_hdrs)) {
$this->addCookie($cookie_hdrs, $ref_uri);
}
}
/**
* Get all cookies in the cookie jar as an array
*
* @param int $ret_as Whether to return cookies as objects of Zend_Http_Cookie or as strings
* @return array|string
*/
public function getAllCookies($ret_as = self::COOKIE_OBJECT)
{
$cookies = $this->_flattenCookiesArray($this->cookies, $ret_as);
return $cookies;
}
/**
* Return an array of all cookies matching a specific request according to the request URI,
* whether session cookies should be sent or not, and the time to consider as "now" when
* checking cookie expiry time.
*
* @param string|Zend_Uri_Http $uri URI to check against (secure, domain, path)
* @param boolean $matchSessionCookies Whether to send session cookies
* @param int $ret_as Whether to return cookies as objects of Zend_Http_Cookie or as strings
* @param int $now Override the current time when checking for expiry time
* @return array|string
*/
public function getMatchingCookies($uri, $matchSessionCookies = true,
$ret_as = self::COOKIE_OBJECT, $now = null)
{
if (is_string($uri)) $uri = Zend_Uri::factory($uri);
if (! $uri instanceof Zend_Uri_Http) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("Invalid URI string or object passed");
}
// Set path
$path = $uri->getPath();
$path = substr($path, 0, strrpos($path, '/'));
if (! $path) $path = '/';
// First, reduce the array of cookies to only those matching domain and path
$cookies = $this->_matchDomain($uri->getHost());
$cookies = $this->_matchPath($cookies, $path);
$cookies = $this->_flattenCookiesArray($cookies, self::COOKIE_OBJECT);
// Next, run Cookie->match on all cookies to check secure, time and session mathcing
$ret = array();
foreach ($cookies as $cookie)
if ($cookie->match($uri, $matchSessionCookies, $now))
$ret[] = $cookie;
// Now, use self::_flattenCookiesArray again - only to convert to the return format ;)
$ret = $this->_flattenCookiesArray($ret, $ret_as);
return $ret;
}
/**
* Get a specific cookie according to a URI and name
*
* @param Zend_Uri_Http|string $uri The uri (domain and path) to match
* @param string $cookie_name The cookie's name
* @param int $ret_as Whether to return cookies as objects of Zend_Http_Cookie or as strings
* @return Zend_Http_Cookie|string
*/
public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
{
if (is_string($uri)) {
$uri = Zend_Uri::factory($uri);
}
if (! $uri instanceof Zend_Uri_Http) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Invalid URI specified');
}
// Get correct cookie path
$path = $uri->getPath();
$path = substr($path, 0, strrpos($path, '/'));
if (! $path) $path = '/';
if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
$cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
switch ($ret_as) {
case self::COOKIE_OBJECT:
return $cookie;
break;
case self::COOKIE_STRING_ARRAY:
case self::COOKIE_STRING_CONCAT:
return $cookie->__toString();
break;
default:
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("Invalid value passed for \$ret_as: {$ret_as}");
break;
}
} else {
return false;
}
}
/**
* Helper function to recursivly flatten an array. Shoud be used when exporting the
* cookies array (or parts of it)
*
* @param Zend_Http_Cookie|array $ptr
* @param int $ret_as What value to return
* @return array|string
*/
protected function _flattenCookiesArray($ptr, $ret_as = self::COOKIE_OBJECT) {
if (is_array($ptr)) {
$ret = ($ret_as == self::COOKIE_STRING_CONCAT ? '' : array());
foreach ($ptr as $item) {
if ($ret_as == self::COOKIE_STRING_CONCAT) {
$ret .= $this->_flattenCookiesArray($item, $ret_as);
} else {
$ret = array_merge($ret, $this->_flattenCookiesArray($item, $ret_as));
}
}
return $ret;
} elseif ($ptr instanceof Zend_Http_Cookie) {
switch ($ret_as) {
case self::COOKIE_STRING_ARRAY:
return array($ptr->__toString());
break;
case self::COOKIE_STRING_CONCAT:
return $ptr->__toString();
break;
case self::COOKIE_OBJECT:
default:
return array($ptr);
break;
}
}
return null;
}
/**
* Return a subset of the cookies array matching a specific domain
*
* Returned array is actually an array of pointers to items in the $this->cookies array.
*
* @param string $domain
* @return array
*/
protected function _matchDomain($domain) {
$ret = array();
foreach (array_keys($this->cookies) as $cdom) {
$regex = "/" . preg_quote($cdom, "/") . "$/i";
if (preg_match($regex, $domain)) $ret[$cdom] = &$this->cookies[$cdom];
}
return $ret;
}
/**
* Return a subset of a domain-matching cookies that also match a specified path
*
* Returned array is actually an array of pointers to items in the $passed array.
*
* @param array $dom_array
* @param string $path
* @return array
*/
protected function _matchPath($domains, $path) {
$ret = array();
if (substr($path, -1) != '/') $path .= '/';
foreach ($domains as $dom => $paths_array) {
foreach (array_keys($paths_array) as $cpath) {
$regex = "|^" . preg_quote($cpath, "|") . "|i";
if (preg_match($regex, $path)) {
if (! isset($ret[$dom])) $ret[$dom] = array();
$ret[$dom][$cpath] = &$paths_array[$cpath];
}
}
}
return $ret;
}
/**
* Create a new CookieJar object and automatically load into it all the
* cookies set in an Http_Response object. If $uri is set, it will be
* considered as the requested URI for setting default domain and path
* of the cookie.
*
* @param Zend_Http_Response $response HTTP Response object
* @param Zend_Uri_Http|string $uri The requested URI
* @return Zend_Http_CookieJar
* @todo Add the $uri functionality.
*/
public static function fromResponse(Zend_Http_Response $response, $ref_uri)
{
$jar = new self();
$jar->addCookiesFromResponse($response, $ref_uri);
return $jar;
}
}
Http/Client/Adapter/Proxy.php 0000604 00000022744 15071256135 0012125 0 ustar 00 <?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_Http
* @subpackage Client_Adapter
* @version $Id: Proxy.php 12504 2008-11-10 16:28:46Z matthew $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Uri/Http.php';
require_once 'Zend/Http/Client.php';
require_once 'Zend/Http/Client/Adapter/Socket.php';
/**
* HTTP Proxy-supporting Zend_Http_Client adapter class, based on the default
* socket based adapter.
*
* Should be used if proxy HTTP access is required. If no proxy is set, will
* fall back to Zend_Http_Client_Adapter_Socket behavior. Just like the
* default Socket adapter, this adapter does not require any special extensions
* installed.
*
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @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_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
{
/**
* Parameters array
*
* @var array
*/
protected $config = array(
'ssltransport' => 'ssl',
'proxy_host' => '',
'proxy_port' => 8080,
'proxy_user' => '',
'proxy_pass' => '',
'proxy_auth' => Zend_Http_Client::AUTH_BASIC,
'persistent' => false
);
/**
* Whether HTTPS CONNECT was already negotiated with the proxy or not
*
* @var boolean
*/
protected $negotiated = false;
/**
* Connect to the remote server
*
* Will try to connect to the proxy server. If no proxy was set, will
* fall back to the target server (behave like regular Socket adapter)
*
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{
// If no proxy is set, fall back to Socket adapter
if (! $this->config['proxy_host']) return parent::connect($host, $port, $secure);
// Go through a proxy - the connection is actually to the proxy server
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
// If we are connected to the wrong proxy, disconnect first
if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
if (is_resource($this->socket)) $this->close();
}
// Now, if we are not connected, connect
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
$this->socket = @fsockopen($host, $port, $errno, $errstr, (int) $this->config['timeout']);
if (! $this->socket) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'Unable to Connect to proxy server ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
}
// Set the stream timeout
if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
}
// Update connected_to
$this->connected_to = array($host, $port);
}
}
/**
* Send request to the proxy server
*
* @param string $method
* @param Zend_Uri_Http $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
// If no proxy is set, fall back to default Socket adapter
if (! $this->config['proxy_host']) return parent::write($method, $uri, $http_ver, $headers, $body);
// Make sure we're properly connected
if (! $this->socket) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
}
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong proxy server");
}
// Add Proxy-Authorization header
if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) {
$headers['proxy-authorization'] = Zend_Http_Client::encodeAuthHeader(
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
);
}
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
$this->negotiated = true;
}
// Save request method for later
$this->method = $method;
// Build request headers
$request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
// Add all headers to the request string
foreach ($headers as $k => $v) {
if (is_string($k)) $v = "$k: $v";
$request .= "$v\r\n";
}
// Add the request body
$request .= "\r\n" . $body;
// Send the request
if (! @fwrite($this->socket, $request)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Error writing request to proxy server");
}
return $request;
}
/**
* Preform handshaking with HTTPS proxy using CONNECT method
*
* @param string $host
* @param integer $port
* @param string $http_ver
* @param array $headers
*/
protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array &$headers = array())
{
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
"Host: " . $this->config['proxy_host'] . "\r\n";
// Add the user-agent header
if (isset($this->config['useragent'])) {
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
}
// If the proxy-authorization header is set, send it to proxy but remove
// it from headers sent to target host
if (isset($headers['proxy-authorization'])) {
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
unset($headers['proxy-authorization']);
}
$request .= "\r\n";
// Send the request
if (! @fwrite($this->socket, $request)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Error writing request to proxy server");
}
// Read response headers only
$response = '';
$gotStatus = false;
while ($line = @fgets($this->socket)) {
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
if ($gotStatus) {
$response .= $line;
if (!chop($line)) break;
}
}
// Check that the response from the proxy is 200
if (Zend_Http_Response::extractCode($response) != 200) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Unable to connect to HTTPS proxy. Server response: " . $response);
}
// If all is good, switch socket to secure mode. We have to fall back
// through the different modes
$modes = array(
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
);
$success = false;
foreach($modes as $mode) {
$success = stream_socket_enable_crypto($this->socket, true, $mode);
if ($success) break;
}
if (! $success) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Unable to connect to" .
" HTTPS server through proxy: could not negotiate secure connection.");
}
}
/**
* Close the connection to the server
*
*/
public function close()
{
parent::close();
$this->negotiated = false;
}
/**
* Destructor: make sure the socket is disconnected
*
*/
public function __destruct()
{
if ($this->socket) $this->close();
}
}
Http/Client/Adapter/Test.php 0000604 00000012514 15071256135 0011715 0 ustar 00 <?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_Http
* @subpackage Client_Adapter
* @version $Id: Test.php 12104 2008-10-23 22:36:28Z shahar $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Uri/Http.php';
require_once 'Zend/Http/Response.php';
require_once 'Zend/Http/Client/Adapter/Interface.php';
/**
* A testing-purposes adapter.
*
* Should be used to test all components that rely on Zend_Http_Client,
* without actually performing an HTTP request. You should instantiate this
* object manually, and then set it as the client's adapter. Then, you can
* set the expected response using the setResponse() method.
*
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @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_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interface
{
/**
* Parameters array
*
* @var array
*/
protected $config = array();
/**
* Buffer of responses to be returned by the read() method. Can be
* set using setResponse() and addResponse().
*
* @var array
*/
protected $responses = array("HTTP/1.1 400 Bad Request\r\n\r\n");
/**
* Current position in the response buffer
*
* @var integer
*/
protected $responseIndex = 0;
/**
* Adapter constructor, currently empty. Config is set using setConfig()
*
*/
public function __construct()
{ }
/**
* Set the configuration array for the adapter
*
* @param array $config
*/
public function setConfig($config = array())
{
if (! is_array($config)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'$config expects an array, ' . gettype($config) . ' recieved.');
}
foreach ($config as $k => $v) {
$this->config[strtolower($k)] = $v;
}
}
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{ }
/**
* Send request to the remote server
*
* @param string $method
* @param Zend_Uri_Http $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host);
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) $v = ucfirst($k) . ": $v";
$request .= "$v\r\n";
}
// Add the request body
$request .= "\r\n" . $body;
// Do nothing - just return the request as string
return $request;
}
/**
* Return the response set in $this->setResponse()
*
* @return string
*/
public function read()
{
if ($this->responseIndex >= count($this->responses)) {
$this->responseIndex = 0;
}
return $this->responses[$this->responseIndex++];
}
/**
* Close the connection (dummy)
*
*/
public function close()
{ }
/**
* Set the HTTP response(s) to be returned by this adapter
*
* @param Zend_Http_Response|array|string $response
*/
public function setResponse($response)
{
if ($response instanceof Zend_Http_Response) {
$response = $response->asString();
}
$this->responses = (array)$response;
$this->responseIndex = 0;
}
/**
* Add another response to the response buffer.
*
* @param string $response
*/
public function addResponse($response)
{
$this->responses[] = $response;
}
/**
* Sets the position of the response buffer. Selects which
* response will be returned on the next call to read().
*
* @param integer $index
*/
public function setResponseIndex($index)
{
if ($index < 0 || $index >= count($this->responses)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'Index out of range of response buffer size');
}
$this->responseIndex = $index;
}
}
Http/Client/Adapter/Exception.php 0000604 00000002212 15071256135 0012726 0 ustar 00 <?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_Http
* @subpackage Client_Adapter_Exception
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Http/Client/Exception.php';
/**
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @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_Http_Client_Adapter_Exception extends Zend_Http_Client_Exception
{}
Http/Client/Adapter/Socket.php 0000604 00000030062 15071256135 0012224 0 ustar 00 <?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_Http
* @subpackage Client_Adapter
* @version $Id: Socket.php 13014 2008-12-04 12:07:05Z yoshida@zend.co.jp $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Uri/Http.php';
require_once 'Zend/Http/Client/Adapter/Interface.php';
/**
* A sockets based (stream_socket_client) adapter class for Zend_Http_Client. Can be used
* on almost every PHP environment, and does not require any special extensions.
*
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @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_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interface
{
/**
* The socket for server connection
*
* @var resource|null
*/
protected $socket = null;
/**
* What host/port are we connected to?
*
* @var array
*/
protected $connected_to = array(null, null);
/**
* Parameters array
*
* @var array
*/
protected $config = array(
'persistent' => false,
'ssltransport' => 'ssl',
'sslcert' => null,
'sslpassphrase' => null
);
/**
* Request method - will be set by write() and might be used by read()
*
* @var string
*/
protected $method = null;
/**
* Adapter constructor, currently empty. Config is set using setConfig()
*
*/
public function __construct()
{
}
/**
* Set the configuration array for the adapter
*
* @param array $config
*/
public function setConfig($config = array())
{
if (! is_array($config)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'$concig expects an array, ' . gettype($config) . ' recieved.');
}
foreach ($config as $k => $v) {
$this->config[strtolower($k)] = $v;
}
}
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{
// If the URI should be accessed via SSL, prepend the Hostname with ssl://
$host = ($secure ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
// If we are connected to the wrong host, disconnect first
if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
if (is_resource($this->socket)) $this->close();
}
// Now, if we are not connected, connect
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
$context = stream_context_create();
if ($secure) {
if ($this->config['sslcert'] !== null) {
if (! stream_context_set_option($context, 'ssl', 'local_cert',
$this->config['sslcert'])) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Unable to set sslcert option');
}
}
if ($this->config['sslpassphrase'] !== null) {
if (! stream_context_set_option($context, 'ssl', 'passphrase',
$this->config['sslpassphrase'])) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Unable to set sslpassphrase option');
}
}
}
$flags = STREAM_CLIENT_CONNECT;
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;
$this->socket = @stream_socket_client($host . ':' . $port,
$errno,
$errstr,
(int) $this->config['timeout'],
$flags,
$context);
if (! $this->socket) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
}
// Set the stream timeout
if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
}
// Update connected_to
$this->connected_to = array($host, $port);
}
}
/**
* Send request to the remote server
*
* @param string $method
* @param Zend_Uri_Http $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
// Make sure we're properly connected
if (! $this->socket) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are not connected');
}
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong host');
}
// Save request method for later
$this->method = $method;
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) $v = ucfirst($k) . ": $v";
$request .= "$v\r\n";
}
// Add the request body
$request .= "\r\n" . $body;
// Send the request
if (! @fwrite($this->socket, $request)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Error writing request to server');
}
return $request;
}
/**
* Read response from server
*
* @return string
*/
public function read()
{
// First, read headers only
$response = '';
$gotStatus = false;
while (($line = @fgets($this->socket)) !== false) {
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
if ($gotStatus) {
$response .= $line;
if (rtrim($line) === '') break;
}
}
$statusCode = Zend_Http_Response::extractCode($response);
// Handle 100 and 101 responses internally by restarting the read again
if ($statusCode == 100 || $statusCode == 101) return $this->read();
/**
* Responses to HEAD requests and 204 or 304 responses are not expected
* to have a body - stop reading here
*/
if ($statusCode == 304 || $statusCode == 204 ||
$this->method == Zend_Http_Client::HEAD) return $response;
// Check headers to see what kind of connection / transfer encoding we have
$headers = Zend_Http_Response::extractHeaders($response);
// If we got a 'transfer-encoding: chunked' header
if (isset($headers['transfer-encoding'])) {
if ($headers['transfer-encoding'] == 'chunked') {
do {
$line = @fgets($this->socket);
$chunk = $line;
// Figure out the next chunk size
$chunksize = trim($line);
if (! ctype_xdigit($chunksize)) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' .
$chunksize . '" unable to read chunked body');
}
// Convert the hexadecimal value to plain integer
$chunksize = hexdec($chunksize);
// Read chunk
$left_to_read = $chunksize;
while ($left_to_read > 0) {
$line = @fread($this->socket, $left_to_read);
if ($line === false || strlen($line) === 0)
{
break;
} else {
$chunk .= $line;
$left_to_read -= strlen($line);
}
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
$chunk .= @fgets($this->socket);
$response .= $chunk;
} while ($chunksize > 0);
} else {
throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' .
$headers['transfer-encoding'] . '" transfer encoding');
}
// Else, if we got the content-length header, read this number of bytes
} elseif (isset($headers['content-length'])) {
$left_to_read = $headers['content-length'];
$chunk = '';
while ($left_to_read > 0) {
$chunk = @fread($this->socket, $left_to_read);
if ($chunk === false || strlen($chunk) === 0)
{
break;
} else {
$left_to_read -= strlen($chunk);
$response .= $chunk;
}
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
// Fallback: just read the response until EOF
} else {
do {
$buff = @fread($this->socket, 8192);
if ($buff === false || strlen($buff) === 0)
{
break;
} else {
$response .= $buff;
}
} while (feof($this->socket) === false);
$this->close();
}
// Close the connection if requested to do so by the server
if (isset($headers['connection']) && $headers['connection'] == 'close') {
$this->close();
}
return $response;
}
/**
* Close the connection to the server
*
*/
public function close()
{
if (is_resource($this->socket)) @fclose($this->socket);
$this->socket = null;
$this->connected_to = array(null, null);
}
/**
* Destructor: make sure the socket is disconnected
*
* If we are in persistent TCP mode, will not close the connection
*
*/
public function __destruct()
{
if (! $this->config['persistent']) {
if ($this->socket) $this->close();
}
}
}
Http/Client/Adapter/Interface.php 0000604 00000004302 15071256135 0012672 0 ustar 00 <?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_Http
* @subpackage Client_Adapter
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* An interface description for Zend_Http_Client_Adapter classes.
*
* These classes are used as connectors for Zend_Http_Client, performing the
* tasks of connecting, writing, reading and closing connection to the server.
*
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Http_Client_Adapter_Interface
{
/**
* Set the configuration array for the adapter
*
* @param array $config
*/
public function setConfig($config = array());
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param boolean $secure
*/
public function connect($host, $port = 80, $secure = false);
/**
* Send request to the remote server
*
* @param string $method
* @param Zend_Uri_Http $url
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as text
*/
public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '');
/**
* Read response from server
*
* @return string
*/
public function read();
/**
* Close the connection to the server
*
*/
public function close();
}
Http/Client/Exception.php 0000604 00000002144 15071256135 0011352 0 ustar 00 <?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_Http
* @subpackage Client_Exception
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Http/Exception.php';
/**
* @category Zend
* @package Zend_Http
* @subpackage Client
* @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_Http_Client_Exception extends Zend_Http_Exception
{}
Http/Response.php 0000604 00000041557 15071256135 0010007 0 ustar 00 <?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_Http
* @subpackage Response
* @version $Id: Response.php 12519 2008-11-10 18:41:24Z alexander $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Http_Response represents an HTTP 1.0 / 1.1 response message. It
* includes easy access to all the response's different elemts, as well as some
* convenience methods for parsing and validating HTTP responses.
*
* @package Zend_Http
* @subpackage Response
* @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_Http_Response
{
/**
* List of all known HTTP response codes - used by responseCodeAsText() to
* translate numeric codes to messages.
*
* @var array
*/
protected static $messages = array(
// Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',
// Success 2xx
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
// Redirection 3xx
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found', // 1.1
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
// 306 is deprecated but reserved
307 => 'Temporary Redirect',
// Client Error 4xx
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
// Server Error 5xx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
509 => 'Bandwidth Limit Exceeded'
);
/**
* The HTTP version (1.0, 1.1)
*
* @var string
*/
protected $version;
/**
* The HTTP response code
*
* @var int
*/
protected $code;
/**
* The HTTP response code as string
* (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)
*
* @var string
*/
protected $message;
/**
* The HTTP response headers array
*
* @var array
*/
protected $headers = array();
/**
* The HTTP response body
*
* @var string
*/
protected $body;
/**
* HTTP response constructor
*
* In most cases, you would use Zend_Http_Response::fromString to parse an HTTP
* response string and create a new Zend_Http_Response object.
*
* NOTE: The constructor no longer accepts nulls or empty values for the code and
* headers and will throw an exception if the passed values do not form a valid HTTP
* responses.
*
* If no message is passed, the message will be guessed according to the response code.
*
* @param int $code Response code (200, 404, ...)
* @param array $headers Headers array
* @param string $body Response body
* @param string $version HTTP version
* @param string $message Response code as text
* @throws Zend_Http_Exception
*/
public function __construct($code, $headers, $body = null, $version = '1.1', $message = null)
{
// Make sure the response code is valid and set it
if (self::responseCodeAsText($code) === null) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("{$code} is not a valid HTTP response code");
}
$this->code = $code;
// Make sure we got valid headers and set them
if (! is_array($headers)) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('No valid headers were passed');
}
foreach ($headers as $name => $value) {
if (is_int($name))
list($name, $value) = explode(": ", $value, 1);
$this->headers[ucwords(strtolower($name))] = $value;
}
// Set the body
$this->body = $body;
// Set the HTTP version
if (! preg_match('|^\d\.\d$|', $version)) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("Invalid HTTP response version: $version");
}
$this->version = $version;
// If we got the response message, set it. Else, set it according to
// the response code
if (is_string($message)) {
$this->message = $message;
} else {
$this->message = self::responseCodeAsText($code);
}
}
/**
* Check whether the response is an error
*
* @return boolean
*/
public function isError()
{
$restype = floor($this->code / 100);
if ($restype == 4 || $restype == 5) {
return true;
}
return false;
}
/**
* Check whether the response in successful
*
* @return boolean
*/
public function isSuccessful()
{
$restype = floor($this->code / 100);
if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
return true;
}
return false;
}
/**
* Check whether the response is a redirection
*
* @return boolean
*/
public function isRedirect()
{
$restype = floor($this->code / 100);
if ($restype == 3) {
return true;
}
return false;
}
/**
* Get the response body as string
*
* This method returns the body of the HTTP response (the content), as it
* should be in it's readable version - that is, after decoding it (if it
* was decoded), deflating it (if it was gzip compressed), etc.
*
* If you want to get the raw body (as transfered on wire) use
* $this->getRawBody() instead.
*
* @return string
*/
public function getBody()
{
$body = '';
// Decode the body if it was transfer-encoded
switch ($this->getHeader('transfer-encoding')) {
// Handle chunked body
case 'chunked':
$body = self::decodeChunkedBody($this->body);
break;
// No transfer encoding, or unknown encoding extension:
// return body as is
default:
$body = $this->body;
break;
}
// Decode any content-encoding (gzip or deflate) if needed
switch (strtolower($this->getHeader('content-encoding'))) {
// Handle gzip encoding
case 'gzip':
$body = self::decodeGzip($body);
break;
// Handle deflate encoding
case 'deflate':
$body = self::decodeDeflate($body);
break;
default:
break;
}
return $body;
}
/**
* Get the raw response body (as transfered "on wire") as string
*
* If the body is encoded (with Transfer-Encoding, not content-encoding -
* IE "chunked" body), gzip compressed, etc. it will not be decoded.
*
* @return string
*/
public function getRawBody()
{
return $this->body;
}
/**
* Get the HTTP version of the response
*
* @return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Get the HTTP response status code
*
* @return int
*/
public function getStatus()
{
return $this->code;
}
/**
* Return a message describing the HTTP response code
* (Eg. "OK", "Not Found", "Moved Permanently")
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* Get the response headers
*
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Get a specific header as string, or null if it is not set
*
* @param string$header
* @return string|array|null
*/
public function getHeader($header)
{
$header = ucwords(strtolower($header));
if (! is_string($header) || ! isset($this->headers[$header])) return null;
return $this->headers[$header];
}
/**
* Get all headers as string
*
* @param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
* @return string
*/
public function getHeadersAsString($status_line = true, $br = "\n")
{
$str = '';
if ($status_line) {
$str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
}
// Iterate over the headers and stringify them
foreach ($this->headers as $name => $value)
{
if (is_string($value))
$str .= "{$name}: {$value}{$br}";
elseif (is_array($value)) {
foreach ($value as $subval) {
$str .= "{$name}: {$subval}{$br}";
}
}
}
return $str;
}
/**
* Get the entire response as string
*
* @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
* @return string
*/
public function asString($br = "\n")
{
return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
}
/**
* A convenience function that returns a text representation of
* HTTP response codes. Returns 'Unknown' for unknown codes.
* Returns array of all codes, if $code is not specified.
*
* Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown')
* See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference
*
* @param int $code HTTP response code
* @param boolean $http11 Use HTTP version 1.1
* @return string
*/
public static function responseCodeAsText($code = null, $http11 = true)
{
$messages = self::$messages;
if (! $http11) $messages[302] = 'Moved Temporarily';
if ($code === null) {
return $messages;
} elseif (isset($messages[$code])) {
return $messages[$code];
} else {
return 'Unknown';
}
}
/**
* Extract the response code from a response string
*
* @param string $response_str
* @return int
*/
public static function extractCode($response_str)
{
preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
if (isset($m[1])) {
return (int) $m[1];
} else {
return false;
}
}
/**
* Extract the HTTP message from a response
*
* @param string $response_str
* @return string
*/
public static function extractMessage($response_str)
{
preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
if (isset($m[1])) {
return $m[1];
} else {
return false;
}
}
/**
* Extract the HTTP version from a response
*
* @param string $response_str
* @return string
*/
public static function extractVersion($response_str)
{
preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
if (isset($m[1])) {
return $m[1];
} else {
return false;
}
}
/**
* Extract the headers from a response string
*
* @param string $response_str
* @return array
*/
public static function extractHeaders($response_str)
{
$headers = array();
// First, split body and headers
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
if (! $parts[0]) return $headers;
// Split headers part to lines
$lines = explode("\n", $parts[0]);
unset($parts);
$last_header = null;
foreach($lines as $line) {
$line = trim($line, "\r\n");
if ($line == "") break;
if (preg_match("|^([\w-]+):\s+(.+)|", $line, $m)) {
unset($last_header);
$h_name = strtolower($m[1]);
$h_value = $m[2];
if (isset($headers[$h_name])) {
if (! is_array($headers[$h_name])) {
$headers[$h_name] = array($headers[$h_name]);
}
$headers[$h_name][] = $h_value;
} else {
$headers[$h_name] = $h_value;
}
$last_header = $h_name;
} elseif (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
if (is_array($headers[$last_header])) {
end($headers[$last_header]);
$last_header_key = key($headers[$last_header]);
$headers[$last_header][$last_header_key] .= $m[1];
} else {
$headers[$last_header] .= $m[1];
}
}
}
return $headers;
}
/**
* Extract the body from a response string
*
* @param string $response_str
* @return string
*/
public static function extractBody($response_str)
{
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
if (isset($parts[1])) {
return $parts[1];
}
return '';
}
/**
* Decode a "chunked" transfer-encoded body and return the decoded text
*
* @param string $body
* @return string
*/
public static function decodeChunkedBody($body)
{
$decBody = '';
while (trim($body)) {
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("Error parsing body - doesn't seem to be a chunked message");
}
$length = hexdec(trim($m[1]));
$cut = strlen($m[0]);
$decBody .= substr($body, $cut, $length);
$body = substr($body, $cut + $length + 2);
}
return $decBody;
}
/**
* Decode a gzip encoded message (when Content-encoding = gzip)
*
* Currently requires PHP with zlib support
*
* @param string $body
* @return string
*/
public static function decodeGzip($body)
{
if (! function_exists('gzinflate')) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Unable to decode gzipped response ' .
'body: perhaps the zlib extension is not loaded?');
}
return gzinflate(substr($body, 10));
}
/**
* Decode a zlib deflated message (when Content-encoding = deflate)
*
* Currently requires PHP with zlib support
*
* @param string $body
* @return string
*/
public static function decodeDeflate($body)
{
if (! function_exists('gzuncompress')) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Unable to decode deflated response ' .
'body: perhaps the zlib extension is not loaded?');
}
return gzuncompress($body);
}
/**
* Create a new Zend_Http_Response object from a string
*
* @param string $response_str
* @return Zend_Http_Response
*/
public static function fromString($response_str)
{
$code = self::extractCode($response_str);
$headers = self::extractHeaders($response_str);
$body = self::extractBody($response_str);
$version = self::extractVersion($response_str);
$message = self::extractMessage($response_str);
return new Zend_Http_Response($code, $headers, $body, $version, $message);
}
}
Http/Cookie.php 0000604 00000022003 15071256135 0007403 0 ustar 00 <?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_Http
* @subpackage Cookie
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com/)
* @version $Id: Cookie.php 9098 2008-03-30 19:29:10Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Uri/Http.php';
/**
* Zend_Http_Cookie is a class describing an HTTP cookie and all it's parameters.
*
* Zend_Http_Cookie is a class describing an HTTP cookie and all it's parameters. The
* class also enables validating whether the cookie should be sent to the server in
* a specified scenario according to the request URI, the expiry time and whether
* session cookies should be used or not. Generally speaking cookies should be
* contained in a Cookiejar object, or instantiated manually and added to an HTTP
* request.
*
* See http://wp.netscape.com/newsref/std/cookie_spec.html for some specs.
*
* @category Zend
* @package Zend_Http
* @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_Http_Cookie
{
/**
* Cookie name
*
* @var string
*/
protected $name;
/**
* Cookie value
*
* @var string
*/
protected $value;
/**
* Cookie expiry date
*
* @var int
*/
protected $expires;
/**
* Cookie domain
*
* @var string
*/
protected $domain;
/**
* Cookie path
*
* @var string
*/
protected $path;
/**
* Whether the cookie is secure or not
*
* @var boolean
*/
protected $secure;
/**
* Cookie object constructor
*
* @todo Add validation of each one of the parameters (legal domain, etc.)
*
* @param string $name
* @param string $value
* @param int $expires
* @param string $domain
* @param string $path
* @param bool $secure
*/
public function __construct($name, $value, $domain, $expires = null, $path = null, $secure = false)
{
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception("Cookie name cannot contain these characters: =,; \\t\\r\\n\\013\\014 ({$name})");
}
if (! $this->name = (string) $name) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Cookies must have a name');
}
if (! $this->domain = (string) $domain) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Cookies must have a domain');
}
$this->value = (string) $value;
$this->expires = ($expires === null ? null : (int) $expires);
$this->path = ($path ? $path : '/');
$this->secure = $secure;
}
/**
* Get Cookie name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get cookie value
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Get cookie domain
*
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* Get the cookie path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Get the expiry time of the cookie, or null if no expiry time is set
*
* @return int|null
*/
public function getExpiryTime()
{
return $this->expires;
}
/**
* Check whether the cookie should only be sent over secure connections
*
* @return boolean
*/
public function isSecure()
{
return $this->secure;
}
/**
* Check whether the cookie has expired
*
* Always returns false if the cookie is a session cookie (has no expiry time)
*
* @param int $now Timestamp to consider as "now"
* @return boolean
*/
public function isExpired($now = null)
{
if ($now === null) $now = time();
if (is_int($this->expires) && $this->expires < $now) {
return true;
} else {
return false;
}
}
/**
* Check whether the cookie is a session cookie (has no expiry time set)
*
* @return boolean
*/
public function isSessionCookie()
{
return ($this->expires === null);
}
/**
* Checks whether the cookie should be sent or not in a specific scenario
*
* @param string|Zend_Uri_Http $uri URI to check against (secure, domain, path)
* @param boolean $matchSessionCookies Whether to send session cookies
* @param int $now Override the current time when checking for expiry time
* @return boolean
*/
public function match($uri, $matchSessionCookies = true, $now = null)
{
if (is_string ($uri)) {
$uri = Zend_Uri_Http::factory($uri);
}
// Make sure we have a valid Zend_Uri_Http object
if (! ($uri->valid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) {
require_once 'Zend/Http/Exception.php';
throw new Zend_Http_Exception('Passed URI is not a valid HTTP or HTTPS URI');
}
// Check that the cookie is secure (if required) and not expired
if ($this->secure && $uri->getScheme() != 'https') return false;
if ($this->isExpired($now)) return false;
if ($this->isSessionCookie() && ! $matchSessionCookies) return false;
// Validate domain and path
// Domain is validated using tail match, while path is validated using head match
$domain_preg = preg_quote($this->getDomain(), "/");
if (! preg_match("/{$domain_preg}$/", $uri->getHost())) return false;
$path_preg = preg_quote($this->getPath(), "/");
if (! preg_match("/^{$path_preg}/", $uri->getPath())) return false;
// If we didn't die until now, return true.
return true;
}
/**
* Get the cookie as a string, suitable for sending as a "Cookie" header in an
* HTTP request
*
* @return string
*/
public function __toString()
{
return $this->name . '=' . urlencode($this->value) . ';';
}
/**
* Generate a new Cookie object from a cookie string
* (for example the value of the Set-Cookie HTTP header)
*
* @param string $cookieStr
* @param Zend_Uri_Http|string $ref_uri Reference URI for default values (domain, path)
* @return Zend_Http_Cookie A new Zend_Http_Cookie object or false on failure.
*/
public static function fromString($cookieStr, $ref_uri = null)
{
// Set default values
if (is_string($ref_uri)) {
$ref_uri = Zend_Uri_Http::factory($ref_uri);
}
$name = '';
$value = '';
$domain = '';
$path = '';
$expires = null;
$secure = false;
$parts = explode(';', $cookieStr);
// If first part does not include '=', fail
if (strpos($parts[0], '=') === false) return false;
// Get the name and value of the cookie
list($name, $value) = explode('=', trim(array_shift($parts)), 2);
$name = trim($name);
$value = urldecode(trim($value));
// Set default domain and path
if ($ref_uri instanceof Zend_Uri_Http) {
$domain = $ref_uri->getHost();
$path = $ref_uri->getPath();
$path = substr($path, 0, strrpos($path, '/'));
}
// Set other cookie parameters
foreach ($parts as $part) {
$part = trim($part);
if (strtolower($part) == 'secure') {
$secure = true;
continue;
}
$keyValue = explode('=', $part, 2);
if (count($keyValue) == 2) {
list($k, $v) = $keyValue;
switch (strtolower($k)) {
case 'expires':
$expires = strtotime($v);
break;
case 'path':
$path = $v;
break;
case 'domain':
$domain = $v;
break;
default:
break;
}
}
}
if ($name !== '') {
return new Zend_Http_Cookie($name, $value, $domain, $expires, $path, $secure);
} else {
return false;
}
}
}
Http/Client.php 0000604 00000113032 15071256135 0007413 0 ustar 00 <?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_Http
* @subpackage Client
* @version $Id: Client.php 12504 2008-11-10 16:28:46Z matthew $
* @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 Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* @see Zend_Http_Client_Adapter_Interface
*/
require_once 'Zend/Http/Client/Adapter/Interface.php';
/**
* @see Zend_Http_Response
*/
require_once 'Zend/Http/Response.php';
/**
* Zend_Http_Client is an implemetation of an HTTP client in PHP. The client
* supports basic features like sending different HTTP requests and handling
* redirections, as well as more advanced features like proxy settings, HTTP
* authentication and cookie persistance (using a Zend_Http_CookieJar object)
*
* @todo Implement proxy settings
* @category Zend
* @package Zend_Http
* @subpackage Client
* @throws Zend_Http_Client_Exception
* @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_Http_Client
{
/**
* HTTP request methods
*/
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const HEAD = 'HEAD';
const DELETE = 'DELETE';
const TRACE = 'TRACE';
const OPTIONS = 'OPTIONS';
const CONNECT = 'CONNECT';
/**
* Supported HTTP Authentication methods
*/
const AUTH_BASIC = 'basic';
//const AUTH_DIGEST = 'digest'; <-- not implemented yet
/**
* HTTP protocol versions
*/
const HTTP_1 = '1.1';
const HTTP_0 = '1.0';
/**
* Content attributes
*/
const CONTENT_TYPE = 'Content-Type';
const CONTENT_LENGTH = 'Content-Length';
/**
* POST data encoding methods
*/
const ENC_URLENCODED = 'application/x-www-form-urlencoded';
const ENC_FORMDATA = 'multipart/form-data';
/**
* Configuration array, set using the constructor or using ::setConfig()
*
* @var array
*/
protected $config = array(
'maxredirects' => 5,
'strictredirects' => false,
'useragent' => 'Zend_Http_Client',
'timeout' => 10,
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'httpversion' => self::HTTP_1,
'keepalive' => false,
'storeresponse' => true,
'strict' => true
);
/**
* The adapter used to preform the actual connection to the server
*
* @var Zend_Http_Client_Adapter_Interface
*/
protected $adapter = null;
/**
* Request URI
*
* @var Zend_Uri_Http
*/
protected $uri;
/**
* Associative array of request headers
*
* @var array
*/
protected $headers = array();
/**
* HTTP request method
*
* @var string
*/
protected $method = self::GET;
/**
* Associative array of GET parameters
*
* @var array
*/
protected $paramsGet = array();
/**
* Assiciative array of POST parameters
*
* @var array
*/
protected $paramsPost = array();
/**
* Request body content type (for POST requests)
*
* @var string
*/
protected $enctype = null;
/**
* The raw post data to send. Could be set by setRawData($data, $enctype).
*
* @var string
*/
protected $raw_post_data = null;
/**
* HTTP Authentication settings
*
* Expected to be an associative array with this structure:
* $this->auth = array('user' => 'username', 'password' => 'password', 'type' => 'basic')
* Where 'type' should be one of the supported authentication types (see the AUTH_*
* constants), for example 'basic' or 'digest'.
*
* If null, no authentication will be used.
*
* @var array|null
*/
protected $auth;
/**
* File upload arrays (used in POST requests)
*
* An associative array, where each element is of the format:
* 'name' => array('filename.txt', 'text/plain', 'This is the actual file contents')
*
* @var array
*/
protected $files = array();
/**
* The client's cookie jar
*
* @var Zend_Http_CookieJar
*/
protected $cookiejar = null;
/**
* The last HTTP request sent by the client, as string
*
* @var string
*/
protected $last_request = null;
/**
* The last HTTP response received by the client
*
* @var Zend_Http_Response
*/
protected $last_response = null;
/**
* Redirection counter
*
* @var int
*/
protected $redirectCounter = 0;
/**
* Fileinfo magic database resource
*
* This varaiable is populated the first time _detectFileMimeType is called
* and is then reused on every call to this method
*
* @var resource
*/
static protected $_fileInfoDb = null;
/**
* Contructor method. Will create a new HTTP client. Accepts the target
* URL and optionally configuration array.
*
* @param Zend_Uri_Http|string $uri
* @param array $config Configuration key-value pairs.
*/
public function __construct($uri = null, $config = null)
{
if ($uri !== null) $this->setUri($uri);
if ($config !== null) $this->setConfig($config);
}
/**
* Set the URI for the next request
*
* @param Zend_Uri_Http|string $uri
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setUri($uri)
{
if (is_string($uri)) {
$uri = Zend_Uri::factory($uri);
}
if (!$uri instanceof Zend_Uri_Http) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
}
// We have no ports, set the defaults
if (! $uri->getPort()) {
$uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
}
$this->uri = $uri;
return $this;
}
/**
* Get the URI for the next request
*
* @param boolean $as_string If true, will return the URI as a string
* @return Zend_Uri_Http|string
*/
public function getUri($as_string = false)
{
if ($as_string && $this->uri instanceof Zend_Uri_Http) {
return $this->uri->__toString();
} else {
return $this->uri;
}
}
/**
* Set configuration parameters for this HTTP client
*
* @param array $config
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setConfig($config = array())
{
if (! is_array($config)) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Expected array parameter, given ' . gettype($config));
}
foreach ($config as $k => $v)
$this->config[strtolower($k)] = $v;
// Pass configuration options to the adapter if it exists
if ($this->adapter instanceof Zend_Http_Client_Adapter_Interface) {
$this->adapter->setConfig($config);
}
return $this;
}
/**
* Set the next request's method
*
* Validated the passed method and sets it. If we have files set for
* POST requests, and the new method is not POST, the files are silently
* dropped.
*
* @param string $method
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setMethod($method = self::GET)
{
$regex = '/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/';
if (! preg_match($regex, $method)) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("'{$method}' is not a valid HTTP request method.");
}
if ($method == self::POST && $this->enctype === null)
$this->setEncType(self::ENC_URLENCODED);
$this->method = $method;
return $this;
}
/**
* Set one or more request headers
*
* This function can be used in several ways to set the client's request
* headers:
* 1. By providing two parameters: $name as the header to set (eg. 'Host')
* and $value as it's value (eg. 'www.example.com').
* 2. By providing a single header string as the only parameter
* eg. 'Host: www.example.com'
* 3. By providing an array of headers as the first parameter
* eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case
* the function will call itself recursively for each array item.
*
* @param string|array $name Header name, full header string ('Header: value')
* or an array of headers
* @param mixed $value Header value or null
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setHeaders($name, $value = null)
{
// If we got an array, go recusive!
if (is_array($name)) {
foreach ($name as $k => $v) {
if (is_string($k)) {
$this->setHeaders($k, $v);
} else {
$this->setHeaders($v, null);
}
}
} else {
// Check if $name needs to be split
if ($value === null && (strpos($name, ':') > 0))
list($name, $value) = explode(':', $name, 2);
// Make sure the name is valid if we are in strict mode
if ($this->config['strict'] && (! preg_match('/^[a-zA-Z0-9-]+$/', $name))) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("{$name} is not a valid HTTP header name");
}
$normalized_name = strtolower($name);
// If $value is null or false, unset the header
if ($value === null || $value === false) {
unset($this->headers[$normalized_name]);
// Else, set the header
} else {
// Header names are storred lowercase internally.
if (is_string($value)) $value = trim($value);
$this->headers[$normalized_name] = array($name, $value);
}
}
return $this;
}
/**
* Get the value of a specific header
*
* Note that if the header has more than one value, an array
* will be returned.
*
* @param string $key
* @return string|array|null The header value or null if it is not set
*/
public function getHeader($key)
{
$key = strtolower($key);
if (isset($this->headers[$key])) {
return $this->headers[$key][1];
} else {
return null;
}
}
/**
* Set a GET parameter for the request. Wrapper around _setParameter
*
* @param string|array $name
* @param string $value
* @return Zend_Http_Client
*/
public function setParameterGet($name, $value = null)
{
if (is_array($name)) {
foreach ($name as $k => $v)
$this->_setParameter('GET', $k, $v);
} else {
$this->_setParameter('GET', $name, $value);
}
return $this;
}
/**
* Set a POST parameter for the request. Wrapper around _setParameter
*
* @param string|array $name
* @param string $value
* @return Zend_Http_Client
*/
public function setParameterPost($name, $value = null)
{
if (is_array($name)) {
foreach ($name as $k => $v)
$this->_setParameter('POST', $k, $v);
} else {
$this->_setParameter('POST', $name, $value);
}
return $this;
}
/**
* Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
*
* @param string $type GET or POST
* @param string $name
* @param string $value
* @return null
*/
protected function _setParameter($type, $name, $value)
{
$parray = array();
$type = strtolower($type);
switch ($type) {
case 'get':
$parray = &$this->paramsGet;
break;
case 'post':
$parray = &$this->paramsPost;
break;
}
if ($value === null) {
if (isset($parray[$name])) unset($parray[$name]);
} else {
$parray[$name] = $value;
}
}
/**
* Get the number of redirections done on the last request
*
* @return int
*/
public function getRedirectionsCount()
{
return $this->redirectCounter;
}
/**
* Set HTTP authentication parameters
*
* $type should be one of the supported types - see the self::AUTH_*
* constants.
*
* To enable authentication:
* <code>
* $this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);
* </code>
*
* To disable authentication:
* <code>
* $this->setAuth(false);
* </code>
*
* @see http://www.faqs.org/rfcs/rfc2617.html
* @param string|false $user User name or false disable authentication
* @param string $password Password
* @param string $type Authentication type
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
{
// If we got false or null, disable authentication
if ($user === false || $user === null) {
$this->auth = null;
// Else, set up authentication
} else {
// Check we got a proper authentication type
if (! defined('self::AUTH_' . strtoupper($type))) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '$type'");
}
$this->auth = array(
'user' => (string) $user,
'password' => (string) $password,
'type' => $type
);
}
return $this;
}
/**
* Set the HTTP client's cookie jar.
*
* A cookie jar is an object that holds and maintains cookies across HTTP requests
* and responses.
*
* @param Zend_Http_CookieJar|boolean $cookiejar Existing cookiejar object, true to create a new one, false to disable
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setCookieJar($cookiejar = true)
{
if (! class_exists('Zend_Http_CookieJar'))
require_once 'Zend/Http/CookieJar.php';
if ($cookiejar instanceof Zend_Http_CookieJar) {
$this->cookiejar = $cookiejar;
} elseif ($cookiejar === true) {
$this->cookiejar = new Zend_Http_CookieJar();
} elseif (! $cookiejar) {
$this->cookiejar = null;
} else {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Invalid parameter type passed as CookieJar');
}
return $this;
}
/**
* Return the current cookie jar or null if none.
*
* @return Zend_Http_CookieJar|null
*/
public function getCookieJar()
{
return $this->cookiejar;
}
/**
* Add a cookie to the request. If the client has no Cookie Jar, the cookies
* will be added directly to the headers array as "Cookie" headers.
*
* @param Zend_Http_Cookie|string $cookie
* @param string|null $value If "cookie" is a string, this is the cookie value.
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setCookie($cookie, $value = null)
{
if (! class_exists('Zend_Http_Cookie'))
require_once 'Zend/Http/Cookie.php';
if (is_array($cookie)) {
foreach ($cookie as $c => $v) {
if (is_string($c)) {
$this->setCookie($c, $v);
} else {
$this->setCookie($v);
}
}
return $this;
}
if ($value !== null) $value = urlencode($value);
if (isset($this->cookiejar)) {
if ($cookie instanceof Zend_Http_Cookie) {
$this->cookiejar->addCookie($cookie);
} elseif (is_string($cookie) && $value !== null) {
$cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri);
$this->cookiejar->addCookie($cookie);
}
} else {
if ($cookie instanceof Zend_Http_Cookie) {
$name = $cookie->getName();
$value = $cookie->getValue();
$cookie = $name;
}
if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");
}
$value = addslashes($value);
if (! isset($this->headers['cookie'])) $this->headers['cookie'] = array('Cookie', '');
$this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
}
return $this;
}
/**
* Set a file to upload (using a POST request)
*
* Can be used in two ways:
*
* 1. $data is null (default): $filename is treated as the name if a local file which
* will be read and sent. Will try to guess the content type using mime_content_type().
* 2. $data is set - $filename is sent as the file name, but $data is sent as the file
* contents and no file is read from the file system. In this case, you need to
* manually set the Content-Type ($ctype) or it will default to
* application/octet-stream.
*
* @param string $filename Name of file to upload, or name to save as
* @param string $formname Name of form element to send as
* @param string $data Data to send (if null, $filename is read and sent)
* @param string $ctype Content type to use (if $data is set and $ctype is
* null, will be application/octet-stream)
* @return Zend_Http_Client
* @throws Zend_Http_Client_Exception
*/
public function setFileUpload($filename, $formname, $data = null, $ctype = null)
{
if ($data === null) {
if (($data = @file_get_contents($filename)) === false) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Unable to read file '{$filename}' for upload");
}
if (! $ctype) $ctype = $this->_detectFileMimeType($filename);
}
// Force enctype to multipart/form-data
$this->setEncType(self::ENC_FORMDATA);
$this->files[$formname] = array(basename($filename), $ctype, $data);
return $this;
}
/**
* Set the encoding type for POST data
*
* @param string $enctype
* @return Zend_Http_Client
*/
public function setEncType($enctype = self::ENC_URLENCODED)
{
$this->enctype = $enctype;
return $this;
}
/**
* Set the raw (already encoded) POST data.
*
* This function is here for two reasons:
* 1. For advanced user who would like to set their own data, already encoded
* 2. For backwards compatibilty: If someone uses the old post($data) method.
* this method will be used to set the encoded data.
*
* @param string $data
* @param string $enctype
* @return Zend_Http_Client
*/
public function setRawData($data, $enctype = null)
{
$this->raw_post_data = $data;
$this->setEncType($enctype);
return $this;
}
/**
* Clear all GET and POST parameters
*
* Should be used to reset the request parameters if the client is
* used for several concurrent requests.
*
* @return Zend_Http_Client
*/
public function resetParameters()
{
// Reset parameter data
$this->paramsGet = array();
$this->paramsPost = array();
$this->files = array();
$this->raw_post_data = null;
// Clear outdated headers
if (isset($this->headers[strtolower(self::CONTENT_TYPE)]))
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)]))
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
return $this;
}
/**
* Get the last HTTP request as string
*
* @return string
*/
public function getLastRequest()
{
return $this->last_request;
}
/**
* Get the last HTTP response received by this client
*
* If $config['storeresponse'] is set to false, or no response was
* stored yet, will return null
*
* @return Zend_Http_Response or null if none
*/
public function getLastResponse()
{
return $this->last_response;
}
/**
* Load the connection adapter
*
* While this method is not called more than one for a client, it is
* seperated from ->request() to preserve logic and readability
*
* @param Zend_Http_Client_Adapter_Interface|string $adapter
* @return null
* @throws Zend_Http_Client_Exception
*/
public function setAdapter($adapter)
{
if (is_string($adapter)) {
try {
Zend_Loader::loadClass($adapter);
} catch (Zend_Exception $e) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}");
}
$adapter = new $adapter;
}
if (! $adapter instanceof Zend_Http_Client_Adapter_Interface) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
}
$this->adapter = $adapter;
$config = $this->config;
unset($config['adapter']);
$this->adapter->setConfig($config);
}
/**
* Send the HTTP request and return an HTTP response object
*
* @param string $method
* @return Zend_Http_Response
* @throws Zend_Http_Client_Exception
*/
public function request($method = null)
{
if (! $this->uri instanceof Zend_Uri_Http) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
}
if ($method) $this->setMethod($method);
$this->redirectCounter = 0;
$response = null;
// Make sure the adapter is loaded
if ($this->adapter == null) $this->setAdapter($this->config['adapter']);
// Send the first request. If redirected, continue.
do {
// Clone the URI and add the additional GET parameters to it
$uri = clone $this->uri;
if (! empty($this->paramsGet)) {
$query = $uri->getQuery();
if (! empty($query)) $query .= '&';
$query .= http_build_query($this->paramsGet, null, '&');
$uri->setQuery($query);
}
$body = $this->_prepareBody();
$headers = $this->_prepareHeaders();
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(),
($uri->getScheme() == 'https' ? true : false));
$this->last_request = $this->adapter->write($this->method,
$uri, $this->config['httpversion'], $headers, $body);
$response = $this->adapter->read();
if (! $response) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception('Unable to read response, or response is empty');
}
$response = Zend_Http_Response::fromString($response);
if ($this->config['storeresponse']) $this->last_response = $response;
// Load cookies into cookie jar
if (isset($this->cookiejar)) $this->cookiejar->addCookiesFromResponse($response, $uri);
// If we got redirected, look for the Location header
if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
// Check whether we send the exact same request again, or drop the parameters
// and send a GET request
if ($response->getStatus() == 303 ||
((! $this->config['strictredirects']) && ($response->getStatus() == 302 ||
$response->getStatus() == 301))) {
$this->resetParameters();
$this->setMethod(self::GET);
}
// If we got a well formed absolute URI
if (Zend_Uri_Http::check($location)) {
$this->setHeaders('host', null);
$this->setUri($location);
} else {
// Split into path and query and set the query
if (strpos($location, '?') !== false) {
list($location, $query) = explode('?', $location, 2);
} else {
$query = '';
}
$this->uri->setQuery($query);
// Else, if we got just an absolute path, set it
if(strpos($location, '/') === 0) {
$this->uri->setPath($location);
// Else, assume we have a relative path
} else {
// Get the current path directory, removing any trailing slashes
$path = $this->uri->getPath();
$path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
$this->uri->setPath($path . '/' . $location);
}
}
++$this->redirectCounter;
} else {
// If we didn't get any location, stop redirecting
break;
}
} while ($this->redirectCounter < $this->config['maxredirects']);
return $response;
}
/**
* Prepare the request headers
*
* @return array
*/
protected function _prepareHeaders()
{
$headers = array();
// Set the host header
if (! isset($this->headers['host'])) {
$host = $this->uri->getHost();
// If the port is not default, add it
if (! (($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80) ||
($this->uri->getScheme() == 'https' && $this->uri->getPort() == 443))) {
$host .= ':' . $this->uri->getPort();
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (! isset($this->headers['connection'])) {
if (! $this->config['keepalive']) $headers[] = "Connection: close";
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (! isset($this->headers['accept-encoding'])) {
if (function_exists('gzinflate')) {
$headers[] = 'Accept-encoding: gzip, deflate';
} else {
$headers[] = 'Accept-encoding: identity';
}
}
// Set the Content-Type header
if ($this->method == self::POST &&
(! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
}
// Set the user agent header
if (! isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
$headers[] = "User-Agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($this->uri,
true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) $headers[] = "Cookie: {$cookstr}";
}
// Add all other user defined headers
foreach ($this->headers as $header) {
list($name, $value) = $header;
if (is_array($value))
$value = implode(', ', $value);
$headers[] = "$name: $value";
}
return $headers;
}
/**
* Prepare the request body (for POST and PUT requests)
*
* @return string
* @throws Zend_Http_Client_Exception
*/
protected function _prepareBody()
{
// According to RFC2616, a TRACE request should not have a body.
if ($this->method == self::TRACE) {
return '';
}
// If we have raw_post_data set, just use it as the body.
if (isset($this->raw_post_data)) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
return $this->raw_post_data;
}
$body = '';
// If we have files to upload, force enctype to multipart/form-data
if (count ($this->files) > 0) $this->setEncType(self::ENC_FORMDATA);
// If we have POST parameters or files, encode and add them to the body
if (count($this->paramsPost) > 0 || count($this->files) > 0) {
switch($this->enctype) {
case self::ENC_FORMDATA:
// Encode body as multipart/form-data
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
// Get POST parameters and encode them
$params = $this->_getParametersRecursive($this->paramsPost);
foreach ($params as $pp) {
$body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
}
// Encode files
foreach ($this->files as $name => $file) {
$fhead = array(self::CONTENT_TYPE => $file[1]);
$body .= self::encodeFormData($boundary, $name, $file[2], $file[0], $fhead);
}
$body .= "--{$boundary}--\r\n";
break;
case self::ENC_URLENCODED:
// Encode body as application/x-www-form-urlencoded
$this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
$body = http_build_query($this->paramsPost, '', '&');
break;
default:
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Cannot handle content type '{$this->enctype}' automatically." .
" Please use Zend_Http_Client::setRawData to send this kind of content.");
break;
}
}
// Set the Content-Length if we have a body or if request is POST/PUT
if ($body || $this->method == self::POST || $this->method == self::PUT) {
$this->setHeaders(self::CONTENT_LENGTH, strlen($body));
}
return $body;
}
/**
* Helper method that gets a possibly multi-level parameters array (get or
* post) and flattens it.
*
* The method returns an array of (key, value) pairs (because keys are not
* necessarily unique. If one of the parameters in as array, it will also
* add a [] suffix to the key.
*
* @param array $parray The parameters array
* @param bool $urlencode Whether to urlencode the name and value
* @return array
*/
protected function _getParametersRecursive($parray, $urlencode = false)
{
if (! is_array($parray)) return $parray;
$parameters = array();
foreach ($parray as $name => $value) {
if ($urlencode) $name = urlencode($name);
// If $value is an array, iterate over it
if (is_array($value)) {
$name .= ($urlencode ? '%5B%5D' : '[]');
foreach ($value as $subval) {
if ($urlencode) $subval = urlencode($subval);
$parameters[] = array($name, $subval);
}
} else {
if ($urlencode) $value = urlencode($value);
$parameters[] = array($name, $value);
}
}
return $parameters;
}
/**
* Attempt to detect the MIME type of a file using available extensions
*
* This method will try to detect the MIME type of a file. If the fileinfo
* extension is available, it will be used. If not, the mime_magic
* extension which is deprected but is still available in many PHP setups
* will be tried.
*
* If neither extension is available, the default application/octet-stream
* MIME type will be returned
*
* @param string $file File path
* @return string MIME type
*/
protected function _detectFileMimeType($file)
{
$type = null;
// First try with fileinfo functions
if (function_exists('finfo_open')) {
if (self::$_fileInfoDb === null) {
self::$_fileInfoDb = @finfo_open(FILEINFO_MIME);
}
if (self::$_fileInfoDb) {
$type = finfo_file(self::$_fileInfoDb, $file);
}
} elseif (function_exists('mime_content_type')) {
$type = mime_content_type($file);
}
// Fallback to the default application/octet-stream
if (! $type) {
$type = 'application/octet-stream';
}
return $type;
}
/**
* Encode data to a multipart/form-data part suitable for a POST request.
*
* @param string $boundary
* @param string $name
* @param mixed $value
* @param string $filename
* @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary")
* @return string
*/
public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) {
$ret = "--{$boundary}\r\n" .
'Content-Disposition: form-data; name="' . $name .'"';
if ($filename) $ret .= '; filename="' . $filename . '"';
$ret .= "\r\n";
foreach ($headers as $hname => $hvalue) {
$ret .= "{$hname}: {$hvalue}\r\n";
}
$ret .= "\r\n";
$ret .= "{$value}\r\n";
return $ret;
}
/**
* Create a HTTP authentication "Authorization:" header according to the
* specified user, password and authentication method.
*
* @see http://www.faqs.org/rfcs/rfc2617.html
* @param string $user
* @param string $password
* @param string $type
* @return string
* @throws Zend_Http_Client_Exception
*/
public static function encodeAuthHeader($user, $password, $type = self::AUTH_BASIC)
{
$authHeader = null;
switch ($type) {
case self::AUTH_BASIC:
// In basic authentication, the user name cannot contain ":"
if (strpos($user, ':') !== false) {
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("The user name cannot contain ':' in 'Basic' HTTP authentication");
}
$authHeader = 'Basic ' . base64_encode($user . ':' . $password);
break;
//case self::AUTH_DIGEST:
/**
* @todo Implement digest authentication
*/
// break;
default:
/** @see Zend_Http_Client_Exception */
require_once 'Zend/Http/Client/Exception.php';
throw new Zend_Http_Client_Exception("Not a supported HTTP authentication type: '$type'");
}
return $authHeader;
}
}
Http/Exception.php 0000604 00000002114 15071256135 0010131 0 ustar 00 <?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_Http
* @subpackage Exception
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Http
* @subpackage Client
* @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_Http_Exception extends Zend_Exception
{}
Measure/Density.php 0000604 00000030356 15071256135 0010305 0 ustar 00 <?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_Measure
* @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: Density.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling density conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Density
* @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_Measure_Density extends Zend_Measure_Abstract
{
const STANDARD = 'KILOGRAM_PER_CUBIC_METER';
const ALUMINIUM = 'ALUMINIUM';
const COPPER = 'COPPER';
const GOLD = 'GOLD';
const GRAIN_PER_CUBIC_FOOT = 'GRAIN_PER_CUBIC_FOOT';
const GRAIN_PER_CUBIC_INCH = 'GRAIN_PER_CUBIC_INCH';
const GRAIN_PER_CUBIC_YARD = 'GRAIN_PER_CUBIC_YARD';
const GRAIN_PER_GALLON = 'GRAIN_PER_GALLON';
const GRAIN_PER_GALLON_US = 'GRAIN_PER_GALLON_US';
const GRAM_PER_CUBIC_CENTIMETER = 'GRAM_PER_CUBIC_CENTIMETER';
const GRAM_PER_CUBIC_DECIMETER = 'GRAM_PER_CUBIC_DECIMETER';
const GRAM_PER_CUBIC_METER = 'GRAM_PER_CUBIC_METER';
const GRAM_PER_LITER = 'GRAM_PER_LITER';
const GRAM_PER_MILLILITER = 'GRAM_PER_MILLILITER';
const IRON = 'IRON';
const KILOGRAM_PER_CUBIC_CENTIMETER = 'KILOGRAM_PER_CUBIC_CENTIMETER';
const KILOGRAM_PER_CUBIC_DECIMETER = 'KILOGRAM_PER_CUBIC_DECIMETER';
const KILOGRAM_PER_CUBIC_METER = 'KILOGRAM_PER_CUBIC_METER';
const KILOGRAM_PER_CUBIC_MILLIMETER = 'KILOGRAM_PER_CUBIC_MILLIMETER';
const KILOGRAM_PER_LITER = 'KILOGRAM_PER_LITER';
const KILOGRAM_PER_MILLILITER = 'KILOGRAM_PER_MILLILITER';
const LEAD = 'LEAD';
const MEGAGRAM_PER_CUBIC_CENTIMETER = 'MEGAGRAM_PER_CUBIC_CENTIMETER';
const MEGAGRAM_PER_CUBIC_DECIMETER = 'MEGAGRAM_PER_CUBIC_DECIMETER';
const MEGAGRAM_PER_CUBIC_METER = 'MEGAGRAM_PER_CUBIC_METER';
const MEGAGRAM_PER_LITER = 'MEGAGRAM_PER_LITER';
const MEGAGRAM_PER_MILLILITER = 'MEGAGRAM_PER_MILLILITER';
const MICROGRAM_PER_CUBIC_CENTIMETER = 'MICROGRAM_PER_CUBIC_CENTIMETER';
const MICROGRAM_PER_CUBIC_DECIMETER = 'MICROGRAM_PER_CUBIC_DECIMETER';
const MICROGRAM_PER_CUBIC_METER = 'MICROGRAM_PER_CUBIC_METER';
const MICROGRAM_PER_LITER = 'MICROGRAM_PER_LITER';
const MICROGRAM_PER_MILLILITER = 'MICROGRAM_PER_MILLILITER';
const MILLIGRAM_PER_CUBIC_CENTIMETER = 'MILLIGRAM_PER_CUBIC_CENTIMETER';
const MILLIGRAM_PER_CUBIC_DECIMETER = 'MILLIGRAM_PER_CUBIC_DECIMETER';
const MILLIGRAM_PER_CUBIC_METER = 'MILLIGRAM_PER_CUBIC_METER';
const MILLIGRAM_PER_LITER = 'MILLIGRAM_PER_LITER';
const MILLIGRAM_PER_MILLILITER = 'MILLIGRAM_PER_MILLILITER';
const OUNCE_PER_CUBIC_FOOT = 'OUNCE_PER_CUBIC_FOOT';
const OUNCR_PER_CUBIC_FOOT_TROY = 'OUNCE_PER_CUBIC_FOOT_TROY';
const OUNCE_PER_CUBIC_INCH = 'OUNCE_PER_CUBIC_INCH';
const OUNCE_PER_CUBIC_INCH_TROY = 'OUNCE_PER_CUBIC_INCH_TROY';
const OUNCE_PER_CUBIC_YARD = 'OUNCE_PER_CUBIC_YARD';
const OUNCE_PER_CUBIC_YARD_TROY = 'OUNCE_PER_CUBIC_YARD_TROY';
const OUNCE_PER_GALLON = 'OUNCE_PER_GALLON';
const OUNCE_PER_GALLON_US = 'OUNCE_PER_GALLON_US';
const OUNCE_PER_GALLON_TROY = 'OUNCE_PER_GALLON_TROY';
const OUNCE_PER_GALLON_US_TROY = 'OUNCE_PER_GALLON_US_TROY';
const POUND_PER_CIRCULAR_MIL_FOOT = 'POUND_PER_CIRCULAR_MIL_FOOT';
const POUND_PER_CUBIC_FOOT = 'POUND_PER_CUBIC_FOOT';
const POUND_PER_CUBIC_INCH = 'POUND_PER_CUBIC_INCH';
const POUND_PER_CUBIC_YARD = 'POUND_PER_CUBIC_YARD';
const POUND_PER_GALLON = 'POUND_PER_GALLON';
const POUND_PER_KILOGALLON = 'POUND_PER_KILOGALLON';
const POUND_PER_MEGAGALLON = 'POUND_PER_MEGAGALLON';
const POUND_PER_GALLON_US = 'POUND_PER_GALLON_US';
const POUND_PER_KILOGALLON_US = 'POUND_PER_KILOGALLON_US';
const POUND_PER_MEGAGALLON_US = 'POUND_PER_MEGAGALLON_US';
const SILVER = 'SILVER';
const SLUG_PER_CUBIC_FOOT = 'SLUG_PER_CUBIC_FOOT';
const SLUG_PER_CUBIC_INCH = 'SLUG_PER_CUBIC_INCH';
const SLUG_PER_CUBIC_YARD = 'SLUG_PER_CUBIC_YARD';
const SLUG_PER_GALLON = 'SLUG_PER_GALLON';
const SLUG_PER_GALLON_US = 'SLUG_PER_GALLON_US';
const TON_PER_CUBIC_FOOT_LONG = 'TON_PER_CUBIC_FOOT_LONG';
const TON_PER_CUBIC_FOOT = 'TON_PER_CUBIC_FOOT';
const TON_PER_CUBIC_INCH_LONG = 'TON_PER_CUBIC_INCH_LONG';
const TON_PER_CUBIC_INCH = 'TON_PER_CUBIC_INCH';
const TON_PER_CUBIC_YARD_LONG = 'TON_PER_CUBIC_YARD_LONG';
const TON_PER_CUBIC_YARD = 'TON_PER_CUBIC_YARD';
const TON_PER_GALLON_LONG = 'TON_PER_GALLON_LONG';
const TON_PER_GALLON_US_LONG = 'TON_PER_GALLON_US_LONG';
const TON_PER_GALLON = 'TON_PER_GALLON';
const TON_PER_GALLON_US = 'TON_PER_GALLON_US';
const TONNE_PER_CUBIC_CENTIMETER = 'TONNE_PER_CUBIC_CENTIMETER';
const TONNE_PER_CUBIC_DECIMETER = 'TONNE_PER_CUBIC_DECIMETER';
const TONNE_PER_CUBIC_METER = 'TONNE_PER_CUBIC_METER';
const TONNE_PER_LITER = 'TONNE_PER_LITER';
const TONNE_PER_MILLILITER = 'TONNE_PER_MILLILITER';
const WATER = 'WATER';
/**
* Calculations for all density units
*
* @var array
*/
protected $_units = array(
'ALUMINIUM' => array('2643', 'aluminium'),
'COPPER' => array('8906', 'copper'),
'GOLD' => array('19300', 'gold'),
'GRAIN_PER_CUBIC_FOOT' => array('0.0022883519', 'gr/ft³'),
'GRAIN_PER_CUBIC_INCH' => array('3.9542721', 'gr/in³'),
'GRAIN_PER_CUBIC_YARD' => array('0.000084753774', 'gr/yd³'),
'GRAIN_PER_GALLON' => array('0.014253768', 'gr/gal'),
'GRAIN_PER_GALLON_US' => array('0.017118061', 'gr/gal'),
'GRAM_PER_CUBIC_CENTIMETER' => array('1000', 'g/cm³'),
'GRAM_PER_CUBIC_DECIMETER' => array('1', 'g/dm³'),
'GRAM_PER_CUBIC_METER' => array('0.001', 'g/m³'),
'GRAM_PER_LITER' => array('1', 'g/l'),
'GRAM_PER_MILLILITER' => array('1000', 'g/ml'),
'IRON' => array('7658', 'iron'),
'KILOGRAM_PER_CUBIC_CENTIMETER' => array('1000000', 'kg/cm³'),
'KILOGRAM_PER_CUBIC_DECIMETER' => array('1000', 'kg/dm³'),
'KILOGRAM_PER_CUBIC_METER' => array('1', 'kg/m³'),
'KILOGRAM_PER_CUBIC_MILLIMETER' => array('1000000000', 'kg/l'),
'KILOGRAM_PER_LITER' => array('1000', 'kg/ml'),
'KILOGRAM_PER_MILLILITER' => array('1000000', 'kg/ml'),
'LEAD' => array('11370', 'lead'),
'MEGAGRAM_PER_CUBIC_CENTIMETER' => array('1.0e+9', 'Mg/cm³'),
'MEGAGRAM_PER_CUBIC_DECIMETER' => array('1000000', 'Mg/dm³'),
'MEGAGRAM_PER_CUBIC_METER' => array('1000', 'Mg/m³'),
'MEGAGRAM_PER_LITER' => array('1000000', 'Mg/l'),
'MEGAGRAM_PER_MILLILITER' => array('1.0e+9', 'Mg/ml'),
'MICROGRAM_PER_CUBIC_CENTIMETER' => array('0.001', 'µg/cm³'),
'MICROGRAM_PER_CUBIC_DECIMETER' => array('1.0e-6', 'µg/dm³'),
'MICROGRAM_PER_CUBIC_METER' => array('1.0e-9', 'µg/m³'),
'MICROGRAM_PER_LITER' => array('1.0e-6', 'µg/l'),
'MICROGRAM_PER_MILLILITER' => array('0.001', 'µg/ml'),
'MILLIGRAM_PER_CUBIC_CENTIMETER' => array('1', 'mg/cm³'),
'MILLIGRAM_PER_CUBIC_DECIMETER' => array('0.001', 'mg/dm³'),
'MILLIGRAM_PER_CUBIC_METER' => array('0.000001', 'mg/m³'),
'MILLIGRAM_PER_LITER' => array('0.001', 'mg/l'),
'MILLIGRAM_PER_MILLILITER' => array('1', 'mg/ml'),
'OUNCE_PER_CUBIC_FOOT' => array('1.001154', 'oz/ft³'),
'OUNCE_PER_CUBIC_FOOT_TROY' => array('1.0984089', 'oz/ft³'),
'OUNCE_PER_CUBIC_INCH' => array('1729.994', 'oz/in³'),
'OUNCE_PER_CUBIC_INCH_TROY' => array('1898.0506', 'oz/in³'),
'OUNCE_PER_CUBIC_YARD' => array('0.037079776', 'oz/yd³'),
'OUNCE_PER_CUBIC_YARD_TROY' => array('0.040681812', 'oz/yd³'),
'OUNCE_PER_GALLON' => array('6.2360233', 'oz/gal'),
'OUNCE_PER_GALLON_US' => array('7.4891517', 'oz/gal'),
'OUNCE_PER_GALLON_TROY' => array('6.8418084', 'oz/gal'),
'OUNCE_PER_GALLON_US_TROY' => array('8.2166693', 'oz/gal'),
'POUND_PER_CIRCULAR_MIL_FOOT' => array('2.9369291', 'lb/cmil ft'),
'POUND_PER_CUBIC_FOOT' => array('16.018463', 'lb/in³'),
'POUND_PER_CUBIC_INCH' => array('27679.905', 'lb/in³'),
'POUND_PER_CUBIC_YARD' => array('0.59327642', 'lb/yd³'),
'POUND_PER_GALLON' => array('99.776373', 'lb/gal'),
'POUND_PER_KILOGALLON' => array('0.099776373', 'lb/kgal'),
'POUND_PER_MEGAGALLON' => array('0.000099776373', 'lb/Mgal'),
'POUND_PER_GALLON_US' => array('119.82643', 'lb/gal'),
'POUND_PER_KILOGALLON_US' => array('0.11982643', 'lb/kgal'),
'POUND_PER_MEGAGALLON_US' => array('0.00011982643', 'lb/Mgal'),
'SILVER' => array('10510', 'silver'),
'SLUG_PER_CUBIC_FOOT' => array('515.37882', 'slug/ft³'),
'SLUG_PER_CUBIC_INCH' => array('890574.6', 'slug/in³'),
'SLUG_PER_CUBIC_YARD' => array('19.088104', 'slug/yd³'),
'SLUG_PER_GALLON' => array('3210.2099', 'slug/gal'),
'SLUG_PER_GALLON_US' => array('3855.3013', 'slug/gal'),
'TON_PER_CUBIC_FOOT_LONG' => array('35881.358', 't/ft³'),
'TON_PER_CUBIC_FOOT' => array('32036.927', 't/ft³'),
'TON_PER_CUBIC_INCH_LONG' => array('6.2202987e+7', 't/in³'),
'TON_PER_CUBIC_INCH' => array('5.5359809e+7', 't/in³'),
'TON_PER_CUBIC_YARD_LONG' => array('1328.9392', 't/yd³'),
'TON_PER_CUBIC_YARD' => array('1186.5528', 't/yd³'),
'TON_PER_GALLON_LONG' => array('223499.07', 't/gal'),
'TON_PER_GALLON_US_LONG' => array('268411.2', 't/gal'),
'TON_PER_GALLON' => array('199522.75', 't/gal'),
'TON_PER_GALLON_US' => array('239652.85', 't/gal'),
'TONNE_PER_CUBIC_CENTIMETER' => array('1.0e+9', 't/cm³'),
'TONNE_PER_CUBIC_DECIMETER' => array('1000000', 't/dm³'),
'TONNE_PER_CUBIC_METER' => array('1000', 't/m³'),
'TONNE_PER_LITER' => array('1000000', 't/l'),
'TONNE_PER_MILLILITER' => array('1.0e+9', 't/ml'),
'WATER' => array('1000', 'water'),
'STANDARD' => 'KILOGRAM_PER_CUBIC_METER'
);
}
Measure/Number.php 0000604 00000031704 15071256135 0010114 0 ustar 00 <?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_Measure
* @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: Number.php 12514 2008-11-10 16:30:24Z matthew $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling number conversions
*
* This class can only handle numbers without precission
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Number
* @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_Measure_Number extends Zend_Measure_Abstract
{
const STANDARD = 'DECIMAL';
const BINARY = 'BINARY';
const TERNARY = 'TERNARY';
const QUATERNARY = 'QUATERNARY';
const QUINARY = 'QUINARY';
const SENARY = 'SENARY';
const SEPTENARY = 'SEPTENARY';
const OCTAL = 'OCTAL';
const NONARY = 'NONARY';
const DECIMAL = 'DECIMAL';
const DUODECIMAL = 'DUODECIMAL';
const HEXADECIMAL = 'HEXADECIMAL';
const ROMAN = 'ROMAN';
/**
* Calculations for all number units
*
* @var array
*/
protected $_units = array(
'BINARY' => array(2, '⑵'),
'TERNARY' => array(3, '⑶'),
'QUATERNARY' => array(4, '⑷'),
'QUINARY' => array(5, '⑸'),
'SENARY' => array(6, '⑹'),
'SEPTENARY' => array(7, '⑺'),
'OCTAL' => array(8, '⑻'),
'NONARY' => array(9, '⑼'),
'DECIMAL' => array(10, '⑽'),
'DUODECIMAL' => array(12, '⑿'),
'HEXADECIMAL' => array(16, '⒃'),
'ROMAN' => array(99, ''),
'STANDARD' => 'DECIMAL'
);
/**
* Definition of all roman signs
*
* @var array $_roman
*/
private static $_roman = array(
'I' => 1,
'A' => 4,
'V' => 5,
'B' => 9,
'X' => 10,
'E' => 40,
'L' => 50,
'F' => 90,
'C' => 100,
'G' => 400,
'D' => 500,
'H' => 900,
'M' => 1000,
'J' => 4000,
'P' => 5000,
'K' => 9000,
'Q' => 10000,
'N' => 40000,
'R' => 50000,
'W' => 90000,
'S' => 100000,
'Y' => 400000,
'T' => 500000,
'Z' => 900000,
'U' => 1000000
);
/**
* Convertion table for roman signs
*
* @var array $_romanconvert
*/
private static $_romanconvert = array(
'/_V/' => '/P/',
'/_X/' => '/Q/',
'/_L/' => '/R/',
'/_C/' => '/S/',
'/_D/' => '/T/',
'/_M/' => '/U/',
'/IV/' => '/A/',
'/IX/' => '/B/',
'/XL/' => '/E/',
'/XC/' => '/F/',
'/CD/' => '/G/',
'/CM/' => '/H/',
'/M_V/'=> '/J/',
'/MQ/' => '/K/',
'/QR/' => '/N/',
'/QS/' => '/W/',
'/ST/' => '/Y/',
'/SU/' => '/Z/'
);
/**
* Zend_Measure_Abstract is an abstract class for the different measurement types
*
* @param integer $value Value
* @param string $type (Optional) A Zend_Measure_Number Type
* @param string|Zend_Locale $locale (Optional) A Zend_Locale
* @throws Zend_Measure_Exception When language is unknown
* @throws Zend_Measure_Exception When type is unknown
*/
public function __construct($value, $type, $locale = null)
{
if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
$locale = $type;
$type = null;
}
if ($locale === null) {
$locale = new Zend_Locale();
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, true, false)) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
}
$locale = new Zend_Locale($locale);
}
$this->_locale = (string) $locale;
if ($type === null) {
$type = $this->_units['STANDARD'];
}
if (isset($this->_units[$type]) === false) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ($type) is unknown");
}
$this->setValue($value, $type, $this->_locale);
}
/**
* Set a new value
*
* @param integer $value Value
* @param string $type (Optional) A Zend_Measure_Number Type
* @param string|Zend_Locale $locale (Optional) A Zend_Locale Type
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type = null, $locale = null)
{
if (empty($locale)) {
$locale = $this->_locale;
}
if (empty($this->_units[$type])) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception('unknown type of number:' . $type);
}
switch($type) {
case 'BINARY':
preg_match('/[01]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'TERNARY':
preg_match('/[012]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'QUATERNARY':
preg_match('/[0123]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'QUINARY':
preg_match('/[01234]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'SENARY':
preg_match('/[012345]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'SEPTENARY':
preg_match('/[0123456]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'OCTAL':
preg_match('/[01234567]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'NONARY':
preg_match('/[012345678]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'DUODECIMAL':
preg_match('/[0123456789AB]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
case 'HEXADECIMAL':
preg_match('/[0123456789ABCDEF]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
case 'ROMAN':
preg_match('/[IVXLCDM_]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
default:
try {
$value = Zend_Locale_Format::getInteger($value, array('locale' => $locale));
} catch (Exception $e) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception($e->getMessage());
}
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$value = call_user_func(Zend_Locale_Math::$sqrt, call_user_func(Zend_Locale_Math::$pow, $value, 2));
}
break;
}
$this->_value = $value;
$this->_type = $type;
}
/**
* Convert input to decimal value string
*
* @param integer $input Input string
* @param string $type Type from which to convert to decimal
* @return string
*/
private function _toDecimal($input, $type)
{
$value = '';
// Convert base xx values
if ($this->_units[$type][0] <= 16) {
$split = str_split($input);
$length = strlen($input);
for ($x = 0; $x < $length; ++$x) {
$split[$x] = hexdec($split[$x]);
$value = call_user_func(Zend_Locale_Math::$add, $value,
call_user_func(Zend_Locale_Math::$mul, $split[$x],
call_user_func(Zend_Locale_Math::$pow, $this->_units[$type][0], ($length - $x - 1))));
}
}
// Convert roman numbers
if ($type === 'ROMAN') {
$input = strtoupper($input);
$input = preg_replace(array_keys(self::$_romanconvert), array_values(self::$_romanconvert), $input);
$split = preg_split('//', strrev($input), -1, PREG_SPLIT_NO_EMPTY);
for ($x =0; $x < sizeof($split); $x++) {
if ($split[$x] == '/') {
continue;
}
$num = self::$_roman[$split[$x]];
if (($x > 0 and ($split[$x-1] != '/') and ($num < self::$_roman[$split[$x-1]]))) {
$num -= $num;
}
$value += $num;
}
str_replace('/', '', $value);
}
return $value;
}
/**
* Convert input to type value string
*
* @param integer $value Input string
* @param string $type Type to convert to
* @return string
* @throws Zend_Measure_Exception When more than 200 digits are calculated
*/
private function _fromDecimal($value, $type)
{
$tempvalue = $value;
if ($this->_units[$type][0] <= 16) {
$newvalue = '';
$count = 200;
$base = $this->_units[$type][0];
while (call_user_func(Zend_Locale_Math::$comp, $value, 0, 25) <> 0) {
$target = call_user_func(Zend_Locale_Math::$mod, $value, $base);
$newvalue = strtoupper(dechex($target)) . $newvalue;
$value = call_user_func(Zend_Locale_Math::$sub, $value, $target, 0);
$value = call_user_func(Zend_Locale_Math::$div, $value, $base, 0);
--$count;
if ($count === 0) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Your value '$tempvalue' cannot be processed because it extends 200 digits");
}
}
if ($newvalue === '') {
$newvalue = '0';
}
}
if ($type === 'ROMAN') {
$i = 0;
$newvalue = '';
$romanval = array_values(array_reverse(self::$_roman));
$romankey = array_keys(array_reverse(self::$_roman));
$count = 200;
while (call_user_func(Zend_Locale_Math::$comp, $value, 0, 25) <> 0) {
while ($value >= $romanval[$i]) {
$value -= $romanval[$i];
$newvalue .= $romankey[$i];
if ($value < 1) {
break;
}
--$count;
if ($count === 0) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Your value '$tempvalue' cannot be processed because it extends 200 digits");
}
}
$i++;
}
$newvalue = str_replace('/', '', preg_replace(array_values(self::$_romanconvert), array_keys(self::$_romanconvert), $newvalue));
}
return $newvalue;
}
/**
* Set a new type, and convert the value
*
* @param string $type New type to set
* @throws Zend_Measure_Exception When a unknown type is given
* @return void
*/
public function setType($type)
{
if (empty($this->_units[$type]) === true) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception('Unknown type of number:' . $type);
}
$value = $this->_toDecimal($this->getValue(-1), $this->getType(-1));
$value = $this->_fromDecimal($value, $type);
$this->_value = $value;
$this->_type = $type;
}
/**
* Alias function for setType returning the converted unit
* Default is 0 as this class only handles numbers without precision
*
* @param string $type Type to convert to
* @param integer $round (Optional) Precision to add, will always be 0
* @return string
*/
public function convertTo($type, $round = 0)
{
$this->setType($type);
return $this->toString($round);
}
}
Measure/Energy.php 0000604 00000034244 15071256135 0010117 0 ustar 00 <?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_Measure
* @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: Energy.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling energy conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Energy
* @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_Measure_Energy extends Zend_Measure_Abstract
{
const STANDARD = 'JOULE';
const ATTOJOULE = 'ATTOJOULE';
const BOARD_OF_TRADE_UNIT = 'BOARD_OF_TRADE_UNIT';
const BTU = 'BTU';
const BTU_THERMOCHEMICAL = 'BTU_TERMOCHEMICAL';
const CALORIE = 'CALORIE';
const CALORIE_15C = 'CALORIE_15C';
const CALORIE_NUTRITIONAL = 'CALORIE_NUTRITIONAL';
const CALORIE_THERMOCHEMICAL = 'CALORIE_THERMOCHEMICAL';
const CELSIUS_HEAT_UNIT = 'CELSIUS_HEAT_UNIT';
const CENTIJOULE = 'CENTIJOULE';
const CHEVAL_VAPEUR_HEURE = 'CHEVAL_VAPEUR_HEURE';
const DECIJOULE = 'DECIJOULE';
const DEKAJOULE = 'DEKAJOULE';
const DEKAWATT_HOUR = 'DEKAWATT_HOUR';
const DEKATHERM = 'DEKATHERM';
const ELECTRONVOLT = 'ELECTRONVOLT';
const ERG = 'ERG';
const EXAJOULE = 'EXAJOULE';
const EXAWATT_HOUR = 'EXAWATT_HOUR';
const FEMTOJOULE = 'FEMTOJOULE';
const FOOT_POUND = 'FOOT_POUND';
const FOOT_POUNDAL = 'FOOT_POUNDAL';
const GALLON_UK_AUTOMOTIVE = 'GALLON_UK_AUTOMOTIVE';
const GALLON_US_AUTOMOTIVE = 'GALLON_US_AUTOMOTIVE';
const GALLON_UK_AVIATION = 'GALLON_UK_AVIATION';
const GALLON_US_AVIATION = 'GALLON_US_AVIATION';
const GALLON_UK_DIESEL = 'GALLON_UK_DIESEL';
const GALLON_US_DIESEL = 'GALLON_US_DIESEL';
const GALLON_UK_DISTILATE = 'GALLON_UK_DISTILATE';
const GALLON_US_DISTILATE = 'GALLON_US_DISTILATE';
const GALLON_UK_KEROSINE_JET = 'GALLON_UK_KEROSINE_JET';
const GALLON_US_KEROSINE_JET = 'GALLON_US_KEROSINE_JET';
const GALLON_UK_LPG = 'GALLON_UK_LPG';
const GALLON_US_LPG = 'GALLON_US_LPG';
const GALLON_UK_NAPHTA = 'GALLON_UK_NAPHTA';
const GALLON_US_NAPHTA = 'GALLON_US_NAPHTA';
const GALLON_UK_KEROSENE = 'GALLON_UK_KEROSINE';
const GALLON_US_KEROSENE = 'GALLON_US_KEROSINE';
const GALLON_UK_RESIDUAL = 'GALLON_UK_RESIDUAL';
const GALLON_US_RESIDUAL = 'GALLON_US_RESIDUAL';
const GIGAELECTRONVOLT = 'GIGAELECTRONVOLT';
const GIGACALORIE = 'GIGACALORIE';
const GIGACALORIE_15C = 'GIGACALORIE_15C';
const GIGAJOULE = 'GIGAJOULE';
const GIGAWATT_HOUR = 'GIGAWATT_HOUR';
const GRAM_CALORIE = 'GRAM_CALORIE';
const HARTREE = 'HARTREE';
const HECTOJOULE = 'HECTOJOULE';
const HECTOWATT_HOUR = 'HECTOWATT_HOUR';
const HORSEPOWER_HOUR = 'HORSEPOWER_HOUR';
const HUNDRED_CUBIC_FOOT_GAS = 'HUNDRED_CUBIC_FOOT_GAS';
const INCH_OUNCE = 'INCH_OUNCE';
const INCH_POUND = 'INCH_POUND';
const JOULE = 'JOULE';
const KILOCALORIE_15C = 'KILOCALORIE_15C';
const KILOCALORIE = 'KILOCALORIE';
const KILOCALORIE_THERMOCHEMICAL = 'KILOCALORIE_THERMOCHEMICAL';
const KILOELECTRONVOLT = 'KILOELECTRONVOLT';
const KILOGRAM_CALORIE = 'KILOGRAM_CALORIE';
const KILOGRAM_FORCE_METER = 'KILOGRAM_FORCE_METER';
const KILOJOULE = 'KILOJOULE';
const KILOPOND_METER = 'KILOPOND_METER';
const KILOTON = 'KILOTON';
const KILOWATT_HOUR = 'KILOWATT_HOUR';
const LITER_ATMOSPHERE = 'LITER_ATMOSPHERE';
const MEGAELECTRONVOLT = 'MEGAELECTRONVOLT';
const MEGACALORIE = 'MEGACALORIE';
const MEGACALORIE_15C = 'MEGACALORIE_15C';
const MEGAJOULE = 'MEGAJOULE';
const MEGALERG = 'MEGALERG';
const MEGATON = 'MEGATON';
const MEGAWATTHOUR = 'MEGAWATTHOUR';
const METER_KILOGRAM_FORCE = 'METER_KILOGRAM_FORCE';
const MICROJOULE = 'MICROJOULE';
const MILLIJOULE = 'MILLIJOULE';
const MYRIAWATT_HOUR = 'MYRIAWATT_HOUR';
const NANOJOULE = 'NANOJOULE';
const NEWTON_METER = 'NEWTON_METER';
const PETAJOULE = 'PETAJOULE';
const PETAWATTHOUR = 'PETAWATTHOUR';
const PFERDESTAERKENSTUNDE = 'PFERDESTAERKENSTUNDE';
const PICOJOULE = 'PICOJOULE';
const Q_UNIT = 'Q_UNIT';
const QUAD = 'QUAD';
const TERAELECTRONVOLT = 'TERAELECTRONVOLT';
const TERAJOULE = 'TERAJOULE';
const TERAWATTHOUR = 'TERAWATTHOUR';
const THERM = 'THERM';
const THERM_US = 'THERM_US';
const THERMIE = 'THERMIE';
const TON = 'TON';
const TONNE_COAL = 'TONNE_COAL';
const TONNE_OIL = 'TONNE_OIL';
const WATTHOUR = 'WATTHOUR';
const WATTSECOND = 'WATTSECOND';
const YOCTOJOULE = 'YOCTOJOULE';
const YOTTAJOULE = 'YOTTAJOULE';
const YOTTAWATTHOUR = 'YOTTAWATTHOUR';
const ZEPTOJOULE = 'ZEPTOJOULE';
const ZETTAJOULE = 'ZETTAJOULE';
const ZETTAWATTHOUR = 'ZETTAWATTHOUR';
/**
* Calculations for all energy units
*
* @var array
*/
protected $_units = array(
'ATTOJOULE' => array('1.0e-18', 'aJ'),
'BOARD_OF_TRADE_UNIT' => array('3600000', 'BOTU'),
'BTU' => array('1055.0559', 'Btu'),
'BTU_TERMOCHEMICAL' => array('1054.3503', 'Btu'),
'CALORIE' => array('4.1868', 'cal'),
'CALORIE_15C' => array('6.1858', 'cal'),
'CALORIE_NUTRITIONAL' => array('4186.8', 'cal'),
'CALORIE_THERMOCHEMICAL' => array('4.184', 'cal'),
'CELSIUS_HEAT_UNIT' => array('1899.1005', 'Chu'),
'CENTIJOULE' => array('0.01', 'cJ'),
'CHEVAL_VAPEUR_HEURE' => array('2647795.5', 'cv heure'),
'DECIJOULE' => array('0.1', 'dJ'),
'DEKAJOULE' => array('10', 'daJ'),
'DEKAWATT_HOUR' => array('36000', 'daWh'),
'DEKATHERM' => array('1.055057e+9', 'dathm'),
'ELECTRONVOLT' => array('1.6021773e-19', 'eV'),
'ERG' => array('0.0000001', 'erg'),
'EXAJOULE' => array('1.0e+18', 'EJ'),
'EXAWATT_HOUR' => array('3.6e+21', 'EWh'),
'FEMTOJOULE' => array('1.0e-15', 'fJ'),
'FOOT_POUND' => array('1.3558179', 'ft lb'),
'FOOT_POUNDAL' => array('0.04214011', 'ft poundal'),
'GALLON_UK_AUTOMOTIVE' => array('158237172', 'gal car gasoline'),
'GALLON_US_AUTOMOTIVE' => array('131760000', 'gal car gasoline'),
'GALLON_UK_AVIATION' => array('158237172', 'gal jet gasoline'),
'GALLON_US_AVIATION' => array('131760000', 'gal jet gasoline'),
'GALLON_UK_DIESEL' => array('175963194', 'gal diesel'),
'GALLON_US_DIESEL' => array('146520000', 'gal diesel'),
'GALLON_UK_DISTILATE' => array('175963194', 'gal destilate fuel'),
'GALLON_US_DISTILATE' => array('146520000', 'gal destilate fuel'),
'GALLON_UK_KEROSINE_JET' => array('170775090', 'gal jet kerosine'),
'GALLON_US_KEROSINE_JET' => array('142200000', 'gal jet kerosine'),
'GALLON_UK_LPG' => array('121005126.0865275', 'gal lpg'),
'GALLON_US_LPG' => array('100757838.45', 'gal lpg'),
'GALLON_UK_NAPHTA' => array('160831224', 'gal jet fuel'),
'GALLON_US_NAPHTA' => array('133920000', 'gal jet fuel'),
'GALLON_UK_KEROSINE' => array('170775090', 'gal kerosine'),
'GALLON_US_KEROSINE' => array('142200000', 'gal kerosine'),
'GALLON_UK_RESIDUAL' => array('189798138', 'gal residual fuel'),
'GALLON_US_RESIDUAL' => array('158040000', 'gal residual fuel'),
'GIGAELECTRONVOLT' => array('1.6021773e-10', 'GeV'),
'GIGACALORIE' => array('4186800000', 'Gcal'),
'GIGACALORIE_15C' => array('4185800000', 'Gcal'),
'GIGAJOULE' => array('1.0e+9', 'GJ'),
'GIGAWATT_HOUR' => array('3.6e+12', 'GWh'),
'GRAM_CALORIE' => array('4.1858', 'g cal'),
'HARTREE' => array('4.3597482e-18', 'Eh'),
'HECTOJOULE' => array('100', 'hJ'),
'HECTOWATT_HOUR' => array('360000', 'hWh'),
'HORSEPOWER_HOUR' => array('2684519.5', 'hph'),
'HUNDRED_CUBIC_FOOT_GAS' => array('108720000', 'hundred ft� gas'),
'INCH_OUNCE' => array('0.0070615518', 'in oc'),
'INCH_POUND' => array('0.112984825', 'in lb'),
'JOULE' => array('1', 'J'),
'KILOCALORIE_15C' => array('4185.8', 'kcal'),
'KILOCALORIE' => array('4186','8', 'kcal'),
'KILOCALORIE_THERMOCHEMICAL' => array('4184', 'kcal'),
'KILOELECTRONVOLT' => array('1.6021773e-16', 'keV'),
'KILOGRAM_CALORIE' => array('4185.8', 'kg cal'),
'KILOGRAM_FORCE_METER' => array('9.80665', 'kgf m'),
'KILOJOULE' => array('1000', 'kJ'),
'KILOPOND_METER' => array('9.80665', 'kp m'),
'KILOTON' => array('4.184e+12', 'kt'),
'KILOWATT_HOUR' => array('3600000', 'kWh'),
'LITER_ATMOSPHERE' => array('101.325', 'l atm'),
'MEGAELECTRONVOLT' => array('1.6021773e-13', 'MeV'),
'MEGACALORIE' => array('4186800', 'Mcal'),
'MEGACALORIE_15C' => array('4185800', 'Mcal'),
'MEGAJOULE' => array('1000000', 'MJ'),
'MEGALERG' => array('0.1', 'megalerg'),
'MEGATON' => array('4.184e+15', 'Mt'),
'MEGAWATTHOUR' => array('3.6e+9', 'MWh'),
'METER_KILOGRAM_FORCE' => array('9.80665', 'm kgf'),
'MICROJOULE' => array('0.000001', '�J'),
'MILLIJOULE' => array('0.001', 'mJ'),
'MYRIAWATT_HOUR' => array('3.6e+7', 'myWh'),
'NANOJOULE' => array('1.0e-9', 'nJ'),
'NEWTON_METER' => array('1', 'Nm'),
'PETAJOULE' => array('1.0e+15', 'PJ'),
'PETAWATTHOUR' => array('3.6e+18', 'PWh'),
'PFERDESTAERKENSTUNDE' => array('2647795.5', 'ps h'),
'PICOJOULE' => array('1.0e-12', 'pJ'),
'Q_UNIT' => array('1.0550559e+21', 'Q unit'),
'QUAD' => array('1.0550559e+18', 'quad'),
'TERAELECTRONVOLT' => array('1.6021773e-7', 'TeV'),
'TERAJOULE' => array('1.0e+12', 'TJ'),
'TERAWATTHOUR' => array('3.6e+15', 'TWh'),
'THERM' => array('1.0550559e+8', 'thm'),
'THERM_US' => array('1.054804e+8', 'thm'),
'THERMIE' => array('4185800', 'th'),
'TON' => array('4.184e+9', 'T explosive'),
'TONNE_COAL' => array('2.93076e+10', 'T coal'),
'TONNE_OIL' => array('4.1868e+10', 'T oil'),
'WATTHOUR' => array('3600', 'Wh'),
'WATTSECOND' => array('1', 'Ws'),
'YOCTOJOULE' => array('1.0e-24', 'yJ'),
'YOTTAJOULE' => array('1.0e+24', 'YJ'),
'YOTTAWATTHOUR' => array('3.6e+27', 'YWh'),
'ZEPTOJOULE' => array('1.0e-21', 'zJ'),
'ZETTAJOULE' => array('1.0e+21', 'ZJ'),
'ZETTAWATTHOUR' => array('3.6e+24', 'ZWh'),
'STANDARD' => 'JOULE'
);
}
Measure/Binary.php 0000604 00000013026 15071256135 0010105 0 ustar 00 <?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_Measure
* @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: Binary.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling binary conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Binary
* @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_Measure_Binary extends Zend_Measure_Abstract
{
const STANDARD = 'BYTE';
const BIT = 'BIT';
const CRUMB = 'CRUMB';
const NIBBLE = 'NIBBLE';
const BYTE = 'BYTE';
const KILOBYTE = 'KILOBYTE';
const KIBIBYTE = 'KIBIBYTE';
const KILO_BINARY_BYTE = 'KILO_BINARY_BYTE';
const KILOBYTE_SI = 'KILOBYTE_SI';
const MEGABYTE = 'MEGABYTE';
const MEBIBYTE = 'MEBIBYTE';
const MEGA_BINARY_BYTE = 'MEGA_BINARY_BYTE';
const MEGABYTE_SI = 'MEGABYTE_SI';
const GIGABYTE = 'GIGABYTE';
const GIBIBYTE = 'GIBIBYTE';
const GIGA_BINARY_BYTE = 'GIGA_BINARY_BYTE';
const GIGABYTE_SI = 'GIGABYTE_SI';
const TERABYTE = 'TERABYTE';
const TEBIBYTE = 'TEBIBYTE';
const TERA_BINARY_BYTE = 'TERA_BINARY_BYTE';
const TERABYTE_SI = 'TERABYTE_SI';
const PETABYTE = 'PETABYTE';
const PEBIBYTE = 'PEBIBYTE';
const PETA_BINARY_BYTE = 'PETA_BINARY_BYTE';
const PETABYTE_SI = 'PETABYTE_SI';
const EXABYTE = 'EXABYTE';
const EXBIBYTE = 'EXBIBYTE';
const EXA_BINARY_BYTE = 'EXA_BINARY_BYTE';
const EXABYTE_SI = 'EXABYTE_SI';
const ZETTABYTE = 'ZETTABYTE';
const ZEBIBYTE = 'ZEBIBYTE';
const ZETTA_BINARY_BYTE = 'ZETTA_BINARY_BYTE';
const ZETTABYTE_SI = 'ZETTABYTE_SI';
const YOTTABYTE = 'YOTTABYTE';
const YOBIBYTE = 'YOBIBYTE';
const YOTTA_BINARY_BYTE = 'YOTTA_BINARY_BYTE';
const YOTTABYTE_SI = 'YOTTABYTE_SI';
/**
* Calculations for all binary units
*
* @var array
*/
protected $_units = array(
'BIT' => array('0.125', 'b'),
'CRUMB' => array('0.25', 'crumb'),
'NIBBLE' => array('0.5', 'nibble'),
'BYTE' => array('1', 'B'),
'KILOBYTE' => array('1024', 'kB'),
'KIBIBYTE' => array('1024', 'KiB'),
'KILO_BINARY_BYTE' => array('1024', 'KiB'),
'KILOBYTE_SI' => array('1000', 'kB.'),
'MEGABYTE' => array('1048576', 'MB'),
'MEBIBYTE' => array('1048576', 'MiB'),
'MEGA_BINARY_BYTE' => array('1048576', 'MiB'),
'MEGABYTE_SI' => array('1000000', 'MB.'),
'GIGABYTE' => array('1073741824', 'GB'),
'GIBIBYTE' => array('1073741824', 'GiB'),
'GIGA_BINARY_BYTE' => array('1073741824', 'GiB'),
'GIGABYTE_SI' => array('1000000000', 'GB.'),
'TERABYTE' => array('1099511627776', 'TB'),
'TEBIBYTE' => array('1099511627776', 'TiB'),
'TERA_BINARY_BYTE' => array('1099511627776', 'TiB'),
'TERABYTE_SI' => array('1000000000000', 'TB.'),
'PETABYTE' => array('1125899906842624', 'PB'),
'PEBIBYTE' => array('1125899906842624', 'PiB'),
'PETA_BINARY_BYTE' => array('1125899906842624', 'PiB'),
'PETABYTE_SI' => array('1000000000000000', 'PB.'),
'EXABYTE' => array('1152921504606846976', 'EB'),
'EXBIBYTE' => array('1152921504606846976', 'EiB'),
'EXA_BINARY_BYTE' => array('1152921504606846976', 'EiB'),
'EXABYTE_SI' => array('1000000000000000000', 'EB.'),
'ZETTABYTE' => array('1180591620717411303424', 'ZB'),
'ZEBIBYTE' => array('1180591620717411303424', 'ZiB'),
'ZETTA_BINARY_BYTE'=> array('1180591620717411303424', 'ZiB'),
'ZETTABYTE_SI' => array('1000000000000000000000', 'ZB.'),
'YOTTABYTE' => array('1208925819614629174706176', 'YB'),
'YOBIBYTE' => array('1208925819614629174706176', 'YiB'),
'YOTTA_BINARY_BYTE'=> array('1208925819614629174706176', 'YiB'),
'YOTTABYTE_SI' => array('1000000000000000000000000', 'YB.'),
'STANDARD' => 'BYTE'
);
}
Measure/Force.php 0000604 00000012145 15071256135 0007720 0 ustar 00 <?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_Measure
* @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: Force.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling force conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Force
* @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_Measure_Force extends Zend_Measure_Abstract
{
const STANDARD = 'NEWTON';
const ATTONEWTON = 'ATTONEWTON';
const CENTINEWTON = 'CENTINEWTON';
const DECIGRAM_FORCE = 'DECIGRAM_FORCE';
const DECINEWTON = 'DECINEWTON';
const DEKAGRAM_FORCE = 'DEKAGRAM_FORCE';
const DEKANEWTON = 'DEKANEWTON';
const DYNE = 'DYNE';
const EXANEWTON = 'EXANEWTON';
const FEMTONEWTON = 'FEMTONEWTON';
const GIGANEWTON = 'GIGANEWTON';
const GRAM_FORCE = 'GRAM_FORCE';
const HECTONEWTON = 'HECTONEWTON';
const JOULE_PER_METER = 'JOULE_PER_METER';
const KILOGRAM_FORCE = 'KILOGRAM_FORCE';
const KILONEWTON = 'KILONEWTON';
const KILOPOND = 'KILOPOND';
const KIP = 'KIP';
const MEGANEWTON = 'MEGANEWTON';
const MEGAPOND = 'MEGAPOND';
const MICRONEWTON = 'MICRONEWTON';
const MILLINEWTON = 'MILLINEWTON';
const NANONEWTON = 'NANONEWTON';
const NEWTON = 'NEWTON';
const OUNCE_FORCE = 'OUNCE_FORCE';
const PETANEWTON = 'PETANEWTON';
const PICONEWTON = 'PICONEWTON';
const POND = 'POND';
const POUND_FORCE = 'POUND_FORCE';
const POUNDAL = 'POUNDAL';
const STHENE = 'STHENE';
const TERANEWTON = 'TERANEWTON';
const TON_FORCE_LONG = 'TON_FORCE_LONG';
const TON_FORCE = 'TON_FORCE';
const TON_FORCE_SHORT = 'TON_FORCE_SHORT';
const YOCTONEWTON = 'YOCTONEWTON';
const YOTTANEWTON = 'YOTTANEWTON';
const ZEPTONEWTON = 'ZEPTONEWTON';
const ZETTANEWTON = 'ZETTANEWTON';
/**
* Calculations for all force units
*
* @var array
*/
protected $_units = array(
'ATTONEWTON' => array('1.0e-18', 'aN'),
'CENTINEWTON' => array('0.01', 'cN'),
'DECIGRAM_FORCE' => array('0.000980665', 'dgf'),
'DECINEWTON' => array('0.1', 'dN'),
'DEKAGRAM_FORCE' => array('0.0980665', 'dagf'),
'DEKANEWTON' => array('10', 'daN'),
'DYNE' => array('0.00001', 'dyn'),
'EXANEWTON' => array('1.0e+18', 'EN'),
'FEMTONEWTON' => array('1.0e-15', 'fN'),
'GIGANEWTON' => array('1.0e+9', 'GN'),
'GRAM_FORCE' => array('0.00980665', 'gf'),
'HECTONEWTON' => array('100', 'hN'),
'JOULE_PER_METER' => array('1', 'J/m'),
'KILOGRAM_FORCE' => array('9.80665', 'kgf'),
'KILONEWTON' => array('1000', 'kN'),
'KILOPOND' => array('9.80665', 'kp'),
'KIP' => array('4448.2216', 'kip'),
'MEGANEWTON' => array('1000000', 'Mp'),
'MEGAPOND' => array('9806.65', 'MN'),
'MICRONEWTON' => array('0.000001', 'µN'),
'MILLINEWTON' => array('0.001', 'mN'),
'NANONEWTON' => array('0.000000001', 'nN'),
'NEWTON' => array('1', 'N'),
'OUNCE_FORCE' => array('0.27801385', 'ozf'),
'PETANEWTON' => array('1.0e+15', 'PN'),
'PICONEWTON' => array('1.0e-12', 'pN'),
'POND' => array('0.00980665', 'pond'),
'POUND_FORCE' => array('4.4482216', 'lbf'),
'POUNDAL' => array('0.13825495', 'pdl'),
'STHENE' => array('1000', 'sn'),
'TERANEWTON' => array('1.0e+12', 'TN'),
'TON_FORCE_LONG' => array('9964.016384', 'tnf'),
'TON_FORCE' => array('9806.65', 'tnf'),
'TON_FORCE_SHORT' => array('8896.4432', 'tnf'),
'YOCTONEWTON' => array('1.0e-24', 'yN'),
'YOTTANEWTON' => array('1.0e+24', 'YN'),
'ZEPTONEWTON' => array('1.0e-21', 'zN'),
'ZETTANEWTON' => array('1.0e+21', 'ZN'),
'STANDARD' => 'NEWTON'
);
}
Measure/Capacitance.php 0000604 00000010142 15071256135 0011050 0 ustar 00 <?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_Measure
* @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: Capacitance.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling capacitance conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Capacitance
* @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_Measure_Capacitance extends Zend_Measure_Abstract
{
const STANDARD = 'FARAD';
const ABFARAD = 'ABFARAD';
const AMPERE_PER_SECOND_VOLT = 'AMPERE_PER_SECOND_VOLT';
const CENTIFARAD = 'CENTIFARAD';
const COULOMB_PER_VOLT = 'COULOMB_PER_VOLT';
const DECIFARAD = 'DECIFARAD';
const DEKAFARAD = 'DEKAFARAD';
const ELECTROMAGNETIC_UNIT = 'ELECTROMAGNETIC_UNIT';
const ELECTROSTATIC_UNIT = 'ELECTROSTATIC_UNIT';
const FARAD = 'FARAD';
const FARAD_INTERNATIONAL = 'FARAD_INTERNATIONAL';
const GAUSSIAN = 'GAUSSIAN';
const GIGAFARAD = 'GIGAFARAD';
const HECTOFARAD = 'HECTOFARAD';
const JAR = 'JAR';
const KILOFARAD = 'KILOFARAD';
const MEGAFARAD = 'MEGAFARAD';
const MICROFARAD = 'MICROFARAD';
const MILLIFARAD = 'MILLIFARAD';
const NANOFARAD = 'NANOFARAD';
const PICOFARAD = 'PICOFARAD';
const PUFF = 'PUFF';
const SECOND_PER_OHM = 'SECOND_PER_OHM';
const STATFARAD = 'STATFARAD';
const TERAFARAD = 'TERAFARAD';
/**
* Calculations for all capacitance units
*
* @var array
*/
protected $_units = array(
'ABFARAD' => array('1.0e+9', 'abfarad'),
'AMPERE_PER_SECOND_VOLT' => array('1', 'A/sV'),
'CENTIFARAD' => array('0.01', 'cF'),
'COULOMB_PER_VOLT' => array('1', 'C/V'),
'DECIFARAD' => array('0.1', 'dF'),
'DEKAFARAD' => array('10', 'daF'),
'ELECTROMAGNETIC_UNIT' => array('1.0e+9', 'capacity emu'),
'ELECTROSTATIC_UNIT' => array('1.11265e-12', 'capacity esu'),
'FARAD' => array('1', 'F'),
'FARAD_INTERNATIONAL' => array('0.99951', 'F'),
'GAUSSIAN' => array('1.11265e-12', 'G'),
'GIGAFARAD' => array('1.0e+9', 'GF'),
'HECTOFARAD' => array('100', 'hF'),
'JAR' => array('1.11265e-9', 'jar'),
'KILOFARAD' => array('1000', 'kF'),
'MEGAFARAD' => array('1000000', 'MF'),
'MICROFARAD' => array('0.000001', 'µF'),
'MILLIFARAD' => array('0.001', 'mF'),
'NANOFARAD' => array('1.0e-9', 'nF'),
'PICOFARAD' => array('1.0e-12', 'pF'),
'PUFF' => array('1.0e-12', 'pF'),
'SECOND_PER_OHM' => array('1', 's/Ohm'),
'STATFARAD' => array('1.11265e-12', 'statfarad'),
'TERAFARAD' => array('1.0e+12', 'TF'),
'STANDARD' => 'FARAD'
);
}
Measure/Area.php 0000604 00000042110 15071256135 0007525 0 ustar 00 <?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_Measure
* @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: Area.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling area conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Area
* @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_Measure_Area extends Zend_Measure_Abstract
{
const STANDARD = 'SQUARE_METER';
const ACRE = 'ACRE';
const ACRE_COMMERCIAL = 'ACRE_COMMERCIAL';
const ACRE_SURVEY = 'ACRE_SURVEY';
const ACRE_IRELAND = 'ACRE_IRELAND';
const ARE = 'ARE';
const ARPENT = 'ARPENT';
const BARN = 'BARN';
const BOVATE = 'BOVATE';
const BUNDER = 'BUNDER';
const CABALLERIA = 'CABALLERIA';
const CABALLERIA_AMERICA = 'CABALLERIA_AMERICA';
const CABALLERIA_CUBA = 'CABALLERIA_CUBA';
const CARREAU = 'CARREAU';
const CARUCATE = 'CARUCATE';
const CAWNEY = 'CAWNEY';
const CENTIARE = 'CENTIARE';
const CONG = 'CONG';
const COVER = 'COVER';
const CUERDA = 'CUERDA';
const DEKARE = 'DEKARE';
const DESSIATINA = 'DESSIATINA';
const DHUR = 'DHUR';
const DUNUM = 'DUNUM';
const DUNHAM = 'DUNHAM';
const FALL_SCOTS = 'FALL_SCOTS';
const FALL = 'FALL';
const FANEGA = 'FANEGA';
const FARTHINGDALE = 'FARTHINGDALE';
const HACIENDA = 'HACIENDA';
const HECTARE = 'HECTARE';
const HIDE = 'HIDE';
const HOMESTEAD = 'HOMESTEAD';
const HUNDRED = 'HUNDRED';
const JERIB = 'JERIB';
const JITRO = 'JITRO';
const JOCH = 'JOCH';
const JUTRO = 'JUTRO';
const JO = 'JO';
const KAPPLAND = 'KAPPLAND';
const KATTHA = 'KATTHA';
const LABOR = 'LABOR';
const LEGUA = 'LEGUA';
const MANZANA_COSTA_RICA = 'MANZANA_COSTA_RICA';
const MANZANA = 'MANZANA';
const MORGEN = 'MORGEN';
const MORGEN_AFRICA = 'MORGEN_AFRICA';
const MU = 'MU';
const NGARN = 'NGARN';
const NOOK = 'NOOK';
const OXGANG = 'OXGANG';
const PERCH = 'PERCH';
const PERCHE = 'PERCHE';
const PING = 'PING';
const PYONG = 'PYONG';
const RAI = 'RAI';
const ROOD = 'ROOD';
const SECTION = 'SECTION';
const SHED = 'SHED';
const SITIO = 'SITIO';
const SQUARE = 'SQUARE';
const SQUARE_ANGSTROM = 'SQUARE_ANGSTROM';
const SQUARE_ASTRONOMICAL_UNIT = 'SQUARE_ASTRONOMICAL_UNIT';
const SQUARE_ATTOMETER = 'SQUARE_ATTOMETER';
const SQUARE_BICRON = 'SQUARE_BICRON';
const SQUARE_CENTIMETER = 'SQUARE_CENTIMETER';
const SQUARE_CHAIN = 'SQUARE_CHAIN';
const SQUARE_CHAIN_ENGINEER = 'SQUARE_CHAIN_ENGINEER';
const SQUARE_CITY_BLOCK_US_EAST = 'SQUARE_CITY_BLOCK_US_EAST';
const SQUARE_CITY_BLOCK_US_WEST = 'SQUARE_CITY_BLOCK_US_WEST';
const SQUARE_CITY_BLOCK_US_SOUTH = 'SQUARE_CITY_BLOCK_US_SOUTH';
const SQUARE_CUBIT = 'SQUARE_CUBIT';
const SQUARE_DECIMETER = 'SQUARE_DECIMETER';
const SQUARE_DEKAMETER = 'SQUARE_DEKAMETER';
const SQUARE_EXAMETER = 'SQUARE_EXAMETER';
const SQUARE_FATHOM = 'SQUARE_FATHOM';
const SQUARE_FEMTOMETER = 'SQUARE_FEMTOMETER';
const SQUARE_FERMI = 'SQUARE_FERMI';
const SQUARE_FOOT = 'SQUARE_FOOT';
const SQUARE_FOOT_SURVEY = 'SQUARE_FOOT_SURVEY';
const SQUARE_FURLONG = 'SQUARE_FURLONG';
const SQUARE_GIGAMETER = 'SQUARE_GIGAMETER';
const SQUARE_HECTOMETER = 'SQUARE_HECTOMETER';
const SQUARE_INCH = 'SQUARE_INCH';
const SQUARE_INCH_SURVEY = 'SQUARE_INCH_SURVEY';
const SQUARE_KILOMETER = 'SQUARE_KILOMETER';
const SQUARE_LEAGUE_NAUTIC = 'SQUARE_LEAGUE_NAUTIC';
const SQUARE_LEAGUE = 'SQUARE_LEAGUE';
const SQUARE_LIGHT_YEAR = 'SQUARE_LIGHT_YEAR';
const SQUARE_LINK = 'SQUARE_LINK';
const SQUARE_LINK_ENGINEER = 'SQUARE_LINK_ENGINEER';
const SQUARE_MEGAMETER = 'SQUARE_MEGAMETER';
const SQUARE_METER = 'SQUARE_METER';
const SQUARE_MICROINCH = 'SQUARE_MICROINCH';
const SQUARE_MICROMETER = 'SQUARE_MICROMETER';
const SQUARE_MICROMICRON = 'SQUARE_MICROMICRON';
const SQUARE_MICRON = 'SQUARE_MICRON';
const SQUARE_MIL = 'SQUARE_MIL';
const SQUARE_MILE = 'SQUARE_MILE';
const SQUARE_MILE_NAUTIC = 'SQUARE_MILE_NAUTIC';
const SQUARE_MILE_SURVEY = 'SQUARE_MILE_SURVEY';
const SQUARE_MILLIMETER = 'SQUARE_MILLIMETER';
const SQUARE_MILLIMICRON = 'SQUARE_MILLIMICRON';
const SQUARE_MYRIAMETER = 'SQUARE_MYRIAMETER';
const SQUARE_NANOMETER = 'SQUARE_NANOMETER';
const SQUARE_PARIS_FOOT = 'SQUARE_PARIS_FOOT';
const SQUARE_PARSEC = 'SQUARE_PARSEC';
const SQUARE_PERCH = 'SQUARE_PERCH';
const SQUARE_PERCHE = 'SQUARE_PERCHE';
const SQUARE_PETAMETER = 'SQUARE_PETAMETER';
const SQUARE_PICOMETER = 'SQUARE_PICOMETER';
const SQUARE_ROD = 'SQUARE_ROD';
const SQUARE_TENTHMETER = 'SQUARE_TENTHMETER';
const SQUARE_TERAMETER = 'SQUARE_TERAMETER';
const SQUARE_THOU = 'SQUARE_THOU';
const SQUARE_VARA = 'SQUARE_VARA';
const SQUARE_VARA_TEXAS = 'SQUARE_VARA_TEXAS';
const SQUARE_YARD = 'SQUARE_YARD';
const SQUARE_YARD_SURVEY = 'SQUARE_YARD_SURVEY';
const SQUARE_YOCTOMETER = 'SQUARE_YOCTOMETER';
const SQUARE_YOTTAMETER = 'SQUARE_YOTTAMETER';
const STANG = 'STANG';
const STREMMA = 'STREMMA';
const TAREA = 'TAREA';
const TATAMI = 'TATAMI';
const TONDE_LAND = 'TONDE_LAND';
const TOWNSHIP = 'TOWNSHIP';
const TSUBO = 'TSUBO';
const TUNNLAND = 'TUNNLAND';
const YARD = 'YARD';
const VIRGATE = 'VIRGATE';
/**
* Calculations for all area units
*
* @var array
*/
protected $_units = array(
'ACRE' => array('4046.856422', 'A'),
'ACRE_COMMERCIAL' => array('3344.50944', 'A'),
'ACRE_SURVEY' => array('4046.872627', 'A'),
'ACRE_IRELAND' => array('6555', 'A'),
'ARE' => array('100', 'a'),
'ARPENT' => array('3418.89', 'arpent'),
'BARN' => array('1e-28', 'b'),
'BOVATE' => array('60000', 'bovate'),
'BUNDER' => array('10000', 'bunder'),
'CABALLERIA' => array('400000', 'caballeria'),
'CABALLERIA_AMERICA' => array('450000', 'caballeria'),
'CABALLERIA_CUBA' => array('134200', 'caballeria'),
'CARREAU' => array('12900', 'carreau'),
'CARUCATE' => array('486000', 'carucate'),
'CAWNEY' => array('5400', 'cawney'),
'CENTIARE' => array('1', 'ca'),
'CONG' => array('1000', 'cong'),
'COVER' => array('2698', 'cover'),
'CUERDA' => array('3930', 'cda'),
'DEKARE' => array('1000', 'dekare'),
'DESSIATINA' => array('10925', 'dessiantina'),
'DHUR' => array('16.929', 'dhur'),
'DUNUM' => array('1000', 'dunum'),
'DUNHAM' => array('1000', 'dunham'),
'FALL_SCOTS' => array('32.15', 'fall'),
'FALL' => array('47.03', 'fall'),
'FANEGA' => array('6430', 'fanega'),
'FARTHINGDALE' => array('1012', 'farthingdale'),
'HACIENDA' => array('89600000', 'hacienda'),
'HECTARE' => array('10000', 'ha'),
'HIDE' => array('486000', 'hide'),
'HOMESTEAD' => array('647500', 'homestead'),
'HUNDRED' => array('50000000', 'hundred'),
'JERIB' => array('2000', 'jerib'),
'JITRO' => array('5755', 'jitro'),
'JOCH' => array('5755', 'joch'),
'JUTRO' => array('5755', 'jutro'),
'JO' => array('1.62', 'jo'),
'KAPPLAND' => array('154.26', 'kappland'),
'KATTHA' => array('338', 'kattha'),
'LABOR' => array('716850', 'labor'),
'LEGUA' => array('17920000', 'legua'),
'MANZANA_COSTA_RICA' => array('6988.96', 'manzana'),
'MANZANA' => array('10000', 'manzana'),
'MORGEN' => array('2500', 'morgen'),
'MORGEN_AFRICA' => array('8567', 'morgen'),
'MU' => array(array('' => '10000', '/' => '15'), 'mu'),
'NGARN' => array('400', 'ngarn'),
'NOOK' => array('80937.128', 'nook'),
'OXGANG' => array('60000', 'oxgang'),
'PERCH' => array('25.29285264', 'perch'),
'PERCHE' => array('34.19', 'perche'),
'PING' => array('3.305', 'ping'),
'PYONG' => array('3.306', 'pyong'),
'RAI' => array('1600', 'rai'),
'ROOD' => array('1011.7141', 'rood'),
'SECTION' => array('2589998.5', 'sec'),
'SHED' => array('10e-52', 'shed'),
'SITIO' => array('18000000', 'sitio'),
'SQUARE' => array('9.290304', 'sq'),
'SQUARE_ANGSTROM' => array('1.0e-20', 'A²'),
'SQUARE_ASTRONOMICAL_UNIT' => array('2.2379523e+22', 'AU²'),
'SQUARE_ATTOMETER' => array('1.0e-36', 'am²'),
'SQUARE_BICRON' => array('1.0e-24', 'µµ²'),
'SQUARE_CENTIMETER' => array('0.0001', 'cm²'),
'SQUARE_CHAIN' => array('404.68726', 'ch²'),
'SQUARE_CHAIN_ENGINEER' => array('929.03412', 'ch²'),
'SQUARE_CITY_BLOCK_US_EAST' => array('4.97027584', 'sq block'),
'SQUARE_CITY_BLOCK_US_WEST' => array('17.141056', 'sq block'),
'SQUARE_CITY_BLOCK_US_SOUTH' => array('99.88110336', 'sq block'),
'SQUARE_CUBIT' => array('0.20903184', 'sq cubit'),
'SQUARE_DECIMETER' => array('0.01', 'dm²'),
'SQUARE_DEKAMETER' => array('100', 'dam²'),
'SQUARE_EXAMETER' => array('1.0e+36', 'Em²'),
'SQUARE_FATHOM' => array('3.3445228', 'fth²'),
'SQUARE_FEMTOMETER' => array('1.0e-30', 'fm²'),
'SQUARE_FERMI' => array('1.0e-30', 'f²'),
'SQUARE_FOOT' => array('0.09290304', 'ft²'),
'SQUARE_FOOT_SURVEY' => array('0.092903412', 'ft²'),
'SQUARE_FURLONG' => array('40468.726', 'fur²'),
'SQUARE_GIGAMETER' => array('1.0e+18', 'Gm²'),
'SQUARE_HECTOMETER' => array('10000', 'hm²'),
'SQUARE_INCH' => array(array('' => '0.09290304','/' => '144'), 'in²'),
'SQUARE_INCH_SURVEY' => array(array('' => '0.092903412','/' => '144'), 'in²'),
'SQUARE_KILOMETER' => array('1000000', 'km²'),
'SQUARE_LEAGUE_NAUTIC' => array('3.0869136e+07', 'sq league'),
'SQUARE_LEAGUE' => array('2.3309986e+07', 'sq league'),
'SQUARE_LIGHT_YEAR' => array('8.9505412e+31', 'ly²'),
'SQUARE_LINK' => array('0.040468726', 'sq link'),
'SQUARE_LINK_ENGINEER' => array('0.092903412', 'sq link'),
'SQUARE_MEGAMETER' => array('1.0e+12', 'Mm²'),
'SQUARE_METER' => array('1', 'm²'),
'SQUARE_MICROINCH' => array(array('' => '1.0e-6','*' => '6.4516e-10'), 'µin²'),
'SQUARE_MICROMETER' => array('1.0e-12', 'µm²'),
'SQUARE_MICROMICRON' => array('1.0e-24', 'µµ²'),
'SQUARE_MICRON' => array('1.0e-12', 'µ²'),
'SQUARE_MIL' => array('6.4516e-10', 'sq mil'),
'SQUARE_MILE' => array(array('' => '0.09290304','*' => '27878400'), 'mi²'),
'SQUARE_MILE_NAUTIC' => array('3429904', 'mi²'),
'SQUARE_MILE_SURVEY' => array('2589998.5', 'mi²'),
'SQUARE_MILLIMETER' => array('0.000001', 'mm²'),
'SQUARE_MILLIMICRON' => array('1.0e-18', 'mµ²'),
'SQUARE_MYRIAMETER' => array('1.0e+8', 'mym²'),
'SQUARE_NANOMETER' => array('1.0e-18', 'nm²'),
'SQUARE_PARIS_FOOT' => array('0.1055', 'sq paris foot'),
'SQUARE_PARSEC' => array('9.5214087e+32', 'pc²'),
'SQUARE_PERCH' => array('25.292954', 'sq perch'),
'SQUARE_PERCHE' => array('51.072', 'sq perche'),
'SQUARE_PETAMETER' => array('1.0e+30', 'Pm²'),
'SQUARE_PICOMETER' => array('1.0e-24', 'pm²'),
'SQUARE_ROD' => array(array('' => '0.092903412','*' => '272.25'), 'rd²'),
'SQUARE_TENTHMETER' => array('1.0e-20', 'sq tenth-meter'),
'SQUARE_TERAMETER' => array('1.0e+24', 'Tm²'),
'SQUARE_THOU' => array('6.4516e-10', 'sq thou'),
'SQUARE_VARA' => array('0.70258205', 'sq vara'),
'SQUARE_VARA_TEXAS' => array('0.71684731', 'sq vara'),
'SQUARE_YARD' => array('0.83612736', 'yd²'),
'SQUARE_YARD_SURVEY' => array('0.836130708', 'yd²'),
'SQUARE_YOCTOMETER' => array('1.0e-48', 'ym²'),
'SQUARE_YOTTAMETER' => array('1.0e+48', 'Ym²'),
'STANG' => array('2709', 'stang'),
'STREMMA' => array('1000', 'stremma'),
'TAREA' => array('628.8', 'tarea'),
'TATAMI' => array('1.62', 'tatami'),
'TONDE_LAND' => array('5516', 'tonde land'),
'TOWNSHIP' => array('93239945.3196288', 'twp'),
'TSUBO' => array('3.3058', 'tsubo'),
'TUNNLAND' => array('4936.4', 'tunnland'),
'YARD' => array('0.83612736', 'yd'),
'VIRGATE' => array('120000', 'virgate'),
'STANDARD' => 'SQUARE_METER'
);
}
Measure/Speed.php 0000604 00000031645 15071256135 0007730 0 ustar 00 <?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_Measure
* @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: Speed.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling speed conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Speed
* @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_Measure_Speed extends Zend_Measure_Abstract
{
const STANDARD = 'METER_PER_SECOND';
const BENZ = 'BENZ';
const CENTIMETER_PER_DAY = 'CENTIMETER_PER_DAY';
const CENTIMETER_PER_HOUR = 'CENTIMETER_PER_HOUR';
const CENTIMETER_PER_MINUTE = 'CENTIMETER_PER_MINUTE';
const CENTIMETER_PER_SECOND = 'CENTIMETER_PER_SECOND';
const DEKAMETER_PER_DAY = 'DEKAMETER_PER_DAY';
const DEKAMETER_PER_HOUR = 'DEKAMETER_PER_HOUR';
const DEKAMETER_PER_MINUTE = 'DEKAMETER_PER_MINUTE';
const DEKAMETER_PER_SECOND = 'DEKAMETER_PER_SECOND';
const FOOT_PER_DAY = 'FOOT_PER_DAY';
const FOOT_PER_HOUR = 'FOOT_PER_HOUR';
const FOOT_PER_MINUTE = 'FOOT_PER_MINUTE';
const FOOT_PER_SECOND = 'FOOT_PER_SECOND';
const FURLONG_PER_DAY = 'FURLONG_PER_DAY';
const FURLONG_PER_FORTNIGHT = 'FURLONG_PER_FORTNIGHT';
const FURLONG_PER_HOUR = 'FURLONG_PER_HOUR';
const FURLONG_PER_MINUTE = 'FURLONG_PER_MINUTE';
const FURLONG_PER_SECOND = 'FURLONG_PER_SECOND';
const HECTOMETER_PER_DAY = 'HECTOMETER_PER_DAY';
const HECTOMETER_PER_HOUR = 'HECTOMETER_PER_HOUR';
const HECTOMETER_PER_MINUTE = 'HECTOMETER_PER_MINUTE';
const HECTOMETER_PER_SECOND = 'HECTOMETER_PER_SECOND';
const INCH_PER_DAY = 'INCH_PER_DAY';
const INCH_PER_HOUR = 'INCH_PER_HOUR';
const INCH_PER_MINUTE = 'INCH_PER_MINUTE';
const INCH_PER_SECOND = 'INCH_PER_SECOND';
const KILOMETER_PER_DAY = 'KILOMETER_PER_DAY';
const KILOMETER_PER_HOUR = 'KILOMETER_PER_HOUR';
const KILOMETER_PER_MINUTE = 'KILOMETER_PER_MINUTE';
const KILOMETER_PER_SECOND = 'KILOMETER_PER_SECOND';
const KNOT = 'KNOT';
const LEAGUE_PER_DAY = 'LEAGUE_PER_DAY';
const LEAGUE_PER_HOUR = 'LEAGUE_PER_HOUR';
const LEAGUE_PER_MINUTE = 'LEAGUE_PER_MINUTE';
const LEAGUE_PER_SECOND = 'LEAGUE_PER_SECOND';
const MACH = 'MACH';
const MEGAMETER_PER_DAY = 'MEGAMETER_PER_DAY';
const MEGAMETER_PER_HOUR = 'MEGAMETER_PER_HOUR';
const MEGAMETER_PER_MINUTE = 'MEGAMETER_PER_MINUTE';
const MEGAMETER_PER_SECOND = 'MEGAMETER_PER_SECOND';
const METER_PER_DAY = 'METER_PER_DAY';
const METER_PER_HOUR = 'METER_PER_HOUR';
const METER_PER_MINUTE = 'METER_PER_MINUTE';
const METER_PER_SECOND = 'METER_PER_SECOND';
const MILE_PER_DAY = 'MILE_PER_DAY';
const MILE_PER_HOUR = 'MILE_PER_HOUR';
const MILE_PER_MINUTE = 'MILE_PER_MINUTE';
const MILE_PER_SECOND = 'MILE_PER_SECOND';
const MILLIMETER_PER_DAY = 'MILLIMETER_PER_DAY';
const MILLIMETER_PER_HOUR = 'MILLIMETER_PER_HOUR';
const MILLIMETER_PER_MINUTE = 'MILLIMETER_PER_MINUTE';
const MILLIMETER_PER_SECOND = 'MILLIMETER_PER_SECOND';
const MILLIMETER_PER_MICROSECOND = 'MILLIMETER_PER_MICROSECOND';
const MILLIMETER_PER_100_MICROSECOND = 'MILLIMETER_PER_100_MICROSECOND';
const NAUTIC_MILE_PER_DAY = 'NAUTIC_MILE_PER_DAY';
const NAUTIC_MILE_PER_HOUR = 'NAUTIC_MILE_PER_HOUR';
const NAUTIC_MILE_PER_MINUTE = 'NAUTIC_MILE_PER_MINUTE';
const NAUTIC_MILE_PER_SECOND = 'NAUTIC_MILE_PER_SECOND';
const LIGHTSPEED_AIR = 'LIGHTSPEED_AIR';
const LIGHTSPEED_GLASS = 'LIGHTSPEED_GLASS';
const LIGHTSPEED_ICE = 'LIGHTSPEED_ICE';
const LIGHTSPEED_VACUUM = 'LIGHTSPEED_VACUUM';
const LIGHTSPEED_WATER = 'LIGHTSPEED_WATER';
const SOUNDSPEED_AIR = 'SOUNDSPEED_AIT';
const SOUNDSPEED_METAL = 'SOUNDSPEED_METAL';
const SOUNDSPEED_WATER = 'SOUNDSPEED_WATER';
const YARD_PER_DAY = 'YARD_PER_DAY';
const YARD_PER_HOUR = 'YARD_PER_HOUR';
const YARD_PER_MINUTE = 'YARD_PER_MINUTE';
const YARD_PER_SECOND = 'YARD_PER_SECOND';
/**
* Calculations for all speed units
*
* @var array
*/
protected $_units = array(
'BENZ' => array('1', 'Bz'),
'CENTIMETER_PER_DAY' => array(array('' => '0.01', '/' => '86400'), 'cm/day'),
'CENTIMETER_PER_HOUR' => array(array('' => '0.01', '/' => '3600'), 'cm/h'),
'CENTIMETER_PER_MINUTE' => array(array('' => '0.01', '/' => '60'), 'cm/m'),
'CENTIMETER_PER_SECOND' => array('0.01', 'cd/s'),
'DEKAMETER_PER_DAY' => array(array('' => '10', '/' => '86400'), 'dam/day'),
'DEKAMETER_PER_HOUR' => array(array('' => '10', '/' => '3600'), 'dam/h'),
'DEKAMETER_PER_MINUTE' => array(array('' => '10', '/' => '60'), 'dam/m'),
'DEKAMETER_PER_SECOND' => array('10', 'dam/s'),
'FOOT_PER_DAY' => array(array('' => '0.3048', '/' => '86400'), 'ft/day'),
'FOOT_PER_HOUR' => array(array('' => '0.3048', '/' => '3600'), 'ft/h'),
'FOOT_PER_MINUTE' => array(array('' => '0.3048', '/' => '60'), 'ft/m'),
'FOOT_PER_SECOND' => array('0.3048', 'ft/s'),
'FURLONG_PER_DAY' => array(array('' => '201.1684', '/' => '86400'), 'fur/day'),
'FURLONG_PER_FORTNIGHT' => array(array('' => '201.1684', '/' => '1209600'), 'fur/fortnight'),
'FURLONG_PER_HOUR' => array(array('' => '201.1684', '/' => '3600'), 'fur/h'),
'FURLONG_PER_MINUTE' => array(array('' => '201.1684', '/' => '60'), 'fur/m'),
'FURLONG_PER_SECOND' => array('201.1684', 'fur/s'),
'HECTOMETER_PER_DAY' => array(array('' => '100', '/' => '86400'), 'hm/day'),
'HECTOMETER_PER_HOUR' => array(array('' => '100', '/' => '3600'), 'hm/h'),
'HECTOMETER_PER_MINUTE' => array(array('' => '100', '/' => '60'), 'hm/m'),
'HECTOMETER_PER_SECOND' => array('100', 'hm/s'),
'INCH_PER_DAY' => array(array('' => '0.0254', '/' => '86400'), 'in/day'),
'INCH_PER_HOUR' => array(array('' => '0.0254', '/' => '3600'), 'in/h'),
'INCH_PER_MINUTE' => array(array('' => '0.0254', '/' => '60'), 'in/m'),
'INCH_PER_SECOND' => array('0.0254', 'in/s'),
'KILOMETER_PER_DAY' => array(array('' => '1000', '/' => '86400'), 'km/day'),
'KILOMETER_PER_HOUR' => array(array('' => '1000', '/' => '3600'), 'km/h'),
'KILOMETER_PER_MINUTE' => array(array('' => '1000', '/' => '60'), 'km/m'),
'KILOMETER_PER_SECOND' => array('1000', 'km/s'),
'KNOT' => array(array('' => '1852', '/' => '3600'), 'kn'),
'LEAGUE_PER_DAY' => array(array('' => '4828.0417', '/' => '86400'), 'league/day'),
'LEAGUE_PER_HOUR' => array(array('' => '4828.0417', '/' => '3600'), 'league/h'),
'LEAGUE_PER_MINUTE' => array(array('' => '4828.0417', '/' => '60'), 'league/m'),
'LEAGUE_PER_SECOND' => array('4828.0417', 'league/s'),
'MACH' => array('340.29', 'M'),
'MEGAMETER_PER_DAY' => array(array('' => '1000000', '/' => '86400'), 'Mm/day'),
'MEGAMETER_PER_HOUR' => array(array('' => '1000000', '/' => '3600'), 'Mm/h'),
'MEGAMETER_PER_MINUTE' => array(array('' => '1000000', '/' => '60'), 'Mm/m'),
'MEGAMETER_PER_SECOND' => array('1000000', 'Mm/s'),
'METER_PER_DAY' => array(array('' => '1', '/' => '86400'), 'm/day'),
'METER_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'm/h'),
'METER_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'm/m'),
'METER_PER_SECOND' => array('1', 'm/s'),
'MILE_PER_DAY' => array(array('' => '1609.344', '/' => '86400'), 'mi/day'),
'MILE_PER_HOUR' => array(array('' => '1609.344', '/' => '3600'), 'mi/h'),
'MILE_PER_MINUTE' => array(array('' => '1609.344', '/' => '60'), 'mi/m'),
'MILE_PER_SECOND' => array('1609.344', 'mi/s'),
'MILLIMETER_PER_DAY' => array(array('' => '0.001', '/' => '86400'), 'mm/day'),
'MILLIMETER_PER_HOUR' => array(array('' => '0.001', '/' => '3600'), 'mm/h'),
'MILLIMETER_PER_MINUTE' => array(array('' => '0.001', '/' => '60'), 'mm/m'),
'MILLIMETER_PER_SECOND' => array('0.001', 'mm/s'),
'MILLIMETER_PER_MICROSECOND' => array('1000', 'mm/µs'),
'MILLIMETER_PER_100_MICROSECOND' => array('10', 'mm/100µs'),
'NAUTIC_MILE_PER_DAY' => array(array('' => '1852', '/' => '86400'), 'nmi/day'),
'NAUTIC_MILE_PER_HOUR' => array(array('' => '1852', '/' => '3600'), 'nmi/h'),
'NAUTIC_MILE_PER_MINUTE' => array(array('' => '1852', '/' => '60'), 'nmi/m'),
'NAUTIC_MILE_PER_SECOND' => array('1852', 'nmi/s'),
'LIGHTSPEED_AIR' => array('299702547', 'speed of light (air)'),
'LIGHTSPEED_GLASS' => array('199861638', 'speed of light (glass)'),
'LIGHTSPEED_ICE' => array('228849204', 'speed of light (ice)'),
'LIGHTSPEED_VACUUM' => array('299792458', 'speed of light (vacuum)'),
'LIGHTSPEED_WATER' => array('225407863', 'speed of light (water)'),
'SOUNDSPEED_AIT' => array('340.29', 'speed of sound (air)'),
'SOUNDSPEED_METAL' => array('5000', 'speed of sound (metal)'),
'SOUNDSPEED_WATER' => array('1500', 'speed of sound (water)'),
'YARD_PER_DAY' => array(array('' => '0.9144', '/' => '86400'), 'yd/day'),
'YARD_PER_HOUR' => array(array('' => '0.9144', '/' => '3600'), 'yd/h'),
'YARD_PER_MINUTE' => array(array('' => '0.9144', '/' => '60'), 'yd/m'),
'YARD_PER_SECOND' => array('0.9144', 'yd/s'),
'STANDARD' => 'METER_PER_SECOND'
);
}
Measure/Power.php 0000604 00000027572 15071256135 0007770 0 ustar 00 <?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_Measure
* @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: Power.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling power conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Power
* @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_Measure_Power extends Zend_Measure_Abstract
{
const STANDARD = 'WATT';
const ATTOWATT = 'ATTOWATT';
const BTU_PER_HOUR = 'BTU_PER_HOUR';
const BTU_PER_MINUTE = 'BTU_PER_MINUTE';
const BTU_PER_SECOND = 'BTU_PER_SECOND';
const CALORIE_PER_HOUR = 'CALORIE_PER_HOUR';
const CALORIE_PER_MINUTE = 'CALORIE_PER_MINUTE';
const CALORIE_PER_SECOND = 'CALORIE_PER_SECOND';
const CENTIWATT = 'CENTIWATT';
const CHEVAL_VAPEUR = 'CHEVAL_VAPEUR';
const CLUSEC = 'CLUSEC';
const DECIWATT = 'DECIWATT';
const DEKAWATT = 'DEKAWATT';
const DYNE_CENTIMETER_PER_HOUR = 'DYNE_CENTIMETER_PER_HOUR';
const DYNE_CENTIMETER_PER_MINUTE = 'DYNE_CENTIMETER_PER_MINUTE';
const DYNE_CENTIMETER_PER_SECOND = 'DYNE_CENTIMETER_PER_SECOND';
const ERG_PER_HOUR = 'ERG_PER_HOUR';
const ERG_PER_MINUTE = 'ERG_PER_MINUTE';
const ERG_PER_SECOND = 'ERG_PER_SECOND';
const EXAWATT = 'EXAWATT';
const FEMTOWATT = 'FEMTOWATT';
const FOOT_POUND_FORCE_PER_HOUR = 'FOOT_POUND_FORCE_PER_HOUR';
const FOOT_POUND_FORCE_PER_MINUTE = 'FOOT_POUND_FORCE_PER_MINUTE';
const FOOT_POUND_FORCE_PER_SECOND = 'FOOT_POUND_FORCE_PER_SECOND';
const FOOT_POUNDAL_PER_HOUR = 'FOOT_POUNDAL_PER_HOUR';
const FOOT_POUNDAL_PER_MINUTE = 'FOOT_POUNDAL_PER_MINUTE';
const FOOT_POUNDAL_PER_SECOND = 'FOOT_POUNDAL_PER_SECOND';
const GIGAWATT = 'GIGAWATT';
const GRAM_FORCE_CENTIMETER_PER_HOUR = 'GRAM_FORCE_CENTIMETER_PER_HOUR';
const GRAM_FORCE_CENTIMETER_PER_MINUTE = 'GRAM_FORCE_CENTIMETER_PER_MINUTE';
const GRAM_FORCE_CENTIMETER_PER_SECOND = 'GRAM_FORCE_CENTIMETER_PER_SECOND';
const HECTOWATT = 'HECTOWATT';
const HORSEPOWER_INTERNATIONAL = 'HORSEPOWER_INTERNATIONAL';
const HORSEPOWER_ELECTRIC = 'HORSEPOWER_ELECTRIC';
const HORSEPOWER = 'HORSEPOWER';
const HORSEPOWER_WATER = 'HORSEPOWER_WATER';
const INCH_OUNCE_FORCE_REVOLUTION_PER_MINUTE = 'INCH_OUNCH_FORCE_REVOLUTION_PER_MINUTE';
const JOULE_PER_HOUR = 'JOULE_PER_HOUR';
const JOULE_PER_MINUTE = 'JOULE_PER_MINUTE';
const JOULE_PER_SECOND = 'JOULE_PER_SECOND';
const KILOCALORIE_PER_HOUR = 'KILOCALORIE_PER_HOUR';
const KILOCALORIE_PER_MINUTE = 'KILOCALORIE_PER_MINUTE';
const KILOCALORIE_PER_SECOND = 'KILOCALORIE_PER_SECOND';
const KILOGRAM_FORCE_METER_PER_HOUR = 'KILOGRAM_FORCE_METER_PER_HOUR';
const KILOGRAM_FORCE_METER_PER_MINUTE = 'KILOGRAM_FORCE_METER_PER_MINUTE';
const KILOGRAM_FORCE_METER_PER_SECOND = 'KILOGRAM_FORCE_METER_PER_SECOND';
const KILOPOND_METER_PER_HOUR = 'KILOPOND_METER_PER_HOUR';
const KILOPOND_METER_PER_MINUTE = 'KILOPOND_METER_PER_MINUTE';
const KILOPOND_METER_PER_SECOND = 'KILOPOND_METER_PER_SECOND';
const KILOWATT = 'KILOWATT';
const MEGAWATT = 'MEGAWATT';
const MICROWATT = 'MICROWATT';
const MILLION_BTU_PER_HOUR = 'MILLION_BTU_PER_HOUR';
const MILLIWATT = 'MILLIWATT';
const NANOWATT = 'NANOWATT';
const NEWTON_METER_PER_HOUR = 'NEWTON_METER_PER_HOUR';
const NEWTON_METER_PER_MINUTE = 'NEWTON_METER_PER_MINUTE';
const NEWTON_METER_PER_SECOND = 'NEWTON_METER_PER_SECOND';
const PETAWATT = 'PETAWATT';
const PFERDESTAERKE = 'PFERDESTAERKE';
const PICOWATT = 'PICOWATT';
const PONCELET = 'PONCELET';
const POUND_SQUARE_FOOR_PER_CUBIC_SECOND = 'POUND_SQUARE_FOOT_PER_CUBIC_SECOND';
const TERAWATT = 'TERAWATT';
const TON_OF_REFRIGERATION = 'TON_OF_REFRIGERATION';
const WATT = 'WATT';
const YOCTOWATT = 'YOCTOWATT';
const YOTTAWATT = 'YOTTAWATT';
const ZEPTOWATT = 'ZEPTOWATT';
const ZETTAWATT = 'ZETTAWATT';
/**
* Calculations for all power units
*
* @var array
*/
protected $_units = array(
'ATTOWATT' => array('1.0e-18', 'aW'),
'BTU_PER_HOUR' => array('0.29307197', 'BTU/h'),
'BTU_PER_MINUTE' => array('17.5843182', 'BTU/m'),
'BTU_PER_SECOND' => array('1055.059092', 'BTU/s'),
'CALORIE_PER_HOUR' => array(array('' => '11630', '*' => '1.0e-7'), 'cal/h'),
'CALORIE_PER_MINUTE' => array(array('' => '697800', '*' => '1.0e-7'), 'cal/m'),
'CALORIE_PER_SECOND' => array(array('' => '41868000', '*' => '1.0e-7'), 'cal/s'),
'CENTIWATT' => array('0.01', 'cW'),
'CHEVAL_VAPEUR' => array('735.49875', 'cv'),
'CLUSEC' => array('0.0000013332237', 'clusec'),
'DECIWATT' => array('0.1', 'dW'),
'DEKAWATT' => array('10', 'daW'),
'DYNE_CENTIMETER_PER_HOUR' => array(array('' => '1.0e-7','/' => '3600'), 'dyn cm/h'),
'DYNE_CENTIMETER_PER_MINUTE' => array(array('' => '1.0e-7','/' => '60'), 'dyn cm/m'),
'DYNE_CENTIMETER_PER_SECOND' => array('1.0e-7', 'dyn cm/s'),
'ERG_PER_HOUR' => array(array('' => '1.0e-7','/' => '3600'), 'erg/h'),
'ERG_PER_MINUTE' => array(array('' => '1.0e-7','/' => '60'), 'erg/m'),
'ERG_PER_SECOND' => array('1.0e-7', 'erg/s'),
'EXAWATT' => array('1.0e+18', 'EW'),
'FEMTOWATT' => array('1.0e-15', 'fW'),
'FOOT_POUND_FORCE_PER_HOUR' => array(array('' => '1.3558179', '/' => '3600'), 'ft lb/h'),
'FOOT_POUND_FORCE_PER_MINUTE' => array(array('' => '1.3558179', '/' => '60'), 'ft lb/m'),
'FOOT_POUND_FORCE_PER_SECOND' => array('1.3558179', 'ft lb/s'),
'FOOT_POUNDAL_PER_HOUR' => array(array('' => '0.04214011','/' => '3600'), 'ft pdl/h'),
'FOOT_POUNDAL_PER_MINUTE' => array(array('' => '0.04214011', '/' => '60'), 'ft pdl/m'),
'FOOT_POUNDAL_PER_SECOND' => array('0.04214011', 'ft pdl/s'),
'GIGAWATT' => array('1.0e+9', 'GW'),
'GRAM_FORCE_CENTIMETER_PER_HOUR' => array(array('' => '0.0000980665','/' => '3600'), 'gf cm/h'),
'GRAM_FORCE_CENTIMETER_PER_MINUTE' => array(array('' => '0.0000980665','/' => '60'), 'gf cm/m'),
'GRAM_FORCE_CENTIMETER_PER_SECOND' => array('0.0000980665', 'gf cm/s'),
'HECTOWATT' => array('100', 'hW'),
'HORSEPOWER_INTERNATIONAL' => array('745.69987', 'hp'),
'HORSEPOWER_ELECTRIC' => array('746', 'hp'),
'HORSEPOWER' => array('735.49875', 'hp'),
'HORSEPOWER_WATER' => array('746.043', 'hp'),
'INCH_OUNCH_FORCE_REVOLUTION_PER_MINUTE' => array('0.00073948398', 'in ocf/m'),
'JOULE_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'J/h'),
'JOULE_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'J/m'),
'JOULE_PER_SECOND' => array('1', 'J/s'),
'KILOCALORIE_PER_HOUR' => array('1.163', 'kcal/h'),
'KILOCALORIE_PER_MINUTE' => array('69.78', 'kcal/m'),
'KILOCALORIE_PER_SECOND' => array('4186.8', 'kcal/s'),
'KILOGRAM_FORCE_METER_PER_HOUR' => array(array('' => '9.80665', '/' => '3600'), 'kgf m/h'),
'KILOGRAM_FORCE_METER_PER_MINUTE' => array(array('' => '9.80665', '/' => '60'), 'kfg m/m'),
'KILOGRAM_FORCE_METER_PER_SECOND' => array('9.80665', 'kfg m/s'),
'KILOPOND_METER_PER_HOUR' => array(array('' => '9.80665', '/' => '3600'), 'kp/h'),
'KILOPOND_METER_PER_MINUTE' => array(array('' => '9.80665', '/' => '60'), 'kp/m'),
'KILOPOND_METER_PER_SECOND' => array('9.80665', 'kp/s'),
'KILOWATT' => array('1000', 'kW'),
'MEGAWATT' => array('1000000', 'MW'),
'MICROWATT' => array('0.000001', 'µW'),
'MILLION_BTU_PER_HOUR' => array('293071.07', 'mio BTU/h'),
'MILLIWATT' => array('0.001', 'mM'),
'NANOWATT' => array('1.0e-9', 'nN'),
'NEWTON_METER_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'Nm/h'),
'NEWTON_METER_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'Nm/m'),
'NEWTON_METER_PER_SECOND' => array('1', 'Nm/s'),
'PETAWATT' => array('1.0e+15', 'PW'),
'PFERDESTAERKE' => array('735.49875', 'PS'),
'PICOWATT' => array('1.0e-12', 'pW'),
'PONCELET' => array('980.665', 'p'),
'POUND_SQUARE_FOOT_PER_CUBIC_SECOND' => array('0.04214011', 'lb ft²/s³'),
'TERAWATT' => array('1.0e+12', 'TW'),
'TON_OF_REFRIGERATION' => array('3516.85284', 'RT'),
'WATT' => array('1', 'W'),
'YOCTOWATT' => array('1.0e-24', 'yW'),
'YOTTAWATT' => array('1.0e+24', 'YW'),
'ZEPTOWATT' => array('1.0e-21', 'zW'),
'ZETTAWATT' => array('1.0e+21', 'ZW'),
'STANDARD' => 'WATT'
);
}
Measure/Exception.php 0000604 00000002116 15071256135 0010615 0 ustar 00 <?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_Measure
* @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 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Exception class
*
* @category Zend
* @package Zend_Measure
* @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_Measure_Exception extends Zend_Exception
{
}
Measure/Illumination.php 0000604 00000005452 15071256135 0011331 0 ustar 00 <?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_Measure
* @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: Illumination.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling illumination conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Illumination
* @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_Measure_Illumination extends Zend_Measure_Abstract
{
const STANDARD = 'LUX';
const FOOTCANDLE = 'FOOTCANDLE';
const KILOLUX = 'KILOLUX';
const LUMEN_PER_SQUARE_CENTIMETER = 'LUMEN_PER_SQUARE_CENTIMETER';
const LUMEN_PER_SQUARE_FOOT = 'LUMEN_PER_SQUARE_FOOT';
const LUMEN_PER_SQUARE_INCH = 'LUMEN_PER_SQUARE_INCH';
const LUMEN_PER_SQUARE_METER = 'LUMEN_PER_SQUARE_METER';
const LUX = 'LUX';
const METERCANDLE = 'METERCANDLE';
const MILLIPHOT = 'MILLIPHOT';
const NOX = 'NOX';
const PHOT = 'PHOT';
/**
* Calculations for all illumination units
*
* @var array
*/
protected $_units = array(
'FOOTCANDLE' => array('10.7639104', 'fc'),
'KILOLUX' => array('1000', 'klx'),
'LUMEN_PER_SQUARE_CENTIMETER' => array('10000', 'lm/cm²'),
'LUMEN_PER_SQUARE_FOOT' => array('10.7639104', 'lm/ft²'),
'LUMEN_PER_SQUARE_INCH' => array('1550.0030976', 'lm/in²'),
'LUMEN_PER_SQUARE_METER' => array('1', 'lm/m²'),
'LUX' => array('1', 'lx'),
'METERCANDLE' => array('1', 'metercandle'),
'MILLIPHOT' => array('10', 'mph'),
'NOX' => array('0.001', 'nox'),
'PHOT' => array('10000', 'ph'),
'STANDARD' => 'LUX'
);
}
Measure/Viscosity/Kinematic.php 0000604 00000013420 15071256135 0012557 0 ustar 00 <?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_Measure
* @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: Kinematic.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling acceleration conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Viscosity_Kinematic
* @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_Measure_Viscosity_Kinematic extends Zend_Measure_Abstract
{
const STANDARD = 'SQUARE_METER_PER_SECOND';
const CENTISTOKES = 'CENTISTOKES';
const LENTOR = 'LENTOR';
const LITER_PER_CENTIMETER_DAY = 'LITER_PER_CENTIMETER_DAY';
const LITER_PER_CENTIMETER_HOUR = 'LITER_PER_CENTIMETER_HOUR';
const LITER_PER_CENTIMETER_MINUTE = 'LITER_PER_CENTIMETER_MINUTE';
const LITER_PER_CENTIMETER_SECOND = 'LITER_PER_CENTIMETER_SECOND';
const POISE_CUBIC_CENTIMETER_PER_GRAM = 'POISE_CUBIC_CENTIMETER_PER_GRAM';
const SQUARE_CENTIMETER_PER_DAY = 'SQUARE_CENTIMETER_PER_DAY';
const SQUARE_CENTIMETER_PER_HOUR = 'SQUARE_CENTIMETER_PER_HOUR';
const SQUARE_CENTIMETER_PER_MINUTE = 'SQUARE_CENTIMETER_PER_MINUTE';
const SQUARE_CENTIMETER_PER_SECOND = 'SQUARE_CENTIMETER_PER_SECOND';
const SQUARE_FOOT_PER_DAY = 'SQUARE_FOOT_PER_DAY';
const SQUARE_FOOT_PER_HOUR = 'SQUARE_FOOT_PER_HOUR';
const SQUARE_FOOT_PER_MINUTE = 'SQUARE_FOOT_PER_MINUTE';
const SQUARE_FOOT_PER_SECOND = 'SQUARE_FOOT_PER_SECOND';
const SQUARE_INCH_PER_DAY = 'SQUARE_INCH_PER_DAY';
const SQUARE_INCH_PER_HOUR = 'SQUARE_INCH_PER_HOUR';
const SQUARE_INCH_PER_MINUTE = 'SQUARE_INCH_PER_MINUTE';
const SQUARE_INCH_PER_SECOND = 'SQUARE_INCH_PER_SECOND';
const SQUARE_METER_PER_DAY = 'SQUARE_METER_PER_DAY';
const SQUARE_METER_PER_HOUR = 'SQUARE_METER_PER_HOUR';
const SQUARE_METER_PER_MINUTE = 'SQUARE_METER_PER_MINUTE';
const SQUARE_METER_PER_SECOND = 'SQUARE_METER_PER_SECOND';
const SQUARE_MILLIMETER_PER_DAY = 'SQUARE_MILLIMETER_PER_DAY';
const SQUARE_MILLIMETER_PER_HOUR = 'SQUARE_MILLIMETER_PER_HOUR';
const SQUARE_MILLIMETER_PER_MINUTE = 'SQUARE_MILLIMETER_PER_MINUTE';
const SQUARE_MILLIMETER_PER_SECOND = 'SQUARE_MILLIMETER_PER_SECOND';
const STOKES = 'STOKES';
/**
* Calculations for all kinematic viscosity units
*
* @var array
*/
protected $_units = array(
'CENTISTOKES' => array('0.000001', 'cSt'),
'LENTOR' => array('0.0001', 'lentor'),
'LITER_PER_CENTIMETER_DAY' => array(array('' => '1', '/' => '864000'), 'l/cm day'),
'LITER_PER_CENTIMETER_HOUR' => array(array('' => '1', '/' => '36000'), 'l/cm h'),
'LITER_PER_CENTIMETER_MINUTE' => array(array('' => '1', '/' => '600'), 'l/cm m'),
'LITER_PER_CENTIMETER_SECOND' => array('0.1', 'l/cm s'),
'POISE_CUBIC_CENTIMETER_PER_GRAM' => array('0.0001', 'P cm³/g'),
'SQUARE_CENTIMETER_PER_DAY' => array(array('' => '1', '/' => '864000000'),'cm²/day'),
'SQUARE_CENTIMETER_PER_HOUR' => array(array('' => '1', '/' => '36000000'),'cm²/h'),
'SQUARE_CENTIMETER_PER_MINUTE' => array(array('' => '1', '/' => '600000'),'cm²/m'),
'SQUARE_CENTIMETER_PER_SECOND' => array('0.0001', 'cm²/s'),
'SQUARE_FOOT_PER_DAY' => array('0.0000010752667', 'ft²/day'),
'SQUARE_FOOT_PER_HOUR' => array('0.0000258064', 'ft²/h'),
'SQUARE_FOOT_PER_MINUTE' => array('0.001548384048', 'ft²/m'),
'SQUARE_FOOT_PER_SECOND' => array('0.09290304', 'ft²/s'),
'SQUARE_INCH_PER_DAY' => array('7.4671296e-9', 'in²/day'),
'SQUARE_INCH_PER_HOUR' => array('0.00000017921111', 'in²/h'),
'SQUARE_INCH_PER_MINUTE' => array('0.000010752667', 'in²/m'),
'SQUARE_INCH_PER_SECOND' => array('0.00064516', 'in²/s'),
'SQUARE_METER_PER_DAY' => array(array('' => '1', '/' => '86400'), 'm²/day'),
'SQUARE_METER_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'm²/h'),
'SQUARE_METER_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'm²/m'),
'SQUARE_METER_PER_SECOND' => array('1', 'm²/s'),
'SQUARE_MILLIMETER_PER_DAY' => array(array('' => '1', '/' => '86400000000'), 'mm²/day'),
'SQUARE_MILLIMETER_PER_HOUR' => array(array('' => '1', '/' => '3600000000'), 'mm²/h'),
'SQUARE_MILLIMETER_PER_MINUTE' => array(array('' => '1', '/' => '60000000'), 'mm²/m'),
'SQUARE_MILLIMETER_PER_SECOND' => array('0.000001', 'mm²/s'),
'STOKES' => array('0.0001', 'St'),
'STANDARD' => 'SQUARE_METER_PER_SECOND'
);
}
Measure/Viscosity/Dynamic.php 0000604 00000015010 15071256135 0012234 0 ustar 00 <?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_Measure
* @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: Dynamic.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling acceleration conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Viscosity_Dynamic
* @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_Measure_Viscosity_Dynamic extends Zend_Measure_Abstract
{
const STANDARD = 'KILOGRAM_PER_METER_SECOND';
const CENTIPOISE = 'CENTIPOISE';
const DECIPOISE = 'DECIPOISE';
const DYNE_SECOND_PER_SQUARE_CENTIMETER = 'DYNE_SECOND_PER_SQUARE_CENTIMETER';
const GRAM_FORCE_SECOND_PER_SQUARE_CENTIMETER = 'GRAM_FORCE_SECOND_PER_SQUARE_CENTIMETER';
const GRAM_PER_CENTIMETER_SECOND = 'GRAM_PER_CENTIMETER_SECOND';
const KILOGRAM_FORCE_SECOND_PER_SQUARE_METER = 'KILOGRAM_FORCE_SECOND_PER_SQUARE_METER';
const KILOGRAM_PER_METER_HOUR = 'KILOGRAM_PER_METER_HOUR';
const KILOGRAM_PER_METER_SECOND = 'KILOGRAM_PER_METER_SECOND';
const MILLIPASCAL_SECOND = 'MILLIPASCAL_SECOND';
const MILLIPOISE = 'MILLIPOISE';
const NEWTON_SECOND_PER_SQUARE_METER = 'NEWTON_SECOND_PER_SQUARE_METER';
const PASCAL_SECOND = 'PASCAL_SECOND';
const POISE = 'POISE';
const POISEUILLE = 'POISEUILLE';
const POUND_FORCE_SECOND_PER_SQUARE_FEET = 'POUND_FORCE_SECOND_PER_SQUARE_FEET';
const POUND_FORCE_SECOND_PER_SQUARE_INCH = 'POUND_FORCE_SECOND_PER_SQUARE_INCH';
const POUND_PER_FOOT_HOUR = 'POUND_PER_FOOT_HOUR';
const POUND_PER_FOOT_SECOND = 'POUND_PER_FOOT_SECOND';
const POUNDAL_HOUR_PER_SQUARE_FOOT = 'POUNDAL_HOUR_PER_SQUARE_FOOT';
const POUNDAL_SECOND_PER_SQUARE_FOOT = 'POUNDAL_SECOND_PER_SQUARE_FOOT';
const REYN = 'REYN';
const SLUG_PER_FOOT_SECOND = 'SLUG_PER_FOOT_SECOND';
const LBFS_PER_SQUARE_FOOT = 'LBFS_PER_SQUARE_FOOT';
const NS_PER_SQUARE_METER = 'NS_PER_SQUARE_METER';
const WATER_20C = 'WATER_20C';
const WATER_40C = 'WATER_40C';
const HEAVY_OIL_20C = 'HEAVY_OIL_20C';
const HEAVY_OIL_40C = 'HEAVY_OIL_40C';
const GLYCERIN_20C = 'GLYCERIN_20C';
const GLYCERIN_40C = 'GLYCERIN_40C';
const SAE_5W_MINUS18C = 'SAE_5W_MINUS18C';
const SAE_10W_MINUS18C = 'SAE_10W_MINUS18C';
const SAE_20W_MINUS18C = 'SAE_20W_MINUS18C';
const SAE_5W_99C = 'SAE_5W_99C';
const SAE_10W_99C = 'SAE_10W_99C';
const SAE_20W_99C = 'SAE_20W_99C';
/**
* Calculations for all dynamic viscosity units
*
* @var array
*/
protected $_units = array(
'CENTIPOISE' => array('0.001', 'cP'),
'DECIPOISE' => array('0.01', 'dP'),
'DYNE_SECOND_PER_SQUARE_CENTIMETER' => array('0.1', 'dyn s/cm²'),
'GRAM_FORCE_SECOND_PER_SQUARE_CENTIMETER' => array('98.0665', 'gf s/cm²'),
'GRAM_PER_CENTIMETER_SECOND' => array('0.1', 'g/cm s'),
'KILOGRAM_FORCE_SECOND_PER_SQUARE_METER' => array('9.80665', 'kgf s/m²'),
'KILOGRAM_PER_METER_HOUR' => array(array('' => '1', '/' => '3600'), 'kg/m h'),
'KILOGRAM_PER_METER_SECOND' => array('1', 'kg/ms'),
'MILLIPASCAL_SECOND' => array('0.001', 'mPa s'),
'MILLIPOISE' => array('0.0001', 'mP'),
'NEWTON_SECOND_PER_SQUARE_METER' => array('1', 'N s/m²'),
'PASCAL_SECOND' => array('1', 'Pa s'),
'POISE' => array('0.1', 'P'),
'POISEUILLE' => array('1', 'Pl'),
'POUND_FORCE_SECOND_PER_SQUARE_FEET' => array('47.880259', 'lbf s/ft²'),
'POUND_FORCE_SECOND_PER_SQUARE_INCH' => array('6894.75729', 'lbf s/in²'),
'POUND_PER_FOOT_HOUR' => array('0.00041337887', 'lb/ft h'),
'POUND_PER_FOOT_SECOND' => array('1.4881639', 'lb/ft s'),
'POUNDAL_HOUR_PER_SQUARE_FOOT' => array('0.00041337887', 'pdl h/ft²'),
'POUNDAL_SECOND_PER_SQUARE_FOOT' => array('1.4881639', 'pdl s/ft²'),
'REYN' => array('6894.75729', 'reyn'),
'SLUG_PER_FOOT_SECOND'=> array('47.880259', 'slug/ft s'),
'WATER_20C' => array('0.001', 'water (20°)'),
'WATER_40C' => array('0.00065', 'water (40°)'),
'HEAVY_OIL_20C' => array('0.45', 'oil (20°)'),
'HEAVY_OIL_40C' => array('0.11', 'oil (40°)'),
'GLYCERIN_20C' => array('1.41', 'glycerin (20°)'),
'GLYCERIN_40C' => array('0.284', 'glycerin (40°)'),
'SAE_5W_MINUS18C' => array('1.2', 'SAE 5W (-18°)'),
'SAE_10W_MINUS18C' => array('2.4', 'SAE 10W (-18°)'),
'SAE_20W_MINUS18C' => array('9.6', 'SAE 20W (-18°)'),
'SAE_5W_99C' => array('0.0039', 'SAE 5W (99°)'),
'SAE_10W_99C' => array('0.0042', 'SAE 10W (99°)'),
'SAE_20W_99C' => array('0.0057', 'SAE 20W (99°)'),
'STANDARD' => 'KILOGRAM_PER_METER_SECOND'
);
}
Measure/Weight.php 0000604 00000063606 15071256135 0010121 0 ustar 00 <?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_Measure
* @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: Weight.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling weight conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Weigth
* @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_Measure_Weight extends Zend_Measure_Abstract
{
const STANDARD = 'KILOGRAM';
const ARRATEL = 'ARRATEL';
const ARTEL = 'ARTEL';
const ARROBA_PORTUGUESE = 'ARROBA_PORTUGUESE';
const ARROBA = 'ARROBA';
const AS_ = 'AS_';
const ASS = 'ASS';
const ATOMIC_MASS_UNIT_1960 = 'ATOMIC_MASS_UNIT_1960';
const ATOMIC_MASS_UNIT_1973 = 'ATOMIC_MASS_UNIT_1973';
const ATOMIC_MASS_UNIT_1986 = 'ATOMIC_MASS_UNIT_1986';
const ATOMIC_MASS_UNIT = 'ATOMIC_MASS_UNIT';
const AVOGRAM = 'AVOGRAM';
const BAG = 'BAG';
const BAHT = 'BAHT';
const BALE = 'BALE';
const BALE_US = 'BALE_US';
const BISMAR_POUND = 'BISMAR_POUND';
const CANDY = 'CANDY';
const CARAT_INTERNATIONAL = 'CARAT_INTERNATIONAL';
const CARAT = 'CARAT';
const CARAT_UK = 'CARAT_UK';
const CARAT_US_1913 = 'CARAT_US_1913';
const CARGA = 'CARGA';
const CATTI = 'CATTI';
const CATTI_JAPANESE = 'CATTI_JAPANESE';
const CATTY = 'CATTY';
const CATTY_JAPANESE = 'CATTY_JAPANESE';
const CATTY_THAI = 'CATTY_THAI';
const CENTAL = 'CENTAL';
const CENTIGRAM = 'CENTIGRAM';
const CENTNER = 'CENTNER';
const CENTNER_RUSSIAN = 'CENTNER_RUSSIAN';
const CHALDER = 'CHALDER';
const CHALDRON = 'CHALDRON';
const CHIN = 'CHIN';
const CHIN_JAPANESE = 'CHIN_JAPANESE';
const CLOVE = 'CLOVE';
const CRITH = 'CRITH';
const DALTON = 'DALTON';
const DAN = 'DAN';
const DAN_JAPANESE = 'DAN_JAPANESE';
const DECIGRAM = 'DECIGRAM';
const DECITONNE = 'DECITONNE';
const DEKAGRAM = 'DEKAGRAM';
const DEKATONNE = 'DEKATONNE';
const DENARO = 'DENARO';
const DENIER = 'DENIER';
const DRACHME = 'DRACHME';
const DRAM = 'DRAM';
const DRAM_APOTHECARIES = 'DRAM_APOTHECARIES';
const DYNE = 'DYNE';
const ELECTRON = 'ELECTRON';
const ELECTRONVOLT = 'ELECTRONVOLT';
const ETTO = 'ETTO';
const EXAGRAM = 'EXAGRAM';
const FEMTOGRAM = 'FEMTOGRAM';
const FIRKIN = 'FIRKIN';
const FLASK = 'FLASK';
const FOTHER = 'FOTHER';
const FOTMAL = 'FOTMAL';
const FUNT = 'FUNT';
const FUNTE = 'FUNTE';
const GAMMA = 'GAMMA';
const GIGAELECTRONVOLT = 'GIGAELECTRONVOLT';
const GIGAGRAM = 'GIGAGRAM';
const GIGATONNE = 'GIGATONNE';
const GIN = 'GIN';
const GIN_JAPANESE = 'GIN_JAPANESE';
const GRAIN = 'GRAIN';
const GRAM = 'GRAM';
const GRAN = 'GRAN';
const GRANO = 'GRANO';
const GRANI = 'GRANI';
const GROS = 'GROS';
const HECTOGRAM = 'HECTOGRAM';
const HUNDRETWEIGHT = 'HUNDRETWEIGHT';
const HUNDRETWEIGHT_US = 'HUNDRETWEIGHT_US';
const HYL = 'HYL';
const JIN = 'JIN';
const JUPITER = 'JUPITER';
const KATI = 'KATI';
const KATI_JAPANESE = 'KATI_JAPANESE';
const KEEL = 'KEEL';
const KEG = 'KEG';
const KILODALTON = 'KILODALTON';
const KILOGRAM = 'KILOGRAM';
const KILOGRAM_FORCE = 'KILOGRAM_FORCE';
const KILOTON = 'KILOTON';
const KILOTON_US = 'KILOTON_US';
const KILOTONNE = 'KILOTONNE';
const KIN = 'KIN';
const KIP = 'KIP';
const KOYAN = 'KOYAN';
const KWAN = 'KWAN';
const LAST_GERMANY = 'LAST_GERMANY';
const LAST = 'LAST';
const LAST_WOOL = 'LAST_WOOL';
const LB = 'LB';
const LBS = 'LBS';
const LIANG = 'LIANG';
const LIBRA_ITALIAN = 'LIBRE_ITALIAN';
const LIBRA_SPANISH = 'LIBRA_SPANISH';
const LIBRA_PORTUGUESE = 'LIBRA_PORTUGUESE';
const LIBRA_ANCIENT = 'LIBRA_ANCIENT';
const LIBRA = 'LIBRA';
const LIVRE = 'LIVRE';
const LONG_TON = 'LONG_TON';
const LOT = 'LOT';
const MACE = 'MACE';
const MAHND = 'MAHND';
const MARC = 'MARC';
const MARCO = 'MARCO';
const MARK = 'MARK';
const MARK_GERMAN = 'MARK_GERMANY';
const MAUND = 'MAUND';
const MAUND_PAKISTAN = 'MAUND_PAKISTAN';
const MEGADALTON = 'MEGADALTON';
const MEGAGRAM = 'MEGAGRAM';
const MEGATONNE = 'MEGATONNE';
const MERCANTILE_POUND = 'MERCANTILE_POUND';
const METRIC_TON = 'METRIC_TON';
const MIC = 'MIC';
const MICROGRAM = 'MICROGRAM';
const MILLIDALTON = 'MILLIDALTON';
const MILLIER = 'MILLIER';
const MILLIGRAM = 'MILLIGRAM';
const MILLIMASS_UNIT = 'MILLIMASS_UNIT';
const MINA = 'MINA';
const MOMME = 'MOMME';
const MYRIAGRAM = 'MYRIAGRAM';
const NANOGRAM = 'NANOGRAM';
const NEWTON = 'NEWTON';
const OBOL = 'OBOL';
const OBOLOS = 'OBOLOS';
const OBOLUS = 'OBOLUS';
const OBOLOS_ANCIENT = 'OBOLOS_ANCIENT';
const OBOLUS_ANCIENT = 'OBOLUS_ANCIENT';
const OKA = 'OKA';
const ONCA = 'ONCA';
const ONCE = 'ONCE';
const ONCIA = 'ONCIA';
const ONZA = 'ONZA';
const ONS = 'ONS';
const OUNCE = 'OUNCE';
const OUNCE_FORCE = 'OUNCE_FORCE';
const OUNCE_TROY = 'OUNCE_TROY';
const PACKEN = 'PACKEN';
const PENNYWEIGHT = 'PENNYWEIGHT';
const PETAGRAM = 'PETAGRAM';
const PFUND = 'PFUND';
const PICOGRAM = 'PICOGRAM';
const POINT = 'POINT';
const POND = 'POND';
const POUND = 'POUND';
const POUND_FORCE = 'POUND_FORCE';
const POUND_METRIC = 'POUND_METRIC';
const POUND_TROY = 'POUND_TROY';
const PUD = 'PUD';
const POOD = 'POOD';
const PUND = 'PUND';
const QIAN = 'QIAN';
const QINTAR = 'QINTAR';
const QUARTER = 'QUARTER';
const QUARTER_US = 'QUARTER_US';
const QUARTER_TON = 'QUARTER_TON';
const QUARTERN = 'QUARTERN';
const QUARTERN_LOAF = 'QUARTERN_LOAF';
const QUINTAL_FRENCH = 'QUINTAL_FRENCH';
const QUINTAL = 'QUINTAL';
const QUINTAL_PORTUGUESE = 'QUINTAL_PORTUGUESE';
const QUINTAL_SPAIN = 'QUINTAL_SPAIN';
const REBAH = 'REBAH';
const ROTL = 'ROTL';
const ROTEL = 'ROTEL';
const ROTTLE = 'ROTTLE';
const RATEL = 'RATEL';
const SACK = 'SACK';
const SCRUPLE = 'SCRUPLE';
const SEER = 'SEER';
const SEER_PAKISTAN = 'SEER_PAKISTAN';
const SHEKEL = 'SHEKEL';
const SHORT_TON = 'SHORT_TON';
const SLINCH = 'SLINCH';
const SLUG = 'SLUG';
const STONE = 'STONE';
const TAEL = 'TAEL';
const TAHIL_JAPANESE = 'TAHIL_JAPANESE';
const TAHIL = 'TAHIL';
const TALENT = 'TALENT';
const TAN = 'TAN';
const TECHNISCHE_MASS_EINHEIT = 'TECHNISCHE_MASS_EINHEIT';
const TERAGRAM = 'TERAGRAM';
const TETRADRACHM = 'TETRADRACHM';
const TICAL = 'TICAL';
const TOD = 'TOD';
const TOLA = 'TOLA';
const TOLA_PAKISTAN = 'TOLA_PAKISTAN';
const TON_UK = 'TON_UK';
const TON = 'TON';
const TON_US = 'TON_US';
const TONELADA_PORTUGUESE = 'TONELADA_PORTUGUESE';
const TONELADA = 'TONELADA';
const TONNE = 'TONNE';
const TONNEAU = 'TONNEAU';
const TOVAR = 'TOVAR';
const TROY_OUNCE = 'TROY_OUNCE';
const TROY_POUND = 'TROY_POUND';
const TRUSS = 'TRUSS';
const UNCIA = 'UNCIA';
const UNZE = 'UNZE';
const VAGON = 'VAGON';
const YOCTOGRAM = 'YOCTOGRAM';
const YOTTAGRAM = 'YOTTAGRAM';
const ZENTNER = 'ZENTNER';
const ZEPTOGRAM = 'ZEPTOGRAM';
const ZETTAGRAM = 'ZETTAGRAM';
/**
* Calculations for all weight units
*
* @var array
*/
protected $_units = array(
'ARRATEL' => array('0.5', 'arratel'),
'ARTEL' => array('0.5', 'artel'),
'ARROBA_PORTUGUESE' => array('14.69', 'arroba'),
'ARROBA' => array('11.502', '@'),
'AS_' => array('0.000052', 'as'),
'ASS' => array('0.000052', 'ass'),
'ATOMIC_MASS_UNIT_1960' => array('1.6603145e-27', 'amu'),
'ATOMIC_MASS_UNIT_1973' => array('1.6605655e-27', 'amu'),
'ATOMIC_MASS_UNIT_1986' => array('1.6605402e-27', 'amu'),
'ATOMIC_MASS_UNIT' => array('1.66053873e-27', 'amu'),
'AVOGRAM' => array('1.6605402e-27', 'avogram'),
'BAG' => array('42.63768278', 'bag'),
'BAHT' => array('0.015', 'baht'),
'BALE' => array('326.5865064', 'bl'),
'BALE_US' => array('217.7243376', 'bl'),
'BISMAR_POUND' => array('5.993', 'bismar pound'),
'CANDY' => array('254', 'candy'),
'CARAT_INTERNATIONAL' => array('0.0002', 'ct'),
'CARAT' => array('0.0002', 'ct'),
'CARAT_UK' => array('0.00025919564', 'ct'),
'CARAT_US_1913' => array('0.0002053', 'ct'),
'CARGA' => array('140', 'carga'),
'CATTI' => array('0.604875', 'catti'),
'CATTI_JAPANESE' => array('0.594', 'catti'),
'CATTY' => array('0.5', 'catty'),
'CATTY_JAPANESE' => array('0.6', 'catty'),
'CATTY_THAI' => array('0.6', 'catty'),
'CENTAL' => array('45.359237', 'cH'),
'CENTIGRAM' => array('0.00001', 'cg'),
'CENTNER' => array('50', 'centner'),
'CENTNER_RUSSIAN' => array('100', 'centner'),
'CHALDER' => array('2692.52', 'chd'),
'CHALDRON' => array('2692.52', 'chd'),
'CHIN' => array('0.5', 'chin'),
'CHIN_JAPANESE' => array('0.6', 'chin'),
'CLOVE' => array('3.175', 'clove'),
'CRITH' => array('0.000089885', 'crith'),
'DALTON' => array('1.6605402e-27', 'D'),
'DAN' => array('50', 'dan'),
'DAN_JAPANESE' => array('60', 'dan'),
'DECIGRAM' => array('0.0001', 'dg'),
'DECITONNE' => array('100', 'dt'),
'DEKAGRAM' => array('0.01', 'dag'),
'DEKATONNE' => array('10000', 'dat'),
'DENARO' => array('0.0011', 'denaro'),
'DENIER' => array('0.001275', 'denier'),
'DRACHME' => array('0.0038', 'drachme'),
'DRAM' => array(array('' => '0.45359237', '/' => '256'), 'dr'),
'DRAM_APOTHECARIES' => array('0.0038879346', 'dr'),
'DYNE' => array('1.0197162e-6', 'dyn'),
'ELECTRON' => array('9.109382e-31', 'e−'),
'ELECTRONVOLT' => array('1.782662e-36', 'eV'),
'ETTO' => array('0.1', 'hg'),
'EXAGRAM' => array('1.0e+15', 'Eg'),
'FEMTOGRAM' => array('1.0e-18', 'fg'),
'FIRKIN' => array('25.40117272', 'fir'),
'FLASK' => array('34.7', 'flask'),
'FOTHER' => array('979.7595192', 'fother'),
'FOTMAL' => array('32.65865064', 'fotmal'),
'FUNT' => array('0.4095', 'funt'),
'FUNTE' => array('0.4095', 'funte'),
'GAMMA' => array('0.000000001', 'gamma'),
'GIGAELECTRONVOLT' => array('1.782662e-27', 'GeV'),
'GIGAGRAM' => array('1000000', 'Gg'),
'GIGATONNE' => array('1.0e+12', 'Gt'),
'GIN' => array('0.6', 'gin'),
'GIN_JAPANESE' => array('0.594', 'gin'),
'GRAIN' => array('0.00006479891', 'gr'),
'GRAM' => array('0.001', 'g'),
'GRAN' => array('0.00082', 'gran'),
'GRANO' => array('0.00004905', 'grano'),
'GRANI' => array('0.00004905', 'grani'),
'GROS' => array('0.003824', 'gros'),
'HECTOGRAM' => array('0.1', 'hg'),
'HUNDRETWEIGHT' => array('50.80234544', 'cwt'),
'HUNDRETWEIGHT_US' => array('45.359237', 'cwt'),
'HYL' => array('9.80665', 'hyl'),
'JIN' => array('0.5', 'jin'),
'JUPITER' => array('1.899e+27', 'jupiter'),
'KATI' => array('0.5', 'kati'),
'KATI_JAPANESE' => array('0.6', 'kati'),
'KEEL' => array('21540.19446656', 'keel'),
'KEG' => array('45.359237', 'keg'),
'KILODALTON' => array('1.6605402e-24', 'kD'),
'KILOGRAM' => array('1', 'kg'),
'KILOGRAM_FORCE' => array('1', 'kgf'),
'KILOTON' => array('1016046.9088', 'kt'),
'KILOTON_US' => array('907184.74', 'kt'),
'KILOTONNE' => array('1000000', 'kt'),
'KIN' => array('0.6', 'kin'),
'KIP' => array('453.59237', 'kip'),
'KOYAN' => array('2419', 'koyan'),
'KWAN' => array('3.75', 'kwan'),
'LAST_GERMANY' => array('2000', 'last'),
'LAST' => array('1814.36948', 'last'),
'LAST_WOOL' => array('1981.29147216', 'last'),
'LB' => array('0.45359237', 'lb'),
'LBS' => array('0.45359237', 'lbs'),
'LIANG' => array('0.05', 'liang'),
'LIBRE_ITALIAN' => array('0.339', 'lb'),
'LIBRA_SPANISH' => array('0.459', 'lb'),
'LIBRA_PORTUGUESE' => array('0.459', 'lb'),
'LIBRA_ANCIENT' => array('0.323', 'lb'),
'LIBRA' => array('1', 'lb'),
'LIVRE' => array('0.4895', 'livre'),
'LONG_TON' => array('1016.0469088', 't'),
'LOT' => array('0.015', 'lot'),
'MACE' => array('0.003778', 'mace'),
'MAHND' => array('0.9253284348', 'mahnd'),
'MARC' => array('0.24475', 'marc'),
'MARCO' => array('0.23', 'marco'),
'MARK' => array('0.2268', 'mark'),
'MARK_GERMANY' => array('0.2805', 'mark'),
'MAUND' => array('37.3242', 'maund'),
'MAUND_PAKISTAN' => array('40', 'maund'),
'MEGADALTON' => array('1.6605402e-21', 'MD'),
'MEGAGRAM' => array('1000', 'Mg'),
'MEGATONNE' => array('1.0e+9', 'Mt'),
'MERCANTILE_POUND' => array('0.46655', 'lb merc'),
'METRIC_TON' => array('1000', 't'),
'MIC' => array('1.0e-9', 'mic'),
'MICROGRAM' => array('1.0e-9', '�g'),
'MILLIDALTON' => array('1.6605402e-30', 'mD'),
'MILLIER' => array('1000', 'millier'),
'MILLIGRAM' => array('0.000001', 'mg'),
'MILLIMASS_UNIT' => array('1.6605402e-30', 'mmu'),
'MINA' => array('0.499', 'mina'),
'MOMME' => array('0.00375', 'momme'),
'MYRIAGRAM' => array('10', 'myg'),
'NANOGRAM' => array('1.0e-12', 'ng'),
'NEWTON' => array('0.101971621', 'N'),
'OBOL' => array('0.0001', 'obol'),
'OBOLOS' => array('0.0001', 'obolos'),
'OBOLUS' => array('0.0001', 'obolus'),
'OBOLOS_ANCIENT' => array('0.0005', 'obolos'),
'OBOLUS_ANCIENT' => array('0.00057', 'obolos'),
'OKA' => array('1.28', 'oka'),
'ONCA' => array('0.02869', 'onca'),
'ONCE' => array('0.03059', 'once'),
'ONCIA' => array('0.0273', 'oncia'),
'ONZA' => array('0.02869', 'onza'),
'ONS' => array('0.1', 'ons'),
'OUNCE' => array(array('' => '0.45359237', '/' => '16'), 'oz'),
'OUNCE_FORCE' => array(array('' => '0.45359237', '/' => '16'), 'ozf'),
'OUNCE_TROY' => array(array('' => '65.31730128', '/' => '2100'), 'oz'),
'PACKEN' => array('490.79', 'packen'),
'PENNYWEIGHT' => array(array('' => '65.31730128', '/' => '42000'), 'dwt'),
'PETAGRAM' => array('1.0e+12', 'Pg'),
'PFUND' => array('0.5', 'pfd'),
'PICOGRAM' => array('1.0e-15', 'pg'),
'POINT' => array('0.000002', 'pt'),
'POND' => array('0.5', 'pond'),
'POUND' => array('0.45359237', 'lb'),
'POUND_FORCE' => array('0.4535237', 'lbf'),
'POUND_METRIC' => array('0.5', 'lb'),
'POUND_TROY' => array(array('' => '65.31730128', '/' => '175'), 'lb'),
'PUD' => array('16.3', 'pud'),
'POOD' => array('16.3', 'pood'),
'PUND' => array('0.5', 'pund'),
'QIAN' => array('0.005', 'qian'),
'QINTAR' => array('50', 'qintar'),
'QUARTER' => array('12.70058636', 'qtr'),
'QUARTER_US' => array('11.33980925', 'qtr'),
'QUARTER_TON' => array('226.796185', 'qtr'),
'QUARTERN' => array('1.587573295', 'quartern'),
'QUARTERN_LOAF' => array('1.81436948', 'quartern-loaf'),
'QUINTAL_FRENCH' => array('48.95', 'q'),
'QUINTAL' => array('100', 'q'),
'QUINTAL_PORTUGUESE' => array('58.752', 'q'),
'QUINTAL_SPAIN' => array('45.9', 'q'),
'REBAH' => array('0.2855', 'rebah'),
'ROTL' => array('0.5', 'rotl'),
'ROTEL' => array('0.5', 'rotel'),
'ROTTLE' => array('0.5', 'rottle'),
'RATEL' => array('0.5', 'ratel'),
'SACK' => array('165.10762268', 'sack'),
'SCRUPLE' => array(array('' => '65.31730128', '/' => '50400'), 's'),
'SEER' => array('0.933105', 'seer'),
'SEER_PAKISTAN' => array('1', 'seer'),
'SHEKEL' => array('0.01142', 'shekel'),
'SHORT_TON' => array('907.18474', 'st'),
'SLINCH' => array('175.126908', 'slinch'),
'SLUG' => array('14.593903', 'slug'),
'STONE' => array('6.35029318', 'st'),
'TAEL' => array('0.03751', 'tael'),
'TAHIL_JAPANESE' => array('0.03751', 'tahil'),
'TAHIL' => array('0.05', 'tahil'),
'TALENT' => array('30', 'talent'),
'TAN' => array('50', 'tan'),
'TECHNISCHE_MASS_EINHEIT' => array('9.80665', 'TME'),
'TERAGRAM' => array('1.0e+9', 'Tg'),
'TETRADRACHM' => array('0.014', 'tetradrachm'),
'TICAL' => array('0.0164', 'tical'),
'TOD' => array('12.70058636', 'tod'),
'TOLA' => array('0.0116638125', 'tola'),
'TOLA_PAKISTAN' => array('0.0125', 'tola'),
'TON_UK' => array('1016.0469088', 't'),
'TON' => array('1000', 't'),
'TON_US' => array('907.18474', 't'),
'TONELADA_PORTUGUESE' => array('793.15', 'tonelada'),
'TONELADA' => array('919.9', 'tonelada'),
'TONNE' => array('1000', 't'),
'TONNEAU' => array('979', 'tonneau'),
'TOVAR' => array('128.8', 'tovar'),
'TROY_OUNCE' => array(array('' => '65.31730128', '/' => '2100'), 'troy oz'),
'TROY_POUND' => array(array('' => '65.31730128', '/' => '175'), 'troy lb'),
'TRUSS' => array('25.40117272', 'truss'),
'UNCIA' => array('0.0272875', 'uncia'),
'UNZE' => array('0.03125', 'unze'),
'VAGON' => array('10000', 'vagon'),
'YOCTOGRAM' => array('1.0e-27', 'yg'),
'YOTTAGRAM' => array('1.0e+21', 'Yg'),
'ZENTNER' => array('50', 'Ztr'),
'ZEPTOGRAM' => array('1.0e-24', 'zg'),
'ZETTAGRAM' => array('1.0e+18', 'Zg'),
'STANDARD' => 'KILOGRAM'
);
}
Measure/Current.php 0000604 00000010461 15071256135 0010303 0 ustar 00 <?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_Measure
* @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: Current.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling current conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Current
* @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_Measure_Current extends Zend_Measure_Abstract
{
const STANDARD = 'AMPERE';
const ABAMPERE = 'ABAMPERE';
const AMPERE = 'AMPERE';
const BIOT = 'BIOT';
const CENTIAMPERE = 'CENTIAMPERE';
const COULOMB_PER_SECOND = 'COULOMB_PER_SECOND';
const DECIAMPERE = 'DECIAMPERE';
const DEKAAMPERE = 'DEKAAMPERE';
const ELECTROMAGNETIC_UNIT = 'ELECTROMAGNATIC_UNIT';
const ELECTROSTATIC_UNIT = 'ELECTROSTATIC_UNIT';
const FRANCLIN_PER_SECOND = 'FRANCLIN_PER_SECOND';
const GAUSSIAN = 'GAUSSIAN';
const GIGAAMPERE = 'GIGAAMPERE';
const GILBERT = 'GILBERT';
const HECTOAMPERE = 'HECTOAMPERE';
const KILOAMPERE = 'KILOAMPERE';
const MEGAAMPERE = 'MEGAAMPERE';
const MICROAMPERE = 'MICROAMPERE';
const MILLIAMPERE = 'MILLIAMPERE';
const NANOAMPERE = 'NANOAMPERE';
const PICOAMPERE = 'PICOAMPERE';
const SIEMENS_VOLT = 'SIEMENS_VOLT';
const STATAMPERE = 'STATAMPERE';
const TERAAMPERE = 'TERAAMPERE';
const VOLT_PER_OHM = 'VOLT_PER_OHM';
const WATT_PER_VOLT = 'WATT_PER_VOLT';
const WEBER_PER_HENRY = 'WEBER_PER_HENRY';
/**
* Calculations for all current units
*
* @var array
*/
protected $_units = array(
'ABAMPERE' => array('10', 'abampere'),
'AMPERE' => array('1', 'A'),
'BIOT' => array('10', 'Bi'),
'CENTIAMPERE' => array('0.01', 'cA'),
'COULOMB_PER_SECOND' => array('1', 'C/s'),
'DECIAMPERE' => array('0.1', 'dA'),
'DEKAAMPERE' => array('10', 'daA'),
'ELECTROMAGNATIC_UNIT' => array('10', 'current emu'),
'ELECTROSTATIC_UNIT' => array('3.335641e-10', 'current esu'),
'FRANCLIN_PER_SECOND' => array('3.335641e-10', 'Fr/s'),
'GAUSSIAN' => array('3.335641e-10', 'G current'),
'GIGAAMPERE' => array('1.0e+9', 'GA'),
'GILBERT' => array('0.79577472', 'Gi'),
'HECTOAMPERE' => array('100', 'hA'),
'KILOAMPERE' => array('1000', 'kA'),
'MEGAAMPERE' => array('1000000', 'MA') ,
'MICROAMPERE' => array('0.000001', 'µA'),
'MILLIAMPERE' => array('0.001', 'mA'),
'NANOAMPERE' => array('1.0e-9', 'nA'),
'PICOAMPERE' => array('1.0e-12', 'pA'),
'SIEMENS_VOLT' => array('1', 'SV'),
'STATAMPERE' => array('3.335641e-10', 'statampere'),
'TERAAMPERE' => array('1.0e+12', 'TA'),
'VOLT_PER_OHM' => array('1', 'V/Ohm'),
'WATT_PER_VOLT' => array('1', 'W/V'),
'WEBER_PER_HENRY' => array('1', 'Wb/H'),
'STANDARD' => 'AMPERE'
);
}
Measure/Frequency.php 0000604 00000007255 15071256135 0010631 0 ustar 00 <?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_Measure
* @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: Frequency.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling flow volume conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Frequency
* @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_Measure_Frequency extends Zend_Measure_Abstract
{
const STANDARD = 'HERTZ';
const ONE_PER_SECOND = 'ONE_PER_SECOND';
const CYCLE_PER_SECOND = 'CYCLE_PER_SECOND';
const DEGREE_PER_HOUR = 'DEGREE_PER_HOUR';
const DEGREE_PER_MINUTE = 'DEGREE_PER_MINUTE';
const DEGREE_PER_SECOND = 'DEGREE_PER_SECOND';
const GIGAHERTZ = 'GIGAHERTZ';
const HERTZ = 'HERTZ';
const KILOHERTZ = 'KILOHERTZ';
const MEGAHERTZ = 'MEGAHERTZ';
const MILLIHERTZ = 'MILLIHERTZ';
const RADIAN_PER_HOUR = 'RADIAN_PER_HOUR';
const RADIAN_PER_MINUTE = 'RADIAN_PER_MINUTE';
const RADIAN_PER_SECOND = 'RADIAN_PER_SECOND';
const REVOLUTION_PER_HOUR = 'REVOLUTION_PER_HOUR';
const REVOLUTION_PER_MINUTE = 'REVOLUTION_PER_MINUTE';
const REVOLUTION_PER_SECOND = 'REVOLUTION_PER_SECOND';
const RPM = 'RPM';
const TERRAHERTZ = 'TERRAHERTZ';
/**
* Calculations for all frequency units
*
* @var array
*/
protected $_units = array(
'ONE_PER_SECOND' => array('1', '1/s'),
'CYCLE_PER_SECOND' => array('1', 'cps'),
'DEGREE_PER_HOUR' => array(array('' => '1', '/' => '1296000'), '°/h'),
'DEGREE_PER_MINUTE' => array(array('' => '1', '/' => '21600'), '°/m'),
'DEGREE_PER_SECOND' => array(array('' => '1', '/' => '360'), '°/s'),
'GIGAHERTZ' => array('1000000000', 'GHz'),
'HERTZ' => array('1', 'Hz'),
'KILOHERTZ' => array('1000', 'kHz'),
'MEGAHERTZ' => array('1000000', 'MHz'),
'MILLIHERTZ' => array('0.001', 'mHz'),
'RADIAN_PER_HOUR' => array(array('' => '1', '/' => '22619.467'), 'rad/h'),
'RADIAN_PER_MINUTE' => array(array('' => '1', '/' => '376.99112'), 'rad/m'),
'RADIAN_PER_SECOND' => array(array('' => '1', '/' => '6.2831853'), 'rad/s'),
'REVOLUTION_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'rph'),
'REVOLUTION_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'rpm'),
'REVOLUTION_PER_SECOND' => array('1', 'rps'),
'RPM' => array(array('' => '1', '/' => '60'), 'rpm'),
'TERRAHERTZ' => array('1000000000000', 'THz'),
'STANDARD' =>'HERTZ'
);
}
Measure/Lightness.php 0000604 00000007113 15071256135 0010621 0 ustar 00 <?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_Measure
* @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: Lightness.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling temperature conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Lightness
* @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_Measure_Lightness extends Zend_Measure_Abstract
{
const STANDARD = 'CANDELA_PER_SQUARE_METER';
const APOSTILB = 'APOSTILB';
const BLONDEL = 'BLONDEL';
const CANDELA_PER_SQUARE_CENTIMETER = 'CANDELA_PER_SQUARE_CENTIMETER';
const CANDELA_PER_SQUARE_FOOT = 'CANDELA_PER_SQUARE_FOOT';
const CANDELA_PER_SQUARE_INCH = 'CANDELA_PER_SQUARE_INCH';
const CANDELA_PER_SQUARE_METER = 'CANDELA_PER_SQUARE_METER';
const FOOTLAMBERT = 'FOOTLAMBERT';
const KILOCANDELA_PER_SQUARE_CENTIMETER = 'KILOCANDELA_PER_SQUARE_CENTIMETER';
const KILOCANDELA_PER_SQUARE_FOOT = 'KILOCANDELA_PER_SQUARE_FOOT';
const KILOCANDELA_PER_SQUARE_INCH = 'KILOCANDELA_PER_SQUARE_INCH';
const KILOCANDELA_PER_SQUARE_METER = 'KILOCANDELA_PER_SQUARE_METER';
const LAMBERT = 'LAMBERT';
const MILLILAMBERT = 'MILLILAMBERT';
const NIT = 'NIT';
const STILB = 'STILB';
/**
* Calculations for all lightness units
*
* @var array
*/
protected $_units = array(
'APOSTILB' => array('0.31830989', 'asb'),
'BLONDEL' => array('0.31830989', 'blondel'),
'CANDELA_PER_SQUARE_CENTIMETER' => array('10000', 'cd/cm²'),
'CANDELA_PER_SQUARE_FOOT' => array('10.76391', 'cd/ft²'),
'CANDELA_PER_SQUARE_INCH' => array('1550.00304', 'cd/in²'),
'CANDELA_PER_SQUARE_METER' => array('1', 'cd/m²'),
'FOOTLAMBERT' => array('3.4262591', 'ftL'),
'KILOCANDELA_PER_SQUARE_CENTIMETER' => array('10000000', 'kcd/cm²'),
'KILOCANDELA_PER_SQUARE_FOOT' => array('10763.91', 'kcd/ft²'),
'KILOCANDELA_PER_SQUARE_INCH' => array('1550003.04', 'kcd/in²'),
'KILOCANDELA_PER_SQUARE_METER' => array('1000', 'kcd/m²'),
'LAMBERT' => array('3183.0989', 'L'),
'MILLILAMBERT' => array('3.1830989', 'mL'),
'NIT' => array('1', 'nt'),
'STILB' => array('10000', 'sb'),
'STANDARD' => 'CANDELA_PER_SQUARE_METER'
);
}
Measure/Angle.php 0000604 00000005643 15071256135 0007715 0 ustar 00 <?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_Measure
* @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: Angle.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling angle conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Angle
* @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_Measure_Angle extends Zend_Measure_Abstract
{
const STANDARD = 'RADIAN';
const RADIAN = 'RADIAN';
const MIL = 'MIL';
const GRAD = 'GRAD';
const DEGREE = 'DEGREE';
const MINUTE = 'MINUTE';
const SECOND = 'SECOND';
const POINT = 'POINT';
const CIRCLE_16 = 'CIRCLE_16';
const CIRCLE_10 = 'CIRCLE_10';
const CIRCLE_8 = 'CIRCLE_8';
const CIRCLE_6 = 'CIRCLE_6';
const CIRCLE_4 = 'CIRCLE_4';
const CIRCLE_2 = 'CIRCLE_2';
const FULL_CIRCLE = 'FULL_CIRCLE';
/**
* Calculations for all angle units
*
* @var array
*/
protected $_units = array(
'RADIAN' => array('1','rad'),
'MIL' => array(array('' => M_PI,'/' => '3200'), 'mil'),
'GRAD' => array(array('' => M_PI,'/' => '200'), 'gr'),
'DEGREE' => array(array('' => M_PI,'/' => '180'), '°'),
'MINUTE' => array(array('' => M_PI,'/' => '10800'), "'"),
'SECOND' => array(array('' => M_PI,'/' => '648000'), '"'),
'POINT' => array(array('' => M_PI,'/' => '16'), 'pt'),
'CIRCLE_16' => array(array('' => M_PI,'/' => '8'), 'per 16 circle'),
'CIRCLE_10' => array(array('' => M_PI,'/' => '5'), 'per 10 circle'),
'CIRCLE_8' => array(array('' => M_PI,'/' => '4'), 'per 8 circle'),
'CIRCLE_6' => array(array('' => M_PI,'/' => '3'), 'per 6 circle'),
'CIRCLE_4' => array(array('' => M_PI,'/' => '2'), 'per 4 circle'),
'CIRCLE_2' => array(M_PI, 'per 2 circle'),
'FULL_CIRCLE' => array(array('' => M_PI,'*' => '2'), 'cir'),
'STANDARD' => 'RADIAN'
);
}
Measure/Pressure.php 0000604 00000035564 15071256135 0010504 0 ustar 00 <?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_Measure
* @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: Pressure.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling pressure conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Pressure
* @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_Measure_Pressure extends Zend_Measure_Abstract
{
const STANDARD = 'NEWTON_PER_SQUARE_METER';
const ATMOSPHERE = 'ATMOSPHERE';
const ATMOSPHERE_TECHNICAL = 'ATMOSPHERE_TECHNICAL';
const ATTOBAR = 'ATTOBAR';
const ATTOPASCAL = 'ATTOPASCAL';
const BAR = 'BAR';
const BARAD = 'BARAD';
const BARYE = 'BARYE';
const CENTIBAR = 'CENTIBAR';
const CENTIHG = 'CENTIHG';
const CENTIMETER_MERCURY_0C = 'CENTIMETER_MERCURY_0C';
const CENTIMETER_WATER_4C = 'CENTIMETER_WATER_4C';
const CENTIPASCAL = 'CENTIPASCAL';
const CENTITORR = 'CENTITORR';
const DECIBAR = 'DECIBAR';
const DECIPASCAL = 'DECIPASCAL';
const DECITORR = 'DECITORR';
const DEKABAR = 'DEKABAR';
const DEKAPASCAL = 'DEKAPASCAL';
const DYNE_PER_SQUARE_CENTIMETER = 'DYNE_PER_SQUARE_CENTIMETER';
const EXABAR = 'EXABAR';
const EXAPASCAL = 'EXAPASCAL';
const FEMTOBAR = 'FEMTOBAR';
const FEMTOPASCAL = 'FEMTOPASCAL';
const FOOT_AIR_0C = 'FOOT_AIR_0C';
const FOOT_AIR_15C = 'FOOT_AIR_15C';
const FOOT_HEAD = 'FOOT_HEAD';
const FOOT_MERCURY_0C = 'FOOT_MERCURY_0C';
const FOOT_WATER_4C = 'FOOT_WATER_4C';
const GIGABAR = 'GIGABAR';
const GIGAPASCAL = 'GIGAPASCAL';
const GRAM_FORCE_SQUARE_CENTIMETER = 'GRAM_FORCE_SQUARE_CENTIMETER';
const HECTOBAR = 'HECTOBAR';
const HECTOPASCAL = 'HECTOPASCAL';
const INCH_AIR_0C = 'INCH_AIR_0C';
const INCH_AIR_15C = 'INCH_AIR_15C';
const INCH_MERCURY_0C = 'INCH_MERCURY_0C';
const INCH_WATER_4C = 'INCH_WATER_4C';
const KILOBAR = 'KILOBAR';
const KILOGRAM_FORCE_PER_SQUARE_CENTIMETER = 'KILOGRAM_FORCE_PER_SQUARE_CENTIMETER';
const KILOGRAM_FORCE_PER_SQUARE_METER = 'KILOGRAM_FORCE_PER_SQUARE_METER';
const KILOGRAM_FORCE_PER_SQUARE_MILLIMETER = 'KILOGRAM_FORCE_PER_SQUARE_MILLIMETER';
const KILONEWTON_PER_SQUARE_METER = 'KILONEWTON_PER_SQUARE_METER';
const KILOPASCAL = 'KILOPASCAL';
const KILOPOND_PER_SQUARE_CENTIMETER = 'KILOPOND_PER_SQUARE_CENTIMETER';
const KILOPOND_PER_SQUARE_METER = 'KILOPOND_PER_SQUARE_METER';
const KILOPOND_PER_SQUARE_MILLIMETER = 'KILOPOND_PER_SQUARE_MILLIMETER';
const KIP_PER_SQUARE_FOOT = 'KIP_PER_SQUARE_FOOT';
const KIP_PER_SQUARE_INCH = 'KIP_PER_SQUARE_INCH';
const MEGABAR = 'MEGABAR';
const MEGANEWTON_PER_SQUARE_METER = 'MEGANEWTON_PER_SQUARE_METER';
const MEGAPASCAL = 'MEGAPASCAL';
const METER_AIR_0C = 'METER_AIR_0C';
const METER_AIR_15C = 'METER_AIR_15C';
const METER_HEAD = 'METER_HEAD';
const MICROBAR = 'MICROBAR';
const MICROMETER_MERCURY_0C = 'MICROMETER_MERCURY_0C';
const MICROMETER_WATER_4C = 'MICROMETER_WATER_4C';
const MICRON_MERCURY_0C = 'MICRON_MERCURY_0C';
const MICROPASCAL = 'MICROPASCAL';
const MILLIBAR = 'MILLIBAR';
const MILLIHG = 'MILLIHG';
const MILLIMETER_MERCURY_0C = 'MILLIMETER_MERCURY_0C';
const MILLIMETER_WATER_4C = 'MILLIMETER_WATER_4C';
const MILLIPASCAL = 'MILLIPASCAL';
const MILLITORR = 'MILLITORR';
const NANOBAR = 'NANOBAR';
const NANOPASCAL = 'NANOPASCAL';
const NEWTON_PER_SQUARE_METER = 'NEWTON_PER_SQUARE_METER';
const NEWTON_PER_SQUARE_MILLIMETER = 'NEWTON_PER_SQUARE_MILLIMETER';
const OUNCE_PER_SQUARE_INCH = 'OUNCE_PER_SQUARE_INCH';
const PASCAL = 'PASCAL';
const PETABAR = 'PETABAR';
const PETAPASCAL = 'PETAPASCAL';
const PICOBAR = 'PICOBAR';
const PICOPASCAL = 'PICOPASCAL';
const PIEZE = 'PIEZE';
const POUND_PER_SQUARE_FOOT = 'POUND_PER_SQUARE_FOOT';
const POUND_PER_SQUARE_INCH = 'POUND_PER_SQUARE_INCH';
const POUNDAL_PER_SQUARE_FOOT = 'POUNDAL_PER_SQUARE_FOOT';
const STHENE_PER_SQUARE_METER = 'STHENE_PER_SQUARE_METER';
const TECHNICAL_ATMOSPHERE = 'TECHNICAL_ATMOSPHERE';
const TERABAR = 'TERABAR';
const TERAPASCAL = 'TERAPASCAL';
const TON_PER_SQUARE_FOOT = 'TON_PER_SQUARE_FOOT';
const TON_PER_SQUARE_FOOT_SHORT = 'TON_PER_SQUARE_FOOT_SHORT';
const TON_PER_SQUARE_INCH = 'TON_PER_SQUARE_INCH';
const TON_PER_SQUARE_INCH_SHORT = 'TON_PER_SQUARE_INCH_SHORT';
const TON_PER_SQUARE_METER = 'TON_PER_SQUARE_METER';
const TORR = 'TORR';
const WATER_COLUMN_CENTIMETER = 'WATER_COLUMN_CENTIMETER';
const WATER_COLUMN_INCH = 'WATER_COLUMN_INCH';
const WATER_COLUMN_MILLIMETER = 'WATER_COLUMN_MILLIMETER';
const YOCTOBAR = 'YOCTOBAR';
const YOCTOPASCAL = 'YOCTOPASCAL';
const YOTTABAR = 'YOTTABAR';
const YOTTAPASCAL = 'YOTTAPASCAL';
const ZEPTOBAR = 'ZEPTOBAR';
const ZEPTOPASCAL = 'ZEPTOPASCAL';
const ZETTABAR = 'ZETTABAR';
const ZETTAPASCAL = 'ZETTAPASCAL';
/**
* Calculations for all pressure units
*
* @var array
*/
protected $_units = array(
'ATMOSPHERE' => array('101325.01', 'atm'),
'ATMOSPHERE_TECHNICAL' => array('98066.5', 'atm'),
'ATTOBAR' => array('1.0e-13', 'ab'),
'ATTOPASCAL' => array('1.0e-18', 'aPa'),
'BAR' => array('100000', 'b'),
'BARAD' => array('0.1', 'barad'),
'BARYE' => array('0.1', 'ba'),
'CENTIBAR' => array('1000', 'cb'),
'CENTIHG' => array('1333.2239', 'cHg'),
'CENTIMETER_MERCURY_0C' => array('1333.2239', 'cm mercury (0°C)'),
'CENTIMETER_WATER_4C' => array('98.0665', 'cm water (4°C)'),
'CENTIPASCAL' => array('0.01', 'cPa'),
'CENTITORR' => array('1.3332237', 'cTorr'),
'DECIBAR' => array('10000', 'db'),
'DECIPASCAL' => array('0.1', 'dPa'),
'DECITORR' => array('13.332237', 'dTorr'),
'DEKABAR' => array('1000000', 'dab'),
'DEKAPASCAL' => array('10', 'daPa'),
'DYNE_PER_SQUARE_CENTIMETER' => array('0.1', 'dyn/cm²'),
'EXABAR' => array('1.0e+23', 'Eb'),
'EXAPASCAL' => array('1.0e+18', 'EPa'),
'FEMTOBAR' => array('1.0e-10', 'fb'),
'FEMTOPASCAL' => array('1.0e-15', 'fPa'),
'FOOT_AIR_0C' => array('3.8640888', 'ft air (0°C)'),
'FOOT_AIR_15C' => array('3.6622931', 'ft air (15°C)'),
'FOOT_HEAD' => array('2989.0669', 'ft head'),
'FOOT_MERCURY_0C' => array('40636.664', 'ft mercury (0°C)'),
'FOOT_WATER_4C' => array('2989.0669', 'ft water (4°C)'),
'GIGABAR' => array('1.0e+14', 'Gb'),
'GIGAPASCAL' => array('1.0e+9', 'GPa'),
'GRAM_FORCE_SQUARE_CENTIMETER' => array('98.0665', 'gf'),
'HECTOBAR' => array('1.0e+7', 'hb'),
'HECTOPASCAL' => array('100', 'hPa'),
'INCH_AIR_0C' => array(array('' => '3.8640888', '/' => '12'), 'in air (0°C)'),
'INCH_AIR_15C' => array(array('' => '3.6622931', '/' => '12'), 'in air (15°C)'),
'INCH_MERCURY_0C' => array(array('' => '40636.664', '/' => '12'), 'in mercury (0°C)'),
'INCH_WATER_4C' => array(array('' => '2989.0669', '/' => '12'), 'in water (4°C)'),
'KILOBAR' => array('1.0e+8', 'kb'),
'KILOGRAM_FORCE_PER_SQUARE_CENTIMETER' => array('98066.5', 'kgf/cm²'),
'KILOGRAM_FORCE_PER_SQUARE_METER' => array('9.80665', 'kgf/m²'),
'KILOGRAM_FORCE_PER_SQUARE_MILLIMETER' => array('9806650', 'kgf/mm²'),
'KILONEWTON_PER_SQUARE_METER' => array('1000', 'kN/m²'),
'KILOPASCAL' => array('1000', 'kPa'),
'KILOPOND_PER_SQUARE_CENTIMETER' => array('98066.5', 'kp/cm²'),
'KILOPOND_PER_SQUARE_METER' => array('9.80665', 'kp/m²'),
'KILOPOND_PER_SQUARE_MILLIMETER' => array('9806650', 'kp/mm²'),
'KIP_PER_SQUARE_FOOT' => array(array('' => '430.92233', '/' => '0.009'), 'kip/ft²'),
'KIP_PER_SQUARE_INCH' => array(array('' => '62052.81552', '/' => '0.009'), 'kip/in²'),
'MEGABAR' => array('1.0e+11', 'Mb'),
'MEGANEWTON_PER_SQUARE_METER' => array('1000000', 'MN/m²'),
'MEGAPASCAL' => array('1000000', 'MPa'),
'METER_AIR_0C' => array('12.677457', 'm air (0°C)'),
'METER_AIR_15C' => array('12.015397', 'm air (15°C)'),
'METER_HEAD' => array('9804.139432', 'm head'),
'MICROBAR' => array('0.1', 'µb'),
'MICROMETER_MERCURY_0C' => array('0.13332239', 'µm mercury (0°C)'),
'MICROMETER_WATER_4C' => array('0.00980665', 'µm water (4°C)'),
'MICRON_MERCURY_0C' => array('0.13332239', 'µ mercury (0°C)'),
'MICROPASCAL' => array('0.000001', 'µPa'),
'MILLIBAR' => array('100', 'mb'),
'MILLIHG' => array('133.32239', 'mHg'),
'MILLIMETER_MERCURY_0C' => array('133.32239', 'mm mercury (0°C)'),
'MILLIMETER_WATER_4C' => array('9.80665', 'mm water (0°C)'),
'MILLIPASCAL' => array('0.001', 'mPa'),
'MILLITORR' => array('0.13332237', 'mTorr'),
'NANOBAR' => array('0.0001', 'nb'),
'NANOPASCAL' => array('1.0e-9', 'nPa'),
'NEWTON_PER_SQUARE_METER' => array('1', 'N/m²'),
'NEWTON_PER_SQUARE_MILLIMETER' => array('1000000', 'N/mm²'),
'OUNCE_PER_SQUARE_INCH' => array('430.92233', 'oz/in²'),
'PASCAL' => array('1', 'Pa'),
'PETABAR' => array('1.0e+20', 'Pb'),
'PETAPASCAL' => array('1.0e+15', 'PPa'),
'PICOBAR' => array('0.0000001', 'pb'),
'PICOPASCAL' => array('1.0e-12', 'pPa'),
'PIEZE' => array('1000', 'pz'),
'POUND_PER_SQUARE_FOOT' => array(array('' => '430.92233', '/' => '9'), 'lb/ft²'),
'POUND_PER_SQUARE_INCH' => array('6894.75728', 'lb/in²'),
'POUNDAL_PER_SQUARE_FOOT' => array('1.4881639', 'pdl/ft²'),
'STHENE_PER_SQUARE_METER' => array('1000', 'sn/m²'),
'TECHNICAL_ATMOSPHERE' => array('98066.5', 'at'),
'TERABAR' => array('1.0e+17', 'Tb'),
'TERAPASCAL' => array('1.0e+12', 'TPa'),
'TON_PER_SQUARE_FOOT' => array(array('' => '120658.2524', '/' => '1.125'), 't/ft²'),
'TON_PER_SQUARE_FOOT_SHORT' => array(array('' => '430.92233', '/' => '0.0045'), 't/ft²'),
'TON_PER_SQUARE_INCH' => array(array('' => '17374788.3456', '/' => '1.125'), 't/in²'),
'TON_PER_SQUARE_INCH_SHORT' => array(array('' => '62052.81552', '/' => '0.0045'), 't/in²'),
'TON_PER_SQUARE_METER' => array('9806.65', 't/m²'),
'TORR' => array('133.32237', 'Torr'),
'WATER_COLUMN_CENTIMETER' => array('98.0665', 'WC (cm)'),
'WATER_COLUMN_INCH' => array(array('' => '2989.0669', '/' => '12'), 'WC (in)'),
'WATER_COLUMN_MILLIMETER' => array('9.80665', 'WC (mm)'),
'YOCTOBAR' => array('1.0e-19', 'yb'),
'YOCTOPASCAL' => array('1.0e-24', 'yPa'),
'YOTTABAR' => array('1.0e+29', 'Yb'),
'YOTTAPASCAL' => array('1.0e+24', 'YPa'),
'ZEPTOBAR' => array('1.0e-16', 'zb'),
'ZEPTOPASCAL' => array('1.0e-21', 'zPa'),
'ZETTABAR' => array('1.0e+26', 'Zb'),
'ZETTAPASCAL' => array('1.0e+21', 'ZPa'),
'STANDARD' => 'NEWTON_PER_SQUARE_METER'
);
}
Measure/Cooking/Volume.php 0000604 00000022702 15071256135 0011522 0 ustar 00 <?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_Measure
* @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: Volume.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling cooking volume conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Cooking_Volume
* @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_Measure_Cooking_Volume extends Zend_Measure_Abstract
{
const STANDARD = 'CUBIC_METER';
const CAN_2POINT5 = 'CAN_2POINT5';
const CAN_10 = 'CAN_10';
const BARREL_WINE = 'BARREL_WINE';
const BARREL = 'BARREL';
const BARREL_US_DRY = 'BARREL_US_DRY';
const BARREL_US_FEDERAL = 'BARREL_US_FEDERAL';
const BARREL_US = 'BARREL_US';
const BUCKET = 'BUCKET';
const BUCKET_US = 'BUCKET_US';
const BUSHEL = 'BUSHEL';
const BUSHEL_US = 'BUSHEL_US';
const CENTILITER = 'CENTILITER';
const COFFEE_SPOON = 'COFFEE_SPOON';
const CUBIC_CENTIMETER = 'CUBIC_CENTIMETER';
const CUBIC_DECIMETER = 'CUBIC_DECIMETER';
const CUBIC_FOOT = 'CUBIC_FOOT';
const CUBIC_INCH = 'CUBIC_INCH';
const CUBIC_METER = 'CUBIC_METER';
const CUBIC_MICROMETER = 'CUBIC_MICROMETER';
const CUBIC_MILLIMETER = 'CUBIC_MILLIMETER';
const CUP_CANADA = 'CUP_CANADA';
const CUP = 'CUP';
const CUP_US = 'CUP_US';
const DASH = 'DASH';
const DECILITER = 'DECILITER';
const DEKALITER = 'DEKALITER';
const DEMI = 'DEMI';
const DRAM = 'DRAM';
const DROP = 'DROP';
const FIFTH = 'FIFTH';
const GALLON = 'GALLON';
const GALLON_US_DRY = 'GALLON_US_DRY';
const GALLON_US = 'GALLON_US';
const GILL = 'GILL';
const GILL_US = 'GILL_US';
const HECTOLITER = 'HECTOLITER';
const HOGSHEAD = 'HOGSHEAD';
const HOGSHEAD_US = 'HOGSHEAD_US';
const JIGGER = 'JIGGER';
const KILOLITER = 'KILOLITER';
const LITER = 'LITER';
const MEASURE = 'MEASURE';
const MEGALITER = 'MEGALITER';
const MICROLITER = 'MICROLITER';
const MILLILITER = 'MILLILITER';
const MINIM = 'MINIM';
const MINIM_US = 'MINIM_US';
const OUNCE = 'OUNCE';
const OUNCE_US = 'OUNCE_US';
const PECK = 'PECK';
const PECK_US = 'PECK_US';
const PINCH = 'PINCH';
const PINT = 'PINT';
const PINT_US_DRY = 'PINT_US_DRY';
const PINT_US = 'PINT_US';
const PIPE = 'PIPE';
const PIPE_US = 'PIPE_US';
const PONY = 'PONY';
const QUART_GERMANY = 'QUART_GERMANY';
const QUART_ANCIENT = 'QUART_ANCIENT';
const QUART = 'QUART';
const QUART_US_DRY = 'QUART_US_DRY';
const QUART_US = 'QUART_US';
const SHOT = 'SHOT';
const TABLESPOON = 'TABLESPOON';
const TABLESPOON_UK = 'TABLESPOON_UK';
const TABLESPOON_US = 'TABLESPOON_US';
const TEASPOON = 'TEASPOON';
const TEASPOON_UK = 'TEASPOON_UK';
const TEASPOON_US = 'TEASPOON_US';
/**
* Calculations for all cooking volume units
*
* @var array
*/
protected $_units = array(
'CAN_2POINT5' => array(array('' => '0.0037854118', '/' => '16', '' => '3.5'), '2.5th can'),
'CAN_10' => array(array('' => '0.0037854118', '*' => '0.75'), '10th can'),
'BARREL_WINE' => array('0.143201835', 'bbl'),
'BARREL' => array('0.16365924', 'bbl'),
'BARREL_US_DRY' => array(array('' => '26.7098656608', '/' => '231'), 'bbl'),
'BARREL_US_FEDERAL' => array('0.1173477658', 'bbl'),
'BARREL_US' => array('0.1192404717', 'bbl'),
'BUCKET' => array('0.01818436', 'bucket'),
'BUCKET_US' => array('0.018927059', 'bucket'),
'BUSHEL' => array('0.03636872', 'bu'),
'BUSHEL_US' => array('0.03523907', 'bu'),
'CENTILITER' => array('0.00001', 'cl'),
'COFFEE_SPOON' => array(array('' => '0.0037854118', '/' => '1536'), 'coffee spoon'),
'CUBIC_CENTIMETER' => array('0.000001', 'cm³'),
'CUBIC_DECIMETER' => array('0.001', 'dm³'),
'CUBIC_FOOT' => array(array('' => '6.54119159', '/' => '231'), 'ft³'),
'CUBIC_INCH' => array(array('' => '0.0037854118', '/' => '231'), 'in³'),
'CUBIC_METER' => array('1', 'm³'),
'CUBIC_MICROMETER' => array('1.0e-18', 'µm³'),
'CUBIC_MILLIMETER' => array('1.0e-9', 'mm³'),
'CUP_CANADA' => array('0.0002273045', 'c'),
'CUP' => array('0.00025', 'c'),
'CUP_US' => array(array('' => '0.0037854118', '/' => '16'), 'c'),
'DASH' => array(array('' => '0.0037854118', '/' => '6144'), 'ds'),
'DECILITER' => array('0.0001', 'dl'),
'DEKALITER' => array('0.001', 'dal'),
'DEMI' => array('0.00025', 'demi'),
'DRAM' => array(array('' => '0.0037854118', '/' => '1024'), 'dr'),
'DROP' => array(array('' => '0.0037854118', '/' => '73728'), 'ggt'),
'FIFTH' => array('0.00075708236', 'fifth'),
'GALLON' => array('0.00454609', 'gal'),
'GALLON_US_DRY' => array('0.0044048838', 'gal'),
'GALLON_US' => array('0.0037854118', 'gal'),
'GILL' => array(array('' => '0.00454609', '/' => '32'), 'gi'),
'GILL_US' => array(array('' => '0.0037854118', '/' => '32'), 'gi'),
'HECTOLITER' => array('0.1', 'hl'),
'HOGSHEAD' => array('0.28640367', 'hhd'),
'HOGSHEAD_US' => array('0.2384809434', 'hhd'),
'JIGGER' => array(array('' => '0.0037854118', '/' => '128', '*' => '1.5'), 'jigger'),
'KILOLITER' => array('1', 'kl'),
'LITER' => array('0.001', 'l'),
'MEASURE' => array('0.0077', 'measure'),
'MEGALITER' => array('1000', 'Ml'),
'MICROLITER' => array('1.0e-9', 'µl'),
'MILLILITER' => array('0.000001', 'ml'),
'MINIM' => array(array('' => '0.00454609', '/' => '76800'), 'min'),
'MINIM_US' => array(array('' => '0.0037854118','/' => '61440'), 'min'),
'OUNCE' => array(array('' => '0.00454609', '/' => '160'), 'oz'),
'OUNCE_US' => array(array('' => '0.0037854118', '/' => '128'), 'oz'),
'PECK' => array('0.00909218', 'pk'),
'PECK_US' => array('0.0088097676', 'pk'),
'PINCH' => array(array('' => '0.0037854118', '/' => '12288'), 'pinch'),
'PINT' => array(array('' => '0.00454609', '/' => '8'), 'pt'),
'PINT_US_DRY' => array(array('' => '0.0044048838', '/' => '8'), 'pt'),
'PINT_US' => array(array('' => '0.0037854118', '/' => '8'), 'pt'),
'PIPE' => array('0.49097772', 'pipe'),
'PIPE_US' => array('0.4769618868', 'pipe'),
'PONY' => array(array('' => '0.0037854118', '/' => '128'), 'pony'),
'QUART_GERMANY' => array('0.00114504', 'qt'),
'QUART_ANCIENT' => array('0.00108', 'qt'),
'QUART' => array(array('' => '0.00454609', '/' => '4'), 'qt'),
'QUART_US_DRY' => array(array('' => '0.0044048838', '/' => '4'), 'qt'),
'QUART_US' => array(array('' => '0.0037854118', '/' => '4'), 'qt'),
'SHOT' => array(array('' => '0.0037854118', '/' => '128'), 'shot'),
'TABLESPOON' => array('0.000015', 'tbsp'),
'TABLESPOON_UK' => array(array('' => '0.00454609', '/' => '320'), 'tbsp'),
'TABLESPOON_US' => array(array('' => '0.0037854118', '/' => '256'), 'tbsp'),
'TEASPOON' => array('0.000005', 'tsp'),
'TEASPOON_UK' => array(array('' => '0.00454609', '/' => '1280'), 'tsp'),
'TEASPOON_US' => array(array('' => '0.0037854118', '/' => '768'), 'tsp'),
'STANDARD' => 'CUBIC_METER'
);
}
Measure/Cooking/Weight.php 0000604 00000005414 15071256135 0011503 0 ustar 00 <?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_Measure
* @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: Weight.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling cooking weight conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Cooking_Weight
* @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_Measure_Cooking_Weight extends Zend_Measure_Abstract
{
const STANDARD = 'GRAM';
const HALF_STICK = 'HALF_STICK';
const STICK = 'STICK';
const CUP = 'CUP';
const GRAM = 'GRAM';
const OUNCE = 'OUNCE';
const POUND = 'POUND';
const TEASPOON = 'TEASPOON';
const TEASPOON_US = 'TEASPOON_US';
const TABLESPOON = 'TABLESPOON';
const TABLESPOON_US = 'TABLESPOON_US';
/**
* Calculations for all cooking weight units
*
* @var array
*/
protected $_units = array(
'HALF_STICK' => array(array('' => '453.59237', '/' => '8'), 'half stk'),
'STICK' => array(array('' => '453.59237', '/' => '4'), 'stk'),
'CUP' => array(array('' => '453.59237', '/' => '2'), 'c'),
'GRAM' => array('1', 'g'),
'OUNCE' => array(array('' => '453.59237', '/' => '16'), 'oz'),
'POUND' => array('453.59237', 'lb'),
'TEASPOON' => array(array('' => '1.2503332', '' => '453.59237', '/' => '128'), 'tsp'),
'TEASPOON_US' => array(array('' => '453.59237', '/' => '96'), 'tsp'),
'TABLESPOON' => array(array('' => '1.2503332', '' => '453.59237', '/' => '32'), 'tbsp'),
'TABLESPOON_US' => array(array('' => '453.59237', '/' => '32'), 'tbsp'),
'STANDARD' => 'GRAM'
);
}
Measure/Volume.php 0000604 00000025621 15071256135 0010134 0 ustar 00 <?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_Measure
* @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: Volume.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling acceleration conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Volume
* @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_Measure_Volume extends Zend_Measure_Abstract
{
const STANDARD = 'CUBIC_METER';
const ACRE_FOOT = 'ACRE_FOOT';
const ACRE_FOOT_SURVEY = 'ACRE_FOOT_SURVEY';
const ACRE_INCH = 'ACRE_INCH';
const BARREL_WINE = 'BARREL_WINE';
const BARREL = 'BARREL';
const BARREL_US_DRY = 'BARREL_US_DRY';
const BARREL_US_FEDERAL = 'BARREL_US_FEDERAL';
const BARREL_US = 'BARREL_US';
const BARREL_US_PETROLEUM = 'BARREL_US_PETROLEUM';
const BOARD_FOOT = 'BOARD_FOOT';
const BUCKET = 'BUCKET';
const BUCKET_US = 'BUCKET_US';
const BUSHEL = 'BUSHEL';
const BUSHEL_US = 'BUSHEL_US';
const CENTILTER = 'CENTILITER';
const CORD = 'CORD';
const CORD_FOOT = 'CORD_FOOT';
const CUBIC_CENTIMETER = 'CUBIC_CENTIMETER';
const CUBIC_CUBIT = 'CUBIC_CUBIT';
const CUBIC_DECIMETER = 'CUBIC_DECIMETER';
const CUBIC_DEKAMETER = 'CUBIC_DEKAMETER';
const CUBIC_FOOT = 'CUBIC_FOOT';
const CUBIC_INCH = 'CUBIC_INCH';
const CUBIC_KILOMETER = 'CUBIC_KILOMETER';
const CUBIC_METER = 'CUBIC_METER';
const CUBIC_MILE = 'CUBIC_MILE';
const CUBIC_MICROMETER = 'CUBIC_MICROMETER';
const CUBIC_MILLIMETER = 'CUBIC_MILLIMETER';
const CUBIC_YARD = 'CUBIC_YARD';
const CUP_CANADA = 'CUP_CANADA';
const CUP = 'CUP';
const CUP_US = 'CUP_US';
const DECILITER = 'DECILITER';
const DEKALITER = 'DEKALITER';
const DRAM = 'DRAM';
const DRUM_US = 'DRUM_US';
const DRUM = 'DRUM';
const FIFTH = 'FIFTH';
const GALLON = 'GALLON';
const GALLON_US_DRY = 'GALLON_US_DRY';
const GALLON_US = 'GALLON_US';
const GILL = 'GILL';
const GILL_US = 'GILL_US';
const HECTARE_METER = 'HECTARE_METER';
const HECTOLITER = 'HECTOLITER';
const HOGSHEAD = 'HOGSHEAD';
const HOGSHEAD_US = 'HOGSHEAD_US';
const JIGGER = 'JIGGER';
const KILOLITER = 'KILOLITER';
const LITER = 'LITER';
const MEASURE = 'MEASURE';
const MEGALITER = 'MEGALITER';
const MICROLITER = 'MICROLITER';
const MILLILITER = 'MILLILITER';
const MINIM = 'MINIM';
const MINIM_US = 'MINIM_US';
const OUNCE = 'OUNCE';
const OUNCE_US = 'OUNCE_US';
const PECK = 'PECK';
const PECK_US = 'PECK_US';
const PINT = 'PINT';
const PINT_US_DRY = 'PINT_US_DRY';
const PINT_US = 'PINT_US';
const PIPE = 'PIPE';
const PIPE_US = 'PIPE_US';
const PONY = 'PONY';
const QUART_GERMANY = 'QUART_GERMANY';
const QUART_ANCIENT = 'QUART_ANCIENT';
const QUART = 'QUART';
const QUART_US_DRY = 'QUART_US_DRY';
const QUART_US = 'QUART_US';
const QUART_UK = 'QUART_UK';
const SHOT = 'SHOT';
const STERE = 'STERE';
const TABLESPOON = 'TABLESPOON';
const TABLESPOON_UK = 'TABLESPOON_UK';
const TABLESPOON_US = 'TABLESPOON_US';
const TEASPOON = 'TEASPOON';
const TEASPOON_UK = 'TEASPOON_UK';
const TEASPOON_US = 'TEASPOON_US';
const YARD = 'YARD';
/**
* Calculations for all volume units
*
* @var array
*/
protected $_units = array(
'ACRE_FOOT' => array('1233.48185532', 'ac ft'),
'ACRE_FOOT_SURVEY' => array('1233.489', 'ac ft'),
'ACRE_INCH' => array('102.79015461', 'ac in'),
'BARREL_WINE' => array('0.143201835', 'bbl'),
'BARREL' => array('0.16365924', 'bbl'),
'BARREL_US_DRY' => array(array('' => '26.7098656608', '/' => '231'), 'bbl'),
'BARREL_US_FEDERAL' => array('0.1173477658', 'bbl'),
'BARREL_US' => array('0.1192404717', 'bbl'),
'BARREL_US_PETROLEUM' => array('0.1589872956', 'bbl'),
'BOARD_FOOT' => array(array('' => '6.5411915904', '/' => '2772'), 'board foot'),
'BUCKET' => array('0.01818436', 'bucket'),
'BUCKET_US' => array('0.018927059', 'bucket'),
'BUSHEL' => array('0.03636872', 'bu'),
'BUSHEL_US' => array('0.03523907', 'bu'),
'CENTILITER' => array('0.00001', 'cl'),
'CORD' => array('3.624556416', 'cd'),
'CORD_FOOT' => array('0.453069552', 'cd ft'),
'CUBIC_CENTIMETER' => array('0.000001', 'cm³'),
'CUBIC_CUBIT' => array('0.144', 'cubit³'),
'CUBIC_DECIMETER' => array('0.001', 'dm³'),
'CUBIC_DEKAMETER' => array('1000', 'dam³'),
'CUBIC_FOOT' => array(array('' => '6.54119159', '/' => '231'), 'ft³'),
'CUBIC_INCH' => array(array('' => '0.0037854118', '/' => '231'), 'in³'),
'CUBIC_KILOMETER' => array('1.0e+9', 'km³'),
'CUBIC_METER' => array('1', 'm³'),
'CUBIC_MILE' => array(array('' => '0.0037854118', '/' => '231', '*' => '75271680', '*' => '3379200'),
'mi³'),
'CUBIC_MICROMETER' => array('1.0e-18', 'µm³'),
'CUBIC_MILLIMETER' => array('1.0e-9', 'mm³'),
'CUBIC_YARD' => array(array('' => '0.0037854118', '/' => '231', '*' => '46656'), 'yd³'),
'CUP_CANADA' => array('0.0002273045', 'c'),
'CUP' => array('0.00025', 'c'),
'CUP_US' => array(array('' => '0.0037854118', '/' => '16'), 'c'),
'DECILITER' => array('0.0001', 'dl'),
'DEKALITER' => array('0.001', 'dal'),
'DRAM' => array(array('' => '0.0037854118', '/' => '1024'), 'dr'),
'DRUM_US' => array('0.208197649', 'drum'),
'DRUM' => array('0.2', 'drum'),
'FIFTH' => array('0.00075708236', 'fifth'),
'GALLON' => array('0.00454609', 'gal'),
'GALLON_US_DRY' => array('0.0044048838', 'gal'),
'GALLON_US' => array('0.0037854118', 'gal'),
'GILL' => array(array('' => '0.00454609', '/' => '32'), 'gi'),
'GILL_US' => array(array('' => '0.0037854118', '/' => '32'), 'gi'),
'HECTARE_METER' => array('10000', 'ha m'),
'HECTOLITER' => array('0.1', 'hl'),
'HOGSHEAD' => array('0.28640367', 'hhd'),
'HOGSHEAD_US' => array('0.2384809434', 'hhd'),
'JIGGER' => array(array('' => '0.0037854118', '/' => '128', '*' => '1.5'), 'jigger'),
'KILOLITER' => array('1', 'kl'),
'LITER' => array('0.001', 'l'),
'MEASURE' => array('0.0077', 'measure'),
'MEGALITER' => array('1000', 'Ml'),
'MICROLITER' => array('1.0e-9', 'µl'),
'MILLILITER' => array('0.000001', 'ml'),
'MINIM' => array(array('' => '0.00454609', '/' => '76800'), 'min'),
'MINIM_US' => array(array('' => '0.0037854118','/' => '61440'), 'min'),
'OUNCE' => array(array('' => '0.00454609', '/' => '160'), 'oz'),
'OUNCE_US' => array(array('' => '0.0037854118', '/' => '128'), 'oz'),
'PECK' => array('0.00909218', 'pk'),
'PECK_US' => array('0.0088097676', 'pk'),
'PINT' => array(array('' => '0.00454609', '/' => '8'), 'pt'),
'PINT_US_DRY' => array(array('' => '0.0044048838', '/' => '8'), 'pt'),
'PINT_US' => array(array('' => '0.0037854118', '/' => '8'), 'pt'),
'PIPE' => array('0.49097772', 'pipe'),
'PIPE_US' => array('0.4769618868', 'pipe'),
'PONY' => array(array('' => '0.0037854118', '/' => '128'), 'pony'),
'QUART_GERMANY' => array('0.00114504', 'qt'),
'QUART_ANCIENT' => array('0.00108', 'qt'),
'QUART' => array(array('' => '0.00454609', '/' => '4'), 'qt'),
'QUART_US_DRY' => array(array('' => '0.0044048838', '/' => '4'), 'qt'),
'QUART_US' => array(array('' => '0.0037854118', '/' => '4'), 'qt'),
'QUART_UK' => array('0.29094976', 'qt'),
'SHOT' => array(array('' => '0.0037854118', '/' => '128'), 'shot'),
'STERE' => array('1', 'st'),
'TABLESPOON' => array('0.000015', 'tbsp'),
'TABLESPOON_UK' => array(array('' => '0.00454609', '/' => '320'), 'tbsp'),
'TABLESPOON_US' => array(array('' => '0.0037854118', '/' => '256'), 'tbsp'),
'TEASPOON' => array('0.000005', 'tsp'),
'TEASPOON_UK' => array(array('' => '0.00454609', '/' => '1280'), 'tsp'),
'TEASPOON_US' => array(array('' => '0.0037854118', '/' => '768'), 'tsp'),
'YARD' => array(array('' => '176.6121729408', '/' => '231'), 'yd'),
'STANDARD' => 'CUBIC_METER'
);
}
Measure/Torque.php 0000604 00000006565 15071256135 0010152 0 ustar 00 <?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_Measure
* @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: Torque.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling torque conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Torque
* @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_Measure_Torque extends Zend_Measure_Abstract
{
const STANDARD = 'NEWTON_METER';
const DYNE_CENTIMETER = 'DYNE_CENTIMETER';
const GRAM_CENTIMETER = 'GRAM_CENTIMETER';
const KILOGRAM_CENTIMETER = 'KILOGRAM_CENTIMETER';
const KILOGRAM_METER = 'KILOGRAM_METER';
const KILONEWTON_METER = 'KILONEWTON_METER';
const KILOPOND_METER = 'KILOPOND_METER';
const MEGANEWTON_METER = 'MEGANEWTON_METER';
const MICRONEWTON_METER = 'MICRONEWTON_METER';
const MILLINEWTON_METER = 'MILLINEWTON_METER';
const NEWTON_CENTIMETER = 'NEWTON_CENTIMETER';
const NEWTON_METER = 'NEWTON_METER';
const OUNCE_FOOT = 'OUNCE_FOOT';
const OUNCE_INCH = 'OUNCE_INCH';
const POUND_FOOT = 'POUND_FOOT';
const POUNDAL_FOOT = 'POUNDAL_FOOT';
const POUND_INCH = 'POUND_INCH';
/**
* Calculations for all torque units
*
* @var array
*/
protected $_units = array(
'DYNE_CENTIMETER' => array('0.0000001', 'dyncm'),
'GRAM_CENTIMETER' => array('0.0000980665', 'gcm'),
'KILOGRAM_CENTIMETER' => array('0.0980665', 'kgcm'),
'KILOGRAM_METER' => array('9.80665', 'kgm'),
'KILONEWTON_METER' => array('1000', 'kNm'),
'KILOPOND_METER' => array('9.80665', 'kpm'),
'MEGANEWTON_METER' => array('1000000', 'MNm'),
'MICRONEWTON_METER' => array('0.000001', 'µNm'),
'MILLINEWTON_METER' => array('0.001', 'mNm'),
'NEWTON_CENTIMETER' => array('0.01', 'Ncm'),
'NEWTON_METER' => array('1', 'Nm'),
'OUNCE_FOOT' => array('0.084738622', 'ozft'),
'OUNCE_INCH' => array(array('' => '0.084738622', '/' => '12'), 'ozin'),
'POUND_FOOT' => array(array('' => '0.084738622', '*' => '16'), 'lbft'),
'POUNDAL_FOOT' => array('0.0421401099752144', 'plft'),
'POUND_INCH' => array(array('' => '0.084738622', '/' => '12', '*' => '16'), 'lbin'),
'STANDARD' => 'NEWTON_METER'
);
}
Measure/Acceleration.php 0000604 00000010272 15071256135 0011252 0 ustar 00 <?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_Measure
* @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: Acceleration.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling acceleration conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Acceleration
* @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_Measure_Acceleration extends Zend_Measure_Abstract
{
const STANDARD = 'METER_PER_SQUARE_SECOND';
const CENTIGAL = 'CENTIGAL';
const CENTIMETER_PER_SQUARE_SECOND = 'CENTIMETER_PER_SQUARE_SECOND';
const DECIGAL = 'DECIGAL';
const DECIMETER_PER_SQUARE_SECOND = 'DECIMETER_PER_SQUARE_SECOND';
const DEKAMETER_PER_SQUARE_SECOND = 'DEKAMETER_PER_SQUARE_SECOND';
const FOOT_PER_SQUARE_SECOND = 'FOOT_PER_SQUARE_SECOND';
const G = 'G';
const GAL = 'GAL';
const GALILEO = 'GALILEO';
const GRAV = 'GRAV';
const HECTOMETER_PER_SQUARE_SECOND = 'HECTOMETER_PER_SQUARE_SECOND';
const INCH_PER_SQUARE_SECOND = 'INCH_PER_SQUARE_SECOND';
const KILOMETER_PER_HOUR_SECOND = 'KILOMETER_PER_HOUR_SECOND';
const KILOMETER_PER_SQUARE_SECOND = 'KILOMETER_PER_SQUARE_SECOND';
const METER_PER_SQUARE_SECOND = 'METER_PER_SQUARE_SECOND';
const MILE_PER_HOUR_MINUTE = 'MILE_PER_HOUR_MINUTE';
const MILE_PER_HOUR_SECOND = 'MILE_PER_HOUR_SECOND';
const MILE_PER_SQUARE_SECOND = 'MILE_PER_SQUARE_SECOND';
const MILLIGAL = 'MILLIGAL';
const MILLIMETER_PER_SQUARE_SECOND = 'MILLIMETER_PER_SQUARE_SECOND';
/**
* Calculations for all acceleration units
*
* @var array
*/
protected $_units = array(
'CENTIGAL' => array('0.0001', 'cgal'),
'CENTIMETER_PER_SQUARE_SECOND' => array('0.01', 'cm/s²'),
'DECIGAL' => array('0.001', 'dgal'),
'DECIMETER_PER_SQUARE_SECOND' => array('0.1', 'dm/s²'),
'DEKAMETER_PER_SQUARE_SECOND' => array('10', 'dam/s²'),
'FOOT_PER_SQUARE_SECOND' => array('0.3048', 'ft/s²'),
'G' => array('9.80665', 'g'),
'GAL' => array('0.01', 'gal'),
'GALILEO' => array('0.01', 'gal'),
'GRAV' => array('9.80665', 'g'),
'HECTOMETER_PER_SQUARE_SECOND' => array('100', 'h/s²'),
'INCH_PER_SQUARE_SECOND' => array('0.0254', 'in/s²'),
'KILOMETER_PER_HOUR_SECOND' => array(array('' => '5','/' => '18'), 'km/h²'),
'KILOMETER_PER_SQUARE_SECOND' => array('1000', 'km/s²'),
'METER_PER_SQUARE_SECOND' => array('1', 'm/s²'),
'MILE_PER_HOUR_MINUTE' => array(array('' => '22', '/' => '15', '*' => '0.3048', '/' => '60'), 'mph/m'),
'MILE_PER_HOUR_SECOND' => array(array('' => '22', '/' => '15', '*' => '0.3048'), 'mph/s'),
'MILE_PER_SQUARE_SECOND' => array('1609.344', 'mi/s²'),
'MILLIGAL' => array('0.00001', 'mgal'),
'MILLIMETER_PER_SQUARE_SECOND' => array('0.001', 'mm/s²'),
'STANDARD' => 'METER_PER_SQUARE_SECOND'
);
}
Measure/Temperature.php 0000604 00000003726 15071256135 0011164 0 ustar 00 <?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_Measure
* @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: Temperature.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling temperature conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Temperature
* @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_Measure_Temperature extends Zend_Measure_Abstract
{
const STANDARD = 'KELVIN';
const CELSIUS = 'CELSIUS';
const FAHRENHEIT = 'FAHRENHEIT';
const RANKINE = 'RANKINE';
const REAUMUR = 'REAUMUR';
const KELVIN = 'KELVIN';
/**
* Calculations for all temperature units
*
* @var array
*/
protected $_units = array(
'CELSIUS' => array(array('' => '1', '+' => '273.15'),'°C'),
'FAHRENHEIT' => array(array('' => '1', '-' => '32', '/' => '1.8', '+' => '273.15'),'°F'),
'RANKINE' => array(array('' => '1', '/' => '1.8'),'°R'),
'REAUMUR' => array(array('' => '1', '*' => '1.25', '+' => '273.15'),'°r'),
'KELVIN' => array(1,'°K'),
'STANDARD' => 'KELVIN'
);
}
Measure/Abstract.php 0000604 00000025226 15071256135 0010431 0 ustar 00 <?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_Measure
* @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: Abstract.php 12060 2008-10-21 17:23:55Z thomas $
*/
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
/**
* @see Zend_Locale_Math
*/
require_once 'Zend/Locale/Math.php';
/**
* @see Zend_Locale_Format
*/
require_once 'Zend/Locale/Format.php';
/**
* Abstract class for all measurements
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Abstract
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Measure_Abstract
{
/**
* Plain value in standard unit
*
* @var string $_value
*/
protected $_value;
/**
* Original type for this unit
*
* @var string $_type
*/
protected $_type;
/**
* Locale identifier
*
* @var string $_locale
*/
protected $_locale = null;
/**
* Unit types for this measurement
*/
protected $_units = array();
/**
* Zend_Measure_Abstract is an abstract class for the different measurement types
*
* @param $value mixed - Value as string, integer, real or float
* @param $type type - OPTIONAL a Zend_Measure_Area Type
* @param $locale locale - OPTIONAL a Zend_Locale Type
* @throws Zend_Measure_Exception
*/
public function __construct($value, $type = null, $locale = null)
{
if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
$locale = $type;
$type = null;
}
if (empty($locale)) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale') === true) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
if ($locale === null) {
$locale = new Zend_Locale();
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
}
$locale = new Zend_Locale($locale);
}
$this->_locale = (string) $locale;
if ($type === null) {
$type = $this->_units['STANDARD'];
}
if (isset($this->_units[$type]) === false) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ($type) is unknown");
}
$this->setValue($value, $type, $this->_locale);
}
/**
* Returns the internal value
*
* @param integer $round (Optional) Rounds the value to an given precision,
* Default is 2, -1 returns without rounding
*/
public function getValue($round = 2)
{
if ($round < 0) {
return $this->_value;
}
return Zend_Locale_Math::round($this->_value, $round);
}
/**
* Set a new value
*
* @param integer|string $value Value as string, integer, real or float
* @param string $type OPTIONAL A Zend_Measure_Acceleration Type
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing numbers
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type = null, $locale = null)
{
if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
$locale = $type;
$type = null;
}
if ($locale === null) {
$locale = $this->_locale;
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if ($type === null) {
$type = $this->_units['STANDARD'];
}
if (empty($this->_units[$type])) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ($type) is unknown");
}
try {
$value = Zend_Locale_Format::getNumber($value, array('locale' => $locale));
} catch(Exception $e) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception($e->getMessage());
}
$this->_value = $value;
$this->setType($type);
}
/**
* Returns the original type
*
* @return type
*/
public function getType()
{
return $this->_type;
}
/**
* Set a new type, and convert the value
*
* @param string $type New type to set
* @throws Zend_Measure_Exception
*/
public function setType($type)
{
if (empty($this->_units[$type])) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ($type) is unknown");
}
if (empty($this->_type)) {
$this->_type = $type;
} else {
// Convert to standard value
$value = $this->getValue(-1);
if (is_array($this->_units[$this->getType()][0])) {
foreach ($this->_units[$this->getType()][0] as $key => $found) {
switch ($key) {
case "/":
if ($found != 0) {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
default:
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
}
}
} else {
$value = call_user_func(Zend_Locale_Math::$mul, $value, $this->_units[$this->getType()][0], 25);
}
// Convert to expected value
if (is_array($this->_units[$type][0])) {
foreach (array_reverse($this->_units[$type][0]) as $key => $found) {
switch ($key) {
case "/":
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
default:
if ($found != 0) {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
}
}
} else {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $this->_units[$type][0], 25);
}
$this->_value = $value;
$this->_type = $type;
}
}
/**
* Compare if the value and type is equal
*
* @param Zend_Measure_Detailtype $object object to compare
* @return boolean
*/
public function equals($object)
{
if ((string) $object == $this->toString()) {
return true;
}
return false;
}
/**
* Returns a string representation
*
* @param integer $round OPTIONAL rounds the value to an given exception
* @return string
*/
public function toString($round = -1)
{
return $this->getValue($round) . ' ' . $this->_units[$this->getType()][1];
}
/**
* Returns a string representation
*
* @return string
*/
public function __toString()
{
return $this->toString();
}
/**
* Returns the conversion list
*
* @return array
*/
public function getConversionList()
{
return $this->_units;
}
/**
* Alias function for setType returning the converted unit
*
* @param $type type
* @param $round integer OPTIONAL rounds the value to a given precision
* @return string
*/
public function convertTo($type, $round = 2)
{
$this->setType($type);
return $this->toString($round);
}
/**
* Adds an unit to another one
*
* @param $object object of same unit type
* @return Zend_Measure object
*/
public function add($object)
{
$object->setType($this->getType());
$value = $this->getValue(-1) + $object->getValue(-1);
$this->setValue($value, $this->getType(), $this->_locale);
return $this;
}
/**
* Substracts an unit from another one
*
* @param $object object of same unit type
* @return Zend_Measure object
*/
public function sub($object)
{
$object->setType($this->getType());
$value = $this->getValue(-1) - $object->getValue(-1);
$this->setValue($value, $this->getType(), $this->_locale);
return $this;
}
/**
* Compares two units
*
* @param $object object of same unit type
* @return boolean
*/
public function compare($object)
{
$object->setType($this->getType());
$value = $this->getValue(-1) - $object->getValue(-1);
if ($value < 0) {
return -1;
} else if ($value > 0) {
return 1;
}
return 0;
}
}
Measure/Length.php 0000604 00000106575 15071256135 0010116 0 ustar 00 <?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_Measure
* @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: Length.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling length conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Length
* @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_Measure_Length extends Zend_Measure_Abstract
{
const STANDARD = 'METER';
const AGATE = 'AGATE';
const ALEN_DANISH = 'ALEN_DANISH';
const ALEN = 'ALEN';
const ALEN_SWEDISH = 'ALEN_SWEDISH';
const ANGSTROM = 'ANGSTROM';
const ARMS = 'ARMS';
const ARPENT_CANADIAN = 'ARPENT_CANADIAN';
const ARPENT = 'ARPENT';
const ARSHEEN = 'ARSHEEN';
const ARSHIN = 'ARSHIN';
const ARSHIN_IRAQ = 'ARSHIN_IRAQ';
const ASTRONOMICAL_UNIT = 'ASTRONOMICAL_UNIT';
const ATTOMETER = 'ATTOMETER';
const BAMBOO = 'BAMBOO';
const BARLEYCORN = 'BARLEYCORN';
const BEE_SPACE = 'BEE_SPACE';
const BICRON = 'BICRON';
const BLOCK_US_EAST = 'BLOCK_US_EAST';
const BLOCK_US_WEST = 'BLOCK_US_WEST';
const BLOCK_US_SOUTH = 'BLOCK_US_SOUTH';
const BOHR = 'BOHR';
const BRACCIO = 'BRACCIO';
const BRAZA_ARGENTINA = 'BRAZA_ARGENTINA';
const BRAZA = 'BRAZA';
const BRAZA_US = 'BRAZA_US';
const BUTTON = 'BUTTON';
const CABLE_US = 'CABLE_US';
const CABLE_UK = 'CABLE_UK';
const CALIBER = 'CALIBER';
const CANA = 'CANA';
const CAPE_FOOT = 'CAPE_FOOT';
const CAPE_INCH = 'CAPE_INCH';
const CAPE_ROOD = 'CAPE_ROOD';
const CENTIMETER = 'CENTIMETER';
const CHAIN = 'CHAIN';
const CHAIN_ENGINEER = 'CHAIN_ENGINEER';
const CHIH = 'CHIH';
const CHINESE_FOOT = 'CHINESE_FOOT';
const CHINESE_INCH = 'CHINESE_INCH';
const CHINESE_MILE = 'CHINESE_MILE';
const CHINESE_YARD = 'CHINESE_YARD';
const CITY_BLOCK_US_EAST = 'CITY_BLOCK_US_EAST';
const CITY_BLOCK_US_WEST = 'CITY_BLOCK_US_WEST';
const CITY_BLOCK_US_SOUTH = 'CITY_BLOCK_US_SOUTH';
const CLICK = 'CLICK';
const CUADRA = 'CUADRA';
const CUADRA_ARGENTINA = 'CUADRA_ARGENTINA';
const CUBIT_EGYPT = 'Length:CUBIT_EGYPT';
const CUBIT_ROYAL = 'CUBIT_ROYAL';
const CUBIT_UK = 'CUBIT_UK';
const CUBIT = 'CUBIT';
const CUERDA = 'CUERDA';
const DECIMETER = 'DECIMETER';
const DEKAMETER = 'DEKAMETER';
const DIDOT_POINT = 'DIDOT_POINT';
const DIGIT = 'DIGIT';
const DIRAA = 'DIRAA';
const DONG = 'DONG';
const DOUZIEME_WATCH = 'DOUZIEME_WATCH';
const DOUZIEME = 'DOUZIEME';
const DRA_IRAQ = 'DRA_IRAQ';
const DRA = 'DRA';
const EL = 'EL';
const ELL = 'ELL';
const ELL_SCOTTISH = 'ELL_SCOTTISH';
const ELLE = 'ELLE';
const ELLE_VIENNA = 'ELLE_VIENNA';
const EM = 'EM';
const ESTADIO_PORTUGAL = 'ESTADIO_PORTUGAL';
const ESTADIO = 'ESTADIO';
const EXAMETER = 'EXAMETER';
const FADEN_AUSTRIA = 'FADEN_AUSTRIA';
const FADEN = 'FADEN';
const FALL = 'FALL';
const FALL_SCOTTISH = 'FALL_SCOTTISH';
const FATHOM = 'FATHOM';
const FATHOM_ANCIENT = 'FATHOM_ANCIENT';
const FAUST = 'FAUST';
const FEET_OLD_CANADIAN = 'FEET_OLD_CANADIAN';
const FEET_EGYPT = 'FEET_EGYPT';
const FEET_FRANCE = 'FEET_FRANCE';
const FEET = 'FEET';
const FEET_IRAQ = 'FEET_IRAQ';
const FEET_NETHERLAND = 'FEET_NETHERLAND';
const FEET_ITALIC = 'FEET_ITALIC';
const FEET_SURVEY = 'FEET_SURVEY';
const FEMTOMETER = 'FEMTOMETER';
const FERMI = 'FERMI';
const FINGER = 'FINGER';
const FINGERBREADTH = 'FINGERBREADTH';
const FIST = 'FIST';
const FOD = 'FOD';
const FOOT_EGYPT = 'FOOT_EGYPT';
const FOOT_FRANCE = 'FOOT_FRANCE';
const FOOT = 'FOOT';
const FOOT_IRAQ = 'FOOT_IRAQ';
const FOOT_NETHERLAND = 'FOOT_NETHERLAND';
const FOOT_ITALIC = 'FOOT_ITALIC';
const FOOT_SURVEY = 'FOOT_SURVEY';
const FOOTBALL_FIELD_CANADA = 'FOOTBALL_FIELD_CANADA';
const FOOTBALL_FIELD_US = 'FOOTBALL_FIELD_US';
const FOOTBALL_FIELD = 'FOOTBALL_FIELD';
const FURLONG = 'FURLONG';
const FURLONG_SURVEY = 'FURLONG_SURVEY';
const FUSS = 'FUSS';
const GIGAMETER = 'GIGAMETER';
const GIGAPARSEC = 'GIGAPARSEC';
const GNATS_EYE = 'GNATS_EYE';
const GOAD = 'GOAD';
const GRY = 'GRY';
const HAIRS_BREADTH = 'HAIRS_BREADTH';
const HAND = 'HAND';
const HANDBREADTH = 'HANDBREADTH';
const HAT = 'HAT';
const HECTOMETER = 'HECTOMETER';
const HEER = 'HEER';
const HIRO = 'HIRO';
const HUBBLE = 'HUBBLE';
const HVAT = 'HVAT';
const INCH = 'INCH';
const IRON = 'IRON';
const KEN = 'KEN';
const KERAT = 'KERAT';
const KILOFOOT = 'KILOFOOT';
const KILOMETER = 'KILOMETER';
const KILOPARSEC = 'KILOPARSEC';
const KILOYARD = 'KILOYARD';
const KIND = 'KIND';
const KLAFTER = 'KLAFTER';
const KLAFTER_SWISS = 'KLAFTER_SWISS';
const KLICK = 'KLICK';
const KYU = 'KYU';
const LAP_ANCIENT = 'LAP_ANCIENT';
const LAP = 'LAP';
const LAP_POOL = 'LAP_POOL';
const LEAGUE_ANCIENT = 'LEAGUE_ANCIENT';
const LEAGUE_NAUTIC = 'LEAGUE_NAUTIC';
const LEAGUE_UK_NAUTIC = 'LEAGUE_UK_NAUTIC';
const LEAGUE = 'LEAGUE';
const LEAGUE_US = 'LEAGUE_US';
const LEAP = 'LEAP';
const LEGOA = 'LEGOA';
const LEGUA = 'LEGUA';
const LEGUA_US = 'LEGUA_US';
const LEGUA_SPAIN_OLD = 'LEGUA_SPAIN_OLD';
const LEGUA_SPAIN = 'LEGUA_SPAIN';
const LI_ANCIENT = 'LI_ANCIENT';
const LI_IMPERIAL = 'LI_IMPERIAL';
const LI = 'LI';
const LIEUE = 'LIEUE';
const LIEUE_METRIC = 'LIEUE_METRIC';
const LIEUE_NAUTIC = 'LIEUE_NAUTIC';
const LIGHT_SECOND = 'LIGHT_SECOND';
const LIGHT_MINUTE = 'LIGHT_MINUTE';
const LIGHT_HOUR = 'LIGHT_HOUR';
const LIGHT_DAY = 'LIGHT_DAY';
const LIGHT_YEAR = 'LIGHT_YEAR';
const LIGNE = 'LIGNE';
const LIGNE_SWISS = 'LIGNE_SWISS';
const LINE = 'LINE';
const LINE_SMALL = 'LINE_SMALL';
const LINK = 'LINK';
const LINK_ENGINEER = 'LINK_ENGINEER';
const LUG = 'LUG';
const LUG_GREAT = 'LUG_GREAT';
const MARATHON = 'MARATHON';
const MARK_TWAIN = 'MARK_TWAIN';
const MEGAMETER = 'MEGAMETER';
const MEGAPARSEC = 'MEGAPARSEC';
const MEILE_AUSTRIAN = 'MEILE_AUSTRIAN';
const MEILE = 'MEILE';
const MEILE_GERMAN = 'MEILE_GERMAN';
const METER = 'METER';
const METRE = 'METRE';
const METRIC_MILE = 'METRIC_MILE';
const METRIC_MILE_US = 'METRIC_MILE_US';
const MICROINCH = 'MICROINCH';
const MICROMETER = 'MICROMETER';
const MICROMICRON = 'MICROMICRON';
const MICRON = 'MICRON';
const MIGLIO = 'MIGLIO';
const MIIL = 'MIIL';
const MIIL_DENMARK = 'MIIL_DENMARK';
const MIIL_SWEDISH = 'MIIL_SWEDISH';
const MIL = 'MIL';
const MIL_SWEDISH = 'MIL_SWEDISH';
const MILE_UK = 'MILE_UK';
const MILE_IRISH = 'MILE_IRISH';
const MILE = 'MILE';
const MILE_NAUTIC = 'MILE_NAUTIC';
const MILE_NAUTIC_UK = 'MILE_NAUTIC_UK';
const MILE_NAUTIC_US = 'MILE_NAUTIC_US';
const MILE_ANCIENT = 'MILE_ANCIENT';
const MILE_SCOTTISH = 'MILE_SCOTTISH';
const MILE_STATUTE = 'MILE_STATUTE';
const MILE_US = 'MILE_US';
const MILHA = 'MILHA';
const MILITARY_PACE = 'MILITARY_PACE';
const MILITARY_PACE_DOUBLE = 'MILITARY_PACE_DOUBLE';
const MILLA = 'MILLA';
const MILLE = 'MILLE';
const MILLIARE = 'MILLIARE';
const MILLIMETER = 'MILLIMETER';
const MILLIMICRON = 'MILLIMICRON';
const MKONO = 'MKONO';
const MOOT = 'MOOT';
const MYRIAMETER = 'MYRIAMETER';
const NAIL = 'NAIL';
const NANOMETER = 'NANOMETER';
const NANON = 'NANON';
const PACE = 'PACE';
const PACE_ROMAN = 'PACE_ROMAN';
const PALM_DUTCH = 'PALM_DUTCH';
const PALM_UK = 'PALM_UK';
const PALM = 'PALM';
const PALMO_PORTUGUESE = 'PALMO_PORTUGUESE';
const PALMO = 'PALMO';
const PALMO_US = 'PALMO_US';
const PARASANG = 'PARASANG';
const PARIS_FOOT = 'PARIS_FOOT';
const PARSEC = 'PARSEC';
const PE = 'PE';
const PEARL = 'PEARL';
const PERCH = 'PERCH';
const PERCH_IRELAND = 'PERCH_IRELAND';
const PERTICA = 'PERTICA';
const PES = 'PES';
const PETAMETER = 'PETAMETER';
const PICA = 'PICA';
const PICOMETER = 'PICOMETER';
const PIE_ARGENTINA = 'PIE_ARGENTINA';
const PIE_ITALIC = 'PIE_ITALIC';
const PIE = 'PIE';
const PIE_US = 'PIE_US';
const PIED_DE_ROI = 'PIED_DE_ROI';
const PIK = 'PIK';
const PIKE = 'PIKE';
const POINT_ADOBE = 'POINT_ADOBE';
const POINT = 'POINT';
const POINT_DIDOT = 'POINT_DIDOT';
const POINT_TEX = 'POINT_TEX';
const POLE = 'POLE';
const POLEGADA = 'POLEGADA';
const POUCE = 'POUCE';
const PU = 'PU';
const PULGADA = 'PULGADA';
const PYGME = 'PYGME';
const Q = 'Q';
const QUADRANT = 'QUADRANT';
const QUARTER = 'QUARTER';
const QUARTER_CLOTH = 'QUARTER_CLOTH';
const QUARTER_PRINT = 'QUARTER_PRINT';
const RANGE = 'RANGE';
const REED = 'REED';
const RI = 'RI';
const RIDGE = 'RIDGE';
const RIVER = 'RIVER';
const ROD = 'ROD';
const ROD_SURVEY = 'ROD_SURVEY';
const ROEDE = 'ROEDE';
const ROOD = 'ROOD';
const ROPE = 'ROPE';
const ROYAL_FOOT = 'ROYAL_FOOT';
const RUTE = 'RUTE';
const SADZHEN = 'SADZHEN';
const SAGENE = 'SAGENE';
const SCOTS_FOOT = 'SCOTS_FOOT';
const SCOTS_MILE = 'SCOTS_MILE';
const SEEMEILE = 'SEEMEILE';
const SHACKLE = 'SHACKLE';
const SHAFTMENT = 'SHAFTMENT';
const SHAFTMENT_ANCIENT = 'SHAFTMENT_ANCIENT';
const SHAKU = 'SHAKU';
const SIRIOMETER = 'SIRIOMETER';
const SMOOT = 'SMOOT';
const SPAN = 'SPAN';
const SPAT = 'SPAT';
const STADIUM = 'STADIUM';
const STEP = 'STEP';
const STICK = 'STICK';
const STORY = 'STORY';
const STRIDE = 'STRIDE';
const STRIDE_ROMAN = 'STRIDE_ROMAN';
const TENTHMETER = 'TENTHMETER';
const TERAMETER = 'TERAMETER';
const THOU = 'THOU';
const TOISE = 'TOISE';
const TOWNSHIP = 'TOWNSHIP';
const T_SUN = 'T_SUN';
const TU = 'TU';
const TWAIN = 'TWAIN';
const TWIP = 'TWIP';
const U = 'U';
const VARA_CALIFORNIA = 'VARA_CALIFORNIA';
const VARA_MEXICAN = 'VARA_MEXICAN';
const VARA_PORTUGUESE = 'VARA_PORTUGUESE';
const VARA_AMERICA = 'VARA_AMERICA';
const VARA = 'VARA';
const VARA_TEXAS = 'VARA_TEXAS';
const VERGE = 'VERGE';
const VERSHOK = 'VERSHOK';
const VERST = 'VERST';
const WAH = 'WAH';
const WERST = 'WERST';
const X_UNIT = 'X_UNIT';
const YARD = 'YARD';
const YOCTOMETER = 'YOCTOMETER';
const YOTTAMETER = 'YOTTAMETER';
const ZEPTOMETER = 'ZEPTOMETER';
const ZETTAMETER = 'ZETTAMETER';
const ZOLL = 'ZOLL';
const ZOLL_SWISS = 'ZOLL_SWISS';
/**
* Calculations for all length units
*
* @var array
*/
protected $_units = array(
'AGATE' => array(array('' => '0.0254', '/' => '72'), 'agate'),
'ALEN_DANISH' => array('0.6277', 'alen'),
'ALEN' => array('0.6', 'alen'),
'ALEN_SWEDISH' => array('0.5938', 'alen'),
'ANGSTROM' => array('1.0e-10', 'Å'),
'ARMS' => array('0.7', 'arms'),
'ARPENT_CANADIAN' => array('58.47', 'arpent'),
'ARPENT' => array('58.471308', 'arpent'),
'ARSHEEN' => array('0.7112', 'arsheen'),
'ARSHIN' => array('1.04', 'arshin'),
'ARSHIN_IRAQ' => array('74.5', 'arshin'),
'ASTRONOMICAL_UNIT' => array('149597870691', 'AU'),
'ATTOMETER' => array('1.0e-18', 'am'),
'BAMBOO' => array('3.2', 'bamboo'),
'BARLEYCORN' => array('0.0085', 'barleycorn'),
'BEE_SPACE' => array('0.0065', 'bee space'),
'BICRON' => array('1.0e-12', '��'),
'BLOCK_US_EAST' => array('80.4672', 'block'),
'BLOCK_US_WEST' => array('100.584', 'block'),
'BLOCK_US_SOUTH' => array('160.9344', 'block'),
'BOHR' => array('52.918e-12', 'a�'),
'BRACCIO' => array('0.7', 'braccio'),
'BRAZA_ARGENTINA' => array('1.733', 'braza'),
'BRAZA' => array('1.67', 'braza'),
'BRAZA_US' => array('1.693', 'braza'),
'BUTTON' => array('0.000635', 'button'),
'CABLE_US' => array('219.456', 'cable'),
'CABLE_UK' => array('185.3184', 'cable'),
'CALIBER' => array('0.0254', 'cal'),
'CANA' => array('2', 'cana'),
'CAPE_FOOT' => array('0.314858', 'cf'),
'CAPE_INCH' => array(array('' => '0.314858','/' => '12'), 'ci'),
'CAPE_ROOD' => array('3.778296', 'cr'),
'CENTIMETER' => array('0.01', 'cm'),
'CHAIN' => array(array('' => '79200','/' => '3937'), 'ch'),
'CHAIN_ENGINEER' => array('30.48', 'ch'),
'CHIH' => array('0.35814', "ch'ih"),
'CHINESE_FOOT' => array('0.371475', 'ft'),
'CHINESE_INCH' => array('0.0371475', 'in'),
'CHINESE_MILE' => array('557.21', 'mi'),
'CHINESE_YARD' => array('0.89154', 'yd'),
'CITY_BLOCK_US_EAST' => array('80.4672', 'block'),
'CITY_BLOCK_US_WEST' => array('100.584', 'block'),
'CITY_BLOCK_US_SOUTH' => array('160.9344', 'block'),
'CLICK' => array('1000', 'click'),
'CUADRA' => array('84', 'cuadra'),
'CUADRA_ARGENTINA'=> array('130', 'cuadra'),
'Length:CUBIT_EGYPT' => array('0.45', 'cubit'),
'CUBIT_ROYAL' => array('0.5235', 'cubit'),
'CUBIT_UK' => array('0.4572', 'cubit'),
'CUBIT' => array('0.444', 'cubit'),
'CUERDA' => array('21', 'cda'),
'DECIMETER' => array('0.1', 'dm'),
'DEKAMETER' => array('10', 'dam'),
'DIDOT_POINT' => array('0.000377', 'didot point'),
'DIGIT' => array('0.019', 'digit'),
'DIRAA' => array('0.58', ''),
'DONG' => array(array('' => '7','/' => '300'), 'dong'),
'DOUZIEME_WATCH' => array('0.000188', 'douzi�me'),
'DOUZIEME' => array('0.00017638888889', 'douzi�me'),
'DRA_IRAQ' => array('0.745', 'dra'),
'DRA' => array('0.7112', 'dra'),
'EL' => array('0.69', 'el'),
'ELL' => array('1.143', 'ell'),
'ELL_SCOTTISH' => array('0.945', 'ell'),
'ELLE' => array('0.6', 'ellen'),
'ELLE_VIENNA' => array('0.7793', 'ellen'),
'EM' => array('0.0042175176', 'em'),
'ESTADIO_PORTUGAL'=> array('261', 'estadio'),
'ESTADIO' => array('174', 'estadio'),
'EXAMETER' => array('1.0e+18', 'Em'),
'FADEN_AUSTRIA' => array('1.8965', 'faden'),
'FADEN' => array('1.8', 'faden'),
'FALL' => array('6.858', 'fall'),
'FALL_SCOTTISH' => array('5.67', 'fall'),
'FATHOM' => array('1.8288', 'fth'),
'FATHOM_ANCIENT' => array('1.829', 'fth'),
'FAUST' => array('0.10536', 'faust'),
'FEET_OLD_CANADIAN' => array('0.325', 'ft'),
'FEET_EGYPT' => array('0.36', 'ft'),
'FEET_FRANCE' => array('0.3248406', 'ft'),
'FEET' => array('0.3048', 'ft'),
'FEET_IRAQ' => array('0.316', 'ft'),
'FEET_NETHERLAND' => array('0.28313', 'ft'),
'FEET_ITALIC' => array('0.296', 'ft'),
'FEET_SURVEY' => array(array('' => '1200', '/' => '3937'), 'ft'),
'FEMTOMETER' => array('1.0e-15', 'fm'),
'FERMI' => array('1.0e-15', 'f'),
'FINGER' => array('0.1143', 'finger'),
'FINGERBREADTH' => array('0.01905', 'fingerbreadth'),
'FIST' => array('0.1', 'fist'),
'FOD' => array('0.3141', 'fod'),
'FOOT_EGYPT' => array('0.36', 'ft'),
'FOOT_FRANCE' => array('0.3248406', 'ft'),
'FOOT' => array('0.3048', 'ft'),
'FOOT_IRAQ' => array('0.316', 'ft'),
'FOOT_NETHERLAND' => array('0.28313', 'ft'),
'FOOT_ITALIC' => array('0.296', 'ft'),
'FOOT_SURVEY' => array(array('' => '1200', '/' => '3937'), 'ft'),
'FOOTBALL_FIELD_CANADA' => array('100.584', 'football field'),
'FOOTBALL_FIELD_US' => array('91.44', 'football field'),
'FOOTBALL_FIELD' => array('109.728', 'football field'),
'FURLONG' => array('201.168', 'fur'),
'FURLONG_SURVEY' => array(array('' => '792000', '/' => '3937'), 'fur'),
'FUSS' => array('0.31608', 'fuss'),
'GIGAMETER' => array('1.0e+9', 'Gm'),
'GIGAPARSEC' => array('30.85678e+24', 'Gpc'),
'GNATS_EYE' => array('0.000125', "gnat's eye"),
'GOAD' => array('1.3716', 'goad'),
'GRY' => array('0.000211667', 'gry'),
'HAIRS_BREADTH' => array('0.0001', "hair's breadth"),
'HAND' => array('0.1016', 'hand'),
'HANDBREADTH' => array('0.08', "hand's breadth"),
'HAT' => array('0.5', 'hat'),
'HECTOMETER' => array('100', 'hm'),
'HEER' => array('73.152', 'heer'),
'HIRO' => array('1.818', 'hiro'),
'HUBBLE' => array('9.4605e+24', 'hubble'),
'HVAT' => array('1.8965', 'hvat'),
'INCH' => array('0.0254', 'in'),
'IRON' => array(array('' => '0.0254', '/' => '48'), 'iron'),
'KEN' => array('1.818', 'ken'),
'KERAT' => array('0.0286', 'kerat'),
'KILOFOOT' => array('304.8', 'kft'),
'KILOMETER' => array('1000', 'km'),
'KILOPARSEC' => array('3.0856776e+19', 'kpc'),
'KILOYARD' => array('914.4', 'kyd'),
'KIND' => array('0.5', 'kind'),
'KLAFTER' => array('1.8965', 'klafter'),
'KLAFTER_SWISS' => array('1.8', 'klafter'),
'KLICK' => array('1000', 'klick'),
'KYU' => array('0.00025', 'kyu'),
'LAP_ANCIENT' => array('402.336', ''),
'LAP' => array('400', 'lap'),
'LAP_POOL' => array('100', 'lap'),
'LEAGUE_ANCIENT' => array('2275', 'league'),
'LEAGUE_NAUTIC' => array('5556', 'league'),
'LEAGUE_UK_NAUTIC'=> array('5559.552', 'league'),
'LEAGUE' => array('4828', 'league'),
'LEAGUE_US' => array('4828.0417', 'league'),
'LEAP' => array('2.0574', 'leap'),
'LEGOA' => array('6174.1', 'legoa'),
'LEGUA' => array('4200', 'legua'),
'LEGUA_US' => array('4233.4', 'legua'),
'LEGUA_SPAIN_OLD' => array('4179.4', 'legua'),
'LEGUA_SPAIN' => array('6680', 'legua'),
'LI_ANCIENT' => array('500', 'li'),
'LI_IMPERIAL' => array('644.65', 'li'),
'LI' => array('500', 'li'),
'LIEUE' => array('3898', 'lieue'),
'LIEUE_METRIC' => array('4000', 'lieue'),
'LIEUE_NAUTIC' => array('5556', 'lieue'),
'LIGHT_SECOND' => array('299792458', 'light second'),
'LIGHT_MINUTE' => array('17987547480', 'light minute'),
'LIGHT_HOUR' => array('1079252848800', 'light hour'),
'LIGHT_DAY' => array('25902068371200', 'light day'),
'LIGHT_YEAR' => array('9460528404879000', 'ly'),
'LIGNE' => array('0.0021167', 'ligne'),
'LIGNE_SWISS' => array('0.002256', 'ligne'),
'LINE' => array('0.0021167', 'li'),
'LINE_SMALL' => array('0.000635', 'li'),
'LINK' => array(array('' => '792','/' => '3937'), 'link'),
'LINK_ENGINEER' => array('0.3048', 'link'),
'LUG' => array('5.0292', 'lug'),
'LUG_GREAT' => array('6.4008', 'lug'),
'MARATHON' => array('42194.988', 'marathon'),
'MARK_TWAIN' => array('3.6576074', 'mark twain'),
'MEGAMETER' => array('1000000', 'Mm'),
'MEGAPARSEC' => array('3.085677e+22', 'Mpc'),
'MEILE_AUSTRIAN' => array('7586', 'meile'),
'MEILE' => array('7412.7', 'meile'),
'MEILE_GERMAN' => array('7532.5', 'meile'),
'METER' => array('1', 'm'),
'METRE' => array('1', 'm'),
'METRIC_MILE' => array('1500', 'metric mile'),
'METRIC_MILE_US' => array('1600', 'metric mile'),
'MICROINCH' => array('2.54e-08', '�in'),
'MICROMETER' => array('0.000001', '�m'),
'MICROMICRON' => array('1.0e-12', '��'),
'MICRON' => array('0.000001', '�'),
'MIGLIO' => array('1488.6', 'miglio'),
'MIIL' => array('7500', 'miil'),
'MIIL_DENMARK' => array('7532.5', 'miil'),
'MIIL_SWEDISH' => array('10687', 'miil'),
'MIL' => array('0.0000254', 'mil'),
'MIL_SWEDISH' => array('10000', 'mil'),
'MILE_UK' => array('1609', 'mi'),
'MILE_IRISH' => array('2048', 'mi'),
'MILE' => array('1609.344', 'mi'),
'MILE_NAUTIC' => array('1852', 'mi'),
'MILE_NAUTIC_UK' => array('1853.184', 'mi'),
'MILE_NAUTIC_US' => array('1852', 'mi'),
'MILE_ANCIENT' => array('1520', 'mi'),
'MILE_SCOTTISH' => array('1814', 'mi'),
'MILE_STATUTE' => array('1609.344', 'mi'),
'MILE_US' => array(array('' => '6336000','/' => '3937'), 'mi'),
'MILHA' => array('2087.3', 'milha'),
'MILITARY_PACE' => array('0.762', 'mil. pace'),
'MILITARY_PACE_DOUBLE' => array('0.9144', 'mil. pace'),
'MILLA' => array('1392', 'milla'),
'MILLE' => array('1949', 'mille'),
'MILLIARE' => array('0.001478', 'milliare'),
'MILLIMETER' => array('0.001', 'mm'),
'MILLIMICRON' => array('1.0e-9', 'm�'),
'MKONO' => array('0.4572', 'mkono'),
'MOOT' => array('0.0762', 'moot'),
'MYRIAMETER' => array('10000', 'mym'),
'NAIL' => array('0.05715', 'nail'),
'NANOMETER' => array('1.0e-9', 'nm'),
'NANON' => array('1.0e-9', 'nanon'),
'PACE' => array('1.524', 'pace'),
'PACE_ROMAN' => array('1.48', 'pace'),
'PALM_DUTCH' => array('0.10', 'palm'),
'PALM_UK' => array('0.075', 'palm'),
'PALM' => array('0.2286', 'palm'),
'PALMO_PORTUGUESE'=> array('0.22', 'palmo'),
'PALMO' => array('0.20', 'palmo'),
'PALMO_US' => array('0.2117', 'palmo'),
'PARASANG' => array('6000', 'parasang'),
'PARIS_FOOT' => array('0.3248406', 'paris foot'),
'PARSEC' => array('3.0856776e+16', 'pc'),
'PE' => array('0.33324', 'p�'),
'PEARL' => array('0.001757299', 'pearl'),
'PERCH' => array('5.0292', 'perch'),
'PERCH_IRELAND' => array('6.4008', 'perch'),
'PERTICA' => array('2.96', 'pertica'),
'PES' => array('0.2967', 'pes'),
'PETAMETER' => array('1.0e+15', 'Pm'),
'PICA' => array('0.0042175176', 'pi'),
'PICOMETER' => array('1.0e-12', 'pm'),
'PIE_ARGENTINA' => array('0.2889', 'pie'),
'PIE_ITALIC' => array('0.298', 'pie'),
'PIE' => array('0.2786', 'pie'),
'PIE_US' => array('0.2822', 'pie'),
'PIED_DE_ROI' => array('0.3248406', 'pied de roi'),
'PIK' => array('0.71', 'pik'),
'PIKE' => array('0.71', 'pike'),
'POINT_ADOBE' => array(array('' => '0.3048', '/' => '864'), 'pt'),
'POINT' => array('0.00035', 'pt'),
'POINT_DIDOT' => array('0.000377', 'pt'),
'POINT_TEX' => array('0.0003514598035', 'pt'),
'POLE' => array('5.0292', 'pole'),
'POLEGADA' => array('0.02777', 'polegada'),
'POUCE' => array('0.02707', 'pouce'),
'PU' => array('1.7907', 'pu'),
'PULGADA' => array('0.02365', 'pulgada'),
'PYGME' => array('0.346', 'pygme'),
'Q' => array('0.00025', 'q'),
'QUADRANT' => array('10001300', 'quad'),
'QUARTER' => array('402.336', 'Q'),
'QUARTER_CLOTH' => array('0.2286', 'Q'),
'QUARTER_PRINT' => array('0.00025', 'Q'),
'RANGE' => array(array('' => '38016000','/' => '3937'), 'range'),
'REED' => array('2.679', 'reed'),
'RI' => array('3927', 'ri'),
'RIDGE' => array('6.1722', 'ridge'),
'RIVER' => array('2000', 'river'),
'ROD' => array('5.0292', 'rd'),
'ROD_SURVEY' => array(array('' => '19800', '/' => '3937'), 'rd'),
'ROEDE' => array('10', 'roede'),
'ROOD' => array('3.7783', 'rood'),
'ROPE' => array('3.7783', 'rope'),
'ROYAL_FOOT' => array('0.3248406', 'royal foot'),
'RUTE' => array('3.75', 'rute'),
'SADZHEN' => array('2.1336', 'sadzhen'),
'SAGENE' => array('2.1336', 'sagene'),
'SCOTS_FOOT' => array('0.30645', 'scots foot'),
'SCOTS_MILE' => array('1814.2', 'scots mile'),
'SEEMEILE' => array('1852', 'seemeile'),
'SHACKLE' => array('27.432', 'shackle'),
'SHAFTMENT' => array('0.15124', 'shaftment'),
'SHAFTMENT_ANCIENT' => array('0.165', 'shaftment'),
'SHAKU' => array('0.303', 'shaku'),
'SIRIOMETER' => array('1.4959787e+17', 'siriometer'),
'SMOOT' => array('1.7018', 'smoot'),
'SPAN' => array('0.2286', 'span'),
'SPAT' => array('1.0e+12', 'spat'),
'STADIUM' => array('185', 'stadium'),
'STEP' => array('0.762', 'step'),
'STICK' => array('3.048', 'stk'),
'STORY' => array('3.3', 'story'),
'STRIDE' => array('1.524', 'stride'),
'STRIDE_ROMAN' => array('1.48', 'stride'),
'TENTHMETER' => array('1.0e-10', 'tenth-meter'),
'TERAMETER' => array('1.0e+12', 'Tm'),
'THOU' => array('0.0000254', 'thou'),
'TOISE' => array('1.949', 'toise'),
'TOWNSHIP' => array(array('' => '38016000','/' => '3937'), 'twp'),
'T_SUN' => array('0.0358', "t'sun"),
'TU' => array('161130', 'tu'),
'TWAIN' => array('3.6576074', 'twain'),
'TWIP' => array('0.000017639', 'twip'),
'U' => array('0.04445', 'U'),
'VARA_CALIFORNIA' => array('0.83820168', 'vara'),
'VARA_MEXICAN' => array('0.83802', 'vara'),
'VARA_PORTUGUESE' => array('1.10', 'vara'),
'VARA_AMERICA' => array('0.864', 'vara'),
'VARA' => array('0.83587', 'vara'),
'VARA_TEXAS' => array('0.84666836', 'vara'),
'VERGE' => array('0.9144', 'verge'),
'VERSHOK' => array('0.04445', 'vershok'),
'VERST' => array('1066.8', 'verst'),
'WAH' => array('2', 'wah'),
'WERST' => array('1066.8', 'werst'),
'X_UNIT' => array('1.0020722e-13', 'Xu'),
'YARD' => array('0.9144', 'yd'),
'YOCTOMETER' => array('1.0e-24', 'ym'),
'YOTTAMETER' => array('1.0e+24', 'Ym'),
'ZEPTOMETER' => array('1.0e-21', 'zm'),
'ZETTAMETER' => array('1.0e+21', 'Zm'),
'ZOLL' => array('0.02634', 'zoll'),
'ZOLL_SWISS' => array('0.03', 'zoll'),
'STANDARD' => 'METER'
);
}
Measure/Time.php 0000604 00000011330 15071256135 0007553 0 ustar 00 <?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_Measure
* @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: $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling time conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Time
* @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_Measure_Time extends Zend_Measure_Abstract
{
const STANDARD = 'SECOND';
const ANOMALISTIC_YEAR = 'ANOMALISTIC_YEAR';
const ATTOSECOND = 'ATTOSECOND';
const CENTURY = 'CENTURY';
const DAY = 'DAY';
const DECADE = 'DECADE';
const DRACONIC_YEAR = 'DRACONTIC_YEAR';
const EXASECOND = 'EXASECOND';
const FEMTOSECOND = 'FEMTOSECOND';
const FORTNIGHT = 'FORTNIGHT';
const GAUSSIAN_YEAR = 'GAUSSIAN_YEAR';
const GIGASECOND = 'GIGASECOND';
const GREGORIAN_YEAR = 'GREGORIAN_YEAR';
const HOUR = 'HOUR';
const JULIAN_YEAR = 'JULIAN_YEAR';
const KILOSECOND = 'KILOSECOND';
const LEAPYEAR = 'LEAPYEAR';
const MEGASECOND = 'MEGASECOND';
const MICROSECOND = 'MICROSECOND';
const MILLENIUM = 'MILLENIUM';
const MILLISECOND = 'MILLISECOND';
const MINUTE = 'MINUTE';
const MONTH = 'MONTH';
const NANOSECOND = 'NANOSECOND';
const PETASECOND = 'PETASECOND';
const PICOSECOND = 'PICOSECOND';
const QUARTER = 'QUARTER';
const SECOND = 'SECOND';
const SHAKE = 'SHAKE';
const SIDEREAL_YEAR = 'SYNODIC_MONTH';
const TERASECOND = 'TERASECOND';
const TROPICAL_YEAR = 'TROPIC_YEAR';
const WEEK = 'WEEK';
const YEAR = 'YEAR';
/**
* Calculations for all time units
*
* @var array
*/
protected $_units = array(
'ANOMALISTIC_YEAR' => array('31558432', 'anomalistic year'),
'ATTOSECOND' => array('1.0e-18', 'as'),
'CENTURY' => array('3153600000', 'century'),
'DAY' => array('86400', 'day'),
'DECADE' => array('315360000', 'decade'),
'DRACONIC_YEAR' => array('29947974', 'draconic year'),
'EXASECOND' => array('1.0e+18', 'Es'),
'FEMTOSECOND' => array('1.0e-15', 'fs'),
'FORTNIGHT' => array('1209600', 'fortnight'),
'GAUSSIAN_YEAR' => array('31558196', 'gaussian year'),
'GIGASECOND' => array('1.0e+9', 'Gs'),
'GREAT_YEAR' => array(array('*' => '31536000', '*' => '25700'), 'great year'),
'GREGORIAN_YEAR' => array('31536000', 'year'),
'HOUR' => array('3600', 'h'),
'JULIAN_YEAR' => array('31557600', 'a'),
'KILOSECOND' => array('1000', 'ks'),
'LEAPYEAR' => array('31622400', 'year'),
'MEGASECOND' => array('1000000', 'Ms'),
'MICROSECOND' => array('0.000001', 'µs'),
'MILLENIUM' => array('31536000000', 'millenium'),
'MILLISECOND' => array('0.001', 'ms'),
'MINUTE' => array('60', 'min'),
'MONTH' => array('2628600', 'month'),
'NANOSECOND' => array('1.0e-9', 'ns'),
'PETASECOND' => array('1.0e+15', 'Ps'),
'PICOSECOND' => array('1.0e-12', 'ps'),
'QUARTER' => array('7884000', 'quarter'),
'SECOND' => array('1', 's'),
'SHAKE' => array('1.0e-9', 'shake'),
'SIDEREAL_YEAR' => array('31558149.7676', 'sidereal year'),
'TERASECOND' => array('1.0e+12', 'Ts'),
'TROPICAL_YEAR' => array('31556925', 'tropical year'),
'WEEK' => array('604800', 'week'),
'YEAR' => array('31536000', 'year'),
'STANDARD' => 'SECOND'
);
}
Measure/Flow/Mass.php 0000604 00000015063 15071256135 0010476 0 ustar 00 <?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_Measure
* @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: Mass.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling flow mass conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Flow_Mass
* @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_Measure_Flow_Mass extends Zend_Measure_Abstract
{
const STANDARD = 'KILOGRAM_PER_SECOND';
const CENTIGRAM_PER_DAY = 'CENTIGRAM_PER_DAY';
const CENTIGRAM_PER_HOUR = 'CENTIGRAM_PER_HOUR';
const CENTIGRAM_PER_MINUTE = 'CENTIGRAM_PER_MINUTE';
const CENTIGRAM_PER_SECOND = 'CENTIGRAM_PER_SECOND';
const GRAM_PER_DAY = 'GRAM_PER_DAY';
const GRAM_PER_HOUR = 'GRAM_PER_HOUR';
const GRAM_PER_MINUTE = 'GRAM_PER_MINUTE';
const GRAM_PER_SECOND = 'GRAM_PER_SECOND';
const KILOGRAM_PER_DAY = 'KILOGRAM_PER_DAY';
const KILOGRAM_PER_HOUR = 'KILOGRAM_PER_HOUR';
const KILOGRAM_PER_MINUTE = 'KILOGRAM_PER_MINUTE';
const KILOGRAM_PER_SECOND = 'KILOGRAM_PER_SECOND';
const MILLIGRAM_PER_DAY = 'MILLIGRAM_PER_DAY';
const MILLIGRAM_PER_HOUR = 'MILLIGRAM_PER_HOUR';
const MILLIGRAM_PER_MINUTE = 'MILLIGRAM_PER_MINUTE';
const MILLIGRAM_PER_SECOND = 'MILLIGRAM_PER_SECOND';
const OUNCE_PER_DAY = 'OUNCE_PER_DAY';
const OUNCE_PER_HOUR = 'OUNCE_PER_HOUR';
const OUNCE_PER_MINUTE = 'OUNCE_PER_MINUTE';
const OUNCE_PER_SECOND = 'OUNCE_PER_SECOND';
const POUND_PER_DAY = 'POUND_PER_DAY';
const POUND_PER_HOUR = 'POUND_PER_HOUR';
const POUND_PER_MINUTE = 'POUND_PER_MINUTE';
const POUND_PER_SECOND = 'POUND_PER_SECOND';
const TON_LONG_PER_DAY = 'TON_LONG_PER_DAY';
const TON_LONG_PER_HOUR = 'TON_LONG_PER_HOUR';
const TON_LONG_PER_MINUTE = 'TON_LONG_PER_MINUTE';
const TON_LONG_PER_SECOND = 'TON_LONG_PER_SECOND';
const TON_PER_DAY = 'TON_PER_DAY';
const TON_PER_HOUR = 'TON_PER_HOUR';
const TON_PER_MINUTE = 'TON_PER_MINUTE';
const TON_PER_SECOND = 'TON_PER_SECOND';
const TON_SHORT_PER_DAY = 'TON_SHORT_PER_DAY';
const TON_SHORT_PER_HOUR = 'TON_SHORT_PER_HOUR';
const TON_SHORT_PER_MINUTE = 'TON_SHORT_PER_MINUTE';
const TON_SHORT_PER_SECOND = 'TON_SHORT_PER_SECOND';
/**
* Calculations for all flow mass units
*
* @var array
*/
protected $_units = array(
'CENTIGRAM_PER_DAY' => array(array('' => '0.00001', '/' => '86400'), 'cg/day'),
'CENTIGRAM_PER_HOUR' => array(array('' => '0.00001', '/' => '3600'), 'cg/h'),
'CENTIGRAM_PER_MINUTE' => array(array('' => '0.00001', '/' => '60'), 'cg/m'),
'CENTIGRAM_PER_SECOND' => array('0.00001', 'cg/s'),
'GRAM_PER_DAY' => array(array('' => '0.001', '/' => '86400'), 'g/day'),
'GRAM_PER_HOUR' => array(array('' => '0.001', '/' => '3600'), 'g/h'),
'GRAM_PER_MINUTE' => array(array('' => '0.001', '/' => '60'), 'g/m'),
'GRAM_PER_SECOND' => array('0.001', 'g/s'),
'KILOGRAM_PER_DAY' => array(array('' => '1', '/' => '86400'), 'kg/day'),
'KILOGRAM_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'kg/h'),
'KILOGRAM_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'kg/m'),
'KILOGRAM_PER_SECOND' => array('1', 'kg/s'),
'MILLIGRAM_PER_DAY' => array(array('' => '0.000001', '/' => '86400'), 'mg/day'),
'MILLIGRAM_PER_HOUR' => array(array('' => '0.000001', '/' => '3600'), 'mg/h'),
'MILLIGRAM_PER_MINUTE' => array(array('' => '0.000001', '/' => '60'), 'mg/m'),
'MILLIGRAM_PER_SECOND' => array('0.000001', 'mg/s'),
'OUNCE_PER_DAY' => array(array('' => '0.0283495', '/' => '86400'), 'oz/day'),
'OUNCE_PER_HOUR' => array(array('' => '0.0283495', '/' => '3600'), 'oz/h'),
'OUNCE_PER_MINUTE' => array(array('' => '0.0283495', '/' => '60'), 'oz/m'),
'OUNCE_PER_SECOND' => array('0.0283495', 'oz/s'),
'POUND_PER_DAY' => array(array('' => '0.453592', '/' => '86400'), 'lb/day'),
'POUND_PER_HOUR' => array(array('' => '0.453592', '/' => '3600'), 'lb/h'),
'POUND_PER_MINUTE' => array(array('' => '0.453592', '/' => '60'), 'lb/m'),
'POUND_PER_SECOND' => array('0.453592', 'lb/s'),
'TON_LONG_PER_DAY' => array(array('' => '1016.04608', '/' => '86400'), 't/day'),
'TON_LONG_PER_HOUR' => array(array('' => '1016.04608', '/' => '3600'), 't/h'),
'TON_LONG_PER_MINUTE' => array(array('' => '1016.04608', '/' => '60'), 't/m'),
'TON_LONG_PER_SECOND' => array('1016.04608', 't/s'),
'TON_PER_DAY' => array(array('' => '1000', '/' => '86400'), 't/day'),
'TON_PER_HOUR' => array(array('' => '1000', '/' => '3600'), 't/h'),
'TON_PER_MINUTE' => array(array('' => '1000', '/' => '60'), 't/m'),
'TON_PER_SECOND' => array('1000', 't/s'),
'TON_SHORT_PER_DAY' => array(array('' => '907.184', '/' => '86400'), 't/day'),
'TON_SHORT_PER_HOUR' => array(array('' => '907.184', '/' => '3600'), 't/h'),
'TON_SHORT_PER_MINUTE' => array(array('' => '907.184', '/' => '60'), 't/m'),
'TON_SHORT_PER_SECOND' => array('907.184', 't/s'),
'STANDARD' => 'KILOGRAM_PER_SECOND'
);
}
Measure/Flow/Mole.php 0000604 00000010264 15071256135 0010465 0 ustar 00 <?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_Measure
* @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: Mole.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling flow mole conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Flow_Mole
* @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_Measure_Flow_Mole extends Zend_Measure_Abstract
{
const STANDARD = 'MOLE_PER_SECOND';
const CENTIMOLE_PER_DAY = 'CENTIMOLE_PER_DAY';
const CENTIMOLE_PER_HOUR = 'CENTIMOLE_PER_HOUR';
const CENTIMOLE_PER_MINUTE = 'CENTIMOLE_PER_MINUTE';
const CENTIMOLE_PER_SECOND = 'CENTIMOLE_PER_SECOND';
const MEGAMOLE_PER_DAY = 'MEGAMOLE_PER_DAY';
const MEGAMOLE_PER_HOUR = 'MEGAMOLE_PER_HOUR';
const MEGAMOLE_PER_MINUTE = 'MEGAMOLE_PER_MINUTE';
const MEGAMOLE_PER_SECOND = 'MEGAMOLE_PER_SECOND';
const MICROMOLE_PER_DAY = 'MICROMOLE_PER_DAY';
const MICROMOLE_PER_HOUR = 'MICROMOLE_PER_HOUR';
const MICROMOLE_PER_MINUTE = 'MICROMOLE_PER_MINUTE';
const MICROMOLE_PER_SECOND = 'MICROMOLE_PER_SECOND';
const MILLIMOLE_PER_DAY = 'MILLIMOLE_PER_DAY';
const MILLIMOLE_PER_HOUR = 'MILLIMOLE_PER_HOUR';
const MILLIMOLE_PER_MINUTE = 'MILLIMOLE_PER_MINUTE';
const MILLIMOLE_PER_SECOND = 'MILLIMOLE_PER_SECOND';
const MOLE_PER_DAY = 'MOLE_PER_DAY';
const MOLE_PER_HOUR = 'MOLE_PER_HOUR';
const MOLE_PER_MINUTE = 'MOLE_PER_MINUTE';
const MOLE_PER_SECOND = 'MOLE_PER_SECOND';
/**
* Calculations for all flow mole units
*
* @var array
*/
protected $_units = array(
'CENTIMOLE_PER_DAY' => array(array('' => '0.01', '/' => '86400'), 'cmol/day'),
'CENTIMOLE_PER_HOUR' => array(array('' => '0.01', '/' => '3600'), 'cmol/h'),
'CENTIMOLE_PER_MINUTE' => array(array('' => '0.01', '/' => '60'), 'cmol/m'),
'CENTIMOLE_PER_SECOND' => array('0.01', 'cmol/s'),
'MEGAMOLE_PER_DAY' => array(array('' => '1000000', '/' => '86400'), 'Mmol/day'),
'MEGAMOLE_PER_HOUR' => array(array('' => '1000000', '/' => '3600'), 'Mmol/h'),
'MEGAMOLE_PER_MINUTE' => array(array('' => '1000000', '/' => '60'), 'Mmol/m'),
'MEGAMOLE_PER_SECOND' => array('1000000', 'Mmol/s'),
'MICROMOLE_PER_DAY' => array(array('' => '0.000001', '/' => '86400'), 'µmol/day'),
'MICROMOLE_PER_HOUR' => array(array('' => '0.000001', '/' => '3600'), 'µmol/h'),
'MICROMOLE_PER_MINUTE' => array(array('' => '0.000001', '/' => '60'), 'µmol/m'),
'MICROMOLE_PER_SECOND' => array('0.000001', 'µmol/s'),
'MILLIMOLE_PER_DAY' => array(array('' => '0.001', '/' => '86400'), 'mmol/day'),
'MILLIMOLE_PER_HOUR' => array(array('' => '0.001', '/' => '3600'), 'mmol/h'),
'MILLIMOLE_PER_MINUTE' => array(array('' => '0.001', '/' => '60'), 'mmol/m'),
'MILLIMOLE_PER_SECOND' => array('0.001', 'mmol/s'),
'MOLE_PER_DAY' => array(array('' => '1', '/' => '86400'), 'mol/day'),
'MOLE_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'mol/h'),
'MOLE_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'mol/m'),
'MOLE_PER_SECOND' => array('1', 'mol/s'),
'STANDARD' => 'MOLE_PER_SECOND'
);
}
Measure/Flow/Volume.php 0000604 00000077136 15071256135 0011053 0 ustar 00 <?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_Measure
* @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: Volume.php 9508 2008-05-23 10:56:41Z thomas $
*/
/**
* Implement needed classes
*/
require_once 'Zend/Measure/Exception.php';
require_once 'Zend/Measure/Abstract.php';
require_once 'Zend/Locale.php';
/**
* Class for handling flow volume conversions
*
* @category Zend
* @package Zend_Measure
* @subpackage Zend_Measure_Flow_Volume
* @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_Measure_Flow_Volume extends Zend_Measure_Abstract
{
const STANDARD = 'CUBIC_METER_PER_SECOND';
const ACRE_FOOT_PER_DAY = 'ACRE_FOOT_PER_DAY';
const ACRE_FOOT_PER_HOUR = 'ACRE_FOOT_PER_HOUR';
const ACRE_FOOT_PER_MINUTE = 'ACRE_FOOT_PER_MINUTE';
const ACRE_FOOT_PER_SECOND = 'ACRE_FOOT_PER_SECOND';
const ACRE_FOOT_SURVEY_PER_DAY = 'ACRE_FOOT_SURVEY_PER_DAY';
const ACRE_FOOT_SURVEY_PER_HOUR = 'ACRE_FOOT_SURVEY_PER_HOUR';
const ACRE_FOOT_SURVEY_PER_MINUTE = 'ACRE_FOOT_SURVEY_PER_MINUTE';
const ACRE_FOOT_SURVEY_PER_SECOND = 'ACRE_FOOT_SURVEY_PER_SECOND';
const ACRE_INCH_PER_DAY = 'ACRE_INCH_PER_DAY';
const ACRE_INCH_PER_HOUR = 'ACRE_INCH_PER_HOUR';
const ACRE_INCH_PER_MINUTE = 'ACRE_INCH_PER_MINUTE';
const ACRE_INCH_PER_SECOND = 'ACRE_INCH_PER_SECOND';
const ACRE_INCH_SURVEY_PER_DAY = 'ACRE_INCH_SURVEY_PER_DAY';
const ACRE_INCH_SURVEY_PER_HOUR = 'ACRE_INCH_SURVEY_PER_HOUR';
const ACRE_INCH_SURVEY_PER_MINUTE = 'ACRE_INCH_SURVEY_PER_MINUTE';
const ACRE_INCH_SURVEY_PER_SECOND = 'ACRE_INCH_SURVEY_PER_SECOND';
const BARREL_PETROLEUM_PER_DAY = 'BARREL_PETROLEUM_PER_DAY';
const BARREL_PETROLEUM_PER_HOUR = 'BARREL_PETROLEUM_PER_HOUR';
const BARREL_PETROLEUM_PER_MINUTE = 'BARREL_PETROLEUM_PER_MINUTE';
const BARREL_PETROLEUM_PER_SECOND = 'BARREL_PETROLEUM_PER_SECOND';
const BARREL_PER_DAY = 'BARREL_PER_DAY';
const BARREL_PER_HOUR = 'BARREL_PER_HOUR';
const BARREL_PER_MINUTE = 'BARREL_PER_MINUTE';
const BARREL_PER_SECOND = 'BARREL_PER_SECOND';
const BARREL_US_PER_DAY = 'BARREL_US_PER_DAY';
const BARREL_US_PER_HOUR = 'BARREL_US_PER_HOUR';
const BARREL_US_PER_MINUTE = 'BARREL_US_PER_MINUTE';
const BARREL_US_PER_SECOND = 'BARREL_US_PER_SECOND';
const BARREL_WINE_PER_DAY = 'BARREL_WINE_PER_DAY';
const BARREL_WINE_PER_HOUR = 'BARREL_WINE_PER_HOUR';
const BARREL_WINE_PER_MINUTE = 'BARREL_WINE_PER_MINUTE';
const BARREL_WINE_PER_SECOND = 'BARREL_WINE_PER_SECOND';
const BARREL_BEER_PER_DAY = 'BARREL_BEER_PER_DAY';
const BARREL_BEER_PER_HOUR = 'BARREL_BEER_PER_HOUR';
const BARREL_BEER_PER_MINUTE = 'BARREL_BEER_PER_MINUTE';
const BARREL_BEER_PER_SECOND = 'BARREL_BEER_PER_SECOND';
const BILLION_CUBIC_FOOT_PER_DAY = 'BILLION_CUBIC_FOOT_PER_DAY';
const BILLION_CUBIC_FOOT_PER_HOUR = 'BILLION_CUBIC_FOOT_PER_HOUR';
const BILLION_CUBIC_FOOT_PER_MINUTE = 'BILLION_CUBIC_FOOT_PER_MINUTE';
const BILLION_CUBIC_FOOT_PER_SECOND = 'BILLION_CUBIC_FOOT_PER_SECOND';
const CENTILITER_PER_DAY = 'CENTILITER_PER_DAY';
const CENTILITER_PER_HOUR = 'CENTILITER_PER_HOUR';
const CENTILITER_PER_MINUTE = 'CENTILITER_PER_MINUTE';
const CENTILITER_PER_SECOND = 'CENTILITER_PER_SECOND';
const CUBEM_PER_DAY = 'CUBEM_PER_DAY';
const CUBEM_PER_HOUR = 'CUBEM_PER_HOUR';
const CUBEM_PER_MINUTE = 'CUBEM_PER_MINUTE';
const CUBEM_PER_SECOND = 'CUBEM_PER_SECOND';
const CUBIC_CENTIMETER_PER_DAY = 'CUBIC_CENTIMETER_PER_DAY';
const CUBIC_CENTIMETER_PER_HOUR = 'CUBIC_CENTIMETER_PER_HOUR';
const CUBIC_CENTIMETER_PER_MINUTE = 'CUBIC_CENTIMETER_PER_MINUTE';
const CUBIC_CENTIMETER_PER_SECOND = 'CUBIC_CENTIMETER_PER_SECOND';
const CUBIC_DECIMETER_PER_DAY = 'CUBIC_DECIMETER_PER_DAY';
const CUBIC_DECIMETER_PER_HOUR = 'CUBIC_DECIMETER_PER_HOUR';
const CUBIC_DECIMETER_PER_MINUTE = 'CUBIC_DECIMETER_PER_MINUTE';
const CUBIC_DECIMETER_PER_SECOND = 'CUBIC_DECIMETER_PER_SECOND';
const CUBIC_DEKAMETER_PER_DAY = 'CUBIC_DEKAMETER_PER_DAY';
const CUBIC_DEKAMETER_PER_HOUR = 'CUBIC_DEKAMETER_PER_HOUR';
const CUBIC_DEKAMETER_PER_MINUTE = 'CUBIC_DEKAMETER_PER_MINUTE';
const CUBIC_DEKAMETER_PER_SECOND = 'CUBIC_DEKAMETER_PER_SECOND';
const CUBIC_FOOT_PER_DAY = 'CUBIC_FOOT_PER_DAY';
const CUBIC_FOOT_PER_HOUR = 'CUBIC_FOOT_PER_HOUR';
const CUBIC_FOOT_PER_MINUTE = 'CUBIC_FOOT_PER_MINUTE';
const CUBIC_FOOT_PER_SECOND = 'CUBIC_FOOT_PER_SECOND';
const CUBIC_INCH_PER_DAY = 'CUBIC_INCH_PER_DAY';
const CUBIC_INCH_PER_HOUR = 'CUBIC_INCH_PER_HOUR';
const CUBIC_INCH_PER_MINUTE = 'CUBIC_INCH_PER_MINUTE';
const CUBIC_INCH_PER_SECOND = 'CUBIC_INCH_PER_SECOND';
const CUBIC_KILOMETER_PER_DAY = 'CUBIC_KILOMETER_PER_DAY';
const CUBIC_KILOMETER_PER_HOUR = 'CUBIC_KILOMETER_PER_HOUR';
const CUBIC_KILOMETER_PER_MINUTE = 'CUBIC_KILOMETER_PER_MINUTE';
const CUBIC_KILOMETER_PER_SECOND = 'CUBIC_KILOMETER_PER_SECOND';
const CUBIC_METER_PER_DAY = 'CUBIC_METER_PER_DAY';
const CUBIC_METER_PER_HOUR = 'CUBIC_METER_PER_HOUR';
const CUBIC_METER_PER_MINUTE = 'CUBIC_METER_PER_MINUTE';
const CUBIC_METER_PER_SECOND = 'CUBIC_METER_PER_SECOND';
const CUBIC_MILE_PER_DAY = 'CUBIC_MILE_PER_DAY';
const CUBIC_MILE_PER_HOUR = 'CUBIC_MILE_PER_HOUR';
const CUBIC_MILE_PER_MINUTE = 'CUBIC_MILE_PER_MINUTE';
const CUBIC_MILE_PER_SECOND = 'CUBIC_MILE_PER_SECOND';
const CUBIC_MILLIMETER_PER_DAY = 'CUBIC_MILLIMETER_PER_DAY';
const CUBIC_MILLIMETER_PER_HOUR = 'CUBIC_MILLIMETER_PER_HOUR';
const CUBIC_MILLIMETER_PER_MINUTE = 'CUBIC_MILLIMETER_PER_MINUTE';
const CUBIC_MILLIMETER_PER_SECOND = 'CUBIC_MILLIMETER_PER_SECOND';
const CUBIC_YARD_PER_DAY = 'CUBIC_YARD_PER_DAY';
const CUBIC_YARD_PER_HOUR = 'CUBIC_YARD_PER_HOUR';
const CUBIC_YARD_PER_MINUTE = 'CUBIC_YARD_PER_MINUTE';
const CUBIC_YARD_PER_SECOND = 'CUBIC_YARD_PER_SECOND';
const CUSEC = 'CUSEC';
const DECILITER_PER_DAY = 'DECILITER_PER_DAY';
const DECILITER_PER_HOUR = 'DECILITER_PER_HOUR';
const DECILITER_PER_MINUTE = 'DECILITER_PER_MINUTE';
const DECILITER_PER_SECOND = 'DECILITER_PER_SECOND';
const DEKALITER_PER_DAY = 'DEKALITER_PER_DAY';
const DEKALITER_PER_HOUR = 'DEKALITER_PER_HOUR';
const DEKALITER_PER_MINUTE = 'DEKALITER_PER_MINUTE';
const DEKALITER_PER_SECOND = 'DEKALITER_PER_SECOND';
const GALLON_PER_DAY = 'GALLON_PER_DAY';
const GALLON_PER_HOUR = 'GALLON_PER_HOUR';
const GALLON_PER_MINUTE = 'GALLON_PER_MINUTE';
const GALLON_PER_SECOND = 'GALLON_PER_SECOND';
const GALLON_US_PER_DAY = 'GALLON_US_PER_DAY';
const GALLON_US_PER_HOUR = 'GALLON_US_PER_HOUR';
const GALLON_US_PER_MINUTE = 'GALLON_US_PER_MINUTE';
const GALLON_US_PER_SECOND = 'GALLON_US_PER_SECOND';
const HECTARE_METER_PER_DAY = 'HECTARE_METER_PER_DAY';
const HECTARE_METER_PER_HOUR = 'HECTARE_METER_PER_HOUR';
const HECTARE_METER_PER_MINUTE = 'HECTARE_METER_PER_MINUTE';
const HECTARE_METER_PER_SECOND = 'HECTARE_METER_PER_SECOND';
const HECTOLITER_PER_DAY = 'HECTOLITER_PER_DAY';
const HECTOLITER_PER_HOUR = 'HECTOLITER_PER_HOUR';
const HECTOLITER_PER_MINUTE = 'HECTOLITER_PER_MINUTE';
const HECTOLITER_PER_SECOND = 'HECTOLITER_PER_SECOND';
const KILOLITER_PER_DAY = 'KILOLITER_PER_DAY';
const KILOLITER_PER_HOUR = 'KILOLITER_PER_HOUR';
const KILOLITER_PER_MINUTE = 'KILOLITER_PER_MINUTE';
const KILOLITER_PER_SECOND = 'KILOLITER_PER_SECOND';
const LAMBDA_PER_DAY = 'LAMBDA_PER_DAY';
const LAMBDA_PER_HOUR = 'LAMBDA_PER_HOUR';
const LAMBDA_PER_MINUTE = 'LAMBDA_PER_MINUTE';
const LAMBDA_PER_SECOND = 'LAMBDA_PER_SECOND';
const LITER_PER_DAY = 'LITER_PER_DAY';
const LITER_PER_HOUR = 'LITER_PER_HOUR';
const LITER_PER_MINUTE = 'LITER_PER_MINUTE';
const LITER_PER_SECOND = 'LITER_PER_SECOND';
const MILLILITER_PER_DAY = 'MILLILITER_PER_DAY';
const MILLILITER_PER_HOUR = 'MILLILITER_PER_HOUR';
const MILLILITER_PER_MINUTE = 'MILLILITER_PER_MINUTE';
const MILLILITER_PER_SECOND = 'MILLILITER_PER_SECOND';
const MILLION_ACRE_FOOT_PER_DAY = 'MILLION_ACRE_FOOT_PER_DAY';
const MILLION_ACRE_FOOT_PER_HOUR = 'MILLION_ACRE_FOOT_PER_HOUR';
const MILLION_ACRE_FOOT_PER_MINUTE = 'MILLION_ACRE_FOOT_PER_MINUTE';
const MILLION_ACRE_FOOT_PER_SECOND = 'MILLION_ACRE_FOOT_PER_SECOND';
const MILLION_CUBIC_FOOT_PER_DAY = 'MILLION_CUBIC_FOOT_PER_DAY';
const MILLION_CUBIC_FOOT_PER_HOUR = 'MILLION_CUBIC_FOOT_PER_HOUR';
const MILLION_CUBIC_FOOT_PER_MINUTE = 'MILLION_CUBIC_FOOT_PER_MINUTE';
const MILLION_CUBIC_FOOT_PER_SECOND = 'MILLION_CUBIC_FOOT_PER_SECOND';
const MILLION_GALLON_PER_DAY = 'MILLION_GALLON_PER_DAY';
const MILLION_GALLON_PER_HOUR = 'MILLION_GALLON_PER_HOUR';
const MILLION_GALLON_PER_MINUTE = 'MILLION_GALLON_PER_MINUTE';
const MILLION_GALLON_PER_SECOND = 'MILLION_GALLON_PER_SECOND';
const MILLION_GALLON_US_PER_DAY = 'MILLION_GALLON_US_PER_DAY';
const MILLION_GALLON_US_PER_HOUR = 'MILLION_GALLON_US_PER_HOUR';
const MILLION_GALLON_US_PER_MINUTE = 'MILLION_GALLON_US_PER_MINUTE';
const MILLION_GALLON_US_PER_SECOND = 'MILLION_GALLON_US_PER_SECOND';
const MINERS_INCH_AZ = 'MINERS_INCH_AZ';
const MINERS_INCH_CA = 'MINERS_INCH_CA';
const MINERS_INCH_OR = 'MINERS_INCH_OR';
const MINERS_INCH_CO = 'MINERS_INCH_CO';
const MINERS_INCH_ID = 'MINERS_INCH_ID';
const MINERS_INCH_WA = 'MINERS_INCH_WA';
const MINERS_INCH_NM = 'MINERS_INCH_NM';
const OUNCE_PER_DAY = 'OUNCE_PER_DAY';
const OUNCE_PER_HOUR = 'OUNCE_PER_HOUR';
const OUNCE_PER_MINUTE = 'OUNCE_PER_MINUTE';
const OUNCE_PER_SECOND = 'OUNCE_PER_SECOND';
const OUNCE_US_PER_DAY = 'OUNCE_US_PER_DAY';
const OUNCE_US_PER_HOUR = 'OUNCE_US_PER_HOUR';
const OUNCE_US_PER_MINUTE = 'OUNCE_US_PER_MINUTE';
const OUNCE_US_PER_SECOND = 'OUNCE_US_PER_SECOND';
const PETROGRAD_STANDARD_PER_DAY = 'PETROGRAD_STANDARD_PER_DAY';
const PETROGRAD_STANDARD_PER_HOUR = 'PETROGRAD_STANDARD_PER_HOUR';
const PETROGRAD_STANDARD_PER_MINUTE = 'PETROGRAD_STANDARD_PER_MINUTE';
const PETROGRAD_STANDARD_PER_SECOND = 'PETROGRAD_STANDARD_PER_SECOND';
const STERE_PER_DAY = 'STERE_PER_DAY';
const STERE_PER_HOUR = 'STERE_PER_HOUR';
const STERE_PER_MINUTE = 'STERE_PER_MINUTE';
const STERE_PER_SECOND = 'STERE_PER_SECOND';
const THOUSAND_CUBIC_FOOT_PER_DAY = 'THOUSAND_CUBIC_FOOT_PER_DAY';
const THOUSAND_CUBIC_FOOT_PER_HOUR = 'THOUSAND_CUBIC_FOOT_PER_HOUR';
const THOUSAND_CUBIC_FOOT_PER_MINUTE = 'THOUSAND_CUBIC_FOOT_PER_MINUTE';
const THOUSAND_CUBIC_FOOT_PER_SECOND = 'THOUSAND_CUBIC_FOOT_PER_SECOND';
const TRILLION_CUBIC_FOOT_PER_DAY = 'TRILLION_CUBIC_FOOT_PER_DAY';
const TRILLION_CUBIC_FOOT_PER_HOUR = 'TRILLION_CUBIC_FOOT_PER_HOUR';
const TRILLION_CUBIC_FOOT_PER_MINUTE = 'TRILLION_CUBIC_FOOT_PER_MINUTE';
const TRILLION_CUBIC_FOOT_PER_SECOND = 'TRILLION_CUBIC_FOOT_PER_';
/**
* Calculations for all flow volume units
*
* @var array
*/
protected $_units = array(
'ACRE_FOOT_PER_DAY' => array(array('' => '1233.48184', '/' => '86400'), 'ac ft/day'),
'ACRE_FOOT_PER_HOUR' => array(array('' => '1233.48184', '/' => '3600'), 'ac ft/h'),
'ACRE_FOOT_PER_MINUTE' => array(array('' => '1233.48184', '/' => '60'), 'ac ft/m'),
'ACRE_FOOT_PER_SECOND' => array('1233.48184', 'ac ft/s'),
'ACRE_FOOT_SURVEY_PER_DAY' => array(array('' => '1233.48924', '/' => '86400'), 'ac ft/day'),
'ACRE_FOOT_SURVEY_PER_HOUR' => array(array('' => '1233.48924', '/' => '3600'), 'ac ft/h'),
'ACRE_FOOT_SURVEY_PER_MINUTE' => array(array('' => '1233.48924', '/' => '60'), 'ac ft/m'),
'ACRE_FOOT_SURVEY_PER_SECOND' => array('1233.48924', 'ac ft/s'),
'ACRE_INCH_PER_DAY' => array(array('' => '1233.48184', '/' => '1036800'), 'ac in/day'),
'ACRE_INCH_PER_HOUR' => array(array('' => '1233.48184', '/' => '43200'), 'ac in/h'),
'ACRE_INCH_PER_MINUTE' => array(array('' => '1233.48184', '/' => '720'), 'ac in/m'),
'ACRE_INCH_PER_SECOND' => array(array('' => '1233.48184', '/' => '12'), 'ac in/s'),
'ACRE_INCH_SURVEY_PER_DAY' => array(array('' => '1233.48924', '/' => '1036800'), 'ac in/day'),
'ACRE_INCH_SURVEY_PER_HOUR' => array(array('' => '1233.48924', '/' => '43200'), 'ac in/h'),
'ACRE_INCH_SURVEY_PER_MINUTE' => array(array('' => '1233.48924', '/' => '720'), 'ac in /m'),
'ACRE_INCH_SURVEY_PER_SECOND' => array(array('' => '1233.48924', '/' => '12'), 'ac in/s'),
'BARREL_PETROLEUM_PER_DAY' => array(array('' => '0.1589872956', '/' => '86400'), 'bbl/day'),
'BARREL_PETROLEUM_PER_HOUR' => array(array('' => '0.1589872956', '/' => '3600'), 'bbl/h'),
'BARREL_PETROLEUM_PER_MINUTE' => array(array('' => '0.1589872956', '/' => '60'), 'bbl/m'),
'BARREL_PETROLEUM_PER_SECOND' => array('0.1589872956', 'bbl/s'),
'BARREL_PER_DAY' => array(array('' => '0.16365924', '/' => '86400'), 'bbl/day'),
'BARREL_PER_HOUR' => array(array('' => '0.16365924', '/' => '3600'), 'bbl/h'),
'BARREL_PER_MINUTE' => array(array('' => '0.16365924', '/' => '60'), 'bbl/m'),
'BARREL_PER_SECOND' => array('0.16365924', 'bbl/s'),
'BARREL_US_PER_DAY' => array(array('' => '0.1192404717', '/' => '86400'), 'bbl/day'),
'BARREL_US_PER_HOUR' => array(array('' => '0.1192404717', '/' => '3600'), 'bbl/h'),
'BARREL_US_PER_MINUTE' => array(array('' => '0.1192404717', '/' => '60'), 'bbl/m'),
'BARREL_US_PER_SECOND' => array('0.1192404717', 'bbl/s'),
'BARREL_WINE_PER_DAY' => array(array('' => '0.1173477658', '/' => '86400'), 'bbl/day'),
'BARREL_WINE_PER_HOUR' => array(array('' => '0.1173477658', '/' => '3600'), 'bbl/h'),
'BARREL_WINE_PER_MINUTE' => array(array('' => '0.1173477658', '/' => '60'), 'bbl/m'),
'BARREL_WINE_PER_SECOND' => array('0.1173477658', 'bbl/s'),
'BARREL_BEER_PER_DAY' => array(array('' => '0.1173477658', '/' => '86400'), 'bbl/day'),
'BARREL_BEER_PER_HOUR' => array(array('' => '0.1173477658', '/' => '3600'), 'bbl/h'),
'BARREL_BEER_PER_MINUTE' => array(array('' => '0.1173477658', '/' => '60'), 'bbl/m'),
'BARREL_BEER_PER_SECOND' => array('0.1173477658', 'bbl/s'),
'BILLION_CUBIC_FOOT_PER_DAY' => array(array('' => '28316847', '/' => '86400'), 'bn ft³/day'),
'BILLION_CUBIC_FOOT_PER_HOUR' => array(array('' => '28316847', '/' => '3600'), 'bn ft³/h'),
'BILLION_CUBIC_FOOT_PER_MINUTE' => array(array('' => '28316847', '/' => '60'), 'bn ft³/m'),
'BILLION_CUBIC_FOOT_PER_SECOND' => array('28316847', 'bn ft³/s'),
'CENTILITER_PER_DAY' => array(array('' => '0.00001', '/' => '86400'), 'cl/day'),
'CENTILITER_PER_HOUR' => array(array('' => '0.00001', '/' => '3600'), 'cl/h'),
'CENTILITER_PER_MINUTE' => array(array('' => '0.00001', '/' => '60'), 'cl/m'),
'CENTILITER_PER_SECOND' => array('0.00001', 'cl/s'),
'CUBEM_PER_DAY' => array(array('' => '4168181830', '/' => '86400'), 'cubem/day'),
'CUBEM_PER_HOUR' => array(array('' => '4168181830', '/' => '3600'), 'cubem/h'),
'CUBEM_PER_MINUTE' => array(array('' => '4168181830', '/' => '60'), 'cubem/m'),
'CUBEM_PER_SECOND' => array('4168181830', 'cubem/s'),
'CUBIC_CENTIMETER_PER_DAY' => array(array('' => '0.000001', '/' => '86400'), 'cm³/day'),
'CUBIC_CENTIMETER_PER_HOUR' => array(array('' => '0.000001', '/' => '3600'), 'cm³/h'),
'CUBIC_CENTIMETER_PER_MINUTE' => array(array('' => '0.000001', '/' => '60'), 'cm³/m'),
'CUBIC_CENTIMETER_PER_SECOND' => array('0.000001', 'cm³/s'),
'CUBIC_DECIMETER_PER_DAY' => array(array('' => '0.001', '/' => '86400'), 'dm³/day'),
'CUBIC_DECIMETER_PER_HOUR' => array(array('' => '0.001', '/' => '3600'), 'dm³/h'),
'CUBIC_DECIMETER_PER_MINUTE' => array(array('' => '0.001', '/' => '60'), 'dm³/m'),
'CUBIC_DECIMETER_PER_SECOND' => array('0.001', 'dm³/s'),
'CUBIC_DEKAMETER_PER_DAY' => array(array('' => '1000', '/' => '86400'), 'dam³/day'),
'CUBIC_DEKAMETER_PER_HOUR' => array(array('' => '1000', '/' => '3600'), 'dam³/h'),
'CUBIC_DEKAMETER_PER_MINUTE' => array(array('' => '1000', '/' => '60'), 'dam³/m'),
'CUBIC_DEKAMETER_PER_SECOND' => array('1000', 'dam³/s'),
'CUBIC_FOOT_PER_DAY' => array(array('' => '0.028316847', '/' => '86400'), 'ft³/day'),
'CUBIC_FOOT_PER_HOUR' => array(array('' => '0.028316847', '/' => '3600'), 'ft³/h'),
'CUBIC_FOOT_PER_MINUTE' => array(array('' => '0.028316847', '/' => '60'), 'ft³/m'),
'CUBIC_FOOT_PER_SECOND' => array('0.028316847', 'ft³/s'),
'CUBIC_INCH_PER_DAY' => array(array('' => '0.028316847', '/' => '149299200'), 'in³/day'),
'CUBIC_INCH_PER_HOUR' => array(array('' => '0.028316847', '/' => '6220800'), 'in³/h'),
'CUBIC_INCH_PER_MINUTE' => array(array('' => '0.028316847', '/' => '103680'), 'in³/m'),
'CUBIC_INCH_PER_SECOND' => array('0.028316847', 'in³/s'),
'CUBIC_KILOMETER_PER_DAY' => array(array('' => '1000000000', '/' => '86400'), 'km³/day'),
'CUBIC_KILOMETER_PER_HOUR' => array(array('' => '1000000000', '/' => '3600'), 'km³/h'),
'CUBIC_KILOMETER_PER_MINUTE' => array(array('' => '1000000000', '/' => '60'), 'km³/m'),
'CUBIC_KILOMETER_PER_SECOND' => array('1000000000', 'km³/s'),
'CUBIC_METER_PER_DAY' => array(array('' => '1', '/' => '86400'), 'm³/day'),
'CUBIC_METER_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'm³/h'),
'CUBIC_METER_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'm³/m'),
'CUBIC_METER_PER_SECOND' => array('1', 'm³/s'),
'CUBIC_MILE_PER_DAY' => array(array('' => '4168181830', '/' => '86400'), 'mi³/day'),
'CUBIC_MILE_PER_HOUR' => array(array('' => '4168181830', '/' => '3600'), 'mi³/h'),
'CUBIC_MILE_PER_MINUTE' => array(array('' => '4168181830', '/' => '60'), 'mi³/m'),
'CUBIC_MILE_PER_SECOND' => array('4168181830', 'mi³/s'),
'CUBIC_MILLIMETER_PER_DAY' => array(array('' => '0.000000001', '/' => '86400'), 'mm³/day'),
'CUBIC_MILLIMETER_PER_HOUR' => array(array('' => '0.000000001', '/' => '3600'), 'mm³/h'),
'CUBIC_MILLIMETER_PER_MINUTE' => array(array('' => '0.000000001', '/' => '60'), 'mm³/m'),
'CUBIC_MILLIMETER_PER_SECOND' => array('0.000000001', 'mm³/s'),
'CUBIC_YARD_PER_DAY' => array(array('' => '0.764554869', '/' => '86400'), 'yd³/day'),
'CUBIC_YARD_PER_HOUR' => array(array('' => '0.764554869', '/' => '3600'), 'yd³/h'),
'CUBIC_YARD_PER_MINUTE' => array(array('' => '0.764554869', '/' => '60'), 'yd³/m'),
'CUBIC_YARD_PER_SECOND' => array('0.764554869', 'yd³/s'),
'CUSEC' => array('0.028316847', 'cusec'),
'DECILITER_PER_DAY' => array(array('' => '0.0001', '/' => '86400'), 'dl/day'),
'DECILITER_PER_HOUR' => array(array('' => '0.0001', '/' => '3600'), 'dl/h'),
'DECILITER_PER_MINUTE' => array(array('' => '0.0001', '/' => '60'), 'dl/m'),
'DECILITER_PER_SECOND' => array('0.0001', 'dl/s'),
'DEKALITER_PER_DAY' => array(array('' => '0.01', '/' => '86400'), 'dal/day'),
'DEKALITER_PER_HOUR' => array(array('' => '0.01', '/' => '3600'), 'dal/h'),
'DEKALITER_PER_MINUTE' => array(array('' => '0.01', '/' => '60'), 'dal/m'),
'DEKALITER_PER_SECOND' => array('0.01', 'dal/s'),
'GALLON_PER_DAY' => array(array('' => '0.00454609', '/' => '86400'), 'gal/day'),
'GALLON_PER_HOUR' => array(array('' => '0.00454609', '/' => '3600'), 'gal/h'),
'GALLON_PER_MINUTE' => array(array('' => '0.00454609', '/' => '60'), 'gal/m'),
'GALLON_PER_SECOND' => array('0.00454609', 'gal/s'),
'GALLON_US_PER_DAY' => array(array('' => '0.0037854118', '/' => '86400'), 'gal/day'),
'GALLON_US_PER_HOUR' => array(array('' => '0.0037854118', '/' => '3600'), 'gal/h'),
'GALLON_US_PER_MINUTE' => array(array('' => '0.0037854118', '/' => '60'), 'gal/m'),
'GALLON_US_PER_SECOND' => array('0.0037854118', 'gal/s'),
'HECTARE_METER_PER_DAY' => array(array('' => '10000', '/' => '86400'), 'ha m/day'),
'HECTARE_METER_PER_HOUR' => array(array('' => '10000', '/' => '3600'), 'ha m/h'),
'HECTARE_METER_PER_MINUTE' => array(array('' => '10000', '/' => '60'), 'ha m/m'),
'HECTARE_METER_PER_SECOND' => array('10000', 'ha m/s'),
'HECTOLITER_PER_DAY' => array(array('' => '0.1', '/' => '86400'), 'hl/day'),
'HECTOLITER_PER_HOUR' => array(array('' => '0.1', '/' => '3600'), 'hl/h'),
'HECTOLITER_PER_MINUTE' => array(array('' => '0.1', '/' => '60'), 'hl/m'),
'HECTOLITER_PER_SECOND' => array('0.1', 'hl/s'),
'KILOLITER_PER_DAY' => array(array('' => '1', '/' => '86400'), 'kl/day'),
'KILOLITER_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'kl/h'),
'KILOLITER_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'kl/m'),
'KILOLITER_PER_SECOND' => array('1', 'kl/s'),
'LAMBDA_PER_DAY' => array(array('' => '0.000000001', '/' => '86400'), 'λ/day'),
'LAMBDA_PER_HOUR' => array(array('' => '0.000000001', '/' => '3600'), 'λ/h'),
'LAMBDA_PER_MINUTE' => array(array('' => '0.000000001', '/' => '60'), 'λ/m'),
'LAMBDA_PER_SECOND' => array('0.000000001', 'λ/s'),
'LITER_PER_DAY' => array(array('' => '0.001', '/' => '86400'), 'l/day'),
'LITER_PER_HOUR' => array(array('' => '0.001', '/' => '3600'), 'l/h'),
'LITER_PER_MINUTE' => array(array('' => '0.001', '/' => '60'), 'l/m'),
'LITER_PER_SECOND' => array('0.001', 'l/s'),
'MILLILITER_PER_DAY' => array(array('' => '0.000001', '/' => '86400'), 'ml/day'),
'MILLILITER_PER_HOUR' => array(array('' => '0.000001', '/' => '3600'), 'ml/h'),
'MILLILITER_PER_MINUTE' => array(array('' => '0.000001', '/' => '60'), 'ml/m'),
'MILLILITER_PER_SECOND' => array('0.000001', 'ml/s'),
'MILLION_ACRE_FOOT_PER_DAY' => array(array('' => '1233481840', '/' => '86400'), 'million ac ft/day'),
'MILLION_ACRE_FOOT_PER_HOUR' => array(array('' => '1233481840', '/' => '3600'), 'million ac ft/h'),
'MILLION_ACRE_FOOT_PER_MINUTE' => array(array('' => '1233481840', '/' => '60'), 'million ac ft/m'),
'MILLION_ACRE_FOOT_PER_SECOND' => array('1233481840', 'million ac ft/s'),
'MILLION_CUBIC_FOOT_PER_DAY' => array(array('' => '28316.847', '/' => '86400'), 'million ft³/day'),
'MILLION_CUBIC_FOOT_PER_HOUR' => array(array('' => '28316.847', '/' => '3600'), 'million ft³/h'),
'MILLION_CUBIC_FOOT_PER_MINUTE' => array(array('' => '28316.847', '/' => '60'), 'million ft³/m'),
'MILLION_CUBIC_FOOT_PER_SECOND' => array('28316.847', 'million ft³/s'),
'MILLION_GALLON_PER_DAY' => array(array('' => '4546.09', '/' => '86400'), 'million gal/day'),
'MILLION_GALLON_PER_HOUR' => array(array('' => '4546.09', '/' => '3600'), 'million gal/h'),
'MILLION_GALLON_PER_MINUTE' => array(array('' => '4546.09', '/' => '60'), 'million gal/m'),
'MILLION_GALLON_PER_SECOND' => array('4546.09', 'million gal/s'),
'MILLION_GALLON_US_PER_DAY' => array(array('' => '3785.4118', '/' => '86400'), 'million gal/day'),
'MILLION_GALLON_US_PER_HOUR' => array(array('' => '3785.4118', '/' => '3600'), 'million gal/h'),
'MILLION_GALLON_US_PER_MINUTE'=> array(array('' => '3785.4118', '/' => '60'), 'million gal/m'),
'MILLION_GALLON_US_PER_SECOND'=> array('3785.4118', 'million gal/s'),
'MINERS_INCH_AZ' => array(array('' => '0.0424752705', '/' => '60'), "miner's inch"),
'MINERS_INCH_CA' => array(array('' => '0.0424752705', '/' => '60'), "miner's inch"),
'MINERS_INCH_OR' => array(array('' => '0.0424752705', '/' => '60'), "miner's inch"),
'MINERS_INCH_CO' => array(array('' => '0.0442450734375', '/' => '60'), "miner's inch"),
'MINERS_INCH_ID' => array(array('' => '0.0340687062', '/' => '60'), "miner's inch"),
'MINERS_INCH_WA' => array(array('' => '0.0340687062', '/' => '60'), "miner's inch"),
'MINERS_INCH_NM' => array(array('' => '0.0340687062', '/' => '60'), "miner's inch"),
'OUNCE_PER_DAY' => array(array('' => '0.00454609', '/' => '13824000'), 'oz/day'),
'OUNCE_PER_HOUR' => array(array('' => '0.00454609', '/' => '576000'), 'oz/h'),
'OUNCE_PER_MINUTE' => array(array('' => '0.00454609', '/' => '9600'), 'oz/m'),
'OUNCE_PER_SECOND' => array(array('' => '0.00454609', '/' => '160'), 'oz/s'),
'OUNCE_US_PER_DAY' => array(array('' => '0.0037854118', '/' => '11059200'), 'oz/day'),
'OUNCE_US_PER_HOUR' => array(array('' => '0.0037854118', '/' => '460800'), 'oz/h'),
'OUNCE_US_PER_MINUTE' => array(array('' => '0.0037854118', '/' => '7680'), 'oz/m'),
'OUNCE_US_PER_SECOND' => array(array('' => '0.0037854118', '/' => '128'), 'oz/s'),
'PETROGRAD_STANDARD_PER_DAY' => array(array('' => '4.672279755', '/' => '86400'), 'petrograd standard/day'),
'PETROGRAD_STANDARD_PER_HOUR' => array(array('' => '4.672279755', '/' => '3600'), 'petrograd standard/h'),
'PETROGRAD_STANDARD_PER_MINUTE' => array(array('' => '4.672279755', '/' => '60'), 'petrograd standard/m'),
'PETROGRAD_STANDARD_PER_SECOND' => array('4.672279755', 'petrograd standard/s'),
'STERE_PER_DAY' => array(array('' => '1', '/' => '86400'), 'st/day'),
'STERE_PER_HOUR' => array(array('' => '1', '/' => '3600'), 'st/h'),
'STERE_PER_MINUTE' => array(array('' => '1', '/' => '60'), 'st/m'),
'STERE_PER_SECOND' => array('1', 'st/s'),
'THOUSAND_CUBIC_FOOT_PER_DAY' => array(array('' => '28.316847', '/' => '86400'), 'thousand ft³/day'),
'THOUSAND_CUBIC_FOOT_PER_HOUR' => array(array('' => '28.316847', '/' => '3600'), 'thousand ft³/h'),
'THOUSAND_CUBIC_FOOT_PER_MINUTE' => array(array('' => '28.316847', '/' => '60'), 'thousand ft³/m'),
'THOUSAND_CUBIC_FOOT_PER_SECOND' => array('28.316847', 'thousand ft³/s'),
'TRILLION_CUBIC_FOOT_PER_DAY' => array(array('' => '28316847000', '/' => '86400'), 'trillion ft³/day'),
'TRILLION_CUBIC_FOOT_PER_HOUR' => array(array('' => '28316847000', '/' => '3600'), 'trillion ft³/h'),
'TRILLION_CUBIC_FOOT_PER_MINUTE' => array(array('' => '28316847000', '/' => '60'), 'trillion ft³/m'),
'TRILLION_CUBIC_FOOT_PER_' => array('28316847000', 'trillion ft³/s'),
'STANDARD' => 'CUBIC_METER_PER_SECOND'
);
}
Validate.php 0000604 00000012222 15071256135 0007006 0 ustar 00 <?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_Validate
* @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: Validate.php 8729 2008-03-10 11:44:10Z thomas $
*/
/**
* @see Zend_Validate_Interface
*/
require_once 'Zend/Validate/Interface.php';
/**
* @category Zend
* @package Zend_Validate
* @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_Validate implements Zend_Validate_Interface
{
/**
* Validator chain
*
* @var array
*/
protected $_validators = array();
/**
* Array of validation failure messages
*
* @var array
*/
protected $_messages = array();
/**
* Array of validation failure message codes
*
* @var array
* @deprecated Since 1.5.0
*/
protected $_errors = array();
/**
* Adds a validator to the end of the chain
*
* If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain,
* if one exists, will not be executed.
*
* @param Zend_Validate_Interface $validator
* @param boolean $breakChainOnFailure
* @return Zend_Validate Provides a fluent interface
*/
public function addValidator(Zend_Validate_Interface $validator, $breakChainOnFailure = false)
{
$this->_validators[] = array(
'instance' => $validator,
'breakChainOnFailure' => (boolean) $breakChainOnFailure
);
return $this;
}
/**
* Returns true if and only if $value passes all validations in the chain
*
* Validators are run in the order in which they were added to the chain (FIFO).
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$this->_messages = array();
$this->_errors = array();
$result = true;
foreach ($this->_validators as $element) {
$validator = $element['instance'];
if ($validator->isValid($value)) {
continue;
}
$result = false;
$messages = $validator->getMessages();
$this->_messages = array_merge($this->_messages, $messages);
$this->_errors = array_merge($this->_errors, array_keys($messages));
if ($element['breakChainOnFailure']) {
break;
}
}
return $result;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns array of validation failure messages
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns array of validation failure message codes
*
* @return array
* @deprecated Since 1.5.0
*/
public function getErrors()
{
return $this->_errors;
}
/**
* @param mixed $value
* @param string $classBaseName
* @param array $args OPTIONAL
* @param mixed $namespaces OPTIONAL
* @return boolean
* @throws Zend_Validate_Exception
*/
public static function is($value, $classBaseName, array $args = array(), $namespaces = array())
{
$namespaces = array_merge(array('Zend_Validate'), (array) $namespaces);
foreach ($namespaces as $namespace) {
$className = $namespace . '_' . ucfirst($classBaseName);
try {
require_once 'Zend/Loader.php';
@Zend_Loader::loadClass($className);
if (class_exists($className, false)) {
$class = new ReflectionClass($className);
if ($class->implementsInterface('Zend_Validate_Interface')) {
if ($class->hasMethod('__construct')) {
$object = $class->newInstanceArgs($args);
} else {
$object = $class->newInstance();
}
return $object->isValid($value);
}
}
} catch (Zend_Validate_Exception $ze) {
// if there is an exception while validating throw it
throw $ze;
} catch (Zend_Exception $ze) {
// fallthrough and continue for missing validation classes
}
}
require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
}
}
TimeSync.php 0000604 00000021261 15071256135 0007013 0 ustar 00 <?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_TimeSync
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: TimeSync.php 9534 2008-05-26 20:01:56Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* Zend_Date
*/
require_once 'Zend/Date.php';
/**
* Zend_TimeSync_Exception
*/
require_once 'Zend/TimeSync/Exception.php';
/**
* @category Zend
* @package Zend_TimeSync
* @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_TimeSync implements IteratorAggregate
{
/**
* Set the default timeserver protocol to "Ntp". This will be called
* when no protocol is specified
*/
const DEFAULT_PROTOCOL = 'Ntp';
/**
* Contains array of timeserver objects
*
* @var array
*/
protected $_timeservers = array();
/**
* Holds a reference to the timeserver that is currently being used
*
* @var object
*/
protected $_current;
/**
* Allowed timeserver schemes
*
* @var array
*/
protected $_allowedSchemes = array(
'Ntp',
'Sntp'
);
/**
* Configuration array, set using the constructor or using
* ::setOptions() or ::setOption()
*
* @var array
*/
public static $options = array(
'timeout' => 1
);
/**
* Zend_TimeSync constructor
*
* @param string|array $target - OPTIONAL single timeserver, or an array of timeservers.
* @param string $alias - OPTIONAL an alias for this timeserver
* @return object
*/
public function __construct($target = null, $alias = null)
{
if (!is_null($target)) {
$this->addServer($target, $alias);
}
}
/**
* getIterator() - return an iteratable object for use in foreach and the like,
* this completes the IteratorAggregate interface
*
* @return ArrayObject
*/
public function getIterator()
{
return new ArrayObject($this->_timeservers);
}
/**
* Add a timeserver or multiple timeservers
*
* Server should be a single string representation of a timeserver,
* or a structured array listing multiple timeservers.
*
* If you provide an array of timeservers in the $target variable,
* $alias will be ignored. you can enter these as the array key
* in the provided array, which should be structured as follows:
*
* <code>
* $example = array(
* 'server_a' => 'ntp://127.0.0.1',
* 'server_b' => 'ntp://127.0.0.1:123',
* 'server_c' => 'ntp://[2000:364:234::2.5]',
* 'server_d' => 'ntp://[2000:364:234::2.5]:123'
* );
* </code>
*
* If no port number has been suplied, the default matching port
* number will be used.
*
* Supported protocols are:
* - ntp
* - sntp
*
* @param string|array $target - Single timeserver, or an array of timeservers.
* @param string $alias - OPTIONAL an alias for this timeserver
* @throws Zend_TimeSync_Exception
*/
public function addServer($target, $alias = null)
{
if (is_array($target)) {
foreach ($target as $key => $server) {
$this->_addServer($server, $key);
}
} else {
$this->_addServer($target, $alias);
}
}
/**
* Sets the value for the given options
*
* This will replace any currently defined options.
*
* @param array $options - An array of options to be set
*/
public static function setOptions(array $options)
{
foreach ($options as $key => $value) {
Zend_TimeSync::$options[$key] = $value;
}
}
/**
* Marks a nameserver as current
*
* @param string|integer $alias - The alias from the timeserver to set as current
* @throws Zend_TimeSync_Exception
*/
public function setServer($alias)
{
if (isset($this->_timeservers[$alias]) === true) {
$this->_current = $this->_timeservers[$alias];
} else {
throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
}
}
/**
* Returns the value to the option
*
* @param string $key - The option's identifier
* @return mixed
* @throws Zend_TimeSync_Exception
*/
public static function getOptions($key = null)
{
if ($key == null) {
return Zend_TimeSync::$options;
}
if (isset(Zend_TimeSync::$options[$key]) === true) {
return Zend_TimeSync::$options[$key];
} else {
throw new Zend_TimeSync_Exception("'$key' does not point to valid option");
}
}
/**
* Return a specified timeserver by alias
* If no alias is given it will return the current timeserver
*
* @param string|integer $alias - The alias from the timeserver to return
* @return object
* @throws Zend_TimeSync_Exception
*/
public function getServer($alias = null)
{
if ($alias === null) {
if (isset($this->_current) && $this->_current !== false) {
return $this->_current;
} else {
throw new Zend_TimeSync_Exception('there is no timeserver set');
}
}
if (isset($this->_timeservers[$alias]) === true) {
return $this->_timeservers[$alias];
} else {
throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
}
}
/**
* Returns information sent/returned from the current timeserver
*
* @return array
*/
public function getInfo()
{
return $this->getServer()->getInfo();
}
/**
* Query the timeserver list using the fallback mechanism
*
* If there are multiple servers listed, this method will act as a
* facade and will try to return the date from the first server that
* returns a valid result.
*
* @param $locale - OPTIONAL locale
* @return object
* @throws Zend_TimeSync_Exception
*/
public function getDate($locale = null)
{
foreach ($this->_timeservers as $alias => $server) {
$this->_current = $server;
try {
return $server->getDate($locale);
} catch (Zend_TimeSync_Exception $e) {
if (!isset($masterException)) {
$masterException = new Zend_TimeSync_Exception('all timeservers are bogus');
}
$masterException->addException($e);
}
}
throw $masterException;
}
/**
* Adds a timeserver object to the timeserver list
*
* @param string|array $target - Single timeserver, or an array of timeservers.
* @param string $alias - An alias for this timeserver
*/
protected function _addServer($target, $alias)
{
if ($pos = strpos($target, '://')) {
$protocol = substr($target, 0, $pos);
$adress = substr($target, $pos + 3);
} else {
$adress = $target;
$protocol = self::DEFAULT_PROTOCOL;
}
if ($pos = strrpos($adress, ':')) {
$posbr = strpos($adress, ']');
if ($posbr and ($pos > $posbr)) {
$port = substr($adress, $pos + 1);
$adress = substr($adress, 0, $pos);
} else if (!$posbr and $pos) {
$port = substr($adress, $pos + 1);
$adress = substr($adress, 0, $pos);
} else {
$port = null;
}
} else {
$port = null;
}
$protocol = ucfirst(strtolower($protocol));
if (!in_array($protocol, $this->_allowedSchemes)) {
throw new Zend_TimeSync_Exception("'$protocol' is not a supported protocol");
}
$className = 'Zend_TimeSync_' . $protocol;
Zend_Loader::loadClass($className);
$timeServerObj = new $className($adress, $port);
$this->_timeservers[$alias] = $timeServerObj;
}
}
Test/PHPUnit/Constraint/DomQuery.php 0000604 00000026716 15071256135 0013371 0 ustar 00 <?php
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
/** Zend_Dom_Query */
require_once 'Zend/Dom/Query.php';
/**
* Zend_Dom_Query-based PHPUnit Constraint
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
{
/**#@+
* @const string Assertion type constants
*/
const ASSERT_QUERY = 'assertQuery';
const ASSERT_CONTENT_CONTAINS = 'assertQueryContentContains';
const ASSERT_CONTENT_REGEX = 'assertQueryContentRegex';
const ASSERT_CONTENT_COUNT = 'assertQueryCount';
const ASSERT_CONTENT_COUNT_MIN= 'assertQueryCountMin';
const ASSERT_CONTENT_COUNT_MAX= 'assertQueryCountMax';
/**#@-*/
/**
* Current assertion type
* @var string
*/
protected $_assertType = null;
/**
* Available assertion types
* @var array
*/
protected $_assertTypes = array(
self::ASSERT_QUERY,
self::ASSERT_CONTENT_CONTAINS,
self::ASSERT_CONTENT_REGEX,
self::ASSERT_CONTENT_COUNT,
self::ASSERT_CONTENT_COUNT_MIN,
self::ASSERT_CONTENT_COUNT_MAX,
);
/**
* Content being matched
* @var string
*/
protected $_content = null;
/**
* Whether or not assertion is negated
* @var bool
*/
protected $_negate = false;
/**
* CSS selector or XPath path to select against
* @var string
*/
protected $_path = null;
/**
* Whether or not to use XPath when querying
* @var bool
*/
protected $_useXpath = false;
/**
* Constructor; setup constraint state
*
* @param string $path CSS selector path
* @return void
*/
public function __construct($path)
{
$this->_path = $path;
}
/**
* Indicate negative match
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
{
$this->_negate = $flag;
}
/**
* Whether or not path is a straight XPath expression
*
* @param bool $flag
* @return Zend_Test_PHPUnit_Constraint_DomQuery
*/
public function setUseXpath($flag = true)
{
$this->_useXpath = (bool) $flag;
return $this;
}
/**
* Evaluate an object to see if it fits the constraints
*
* @param string $other String to examine
* @param null|string Assertion type
* @return bool
*/
public function evaluate($other, $assertType = null)
{
if (strstr($assertType, 'Not')) {
$this->setNegate(true);
$assertType = str_replace('Not', '', $assertType);
}
if (strstr($assertType, 'Xpath')) {
$this->setUseXpath(true);
$assertType = str_replace('Xpath', 'Query', $assertType);
}
if (!in_array($assertType, $this->_assertTypes)) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
}
$this->_assertType = $assertType;
$method = $this->_useXpath ? 'queryXpath' : 'query';
$domQuery = new Zend_Dom_Query($other);
$result = $domQuery->$method($this->_path);
$argv = func_get_args();
$argc = func_num_args();
switch ($assertType) {
case self::ASSERT_CONTENT_CONTAINS:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No content provided against which to match');
}
$this->_content = $content = $argv[2];
return ($this->_negate)
? $this->_notMatchContent($result, $content)
: $this->_matchContent($result, $content);
case self::ASSERT_CONTENT_REGEX:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No pattern provided against which to match');
}
$this->_content = $content = $argv[2];
return ($this->_negate)
? $this->_notRegexContent($result, $content)
: $this->_regexContent($result, $content);
case self::ASSERT_CONTENT_COUNT:
case self::ASSERT_CONTENT_COUNT_MIN:
case self::ASSERT_CONTENT_COUNT_MAX:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No count provided against which to compare');
}
$this->_content = $content = $argv[2];
return $this->_countContent($result, $content, $assertType);
case self::ASSERT_QUERY:
default:
if ($this->_negate) {
return (0 == count($result));
} else {
return (0 != count($result));
}
}
}
/**
* Report Failure
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other CSS selector path
* @param string $description
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function fail($other, $description, $not = false)
{
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
switch ($this->_assertType) {
case self::ASSERT_CONTENT_CONTAINS:
$failure = 'Failed asserting node denoted by %s CONTAINS content "%s"';
if ($this->_negate) {
$failure = 'Failed asserting node DENOTED BY %s DOES NOT CONTAIN content "%s"';
}
$failure = sprintf($failure, $other, $this->_content);
break;
case self::ASSERT_CONTENT_REGEX:
$failure = 'Failed asserting node denoted by %s CONTAINS content MATCHING "%s"';
if ($this->_negate) {
$failure = 'Failed asserting node DENOTED BY %s DOES NOT CONTAIN content MATCHING "%s"';
}
$failure = sprintf($failure, $other, $this->_content);
break;
case self::ASSERT_CONTENT_COUNT:
$failure = 'Failed asserting node DENOTED BY %s OCCURS EXACTLY %d times';
if ($this->_negate) {
$failure = 'Failed asserting node DENOTED BY %s DOES NOT OCCUR EXACTLY %d times';
}
$failure = sprintf($failure, $other, $this->_content);
break;
case self::ASSERT_CONTENT_COUNT_MIN:
$failure = 'Failed asserting node DENOTED BY %s OCCURS AT LEAST %d times';
$failure = sprintf($failure, $other, $this->_content);
break;
case self::ASSERT_CONTENT_COUNT_MAX:
$failure = 'Failed asserting node DENOTED BY %s OCCURS AT MOST %d times';
$failure = sprintf($failure, $other, $this->_content);
break;
case self::ASSERT_QUERY:
default:
$failure = 'Failed asserting node DENOTED BY %s EXISTS';
if ($this->_negate) {
$failure = 'Failed asserting node DENOTED BY %s DOES NOT EXIST';
}
$failure = sprintf($failure, $other);
break;
}
if (!empty($description)) {
$failure = $description . "\n" . $failure;
}
throw new Zend_Test_PHPUnit_Constraint_Exception($failure);
}
/**
* Complete implementation
*
* @return string
*/
public function toString()
{
return '';
}
/**
* Check to see if content is matched in selected nodes
*
* @param Zend_Dom_Query_Result $result
* @param string $match Content to match
* @return bool
*/
protected function _matchContent($result, $match)
{
if (0 == count($result)) {
return false;
}
foreach ($result as $node) {
$content = $this->_getNodeContent($node);
if (strstr($content, $match)) {
return true;
}
}
return false;
}
/**
* Check to see if content is NOT matched in selected nodes
*
* @param Zend_Dom_Query_Result $result
* @param string $match
* @return bool
*/
protected function _notMatchContent($result, $match)
{
if (0 == count($result)) {
return true;
}
foreach ($result as $node) {
$content = $this->_getNodeContent($node);
if (strstr($content, $match)) {
return false;
}
}
return true;
}
/**
* Check to see if content is matched by regex in selected nodes
*
* @param Zend_Dom_Query_Result $result
* @param string $pattern
* @return bool
*/
protected function _regexContent($result, $pattern)
{
if (0 == count($result)) {
return false;
}
foreach ($result as $node) {
$content = $this->_getNodeContent($node);
if (preg_match($pattern, $content)) {
return true;
}
}
return false;
}
/**
* Check to see if content is NOT matched by regex in selected nodes
*
* @param Zend_Dom_Query_Result $result
* @param string $pattern
* @return bool
*/
protected function _notRegexContent($result, $pattern)
{
if (0 == count($result)) {
return true;
}
foreach ($result as $node) {
$content = $this->_getNodeContent($node);
if (preg_match($pattern, $content)) {
return false;
}
}
return true;
}
/**
* Determine if content count matches criteria
*
* @param Zend_Dom_Query_Result $result
* @param int $test Value against which to test
* @param string $type assertion type
* @return boolean
*/
protected function _countContent($result, $test, $type)
{
$count = count($result);
switch ($type) {
case self::ASSERT_CONTENT_COUNT:
return ($this->_negate)
? ($test != $count)
: ($test == $count);
case self::ASSERT_CONTENT_COUNT_MIN:
return ($count >= $test);
case self::ASSERT_CONTENT_COUNT_MAX:
return ($count <= $test);
default:
return false;
}
}
/**
* Get node content, minus node markup tags
*
* @param DOMNode $node
* @return string
*/
protected function _getNodeContent(DOMNode $node)
{
$doc = $node->ownerDocument;
$content = $doc->saveXML($node);
$tag = $node->nodeName;
$regex = '|</?' . $tag . '[^>]*>|';
return preg_replace($regex, '', $content);
}
}
Test/PHPUnit/Constraint/Exception.php 0000604 00000001023 15071256135 0013542 0 ustar 00 <?php
/** PHPUnit_Framework_ExpectationFailedException */
require_once 'PHPUnit/Framework/ExpectationFailedException.php';
/**
* Zend_Test_PHPUnit_Constraint_Exception
*
* @uses PHPUnit_Framework_ExpectationFailedException
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Test_PHPUnit_Constraint_Exception extends PHPUnit_Framework_ExpectationFailedException
{
}
Test/PHPUnit/Constraint/Redirect.php 0000604 00000017322 15071256135 0013356 0 ustar 00 <?php
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
/**
* Redirection constraints
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
{
/**#@+
* @const string Assertion type constants
*/
const ASSERT_REDIRECT = 'assertRedirect';
const ASSERT_REDIRECT_TO = 'assertRedirectTo';
const ASSERT_REDIRECT_REGEX = 'assertRedirectRegex';
/**#@-*/
/**
* Current assertion type
* @var string
*/
protected $_assertType = null;
/**
* Available assertion types
* @var array
*/
protected $_assertTypes = array(
self::ASSERT_REDIRECT,
self::ASSERT_REDIRECT_TO,
self::ASSERT_REDIRECT_REGEX,
);
/**
* Pattern to match against
* @var string
*/
protected $_match = null;
/**
* Whether or not assertion is negated
* @var bool
*/
protected $_negate = false;
/**
* Constructor; setup constraint state
*
* @return void
*/
public function __construct()
{
}
/**
* Indicate negative match
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
{
$this->_negate = $flag;
}
/**
* Evaluate an object to see if it fits the constraints
*
* @param string $other String to examine
* @param null|string Assertion type
* @return bool
*/
public function evaluate($other, $assertType = null)
{
if (!$other instanceof Zend_Controller_Response_Abstract) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('Redirect constraint assertions require a response object');
}
if (strstr($assertType, 'Not')) {
$this->setNegate(true);
$assertType = str_replace('Not', '', $assertType);
}
if (!in_array($assertType, $this->_assertTypes)) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
}
$this->_assertType = $assertType;
$response = $other;
$argv = func_get_args();
$argc = func_num_args();
switch ($assertType) {
case self::ASSERT_REDIRECT_TO:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No redirect URL provided against which to match');
}
$this->_match = $match = $argv[2];
return ($this->_negate)
? $this->_notMatch($response, $match)
: $this->_match($response, $match);
case self::ASSERT_REDIRECT_REGEX:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No pattern provided against which to match redirect');
}
$this->_match = $match = $argv[2];
return ($this->_negate)
? $this->_notRegex($response, $match)
: $this->_regex($response, $match);
case self::ASSERT_REDIRECT:
default:
return ($this->_negate) ? !$response->isRedirect() : $response->isRedirect();
}
}
/**
* Report Failure
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other
* @param string $description Additional message to display
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function fail($other, $description, $not = false)
{
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
switch ($this->_assertType) {
case self::ASSERT_REDIRECT_TO:
$failure = 'Failed asserting response redirects to "%s"';
if ($this->_negate) {
$failure = 'Failed asserting response DOES NOT redirect to "%s"';
}
$failure = sprintf($failure, $this->_match);
break;
case self::ASSERT_REDIRECT_REGEX:
$failure = 'Failed asserting response redirects to URL MATCHING "%s"';
if ($this->_negate) {
$failure = 'Failed asserting response DOES NOT redirect to URL MATCHING "%s"';
}
$failure = sprintf($failure, $this->_match);
break;
case self::ASSERT_REDIRECT:
default:
$failure = 'Failed asserting response is a redirect';
if ($this->_negate) {
$failure = 'Failed asserting response is NOT a redirect';
}
break;
}
if (!empty($description)) {
$failure = $description . "\n" . $failure;
}
throw new Zend_Test_PHPUnit_Constraint_Exception($failure);
}
/**
* Complete implementation
*
* @return string
*/
public function toString()
{
return '';
}
/**
* Check to see if content is matched in selected nodes
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $match Content to match
* @return bool
*/
protected function _match($response, $match)
{
if (!$response->isRedirect()) {
return false;
}
$headers = $response->sendHeaders();
$redirect = $headers['location'];
$redirect = str_replace('Location: ', '', $redirect);
return ($redirect == $match);
}
/**
* Check to see if content is NOT matched in selected nodes
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $match
* @return bool
*/
protected function _notMatch($response, $match)
{
if (!$response->isRedirect()) {
return true;
}
$headers = $response->sendHeaders();
$redirect = $headers['location'];
$redirect = str_replace('Location: ', '', $redirect);
return ($redirect != $match);
}
/**
* Check to see if content is matched by regex in selected nodes
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $pattern
* @return bool
*/
protected function _regex($response, $pattern)
{
if (!$response->isRedirect()) {
return false;
}
$headers = $response->sendHeaders();
$redirect = $headers['location'];
$redirect = str_replace('Location: ', '', $redirect);
return preg_match($pattern, $redirect);
}
/**
* Check to see if content is NOT matched by regex in selected nodes
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $pattern
* @return bool
*/
protected function _notRegex($response, $pattern)
{
if (!$response->isRedirect()) {
return true;
}
$headers = $response->sendHeaders();
$redirect = $headers['location'];
$redirect = str_replace('Location: ', '', $redirect);
return !preg_match($pattern, $redirect);
}
}
Test/PHPUnit/Constraint/ResponseHeader.php 0000604 00000030164 15071256135 0014523 0 ustar 00 <?php
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
/**
* Response header PHPUnit Constraint
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Constraint
{
/**#@+
* @const string Assertion type constants
*/
const ASSERT_RESPONSE_CODE = 'assertResponseCode';
const ASSERT_HEADER = 'assertHeader';
const ASSERT_HEADER_CONTAINS = 'assertHeaderContains';
const ASSERT_HEADER_REGEX = 'assertHeaderRegex';
/**#@-*/
/**
* Current assertion type
* @var string
*/
protected $_assertType = null;
/**
* Available assertion types
* @var array
*/
protected $_assertTypes = array(
self::ASSERT_RESPONSE_CODE,
self::ASSERT_HEADER,
self::ASSERT_HEADER_CONTAINS,
self::ASSERT_HEADER_REGEX,
);
/**
* @var int Response code
*/
protected $_code = 200;
/**
* @var string Header
*/
protected $_header = null;
/**
* @var string pattern against which to compare header content
*/
protected $_match = null;
/**
* Whether or not assertion is negated
* @var bool
*/
protected $_negate = false;
/**
* Constructor; setup constraint state
*
* @return void
*/
public function __construct()
{
}
/**
* Indicate negative match
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
{
$this->_negate = $flag;
}
/**
* Evaluate an object to see if it fits the constraints
*
* @param Zend_Controller_Response_Abstract $other String to examine
* @param null|string Assertion type
* @return bool
*/
public function evaluate($other, $assertType = null)
{
if (!$other instanceof Zend_Controller_Response_Abstract) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('Header constraint assertions require a response object');
}
if (strstr($assertType, 'Not')) {
$this->setNegate(true);
$assertType = str_replace('Not', '', $assertType);
}
if (!in_array($assertType, $this->_assertTypes)) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
}
$this->_assertType = $assertType;
$response = $other;
$argv = func_get_args();
$argc = func_num_args();
switch ($assertType) {
case self::ASSERT_RESPONSE_CODE:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No response code provided against which to match');
}
$this->_code = $code = $argv[2];
return ($this->_negate)
? $this->_notCode($response, $code)
: $this->_code($response, $code);
case self::ASSERT_HEADER:
if (3 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No header provided against which to match');
}
$this->_header = $header = $argv[2];
return ($this->_negate)
? $this->_notHeader($response, $header)
: $this->_header($response, $header);
case self::ASSERT_HEADER_CONTAINS:
if (4 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('Both a header name and content to match are required for ' . __FUNCTION__);
}
$this->_header = $header = $argv[2];
$this->_match = $match = $argv[3];
return ($this->_negate)
? $this->_notHeaderContains($response, $header, $match)
: $this->_headerContains($response, $header, $match);
case self::ASSERT_HEADER_REGEX:
if (4 > $argc) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('Both a header name and content to match are required for ' . __FUNCTION__);
}
$this->_header = $header = $argv[2];
$this->_match = $match = $argv[3];
return ($this->_negate)
? $this->_notHeaderRegex($response, $header, $match)
: $this->_headerRegex($response, $header, $match);
default:
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('Invalid assertion type ' . __FUNCTION__);
}
}
/**
* Report Failure
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other
* @param string $description Additional message to display
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function fail($other, $description, $not = false)
{
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
switch ($this->_assertType) {
case self::ASSERT_RESPONSE_CODE:
$failure = 'Failed asserting response code "%s"';
if ($this->_negate) {
$failure = 'Failed asserting response code IS NOT "%s"';
}
$failure = sprintf($failure, $this->_code);
break;
case self::ASSERT_HEADER:
$failure = 'Failed asserting response header "%s" found';
if ($this->_negate) {
$failure = 'Failed asserting response response header "%s" WAS NOT found';
}
$failure = sprintf($failure, $this->_header);
break;
case self::ASSERT_HEADER_CONTAINS:
$failure = 'Failed asserting response header "%s" exists and contains "%s"';
if ($this->_negate) {
$failure = 'Failed asserting response header "%s" DOES NOT CONTAIN "%s"';
}
$failure = sprintf($failure, $this->_header, $this->_match);
break;
case self::ASSERT_HEADER_REGEX:
$failure = 'Failed asserting response header "%s" exists and matches regex "%s"';
if ($this->_negate) {
$failure = 'Failed asserting response header "%s" DOES NOT MATCH regex "%s"';
}
$failure = sprintf($failure, $this->_header, $this->_match);
break;
default:
throw new Zend_Test_PHPUnit_Constraint_Exception('Invalid assertion type ' . __FUNCTION__);
}
if (!empty($description)) {
$failure = $description . "\n" . $failure;
}
throw new Zend_Test_PHPUnit_Constraint_Exception($failure);
}
/**
* Complete implementation
*
* @return string
*/
public function toString()
{
return '';
}
/**
* Compare response code for positive match
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
* @return bool
*/
protected function _code(Zend_Controller_Response_Abstract $response, $code)
{
$test = $this->_getCode($response);
return ($test == $code);
}
/**
* Compare response code for negative match
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
* @return bool
*/
protected function _notCode(Zend_Controller_Response_Abstract $response, $code)
{
$test = $this->_getCode($response);
return ($test != $code);
}
/**
* Retrieve response code
*
* @param Zend_Controller_Response_Abstract $response
* @return int
*/
protected function _getCode(Zend_Controller_Response_Abstract $response)
{
$test = $response->getHttpResponseCode();
if (null === $test) {
$test = 200;
}
return $test;
}
/**
* Positive check for response header presence
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return bool
*/
protected function _header(Zend_Controller_Response_Abstract $response, $header)
{
return (null !== $this->_getHeader($response, $header));
}
/**
* Negative check for response header presence
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return bool
*/
protected function _notHeader(Zend_Controller_Response_Abstract $response, $header)
{
return (null === $this->_getHeader($response, $header));
}
/**
* Retrieve response header
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return string|null
*/
protected function _getHeader(Zend_Controller_Response_Abstract $response, $header)
{
$headers = $response->sendHeaders();
$header = strtolower($header);
if (array_key_exists($header, $headers)) {
return $headers[$header];
}
return null;
}
/**
* Positive check for header contents matching pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
* @return bool
*/
protected function _headerContains(Zend_Controller_Response_Abstract $response, $header, $match)
{
if (null === ($fullHeader = $this->_getHeader($response, $header))) {
return false;
}
$contents = str_replace($header . ': ', '', $fullHeader);
return (strstr($contents, $match));
}
/**
* Negative check for header contents matching pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
* @return bool
*/
protected function _notHeaderContains(Zend_Controller_Response_Abstract $response, $header, $match)
{
if (null === ($fullHeader = $this->_getHeader($response, $header))) {
return true;
}
$contents = str_replace($header . ': ', '', $fullHeader);
return (!strstr($contents, $match));
}
/**
* Positive check for header contents matching regex
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
* @return bool
*/
protected function _headerRegex(Zend_Controller_Response_Abstract $response, $header, $pattern)
{
if (null === ($fullHeader = $this->_getHeader($response, $header))) {
return false;
}
$contents = str_replace($header . ': ', '', $fullHeader);
return preg_match($pattern, $contents);
}
/**
* Negative check for header contents matching regex
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
* @return bool
*/
protected function _notHeaderRegex(Zend_Controller_Response_Abstract $response, $header, $pattern)
{
if (null === ($fullHeader = $this->_getHeader($response, $header))) {
return true;
}
$contents = str_replace($header . ': ', '', $fullHeader);
return !preg_match($pattern, $contents);
}
}
Test/PHPUnit/ControllerTestCase.php 0000604 00000105142 15071256135 0013246 0 ustar 00 <?php
/** PHPUnit_Framework_TestCase */
require_once 'PHPUnit/Framework/TestCase.php';
/** PHPUnit_Runner_Version */
require_once 'PHPUnit/Runner/Version.php';
/** Zend_Controller_Front */
require_once 'Zend/Controller/Front.php';
/** Zend_Controller_Action_HelperBroker */
require_once 'Zend/Controller/Action/HelperBroker.php';
/** Zend_Layout */
require_once 'Zend/Layout.php';
/** Zend_Session */
require_once 'Zend/Session.php';
/** Zend_Registry */
require_once 'Zend/Registry.php';
/**
* Functional testing scaffold for MVC applications
*
* @uses PHPUnit_Framework_TestCase
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var mixed Bootstrap file path or callback
*/
public $bootstrap;
/**
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* @var Zend_Dom_Query
*/
protected $_query;
/**
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* @var Zend_Controller_Response_Abstract
*/
protected $_response;
/**
* Overlaoding: prevent overloading to special properties
*
* @param string $name
* @param mixed $value
* @return void
*/
public function __set($name, $value)
{
if (in_array($name, array('request', 'response', 'frontController'))) {
throw new Zend_Exception(sprintf('Setting %s object manually is not allowed', $name));
}
$this->$name = $value;
}
/**
* Overloading for common properties
*
* Provides overloading for request, response, and frontController objects.
*
* @param mixed $name
* @return void
*/
public function __get($name)
{
switch ($name) {
case 'request':
return $this->getRequest();
case 'response':
return $this->getResponse();
case 'frontController':
return $this->getFrontController();
}
return null;
}
/**
* Set up MVC app
*
* Calls {@link bootstrap()} by default
*
* @return void
*/
protected function setUp()
{
$this->bootstrap();
}
/**
* Bootstrap the front controller
*
* Resets the front controller, and then bootstraps it.
*
* If {@link $bootstrap} is a callback, executes it; if it is a file, it include's
* it. When done, sets the test case request and response objects into the
* front controller.
*
* @return void
*/
final public function bootstrap()
{
$this->reset();
if (null !== $this->bootstrap) {
if (is_callable($this->bootstrap)) {
call_user_func($this->bootstrap);
} elseif (is_string($this->bootstrap)) {
require_once 'Zend/Loader.php';
if (Zend_Loader::isReadable($this->bootstrap)) {
include $this->bootstrap;
}
}
}
$this->frontController
->setRequest($this->getRequest())
->setResponse($this->getResponse());
}
/**
* Dispatch the MVC
*
* If a URL is provided, sets it as the request URI in the request object.
* Then sets test case request and response objects in front controller,
* disables throwing exceptions, and disables returning the response.
* Finally, dispatches the front controller.
*
* @param string|null $url
* @return void
*/
public function dispatch($url = null)
{
// redirector should not exit
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->setExit(false);
// json helper should not exit
$json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
$json->suppressExit = true;
$request = $this->getRequest();
if (null !== $url) {
$request->setRequestUri($url);
}
$request->setPathInfo(null);
$controller = $this->getFrontController();
$this->frontController
->setRequest($request)
->setResponse($this->getResponse())
->throwExceptions(false)
->returnResponse(false);
$this->frontController->dispatch();
}
/**
* Reset MVC state
*
* Creates new request/response objects, resets the front controller
* instance, and resets the action helper broker.
*
* @todo Need to update Zend_Layout to add a resetInstance() method
* @return void
*/
public function reset()
{
$_SESSION = array();
$_GET = array();
$_POST = array();
$_COOKIE = array();
$this->resetRequest();
$this->resetResponse();
Zend_Layout::resetMvcInstance();
Zend_Controller_Action_HelperBroker::resetHelpers();
$this->frontController->resetInstance();
Zend_Session::$_unitTestEnabled = true;
}
/**
* Rest all view placeholders
*
* @return void
*/
protected function _resetPlaceholders()
{
$registry = Zend_Registry::getInstance();
$remove = array();
foreach ($registry as $key => $value) {
if (strstr($key, '_View_')) {
$remove[] = $key;
}
}
foreach ($remove as $key) {
unset($registry[$key]);
}
}
/**
* Reset the request object
*
* Useful for test cases that need to test multiple trips to the server.
*
* @return Zend_Test_PHPUnit_ControllerTestCase
*/
public function resetRequest()
{
$this->_request = null;
return $this;
}
/**
* Reset the response object
*
* Useful for test cases that need to test multiple trips to the server.
*
* @return Zend_Test_PHPUnit_ControllerTestCase
*/
public function resetResponse()
{
$this->_response = null;
$this->_resetPlaceholders();
return $this;
}
/**
* Assert against DOM selection
*
* @param string $path CSS selector path
* @param string $message
* @return void
*/
public function assertQuery($path, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection
*
* @param string $path CSS selector path
* @param string $message
* @return void
*/
public function assertNotQuery($path, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; node should contain content
*
* @param string $path CSS selector path
* @param string $match content that should be contained in matched nodes
* @param string $message
* @return void
*/
public function assertQueryContentContains($path, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; node should NOT contain content
*
* @param string $path CSS selector path
* @param string $match content that should NOT be contained in matched nodes
* @param string $message
* @return void
*/
public function assertNotQueryContentContains($path, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; node should match content
*
* @param string $path CSS selector path
* @param string $pattern Pattern that should be contained in matched nodes
* @param string $message
* @return void
*/
public function assertQueryContentRegex($path, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; node should NOT match content
*
* @param string $path CSS selector path
* @param string $pattern pattern that should NOT be contained in matched nodes
* @param string $message
* @return void
*/
public function assertNotQueryContentRegex($path, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; should contain exact number of nodes
*
* @param string $path CSS selector path
* @param string $count Number of nodes that should match
* @param string $message
* @return void
*/
public function assertQueryCount($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; should NOT contain exact number of nodes
*
* @param string $path CSS selector path
* @param string $count Number of nodes that should NOT match
* @param string $message
* @return void
*/
public function assertNotQueryCount($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; should contain at least this number of nodes
*
* @param string $path CSS selector path
* @param string $count Minimum number of nodes that should match
* @param string $message
* @return void
*/
public function assertQueryCountMin($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against DOM selection; should contain no more than this number of nodes
*
* @param string $path CSS selector path
* @param string $count Maximum number of nodes that should match
* @param string $message
* @return void
*/
public function assertQueryCountMax($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection
*
* @param string $path XPath path
* @param string $message
* @return void
*/
public function assertXpath($path, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection
*
* @param string $path XPath path
* @param string $message
* @return void
*/
public function assertNotXpath($path, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; node should contain content
*
* @param string $path XPath path
* @param string $match content that should be contained in matched nodes
* @param string $message
* @return void
*/
public function assertXpathContentContains($path, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; node should NOT contain content
*
* @param string $path XPath path
* @param string $match content that should NOT be contained in matched nodes
* @param string $message
* @return void
*/
public function assertNotXpathContentContains($path, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $match)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; node should match content
*
* @param string $path XPath path
* @param string $pattern Pattern that should be contained in matched nodes
* @param string $message
* @return void
*/
public function assertXpathContentRegex($path, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; node should NOT match content
*
* @param string $path XPath path
* @param string $pattern pattern that should NOT be contained in matched nodes
* @param string $message
* @return void
*/
public function assertNotXpathContentRegex($path, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $pattern)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; should contain exact number of nodes
*
* @param string $path XPath path
* @param string $count Number of nodes that should match
* @param string $message
* @return void
*/
public function assertXpathCount($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; should NOT contain exact number of nodes
*
* @param string $path XPath path
* @param string $count Number of nodes that should NOT match
* @param string $message
* @return void
*/
public function assertNotXpathCount($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; should contain at least this number of nodes
*
* @param string $path XPath path
* @param string $count Minimum number of nodes that should match
* @param string $message
* @return void
*/
public function assertXpathCountMin($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert against XPath selection; should contain no more than this number of nodes
*
* @param string $path XPath path
* @param string $count Maximum number of nodes that should match
* @param string $message
* @return void
*/
public function assertXpathCountMax($path, $count, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
$constraint = new Zend_Test_PHPUnit_Constraint_DomQuery($path);
$content = $this->response->outputBody();
if (!$constraint->evaluate($content, __FUNCTION__, $count)) {
$constraint->fail($path, $message);
}
}
/**
* Assert that response is a redirect
*
* @param string $message
* @return void
*/
public function assertRedirect($message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that response is NOT a redirect
*
* @param string $message
* @return void
*/
public function assertNotRedirect($message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that response redirects to given URL
*
* @param string $url
* @param string $message
* @return void
*/
public function assertRedirectTo($url, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $url)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that response does not redirect to given URL
*
* @param string $url
* @param string $message
* @return void
*/
public function assertNotRedirectTo($url, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $url)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that redirect location matches pattern
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertRedirectRegex($pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $pattern)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that redirect location does not match pattern
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertNotRedirectRegex($pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';
$constraint = new Zend_Test_PHPUnit_Constraint_Redirect();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $pattern)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response code
*
* @param int $code
* @param string $message
* @return void
*/
public function assertResponseCode($code, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $code)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response code
*
* @param int $code
* @param string $message
* @return void
*/
public function assertNotResponseCode($code, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$constraint->setNegate(true);
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $code)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header exists
*
* @param string $header
* @param string $message
* @return void
*/
public function assertHeader($header, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header does not exist
*
* @param string $header
* @param string $message
* @return void
*/
public function assertNotHeader($header, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$constraint->setNegate(true);
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header exists and contains the given string
*
* @param string $header
* @param string $match
* @param string $message
* @return void
*/
public function assertHeaderContains($header, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header, $match)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header does not exist and/or does not contain the given string
*
* @param string $header
* @param string $match
* @param string $message
* @return void
*/
public function assertNotHeaderContains($header, $match, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$constraint->setNegate(true);
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header, $match)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header exists and matches the given pattern
*
* @param string $header
* @param string $pattern
* @param string $message
* @return void
*/
public function assertHeaderRegex($header, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header, $pattern)) {
$constraint->fail($response, $message);
}
}
/**
* Assert response header does not exist and/or does not match the given regex
*
* @param string $header
* @param string $pattern
* @param string $message
* @return void
*/
public function assertNotHeaderRegex($header, $pattern, $message = '')
{
$this->_incrementAssertionCount();
require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';
$constraint = new Zend_Test_PHPUnit_Constraint_ResponseHeader();
$constraint->setNegate(true);
$response = $this->response;
if (!$constraint->evaluate($response, __FUNCTION__, $header, $pattern)) {
$constraint->fail($response, $message);
}
}
/**
* Assert that the last handled request used the given module
*
* @param string $module
* @param string $message
* @return void
*/
public function assertModule($module, $message = '')
{
$this->_incrementAssertionCount();
if ($module != $this->request->getModuleName()) {
$msg = sprintf('Failed asserting last module used was "%s"', $module);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the last handled request did NOT use the given module
*
* @param string $module
* @param string $message
* @return void
*/
public function assertNotModule($module, $message = '')
{
$this->_incrementAssertionCount();
if ($module == $this->request->getModuleName()) {
$msg = sprintf('Failed asserting last module used was NOT "%s"', $module);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the last handled request used the given controller
*
* @param string $controller
* @param string $message
* @return void
*/
public function assertController($controller, $message = '')
{
$this->_incrementAssertionCount();
if ($controller != $this->request->getControllerName()) {
$msg = sprintf('Failed asserting last controller used was "%s"', $controller);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the last handled request did NOT use the given controller
*
* @param string $controller
* @param string $message
* @return void
*/
public function assertNotController($controller, $message = '')
{
$this->_incrementAssertionCount();
if ($controller == $this->request->getControllerName()) {
$msg = sprintf('Failed asserting last controller used was NOT "%s"', $controller);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the last handled request used the given action
*
* @param string $action
* @param string $message
* @return void
*/
public function assertAction($action, $message = '')
{
$this->_incrementAssertionCount();
if ($action != $this->request->getActionName()) {
$msg = sprintf('Failed asserting last action used was "%s"', $action);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the last handled request did NOT use the given action
*
* @param string $action
* @param string $message
* @return void
*/
public function assertNotAction($action, $message = '')
{
$this->_incrementAssertionCount();
if ($action == $this->request->getActionName()) {
$msg = sprintf('Failed asserting last action used was NOT "%s"', $action);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the specified route was used
*
* @param string $route
* @param string $message
* @return void
*/
public function assertRoute($route, $message = '')
{
$this->_incrementAssertionCount();
$router = $this->frontController->getRouter();
if ($route != $router->getCurrentRouteName()) {
$msg = sprintf('Failed asserting route matched was "%s"', $route);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Assert that the route matched is NOT as specified
*
* @param string $route
* @param string $message
* @return void
*/
public function assertNotRoute($route, $message = '')
{
$this->_incrementAssertionCount();
$router = $this->frontController->getRouter();
if ($route == $router->getCurrentRouteName()) {
$msg = sprintf('Failed asserting route matched was NOT "%s"', $route);
if (!empty($message)) {
$msg = $message . "\n" . $msg;
}
$this->fail($msg);
}
}
/**
* Retrieve front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_frontController) {
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
/**
* Retrieve test case request object
*
* @return Zend_Controller_Request_Abstract
*/
public function getRequest()
{
if (null === $this->_request) {
require_once 'Zend/Controller/Request/HttpTestCase.php';
$this->_request = new Zend_Controller_Request_HttpTestCase;
}
return $this->_request;
}
/**
* Retrieve test case response object
*
* @return Zend_Controller_Response_Abstract
*/
public function getResponse()
{
if (null === $this->_response) {
require_once 'Zend/Controller/Response/HttpTestCase.php';
$this->_response = new Zend_Controller_Response_HttpTestCase;
}
return $this->_response;
}
/**
* Retrieve DOM query object
*
* @return Zend_Dom_Query
*/
public function getQuery()
{
if (null === $this->_query) {
require_once 'Zend/Dom/Query.php';
$this->_query = new Zend_Dom_Query;
}
return $this->_query;
}
/**
* Increment assertion count
*
* @return void
*/
protected function _incrementAssertionCount()
{
$stack = debug_backtrace();
foreach (debug_backtrace() as $step) {
if (isset($step['object'])
&& $step['object'] instanceof PHPUnit_Framework_TestCase
) {
if (version_compare(PHPUnit_Runner_Version::id(), '3.3.3', 'lt')) {
$step['object']->incrementAssertionCounter();
} else {
$step['object']->addToAssertionCount(1);
}
break;
}
}
}
}
Feed.php 0000604 00000031436 15071256135 0006130 0 ustar 00 <?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_Feed
* @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: Feed.php 10383 2008-07-24 19:46:15Z matthew $
*/
/**
* Feed utility class
*
* Base Zend_Feed class, containing constants and the Zend_Http_Client instance
* accessor.
*
* @category Zend
* @package Zend_Feed
* @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_Feed
{
/**
* HTTP client object to use for retrieving feeds
*
* @var Zend_Http_Client
*/
protected static $_httpClient = null;
/**
* Override HTTP PUT and DELETE request methods?
*
* @var boolean
*/
protected static $_httpMethodOverride = false;
/**
* @var array
*/
protected static $_namespaces = array(
'opensearch' => 'http://a9.com/-/spec/opensearchrss/1.0/',
'atom' => 'http://www.w3.org/2005/Atom',
'rss' => 'http://blogs.law.harvard.edu/tech/rss',
);
/**
* Set the HTTP client instance
*
* Sets the HTTP client object to use for retrieving the feeds.
*
* @param Zend_Http_Client $httpClient
* @return void
*/
public static function setHttpClient(Zend_Http_Client $httpClient)
{
self::$_httpClient = $httpClient;
}
/**
* Gets the HTTP client object. If none is set, a new Zend_Http_Client will be used.
*
* @return Zend_Http_Client_Abstract
*/
public static function getHttpClient()
{
if (!self::$_httpClient instanceof Zend_Http_Client) {
/**
* @see Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
self::$_httpClient = new Zend_Http_Client();
}
return self::$_httpClient;
}
/**
* Toggle using POST instead of PUT and DELETE HTTP methods
*
* Some feed implementations do not accept PUT and DELETE HTTP
* methods, or they can't be used because of proxies or other
* measures. This allows turning on using POST where PUT and
* DELETE would normally be used; in addition, an
* X-Method-Override header will be sent with a value of PUT or
* DELETE as appropriate.
*
* @param boolean $override Whether to override PUT and DELETE.
* @return void
*/
public static function setHttpMethodOverride($override = true)
{
self::$_httpMethodOverride = $override;
}
/**
* Get the HTTP override state
*
* @return boolean
*/
public static function getHttpMethodOverride()
{
return self::$_httpMethodOverride;
}
/**
* Get the full version of a namespace prefix
*
* Looks up a prefix (atom:, etc.) in the list of registered
* namespaces and returns the full namespace URI if
* available. Returns the prefix, unmodified, if it's not
* registered.
*
* @return string
*/
public static function lookupNamespace($prefix)
{
return isset(self::$_namespaces[$prefix]) ?
self::$_namespaces[$prefix] :
$prefix;
}
/**
* Add a namespace and prefix to the registered list
*
* Takes a prefix and a full namespace URI and adds them to the
* list of registered namespaces for use by
* Zend_Feed::lookupNamespace().
*
* @param string $prefix The namespace prefix
* @param string $namespaceURI The full namespace URI
* @return void
*/
public static function registerNamespace($prefix, $namespaceURI)
{
self::$_namespaces[$prefix] = $namespaceURI;
}
/**
* Imports a feed located at $uri.
*
* @param string $uri
* @throws Zend_Feed_Exception
* @return Zend_Feed_Abstract
*/
public static function import($uri)
{
$client = self::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$feed = $response->getBody();
return self::importString($feed);
}
/**
* Imports a feed represented by $string.
*
* @param string $string
* @throws Zend_Feed_Exception
* @return Zend_Feed_Abstract
*/
public static function importString($string)
{
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument;
$status = @$doc->loadXML($string);
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
// Try to find the base feed element or a single <entry> of an Atom feed
if ($doc->getElementsByTagName('feed')->item(0) ||
$doc->getElementsByTagName('entry')->item(0)) {
/**
* @see Zend_Feed_Atom
*/
require_once 'Zend/Feed/Atom.php';
// return a newly created Zend_Feed_Atom object
return new Zend_Feed_Atom(null, $string);
}
// Try to find the base feed element of an RSS feed
if ($doc->getElementsByTagName('channel')->item(0)) {
/**
* @see Zend_Feed_Rss
*/
require_once 'Zend/Feed/Rss.php';
// return a newly created Zend_Feed_Rss object
return new Zend_Feed_Rss(null, $string);
}
// $string does not appear to be a valid feed of the supported types
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Invalid or unsupported feed format');
}
/**
* Imports a feed from a file located at $filename.
*
* @param string $filename
* @throws Zend_Feed_Exception
* @return Zend_Feed_Abstract
*/
public static function importFile($filename)
{
@ini_set('track_errors', 1);
$feed = @file_get_contents($filename);
@ini_restore('track_errors');
if ($feed === false) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg");
}
return self::importString($feed);
}
/**
* Attempts to find feeds at $uri referenced by <link ... /> tags. Returns an
* array of the feeds referenced at $uri.
*
* @todo Allow findFeeds() to follow one, but only one, code 302.
*
* @param string $uri
* @throws Zend_Feed_Exception
* @return array
*/
public static function findFeeds($uri)
{
// Get the HTTP response from $uri and save the contents
$client = self::getHttpClient();
$client->setUri($uri);
$response = $client->request();
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus());
}
$contents = $response->getBody();
// Parse the contents for appropriate <link ... /> tags
@ini_set('track_errors', 1);
$pattern = '~(<link[^>]+)/?>~i';
$result = @preg_match_all($pattern, $contents, $matches);
@ini_restore('track_errors');
if ($result === false) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("Internal error: $php_errormsg");
}
// Try to fetch a feed for each link tag that appears to refer to a feed
$feeds = array();
if (isset($matches[1]) && count($matches[1]) > 0) {
foreach ($matches[1] as $link) {
// force string to be an utf-8 one
if (!mb_check_encoding($link, 'UTF-8')) {
$link = mb_convert_encoding($link, 'UTF-8');
}
$xml = @simplexml_load_string(rtrim($link, ' /') . ' />');
if ($xml === false) {
continue;
}
$attributes = $xml->attributes();
if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) {
continue;
}
if (!isset($attributes['type']) ||
!@preg_match('~^application/(?:atom|rss|rdf)\+xml~', $attributes['type'])) {
continue;
}
if (!isset($attributes['href'])) {
continue;
}
try {
// checks if we need to canonize the given uri
try {
$uri = Zend_Uri::factory((string) $attributes['href']);
} catch (Zend_Uri_Exception $e) {
// canonize the uri
$path = (string) $attributes['href'];
$query = $fragment = '';
if (substr($path, 0, 1) != '/') {
// add the current root path to this one
$path = rtrim($client->getUri()->getPath(), '/') . '/' . $path;
}
if (strpos($path, '?') !== false) {
list($path, $query) = explode('?', $path, 2);
}
if (strpos($query, '#') !== false) {
list($query, $fragment) = explode('#', $query, 2);
}
$uri = Zend_Uri::factory($client->getUri(true));
$uri->setPath($path);
$uri->setQuery($query);
$uri->setFragment($fragment);
}
$feed = self::import($uri);
} catch (Exception $e) {
continue;
}
$feeds[] = $feed;
}
}
// Return the fetched feeds
return $feeds;
}
/**
* Construct a new Zend_Feed_Abstract object from a custom array
*
* @param array $data
* @param string $format (rss|atom) the requested output format
* @return Zend_Feed_Abstract
*/
public static function importArray(array $data, $format = 'atom')
{
$obj = 'Zend_Feed_' . ucfirst(strtolower($format));
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($obj);
Zend_Loader::loadClass('Zend_Feed_Builder');
return new $obj(null, null, new Zend_Feed_Builder($data));
}
/**
* Construct a new Zend_Feed_Abstract object from a Zend_Feed_Builder_Interface data source
*
* @param Zend_Feed_Builder_Interface $builder this object will be used to extract the data of the feed
* @param string $format (rss|atom) the requested output format
* @return Zend_Feed_Abstract
*/
public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom')
{
$obj = 'Zend_Feed_' . ucfirst(strtolower($format));
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($obj);
return new $obj(null, null, $builder);
}
}
Form/Decorator/FormElements.php 0000604 00000007374 15071256135 0012516 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_FormElements
*
* Render all form elements registered with current form
*
* Accepts following options:
* - separator: Separator to use between elements
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: FormElements.php 12347 2008-11-06 21:45:56Z matthew $
*/
class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
{
/**
* Merges given two belongsTo (array notation) strings
*
* @param string $baseBelongsTo
* @param string $belongsTo
* @return string
*/
public function mergeBelongsTo($baseBelongsTo, $belongsTo)
{
$endOfArrayName = strpos($belongsTo, '[');
if ($endOfArrayName === false) {
return $baseBelongsTo . '[' . $belongsTo . ']';
}
$arrayName = substr($belongsTo, 0, $endOfArrayName);
return $baseBelongsTo . '[' . $arrayName . ']' . substr($belongsTo, $endOfArrayName);
}
/**
* Render form elements
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
return $content;
}
$belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
$elementContent = '';
$separator = $this->getSeparator();
$translator = $form->getTranslator();
$items = array();
$view = $form->getView();
foreach ($form as $item) {
$item->setView($view)
->setTranslator($translator);
if ($item instanceof Zend_Form_Element) {
$item->setBelongsTo($belongsTo);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
if ($item->isArray()) {
$name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
$item->setElementsBelongTo($name, true);
} else {
$item->setElementsBelongTo($belongsTo, true);
}
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
foreach ($item as $element) {
$element->setBelongsTo($belongsTo);
}
}
$items[] = $item->render();
}
$elementContent = implode($separator, $items);
switch ($this->getPlacement()) {
case self::PREPEND:
return $elementContent . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $elementContent;
}
}
}
Form/Decorator/Label.php 0000604 00000022213 15071256135 0011122 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Label
*
* Accepts the options:
* - separator: separator to use between label and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to prepend)
* - tag: if set, used to wrap the label in an additional HTML tag
* - opt(ional)Prefix: a prefix to the label to use when the element is optional
* - opt(iona)lSuffix: a suffix to the label to use when the element is optional
* - req(uired)Prefix: a prefix to the label to use when the element is required
* - req(uired)Suffix: a suffix to the label to use when the element is required
*
* Any other options passed will be used as HTML attributes of the label tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Label.php 12383 2008-11-07 19:38:55Z matthew $
*/
class Zend_Form_Decorator_Label extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: prepend
* @var string
*/
protected $_placement = 'PREPEND';
/**
* HTML tag with which to surround label
* @var string
*/
protected $_tag;
/**
* Set element ID
*
* @param string $id
* @return Zend_Form_Decorator_Label
*/
public function setId($id)
{
$this->setOption('id', $id);
return $this;
}
/**
* Retrieve element ID (used in 'for' attribute)
*
* If none set in decorator, looks first for element 'id' attribute, and
* defaults to element name.
*
* @return string
*/
public function getId()
{
$id = $this->getOption('id');
if (null === $id) {
if (null !== ($element = $this->getElement())) {
$id = $element->getId();
$this->setId($id);
}
}
return $id;
}
/**
* Set HTML tag with which to surround label
*
* @param string $tag
* @return Zend_Form_Decorator_Label
*/
public function setTag($tag)
{
if (empty($tag)) {
$this->_tag = null;
} else {
$this->_tag = (string) $tag;
}
return $this;
}
/**
* Get HTML tag, if any, with which to surround label
*
* @return void
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
$this->setTag($tag);
}
return $tag;
}
return $this->_tag;
}
/**
* Get class with which to define label
*
* Appends either 'optional' or 'required' to class, depending on whether
* or not the element is required.
*
* @return string
*/
public function getClass()
{
$class = '';
$element = $this->getElement();
$decoratorClass = $this->getOption('class');
if (!empty($decoratorClass)) {
$class .= ' ' . $decoratorClass;
}
$type = $element->isRequired() ? 'required' : 'optional';
if (!strstr($class, $type)) {
$class .= ' ' . $type;
$class = trim($class);
}
return $class;
}
/**
* Load an optional/required suffix/prefix key
*
* @param string $key
* @return void
*/
protected function _loadOptReqKey($key)
{
if (!isset($this->$key)) {
$value = $this->getOption($key);
$this->$key = (string) $value;
if (null !== $value) {
$this->removeOption($key);
}
}
}
/**
* Overloading
*
* Currently overloads:
*
* - getOpt(ional)Prefix()
* - getOpt(ional)Suffix()
* - getReq(uired)Prefix()
* - getReq(uired)Suffix()
* - setOpt(ional)Prefix()
* - setOpt(ional)Suffix()
* - setReq(uired)Prefix()
* - setReq(uired)Suffix()
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Form_Exception for unsupported methods
*/
public function __call($method, $args)
{
$tail = substr($method, -6);
$head = substr($method, 0, 3);
if (in_array($head, array('get', 'set'))
&& (('Prefix' == $tail) || ('Suffix' == $tail))
) {
$position = substr($method, -6);
$type = strtolower(substr($method, 3, 3));
switch ($type) {
case 'req':
$key = 'required' . $position;
break;
case 'opt':
$key = 'optional' . $position;
break;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator, and detected as type %s', $method, $type));
}
switch ($head) {
case 'set':
if (0 === count($args)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Method "%s" requires at least one argument; none provided', $method));
}
$value = array_shift($args);
$this->$key = $value;
return $this;
case 'get':
default:
if (null === ($element = $this->getElement())) {
$this->_loadOptReqKey($key);
} elseif (isset($element->$key)) {
$this->$key = (string) $element->$key;
} else {
$this->_loadOptReqKey($key);
}
return $this->$key;
}
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid method "%s" called in Label decorator', $method));
}
/**
* Get label to render
*
* @return void
*/
public function getLabel()
{
if (null === ($element = $this->getElement())) {
return '';
}
$label = $element->getLabel();
$label = trim($label);
if (empty($label)) {
return '';
}
if (null !== ($translator = $element->getTranslator())) {
$label = $translator->translate($label);
}
$optPrefix = $this->getOptPrefix();
$optSuffix = $this->getOptSuffix();
$reqPrefix = $this->getReqPrefix();
$reqSuffix = $this->getReqSuffix();
$separator = $this->getSeparator();
if (!empty($label)) {
if ($element->isRequired()) {
$label = $reqPrefix . $label . $reqSuffix;
} else {
$label = $optPrefix . $label . $optSuffix;
}
}
return $label;
}
/**
* Render a label
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$label = $this->getLabel();
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$tag = $this->getTag();
$id = $this->getId();
$class = $this->getClass();
$options = $this->getOptions();
if (empty($label) && empty($tag)) {
return $content;
}
if (!empty($label)) {
$options['class'] = $class;
$label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
} else {
$label = ' ';
}
if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
$decorator->setOptions(array('tag' => $tag));
$label = $decorator->render($label);
}
switch ($placement) {
case self::APPEND:
return $content . $separator . $label;
case self::PREPEND:
return $label . $separator . $content;
}
}
}
Form/Decorator/Image.php 0000604 00000010345 15071256135 0011130 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Image
*
* Accepts the options:
* - separator: separator to use between image and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to append)
* - tag: if set, used to wrap the label in an additional HTML tag
*
* Any other options passed will be used as HTML attributes of the image tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Image.php 10008 2008-07-09 16:52:08Z matthew $
*/
class Zend_Form_Decorator_Image extends Zend_Form_Decorator_Abstract
{
/**
* Attributes that should not be passed to helper
* @var array
*/
protected $_attribBlacklist = array('helper', 'placement', 'separator', 'tag');
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* HTML tag with which to surround image
* @var string
*/
protected $_tag;
/**
* Set HTML tag with which to surround label
*
* @param string $tag
* @return Zend_Form_Decorator_Image
*/
public function setTag($tag)
{
$this->_tag = (string) $tag;
return $this;
}
/**
* Get HTML tag, if any, with which to surround label
*
* @return void
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
$this->setTag($tag);
}
return $tag;
}
return $this->_tag;
}
/**
* Get attributes to pass to image helper
*
* @return array
*/
public function getAttribs()
{
$attribs = $this->getOptions();
if (null !== ($element = $this->getElement())) {
$attribs['alt'] = $element->getLabel();
$attribs = array_merge($attribs, $element->getAttribs());
}
foreach ($this->_attribBlacklist as $key) {
if (array_key_exists($key, $attribs)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Render a form image
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$tag = $this->getTag();
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$name = $element->getFullyQualifiedName();
$attribs = $this->getAttribs();
$attribs['id'] = $element->getId();
$image = $view->formImage($name, $element->getImageValue(), $attribs);
if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
$decorator->setOptions(array('tag' => $tag));
$image = $decorator->render($image);
}
switch ($placement) {
case self::PREPEND:
return $image . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $image;
}
}
}
Form/Decorator/Interface.php 0000604 00000005646 15071256135 0012016 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Form_Decorator_Interface
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
interface Zend_Form_Decorator_Interface
{
/**
* Constructor
*
* Accept options during initialization.
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null);
/**
* Set an element to decorate
*
* While the name is "setElement", a form decorator could decorate either
* an element or a form object.
*
* @param mixed $element
* @return Zend_Form_Decorator_Interface
*/
public function setElement($element);
/**
* Retrieve current element
*
* @return mixed
*/
public function getElement();
/**
* Set decorator options from an array
*
* @param array $options
* @return Zend_Form_Decorator_Interface
*/
public function setOptions(array $options);
/**
* Set decorator options from a config object
*
* @param Zend_Config $config
* @return Zend_Form_Decorator_Interface
*/
public function setConfig(Zend_Config $config);
/**
* Set a single option
*
* @param string $key
* @param mixed $value
* @return Zend_Form_Decorator_Interface
*/
public function setOption($key, $value);
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key);
/**
* Retrieve decorator options
*
* @return array
*/
public function getOptions();
/**
* Delete a single option
*
* @param string $key
* @return bool
*/
public function removeOption($key);
/**
* Clear all options
*
* @return Zend_Form_Decorator_Interface
*/
public function clearOptions();
/**
* Render the element
*
* @param string $content Content to decorate
* @return string
*/
public function render($content);
}
Form/Decorator/PrepareElements.php 0000604 00000006030 15071256135 0013175 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_FormElements */
require_once 'Zend/Form/Decorator/FormElements.php';
/**
* Zend_Form_Decorator_PrepareElements
*
* Render all form elements registered with current form
*
* Accepts following options:
* - separator: Separator to use between elements
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: PrepareElements.php 12347 2008-11-06 21:45:56Z matthew $
*/
class Zend_Form_Decorator_PrepareElements extends Zend_Form_Decorator_FormElements
{
/**
* Render form elements
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
return $content;
}
$this->_recursivelyPrepareForm($form);
return $content;
}
protected function _recursivelyPrepareForm(Zend_Form $form)
{
$belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
$elementContent = '';
$separator = $this->getSeparator();
$translator = $form->getTranslator();
$view = $form->getView();
foreach ($form as $item) {
$item->setView($view)
->setTranslator($translator);
if ($item instanceof Zend_Form_Element) {
$item->setBelongsTo($belongsTo);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
if ($item->isArray()) {
$name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
$item->setElementsBelongTo($name, true);
} else {
$item->setElementsBelongTo($belongsTo, true);
}
$this->_recursivelyPrepareForm($item);
} elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
foreach ($item as $element) {
$element->setBelongsTo($belongsTo);
}
}
}
}
}
Form/Decorator/ViewScript.php 0000604 00000010207 15071256135 0012202 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_ViewScript
*
* Render a view script as a decorator
*
* Accepts the options:
* - separator: separator to use between view script content and provided content (defaults to PHP_EOL)
* - placement: whether to append or prepend view script content to provided content (defaults to prepend)
* - viewScript: view script to use
*
* The view script is rendered as a partial; the element being decorated is
* passed in as the 'element' variable:
* <code>
* // in view script:
* echo $this->element->getLabel();
* </code>
*
* Any options other than separator, placement, and viewScript are passed to
* the partial as local variables.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: ViewScript.php 8651 2008-03-07 20:24:34Z matthew $
*/
class Zend_Form_Decorator_ViewScript extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* View script to render
* @var string
*/
protected $_viewScript;
/**
* Set view script
*
* @param string $script
* @return Zend_Form_Decorator_ViewScript
*/
public function setViewScript($script)
{
$this->_viewScript = (string) $script;
return $this;
}
/**
* Get view script
*
* @return string|null
*/
public function getViewScript()
{
if (null === $this->_viewScript) {
if (null !== ($element = $this->getElement())) {
if (null !== ($viewScript = $element->getAttrib('viewScript'))) {
$this->setViewScript($viewScript);
return $viewScript;
}
}
if (null !== ($viewScript = $this->getOption('viewScript'))) {
$this->setViewScript($viewScript)
->removeOption('viewScript');
}
}
return $this->_viewScript;
}
/**
* Render a view script
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$viewScript = $this->getViewScript();
if (empty($viewScript)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('No view script registered with ViewScript decorator');
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$vars = $this->getOptions();
$vars['element'] = $element;
$vars['content'] = $content;
$vars['decorator'] = $this;
$renderedContent = $view->partial($viewScript, $vars);
// Get placement again to see if it has changed
$placement = $this->getPlacement();
switch ($placement) {
case self::PREPEND:
return $renderedContent . $separator . $content;
case self::APPEND:
return $content . $separator . $renderedContent;
default:
return $renderedContent;
}
}
}
Form/Decorator/Abstract.php 0000604 00000014045 15071256135 0011652 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Interface */
require_once 'Zend/Form/Decorator/Interface.php';
/**
* Zend_Form_Decorator_Abstract
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Abstract.php 8892 2008-03-18 19:47:46Z thomas $
*/
abstract class Zend_Form_Decorator_Abstract implements Zend_Form_Decorator_Interface
{
/**
* Placement constants
*/
const APPEND = 'APPEND';
const PREPEND = 'PREPEND';
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* @var Zend_Form_Element|Zend_Form
*/
protected $_element;
/**
* Decorator options
* @var array
*/
protected $_options = array();
/**
* Separator between new content and old
* @var string
*/
protected $_separator = PHP_EOL;
/**
* Constructor
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if (is_array($options)) {
$this->setOptions($options);
} elseif ($options instanceof Zend_Config) {
$this->setConfig($options);
}
}
/**
* Set options
*
* @param array $options
* @return Zend_Form_Decorator_Abstract
*/
public function setOptions(array $options)
{
$this->_options = $options;
return $this;
}
/**
* Set options from config object
*
* @param Zend_Config $config
* @return Zend_Form_Decorator_Abstract
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Set option
*
* @param string $key
* @param mixed $value
* @return Zend_Form_Decorator_Abstract
*/
public function setOption($key, $value)
{
$this->_options[(string) $key] = $value;
return $this;
}
/**
* Get option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
$key = (string) $key;
if (isset($this->_options[$key])) {
return $this->_options[$key];
}
return null;
}
/**
* Retrieve options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Remove single option
*
* @param mixed $key
* @return void
*/
public function removeOption($key)
{
if (null !== $this->getOption($key)) {
unset($this->_options[$key]);
return true;
}
return false;
}
/**
* Clear all options
*
* @return Zend_Form_Decorator_Abstract
*/
public function clearOptions()
{
$this->_options = array();
return $this;
}
/**
* Set current form element
*
* @param Zend_Form_Element|Zend_Form $element
* @return Zend_Form_Decorator_Abstract
* @throws Zend_Form_Decorator_Exception on invalid element type
*/
public function setElement($element)
{
if ((!$element instanceof Zend_Form_Element)
&& (!$element instanceof Zend_Form)
&& (!$element instanceof Zend_Form_DisplayGroup))
{
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('Invalid element type passed to decorator');
}
$this->_element = $element;
return $this;
}
/**
* Retrieve current element
*
* @return Zend_Form_Element|Zend_Form
*/
public function getElement()
{
return $this->_element;
}
/**
* Determine if decorator should append or prepend content
*
* @return string
*/
public function getPlacement()
{
$placement = $this->_placement;
if (null !== ($placementOpt = $this->getOption('placement'))) {
$placementOpt = strtoupper($placementOpt);
switch ($placementOpt) {
case self::APPEND:
case self::PREPEND:
$placement = $this->_placement = $placementOpt;
break;
case false:
$placement = $this->_placement = null;
break;
default:
break;
}
$this->removeOption('placement');
}
return $placement;
}
/**
* Retrieve separator to use between old and new content
*
* @return string
*/
public function getSeparator()
{
$separator = $this->_separator;
if (null !== ($separatorOpt = $this->getOption('separator'))) {
$separator = $this->_separator = (string) $separatorOpt;
$this->removeOption('separator');
}
return $separator;
}
/**
* Decorate content and/or element
*
* @param string $content
* @return string
* @throws Zend_Dorm_Decorator_Exception when unimplemented
*/
public function render($content)
{
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('render() not implemented');
}
}
Form/Decorator/Exception.php 0000604 00000002250 15071256135 0012040 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Exception */
require_once 'Zend/Form/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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_Form_Decorator_Exception extends Zend_Form_Exception
{
}
Form/Decorator/Callback.php 0000604 00000007742 15071256135 0011611 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Callback
*
* Execute an arbitrary callback to decorate an element. Callbacks should take
* three arguments, $content, $element, and $options:
*
* function mycallback($content, $element, array $options)
* {
* }
*
* and should return a string. ($options are whatever options were provided to
* the decorator.)
*
* To specify a callback, pass a valid callback as the 'callback' option.
*
* Callback results will be either appended, prepended, or replace the provided
* content. To replace the content, specify a placement of boolean false;
* defaults to append content.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Callback.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Decorator_Callback extends Zend_Form_Decorator_Abstract
{
/**
* Callback
* @var string|array
*/
protected $_callback;
/**
* Set callback
*
* @param string|array $callback
* @return Zend_Form_Decorator_Callback
* @throws Zend_Form_Exception
*/
public function setCallback($callback)
{
if (!is_string($callback) && !is_array($callback)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid callback provided to callback decorator');
}
if (is_array($callback)) {
if (2 !== count($callback)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid method callback provided to callback decorator');
}
}
$this->_callback = $callback;
return $this;
}
/**
* Get registered callback
*
* If not previously registered, checks to see if it exists in registered
* options.
*
* @return null|string|array
*/
public function getCallback()
{
if (null === $this->_callback) {
if (null !== ($callback = $this->getOption('callback'))) {
$this->setCallback($callback);
$this->removeOption('callback');
}
}
return $this->_callback;
}
/**
* Render
*
* If no callback registered, returns callback. Otherwise, gets return
* value of callback and either appends, prepends, or replaces passed in
* content.
*
* @param string $content
* @return string
*/
public function render($content)
{
$callback = $this->getCallback();
if (null === $callback) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$response = call_user_func($callback, $content, $this->getElement(), $this->getOptions());
switch ($placement) {
case self::APPEND:
return $content . $separator . $response;
case self::PREPEND:
return $response . $separator . $content;
default:
// replace content
return $response;
}
}
}
Form/Decorator/ViewHelper.php 0000604 00000016265 15071256135 0012167 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_ViewHelper
*
* Decorate an element by using a view helper to render it.
*
* Accepts the following options:
* - separator: string with which to separate passed in content and generated content
* - placement: whether to append or prepend the generated content to the passed in content
* - helper: the name of the view helper to use
*
* Assumes the view helper accepts three parameters, the name, value, and
* optional attributes; these will be provided by the element.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: ViewHelper.php 12374 2008-11-07 17:49:43Z matthew $
*/
class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
{
/**
* Element types that represent buttons
* @var array
*/
protected $_buttonTypes = array(
'Zend_Form_Element_Button',
'Zend_Form_Element_Reset',
'Zend_Form_Element_Submit',
);
/**
* View helper to use when rendering
* @var string
*/
protected $_helper;
/**
* Set view helper to use when rendering
*
* @param string $helper
* @return Zend_Form_Decorator_Element_ViewHelper
*/
public function setHelper($helper)
{
$this->_helper = (string) $helper;
return $this;
}
/**
* Retrieve view helper for rendering element
*
* @return string
*/
public function getHelper()
{
if (null === $this->_helper) {
$options = $this->getOptions();
if (isset($options['helper'])) {
$this->setHelper($options['helper']);
$this->removeOption('helper');
} else {
$element = $this->getElement();
if (null !== $element) {
if (null !== ($helper = $element->getAttrib('helper'))) {
$this->setHelper($helper);
} else {
$type = $element->getType();
if ($pos = strrpos($type, '_')) {
$type = substr($type, $pos + 1);
}
$this->setHelper('form' . ucfirst($type));
}
}
}
}
return $this->_helper;
}
/**
* Get name
*
* If element is a Zend_Form_Element, will attempt to namespace it if the
* element belongs to an array.
*
* @return string
*/
public function getName()
{
if (null === ($element = $this->getElement())) {
return '';
}
$name = $element->getName();
if (!$element instanceof Zend_Form_Element) {
return $name;
}
if (null !== ($belongsTo = $element->getBelongsTo())) {
$name = $belongsTo . '['
. $name
. ']';
}
if ($element->isArray()) {
$name .= '[]';
}
return $name;
}
/**
* Retrieve element attributes
*
* Set id to element name and/or array item.
*
* @return array
*/
public function getElementAttribs()
{
if (null === ($element = $this->getElement())) {
return null;
}
$attribs = $element->getAttribs();
if (isset($attribs['helper'])) {
unset($attribs['helper']);
}
if (method_exists($element, 'getSeparator')) {
if (null !== ($listsep = $element->getSeparator())) {
$attribs['listsep'] = $listsep;
}
}
if (isset($attribs['id'])) {
return $attribs;
}
$id = $element->getName();
if ($element instanceof Zend_Form_Element) {
if (null !== ($belongsTo = $element->getBelongsTo())) {
$belongsTo = preg_replace('/\[([^\]]+)\]/', '-$1', $belongsTo);
$id = $belongsTo . '-' . $id;
}
}
$element->setAttrib('id', $id);
$attribs['id'] = $id;
return $attribs;
}
/**
* Get value
*
* If element type is one of the button types, returns the label.
*
* @param Zend_Form_Element $element
* @return string|null
*/
public function getValue($element)
{
if (!$element instanceof Zend_Form_Element) {
return null;
}
foreach ($this->_buttonTypes as $type) {
if ($element instanceof $type) {
if (stristr($type, 'button')) {
$element->content = $element->getLabel();
return null;
}
return $element->getLabel();
}
}
return $element->getValue();
}
/**
* Render an element using a view helper
*
* Determine view helper from 'viewHelper' option, or, if none set, from
* the element type. Then call as
* helper($element->getName(), $element->getValue(), $element->getAttribs())
*
* @param string $content
* @return string
* @throws Zend_Form_Decorator_Exception if element or view are not registered
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
require_once 'Zend/Form/Decorator/Exception.php';
throw new Zend_Form_Decorator_Exception('ViewHelper decorator cannot render without a registered view object');
}
if (method_exists($element, 'getMultiOptions')) {
$element->getMultiOptions();
}
$helper = $this->getHelper();
$separator = $this->getSeparator();
$value = $this->getValue($element);
$attribs = $this->getElementAttribs();
$name = $element->getFullyQualifiedName();
$id = $element->getId();
$attribs['id'] = $id;
$elementContent = $view->$helper($name, $value, $attribs, $element->options);
switch ($this->getPlacement()) {
case self::APPEND:
return $content . $separator . $elementContent;
case self::PREPEND:
return $elementContent . $separator . $content;
default:
return $elementContent;
}
}
}
Form/Decorator/Form.php 0000604 00000007611 15071256135 0011013 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Form
*
* Render a Zend_Form object.
*
* Accepts following options:
* - separator: Separator to use between elements
* - helper: which view helper to use when rendering form. Should accept three
* arguments, string content, a name, and an array of attributes.
*
* Any other options passed will be used as HTML attributes of the form tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Form.php 10014 2008-07-10 00:51:54Z matthew $
*/
class Zend_Form_Decorator_Form extends Zend_Form_Decorator_Abstract
{
/**
* Default view helper
* @var string
*/
protected $_helper = 'form';
/**
* Set view helper for rendering form
*
* @param string $helper
* @return Zend_Form_Decorator_Form
*/
public function setHelper($helper)
{
$this->_helper = (string) $helper;
return $this;
}
/**
* Get view helper for rendering form
*
* @return string
*/
public function getHelper()
{
if (null !== ($helper = $this->getOption('helper'))) {
$this->setHelper($helper);
$this->removeOption('helper');
}
return $this->_helper;
}
/**
* Retrieve decorator options
*
* Assures that form action and method are set, and sets appropriate
* encoding type if current method is POST.
*
* @return array
*/
public function getOptions()
{
if (null !== ($element = $this->getElement())) {
if ($element instanceof Zend_Form) {
$element->getAction();
$method = $element->getMethod();
if ($method == Zend_Form::METHOD_POST) {
$this->setOption('enctype', 'application/x-www-form-urlencoded');
}
foreach ($element->getAttribs() as $key => $value) {
$this->setOption($key, $value);
}
} elseif ($element instanceof Zend_Form_DisplayGroup) {
foreach ($element->getAttribs() as $key => $value) {
$this->setOption($key, $value);
}
}
}
if (isset($this->_options['method'])) {
$this->_options['method'] = strtolower($this->_options['method']);
}
return $this->_options;
}
/**
* Render a form
*
* Replaces $content entirely from currently set element.
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
$view = $form->getView();
if (null === $view) {
return $content;
}
$helper = $this->getHelper();
$attribs = $this->getOptions();
$name = $form->getFullyQualifiedName();
$attribs['id'] = $form->getId();
return $view->$helper($name, $attribs, $content);
}
}
Form/Decorator/DtDdWrapper.php 0000604 00000003326 15071256135 0012267 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_DtDdWrapper
*
* Creates an empty <dt> item, and wraps the content in a <dd>. Used as a
* default decorator for subforms and display groups.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: DtDdWrapper.php 9309 2008-04-25 16:06:59Z matthew $
*/
class Zend_Form_Decorator_DtDdWrapper extends Zend_Form_Decorator_Abstract
{
/**
* Default placement: surround content
* @var string
*/
protected $_placement = null;
/**
* Render
*
* Renders as the following:
* <dt></dt>
* <dd>$content</dd>
*
* @param string $content
* @return string
*/
public function render($content)
{
return '<dt> </dt><dd>' . $content . '</dd>';
}
}
Form/Decorator/Errors.php 0000604 00000004037 15071256135 0011363 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Errors
*
* Any options passed will be used as HTML attributes of the ul tag for the errors.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Errors.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Decorator_Errors extends Zend_Form_Decorator_Abstract
{
/**
* Render errors
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$errors = $element->getMessages();
if (empty($errors)) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$errors = $view->formErrors($errors, $this->getOptions());
switch ($placement) {
case self::APPEND:
return $content . $separator . $errors;
case self::PREPEND:
return $errors . $separator . $content;
}
}
}
Form/Decorator/File.php 0000604 00000007052 15071256135 0010766 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_File
*
* Fixes the rendering for all subform and multi file elements
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: $
*/
class Zend_Form_Decorator_File extends Zend_Form_Decorator_Abstract
{
/**
* Attributes that should not be passed to helper
* @var array
*/
protected $_attribBlacklist = array('helper', 'placement', 'separator', 'value');
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* Get attributes to pass to file helper
*
* @return array
*/
public function getAttribs()
{
$attribs = $this->getOptions();
if (null !== ($element = $this->getElement())) {
$attribs = array_merge($attribs, $element->getAttribs());
}
foreach ($this->_attribBlacklist as $key) {
if (array_key_exists($key, $attribs)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Render a form file
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
if (!$element instanceof Zend_Form_Element) {
return $content;
}
$view = $element->getView();
if (!$view instanceof Zend_View_Interface) {
return $content;
}
$name = $element->getName();
$attribs = $this->getAttribs();
if (!array_key_exists('id', $attribs)) {
$attribs['id'] = $name;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$markup = array();
$size = $element->getMaxFileSize();
if ($size > 0) {
$element->setMaxFileSize(0);
$markup[] = $view->formHidden('MAX_FILE_SIZE', $size);
}
if ($element->isArray()) {
$name .= "[]";
$count = $element->getMultiFile();
for ($i = 0; $i < $count; ++$i) {
$htmlAttribs = $attribs;
$htmlAttribs['id'] .= '-' . $i;
$markup[] = $view->formFile($name, $htmlAttribs);
}
} else {
$markup[] = $view->formFile($name, $attribs);
}
$markup = implode($separator, $markup);
switch ($placement) {
case self::PREPEND:
return $markup . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $markup;
}
}
}
Form/Decorator/Fieldset.php 0000604 00000007745 15071256135 0011657 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Fieldset
*
* Any options passed will be used as HTML attributes of the fieldset tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Fieldset.php 10689 2008-08-05 17:00:54Z matthew $
*/
class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
{
/**
* Attribs that should be removed prior to rendering
* @var array
*/
public $stripAttribs = array(
'action',
'enctype',
'helper',
'method',
'name',
);
/**
* Fieldset legend
* @var string
*/
protected $_legend;
/**
* Default placement: surround content
* @var string
*/
protected $_placement = null;
/**
* Get options
*
* Merges in element attributes as well.
*
* @return array
*/
public function getOptions()
{
$options = parent::getOptions();
if (null !== ($element = $this->getElement())) {
$attribs = $element->getAttribs();
$options = array_merge($options, $attribs);
$this->setOptions($options);
}
return $options;
}
/**
* Set legend
*
* @param string $value
* @return Zend_Form_Decorator_Fieldset
*/
public function setLegend($value)
{
$this->_legend = (string) $value;
return $this;
}
/**
* Get legend
*
* @return string
*/
public function getLegend()
{
$legend = $this->_legend;
if ((null === $legend) && (null !== ($element = $this->getElement()))) {
if (method_exists($element, 'getLegend')) {
$legend = $element->getLegend();
$this->setLegend($legend);
}
}
if ((null === $legend) && (null !== ($legend = $this->getOption('legend')))) {
$this->setLegend($legend);
$this->removeOption('legend');
}
return $legend;
}
/**
* Render a fieldset
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$legend = $this->getLegend();
$attribs = $this->getOptions();
$name = $element->getFullyQualifiedName();
$id = $element->getId();
if (!empty($id)) {
$attribs['id'] = 'fieldset-' . $id;
}
if (null !== $legend) {
if (null !== ($translator = $element->getTranslator())) {
$legend = $translator->translate($legend);
}
$attribs['legend'] = $legend;
}
foreach (array_keys($attribs) as $attrib) {
$testAttrib = strtolower($attrib);
if (in_array($testAttrib, $this->stripAttribs)) {
unset($attribs[$attrib]);
}
}
return $view->fieldset($name, $content, $attribs);
}
}
Form/Decorator/Captcha.php 0000604 00000004014 15071256135 0011445 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Captcha generic decorator
*
* Adds captcha adapter output
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: $
*/
class Zend_Form_Decorator_Captcha extends Zend_Form_Decorator_Abstract
{
/**
* Render captcha
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
if (!method_exists($element, 'getCaptcha')) {
return $content;
}
$view = $element->getView();
if (null === $view) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$captcha = $element->getCaptcha();
$markup = $captcha->render($view, $element);
switch ($placement) {
case 'PREPEND':
$content = $markup . $separator . $content;
break;
case 'APPEND':
default:
$content = $content . $separator . $markup;
}
return $content;
}
}
Form/Decorator/FormErrors.php 0000604 00000026175 15071256135 0012216 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_FormErrors
*
* Displays all form errors in one view.
*
* Any options passed will be used as HTML attributes of the ul tag for the errors.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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$
*/
class Zend_Form_Decorator_FormErrors extends Zend_Form_Decorator_Abstract
{
/**
* Default values for markup options
* @var array
*/
protected $_defaults = array(
'ignoreSubForms' => false,
'markupElementLabelEnd' => '</b>',
'markupElementLabelStart' => '<b>',
'markupListEnd' => '</ul>',
'markupListItemEnd' => '</li>',
'markupListItemStart' => '<li>',
'markupListStart' => '<ul class="form-errors">',
);
/**#@+
* Markup options
* @var string
*/
protected $_ignoreSubForms;
protected $_markupElementLabelEnd;
protected $_markupElementLabelStart;
protected $_markupListEnd;
protected $_markupListItemEnd;
protected $_markupListItemStart;
protected $_markupListStart;
/**#@-*/
/**
* Render errors
*
* @param string $content
* @return string
*/
public function render($content)
{
$form = $this->getElement();
if (!$form instanceof Zend_Form) {
return $content;
}
$view = $form->getView();
if (null === $view) {
return $content;
}
$this->initOptions();
$markup = $this->_recurseForm($form, $view);
if (empty($markup)) {
return $content;
}
$markup = $this->getMarkupListStart()
. $markup
. $this->getMarkupListEnd();
switch ($this->getPlacement()) {
case self::APPEND:
return $content . $this->getSeparator() . $markup;
case self::PREPEND:
return $markup . $this->getSeparator() . $content;
}
}
/**
* Initialize options
*
* @return void
*/
public function initOptions()
{
$this->getMarkupElementLabelEnd();
$this->getMarkupElementLabelStart();
$this->getMarkupListEnd();
$this->getMarkupListItemEnd();
$this->getMarkupListItemStart();
$this->getMarkupListStart();
$this->getPlacement();
$this->getSeparator();
$this->ignoreSubForms();
}
/**
* Retrieve markupElementLabelStart
*
* @return string
*/
public function getMarkupElementLabelStart()
{
if (null === $this->_markupElementLabelStart) {
if (null === ($markupElementLabelStart = $this->getOption('markupElementLabelStart'))) {
$this->setMarkupElementLabelStart($this->_defaults['markupElementLabelStart']);
} else {
$this->setMarkupElementLabelStart($markupElementLabelStart);
$this->removeOption('markupElementLabelStart');
}
}
return $this->_markupElementLabelStart;
}
/**
* Set markupElementLabelStart
*
* @param string $markupElementLabelStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupElementLabelStart($markupElementLabelStart)
{
$this->_markupElementLabelStart = $markupElementLabelStart;
return $this;
}
/**
* Retrieve markupElementLabelEnd
*
* @return string
*/
public function getMarkupElementLabelEnd()
{
if (null === $this->_markupElementLabelEnd) {
if (null === ($markupElementLabelEnd = $this->getOption('markupElementLabelEnd'))) {
$this->setMarkupElementLabelEnd($this->_defaults['markupElementLabelEnd']);
} else {
$this->setMarkupElementLabelEnd($markupElementLabelEnd);
$this->removeOption('markupElementLabelEnd');
}
}
return $this->_markupElementLabelEnd;
}
/**
* Set markupElementLabelEnd
*
* @param string $markupElementLabelEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupElementLabelEnd($markupElementLabelEnd)
{
$this->_markupElementLabelEnd = $markupElementLabelEnd;
return $this;
}
/**
* Retrieve markupListStart
*
* @return string
*/
public function getMarkupListStart()
{
if (null === $this->_markupListStart) {
if (null === ($markupListStart = $this->getOption('markupListStart'))) {
$this->setMarkupListStart($this->_defaults['markupListStart']);
} else {
$this->setMarkupListStart($markupListStart);
$this->removeOption('markupListStart');
}
}
return $this->_markupListStart;
}
/**
* Set markupListStart
*
* @param string $markupListStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListStart($markupListStart)
{
$this->_markupListStart = $markupListStart;
return $this;
}
/**
* Retrieve markupListEnd
*
* @return string
*/
public function getMarkupListEnd()
{
if (null === $this->_markupListEnd) {
if (null === ($markupListEnd = $this->getOption('markupListEnd'))) {
$this->setMarkupListEnd($this->_defaults['markupListEnd']);
} else {
$this->setMarkupListEnd($markupListEnd);
$this->removeOption('markupListEnd');
}
}
return $this->_markupListEnd;
}
/**
* Set markupListEnd
*
* @param string $markupListEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListEnd($markupListEnd)
{
$this->_markupListEnd = $markupListEnd;
return $this;
}
/**
* Retrieve markupListItemStart
*
* @return string
*/
public function getMarkupListItemStart()
{
if (null === $this->_markupListItemStart) {
if (null === ($markupListItemStart = $this->getOption('markupListItemStart'))) {
$this->setMarkupListItemStart($this->_defaults['markupListItemStart']);
} else {
$this->setMarkupListItemStart($markupListItemStart);
$this->removeOption('markupListItemStart');
}
}
return $this->_markupListItemStart;
}
/**
* Set markupListItemStart
*
* @param string $markupListItemStart
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListItemStart($markupListItemStart)
{
$this->_markupListItemStart = $markupListItemStart;
return $this;
}
/**
* Retrieve markupListItemEnd
*
* @return string
*/
public function getMarkupListItemEnd()
{
if (null === $this->_markupListItemEnd) {
if (null === ($markupListItemEnd = $this->getOption('markupListItemEnd'))) {
$this->setMarkupListItemEnd($this->_defaults['markupListItemEnd']);
} else {
$this->setMarkupListItemEnd($markupListItemEnd);
$this->removeOption('markupListItemEnd');
}
}
return $this->_markupListItemEnd;
}
/**
* Set markupListItemEnd
*
* @param string $markupListItemEnd
* @return Zend_Form_Decorator_FormErrors
*/
public function setMarkupListItemEnd($markupListItemEnd)
{
$this->_markupListItemEnd = $markupListItemEnd;
return $this;
}
/**
* Retrieve ignoreSubForms
*
* @return bool
*/
public function ignoreSubForms()
{
if (null === $this->_ignoreSubForms) {
if (null === ($ignoreSubForms = $this->getOption('ignoreSubForms'))) {
$this->setIgnoreSubForms($this->_defaults['ignoreSubForms']);
} else {
$this->setIgnoreSubForms($ignoreSubForms);
$this->removeOption('ignoreSubForms');
}
}
return $this->_ignoreSubForms;
}
/**
* Set ignoreSubForms
*
* @param bool $ignoreSubForms
* @return Zend_Form_Decorator_FormErrors
*/
public function setIgnoreSubForms($ignoreSubForms)
{
$this->_ignoreSubForms = (bool) $ignoreSubForms;
return $this;
}
/**
* Render element label
*
* @param Zend_Form_Element $element
* @param Zend_View_Interface $view
* @return string
*/
public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view)
{
$label = $element->getLabel();
if (empty($label)) {
$label = $element->getName();
}
return $this->getMarkupElementLabelStart()
. $view->escape($label)
. $this->getMarkupElementLabelEnd();
}
/**
* Recurse through a form object, rendering errors
*
* @param Zend_Form $form
* @param Zend_View_Interface $view
* @return string
*/
protected function _recurseForm(Zend_Form $form, Zend_View_Interface $view)
{
$content = '';
$errors = $form->getMessages();
if ($form instanceof Zend_Form_SubForm) {
$name = $form->getName();
if ((1 == count($errors)) && array_key_exists($name, $errors)) {
$errors = $errors[$name];
}
}
if (empty($errors)) {
return $content;
}
foreach ($errors as $name => $list) {
$element = $form->$name;
if ($element instanceof Zend_Form_Element) {
$element->setView($view);
$content .= $this->getMarkupListItemStart()
. $this->renderLabel($element, $view)
. $view->formErrors($list, $this->getOptions())
. $this->getMarkupListItemEnd();
} elseif (!$this->ignoreSubForms() && ($element instanceof Zend_Form)) {
$content .= $this->getMarkupListStart()
. $this->_recurseForm($element, $view)
. $this->getMarkupListEnd();
}
}
return $content;
}
}
Form/Decorator/HtmlTag.php 0000604 00000014100 15071256135 0011437 0 ustar 00 <?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_Form
* @subpackage Decorator
* @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 Zend_Form_Decorator_Abstract
*/
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Element_HtmlTag
*
* Wraps content in an HTML block tag.
*
* Options accepted are:
* - tag: tag to use in decorator
* - noAttribs: do not render attributes in the opening tag
* - placement: 'append' or 'prepend'. If 'append', renders opening and
* closing tag after content; if prepend, renders opening and closing tag
* before content.
* - openOnly: render opening tag only
* - closeOnly: render closing tag only
*
* Any other options passed are processed as HTML attributes of the tag.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: HtmlTag.php 12514 2008-11-10 16:30:24Z matthew $
*/
class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
{
/**
* Placement; default to surround content
* @var string
*/
protected $_placement = null;
/**
* HTML tag to use
* @var string
*/
protected $_tag;
/**
* @var Zend_Filter
*/
protected $_tagFilter;
/**
* Convert options to tag attributes
*
* @return string
*/
protected function _htmlAttribs(array $attribs)
{
$xhtml = '';
foreach ((array) $attribs as $key => $val) {
$key = htmlspecialchars($key, ENT_COMPAT, 'UTF-8');
if (is_array($val)) {
$val = implode(' ', $val);
}
$val = htmlspecialchars($val, ENT_COMPAT, 'UTF-8');
$xhtml .= " $key=\"$val\"";
}
return $xhtml;
}
/**
* Normalize tag
*
* Ensures tag is alphanumeric characters only, and all lowercase.
*
* @param string $tag
* @return string
*/
public function normalizeTag($tag)
{
if (!isset($this->_tagFilter)) {
require_once 'Zend/Filter.php';
require_once 'Zend/Filter/Alnum.php';
require_once 'Zend/Filter/StringToLower.php';
$this->_tagFilter = new Zend_Filter();
$this->_tagFilter->addFilter(new Zend_Filter_Alnum())
->addFilter(new Zend_Filter_StringToLower());
}
return $this->_tagFilter->filter($tag);
}
/**
* Set tag to use
*
* @param string $tag
* @return Zend_Form_Decorator_HtmlTag
*/
public function setTag($tag)
{
$this->_tag = $this->normalizeTag($tag);
return $this;
}
/**
* Get tag
*
* If no tag is registered, either via setTag() or as an option, uses 'div'.
*
* @return string
*/
public function getTag()
{
if (null === $this->_tag) {
if (null === ($tag = $this->getOption('tag'))) {
$this->setTag('div');
} else {
$this->setTag($tag);
$this->removeOption('tag');
}
}
return $this->_tag;
}
/**
* Get the formatted open tag
*
* @param string $tag
* @param array $attribs
* @return string
*/
protected function _getOpenTag($tag, array $attribs = null)
{
$html = '<' . $tag;
if (null !== $attribs) {
$html .= $this->_htmlAttribs($attribs);
}
$html .= '>';
return $html;
}
/**
* Get formatted closing tag
*
* @param string $tag
* @return string
*/
protected function _getCloseTag($tag)
{
return '</' . $tag . '>';
}
/**
* Render content wrapped in an HTML tag
*
* @param string $content
* @return string
*/
public function render($content)
{
$tag = $this->getTag();
$placement = $this->getPlacement();
$noAttribs = $this->getOption('noAttribs');
$openOnly = $this->getOption('openOnly');
$closeOnly = $this->getOption('closeOnly');
$this->removeOption('noAttribs');
$this->removeOption('openOnly');
$this->removeOption('closeOnly');
$attribs = null;
if (!$noAttribs) {
$attribs = $this->getOptions();
}
switch ($placement) {
case self::APPEND:
if ($closeOnly) {
return $content . $this->_getCloseTag($tag);
}
if ($openOnly) {
return $content . $this->_getOpenTag($tag, $attribs);
}
return $content
. $this->_getOpenTag($tag, $attribs)
. $this->_getCloseTag($tag);
case self::PREPEND:
if ($closeOnly) {
return $this->_getCloseTag($tag) . $content;
}
if ($openOnly) {
return $this->_getOpenTag($tag, $attribs) . $content;
}
return $this->_getOpenTag($tag, $attribs)
. $this->_getCloseTag($tag)
. $content;
default:
return (($openOnly || !$closeOnly) ? $this->_getOpenTag($tag, $attribs) : '')
. $content
. (($closeOnly || !$openOnly) ? $this->_getCloseTag($tag) : '');
}
}
}
Form/Decorator/Captcha/Word.php 0000604 00000004315 15071256135 0012364 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Word-based captcha decorator
*
* Adds hidden field for ID and text input field for captcha text
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: $
*/
class Zend_Form_Decorator_Captcha_Word extends Zend_Form_Decorator_Abstract
{
/**
* Render captcha
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$name = $element->getFullyQualifiedName();
$hiddenName = $name . '[id]';
$textName = $name . '[input]';
$placement = $this->getPlacement();
$separator = $this->getSeparator();
$hidden = $view->formHidden($hiddenName, $element->getValue(), $element->getAttribs());
$text = $view->formText($textName, '', $element->getAttribs());
switch ($placement) {
case 'PREPEND':
$content = $hidden . $separator . $text . $separator . $content;
break;
case 'APPEND':
default:
$content = $content . $separator . $hidden . $separator . $text;
}
return $content;
}
}
Form/Decorator/Description.php 0000604 00000012241 15071256135 0012366 0 ustar 00 <?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_Form
* @subpackage Decorator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Decorator_Abstract */
require_once 'Zend/Form/Decorator/Abstract.php';
/**
* Zend_Form_Decorator_Description
*
* Accepts the options:
* - separator: separator to use between label and content (defaults to PHP_EOL)
* - placement: whether to append or prepend label to content (defaults to prepend)
* - tag: if set, used to wrap the label in an additional HTML tag
* - class: if set, override default class used with HTML tag
* - escape: whether or not to escape description (true by default)
*
* Any other options passed will be used as HTML attributes of the HTML tag used.
*
* @category Zend
* @package Zend_Form
* @subpackage Decorator
* @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: Description.php 12328 2008-11-06 16:49:03Z matthew $
*/
class Zend_Form_Decorator_Description extends Zend_Form_Decorator_Abstract
{
/**
* Whether or not to escape the description
* @var bool
*/
protected $_escape;
/**
* Default placement: append
* @var string
*/
protected $_placement = 'APPEND';
/**
* HTML tag with which to surround description
* @var string
*/
protected $_tag;
/**
* Set HTML tag with which to surround description
*
* @param string $tag
* @return Zend_Form_Decorator_Description
*/
public function setTag($tag)
{
$this->_tag = (string) $tag;
return $this;
}
/**
* Get HTML tag, if any, with which to surround description
*
* @return string
*/
public function getTag()
{
if (null === $this->_tag) {
$tag = $this->getOption('tag');
if (null !== $tag) {
$this->removeOption('tag');
} else {
$tag = 'p';
}
$this->setTag($tag);
return $tag;
}
return $this->_tag;
}
/**
* Get class with which to define description
*
* Defaults to 'hint'
*
* @return string
*/
public function getClass()
{
$class = $this->getOption('class');
if (null === $class) {
$class = 'hint';
$this->setOption('class', $class);
}
return $class;
}
/**
* Set whether or not to escape description
*
* @param bool $flag
* @return Zend_Form_Decorator_Description
*/
public function setEscape($flag)
{
$this->_escape = (bool) $flag;
return $this;
}
/**
* Get escape flag
*
* @return true
*/
public function getEscape()
{
if (null === $this->_escape) {
if (null !== ($escape = $this->getOption('escape'))) {
$this->setEscape($escape);
$this->removeOption('escape');
} else {
$this->setEscape(true);
}
}
return $this->_escape;
}
/**
* Render a description
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}
$description = $element->getDescription();
$description = trim($description);
if (!empty($description) && (null !== ($translator = $element->getTranslator()))) {
$description = $translator->translate($description);
}
if (empty($description)) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$tag = $this->getTag();
$class = $this->getClass();
$escape = $this->getEscape();
$options = $this->getOptions();
if ($escape) {
$description = $view->escape($description);
}
if (!empty($tag)) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$options['tag'] = $tag;
$decorator = new Zend_Form_Decorator_HtmlTag($options);
$description = $decorator->render($description);
}
switch ($placement) {
case self::PREPEND:
return $description . $separator . $content;
case self::APPEND:
default:
return $content . $separator . $description;
}
}
}
Form/Exception.php 0000604 00000002135 15071256135 0010120 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @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_Form_Exception extends Zend_Exception
{
}
Form/Element.php 0000604 00000161501 15071256135 0007556 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Filter */
require_once 'Zend/Filter.php';
/** Zend_Validate_Interface */
require_once 'Zend/Validate/Interface.php';
/**
* Zend_Form_Element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Element.php 12787 2008-11-23 14:17:44Z matthew $
*/
class Zend_Form_Element implements Zend_Validate_Interface
{
/**
* Element Constants
*/
const DECORATOR = 'DECORATOR';
const FILTER = 'FILTER';
const VALIDATE = 'VALIDATE';
/**
* Default view helper to use
* @var string
*/
public $helper = 'formText';
/**
* 'Allow empty' flag
* @var bool
*/
protected $_allowEmpty = true;
/**
* Flag indicating whether or not to insert NotEmpty validator when element is required
* @var bool
*/
protected $_autoInsertNotEmptyValidator = true;
/**
* Array to which element belongs
* @var string
*/
protected $_belongsTo;
/**
* Element decorators
* @var array
*/
protected $_decorators = array();
/**
* Element description
* @var string
*/
protected $_description;
/**
* Should we disable loading the default decorators?
* @var bool
*/
protected $_disableLoadDefaultDecorators = false;
/**
* Custom error messages
* @var array
*/
protected $_errorMessages = array();
/**
* Validation errors
* @var array
*/
protected $_errors = array();
/**
* Element filters
* @var array
*/
protected $_filters = array();
/**
* Ignore flag (used when retrieving values at form level)
* @var bool
*/
protected $_ignore = false;
/**
* Does the element represent an array?
* @var bool
*/
protected $_isArray = false;
/**
* Is the error marked as in an invalid state?
* @var bool
*/
protected $_isError = false;
/**
* Element label
* @var string
*/
protected $_label;
/**
* Plugin loaders for filter and validator chains
* @var array
*/
protected $_loaders = array();
/**
* Formatted validation error messages
* @var array
*/
protected $_messages = array();
/**
* Element name
* @var string
*/
protected $_name;
/**
* Order of element
* @var int
*/
protected $_order;
/**
* Required flag
* @var bool
*/
protected $_required = false;
/**
* @var Zend_Translate
*/
protected $_translator;
/**
* Is translation disabled?
* @var bool
*/
protected $_translatorDisabled = false;
/**
* Element type
* @var string
*/
protected $_type;
/**
* Array of initialized validators
* @var array Validators
*/
protected $_validators = array();
/**
* Array of un-initialized validators
* @var array
*/
protected $_validatorRules = array();
/**
* Element value
* @var mixed
*/
protected $_value;
/**
* @var Zend_View_Interface
*/
protected $_view;
/**
* Constructor
*
* $spec may be:
* - string: name of element
* - array: options with which to configure element
* - Zend_Config: Zend_Config with options for configuring element
*
* @param string|array|Zend_Config $spec
* @return void
* @throws Zend_Form_Exception if no element name after initialization
*/
public function __construct($spec, $options = null)
{
if (is_string($spec)) {
$this->setName($spec);
} elseif (is_array($spec)) {
$this->setOptions($spec);
} elseif ($spec instanceof Zend_Config) {
$this->setConfig($spec);
}
if (is_string($spec) && is_array($options)) {
$this->setOptions($options);
} elseif (is_string($spec) && ($options instanceof Zend_Config)) {
$this->setConfig($options);
}
if (null === $this->getName()) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Zend_Form_Element requires each element to have a name');
}
/**
* Extensions
*/
$this->init();
/**
* Register ViewHelper decorator by default
*/
$this->loadDefaultDecorators();
}
/**
* Initialize object; used by extending classes
*
* @return void
*/
public function init()
{
}
/**
* Set flag to disable loading default decorators
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setDisableLoadDefaultDecorators($flag)
{
$this->_disableLoadDefaultDecorators = (bool) $flag;
return $this;
}
/**
* Should we load the default decorators?
*
* @return bool
*/
public function loadDefaultDecoratorsIsDisabled()
{
return $this->_disableLoadDefaultDecorators;
}
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set object state from options array
*
* @param array $options
* @return Zend_Form_Element
*/
public function setOptions(array $options)
{
if (isset($options['prefixPath'])) {
$this->addPrefixPaths($options['prefixPath']);
unset($options['prefixPath']);
}
if (isset($options['disableTranslator'])) {
$this->setDisableTranslator($options['disableTranslator']);
unset($options['disableTranslator']);
}
unset($options['options']);
unset($options['config']);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, array('setTranslator', 'setPluginLoader', 'setView'))) {
if (!is_object($value)) {
continue;
}
}
if (method_exists($this, $method)) {
// Setter exists; use it
$this->$method($value);
} else {
// Assume it's metadata
$this->setAttrib($key, $value);
}
}
return $this;
}
/**
* Set object state from Zend_Config object
*
* @param Zend_Config $config
* @return Zend_Form_Element
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
// Localization:
/**
* Set translator object for localization
*
* @param Zend_Translate|null $translator
* @return Zend_Form_Element
*/
public function setTranslator($translator = null)
{
if (null === $translator) {
$this->_translator = null;
} elseif ($translator instanceof Zend_Translate_Adapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid translator specified');
}
return $this;
}
/**
* Retrieve localization translator object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
if (null === $this->_translator) {
require_once 'Zend/Form.php';
return Zend_Form::getDefaultTranslator();
}
return $this->_translator;
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setDisableTranslator($flag)
{
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
return $this->_translatorDisabled;
}
// Metadata
/**
* Filter a name to only allow valid variable characters
*
* @param string $value
* @param bool $allowBrackets
* @return string
*/
public function filterName($value, $allowBrackets = false)
{
$charset = '^a-zA-Z0-9_\x7f-\xff';
if ($allowBrackets) {
$charset .= '\[\]';
}
return preg_replace('/[' . $charset . ']/', '', (string) $value);
}
/**
* Set element name
*
* @param string $name
* @return Zend_Form_Element
*/
public function setName($name)
{
$name = $this->filterName($name);
if ('' === $name) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty');
}
$this->_name = $name;
return $this;
}
/**
* Return element name
*
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* Get fully qualified name
*
* Places name as subitem of array and/or appends brackets.
*
* @return string
*/
public function getFullyQualifiedName()
{
$name = $this->getName();
if (null !== ($belongsTo = $this->getBelongsTo())) {
$name = $belongsTo . '[' . $name . ']';
}
if ($this->isArray()) {
$name .= '[]';
}
return $name;
}
/**
* Get element id
*
* @return string
*/
public function getId()
{
if (isset($this->id)) {
return $this->id;
}
$id = $this->getFullyQualifiedName();
// Bail early if no array notation detected
if (!strstr($id, '[')) {
return $id;
}
// Strip array notation
if ('[]' == substr($id, -2)) {
$id = substr($id, 0, strlen($id) - 2);
}
$id = str_replace('][', '-', $id);
$id = str_replace(array(']', '['), '-', $id);
$id = trim($id, '-');
return $id;
}
/**
* Set element value
*
* @param mixed $value
* @return Zend_Form_Element
*/
public function setValue($value)
{
$this->_value = $value;
return $this;
}
/**
* Filter a value
*
* @param string $value
* @param string $key
* @return void
*/
protected function _filterValue(&$value, &$key)
{
foreach ($this->getFilters() as $filter) {
$value = $filter->filter($value);
}
}
/**
* Retrieve filtered element value
*
* @return mixed
*/
public function getValue()
{
$valueFiltered = $this->_value;
if ($this->isArray() && is_array($valueFiltered)) {
array_walk_recursive($valueFiltered, array($this, '_filterValue'));
} else {
$this->_filterValue($valueFiltered, $valueFiltered);
}
return $valueFiltered;
}
/**
* Retrieve unfiltered element value
*
* @return mixed
*/
public function getUnfilteredValue()
{
return $this->_value;
}
/**
* Set element label
*
* @param string $label
* @return Zend_Form_Element
*/
public function setLabel($label)
{
$this->_label = (string) $label;
return $this;
}
/**
* Retrieve element label
*
* @return string
*/
public function getLabel()
{
return $this->_label;
}
/**
* Set element order
*
* @param int $order
* @return Zend_Form_Element
*/
public function setOrder($order)
{
$this->_order = (int) $order;
return $this;
}
/**
* Retrieve element order
*
* @return int
*/
public function getOrder()
{
return $this->_order;
}
/**
* Set required flag
*
* @param bool $flag Default value is true
* @return Zend_Form_Element
*/
public function setRequired($flag = true)
{
$this->_required = (bool) $flag;
return $this;
}
/**
* Is the element required?
*
* @return bool
*/
public function isRequired()
{
return $this->_required;
}
/**
* Set flag indicating whether a NotEmpty validator should be inserted when element is required
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setAutoInsertNotEmptyValidator($flag)
{
$this->_autoInsertNotEmptyValidator = (bool) $flag;
return $this;
}
/**
* Get flag indicating whether a NotEmpty validator should be inserted when element is required
*
* @return bool
*/
public function autoInsertNotEmptyValidator()
{
return $this->_autoInsertNotEmptyValidator;
}
/**
* Set element description
*
* @param string $description
* @return Zend_Form_Element
*/
public function setDescription($description)
{
$this->_description = (string) $description;
return $this;
}
/**
* Retrieve element description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
/**
* Set 'allow empty' flag
*
* When the allow empty flag is enabled and the required flag is false, the
* element will validate with empty values.
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setAllowEmpty($flag)
{
$this->_allowEmpty = (bool) $flag;
return $this;
}
/**
* Get 'allow empty' flag
*
* @return bool
*/
public function getAllowEmpty()
{
return $this->_allowEmpty;
}
/**
* Set ignore flag (used when retrieving values at form level)
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setIgnore($flag)
{
$this->_ignore = (bool) $flag;
return $this;
}
/**
* Get ignore flag (used when retrieving values at form level)
*
* @return bool
*/
public function getIgnore()
{
return $this->_ignore;
}
/**
* Set flag indicating if element represents an array
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setIsArray($flag)
{
$this->_isArray = (bool) $flag;
return $this;
}
/**
* Is the element representing an array?
*
* @return bool
*/
public function isArray()
{
return $this->_isArray;
}
/**
* Set array to which element belongs
*
* @param string $array
* @return Zend_Form_Element
*/
public function setBelongsTo($array)
{
$array = $this->filterName($array, true);
if (!empty($array)) {
$this->_belongsTo = $array;
}
return $this;
}
/**
* Return array name to which element belongs
*
* @return string
*/
public function getBelongsTo()
{
return $this->_belongsTo;
}
/**
* Return element type
*
* @return string
*/
public function getType()
{
if (null === $this->_type) {
$this->_type = get_class($this);
}
return $this->_type;
}
/**
* Set element attribute
*
* @param string $name
* @param mixed $value
* @return Zend_Form_Element
* @throws Zend_Form_Exception for invalid $name values
*/
public function setAttrib($name, $value)
{
$name = (string) $name;
if ('_' == $name[0]) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid attribute "%s"; must not contain a leading underscore', $name));
}
if (null === $value) {
unset($this->$name);
} else {
$this->$name = $value;
}
return $this;
}
/**
* Set multiple attributes at once
*
* @param array $attribs
* @return Zend_Form_Element
*/
public function setAttribs(array $attribs)
{
foreach ($attribs as $key => $value) {
$this->setAttrib($key, $value);
}
return $this;
}
/**
* Retrieve element attribute
*
* @param string $name
* @return string
*/
public function getAttrib($name)
{
$name = (string) $name;
if (isset($this->$name)) {
return $this->$name;
}
return null;
}
/**
* Return all attributes
*
* @return array
*/
public function getAttribs()
{
$attribs = get_object_vars($this);
foreach ($attribs as $key => $value) {
if ('_' == substr($key, 0, 1)) {
unset($attribs[$key]);
}
}
return $attribs;
}
/**
* Overloading: retrieve object property
*
* Prevents access to properties beginning with '_'.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if ('_' == $key[0]) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Cannot retrieve value for protected/private property "%s"', $key));
}
if (!isset($this->$key)) {
return null;
}
return $this->$key;
}
/**
* Overloading: set object property
*
* @param string $key
* @param mixed $value
* @return voide
*/
public function __set($key, $value)
{
$this->setAttrib($key, $value);
}
/**
* Overloading: allow rendering specific decorators
*
* Call renderDecoratorName() to render a specific decorator.
*
* @param string $method
* @param array $args
* @return string
* @throws Zend_Form_Exception for invalid decorator or invalid method call
*/
public function __call($method, $args)
{
if ('render' == substr($method, 0, 6)) {
$decoratorName = substr($method, 6);
if (false !== ($decorator = $this->getDecorator($decoratorName))) {
$decorator->setElement($this);
$seed = '';
if (0 < count($args)) {
$seed = array_shift($args);
}
return $decorator->render($seed);
}
require_once 'Zend/Form/Element/Exception.php';
throw new Zend_Form_Element_Exception(sprintf('Decorator by name %s does not exist', $decoratorName));
}
require_once 'Zend/Form/Element/Exception.php';
throw new Zend_Form_Element_Exception(sprintf('Method %s does not exist', $method));
}
// Loaders
/**
* Set plugin loader to use for validator or filter chain
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type 'decorator', 'filter', or 'validate'
* @return Zend_Form_Element
* @throws Zend_Form_Exception on invalid type
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
{
$type = strtoupper($type);
switch ($type) {
case self::DECORATOR:
case self::FILTER:
case self::VALIDATE:
$this->_loaders[$type] = $loader;
return $this;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));
}
}
/**
* Retrieve plugin loader for validator or filter chain
*
* Instantiates with default rules if none available for that type. Use
* 'decorator', 'filter', or 'validate' for $type.
*
* @param string $type
* @return Zend_Loader_PluginLoader
* @throws Zend_Loader_Exception on invalid type.
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
switch ($type) {
case self::FILTER:
case self::VALIDATE:
$prefixSegment = ucfirst(strtolower($type));
$pathSegment = $prefixSegment;
case self::DECORATOR:
if (!isset($prefixSegment)) {
$prefixSegment = 'Form_Decorator';
$pathSegment = 'Form/Decorator';
}
if (!isset($this->_loaders[$type])) {
require_once 'Zend/Loader/PluginLoader.php';
$this->_loaders[$type] = new Zend_Loader_PluginLoader(
array('Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/')
);
}
return $this->_loaders[$type];
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
}
/**
* Add prefix path for plugin loader
*
* If no $type specified, assumes it is a base path for both filters and
* validators, and sets each according to the following rules:
* - decorators: $prefix = $prefix . '_Decorator'
* - filters: $prefix = $prefix . '_Filter'
* - validators: $prefix = $prefix . '_Validate'
*
* Otherwise, the path prefix is set on the appropriate plugin loader.
*
* @param string $path
* @return Zend_Form_Element
* @throws Zend_Form_Exception for invalid type
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case self::DECORATOR:
case self::FILTER:
case self::VALIDATE:
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
case null:
$prefix = rtrim($prefix, '_');
$path = rtrim($path, DIRECTORY_SEPARATOR);
foreach (array(self::DECORATOR, self::FILTER, self::VALIDATE) as $type) {
$cType = ucfirst(strtolower($type));
$pluginPath = $path . DIRECTORY_SEPARATOR . $cType . DIRECTORY_SEPARATOR;
$pluginPrefix = $prefix . '_' . $cType;
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
}
return $this;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
}
/**
* Add many prefix paths at once
*
* @param array $spec
* @return Zend_Form_Element
*/
public function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
return $this->addPrefixPath($spec['prefix'], $spec['path']);
}
foreach ($spec as $type => $paths) {
if (is_numeric($type) && is_array($paths)) {
$type = null;
if (isset($paths['prefix']) && isset($paths['path'])) {
if (isset($paths['type'])) {
$type = $paths['type'];
}
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
} elseif (!is_numeric($type)) {
if (!isset($paths['prefix']) || !isset($paths['path'])) {
foreach ($paths as $prefix => $spec) {
if (is_array($spec)) {
foreach ($spec as $path) {
if (!is_string($path)) {
continue;
}
$this->addPrefixPath($prefix, $path, $type);
}
} elseif (is_string($spec)) {
$this->addPrefixPath($prefix, $spec, $type);
}
}
} else {
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
}
}
return $this;
}
// Validation
/**
* Add validator to validation chain
*
* Note: will overwrite existing validators if they are of the same class.
*
* @param string|Zend_Validate_Interface $validator
* @param bool $breakChainOnFailure
* @param array $options
* @return Zend_Form_Element
* @throws Zend_Form_Exception if invalid validator type
*/
public function addValidator($validator, $breakChainOnFailure = false, $options = array())
{
if ($validator instanceof Zend_Validate_Interface) {
$name = get_class($validator);
if (!isset($validator->zfBreakChainOnFailure)) {
$validator->zfBreakChainOnFailure = $breakChainOnFailure;
}
} elseif (is_string($validator)) {
$name = $validator;
$validator = array(
'validator' => $validator,
'breakChainOnFailure' => $breakChainOnFailure,
'options' => $options,
);
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid validator provided to addValidator; must be string or Zend_Validate_Interface');
}
$this->_validators[$name] = $validator;
return $this;
}
/**
* Add multiple validators
*
* @param array $validators
* @return Zend_Form_Element
*/
public function addValidators(array $validators)
{
foreach ($validators as $validatorInfo) {
if (is_string($validatorInfo)) {
$this->addValidator($validatorInfo);
} elseif ($validatorInfo instanceof Zend_Validate_Interface) {
$this->addValidator($validatorInfo);
} elseif (is_array($validatorInfo)) {
$argc = count($validatorInfo);
$breakChainOnFailure = false;
$options = array();
if (isset($validatorInfo['validator'])) {
$validator = $validatorInfo['validator'];
if (isset($validatorInfo['breakChainOnFailure'])) {
$breakChainOnFailure = $validatorInfo['breakChainOnFailure'];
}
if (isset($validatorInfo['options'])) {
$options = $validatorInfo['options'];
}
$this->addValidator($validator, $breakChainOnFailure, $options);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$validator = array_shift($validatorInfo);
case (2 <= $argc):
$breakChainOnFailure = array_shift($validatorInfo);
case (3 <= $argc):
$options = array_shift($validatorInfo);
default:
$this->addValidator($validator, $breakChainOnFailure, $options);
break;
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid validator passed to addValidators()');
}
}
return $this;
}
/**
* Set multiple validators, overwriting previous validators
*
* @param array $validators
* @return Zend_Form_Element
*/
public function setValidators(array $validators)
{
$this->clearValidators();
return $this->addValidators($validators);
}
/**
* Retrieve a single validator by name
*
* @param string $name
* @return Zend_Validate_Interface|false False if not found, validator otherwise
*/
public function getValidator($name)
{
if (!isset($this->_validators[$name])) {
$len = strlen($name);
foreach ($this->_validators as $localName => $validator) {
if ($len > strlen($localName)) {
continue;
}
if (0 === substr_compare($localName, $name, -$len, $len, true)) {
if (is_array($validator)) {
return $this->_loadValidator($validator);
}
return $validator;
}
}
return false;
}
if (is_array($this->_validators[$name])) {
return $this->_loadValidator($this->_validators[$name]);
}
return $this->_validators[$name];
}
/**
* Retrieve all validators
*
* @return array
*/
public function getValidators()
{
$validators = array();
foreach ($this->_validators as $key => $value) {
if ($value instanceof Zend_Validate_Interface) {
$validators[$key] = $value;
continue;
}
$validator = $this->_loadValidator($value);
$validators[get_class($validator)] = $validator;
}
return $validators;
}
/**
* Remove a single validator by name
*
* @param string $name
* @return bool
*/
public function removeValidator($name)
{
if (isset($this->_validators[$name])) {
unset($this->_validators[$name]);
} else {
$len = strlen($name);
foreach (array_keys($this->_validators) as $validator) {
if ($len > strlen($validator)) {
continue;
}
if (0 === substr_compare($validator, $name, -$len, $len, true)) {
unset($this->_validators[$validator]);
break;
}
}
}
return $this;
}
/**
* Clear all validators
*
* @return Zend_Form_Element
*/
public function clearValidators()
{
$this->_validators = array();
return $this;
}
/**
* Validate element value
*
* If a translation adapter is registered, any error messages will be
* translated according to the current locale, using the given error code;
* if no matching translation is found, the original message will be
* utilized.
*
* Note: The *filtered* value is validated.
*
* @param mixed $value
* @param mixed $context
* @return boolean
*/
public function isValid($value, $context = null)
{
$this->setValue($value);
$value = $this->getValue();
if ((('' === $value) || (null === $value))
&& !$this->isRequired()
&& $this->getAllowEmpty()
) {
return true;
}
if ($this->isRequired()
&& $this->autoInsertNotEmptyValidator()
&& !$this->getValidator('NotEmpty'))
{
$validators = $this->getValidators();
$notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
array_unshift($validators, $notEmpty);
$this->setValidators($validators);
}
$this->_messages = array();
$this->_errors = array();
$result = true;
$translator = $this->getTranslator();
$isArray = $this->isArray();
foreach ($this->getValidators() as $key => $validator) {
if (method_exists($validator, 'setTranslator')) {
$validator->setTranslator($translator);
}
if ($isArray && is_array($value)) {
$messages = array();
$errors = array();
foreach ($value as $val) {
if (!$validator->isValid($val, $context)) {
$result = false;
if ($this->_hasErrorMessages()) {
$messages = $this->_getErrorMessages();
$errors = $messages;
} else {
$messages = array_merge($messages, $validator->getMessages());
$errors = array_merge($errors, $validator->getErrors());
}
}
}
if ($result) {
continue;
}
} elseif ($validator->isValid($value, $context)) {
continue;
} else {
$result = false;
if ($this->_hasErrorMessages()) {
$messages = $this->_getErrorMessages();
$errors = $messages;
} else {
$messages = $validator->getMessages();
$errors = array_keys($messages);
}
}
$result = false;
$this->_messages = array_merge($this->_messages, $messages);
$this->_errors = array_merge($this->_errors, $errors);
if ($validator->zfBreakChainOnFailure) {
break;
}
}
return $result;
}
/**
* Add a custom error message to return in the event of failed validation
*
* @param string $message
* @return Zend_Form_Element
*/
public function addErrorMessage($message)
{
$this->_errorMessages[] = (string) $message;
return $this;
}
/**
* Add multiple custom error messages to return in the event of failed validation
*
* @param array $messages
* @return Zend_Form_Element
*/
public function addErrorMessages(array $messages)
{
foreach ($messages as $message) {
$this->addErrorMessage($message);
}
return $this;
}
/**
* Same as addErrorMessages(), but clears custom error message stack first
*
* @param array $messages
* @return Zend_Form_Element
*/
public function setErrorMessages(array $messages)
{
$this->clearErrorMessages();
return $this->addErrorMessages($messages);
}
/**
* Retrieve custom error messages
*
* @return array
*/
public function getErrorMessages()
{
return $this->_errorMessages;
}
/**
* Clear custom error messages stack
*
* @return Zend_Form_Element
*/
public function clearErrorMessages()
{
$this->_errorMessages = array();
return $this;
}
/**
* Mark the element as being in a failed validation state
*
* @return Zend_Form_Element
*/
public function markAsError()
{
$messages = $this->getMessages();
$customMessages = $this->_getErrorMessages();
$messages = $messages + $customMessages;
if (empty($messages)) {
$this->_isError = true;
} else {
$this->_messages = $messages;
}
return $this;
}
/**
* Add an error message and mark element as failed validation
*
* @param string $message
* @return Zend_Form_Element
*/
public function addError($message)
{
$this->addErrorMessage($message);
$this->markAsError();
return $this;
}
/**
* Add multiple error messages and flag element as failed validation
*
* @param array $messages
* @return Zend_Form_Element
*/
public function addErrors(array $messages)
{
foreach ($messages as $message) {
$this->addError($message);
}
return $this;
}
/**
* Overwrite any previously set error messages and flag as failed validation
*
* @param array $messages
* @return Zend_Form_Element
*/
public function setErrors(array $messages)
{
$this->clearErrorMessages();
return $this->addErrors($messages);
}
/**
* Are there errors registered?
*
* @return bool
*/
public function hasErrors()
{
return (!empty($this->_messages) || $this->_isError);
}
/**
* Retrieve validator chain errors
*
* @return array
*/
public function getErrors()
{
return $this->_errors;
}
/**
* Retrieve error messages
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
// Filtering
/**
* Add a filter to the element
*
* @param string|Zend_Filter_Interface $filter
* @return Zend_Form_Element
*/
public function addFilter($filter, $options = array())
{
if ($filter instanceof Zend_Filter_Interface) {
$name = get_class($filter);
} elseif (is_string($filter)) {
$name = $filter;
$filter = array(
'filter' => $filter,
'options' => $options,
);
$this->_filters[$name] = $filter;
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid filter provided to addFilter; must be string or Zend_Filter_Interface');
}
$this->_filters[$name] = $filter;
return $this;
}
/**
* Add filters to element
*
* @param array $filters
* @return Zend_Form_Element
*/
public function addFilters(array $filters)
{
foreach ($filters as $filterInfo) {
if (is_string($filterInfo)) {
$this->addFilter($filterInfo);
} elseif ($filterInfo instanceof Zend_Filter_Interface) {
$this->addFilter($filterInfo);
} elseif (is_array($filterInfo)) {
$argc = count($filterInfo);
$options = array();
if (isset($filterInfo['filter'])) {
$filter = $filterInfo['filter'];
if (isset($filterInfo['options'])) {
$options = $filterInfo['options'];
}
$this->addFilter($filter, $options);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$filter = array_shift($filterInfo);
case (2 <= $argc):
$options = array_shift($filterInfo);
default:
$this->addFilter($filter, $options);
break;
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid filter passed to addFilters()');
}
}
return $this;
}
/**
* Add filters to element, overwriting any already existing
*
* @param array $filters
* @return Zend_Form_Element
*/
public function setFilters(array $filters)
{
$this->clearFilters();
return $this->addFilters($filters);
}
/**
* Retrieve a single filter by name
*
* @param string $name
* @return Zend_Filter_Interface
*/
public function getFilter($name)
{
if (!isset($this->_filters[$name])) {
$len = strlen($name);
foreach ($this->_filters as $localName => $filter) {
if ($len > strlen($localName)) {
continue;
}
if (0 === substr_compare($localName, $name, -$len, $len, true)) {
if (is_array($filter)) {
return $this->_loadFilter($filter);
}
return $filter;
}
}
return false;
}
if (is_array($this->_filters[$name])) {
return $this->_loadFilter($this->_filters[$name]);
}
return $this->_filters[$name];
}
/**
* Get all filters
*
* @return array
*/
public function getFilters()
{
$filters = array();
foreach ($this->_filters as $key => $value) {
if ($value instanceof Zend_Filter_Interface) {
$filters[$key] = $value;
continue;
}
$filter = $this->_loadFilter($value);
$filters[get_class($filter)] = $filter;
}
return $filters;
}
/**
* Remove a filter by name
*
* @param string $name
* @return Zend_Form_Element
*/
public function removeFilter($name)
{
if (isset($this->_filters[$name])) {
unset($this->_filters[$name]);
} else {
$len = strlen($name);
foreach (array_keys($this->_filters) as $filter) {
if ($len > strlen($filter)) {
continue;
}
if (0 === substr_compare($filter, $name, -$len, $len, true)) {
unset($this->_filters[$filter]);
break;
}
}
}
return $this;
}
/**
* Clear all filters
*
* @return Zend_Form_Element
*/
public function clearFilters()
{
$this->_filters = array();
return $this;
}
// Rendering
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_Form_Element
*/
public function setView(Zend_View_Interface $view = null)
{
$this->_view = $view;
return $this;
}
/**
* Retrieve view object
*
* Retrieves from ViewRenderer if none previously set.
*
* @return null|Zend_View_Interface
*/
public function getView()
{
if (null === $this->_view) {
require_once 'Zend/Controller/Action/HelperBroker.php';
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$this->setView($viewRenderer->view);
}
return $this->_view;
}
/**
* Instantiate a decorator based on class name or class name fragment
*
* @param string $name
* @param null|array $options
* @return Zend_Form_Decorator_Interface
*/
protected function _getDecorator($name, $options)
{
$class = $this->getPluginLoader(self::DECORATOR)->load($name);
if (null === $options) {
$decorator = new $class;
} else {
$decorator = new $class($options);
}
return $decorator;
}
/**
* Add a decorator for rendering the element
*
* @param string|Zend_Form_Decorator_Interface $decorator
* @param array|Zend_Config $options Options with which to initialize decorator
* @return Zend_Form_Element
*/
public function addDecorator($decorator, $options = null)
{
if ($decorator instanceof Zend_Form_Decorator_Interface) {
$name = get_class($decorator);
} elseif (is_string($decorator)) {
$name = $decorator;
$decorator = array(
'decorator' => $name,
'options' => $options,
);
} elseif (is_array($decorator)) {
foreach ($decorator as $name => $spec) {
break;
}
if (is_numeric($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string');
}
if (is_string($spec)) {
$decorator = array(
'decorator' => $spec,
'options' => $options,
);
} elseif ($spec instanceof Zend_Form_Decorator_Interface) {
$decorator = $spec;
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface');
}
$this->_decorators[$name] = $decorator;
return $this;
}
/**
* Add many decorators at once
*
* @param array $decorators
* @return Zend_Form_Element
*/
public function addDecorators(array $decorators)
{
foreach ($decorators as $decoratorInfo) {
if (is_string($decoratorInfo)) {
$this->addDecorator($decoratorInfo);
} elseif ($decoratorInfo instanceof Zend_Form_Decorator_Interface) {
$this->addDecorator($decoratorInfo);
} elseif (is_array($decoratorInfo)) {
$argc = count($decoratorInfo);
$options = array();
if (isset($decoratorInfo['decorator'])) {
$decorator = $decoratorInfo['decorator'];
if (isset($decoratorInfo['options'])) {
$options = $decoratorInfo['options'];
}
$this->addDecorator($decorator, $options);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$decorator = array_shift($decoratorInfo);
case (2 <= $argc):
$options = array_shift($decoratorInfo);
default:
$this->addDecorator($decorator, $options);
break;
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()');
}
}
return $this;
}
/**
* Overwrite all decorators
*
* @param array $decorators
* @return Zend_Form_Element
*/
public function setDecorators(array $decorators)
{
$this->clearDecorators();
return $this->addDecorators($decorators);
}
/**
* Retrieve a registered decorator
*
* @param string $name
* @return false|Zend_Form_Decorator_Abstract
*/
public function getDecorator($name)
{
if (!isset($this->_decorators[$name])) {
$len = strlen($name);
foreach ($this->_decorators as $localName => $decorator) {
if ($len > strlen($localName)) {
continue;
}
if (0 === substr_compare($localName, $name, -$len, $len, true)) {
if (is_array($decorator)) {
return $this->_loadDecorator($decorator, $localName);
}
return $decorator;
}
}
return false;
}
if (is_array($this->_decorators[$name])) {
return $this->_loadDecorator($this->_decorators[$name], $name);
}
return $this->_decorators[$name];
}
/**
* Retrieve all decorators
*
* @return array
*/
public function getDecorators()
{
foreach ($this->_decorators as $key => $value) {
if (is_array($value)) {
$this->_loadDecorator($value, $key);
}
}
return $this->_decorators;
}
/**
* Remove a single decorator
*
* @param string $name
* @return bool
*/
public function removeDecorator($name)
{
if (isset($this->_decorators[$name])) {
unset($this->_decorators[$name]);
} else {
$len = strlen($name);
foreach (array_keys($this->_decorators) as $decorator) {
if ($len > strlen($decorator)) {
continue;
}
if (0 === substr_compare($decorator, $name, -$len, $len, true)) {
unset($this->_decorators[$decorator]);
break;
}
}
}
return $this;
}
/**
* Clear all decorators
*
* @return Zend_Form_Element
*/
public function clearDecorators()
{
$this->_decorators = array();
return $this;
}
/**
* Render form element
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
if (null !== $view) {
$this->setView($view);
}
$content = '';
foreach ($this->getDecorators() as $decorator) {
$decorator->setElement($this);
$content = $decorator->render($content);
}
return $content;
}
/**
* String representation of form element
*
* Proxies to {@link render()}.
*
* @return string
*/
public function __toString()
{
try {
$return = $this->render();
return $return;
} catch (Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
return '';
}
}
/**
* Lazy-load a filter
*
* @param array $filter
* @return Zend_Filter_Interface
*/
protected function _loadFilter(array $filter)
{
$origName = $filter['filter'];
$name = $this->getPluginLoader(self::FILTER)->load($filter['filter']);
if (array_key_exists($name, $this->_filters)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Filter instance already exists for filter "%s"', $origName));
}
if (empty($filter['options'])) {
$instance = new $name;
} else {
$r = new ReflectionClass($name);
if ($r->hasMethod('__construct')) {
$instance = $r->newInstanceArgs((array) $filter['options']);
} else {
$instance = $r->newInstance();
}
}
if ($origName != $name) {
$filterNames = array_keys($this->_filters);
$order = array_flip($filterNames);
$order[$name] = $order[$origName];
$filtersExchange = array();
unset($order[$origName]);
asort($order);
foreach ($order as $key => $index) {
if ($key == $name) {
$filtersExchange[$key] = $instance;
continue;
}
$filtersExchange[$key] = $this->_filters[$key];
}
$this->_filters = $filtersExchange;
} else {
$this->_filters[$name] = $instance;
}
return $instance;
}
/**
* Lazy-load a validator
*
* @param array $validator Validator definition
* @return Zend_Validate_Interface
*/
protected function _loadValidator(array $validator)
{
$origName = $validator['validator'];
$name = $this->getPluginLoader(self::VALIDATE)->load($validator['validator']);
if (array_key_exists($name, $this->_validators)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Validator instance already exists for validator "%s"', $origName));
}
if (empty($validator['options'])) {
$instance = new $name;
} else {
$messages = false;
if (isset($validator['options']['messages'])) {
$messages = $validator['options']['messages'];
unset($validator['options']['messages']);
}
$r = new ReflectionClass($name);
if ($r->hasMethod('__construct')) {
$instance = $r->newInstanceArgs((array) $validator['options']);
} else {
$instance = $r->newInstance();
}
if ($messages) {
if (is_array($messages)) {
$instance->setMessages($messages);
} elseif (is_string($messages)) {
$instance->setMessage($messages);
}
}
}
$instance->zfBreakChainOnFailure = $validator['breakChainOnFailure'];
if ($origName != $name) {
$validatorNames = array_keys($this->_validators);
$order = array_flip($validatorNames);
$order[$name] = $order[$origName];
$validatorsExchange = array();
unset($order[$origName]);
asort($order);
foreach ($order as $key => $index) {
if ($key == $name) {
$validatorsExchange[$key] = $instance;
continue;
}
$validatorsExchange[$key] = $this->_validators[$key];
}
$this->_validators = $validatorsExchange;
} else {
$this->_validators[$name] = $instance;
}
return $instance;
}
/**
* Lazy-load a decorator
*
* @param array $decorator Decorator type and options
* @param mixed $name Decorator name or alias
* @return Zend_Form_Decorator_Interface
*/
protected function _loadDecorator(array $decorator, $name)
{
$sameName = false;
if ($name == $decorator['decorator']) {
$sameName = true;
}
$instance = $this->_getDecorator($decorator['decorator'], $decorator['options']);
if ($sameName) {
$newName = get_class($instance);
$decoratorNames = array_keys($this->_decorators);
$order = array_flip($decoratorNames);
$order[$newName] = $order[$name];
$decoratorsExchange = array();
unset($order[$name]);
asort($order);
foreach ($order as $key => $index) {
if ($key == $newName) {
$decoratorsExchange[$key] = $instance;
continue;
}
$decoratorsExchange[$key] = $this->_decorators[$key];
}
$this->_decorators = $decoratorsExchange;
} else {
$this->_decorators[$name] = $instance;
}
return $instance;
}
/**
* Retrieve error messages and perform translation and value substitution
*
* @return array
*/
protected function _getErrorMessages()
{
$translator = $this->getTranslator();
$messages = $this->getErrorMessages();
$value = $this->getValue();
foreach ($messages as $key => $message) {
if (null !== $translator) {
$message = $translator->translate($message);
}
if ($this->isArray() || is_array($value)) {
$aggregateMessages = array();
foreach ($value as $val) {
$aggregateMessages[] = str_replace('%value%', $val, $message);
}
$messages[$key] = $aggregateMessages;
} else {
$messages[$key] = str_replace('%value%', $value, $message);
}
}
return $messages;
}
/**
* Are there custom error messages registered?
*
* @return bool
*/
protected function _hasErrorMessages()
{
return !empty($this->_errorMessages);
}
}
Form/SubForm.php 0000604 00000003276 15071256135 0007546 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form */
require_once 'Zend/Form.php';
/**
* Zend_Form_SubForm
*
* @category Zend
* @package Zend_Form
* @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: SubForm.php 8585 2008-03-06 19:32:34Z matthew $
*/
class Zend_Form_SubForm extends Zend_Form
{
/**
* Whether or not form elements are members of an array
* @var bool
*/
protected $_isArray = true;
/**
* Load the default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl'))
->addDecorator('Fieldset')
->addDecorator('DtDdWrapper');
}
}
}
Form/Element/MultiCheckbox.php 0000604 00000003136 15071256135 0012316 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* MultiCheckbox form element
*
* Allows specifyinc a (multi-)dimensional associative array of values to use
* as labelled checkboxes; these will return an array of values for those
* checkboxes selected.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: MultiCheckbox.php 8628 2008-03-07 15:04:13Z matthew $
*/
class Zend_Form_Element_MultiCheckbox extends Zend_Form_Element_Multi
{
/**
* Use formMultiCheckbox view helper by default
* @var string
*/
public $helper = 'formMultiCheckbox';
/**
* MultiCheckbox is an array of values by default
* @var bool
*/
protected $_isArray = true;
}
Form/Element/Hash.php 0000604 00000013400 15071256135 0010433 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* CSRF form protection
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Hash.php 11332 2008-09-10 16:35:45Z matthew $
*/
class Zend_Form_Element_Hash extends Zend_Form_Element_Xhtml
{
/**
* Use formHidden view helper by default
* @var string
*/
public $helper = 'formHidden';
/**
* Actual hash used.
*
* @var mixed
*/
protected $_hash;
/**
* Salt for CSRF token
* @var string
*/
protected $_salt = 'salt';
/**
* @var Zend_Session_Namespace
*/
protected $_session;
/**
* TTL for CSRF token
* @var int
*/
protected $_timeout = 300;
/**
* Constructor
*
* Creates session namespace for CSRF token, and adds validator for CSRF
* token.
*
* @param string|array|Zend_Config $spec
* @param array|Zend_Config $options
* @return void
*/
public function __construct($spec, $options = null)
{
parent::__construct($spec, $options);
$this->setAllowEmpty(false)
->setRequired(true)
->initCsrfValidator();
}
/**
* Set session object
*
* @param Zend_Session_Namespace $session
* @return Zend_Form_Element_Hash
*/
public function setSession($session)
{
$this->_session = $session;
return $this;
}
/**
* Get session object
*
* Instantiate session object if none currently exists
*
* @return Zend_Session_Namespace
*/
public function getSession()
{
if (null === $this->_session) {
require_once 'Zend/Session/Namespace.php';
$this->_session = new Zend_Session_Namespace($this->getSessionName());
}
return $this->_session;
}
/**
* Initialize CSRF validator
*
* Creates Session namespace, and initializes CSRF token in session.
* Additionally, adds validator for validating CSRF token.
*
* @return Zend_Form_Element_Hash
*/
public function initCsrfValidator()
{
$session = $this->getSession();
if (isset($session->hash)) {
$rightHash = $session->hash;
} else {
$rightHash = null;
}
$this->addValidator('Identical', true, array($rightHash));
return $this;
}
/**
* Salt for CSRF token
*
* @param string $salt
* @return Zend_Form_Element_Hash
*/
public function setSalt($salt)
{
$this->_salt = (string) $salt;
return $this;
}
/**
* Retrieve salt for CSRF token
*
* @return string
*/
public function getSalt()
{
return $this->_salt;
}
/**
* Retrieve CSRF token
*
* If no CSRF token currently exists, generates one.
*
* @return string
*/
public function getHash()
{
if (null === $this->_hash) {
$this->_generateHash();
}
return $this->_hash;
}
/**
* Get session namespace for CSRF token
*
* Generates a session namespace based on salt, element name, and class.
*
* @return string
*/
public function getSessionName()
{
return __CLASS__ . '_' . $this->getSalt() . '_' . $this->getName();
}
/**
* Set timeout for CSRF session token
*
* @param int $ttl
* @return Zend_Form_Element_Hash
*/
public function setTimeout($ttl)
{
$this->_timeout = (int) $ttl;
return $this;
}
/**
* Get CSRF session token timeout
*
* @return int
*/
public function getTimeout()
{
return $this->_timeout;
}
/**
* Override getLabel() to always be empty
*
* @return null
*/
public function getLabel()
{
return null;
}
/**
* Initialize CSRF token in session
*
* @return void
*/
public function initCsrfToken()
{
$session = $this->getSession();
$session->setExpirationHops(1, null, true);
$session->setExpirationSeconds($this->getTimeout());
$session->hash = $this->getHash();
}
/**
* Render CSRF token in form
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$this->initCsrfToken();
return parent::render($view);
}
/**
* Generate CSRF token
*
* Generates CSRF token and stores both in {@link $_hash} and element
* value.
*
* @return void
*/
protected function _generateHash()
{
$this->_hash = md5(
mt_rand(1,1000000)
. $this->getSalt()
. $this->getName()
. mt_rand(1,1000000)
);
$this->setValue($this->_hash);
}
}
Form/Element/Password.php 0000604 00000004517 15071256135 0011363 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Password form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Password.php 9337 2008-04-28 18:14:48Z matthew $
*/
class Zend_Form_Element_Password extends Zend_Form_Element_Xhtml
{
/**
* Use formPassword view helper by default
* @var string
*/
public $helper = 'formPassword';
/**
* Whether or not to render the password
* @var bool
*/
public $renderPassword = false;
/**
* Set flag indicating whether or not to render the password
* @param bool $flag
* @return Zend_Form_Element_Password
*/
public function setRenderPassword($flag)
{
$this->renderPassword = (bool) $flag;
return $this;
}
/**
* Get value of renderPassword flag
*
* @return bool
*/
public function renderPassword()
{
return $this->renderPassword;
}
/**
* Override isValid()
*
* Ensure that validation error messages mask password value.
*
* @param string $value
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
foreach ($this->getValidators() as $validator) {
if ($validator instanceof Zend_Validate_Abstract) {
$validator->setObscureValue(true);
}
}
return parent::isValid($value, $context);
}
}
Form/Element/Captcha.php 0000604 00000016744 15071256135 0011131 0 ustar 00 <?php
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/** Zend_Captcha_Adapter */
require_once 'Zend/Captcha/Adapter.php';
/**
* Generic captcha element
*
* This element allows to insert CAPTCHA into the form in order
* to validate that human is submitting the form. The actual
* logic is contained in the captcha adapter.
*
* @see http://en.wikipedia.org/wiki/Captcha
*
*/
class Zend_Form_Element_Captcha extends Zend_Form_Element_Xhtml
{
/**
* @const string Captch plugin type constant
*/
const CAPTCHA = 'CAPTCHA';
/**
* Captcha adapter
*
* @var Zend_Captcha_Adapter
*/
protected $_captcha;
/**
* Get captcha adapter
*
* @return Zend_Captcha_Adapter
*/
public function getCaptcha()
{
return $this->_captcha;
}
/**
* Set captcha adapter
*
* @param string|array|Zend_Captcha_Adapter $captcha
* @param array $options
*/
public function setCaptcha($captcha, $options = array())
{
if ($captcha instanceof Zend_Captcha_Adapter) {
$instance = $captcha;
} else {
if (is_array($captcha)) {
if (array_key_exists('captcha', $captcha)) {
$name = $captcha['captcha'];
unset($captcha['captcha']);
} else {
$name = array_shift($captcha);
}
$options = array_merge($options, $captcha);
} else {
$name = $captcha;
}
$name = $this->getPluginLoader(self::CAPTCHA)->load($name);
if (empty($options)) {
$instance = new $name;
} else {
$r = new ReflectionClass($name);
if ($r->hasMethod('__construct')) {
$instance = $r->newInstanceArgs(array($options));
} else {
$instance = $r->newInstance();
}
}
}
$this->_captcha = $instance;
$this->_captcha->setName($this->getName());
return $this;
}
/**
* Constructor
*
* $spec may be:
* - string: name of element
* - array: options with which to configure element
* - Zend_Config: Zend_Config with options for configuring element
*
* @param string|array|Zend_Config $spec
* @return void
*/
public function __construct($spec, $options = null)
{
parent::__construct($spec, $options);
$this->setAllowEmpty(true)
->setRequired(true)
->setAutoInsertNotEmptyValidator(false)
->addValidator($this->getCaptcha(), true);
}
/**
* Set options
*
* Overrides to allow passing captcha options
*
* @param array $options
* @return Zend_Form_Element_Captcha
*/
public function setOptions(array $options)
{
if (array_key_exists('captcha', $options)) {
if (array_key_exists('captchaOptions', $options)) {
$this->setCaptcha($options['captcha'], $options['captchaOptions']);
unset($options['captchaOptions']);
} else {
$this->setCaptcha($options['captcha']);
}
unset($options['captcha']);
}
return parent::setOptions($options);
}
/**
* Render form element
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$captcha = $this->getCaptcha();
$captcha->setName($this->getFullyQualifiedName());
$decorators = $this->getDecorators();
$decorator = $captcha->getDecorator();
if (!empty($decorator)) {
array_unshift($decorators, $decorator);
}
$decorator = array('Captcha', array('captcha' => $captcha));
array_unshift($decorators, $decorator);
$this->setDecorators($decorators);
$this->setValue($this->getCaptcha()->generate());
return parent::render($view);
}
/**
* Retrieve plugin loader for validator or filter chain
*
* Support for plugin loader for Captcha adapters
*
* @param string $type
* @return Zend_Loader_PluginLoader
* @throws Zend_Loader_Exception on invalid type.
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
if ($type == self::CAPTCHA) {
if (!isset($this->_loaders[$type])) {
require_once 'Zend/Loader/PluginLoader.php';
$this->_loaders[$type] = new Zend_Loader_PluginLoader(
array('Zend_Captcha' => 'Zend/Captcha/')
);
}
return $this->_loaders[$type];
} else {
return parent::getPluginLoader($type);
}
}
/**
* Add prefix path for plugin loader for captcha adapters
*
* This method handles the captcha type, the rest is handled by
* the parent
*
* @param string $path
* @return Zend_Form_Element
* @see Zend_Form_Element::addPrefixPath
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case null:
$loader = $this->getPluginLoader(self::CAPTCHA);
$cPrefix = rtrim($prefix, '_') . '_Captcha';
$cPath = rtrim($path, '/\\') . '/Captcha';
$loader->addPrefixPath($cPrefix, $cPath);
return parent::addPrefixPath($prefix, $path);
case self::CAPTCHA:
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
default:
return parent::addPrefixPath($prefix, $path, $type);
}
}
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Is the captcha valid?
*
* @param mixed $value
* @param mixed $context
* @return boolean
*/
public function isValid($value, $context = null)
{
$this->getCaptcha()->setName($this->getName());
$belongsTo = $this->getBelongsTo();
if (empty($belongsTo) || !is_array($context)) {
return parent::isValid($value, $context);
}
$name = $this->getFullyQualifiedName();
$root = substr($name, 0, strpos($name, '['));
$segments = substr($name, strpos($name, '['));
$segments = ltrim($segments, '[');
$segments = rtrim($segments, ']');
$segments = explode('][', $segments);
array_unshift($segments, $root);
array_pop($segments);
$newContext = $context;
foreach ($segments as $segment) {
if (array_key_exists($segment, $newContext)) {
$newContext = $newContext[$segment];
}
}
return parent::isValid($value, $newContext);
}
}
Form/Element/Button.php 0000604 00000002420 15071256135 0011023 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Submit */
require_once 'Zend/Form/Element/Submit.php';
/**
* Button form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Button.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Button extends Zend_Form_Element_Submit
{
/**
* Use formButton view helper by default
* @var string
*/
public $helper = 'formButton';
}
Form/Element/Radio.php 0000604 00000002410 15071256135 0010605 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* Radio form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Radio.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Radio extends Zend_Form_Element_Multi
{
/**
* Use formRadio view helper by default
* @var string
*/
public $helper = 'formRadio';
}
Form/Element/Reset.php 0000604 00000002413 15071256135 0010634 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Submit */
require_once 'Zend/Form/Element/Submit.php';
/**
* Reset form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Reset.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Reset extends Zend_Form_Element_Submit
{
/**
* Use formReset view helper by default
* @var string
*/
public $helper = 'formReset';
}
Form/Element/Submit.php 0000604 00000006017 15071256135 0011021 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Submit form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Submit.php 8585 2008-03-06 19:32:34Z matthew $
*/
class Zend_Form_Element_Submit extends Zend_Form_Element_Xhtml
{
/**
* Default view helper to use
* @var string
*/
public $helper = 'formSubmit';
/**
* Constructor
*
* @param string|array|Zend_Config $spec Element name or configuration
* @param string|array|Zend_Config $options Element value or configuration
* @return void
*/
public function __construct($spec, $options = null)
{
if (is_string($spec) && ((null !== $options) && is_string($options))) {
$options = array('label' => $options);
}
parent::__construct($spec, $options);
}
/**
* Return label
*
* If no label is present, returns the currently set name.
*
* If a translator is present, returns the translated label.
*
* @return string
*/
public function getLabel()
{
$value = parent::getLabel();
if (null === $value) {
$value = $this->getName();
}
if (null !== ($translator = $this->getTranslator())) {
return $translator->translate($value);
}
return $value;
}
/**
* Has this submit button been selected?
*
* @return bool
*/
public function isChecked()
{
$value = $this->getValue();
if (empty($value)) {
return false;
}
if ($value != $this->getLabel()) {
return false;
}
return true;
}
/**
* Default decorators
*
* Uses only 'Submit' and 'DtDdWrapper' decorators by default.
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('ViewHelper')
->addDecorator('DtDdWrapper');
}
}
}
Form/Element/File.php 0000604 00000051152 15071256135 0010435 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Zend_Form_Element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: File.php 13240 2008-12-14 17:35:56Z thomas $
*/
class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
{
/**
* @const string Plugin loader type
*/
const TRANSFER_ADAPTER = 'TRANSFER_ADAPTER';
/**
* @var string Default view helper
*/
public $helper = 'formFile';
/**
* @var Zend_File_Transfer_Adapter_Abstract
*/
protected $_adapter;
/**
* @var boolean Already validated ?
*/
protected $_validated = false;
/**
* @var integer Internal multifile counter
*/
protected $_counter = 1;
/**
* @var integer Maximum file size for MAX_FILE_SIZE attribut of form
*/
protected static $_maxFileSize = 0;
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('File')
->addDecorator('Errors')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set plugin loader
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type
* @return Zend_Form_Element_File
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
{
$type = strtoupper($type);
if ($type != self::TRANSFER_ADAPTER) {
return parent::setPluginLoader($loader, $type);
}
$this->_loaders[$type] = $loader;
return $this;
}
/**
* Get Plugin Loader
*
* @param string $type
* @return Zend_Loader_PluginLoader_Interface
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
if ($type != self::TRANSFER_ADAPTER) {
return parent::getPluginLoader($type);
}
if (!array_key_exists($type, $this->_loaders)) {
require_once 'Zend/Loader/PluginLoader.php';
$loader = new Zend_Loader_PluginLoader(array(
'Zend_File_Transfer_Adapter' => 'Zend/File/Transfer/Adapter/',
));
$this->setPluginLoader($loader, self::TRANSFER_ADAPTER);
}
return $this->_loaders[$type];
}
/**
* Add prefix path for plugin loader
*
* @param string $prefix
* @param string $path
* @param string $type
* @return Zend_Form_Element_File
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
if (!empty($type) && ($type != self::TRANSFER_ADAPTER)) {
return parent::addPrefixPath($prefix, $path, $type);
}
if (empty($type)) {
$pluginPrefix = rtrim($prefix, '_') . '_Transfer_Adapter';
$pluginPath = rtrim($path, DIRECTORY_SEPARATOR) . '/Transfer/Adapter/';
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
return parent::addPrefixPath($prefix, $path, null);
}
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
}
/**
* Set transfer adapter
*
* @param string|Zend_File_Transfer_Adapter_Abstract $adapter
* @return Zend_Form_Element_File
*/
public function setTransferAdapter($adapter)
{
if ($adapter instanceof Zend_File_Transfer_Adapter_Abstract) {
$this->_adapter = $adapter;
} elseif (is_string($adapter)) {
$loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
$class = $loader->load($adapter);
$this->_adapter = new $class;
} else {
require_once 'Zend/Form/Element/Exception.php';
throw new Zend_Form_Element_Exception('Invalid adapter specified');
}
foreach (array('filter', 'validate') as $type) {
$loader = $this->getPluginLoader($type);
$this->_adapter->setPluginLoader($loader, $type);
}
return $this;
}
/**
* Get transfer adapter
*
* Lazy loads HTTP transfer adapter when no adapter registered.
*
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function getTransferAdapter()
{
if (null === $this->_adapter) {
$this->setTransferAdapter('Http');
}
return $this->_adapter;
}
/**
* Add Validator; proxy to adapter
*
* @param string|Zend_Validate_Interface $validator
* @param bool $breakChainOnFailure
* @param mixed $options
* @return Zend_Form_Element_File
*/
public function addValidator($validator, $breakChainOnFailure = false, $options = array())
{
$adapter = $this->getTransferAdapter();
$adapter->addValidator($validator, $breakChainOnFailure, $options, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Add multiple validators at once; proxy to adapter
*
* @param array $validators
* @return Zend_Form_Element_File
*/
public function addValidators(array $validators)
{
$adapter = $this->getTransferAdapter();
$adapter->addValidators($validators, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Add multiple validators at once, overwriting; proxy to adapter
*
* @param array $validators
* @return Zend_Form_Element_File
*/
public function setValidators(array $validators)
{
$adapter = $this->getTransferAdapter();
$adapter->setValidators($validators, $this->getName());
$this->_validated = false;
return $this;
}
/**
* Retrieve validator by name; proxy to adapter
*
* @param string $name
* @return Zend_Validate_Interface|null
*/
public function getValidator($name)
{
$adapter = $this->getTransferAdapter();
return $adapter->getValidator($name);
}
/**
* Retrieve all validators; proxy to adapter
*
* @return array
*/
public function getValidators()
{
$adapter = $this->getTransferAdapter();
$validators = $adapter->getValidators($this->getName());
if ($validators === null) {
$validators = array();
}
return $validators;
}
/**
* Remove validator by name; proxy to adapter
*
* @param string $name
* @return Zend_Form_Element_File
*/
public function removeValidator($name)
{
$adapter = $this->getTransferAdapter();
$adapter->removeValidator($name);
$this->_validated = false;
return $this;
}
/**
* Remove all validators; proxy to adapter
*
* @return Zend_Form_Element_File
*/
public function clearValidators()
{
$adapter = $this->getTransferAdapter();
$adapter->clearValidators();
$this->_validated = false;
return $this;
}
/**
* Add Filter; proxy to adapter
*
* @param string|array $filter Type of filter to add
* @param string|array $options Options to set for the filter
* @return Zend_Form_Element_File
*/
public function addFilter($filter, $options = null)
{
$adapter = $this->getTransferAdapter();
$adapter->addFilter($filter, $options, $this->getName());
return $this;
}
/**
* Add Multiple filters at once; proxy to adapter
*
* @param array $filters
* @return Zend_Form_Element_File
*/
public function addFilters(array $filters)
{
$adapter = $this->getTransferAdapter();
$adapter->addFilters($filters, $this->getName());
return $this;
}
/**
* Sets a filter for the class, erasing all previous set; proxy to adapter
*
* @param string|array $filter Filter to set
* @return Zend_Form_Element_File
*/
public function setFilters(array $filters)
{
$adapter = $this->getTransferAdapter();
$adapter->setFilters($filters, $this->getName());
return $this;
}
/**
* Retrieve individual filter; proxy to adapter
*
* @param string $name
* @return Zend_Filter_Interface|null
*/
public function getFilter($name)
{
$adapter = $this->getTransferAdapter();
return $adapter->getFilter($name);
}
/**
* Returns all set filters; proxy to adapter
*
* @return array List of set filters
*/
public function getFilters()
{
$adapter = $this->getTransferAdapter();
$filters = $adapter->getFilters($this->getName());
if ($filters === null) {
$filters = array();
}
return $filters;
}
/**
* Remove an individual filter; proxy to adapter
*
* @param string $name
* @return Zend_Form_Element_File
*/
public function removeFilter($name)
{
$adapter = $this->getTransferAdapter();
$adapter->removeFilter($name);
return $this;
}
/**
* Remove all filters; proxy to adapter
*
* @return Zend_Form_Element_File
*/
public function clearFilters()
{
$adapter = $this->getTransferAdapter();
$adapter->clearFilters();
return $this;
}
/**
* Validate upload
*
* @param string $value File, can be optional, give null to validate all files
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
if ($this->_validated) {
return true;
}
$adapter = $this->getTransferAdapter();
$translator = $this->getTranslator();
if ($translator !== null) {
$adapter->setTranslator($translator);
}
if (!$this->isRequired()) {
$adapter->setOptions(array('ignoreNoFile' => true), $this->getName());
} else {
$adapter->setOptions(array('ignoreNoFile' => false), $this->getName());
if ($this->autoInsertNotEmptyValidator() and
!$this->getValidator('NotEmpty'))
{
$validators = $this->getValidators();
$notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
array_unshift($validators, $notEmpty);
$this->setValidators($validators);
}
}
if($adapter->isValid($this->getName())) {
$this->_validated = true;
return true;
}
$this->_validated = false;
return false;
}
/**
* Receive the uploaded file
*
* @param string $value
* @return boolean
*/
public function receive($value = null)
{
if (!$this->_validated) {
if (!$this->isValid($this->getName())) {
return false;
}
}
$adapter = $this->getTransferAdapter();
if ($adapter->receive($this->getName())) {
return true;
}
return false;
}
/**
* Retrieve error codes; proxy to transfer adapter
*
* @return array
*/
public function getErrors()
{
return $this->getTransferAdapter()->getErrors();
}
/**
* Are there errors registered?
*
* @return bool
*/
public function hasErrors()
{
return $this->getTransferAdapter()->hasErrors();
}
/**
* Retrieve error messages; proxy to transfer adapter
*
* @return array
*/
public function getMessages()
{
return $this->getTransferAdapter()->getMessages();
}
/**
* Set the upload destination
*
* @param string $path
* @return Zend_Form_Element_File
*/
public function setDestination($path)
{
$this->getTransferAdapter()->setDestination($path, $this->getName());
return $this;
}
/**
* Get the upload destination
*
* @return string
*/
public function getDestination()
{
return $this->getTransferAdapter()->getDestination($this->getName());
}
/**
* Get the final filename
*
* @param string $value (Optional) Element or file to return
* @return string
*/
public function getFileName($value = null)
{
if (empty($value)) {
$value = $this->getName();
}
return $this->getTransferAdapter()->getFileName($value);
}
/**
* Get internal file informations
*
* @param string $value (Optional) Element or file to return
* @return array
*/
public function getFileInfo($value = null)
{
if (empty($value)) {
$value = $this->getName();
}
return $this->getTransferAdapter()->getFileInfo($value);
}
/**
* Set a multifile element
*
* @param integer $count Number of file elements
* @return Zend_Form_Element_File Provides fluent interface
*/
public function setMultiFile($count)
{
if ((integer) $count < 2) {
$this->setIsArray(false);
$this->_counter = 1;
} else {
$this->setIsArray(true);
$this->_counter = (integer) $count;
}
return $this;
}
/**
* Returns the multifile element number
*
* @return integer
*/
public function getMultiFile()
{
return $this->_counter;
}
/**
* Sets the maximum file size of the form
*
* @param integer $size
* @return integer
*/
public function setMaxFileSize($size)
{
$ini = $this->_convertIniToInteger(trim(ini_get('post_max_size')));
$mem = $this->_convertIniToInteger(trim(ini_get('memory_limit')));
$max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize')));
if (($max > -1) and ($size > $max)) {
trigger_error("Your 'upload_max_filesize' config setting allows only $max. You set $size.", E_USER_ERROR);
}
if (($ini > -1) and ($size > $ini)) {
trigger_error("Your 'post_max_size' config setting allows only $ini. You set $size.", E_USER_ERROR);
}
if (($mem > -1) and ($ini > $mem)) {
trigger_error("Your 'post_max_size' config settings exceeds the 'memory_limit' setting. You should fix this.", E_USER_ERROR);
}
self::$_maxFileSize = $size;
return $this;
}
/**
* Converts a ini setting to a integer value
*
* @param string $setting
* @return integer
*/
private function _convertIniToInteger($setting)
{
if (!is_numeric($setting)) {
$type = strtoupper(substr($setting, -1));
$setting = (integer) substr($setting, 0, -1);
switch ($type) {
case 'K' :
$setting *= 1024;
case 'M' :
$setting *= 1024 * 1024;
break;
case 'G' :
$setting *= 1024 * 1024 * 1024;
break;
default :
break;
}
}
return (integer) $setting;
}
/**
* Sets the maximum file size of the form
*
* @return integer
*/
public function getMaxFileSize()
{
return self::$_maxFileSize;
}
/**
* Processes the file, returns null or the filename only
* For the complete path, use getFileName
*
* @return null|string
*/
public function getValue()
{
if (!is_null($this->_value)) {
return $this->_value;
}
$content = $this->getTransferAdapter()->getFileName($this->getName());
if (empty($content)) {
return null;
}
if (!$this->isValid(null)) {
return null;
}
if (!$this->receive()) {
return null;
}
$filenames = $this->getFileName();
if (count($filenames) == 1) {
$this->_value = basename($filenames);
return $this->_value;
}
$this->_value = array();
foreach($filenames as $filename) {
$this->_value[] = basename($filename);
}
return $this->_value;
}
/**
* Disallow setting the value
*
* @param mixed $value
* @return Zend_Form_Element_File
*/
public function setValue($value)
{
return $this;
}
/**
* Set translator object for localization
*
* @param Zend_Translate|null $translator
* @return Zend_Form_Element_File
*/
public function setTranslator($translator = null)
{
$adapter = $this->getTransferAdapter();
$adapter->setTranslator($translator);
parent::setTranslator($translator);
return $this;
}
/**
* Retrieve localization translator object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
$adapter = $this->getTransferAdapter();
return $adapter->getTranslator();
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_Form_Element_File
*/
public function setDisableTranslator($flag)
{
$adapter = $this->getTransferAdapter();
$adapter->setDisableTranslator($flag);
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
$adapter = $this->getTransferAdapter();
return $adapter->translatorIsDisabled();
}
/**
* Was the file received?
*
* @return bool
*/
public function isReceived()
{
$adapter = $this->getTransferAdapter();
return $adapter->isReceived($this->getName());
}
/**
* Was the file uploaded?
*
* @return bool
*/
public function isUploaded()
{
$adapter = $this->getTransferAdapter();
return $adapter->isUploaded($this->getName());
}
/**
* Has the file been filtered?
*
* @return bool
*/
public function isFiltered()
{
$adapter = $this->getTransferAdapter();
return $adapter->isFiltered($this->getName());
}
/**
* Returns the hash for this file element
*
* @param string $hash (Optional) Hash algorithm to use
* @return string|array Hashstring
*/
public function getHash($hash = 'crc32')
{
$adapter = $this->getTransferAdapter();
return $adapter->getHash($hash, $this->getName());
}
/**
* Retrieve error messages and perform translation and value substitution
*
* @return array
*/
protected function _getErrorMessages()
{
$translator = $this->getTranslator();
$messages = $this->getErrorMessages();
$value = $this->getFileName();
foreach ($messages as $key => $message) {
if (null !== $translator) {
$message = $translator->translate($message);
}
if ($this->isArray() || is_array($value)) {
$aggregateMessages = array();
foreach ($value as $val) {
$aggregateMessages[] = str_replace('%value%', $val, $message);
}
$messages[$key] = $aggregateMessages;
} else {
$messages[$key] = str_replace('%value%', $value, $message);
}
}
return $messages;
}
}
Form/Element/Hidden.php 0000604 00000002415 15071256135 0010747 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Hidden form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Hidden.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Hidden extends Zend_Form_Element_Xhtml
{
/**
* Use formHidden view helper by default
* @var string
*/
public $helper = 'formHidden';
}
Form/Element/Text.php 0000604 00000002415 15071256135 0010500 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Text form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Text.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Text extends Zend_Form_Element_Xhtml
{
/**
* Default form view helper to use for rendering
* @var string
*/
public $helper = 'formText';
}
Form/Element/Checkbox.php 0000604 00000012040 15071256135 0011275 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Checkbox form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Checkbox.php 9323 2008-04-25 21:13:17Z matthew $
*/
class Zend_Form_Element_Checkbox extends Zend_Form_Element_Xhtml
{
/**
* Is the checkbox checked?
* @var bool
*/
public $checked = false;
/**
* Use formCheckbox view helper by default
* @var string
*/
public $helper = 'formCheckbox';
/**
* Value when checked
* @var string
*/
protected $_checkedValue = '1';
/**
* Value when not checked
* @var string
*/
protected $_uncheckedValue = '0';
/**
* Current value
* @var string 0 or 1
*/
protected $_value = '0';
/**
* Set options
*
* Intercept checked and unchecked values and set them early; test stored
* value against checked and unchecked values after configuration.
*
* @param array $options
* @return Zend_Form_Element_Checkbox
*/
public function setOptions(array $options)
{
if (array_key_exists('checkedValue', $options)) {
$this->setCheckedValue($options['checkedValue']);
unset($options['checkedValue']);
}
if (array_key_exists('uncheckedValue', $options)) {
$this->setUncheckedValue($options['uncheckedValue']);
unset($options['uncheckedValue']);
}
parent::setOptions($options);
$curValue = $this->getValue();
$test = array($this->getCheckedValue(), $this->getUncheckedValue());
if (!in_array($curValue, $test)) {
$this->setValue($curValue);
}
return $this;
}
/**
* Set value
*
* If value matches checked value, sets to that value, and sets the checked
* flag to true.
*
* Any other value causes the unchecked value to be set as the current
* value, and the checked flag to be set as false.
*
*
* @param mixed $value
* @return Zend_Form_Element_Checkbox
*/
public function setValue($value)
{
if ($value == $this->getCheckedValue()) {
parent::setValue($value);
$this->checked = true;
} else {
parent::setValue($this->getUncheckedValue());
$this->checked = false;
}
return $this;
}
/**
* Set checked value
*
* @param string $value
* @return Zend_Form_Element_Checkbox
*/
public function setCheckedValue($value)
{
$this->_checkedValue = (string) $value;
return $this;
}
/**
* Get value when checked
*
* @return string
*/
public function getCheckedValue()
{
return $this->_checkedValue;
}
/**
* Set unchecked value
*
* @param string $value
* @return Zend_Form_Element_Checkbox
*/
public function setUncheckedValue($value)
{
$this->_uncheckedValue = (string) $value;
return $this;
}
/**
* Get value when not checked
*
* @return string
*/
public function getUncheckedValue()
{
return $this->_uncheckedValue;
}
/**
* Set checked flag
*
* @param bool $flag
* @return Zend_Form_Element_Checkbox
*/
public function setChecked($flag)
{
$this->checked = (bool) $flag;
if ($this->checked) {
$this->setValue($this->getCheckedValue());
} else {
$this->setValue($this->getUncheckedValue());
}
return $this;
}
/**
* Get checked flag
*
* @return bool
*/
public function isChecked()
{
return $this->checked;
}
/**
* Render
*
* Ensure that options property is set when rendering.
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$this->options = array(
'checked' => $this->getCheckedValue(),
'unChecked' => $this->getUncheckedValue(),
);
return parent::render($view);
}
}
Form/Element/Image.php 0000604 00000005732 15071256135 0010603 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Image form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Image.php 8680 2008-03-07 22:25:35Z matthew $
*/
class Zend_Form_Element_Image extends Zend_Form_Element_Xhtml
{
/**
* What view helper to use when using view helper decorator
* @var string
*/
public $helper = 'formImage';
/**
* Image source
* @var string
*/
public $src;
/**
* Image value
* @var mixed
*/
protected $_imageValue;
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('Image')
->addDecorator('Errors')
->addDecorator('HtmlTag', array('tag' => 'dd'))
->addDecorator('Label', array('tag' => 'dt'));
}
}
/**
* Set image path
*
* @param string $path
* @return Zend_Form_Element_Image
*/
public function setImage($path)
{
$this->src = (string) $path;
return $this;
}
/**
* Get image path
*
* @return string
*/
public function getImage()
{
return $this->src;
}
/**
* Set image value to use when submitted
*
* @param mixed $value
* @return Zend_Form_Element_Image
*/
public function setImageValue($value)
{
$this->_imageValue = $value;
return $this;
}
/**
* Get image value to use when submitted
*
* @return mixed
*/
public function getImageValue()
{
return $this->_imageValue;
}
/**
* Was this element used to submit the form?
*
* @return bool
*/
public function isChecked()
{
$imageValue = $this->getImageValue();
return ((null !== $imageValue) && ($this->getValue() == $imageValue));
}
}
Form/Element/Xhtml.php 0000604 00000002233 15071256135 0010646 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element */
require_once 'Zend/Form/Element.php';
/**
* Base element for XHTML elements
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Xhtml.php 8064 2008-02-16 10:58:39Z thomas $
*/
abstract class Zend_Form_Element_Xhtml extends Zend_Form_Element
{
}
Form/Element/Multiselect.php 0000604 00000002771 15071256135 0012053 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Select */
require_once 'Zend/Form/Element/Select.php';
/**
* Multiselect form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Multiselect.php 8628 2008-03-07 15:04:13Z matthew $
*/
class Zend_Form_Element_Multiselect extends Zend_Form_Element_Select
{
/**
* 'multiple' attribute
* @var string
*/
public $multiple = 'multiple';
/**
* Use formSelect view helper by default
* @var string
*/
public $helper = 'formSelect';
/**
* Multiselect is an array of values by default
* @var bool
*/
protected $_isArray = true;
}
Form/Element/Select.php 0000604 00000002421 15071256135 0010770 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Multi */
require_once 'Zend/Form/Element/Multi.php';
/**
* Select.php form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Select.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Select extends Zend_Form_Element_Multi
{
/**
* Use formSelect view helper by default
* @var string
*/
public $helper = 'formSelect';
}
Form/Element/Exception.php 0000604 00000002242 15071256135 0011510 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Exception */
require_once 'Zend/Form/Exception.php';
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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_Form_Element_Exception extends Zend_Form_Exception
{
}
Form/Element/Multi.php 0000604 00000017426 15071256135 0010656 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Base class for multi-option form elements
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Multi.php 12527 2008-11-10 21:00:57Z thomas $
*/
abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml
{
/**
* Array of options for multi-item
* @var array
*/
public $options = array();
/**
* Flag: autoregister inArray validator?
* @var bool
*/
protected $_registerInArrayValidator = true;
/**
* Separator to use between options; defaults to '<br />'.
* @var string
*/
protected $_separator = '<br />';
/**
* Which values are translated already?
* @var array
*/
protected $_translated = array();
/**
* Retrieve separator
*
* @return mixed
*/
public function getSeparator()
{
return $this->_separator;
}
/**
* Set separator
*
* @param mixed $separator
* @return self
*/
public function setSeparator($separator)
{
$this->_separator = $separator;
return $this;
}
/**
* Retrieve options array
*
* @return array
*/
protected function _getMultiOptions()
{
if (null === $this->options || !is_array($this->options)) {
$this->options = array();
}
return $this->options;
}
/**
* Add an option
*
* @param string $option
* @param string $value
* @return Zend_Form_Element_Multi
*/
public function addMultiOption($option, $value = '')
{
$option = (string) $option;
$this->_getMultiOptions();
if (!$this->_translateOption($option, $value)) {
$this->options[$option] = $value;
}
return $this;
}
/**
* Add many options at once
*
* @param array $options
* @return Zend_Form_Element_Multi
*/
public function addMultiOptions(array $options)
{
foreach ($options as $option => $value) {
if (is_array($value)
&& array_key_exists('key', $value)
&& array_key_exists('value', $value)
) {
$this->addMultiOption($value['key'], $value['value']);
} else {
$this->addMultiOption($option, $value);
}
}
return $this;
}
/**
* Set all options at once (overwrites)
*
* @param array $options
* @return Zend_Form_Element_Multi
*/
public function setMultiOptions(array $options)
{
$this->clearMultiOptions();
return $this->addMultiOptions($options);
}
/**
* Retrieve single multi option
*
* @param string $option
* @return mixed
*/
public function getMultiOption($option)
{
$option = (string) $option;
$this->_getMultiOptions();
if (isset($this->options[$option])) {
$this->_translateOption($option, $this->options[$option]);
return $this->options[$option];
}
return null;
}
/**
* Retrieve options
*
* @return array
*/
public function getMultiOptions()
{
$this->_getMultiOptions();
foreach ($this->options as $option => $value) {
$this->_translateOption($option, $value);
}
return $this->options;
}
/**
* Remove a single multi option
*
* @param string $option
* @return bool
*/
public function removeMultiOption($option)
{
$option = (string) $option;
$this->_getMultiOptions();
if (isset($this->options[$option])) {
unset($this->options[$option]);
if (isset($this->_translated[$option])) {
unset($this->_translated[$option]);
}
return true;
}
return false;
}
/**
* Clear all options
*
* @return Zend_Form_Element_Multi
*/
public function clearMultiOptions()
{
$this->options = array();
$this->_translated = array();
return $this;
}
/**
* Set flag indicating whether or not to auto-register inArray validator
*
* @param bool $flag
* @return Zend_Form_Element_Multi
*/
public function setRegisterInArrayValidator($flag)
{
$this->_registerInArrayValidator = (bool) $flag;
return $this;
}
/**
* Get status of auto-register inArray validator flag
*
* @return bool
*/
public function registerInArrayValidator()
{
return $this->_registerInArrayValidator;
}
/**
* Is the value provided valid?
*
* Autoregisters InArray validator if necessary.
*
* @param string $value
* @param mixed $context
* @return bool
*/
public function isValid($value, $context = null)
{
if ($this->registerInArrayValidator()) {
if (!$this->getValidator('InArray')) {
$multiOptions = $this->getMultiOptions();
$options = array();
foreach ($multiOptions as $opt_value => $opt_label) {
// optgroup instead of option label
if (is_array($opt_label)) {
$options = array_merge($options, array_keys($opt_label));
}
else {
$options[] = $opt_value;
}
}
$this->addValidator(
'InArray',
true,
array($options)
);
}
}
return parent::isValid($value, $context);
}
/**
* Translate an option
*
* @param string $option
* @param string $value
* @return bool
*/
protected function _translateOption($option, $value)
{
if ($this->translatorIsDisabled()) {
return true;
}
if (!isset($this->_translated[$option]) && !empty($value)) {
$this->options[$option] = $this->_translateValue($value);
if ($this->options[$option] === $value) {
return false;
}
$this->_translated[$option] = true;
return true;
}
return false;
}
/**
* Translate a multi option value
*
* @param string $value
* @return string
*/
protected function _translateValue($value)
{
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = $this->_translateValue($val);
}
return $value;
} else {
if (null !== ($translator = $this->getTranslator())) {
if ($translator->isTranslated($value)) {
return $translator->translate($value);
}
}
return $value;
}
}
}
Form/Element/Textarea.php 0000604 00000002427 15071256135 0011334 0 ustar 00 <?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_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Textarea form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @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: Textarea.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Form_Element_Textarea extends Zend_Form_Element_Xhtml
{
/**
* Use formTextarea view helper by default
* @var string
*/
public $helper = 'formTextarea';
}
Form/DisplayGroup.php 0000604 00000066352 15071256135 0010617 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Form_DisplayGroup
*
* @category Zend
* @package Zend_Form
* @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: DisplayGroup.php 12787 2008-11-23 14:17:44Z matthew $
*/
class Zend_Form_DisplayGroup implements Iterator,Countable
{
/**
* Group attributes
* @var array
*/
protected $_attribs = array();
/**
* Display group decorators
* @var array
*/
protected $_decorators = array();
/**
* Description
* @var string
*/
protected $_description;
/**
* Should we disable loading the default decorators?
* @var bool
*/
protected $_disableLoadDefaultDecorators = false;
/**
* Element order
* @var array
*/
protected $_elementOrder = array();
/**
* Elements
* @var array
*/
protected $_elements = array();
/**
* Whether or not a new element has been added to the group
* @var bool
*/
protected $_groupUpdated = false;
/**
* Plugin loader for decorators
* @var Zend_Loader_PluginLoader
*/
protected $_loader;
/**
* Group name
* @var string
*/
protected $_name;
/**
* Group order
* @var int
*/
protected $_order;
/**
* @var Zend_Translate
*/
protected $_translator;
/**
* Is translation disabled?
* @var bool
*/
protected $_translatorDisabled = false;
/**
* @var Zend_View_Interface
*/
protected $_view;
/**
* Constructor
*
* @param string $name
* @param Zend_Loader_PluginLoader $loader
* @param array|Zend_Config $options
* @return void
*/
public function __construct($name, Zend_Loader_PluginLoader $loader, $options = null)
{
$this->setName($name);
$this->setPluginLoader($loader);
if (is_array($options)) {
$this->setOptions($options);
} elseif ($options instanceof Zend_Config) {
$this->setConfig($options);
}
// Extensions...
$this->init();
$this->loadDefaultDecorators();
}
/**
* Initialize object; used by extending classes
*
* @return void
*/
public function init()
{
}
/**
* Set options
*
* @param array $options
* @return Zend_Form_DisplayGroup
*/
public function setOptions(array $options)
{
$forbidden = array(
'Options', 'Config', 'PluginLoader', 'View',
'Translator', 'Attrib'
);
foreach ($options as $key => $value) {
$normalized = ucfirst($key);
if (in_array($normalized, $forbidden)) {
continue;
}
$method = 'set' . $normalized;
if (method_exists($this, $method)) {
$this->$method($value);
} else {
$this->setAttrib($key, $value);
}
}
return $this;
}
/**
* Set options from config object
*
* @param Zend_Config $config
* @return Zend_Form_DisplayGroup
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Set group attribute
*
* @param string $key
* @param mixed $value
* @return Zend_Form_DisplayGroup
*/
public function setAttrib($key, $value)
{
$key = (string) $key;
$this->_attribs[$key] = $value;
return $this;
}
/**
* Add multiple form attributes at once
*
* @param array $attribs
* @return Zend_Form_DisplayGroup
*/
public function addAttribs(array $attribs)
{
foreach ($attribs as $key => $value) {
$this->setAttrib($key, $value);
}
return $this;
}
/**
* Set multiple form attributes at once
*
* Overwrites any previously set attributes.
*
* @param array $attribs
* @return Zend_Form_DisplayGroup
*/
public function setAttribs(array $attribs)
{
$this->clearAttribs();
return $this->addAttribs($attribs);
}
/**
* Retrieve a single form attribute
*
* @param string $key
* @return mixed
*/
public function getAttrib($key)
{
$key = (string) $key;
if (!isset($this->_attribs[$key])) {
return null;
}
return $this->_attribs[$key];
}
/**
* Retrieve all form attributes/metadata
*
* @return array
*/
public function getAttribs()
{
return $this->_attribs;
}
/**
* Remove attribute
*
* @param string $key
* @return bool
*/
public function removeAttrib($key)
{
if (array_key_exists($key, $this->_attribs)) {
unset($this->_attribs[$key]);
return true;
}
return false;
}
/**
* Clear all form attributes
*
* @return Zend_Form
*/
public function clearAttribs()
{
$this->_attribs = array();
return $this;
}
/**
* Filter a name to only allow valid variable characters
*
* @param string $value
* @return string
*/
public function filterName($value)
{
return preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', (string) $value);
}
/**
* Set group name
*
* @param string $name
* @return Zend_Form_DisplayGroup
*/
public function setName($name)
{
$name = $this->filtername($name);
if (('0' !== $name) && empty($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty');
}
$this->_name = $name;
return $this;
}
/**
* Retrieve group name
*
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* Get fully qualified name
*
* Places name as subitem of array and/or appends brackets.
*
* @return string
*/
public function getFullyQualifiedName()
{
return $this->getName();
}
/**
* Get element id
*
* @return string
*/
public function getId()
{
if (isset($this->id)) {
return $this->id;
}
$id = $this->getFullyQualifiedName();
// Bail early if no array notation detected
if (!strstr($id, '[')) {
return $id;
}
// Strip array notation
if ('[]' == substr($id, -2)) {
$id = substr($id, 0, strlen($id) - 2);
}
$id = str_replace('][', '-', $id);
$id = str_replace(array(']', '['), '-', $id);
$id = trim($id, '-');
return $id;
}
/**
* Set group legend
*
* @param string $legend
* @return Zend_Form_DisplayGroup
*/
public function setLegend($legend)
{
return $this->setAttrib('legend', (string) $legend);
}
/**
* Retrieve group legend
*
* @return string
*/
public function getLegend()
{
return $this->getAttrib('legend');
}
/**
* Set description
*
* @param string $value
* @return Zend_Form_DisplayGroup
*/
public function setDescription($value)
{
$this->_description = (string) $value;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
/**
* Set group order
*
* @param int $order
* @return Zend_Form_Element
*/
public function setOrder($order)
{
$this->_order = (int) $order;
return $this;
}
/**
* Retrieve group order
*
* @return int
*/
public function getOrder()
{
return $this->_order;
}
// Elements
/**
* Add element to stack
*
* @param Zend_Form_Element $element
* @return Zend_Form_DisplayGroup
*/
public function addElement(Zend_Form_Element $element)
{
$this->_elements[$element->getName()] = $element;
$this->_groupUpdated = true;
return $this;
}
/**
* Add multiple elements at once
*
* @param array $elements
* @return Zend_Form_DisplayGroup
* @throws Zend_Form_Exception if any element is not a Zend_Form_Element
*/
public function addElements(array $elements)
{
foreach ($elements as $element) {
if (!$element instanceof Zend_Form_Element) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('elements passed via array to addElements() must be Zend_Form_Elements only');
}
$this->addElement($element);
}
return $this;
}
/**
* Set multiple elements at once (overwrites)
*
* @param array $elements
* @return Zend_Form_DisplayGroup
*/
public function setElements(array $elements)
{
$this->clearElements();
return $this->addElements($elements);
}
/**
* Retrieve element
*
* @param string $name
* @return Zend_Form_Element|null
*/
public function getElement($name)
{
$name = (string) $name;
if (isset($this->_elements[$name])) {
return $this->_elements[$name];
}
return null;
}
/**
* Retrieve elements
* @return array
*/
public function getElements()
{
return $this->_elements;
}
/**
* Remove a single element
*
* @param string $name
* @return boolean
*/
public function removeElement($name)
{
$name = (string) $name;
if (array_key_exists($name, $this->_elements)) {
unset($this->_elements[$name]);
$this->_groupUpdated = true;
return true;
}
return false;
}
/**
* Remove all elements
*
* @return Zend_Form_DisplayGroup
*/
public function clearElements()
{
$this->_elements = array();
$this->_groupUpdated = true;
return $this;
}
// Plugin loader (for decorators)
/**
* Set plugin loader
*
* @param Zend_Loader_PluginLoader $loader
* @return Zend_Form_DisplayGroup
*/
public function setPluginLoader(Zend_Loader_PluginLoader $loader)
{
$this->_loader = $loader;
return $this;
}
/**
* Retrieve plugin loader
*
* @return Zend_Loader_PluginLoader
*/
public function getPluginLoader()
{
return $this->_loader;
}
/**
* Add a prefix path for the plugin loader
*
* @param string $prefix
* @param string $path
* @return Zend_Form_DisplayGroup
*/
public function addPrefixPath($prefix, $path)
{
$this->getPluginLoader()->addPrefixPath($prefix, $path);
return $this;
}
/**
* Add several prefix paths at once
*
* @param array $spec
* @return Zend_Form_DisplayGroup
*/
public function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
return $this->addPrefixPath($spec['prefix'], $spec['path']);
}
foreach ($spec as $prefix => $paths) {
if (is_numeric($prefix) && is_array($paths)) {
$prefix = null;
if (isset($paths['prefix']) && isset($paths['path'])) {
$this->addPrefixPath($paths['prefix'], $paths['path']);
}
} elseif (!is_numeric($prefix)) {
if (is_string($paths)) {
$this->addPrefixPath($prefix, $paths);
} elseif (is_array($paths)) {
foreach ($paths as $path) {
$this->addPrefixPath($prefix, $path);
}
}
}
}
return $this;
}
// Decorators
/**
* Set flag to disable loading default decorators
*
* @param bool $flag
* @return Zend_Form_Element
*/
public function setDisableLoadDefaultDecorators($flag)
{
$this->_disableLoadDefaultDecorators = (bool) $flag;
return $this;
}
/**
* Should we load the default decorators?
*
* @return bool
*/
public function loadDefaultDecoratorsIsDisabled()
{
return $this->_disableLoadDefaultDecorators;
}
/**
* Load default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl'))
->addDecorator('Fieldset')
->addDecorator('DtDdWrapper');
}
}
/**
* Instantiate a decorator based on class name or class name fragment
*
* @param string $name
* @param null|array $options
* @return Zend_Form_Decorator_Interface
*/
protected function _getDecorator($name, $options = null)
{
$class = $this->getPluginLoader()->load($name);
if (null === $options) {
$decorator = new $class;
} else {
$decorator = new $class($options);
}
return $decorator;
}
/**
* Add a decorator for rendering the group
*
* @param string|Zend_Form_Decorator_Interface $decorator
* @param array|Zend_Config $options Options with which to initialize decorator
* @return Zend_Form_DisplayGroup
*/
public function addDecorator($decorator, $options = null)
{
if ($decorator instanceof Zend_Form_Decorator_Interface) {
$name = get_class($decorator);
} elseif (is_string($decorator)) {
$name = $decorator;
$decorator = array(
'decorator' => $name,
'options' => $options,
);
} elseif (is_array($decorator)) {
foreach ($decorator as $name => $spec) {
break;
}
if (is_numeric($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string');
}
if (is_string($spec)) {
$decorator = array(
'decorator' => $spec,
'options' => $options,
);
} elseif ($spec instanceof Zend_Form_Decorator_Interface) {
$decorator = $spec;
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface');
}
$this->_decorators[$name] = $decorator;
return $this;
}
/**
* Add many decorators at once
*
* @param array $decorators
* @return Zend_Form_DisplayGroup
*/
public function addDecorators(array $decorators)
{
foreach ($decorators as $decoratorInfo) {
if (is_string($decoratorInfo)) {
$this->addDecorator($decoratorInfo);
} elseif ($decoratorInfo instanceof Zend_Form_Decorator_Interface) {
$this->addDecorator($decoratorInfo);
} elseif (is_array($decoratorInfo)) {
$argc = count($decoratorInfo);
$options = array();
if (isset($decoratorInfo['decorator'])) {
$decorator = $decoratorInfo['decorator'];
if (isset($decoratorInfo['options'])) {
$options = $decoratorInfo['options'];
}
$this->addDecorator($decorator, $options);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$decorator = array_shift($decoratorInfo);
case (2 <= $argc):
$options = array_shift($decoratorInfo);
default:
$this->addDecorator($decorator, $options);
break;
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()');
}
}
return $this;
}
/**
* Overwrite all decorators
*
* @param array $decorators
* @return Zend_Form_DisplayGroup
*/
public function setDecorators(array $decorators)
{
$this->clearDecorators();
return $this->addDecorators($decorators);
}
/**
* Retrieve a registered decorator
*
* @param string $name
* @return false|Zend_Form_Decorator_Abstract
*/
public function getDecorator($name)
{
if (!isset($this->_decorators[$name])) {
$len = strlen($name);
foreach ($this->_decorators as $localName => $decorator) {
if ($len > strlen($localName)) {
continue;
}
if (0 === substr_compare($localName, $name, -$len, $len, true)) {
if (is_array($decorator)) {
return $this->_loadDecorator($decorator, $localName);
}
return $decorator;
}
}
return false;
}
if (is_array($this->_decorators[$name])) {
return $this->_loadDecorator($this->_decorators[$name], $name);
}
return $this->_decorators[$name];
}
/**
* Retrieve all decorators
*
* @return array
*/
public function getDecorators()
{
foreach ($this->_decorators as $key => $value) {
if (is_array($value)) {
$this->_loadDecorator($value, $key);
}
}
return $this->_decorators;
}
/**
* Remove a single decorator
*
* @param string $name
* @return bool
*/
public function removeDecorator($name)
{
$decorator = $this->getDecorator($name);
if ($decorator) {
if (array_key_exists($name, $this->_decorators)) {
unset($this->_decorators[$name]);
} else {
$class = get_class($decorator);
unset($this->_decorators[$class]);
}
return true;
}
return false;
}
/**
* Clear all decorators
*
* @return Zend_Form_DisplayGroup
*/
public function clearDecorators()
{
$this->_decorators = array();
return $this;
}
/**
* Set view
*
* @param Zend_View_Interface $view
* @return Zend_Form_DisplayGroup
*/
public function setView(Zend_View_Interface $view = null)
{
$this->_view = $view;
return $this;
}
/**
* Retrieve view
*
* @return Zend_View_Interface
*/
public function getView()
{
if (null === $this->_view) {
require_once 'Zend/Controller/Action/HelperBroker.php';
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$this->setView($viewRenderer->view);
}
return $this->_view;
}
/**
* Render display group
*
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
if (null !== $view) {
$this->setView($view);
}
$content = '';
foreach ($this->getDecorators() as $decorator) {
$decorator->setElement($this);
$content = $decorator->render($content);
}
return $content;
}
/**
* String representation of group
*
* @return string
*/
public function __toString()
{
try {
$return = $this->render();
return $return;
} catch (Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
return '';
}
}
/**
* Set translator object
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return Zend_Form_DisplayGroup
*/
public function setTranslator($translator = null)
{
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid translator specified');
}
return $this;
}
/**
* Retrieve translator object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
if (null === $this->_translator) {
require_once 'Zend/Form.php';
return Zend_Form::getDefaultTranslator();
}
return $this->_translator;
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_Form_DisplayGroup
*/
public function setDisableTranslator($flag)
{
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
return $this->_translatorDisabled;
}
/**
* Overloading: allow rendering specific decorators
*
* Call renderDecoratorName() to render a specific decorator.
*
* @param string $method
* @param array $args
* @return string
* @throws Zend_Form_Exception for invalid decorator or invalid method call
*/
public function __call($method, $args)
{
if ('render' == substr($method, 0, 6)) {
$decoratorName = substr($method, 6);
if (false !== ($decorator = $this->getDecorator($decoratorName))) {
$decorator->setElement($this);
$seed = '';
if (0 < count($args)) {
$seed = array_shift($args);
}
return $decorator->render($seed);
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Decorator by name %s does not exist', $decoratorName));
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Method %s does not exist', $method));
}
// Interfaces: Iterator, Countable
/**
* Current element
*
* @return Zend_Form_Element
*/
public function current()
{
$this->_sort();
current($this->_elementOrder);
$key = key($this->_elementOrder);
return $this->getElement($key);
}
/**
* Current element
*
* @return string
*/
public function key()
{
$this->_sort();
return key($this->_elementOrder);
}
/**
* Move pointer to next element
*
* @return void
*/
public function next()
{
$this->_sort();
next($this->_elementOrder);
}
/**
* Move pointer to beginning of element loop
*
* @return void
*/
public function rewind()
{
$this->_sort();
reset($this->_elementOrder);
}
/**
* Determine if current element/subform/display group is valid
*
* @return bool
*/
public function valid()
{
$this->_sort();
return (current($this->_elementOrder) !== false);
}
/**
* Count of elements/subforms that are iterable
*
* @return int
*/
public function count()
{
return count($this->_elements);
}
/**
* Sort items according to their order
*
* @return void
*/
protected function _sort()
{
if ($this->_groupUpdated || !is_array($this->_elementOrder)) {
$elementOrder = array();
foreach ($this->getElements() as $key => $element) {
$elementOrder[$key] = $element->getOrder();
}
$items = array();
$index = 0;
foreach ($elementOrder as $key => $order) {
if (null === $order) {
while (array_search($index, $elementOrder, true)) {
++$index;
}
$items[$index] = $key;
++$index;
} else {
$items[$order] = $key;
}
}
$items = array_flip($items);
asort($items);
$this->_elementOrder = $items;
$this->_groupUpdated = false;
}
}
/**
* Lazy-load a decorator
*
* @param array $decorator Decorator type and options
* @param mixed $name Decorator name or alias
* @return Zend_Form_Decorator_Interface
*/
protected function _loadDecorator(array $decorator, $name)
{
$sameName = false;
if ($name == $decorator['decorator']) {
$sameName = true;
}
$instance = $this->_getDecorator($decorator['decorator'], $decorator['options']);
if ($sameName) {
$newName = get_class($instance);
$decoratorNames = array_keys($this->_decorators);
$order = array_flip($decoratorNames);
$order[$newName] = $order[$name];
$decoratorsExchange = array();
unset($order[$name]);
asort($order);
foreach ($order as $key => $index) {
if ($key == $newName) {
$decoratorsExchange[$key] = $instance;
continue;
}
$decoratorsExchange[$key] = $this->_decorators[$key];
}
$this->_decorators = $decoratorsExchange;
} else {
$this->_decorators[$name] = $instance;
}
return $instance;
}
}
TimeSync/Exception.php 0000604 00000003262 15071256135 0010752 0 ustar 00 <?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_TimeSync
* @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 9488 2008-05-19 20:41:34Z thomas $
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Exception class for Zend_TimeSync
*
* @category Zend
* @package Zend_TimeSync
* @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_TimeSync_Exception extends Zend_Exception
{
/**
* Contains array of exceptions thrown in queried server
*
* @var array
*/
protected $_exceptions;
/**
* Adds an exception to the exception list
*
* @param Zend_TimeSync_Exception $exception New exteption to throw
* @return void
*/
public function addException(Zend_TimeSync_Exception $exception)
{
$this->_exceptions[] = $exception;
}
/**
* Returns an array of exceptions that were thrown
*
* @return array
*/
public function get()
{
return $this->_exceptions;
}
}
TimeSync/Protocol.php 0000604 00000007336 15071256135 0010623 0 ustar 00 <?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_TimeSync
* @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: Protocol.php 9488 2008-05-19 20:41:34Z thomas $
*/
/**
* Abstract class definition for all timeserver protocols
*
* @category Zend
* @package Zend_TimeSync
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_TimeSync_Protocol
{
/**
* Holds the current socket connection
*
* @var array
*/
protected $_socket;
/**
* Exceptions that might have occured
*
* @var array
*/
protected $_exceptions;
/**
* Hostname for timeserver
*
* @var string
*/
protected $_timeserver;
/**
* Holds information passed/returned from timeserver
*
* @var array
*/
protected $_info = array();
/**
* Abstract method that prepares the data to send to the timeserver
*
* @return mixed
*/
abstract protected function _prepare();
/**
* Abstract method that reads the data returned from the timeserver
*
* @return mixed
*/
abstract protected function _read();
/**
* Abstract method that writes data to to the timeserver
*
* @param string $data Data to write
* @return void
*/
abstract protected function _write($data);
/**
* Abstract method that extracts the binary data returned from the timeserver
*
* @param string|array $data Data returned from the timeserver
* @return integer
*/
abstract protected function _extract($data);
/**
* Connect to the specified timeserver.
*
* @return void
* @throws Zend_TimeSync_Exception When the connection failed
*/
protected function _connect()
{
$socket = @fsockopen($this->_timeserver, $this->_port, $errno, $errstr,
Zend_TimeSync::$options['timeout']);
if ($socket === false) {
throw new Zend_TimeSync_Exception('could not connect to ' .
"'$this->_timeserver' on port '$this->_port', reason: '$errstr'");
}
$this->_socket = $socket;
}
/**
* Disconnects from the peer, closes the socket.
*
* @return void
*/
protected function _disconnect()
{
@fclose($this->_socket);
$this->_socket = null;
}
/**
* Return information sent/returned from the timeserver
*
* @return array
*/
public function getInfo()
{
if (empty($this->_info) === true) {
$this->_write($this->_prepare());
$timestamp = $this->_extract($this->_read());
}
return $this->_info;
}
/**
* Query this timeserver without using the fallback mechanism
*
* @param string|Zend_Locale $locale (Optional) Locale
* @return Zend_Date
*/
public function getDate($locale = null)
{
$this->_write($this->_prepare());
$timestamp = $this->_extract($this->_read());
$date = new Zend_Date($this, null, $locale);
return $date;
}
}
TimeSync/Ntp.php 0000604 00000032607 15071256135 0007562 0 ustar 00 <?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_TimeSync
* @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: Ntp.php 9488 2008-05-19 20:41:34Z thomas $
*/
/**
* Zend_TimeSync_Protocol
*/
require_once 'Zend/TimeSync/Protocol.php';
/**
* NTP Protocol handling class
*
* @category Zend
* @package Zend_TimeSync
* @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_TimeSync_Ntp extends Zend_TimeSync_Protocol
{
/**
* NTP port number (123) assigned by the Internet Assigned Numbers Authority
*
* @var integer
*/
protected $_port = 123;
/**
* NTP class constructor, sets the timeserver and port number
*
* @param string $timeserver Adress of the timeserver to connect to
* @param integer $port (Optional) Port for this timeserver
*/
public function __construct($timeserver, $port = 123)
{
$this->_timeserver = 'udp://' . $timeserver;
if (is_null($port) === false) {
$this->_port = $port;
}
}
/**
* Prepare local timestamp for transmission in our request packet
*
* NTP timestamps are represented as a 64-bit fixed-point number, in
* seconds relative to 0000 UT on 1 January 1900. The integer part is
* in the first 32 bits and the fraction part in the last 32 bits
*
* @return string
*/
protected function _prepare()
{
$frac = microtime();
$fracba = ($frac & 0xff000000) >> 24;
$fracbb = ($frac & 0x00ff0000) >> 16;
$fracbc = ($frac & 0x0000ff00) >> 8;
$fracbd = ($frac & 0x000000ff);
$sec = (time() + 2208988800);
$secba = ($sec & 0xff000000) >> 24;
$secbb = ($sec & 0x00ff0000) >> 16;
$secbc = ($sec & 0x0000ff00) >> 8;
$secbd = ($sec & 0x000000ff);
// Flags
$nul = chr(0x00);
$nulbyte = $nul . $nul . $nul . $nul;
$ntppacket = chr(0xd9) . $nul . chr(0x0a) . chr(0xfa);
/*
* Root delay
*
* Indicates the total roundtrip delay to the primary reference
* source at the root of the synchronization subnet, in seconds
*/
$ntppacket .= $nul . $nul . chr(0x1c) . chr(0x9b);
/*
* Clock Dispersion
*
* Indicates the maximum error relative to the primary reference source at the
* root of the synchronization subnet, in seconds
*/
$ntppacket .= $nul . chr(0x08) . chr(0xd7) . chr(0xff);
/*
* ReferenceClockID
*
* Identifying the particular reference clock
*/
$ntppacket .= $nulbyte;
/*
* The local time, in timestamp format, at the peer when its latest NTP message
* was sent. Contanis an integer and a fractional part
*/
$ntppacket .= chr($secba) . chr($secbb) . chr($secbc) . chr($secbd);
$ntppacket .= chr($fracba) . chr($fracbb) . chr($fracbc) . chr($fracbd);
/*
* The local time, in timestamp format, at the peer. Contains an integer
* and a fractional part.
*/
$ntppacket .= $nulbyte;
$ntppacket .= $nulbyte;
/*
* This is the local time, in timestamp format, when the latest NTP message from
* the peer arrived. Contanis an integer and a fractional part.
*/
$ntppacket .= $nulbyte;
$ntppacket .= $nulbyte;
/*
* The local time, in timestamp format, at which the
* NTP message departed the sender. Contanis an integer
* and a fractional part.
*/
$ntppacket .= chr($secba) . chr($secbb) . chr($secbc) . chr($secbd);
$ntppacket .= chr($fracba) . chr($fracbb) . chr($fracbc) . chr($fracbd);
return $ntppacket;
}
/**
* Reads the data returned from the timeserver
*
* This will return an array with binary data listing:
*
* @return array
* @throws Zend_TimeSync_Exception When timeserver can not be connected
*/
protected function _read()
{
$flags = ord(fread($this->_socket, 1));
$info = stream_get_meta_data($this->_socket);
if ($info['timed_out'] === true) {
fclose($this->_socket);
throw new Zend_TimeSync_Exception('could not connect to ' .
"'$this->_timeserver' on port '$this->_port', reason: 'server timed out'");
}
$result = array(
'flags' => $flags,
'stratum' => ord(fread($this->_socket, 1)),
'poll' => ord(fread($this->_socket, 1)),
'precision' => ord(fread($this->_socket, 1)),
'rootdelay' => ord(fread($this->_socket, 4)),
'rootdispersion' => ord(fread($this->_socket, 4)),
'referenceid' => ord(fread($this->_socket, 4)),
'referencestamp' => ord(fread($this->_socket, 4)),
'referencemicro' => ord(fread($this->_socket, 4)),
'originatestamp' => ord(fread($this->_socket, 4)),
'originatemicro' => ord(fread($this->_socket, 4)),
'receivestamp' => ord(fread($this->_socket, 4)),
'receivemicro' => ord(fread($this->_socket, 4)),
'transmitstamp' => ord(fread($this->_socket, 4)),
'transmitmicro' => ord(fread($this->_socket, 4)),
'clientreceived' => 0
);
$this->_disconnect();
return $result;
}
/**
* Sends the NTP packet to the server
*
* @param string $data Data to send to the timeserver
* @return void
*/
protected function _write($data)
{
$this->_connect();
fwrite($this->_socket, $data);
stream_set_timeout($this->_socket, Zend_TimeSync::$options['timeout']);
}
/**
* Extracts the binary data returned from the timeserver
*
* @param string|array $binary Data returned from the timeserver
* @return integer Difference in seconds
*/
protected function _extract($binary)
{
/*
* Leap Indicator bit 1100 0000
*
* Code warning of impending leap-second to be inserted at the end of
* the last day of the current month.
*/
$leap = ($binary['flags'] & 0xc0) >> 6;
switch($leap) {
case 0:
$this->_info['leap'] = '0 - no warning';
break;
case 1:
$this->_info['leap'] = '1 - last minute has 61 seconds';
break;
case 2:
$this->_info['leap'] = '2 - last minute has 59 seconds';
break;
default:
$this->_info['leap'] = '3 - not syncronised';
break;
}
/*
* Version Number bit 0011 1000
*
* This should be 3 (RFC 1305)
*/
$this->_info['version'] = ($binary['flags'] & 0x38) >> 3;
/*
* Mode bit 0000 0111
*
* Except in broadcast mode, an NTP association is formed when two peers
* exchange messages and one or both of them create and maintain an
* instantiation of the protocol machine, called an association.
*/
$mode = ($binary['flags'] & 0x07);
switch($mode) {
case 1:
$this->_info['mode'] = 'symetric active';
break;
case 2:
$this->_info['mode'] = 'symetric passive';
break;
case 3:
$this->_info['mode'] = 'client';
break;
case 4:
$this->_info['mode'] = 'server';
break;
case 5:
$this->_info['mode'] = 'broadcast';
break;
default:
$this->_info['mode'] = 'reserved';
break;
}
$ntpserviceid = 'Unknown Stratum ' . $binary['stratum'] . ' Service';
/*
* Reference Clock Identifier
*
* Identifies the particular reference clock.
*/
$refid = strtoupper($binary['referenceid']);
switch($binary['stratum']) {
case 0:
if (substr($refid, 0, 3) === 'DCN') {
$ntpserviceid = 'DCN routing protocol';
} else if (substr($refid, 0, 4) === 'NIST') {
$ntpserviceid = 'NIST public modem';
} else if (substr($refid, 0, 3) === 'TSP') {
$ntpserviceid = 'TSP time protocol';
} else if (substr($refid, 0, 3) === 'DTS') {
$ntpserviceid = 'Digital Time Service';
}
break;
case 1:
if (substr($refid, 0, 4) === 'ATOM') {
$ntpserviceid = 'Atomic Clock (calibrated)';
} else if (substr($refid, 0, 3) === 'VLF') {
$ntpserviceid = 'VLF radio';
} else if ($refid === 'CALLSIGN') {
$ntpserviceid = 'Generic radio';
} else if (substr($refid, 0, 4) === 'LORC') {
$ntpserviceid = 'LORAN-C radionavigation';
} else if (substr($refid, 0, 4) === 'GOES') {
$ntpserviceid = 'GOES UHF environment satellite';
} else if (substr($refid, 0, 3) === 'GPS') {
$ntpserviceid = 'GPS UHF satellite positioning';
}
break;
default:
$ntpserviceid = ord(substr($binary['referenceid'], 0, 1));
$ntpserviceid .= '.';
$ntpserviceid .= ord(substr($binary['referenceid'], 1, 1));
$ntpserviceid .= '.';
$ntpserviceid .= ord(substr($binary['referenceid'], 2, 1));
$ntpserviceid .= '.';
$ntpserviceid .= ord(substr($binary['referenceid'], 3, 1));
break;
}
$this->_info['ntpid'] = $ntpserviceid;
/*
* Stratum
*
* Indicates the stratum level of the local clock
*/
switch($binary['stratum']) {
case 0:
$this->_info['stratum'] = 'undefined';
break;
case 1:
$this->_info['stratum'] = 'primary reference';
break;
default:
$this->_info['stratum'] = 'secondary reference';
break;
}
/*
* Indicates the total roundtrip delay to the primary reference source at the
* root of the synchronization subnet, in seconds.
*
* Both positive and negative values, depending on clock precision and skew, are
* possible.
*/
$this->_info['rootdelay'] = $binary['rootdelay'] >> 15;
$this->_info['rootdelayfrac'] = ($binary['rootdelay'] << 17) >> 17;
/*
* Indicates the maximum error relative to the primary reference source at the
* root of the synchronization subnet, in seconds.
*
* Only positive values greater than zero are possible.
*/
$this->_info['rootdispersion'] = $binary['rootdispersion'] >> 15;
$this->_info['rootdispersionfrac'] = ($binary['rootdispersion'] << 17) >> 17;
/*
* The local time, in timestamp format, at the peer
* when its latest NTP message was sent.
*/
$original = (float) $binary['originatestamp'];
$original += (float) ($binary['originatemicro'] / 4294967296);
/*
* The local time, in timestamp format, when the latest
* NTP message from the peer arrived.
*/
$received = (float) $binary['receivestamp'];
$received += (float) ($binary['receivemicro'] / 4294967296);
/*
* The local time, in timestamp format, at which the
* NTP message departed the sender.
*/
$transmit = (float) $binary['transmitstamp'];
$transmit += (float) ($binary['transmitmicro'] / 4294967296);
/*
* The roundtrip delay of the peer clock relative to the local clock
* over the network path between them, in seconds.
*
* Note that this variable can take on both positive and negative values,
* depending on clock precision and skew-error accumulation.
*/
$roundtrip = ($binary['clientreceived'] - $original);
$roundtrip -= ($transmit - $received);
$this->_info['roundtrip'] = ($roundtrip / 2);
// The offset of the peer clock relative to the local clock, in seconds.
$offset = ($received - $original + $transmit - $binary['clientreceived']);
$this->_info['offset'] = ($offset / 2);
$time = (time() - $this->_info['offset']);
return $time;
}
}
TimeSync/Sntp.php 0000604 00000005621 15071256135 0007741 0 ustar 00 <?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_TimeSync
* @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: Sntp.php 10835 2008-08-08 22:28:26Z thomas $
*/
/**
* Zend_TimeSync_Protocol
*/
require_once 'Zend/TimeSync/Protocol.php';
/**
* SNTP Protocol handling class
*
* @category Zend
* @package Zend_TimeSync
* @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_TimeSync_Sntp extends Zend_TimeSync_Protocol
{
/**
* Port number for this timeserver
*
* @var integer
*/
protected $_port = 37;
/**
* Socket delay
*
* @var integer
*/
private $_delay;
/**
* Class constructor, sets the timeserver and port number
*
* @param string $timeserver Timeserver to connect to
* @param integer $port Port of the timeserver when it differs from the default port
*/
public function __construct($timeserver, $port)
{
$this->_timeserver = 'udp://' . $timeserver;
if (is_null($port) === false) {
$this->_port = $port;
}
}
/**
* Prepares the data that will be send to the timeserver
*
* @return array
*/
protected function _prepare()
{
return "\n";
}
/**
* Reads the data returned from the timeserver
*
* @return string
*/
protected function _read()
{
$result = fread($this->_socket, 49);
$this->_delay = (($this->_delay - time()) / 2);
return $result;
}
/**
* Writes data to to the timeserver
*
* @param string $data Data to write to the timeserver
* @return void
*/
protected function _write($data)
{
$this->_connect();
$this->_delay = time();
fputs($this->_socket, $data);
}
/**
* Extracts the data returned from the timeserver
*
* @param string $result Data to extract
* @return integer
*/
protected function _extract($result)
{
$dec = hexdec('7fffffff');
$time = abs(($dec - hexdec(bin2hex($result))) - $dec);
$time -= 2208988800;
// Socket delay
$time -= $this->_delay;
$this->_info['offset'] = $this->_delay;
return $time;
}
}
ProgressBar.php 0000604 00000013411 15071256135 0007507 0 ustar 00 <?php
/**
* 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_ProgressBar
* @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: ProgressBar.php 12296 2008-11-05 11:26:37Z dasprid $
*/
/**
* Zend_ProgressBar offers an interface for multiple enviroments.
*
* @category Zend
* @package Zend_ProgressBar
* @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_ProgressBar
{
/**
* Min value
*
* @var float
*/
protected $_min;
/**
* Max value
*
* @var float
*/
protected $_max;
/**
* Current value
*
* @var float
*/
protected $_current;
/**
* Start time of the progressbar, required for ETA
*
* @var integer
*/
protected $_startTime;
/**
* Current status text
*
* @var string
*/
protected $_statusText = null;
/**
* Adapter for the output
*
* @var Zend_ProgressBar_Adapter
*/
protected $_adapter;
/**
* Namespace for keeping the progressbar persistent
*
* @var string
*/
protected $_persistenceNamespace = null;
/**
* Create a new progressbar backend.
*
* @param Zend_ProgressBar_Adapter $adapter
* @param float $min
* @param float $max
* @param string $persistenceNamespace
* @throws Zend_ProgressBar_Exception When $min is greater than $max
*/
public function __construct(Zend_ProgressBar_Adapter $adapter, $min = 0, $max = 100, $persistenceNamespace = null)
{
// Check min/max values and set them
if ($min > $max) {
require_once 'Zend/ProgressBar/Exception.php';
throw new Zend_ProgressBar_Exception('$max must be greater than $min');
}
$this->_min = (float) $min;
$this->_max = (float) $max;
$this->_current = (float) $min;
// See if we have to open a session namespace
if ($persistenceNamespace !== null) {
require_once 'Zend/Session/Namespace.php';
$this->_persistenceNamespace = new Zend_Session_Namespace($persistenceNamespace);
}
// Set adapter
$this->_adapter = $adapter;
// Track the start time
$this->_startTime = time();
// See If a persistenceNamespace exists and handle accordingly
if ($this->_persistenceNamespace !== null) {
if (isset($this->_persistenceNamespace->isSet)) {
$this->_startTime = $this->_persistenceNamespace->startTime;
$this->_current = $this->_persistenceNamespace->current;
$this->_statusText = $this->_persistenceNamespace->statusText;
} else {
$this->_persistenceNamespace->isSet = true;
$this->_persistenceNamespace->startTime = $this->_startTime;
$this->_persistenceNamespace->current = $this->_current;
$this->_persistenceNamespace->statusText = $this->_statusText;
}
} else {
$this->update();
}
}
/**
* Get the current adapter
*
* @return Zend_ProgressBar_Adapter
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
* Update the progressbar
*
* @param float $value
* @param string $text
* @return void
*/
public function update($value = null, $text = null)
{
// Update value if given
if ($value !== null) {
$this->_current = min($this->_max, max($this->_min, $value));
}
// Update text if given
if ($text !== null) {
$this->_statusText = $text;
}
// See if we have to update a namespace
if ($this->_persistenceNamespace !== null) {
$this->_persistenceNamespace->current = $this->_current;
$this->_persistenceNamespace->statusText = $this->_statusText;
}
// Calculate percent
$percent = (float) ($this->_current - $this->_min) / ($this->_max - $this->_min);
// Calculate ETA
$timeTaken = time() - $this->_startTime;
if ($percent === .0) {
$timeRemaining = null;
} else {
$timeRemaining = round(((1 / $percent) * $timeTaken) - $timeTaken);
}
// Poll the adapter
$this->_adapter->notify($this->_current, $this->_max, $percent, $timeTaken, $timeRemaining, $this->_statusText);
}
/**
* Update the progressbar to the next value
*
* @param string $text
* @return void
*/
public function next($diff = 1, $text = null)
{
$this->update(max($this->_min, min($this->_max, $this->_current + $diff)), $text);
}
/**
* Call the adapters finish() behaviour
*
* @return void
*/
public function finish()
{
if ($this->_persistenceNamespace !== null) {
unset($this->_persistenceNamespace->isSet);
}
$this->_adapter->finish();
}
}
Paginator/Adapter/Interface.php 0000604 00000002716 15071256135 0012470 0 ustar 00 <?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_Paginator
* @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: Interface.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* Interface for pagination adapters.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Paginator_Adapter_Interface extends Countable
{
/**
* Returns the total number of rows in the collection.
*
* @return integer
*/
//public function count();
/**
* Returns an collection of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage);
} Paginator/Adapter/DbSelect.php 0000604 00000014760 15071256135 0012257 0 ustar 00 <?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_Paginator
* @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: DbSelect.php 12287 2008-11-04 21:49:22Z mikaelkael $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @see Zend_Db
*/
require_once 'Zend/Db.php';
/**
* @see Zend_Db_Select
*/
require_once 'Zend/Db/Select.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Adapter_DbSelect implements Zend_Paginator_Adapter_Interface
{
/**
* Name of the row count column
*
* @var string
*/
const ROW_COUNT_COLUMN = 'zend_paginator_row_count';
/**
* Database query
*
* @var Zend_Db_Select
*/
protected $_select = null;
/**
* Total item count
*
* @var integer
*/
protected $_rowCount = null;
/**
* Constructor.
*
* @param Zend_Db_Select $select The select query
*/
public function __construct(Zend_Db_Select $select)
{
$this->_select = $select;
}
/**
* Sets the total row count, either directly or through a supplied
* query. Without setting this, {@link getPages()} selects the count
* as a subquery (SELECT COUNT ... FROM (SELECT ...)). While this
* yields an accurate count even with queries containing clauses like
* LIMIT, it can be slow in some circumstances. For example, in MySQL,
* subqueries are generally slow when using the InnoDB storage engine.
* Users are therefore encouraged to profile their queries to find
* the solution that best meets their needs.
*
* @param Zend_Db_Select|integer $totalRowCount Total row count integer
* or query
* @return Zend_Paginator_Adapter_DbSelect $this
* @throws Zend_Paginator_Exception
*/
public function setRowCount($rowCount)
{
if ($rowCount instanceof Zend_Db_Select) {
$columns = $rowCount->getPart(Zend_Db_Select::COLUMNS);
$countColumnPart = $columns[0][1];
if ($countColumnPart instanceof Zend_Db_Expr) {
$countColumnPart = $countColumnPart->__toString();
}
// The select query can contain only one column, which should be the row count column
if (false === strpos($countColumnPart, self::ROW_COUNT_COLUMN)) {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Row count column not found');
}
$result = $rowCount->query(Zend_Db::FETCH_ASSOC)->fetch();
$this->_rowCount = count($result) > 0 ? $result[self::ROW_COUNT_COLUMN] : 0;
} else if (is_integer($rowCount)) {
$this->_rowCount = $rowCount;
} else {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Invalid row count');
}
return $this;
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
$this->_select->limit($itemCountPerPage, $offset);
return $this->_select->query()->fetchAll();
}
/**
* Returns the total number of rows in the result set.
*
* @return integer
*/
public function count()
{
if ($this->_rowCount === null) {
$rowCount = clone $this->_select;
/**
* The DISTINCT and GROUP BY queries only work when selecting one column.
* The question is whether any RDBMS supports DISTINCT for multiple columns, without workarounds.
*/
if (true === $rowCount->getPart(Zend_Db_Select::DISTINCT)) {
$columnParts = $rowCount->getPart(Zend_Db_Select::COLUMNS);
$columns = array();
foreach ($columnParts as $part) {
if ($part[1] == '*' || $part[1] instanceof Zend_Db_Expr) {
$columns[] = $part[1];
} else {
$columns[] = $rowCount->getAdapter()->quoteIdentifier($part[1], true);
}
}
if (count($columns) == 1 && $columns[0] == '*') {
$groupPart = null;
} else {
$groupPart = implode(',', $columns);
}
} else {
$groupParts = $rowCount->getPart(Zend_Db_Select::GROUP);
foreach ($groupParts as &$part) {
if (!($part == '*' || $part instanceof Zend_Db_Expr)) {
$part = $rowCount->getAdapter()->quoteIdentifier($part, true);
}
}
$groupPart = implode(',', $groupParts);
}
$countPart = empty($groupPart) ? 'COUNT(*)' : 'COUNT(DISTINCT ' . $groupPart . ')';
$expression = new Zend_Db_Expr($countPart . ' AS ' . $rowCount->getAdapter()->quoteIdentifier(self::ROW_COUNT_COLUMN));
$rowCount->__toString(); // Workaround for ZF-3719 and related
$rowCount->reset(Zend_Db_Select::COLUMNS)
->reset(Zend_Db_Select::ORDER)
->reset(Zend_Db_Select::LIMIT_OFFSET)
->reset(Zend_Db_Select::GROUP)
->reset(Zend_Db_Select::DISTINCT)
->columns($expression);
$this->setRowCount($rowCount);
}
return $this->_rowCount;
}
}
Paginator/Adapter/Null.php 0000604 00000003604 15071256135 0011477 0 ustar 00 <?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_Paginator
* @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: Null.php 10792 2008-08-08 03:11:03Z mratzloff $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Adapter_Null implements Zend_Paginator_Adapter_Interface
{
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param array $count Total item count
*/
public function __construct($count = 0)
{
$this->_count = $count;
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
return array_fill(0, $itemCountPerPage, null);
}
/**
* Returns the total number of rows in the array.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
} Paginator/Adapter/Array.php 0000604 00000004031 15071256135 0011636 0 ustar 00 <?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_Paginator
* @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: Array.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Adapter_Array implements Zend_Paginator_Adapter_Interface
{
/**
* Array
*
* @var array
*/
protected $_array = null;
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param array $array Array to paginate
*/
public function __construct(array $array)
{
$this->_array = $array;
$this->_count = count($array);
}
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage)
{
return array_slice($this->_array, $offset, $itemCountPerPage);
}
/**
* Returns the total number of rows in the array.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
} Paginator/Adapter/DbTableSelect.php 0000604 00000003124 15071256135 0013217 0 ustar 00 <?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_Paginator
* @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: DbTableSelect.php 11735 2008-10-08 14:00:24Z norm2782 $
*/
/**
* @see Zend_Paginator_Adapter_DbSelect
*/
require_once 'Zend/Paginator/Adapter/DbSelect.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Adapter_DbTableSelect extends Zend_Paginator_Adapter_DbSelect
{
/**
* Returns a Zend_Db_Table_Rowset_Abstract of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return Zend_Db_Table_Rowset_Abstract
*/
public function getItems($offset, $itemCountPerPage)
{
$this->_select->limit($itemCountPerPage, $offset);
return $this->_select->getTable()->fetchAll($this->_select);
}
} Paginator/Adapter/Iterator.php 0000604 00000005036 15071256135 0012357 0 ustar 00 <?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_Paginator
* @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: Iterator.php 11222 2008-09-04 03:18:34Z mratzloff $
*/
/**
* @see Zend_Paginator_Adapter_Interface
*/
require_once 'Zend/Paginator/Adapter/Interface.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Adapter_Iterator implements Zend_Paginator_Adapter_Interface
{
/**
* Iterator which implements Countable
*
* @var Iterator
*/
protected $_iterator = null;
/**
* Item count
*
* @var integer
*/
protected $_count = null;
/**
* Constructor.
*
* @param Iterator $iterator Iterator to paginate
* @throws Zend_Paginator_Exception
*/
public function __construct(Iterator $iterator)
{
if (!$iterator instanceof Countable) {
/**
* @see Zend_Paginator_Exception
*/
require_once 'Zend/Paginator/Exception.php';
throw new Zend_Paginator_Exception('Iterator must implement Countable');
}
$this->_iterator = $iterator;
$this->_count = count($iterator);
}
/**
* Returns an iterator of items for a page, or an empty array.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return LimitIterator|array
*/
public function getItems($offset, $itemCountPerPage)
{
if ($this->_count == 0) {
return array();
}
return new LimitIterator($this->_iterator, $offset, $itemCountPerPage);
}
/**
* Returns the total number of rows in the collection.
*
* @return integer
*/
public function count()
{
return $this->_count;
}
} Paginator/Exception.php 0000604 00000002116 15071256135 0011140 0 ustar 00 <?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_Paginator
* @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 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Paginator
* @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_Paginator_Exception extends Zend_Exception
{
} Paginator/ScrollingStyle/Jumping.php 0000604 00000004112 15071256135 0013566 0 ustar 00 <?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_Paginator
* @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: Jumping.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_ScrollingStyle_Interface
*/
require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
/**
* A scrolling style in which the cursor advances to the upper bound
* of the page range, the page range "jumps" to the next section, and
* the cursor moves back to the beginning of the range.
*
* @category Zend
* @package Zend_Paginator
* @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_Paginator_ScrollingStyle_Jumping implements Zend_Paginator_ScrollingStyle_Interface
{
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange Unused
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
$pageRange = $paginator->getPageRange();
$pageNumber = $paginator->getCurrentPageNumber();
$delta = $pageNumber % $pageRange;
if ($delta == 0) {
$delta = $pageRange;
}
$offset = $pageNumber - $delta;
$lowerBound = $offset + 1;
$upperBound = $offset + $pageRange;
return $paginator->getPagesInRange($lowerBound, $upperBound);
}
} Paginator/ScrollingStyle/Sliding.php 0000604 00000005144 15071256135 0013554 0 ustar 00 <?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_Paginator
* @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: Sliding.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_ScrollingStyle_Interface
*/
require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
/**
* A Yahoo! Search-like scrolling style. The cursor will advance to
* the middle of the range, then remain there until the user reaches
* the end of the page set, at which point it will continue on to
* the end of the range and the last page in the set.
*
* @link http://search.yahoo.com/search?p=Zend+Framework
* @category Zend
* @package Zend_Paginator
* @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_Paginator_ScrollingStyle_Sliding implements Zend_Paginator_ScrollingStyle_Interface
{
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
if ($pageRange === null) {
$pageRange = $paginator->getPageRange();
}
$pageNumber = $paginator->getCurrentPageNumber();
$pageCount = count($paginator);
if ($pageRange > $pageCount) {
$pageRange = $pageCount;
}
$delta = ceil($pageRange / 2);
if ($pageNumber - $delta > $pageCount - $pageRange) {
$lowerBound = $pageCount - $pageRange + 1;
$upperBound = $pageCount;
} else {
if ($pageNumber - $delta < 0) {
$delta = $pageNumber;
}
$offset = $pageNumber - $delta;
$lowerBound = $offset + 1;
$upperBound = $offset + $pageRange;
}
return $paginator->getPagesInRange($lowerBound, $upperBound);
}
} Paginator/ScrollingStyle/All.php 0000604 00000003310 15071256135 0012664 0 ustar 00 <?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_Paginator
* @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: All.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_ScrollingStyle_Interface
*/
require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
/**
* A scrolling style that returns every page in the collection.
* Useful when it is necessary to make every page available at
* once--for example, when using a dropdown menu pagination control.
*
* @category Zend
* @package Zend_Paginator
* @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_Paginator_ScrollingStyle_All implements Zend_Paginator_ScrollingStyle_Interface
{
/**
* Returns an array of all pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange Unused
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
return $paginator->getPagesInRange(1, $paginator->count());
}
} Paginator/ScrollingStyle/Elastic.php 0000604 00000004062 15071256135 0013545 0 ustar 00 <?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_Paginator
* @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: Elastic.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @see Zend_Paginator_ScrollingStyle_Sliding
*/
require_once 'Zend/Paginator/ScrollingStyle/Sliding.php';
/**
* A Google-like scrolling style. Incrementally expands the range to about
* twice the given page range, then behaves like a slider. See the example
* link.
*
* @link http://www.google.com/search?q=Zend+Framework
* @category Zend
* @package Zend_Paginator
* @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_Paginator_ScrollingStyle_Elastic extends Zend_Paginator_ScrollingStyle_Sliding
{
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange Unused
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
$pageRange = $paginator->getPageRange();
$pageNumber = $paginator->getCurrentPageNumber();
$originalPageRange = $pageRange;
$pageRange = $pageRange * 2 - 1;
if ($originalPageRange + $pageNumber - 1 < $pageRange) {
$pageRange = $originalPageRange + $pageNumber - 1;
}
return parent::getPages($paginator, $pageRange);
}
} Paginator/ScrollingStyle/Interface.php 0000604 00000002451 15071256135 0014061 0 ustar 00 <?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_Paginator
* @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: Interface.php 10013 2008-07-09 21:08:06Z norm2782 $
*/
/**
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Paginator_ScrollingStyle_Interface
{
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null);
} Mime.php 0000604 00000021547 15071256135 0006156 0 ustar 00 <?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_Mime
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Support class for MultiPart Mime Messages
*
* @category Zend
* @package Zend_Mime
* @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_Mime
{
const TYPE_OCTETSTREAM = 'application/octet-stream';
const TYPE_TEXT = 'text/plain';
const TYPE_HTML = 'text/html';
const ENCODING_7BIT = '7bit';
const ENCODING_8BIT = '8bit';
const ENCODING_QUOTEDPRINTABLE = 'quoted-printable';
const ENCODING_BASE64 = 'base64';
const DISPOSITION_ATTACHMENT = 'attachment';
const DISPOSITION_INLINE = 'inline';
const LINELENGTH = 72;
const LINEEND = "\n";
const MULTIPART_ALTERNATIVE = 'multipart/alternative';
const MULTIPART_MIXED = 'multipart/mixed';
const MULTIPART_RELATED = 'multipart/related';
protected $_boundary;
protected static $makeUnique = 0;
// lookup-Tables for QuotedPrintable
public static $qpKeys = array(
"\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07",
"\x08","\x09","\x0A","\x0B","\x0C","\x0D","\x0E","\x0F",
"\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17",
"\x18","\x19","\x1A","\x1B","\x1C","\x1D","\x1E","\x1F",
"\x7F","\x80","\x81","\x82","\x83","\x84","\x85","\x86",
"\x87","\x88","\x89","\x8A","\x8B","\x8C","\x8D","\x8E",
"\x8F","\x90","\x91","\x92","\x93","\x94","\x95","\x96",
"\x97","\x98","\x99","\x9A","\x9B","\x9C","\x9D","\x9E",
"\x9F","\xA0","\xA1","\xA2","\xA3","\xA4","\xA5","\xA6",
"\xA7","\xA8","\xA9","\xAA","\xAB","\xAC","\xAD","\xAE",
"\xAF","\xB0","\xB1","\xB2","\xB3","\xB4","\xB5","\xB6",
"\xB7","\xB8","\xB9","\xBA","\xBB","\xBC","\xBD","\xBE",
"\xBF","\xC0","\xC1","\xC2","\xC3","\xC4","\xC5","\xC6",
"\xC7","\xC8","\xC9","\xCA","\xCB","\xCC","\xCD","\xCE",
"\xCF","\xD0","\xD1","\xD2","\xD3","\xD4","\xD5","\xD6",
"\xD7","\xD8","\xD9","\xDA","\xDB","\xDC","\xDD","\xDE",
"\xDF","\xE0","\xE1","\xE2","\xE3","\xE4","\xE5","\xE6",
"\xE7","\xE8","\xE9","\xEA","\xEB","\xEC","\xED","\xEE",
"\xEF","\xF0","\xF1","\xF2","\xF3","\xF4","\xF5","\xF6",
"\xF7","\xF8","\xF9","\xFA","\xFB","\xFC","\xFD","\xFE",
"\xFF"
);
public static $qpReplaceValues = array(
"=00","=01","=02","=03","=04","=05","=06","=07",
"=08","=09","=0A","=0B","=0C","=0D","=0E","=0F",
"=10","=11","=12","=13","=14","=15","=16","=17",
"=18","=19","=1A","=1B","=1C","=1D","=1E","=1F",
"=7F","=80","=81","=82","=83","=84","=85","=86",
"=87","=88","=89","=8A","=8B","=8C","=8D","=8E",
"=8F","=90","=91","=92","=93","=94","=95","=96",
"=97","=98","=99","=9A","=9B","=9C","=9D","=9E",
"=9F","=A0","=A1","=A2","=A3","=A4","=A5","=A6",
"=A7","=A8","=A9","=AA","=AB","=AC","=AD","=AE",
"=AF","=B0","=B1","=B2","=B3","=B4","=B5","=B6",
"=B7","=B8","=B9","=BA","=BB","=BC","=BD","=BE",
"=BF","=C0","=C1","=C2","=C3","=C4","=C5","=C6",
"=C7","=C8","=C9","=CA","=CB","=CC","=CD","=CE",
"=CF","=D0","=D1","=D2","=D3","=D4","=D5","=D6",
"=D7","=D8","=D9","=DA","=DB","=DC","=DD","=DE",
"=DF","=E0","=E1","=E2","=E3","=E4","=E5","=E6",
"=E7","=E8","=E9","=EA","=EB","=EC","=ED","=EE",
"=EF","=F0","=F1","=F2","=F3","=F4","=F5","=F6",
"=F7","=F8","=F9","=FA","=FB","=FC","=FD","=FE",
"=FF"
);
public static $qpKeysString =
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
/**
* Check if the given string is "printable"
*
* Checks that a string contains no unprintable characters. If this returns
* false, encode the string for secure delivery.
*
* @param string $str
* @return boolean
*/
public static function isPrintable($str)
{
return (strcspn($str, self::$qpKeysString) == strlen($str));
}
/**
* Encode a given string with the QUOTED_PRINTABLE mechanism
*
* @param string $str
* @param int $lineLength Defaults to {@link LINELENGTH}
* @param int $lineEnd Defaults to {@link LINEEND}
* @return string
*/
public static function encodeQuotedPrintable($str,
$lineLength = self::LINELENGTH,
$lineEnd = self::LINEEND)
{
$out = '';
$str = str_replace('=', '=3D', $str);
$str = str_replace(self::$qpKeys, self::$qpReplaceValues, $str);
$str = rtrim($str);
// Split encoded text into separate lines
while ($str) {
$ptr = strlen($str);
if ($ptr > $lineLength) {
$ptr = $lineLength;
}
// Ensure we are not splitting across an encoded character
$pos = strrpos(substr($str, 0, $ptr), '=');
if ($pos !== false && $pos >= $ptr - 2) {
$ptr = $pos;
}
// Check if there is a space at the end of the line and rewind
if ($ptr > 0 && $str[$ptr - 1] == ' ') {
--$ptr;
}
// Add string and continue
$out .= substr($str, 0, $ptr) . '=' . $lineEnd;
$str = substr($str, $ptr);
}
$out = rtrim($out, $lineEnd);
$out = rtrim($out, '=');
return $out;
}
/**
* Encode a given string in base64 encoding and break lines
* according to the maximum linelength.
*
* @param string $str
* @param int $lineLength Defaults to {@link LINELENGTH}
* @param int $lineEnd Defaults to {@link LINEEND}
* @return string
*/
public static function encodeBase64($str,
$lineLength = self::LINELENGTH,
$lineEnd = self::LINEEND)
{
return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
}
/**
* Constructor
*
* @param null|string $boundary
* @access public
* @return void
*/
public function __construct($boundary = null)
{
// This string needs to be somewhat unique
if ($boundary === null) {
$this->_boundary = '=_' . md5(microtime(1) . self::$makeUnique++);
} else {
$this->_boundary = $boundary;
}
}
/**
* Encode the given string with the given encoding.
*
* @param string $str
* @param string $encoding
* @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
* @return string
*/
public static function encode($str, $encoding, $EOL = self::LINEEND)
{
switch ($encoding) {
case self::ENCODING_BASE64:
return self::encodeBase64($str, self::LINELENGTH, $EOL);
case self::ENCODING_QUOTEDPRINTABLE:
return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);
default:
/**
* @todo 7Bit and 8Bit is currently handled the same way.
*/
return $str;
}
}
/**
* Return a MIME boundary
*
* @access public
* @return string
*/
public function boundary()
{
return $this->_boundary;
}
/**
* Return a MIME boundary line
*
* @param mixed $EOL Defaults to {@link LINEEND}
* @access public
* @return string
*/
public function boundaryLine($EOL = self::LINEEND)
{
return $EOL . '--' . $this->_boundary . $EOL;
}
/**
* Return MIME ending
*
* @access public
* @return string
*/
public function mimeEnd($EOL = self::LINEEND)
{
return $EOL . '--' . $this->_boundary . '--' . $EOL;
}
}
OpenId/Consumer.php 0000604 00000102375 15071256135 0010237 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Consumer
* @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: Consumer.php 12972 2008-12-01 13:26:36Z dmitry $
*/
/**
* @see Zend_OpenId
*/
require_once "Zend/OpenId.php";
/**
* @see Zend_OpenId_Extension
*/
require_once "Zend/OpenId/Extension.php";
/**
* @see Zend_OpenId_Consumer_Storage
*/
require_once "Zend/OpenId/Consumer/Storage.php";
/**
* @see Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* OpenID consumer implementation
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Consumer
* @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_OpenId_Consumer
{
/**
* Reference to an implementation of storage object
*
* @var Zend_OpenId_Consumer_Storage $_storage
*/
protected $_storage = null;
/**
* Enables or disables consumer to use association with server based on
* Diffie-Hellman key agreement
*
* @var Zend_OpenId_Consumer_Storage $_dumbMode
*/
protected $_dumbMode = false;
/**
* Internal cache to prevent unnecessary access to storage
*
* @var array $_cache
*/
protected $_cache = array();
/**
* HTTP client to make HTTP requests
*
* @var Zend_Http_Client $_httpClient
*/
private $_httpClient = null;
/**
* HTTP session to store climed_id between requests
*
* @var Zend_Session_Namespace $_session
*/
private $_session = null;
/**
* Last error message for logi, check or verify failure
*
* @var string $_error
*/
private $_error = '';
/**
* Constructs a Zend_OpenId_Consumer object with given $storage.
* Enables or disables future association with server based on
* Diffie-Hellman key agreement.
*
* @param Zend_OpenId_Consumer_Storage $storage implementation of custom
* storage object
* @param bool $dumbMode Enables or disables consumer to use association
* with server based on Diffie-Hellman key agreement
*/
public function __construct(Zend_OpenId_Consumer_Storage $storage = null,
$dumbMode = false)
{
if ($storage === null) {
require_once "Zend/OpenId/Consumer/Storage/File.php";
$this->_storage = new Zend_OpenId_Consumer_Storage_File();
} else {
$this->_storage = $storage;
}
$this->_dumbMode = $dumbMode;
}
/**
* Performs check (with possible user interaction) of OpenID identity.
*
* This is the first step of OpenID authentication process.
* On success the function does not return (it does HTTP redirection to
* server and exits). On failure it returns false.
*
* @param string $id OpenID identity
* @param string $returnTo URL to redirect response from server to
* @param string $root HTTP URL to identify consumer on server
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
* @return bool
*/
public function login($id, $returnTo = null, $root = null, $extensions = null,
Zend_Controller_Response_Abstract $response = null)
{
return $this->_checkId(
false,
$id,
$returnTo,
$root,
$extensions,
$response);
}
/**
* Performs immediate check (without user interaction) of OpenID identity.
*
* This is the first step of OpenID authentication process.
* On success the function does not return (it does HTTP redirection to
* server and exits). On failure it returns false.
*
* @param string $id OpenID identity
* @param string $returnTo HTTP URL to redirect response from server to
* @param string $root HTTP URL to identify consumer on server
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
* @return bool
*/
public function check($id, $returnTo=null, $root=null, $extensions = null,
Zend_Controller_Response_Abstract $response = null)
{
return $this->_checkId(
true,
$id,
$returnTo,
$root,
$extensions,
$response);
}
/**
* Verifies authentication response from OpenID server.
*
* This is the second step of OpenID authentication process.
* The function returns true on successful authentication and false on
* failure.
*
* @param array $params HTTP query data from OpenID server
* @param string &$identity this argument is set to end-user's claimed
* identifier or OpenID provider local identifier.
* @param mixed $extensions extension object or array of extensions objects
* @return bool
*/
public function verify($params, &$identity = "", $extensions = null)
{
$this->_setError('');
$version = 1.1;
if (isset($params['openid_ns']) &&
$params['openid_ns'] == Zend_OpenId::NS_2_0) {
$version = 2.0;
}
if (isset($params["openid_claimed_id"])) {
$identity = $params["openid_claimed_id"];
} else if (isset($params["openid_identity"])){
$identity = $params["openid_identity"];
} else {
$identity = "";
}
if ($version < 2.0 && !isset($params["openid_claimed_id"])) {
if ($this->_session !== null) {
if ($this->_session->identity === $identity) {
$identity = $this->_session->claimed_id;
}
} else if (defined('SID')) {
if (isset($_SESSION["zend_openid"]["identity"]) &&
isset($_SESSION["zend_openid"]["claimed_id"]) &&
$_SESSION["zend_openid"]["identity"] === $identity) {
$identity = $_SESSION["zend_openid"]["claimed_id"];
}
} else {
require_once "Zend/Session/Namespace.php";
$this->_session = new Zend_Session_Namespace("zend_openid");
if ($this->_session->identity === $identity) {
$identity = $this->_session->claimed_id;
}
}
}
if (empty($params['openid_mode'])) {
$this->_setError("Missing openid.mode");
return false;
}
if (empty($params['openid_return_to'])) {
$this->_setError("Missing openid.return_to");
return false;
}
if (empty($params['openid_signed'])) {
$this->_setError("Missing openid.signed");
return false;
}
if (empty($params['openid_sig'])) {
$this->_setError("Missing openid.sig");
return false;
}
if ($params['openid_mode'] != 'id_res') {
$this->_setError("Wrong openid.mode '".$params['openid_mode']."' != 'id_res'");
return false;
}
if (empty($params['openid_assoc_handle'])) {
$this->_setError("Missing openid.assoc_handle");
return false;
}
if ($params['openid_return_to'] != Zend_OpenId::selfUrl()) {
/* Ignore query part in openid.return_to */
$pos = strpos($params['openid_return_to'], '?');
if ($pos === false ||
SUBSTR($params['openid_return_to'], 0 , $pos) != Zend_OpenId::selfUrl()) {
$this->_setError("Wrong openid.return_to '".
$params['openid_return_to']."' != '" . Zend_OpenId::selfUrl() ."'");
return false;
}
}
if ($version >= 2.0) {
if (empty($params['openid_response_nonce'])) {
$this->_setError("Missing openid.response_nonce");
return false;
}
if (empty($params['openid_op_endpoint'])) {
$this->_setError("Missing openid.op_endpoint");
return false;
/* OpenID 2.0 (11.3) Checking the Nonce */
} else if (!$this->_storage->isUniqueNonce($params['openid_op_endpoint'], $params['openid_response_nonce'])) {
$this->_setError("Duplicate openid.response_nonce");
return false;
}
}
if (!empty($params['openid_invalidate_handle'])) {
if ($this->_storage->getAssociationByHandle(
$params['openid_invalidate_handle'],
$url,
$macFunc,
$secret,
$expires)) {
$this->_storage->delAssociation($url);
}
}
if ($this->_storage->getAssociationByHandle(
$params['openid_assoc_handle'],
$url,
$macFunc,
$secret,
$expires)) {
$signed = explode(',', $params['openid_signed']);
$data = '';
foreach ($signed as $key) {
$data .= $key . ':' . $params['openid_' . strtr($key,'.','_')] . "\n";
}
if (base64_decode($params['openid_sig']) ==
Zend_OpenId::hashHmac($macFunc, $data, $secret)) {
if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) {
$this->_setError("Extension::prepareResponse failure");
return false;
}
/* OpenID 2.0 (11.2) Verifying Discovered Information */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
if (!Zend_OpenId::normalize($id)) {
$this->_setError("Normalization failed");
return false;
} else if (!$this->_discovery($id, $discovered_server, $discovered_version)) {
$this->_setError("Discovery failed: " . $this->getError());
return false;
} else if ((!empty($params['openid_identity']) &&
$params["openid_identity"] != $id) ||
(!empty($params['openid_op_endpoint']) &&
$params['openid_op_endpoint'] != $discovered_server) ||
$discovered_version != $version) {
$this->_setError("Discovery information verification failed");
return false;
}
}
return true;
}
$this->_storage->delAssociation($url);
$this->_setError("Signature check failed");
return false;
}
else
{
/* Use dumb mode */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
} else if (isset($params['openid_identity'])) {
$id = $params['openid_identity'];
} else {
$this->_setError("Missing openid.climed_id and openid.identity");
return false;
}
if (!Zend_OpenId::normalize($id)) {
$this->_setError("Normalization failed");
return false;
} else if (!$this->_discovery($id, $server, $discovered_version)) {
$this->_setError("Discovery failed: " . $this->getError());
return false;
}
/* OpenID 2.0 (11.2) Verifying Discovered Information */
if ((isset($params['openid_identity']) &&
$params["openid_identity"] != $id) ||
(isset($params['openid_op_endpoint']) &&
$params['openid_op_endpoint'] != $server) ||
$discovered_version != $version) {
$this->_setError("Discovery information verification failed");
return false;
}
$params2 = array();
foreach ($params as $key => $val) {
if (strpos($key, 'openid_ns_') === 0) {
$key = 'openid.ns.' . substr($key, strlen('openid_ns_'));
} else if (strpos($key, 'openid_sreg_') === 0) {
$key = 'openid.sreg.' . substr($key, strlen('openid_sreg_'));
} else if (strpos($key, 'openid_') === 0) {
$key = 'openid.' . substr($key, strlen('openid_'));
}
$params2[$key] = $val;
}
$params2['openid.mode'] = 'check_authentication';
$ret = $this->_httpRequest($server, 'POST', $params2, $status);
if ($status != 200) {
$this->_setError("'Dumb' signature verification HTTP request failed");
return false;
}
$r = array();
if (is_string($ret)) {
foreach(explode("\n", $ret) as $line) {
$line = trim($line);
if (!empty($line)) {
$x = explode(':', $line, 2);
if (is_array($x) && count($x) == 2) {
list($key, $value) = $x;
$r[trim($key)] = trim($value);
}
}
}
}
$ret = $r;
if (!empty($ret['invalidate_handle'])) {
if ($this->_storage->getAssociationByHandle(
$ret['invalidate_handle'],
$url,
$macFunc,
$secret,
$expires)) {
$this->_storage->delAssociation($url);
}
}
if (isset($ret['is_valid']) && $ret['is_valid'] == 'true') {
if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) {
$this->_setError("Extension::parseResponse failure");
return false;
}
return true;
}
$this->_setError("'Dumb' signature verification failed");
return false;
}
}
/**
* Store assiciation in internal chace and external storage
*
* @param string $url OpenID server url
* @param string $handle association handle
* @param string $macFunc HMAC function (sha1 or sha256)
* @param string $secret shared secret
* @param integer $expires expiration UNIX time
* @return void
*/
protected function _addAssociation($url, $handle, $macFunc, $secret, $expires)
{
$this->_cache[$url] = array($handle, $macFunc, $secret, $expires);
return $this->_storage->addAssociation(
$url,
$handle,
$macFunc,
$secret,
$expires);
}
/**
* Retrive assiciation information for given $url from internal cahce or
* external storage
*
* @param string $url OpenID server url
* @param string &$handle association handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param integer &$expires expiration UNIX time
* @return void
*/
protected function _getAssociation($url, &$handle, &$macFunc, &$secret, &$expires)
{
if (isset($this->_cache[$url])) {
$handle = $this->_cache[$url][0];
$macFunc = $this->_cache[$url][1];
$secret = $this->_cache[$url][2];
$expires = $this->_cache[$url][3];
return true;
}
if ($this->_storage->getAssociation(
$url,
$handle,
$macFunc,
$secret,
$expires)) {
$this->_cache[$url] = array($handle, $macFunc, $secret, $expires);
return true;
}
return false;
}
/**
* Performs HTTP request to given $url using given HTTP $method.
* Send additinal query specified by variable/value array,
* On success returns HTTP response without headers, false on failure.
*
* @param string $url OpenID server url
* @param string $method HTTP request method 'GET' or 'POST'
* @param array $params additional qwery parameters to be passed with
* @param int &$staus HTTP status code
* request
* @return mixed
*/
protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null)
{
$client = $this->_httpClient;
if ($client === null) {
$client = new Zend_Http_Client(
$url,
array(
'maxredirects' => 4,
'timeout' => 15,
'useragent' => 'Zend_OpenId'
)
);
} else {
$client->setUri($url);
}
$client->resetParameters();
if ($method == 'POST') {
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost($params);
} else {
$client->setMethod(Zend_Http_Client::GET);
$client->setParameterGet($params);
}
try {
$response = $client->request();
} catch (Exception $e) {
$this->_setError('HTTP Request failed: ' . $e->getMessage());
return false;
}
$status = $response->getStatus();
$body = $response->getBody();
if ($status == 200 || ($status == 400 && !empty($body))) {
return $body;
}else{
$this->_setError('Bad HTTP response');
return false;
}
}
/**
* Create (or reuse existing) association between OpenID consumer and
* OpenID server based on Diffie-Hellman key agreement. Returns true
* on success and false on failure.
*
* @param string $url OpenID server url
* @param float $version OpenID protocol version
* @param string $priv_key for testing only
* @return bool
*/
protected function _associate($url, $version, $priv_key=null)
{
/* Check if we already have association in chace or storage */
if ($this->_getAssociation(
$url,
$handle,
$macFunc,
$secret,
$expires)) {
return true;
}
if ($this->_dumbMode) {
/* Use dumb mode */
return true;
}
$params = array();
if ($version >= 2.0) {
$params = array(
'openid.ns' => Zend_OpenId::NS_2_0,
'openid.mode' => 'associate',
'openid.assoc_type' => 'HMAC-SHA256',
'openid.session_type' => 'DH-SHA256',
);
} else {
$params = array(
'openid.mode' => 'associate',
'openid.assoc_type' => 'HMAC-SHA1',
'openid.session_type' => 'DH-SHA1',
);
}
$dh = Zend_OpenId::createDhKey(pack('H*', Zend_OpenId::DH_P),
pack('H*', Zend_OpenId::DH_G),
$priv_key);
$dh_details = Zend_OpenId::getDhKeyDetails($dh);
$params['openid.dh_modulus'] = base64_encode(
Zend_OpenId::btwoc($dh_details['p']));
$params['openid.dh_gen'] = base64_encode(
Zend_OpenId::btwoc($dh_details['g']));
$params['openid.dh_consumer_public'] = base64_encode(
Zend_OpenId::btwoc($dh_details['pub_key']));
while(1) {
$ret = $this->_httpRequest($url, 'POST', $params, $status);
if ($ret === false) {
$this->_setError("HTTP request failed");
return false;
}
$r = array();
$bad_response = false;
foreach(explode("\n", $ret) as $line) {
$line = trim($line);
if (!empty($line)) {
$x = explode(':', $line, 2);
if (is_array($x) && count($x) == 2) {
list($key, $value) = $x;
$r[trim($key)] = trim($value);
} else {
$bad_response = true;
}
}
}
if ($bad_response && strpos($ret, 'Unknown session type') !== false) {
$r['error_code'] = 'unsupported-type';
}
$ret = $r;
if (isset($ret['error_code']) &&
$ret['error_code'] == 'unsupported-type') {
if ($params['openid.session_type'] == 'DH-SHA256') {
$params['openid.session_type'] = 'DH-SHA1';
$params['openid.assoc_type'] = 'HMAC-SHA1';
} else if ($params['openid.session_type'] == 'DH-SHA1') {
$params['openid.session_type'] = 'no-encryption';
} else {
$this->_setError("The OpenID service responded with: " . $ret['error_code']);
return false;
}
} else {
break;
}
}
if ($status != 200) {
$this->_setError("The server responded with status code: " . $status);
return false;
}
if ($version >= 2.0 &&
isset($ret['ns']) &&
$ret['ns'] != Zend_OpenId::NS_2_0) {
$this->_setError("Wrong namespace definition in the server response");
return false;
}
if (!isset($ret['assoc_handle']) ||
!isset($ret['expires_in']) ||
!isset($ret['assoc_type']) ||
$params['openid.assoc_type'] != $ret['assoc_type']) {
if ($params['openid.assoc_type'] != $ret['assoc_type']) {
$this->_setError("The returned assoc_type differed from the supplied openid.assoc_type");
} else {
$this->_setError("Missing required data from provider (assoc_handle, expires_in, assoc_type are required)");
}
return false;
}
$handle = $ret['assoc_handle'];
$expiresIn = $ret['expires_in'];
if ($ret['assoc_type'] == 'HMAC-SHA1') {
$macFunc = 'sha1';
} else if ($ret['assoc_type'] == 'HMAC-SHA256' &&
$version >= 2.0) {
$macFunc = 'sha256';
} else {
$this->_setError("Unsupported assoc_type");
return false;
}
if ((empty($ret['session_type']) ||
($version >= 2.0 && $ret['session_type'] == 'no-encryption')) &&
isset($ret['mac_key'])) {
$secret = base64_decode($ret['mac_key']);
} else if (isset($ret['session_type']) &&
$ret['session_type'] == 'DH-SHA1' &&
!empty($ret['dh_server_public']) &&
!empty($ret['enc_mac_key'])) {
$dhFunc = 'sha1';
} else if (isset($ret['session_type']) &&
$ret['session_type'] == 'DH-SHA256' &&
$version >= 2.0 &&
!empty($ret['dh_server_public']) &&
!empty($ret['enc_mac_key'])) {
$dhFunc = 'sha256';
} else {
$this->_setError("Unsupported session_type");
return false;
}
if (isset($dhFunc)) {
$serverPub = base64_decode($ret['dh_server_public']);
$dhSec = Zend_OpenId::computeDhSecret($serverPub, $dh);
if ($dhSec === false) {
$this->_setError("DH secret comutation failed");
return false;
}
$sec = Zend_OpenId::digest($dhFunc, $dhSec);
if ($sec === false) {
$this->_setError("Could not create digest");
return false;
}
$secret = $sec ^ base64_decode($ret['enc_mac_key']);
}
if ($macFunc == 'sha1') {
if (Zend_OpenId::strlen($secret) != 20) {
$this->_setError("The length of the sha1 secret must be 20");
return false;
}
} else if ($macFunc == 'sha256') {
if (Zend_OpenId::strlen($secret) != 32) {
$this->_setError("The length of the sha256 secret must be 32");
return false;
}
}
$this->_addAssociation(
$url,
$handle,
$macFunc,
$secret,
time() + $expiresIn);
return true;
}
/**
* Performs discovery of identity and finds OpenID URL, OpenID server URL
* and OpenID protocol version. Returns true on succees and false on
* failure.
*
* @param string &$id OpenID identity URL
* @param string &$server OpenID server URL
* @param float &$version OpenID protocol version
* @return bool
* @todo OpenID 2.0 (7.3) XRI and Yadis discovery
*/
protected function _discovery(&$id, &$server, &$version)
{
$realId = $id;
if ($this->_storage->getDiscoveryInfo(
$id,
$realId,
$server,
$version,
$expire)) {
$id = $realId;
return true;
}
/* TODO: OpenID 2.0 (7.3) XRI and Yadis discovery */
/* HTML-based discovery */
$response = $this->_httpRequest($id, 'GET', array(), $status);
if ($status != 200 || !is_string($response)) {
return false;
}
if (preg_match(
'/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.provider[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i',
$response,
$r)) {
$version = 2.0;
$server = $r[3];
} else if (preg_match(
'/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.provider[ \t]*[^"\']*\\3[^>]*\/?>/i',
$response,
$r)) {
$version = 2.0;
$server = $r[2];
} else if (preg_match(
'/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.server[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i',
$response,
$r)) {
$version = 1.1;
$server = $r[3];
} else if (preg_match(
'/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.server[ \t]*[^"\']*\\3[^>]*\/?>/i',
$response,
$r)) {
$version = 1.1;
$server = $r[2];
} else {
return false;
}
if ($version >= 2.0) {
if (preg_match(
'/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.local_id[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i',
$response,
$r)) {
$realId = $r[3];
} else if (preg_match(
'/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.local_id[ \t]*[^"\']*\\3[^>]*\/?>/i',
$response,
$r)) {
$realId = $r[2];
}
} else {
if (preg_match(
'/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.delegate[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i',
$response,
$r)) {
$realId = $r[3];
} else if (preg_match(
'/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.delegate[ \t]*[^"\']*\\3[^>]*\/?>/i',
$response,
$r)) {
$realId = $r[2];
}
}
$expire = time() + 60 * 60;
$this->_storage->addDiscoveryInfo($id, $realId, $server, $version, $expire);
$id = $realId;
return true;
}
/**
* Performs check of OpenID identity.
*
* This is the first step of OpenID authentication process.
* On success the function does not return (it does HTTP redirection to
* server and exits). On failure it returns false.
*
* @param bool $immediate enables or disables interaction with user
* @param string $id OpenID identity
* @param string $returnTo HTTP URL to redirect response from server to
* @param string $root HTTP URL to identify consumer on server
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
* @return bool
*/
protected function _checkId($immediate, $id, $returnTo=null, $root=null,
$extensions=null, Zend_Controller_Response_Abstract $response = null)
{
$this->_setError('');
if (!Zend_OpenId::normalize($id)) {
$this->_setError("Normalisation failed");
return false;
}
$claimedId = $id;
if (!$this->_discovery($id, $server, $version)) {
$this->_setError("Discovery failed: " . $this->getError());
return false;
}
if (!$this->_associate($server, $version)) {
$this->_setError("Association failed: " . $this->getError());
return false;
}
if (!$this->_getAssociation(
$server,
$handle,
$macFunc,
$secret,
$expires)) {
/* Use dumb mode */
unset($handle);
unset($macFunc);
unset($secret);
unset($expires);
}
$params = array();
if ($version >= 2.0) {
$params['openid.ns'] = Zend_OpenId::NS_2_0;
}
$params['openid.mode'] = $immediate ?
'checkid_immediate' : 'checkid_setup';
$params['openid.identity'] = $id;
$params['openid.claimed_id'] = $claimedId;
if ($version <= 2.0) {
if ($this->_session !== null) {
$this->_session->identity = $id;
$this->_session->claimed_id = $claimedId;
} else if (defined('SID')) {
$_SESSION["zend_openid"] = array(
"identity" => $id,
"claimed_id" => $claimedId);
} else {
require_once "Zend/Session/Namespace.php";
$this->_session = new Zend_Session_Namespace("zend_openid");
$this->_session->identity = $id;
$this->_session->claimed_id = $claimedId;
}
}
if (isset($handle)) {
$params['openid.assoc_handle'] = $handle;
}
$params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
if (empty($root)) {
$root = Zend_OpenId::selfUrl();
if ($root[strlen($root)-1] != '/') {
$root = dirname($root);
}
}
if ($version >= 2.0) {
$params['openid.realm'] = $root;
} else {
$params['openid.trust_root'] = $root;
}
if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
$this->_setError("Extension::prepareRequest failure");
return false;
}
Zend_OpenId::redirect($server, $params, $response);
return true;
}
/**
* Sets HTTP client object to make HTTP requests
*
* @param Zend_Http_Client $client HTTP client object to be used
*/
public function setHttpClient($client) {
$this->_httpClient = $client;
}
/**
* Returns HTTP client object that will be used to make HTTP requests
*
* @return Zend_Http_Client
*/
public function getHttpClient() {
return $this->_httpClient;
}
/**
* Sets session object to store climed_id
*
* @param Zend_Session_Namespace $session HTTP client object to be used
*/
public function setSession(Zend_Session_Namespace $session) {
$this->_session = $session;
}
/**
* Returns session object that is used to store climed_id
*
* @return Zend_Session_Namespace
*/
public function getSession() {
return $this->_session;
}
/**
* Saves error message
*
* @param string $message error message
*/
protected function _setError($message)
{
$this->_error = $message;
}
/**
* Returns error message that explains failure of login, check or verify
*
* @return string
*/
public function getError()
{
return $this->_error;
}
}
OpenId/Exception.php 0000604 00000003045 15071256135 0010374 0 ustar 00 <?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_OpenId
* @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 $
*/
/**
* @see Zend_Exception
*/
require_once "Zend/Exception.php";
/**
* Exception class for Zend_OpenId
*
* @category Zend
* @package Zend_OpenId
* @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_OpenId_Exception extends Zend_Exception
{
/**
* The specified digest algotithm is not supported by this PHP installation
*/
const UNSUPPORTED_DIGEST = 1;
/**
* The long math arithmetick is not supported by this PHP installation
*/
const UNSUPPORTED_LONG_MATH = 2;
/**
* Internal long math arithmetic error
*/
const ERROR_LONG_MATH = 3;
/**
* Iternal storage error
*/
const ERROR_STORAGE = 4;
}
OpenId/Provider.php 0000604 00000064424 15071256135 0010240 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Provider
* @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: Provider.php 12507 2008-11-10 16:29:09Z matthew $
*/
/**
* @see Zend_OpenId
*/
require_once "Zend/OpenId.php";
/**
* @see Zend_OpenId_Extension
*/
require_once "Zend/OpenId/Extension.php";
/**
* OpenID provider (server) implementation
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Provider
* @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_OpenId_Provider
{
/**
* Reference to an implementation of storage object
*
* @var Zend_OpenId_Provider_Storage $_storage
*/
private $_storage;
/**
* Reference to an implementation of user object
*
* @var Zend_OpenId_Provider_User $_user
*/
private $_user;
/**
* Time to live of association session in secconds
*
* @var integer $_sessionTtl
*/
private $_sessionTtl;
/**
* URL to peform interactive user login
*
* @var string $_loginUrl
*/
private $_loginUrl;
/**
* URL to peform interactive validation of consumer by user
*
* @var string $_trustUrl
*/
private $_trustUrl;
/**
* The OP Endpoint URL
*
* @var string $_opEndpoint
*/
private $_opEndpoint;
/**
* Constructs a Zend_OpenId_Provider object with given parameters.
*
* @param string $loginUrl is an URL that provides login screen for
* end-user (by default it is the same URL with additional GET variable
* openid.action=login)
* @param string $trustUrl is an URL that shows a question if end-user
* trust to given consumer (by default it is the same URL with additional
* GET variable openid.action=trust)
* @param Zend_OpenId_Provider_User $user is an object for communication
* with User-Agent and store information about logged-in user (it is a
* Zend_OpenId_Provider_User_Session object by default)
* @param Zend_OpenId_Provider_Storage $storage is an object for keeping
* persistent database (it is a Zend_OpenId_Provider_Storage_File object
* by default)
* @param integer $sessionTtl is a default time to live for association
* session in seconds (1 hour by default). Consumer must reestablish
* association after that time.
*/
public function __construct($loginUrl = null,
$trustUrl = null,
Zend_OpenId_Provider_User $user = null,
Zend_OpenId_Provider_Storage $storage = null,
$sessionTtl = 3600)
{
if ($loginUrl === null) {
$loginUrl = Zend_OpenId::selfUrl() . '?openid.action=login';
} else {
$loginUrl = Zend_OpenId::absoluteUrl($loginUrl);
}
$this->_loginUrl = $loginUrl;
if ($trustUrl === null) {
$trustUrl = Zend_OpenId::selfUrl() . '?openid.action=trust';
} else {
$trustUrl = Zend_OpenId::absoluteUrl($trustUrl);
}
$this->_trustUrl = $trustUrl;
if ($user === null) {
require_once "Zend/OpenId/Provider/User/Session.php";
$this->_user = new Zend_OpenId_Provider_User_Session();
} else {
$this->_user = $user;
}
if ($storage === null) {
require_once "Zend/OpenId/Provider/Storage/File.php";
$this->_storage = new Zend_OpenId_Provider_Storage_File();
} else {
$this->_storage = $storage;
}
$this->_sessionTtl = $sessionTtl;
}
/**
* Sets the OP Endpoint URL
*
* @param string $url the OP Endpoint URL
* @return null
*/
public function setOpEndpoint($url)
{
$this->_opEndpoint = $url;
}
/**
* Registers a new user with given $id and $password
* Returns true in case of success and false if user with given $id already
* exists
*
* @param string $id user identity URL
* @param string $password encoded user password
* @return bool
*/
public function register($id, $password)
{
if (!Zend_OpenId::normalize($id) || empty($id)) {
return false;
}
return $this->_storage->addUser($id, md5($id.$password));
}
/**
* Returns true if user with given $id exists and false otherwise
*
* @param string $id user identity URL
* @return bool
*/
public function hasUser($id) {
if (!Zend_OpenId::normalize($id)) {
return false;
}
return $this->_storage->hasUser($id);
}
/**
* Performs login of user with given $id and $password
* Returns true in case of success and false otherwise
*
* @param string $id user identity URL
* @param string $password user password
* @return bool
*/
public function login($id, $password)
{
if (!Zend_OpenId::normalize($id)) {
return false;
}
if (!$this->_storage->checkUser($id, md5($id.$password))) {
return false;
}
$this->_user->setLoggedInUser($id);
return true;
}
/**
* Performs logout. Clears information about logged in user.
*
* @return void
*/
public function logout()
{
$this->_user->delLoggedInUser();
return true;
}
/**
* Returns identity URL of current logged in user or false
*
* @return mixed
*/
public function getLoggedInUser() {
return $this->_user->getLoggedInUser();
}
/**
* Retrieve consumer's root URL from request query.
* Returns URL or false in case of failure
*
* @param array $params query arguments
* @return mixed
*/
public function getSiteRoot($params)
{
$version = 1.1;
if (isset($params['openid_ns']) &&
$params['openid_ns'] == Zend_OpenId::NS_2_0) {
$version = 2.0;
}
if ($version >= 2.0 && isset($params['openid_realm'])) {
$root = $params['openid_realm'];
} else if ($version < 2.0 && isset($params['openid_trust_root'])) {
$root = $params['openid_trust_root'];
} else if (isset($params['openid_return_to'])) {
$root = $params['openid_return_to'];
} else {
return false;
}
if (Zend_OpenId::normalizeUrl($root) && !empty($root)) {
return $root;
}
return false;
}
/**
* Allows consumer with given root URL to authenticate current logged
* in user. Returns true on success and false on error.
*
* @param string $root root URL
* @param mixed $extensions extension object or array of extensions objects
* @return bool
*/
public function allowSite($root, $extensions=null)
{
$id = $this->getLoggedInUser();
if ($id === false) {
return false;
}
if ($extensions !== null) {
$data = array();
Zend_OpenId_Extension::forAll($extensions, 'getTrustData', $data);
} else {
$data = true;
}
$this->_storage->addSite($id, $root, $data);
return true;
}
/**
* Prohibit consumer with given root URL to authenticate current logged
* in user. Returns true on success and false on error.
*
* @param string $root root URL
* @return bool
*/
public function denySite($root)
{
$id = $this->getLoggedInUser();
if ($id === false) {
return false;
}
$this->_storage->addSite($id, $root, false);
return true;
}
/**
* Delete consumer with given root URL from known sites of current logged
* in user. Next time this consumer will try to authenticate the user,
* Provider will ask user's confirmation.
* Returns true on success and false on error.
*
* @param string $root root URL
* @return bool
*/
public function delSite($root)
{
$id = $this->getLoggedInUser();
if ($id === false) {
return false;
}
$this->_storage->addSite($id, $root, null);
return true;
}
/**
* Returns list of known consumers for current logged in user or false
* if he is not logged in.
*
* @return mixed
*/
public function getTrustedSites()
{
$id = $this->getLoggedInUser();
if ($id === false) {
return false;
}
return $this->_storage->getTrustedSites($id);
}
/**
* Handles HTTP request from consumer
*
* @param array $params GET or POST variables. If this parameter is omited
* or set to null, then $_GET or $_POST superglobal variable is used
* according to REQUEST_METHOD.
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
* @return mixed
*/
public function handle($params=null, $extensions=null,
Zend_Controller_Response_Abstract $response = null)
{
if ($params === null) {
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$params = $_GET;
} else if ($_SERVER["REQUEST_METHOD"] == "POST") {
$params = $_POST;
} else {
return false;
}
}
$version = 1.1;
if (isset($params['openid_ns']) &&
$params['openid_ns'] == Zend_OpenId::NS_2_0) {
$version = 2.0;
}
if (isset($params['openid_mode'])) {
if ($params['openid_mode'] == 'associate') {
$response = $this->_associate($version, $params);
$ret = '';
foreach ($response as $key => $val) {
$ret .= $key . ':' . $val . "\n";
}
return $ret;
} else if ($params['openid_mode'] == 'checkid_immediate') {
$ret = $this->_checkId($version, $params, 1, $extensions, $response);
if (is_bool($ret)) return $ret;
if (!empty($params['openid_return_to'])) {
Zend_OpenId::redirect($params['openid_return_to'], $ret, $response);
}
return true;
} else if ($params['openid_mode'] == 'checkid_setup') {
$ret = $this->_checkId($version, $params, 0, $extensions, $response);
if (is_bool($ret)) return $ret;
if (!empty($params['openid_return_to'])) {
Zend_OpenId::redirect($params['openid_return_to'], $ret, $response);
}
return true;
} else if ($params['openid_mode'] == 'check_authentication') {
$response = $this->_checkAuthentication($version, $params);
$ret = '';
foreach ($response as $key => $val) {
$ret .= $key . ':' . $val . "\n";
}
return $ret;
}
}
return false;
}
/**
* Generates a secret key for given hash function, returns RAW key or false
* if function is not supported
*
* @param string $func hash function (sha1 or sha256)
* @return mixed
*/
protected function _genSecret($func)
{
if ($func == 'sha1') {
$macLen = 20; /* 160 bit */
} else if ($func == 'sha256') {
$macLen = 32; /* 256 bit */
} else {
return false;
}
return Zend_OpenId::randomBytes($macLen);
}
/**
* Processes association request from OpenID consumerm generates secret
* shared key and send it back using Diffie-Hellman encruption.
* Returns array of variables to push back to consumer.
*
* @param float $version OpenID version
* @param array $params GET or POST request variables
* @return array
*/
protected function _associate($version, $params)
{
$ret = array();
if ($version >= 2.0) {
$ret['ns'] = Zend_OpenId::NS_2_0;
}
if (isset($params['openid_assoc_type']) &&
$params['openid_assoc_type'] == 'HMAC-SHA1') {
$macFunc = 'sha1';
} else if (isset($params['openid_assoc_type']) &&
$params['openid_assoc_type'] == 'HMAC-SHA256' &&
$version >= 2.0) {
$macFunc = 'sha256';
} else {
$ret['error'] = 'Wrong "openid.assoc_type"';
$ret['error-code'] = 'unsupported-type';
return $ret;
}
$ret['assoc_type'] = $params['openid_assoc_type'];
$secret = $this->_genSecret($macFunc);
if (empty($params['openid_session_type']) ||
$params['openid_session_type'] == 'no-encryption') {
$ret['mac_key'] = base64_encode($secret);
} else if (isset($params['openid_session_type']) &&
$params['openid_session_type'] == 'DH-SHA1') {
$dhFunc = 'sha1';
} else if (isset($params['openid_session_type']) &&
$params['openid_session_type'] == 'DH-SHA256' &&
$version >= 2.0) {
$dhFunc = 'sha256';
} else {
$ret['error'] = 'Wrong "openid.session_type"';
$ret['error-code'] = 'unsupported-type';
return $ret;
}
if (isset($params['openid_session_type'])) {
$ret['session_type'] = $params['openid_session_type'];
}
if (isset($dhFunc)) {
if (empty($params['openid_dh_consumer_public'])) {
$ret['error'] = 'Wrong "openid.dh_consumer_public"';
return $ret;
}
if (empty($params['openid_dh_gen'])) {
$g = pack('H*', Zend_OpenId::DH_G);
} else {
$g = base64_decode($params['openid_dh_gen']);
}
if (empty($params['openid_dh_modulus'])) {
$p = pack('H*', Zend_OpenId::DH_P);
} else {
$p = base64_decode($params['openid_dh_modulus']);
}
$dh = Zend_OpenId::createDhKey($p, $g);
$dh_details = Zend_OpenId::getDhKeyDetails($dh);
$sec = Zend_OpenId::computeDhSecret(
base64_decode($params['openid_dh_consumer_public']), $dh);
if ($sec === false) {
$ret['error'] = 'Wrong "openid.session_type"';
$ret['error-code'] = 'unsupported-type';
return $ret;
}
$sec = Zend_OpenId::digest($dhFunc, $sec);
$ret['dh_server_public'] = base64_encode(
Zend_OpenId::btwoc($dh_details['pub_key']));
$ret['enc_mac_key'] = base64_encode($secret ^ $sec);
}
$handle = uniqid();
$expiresIn = $this->_sessionTtl;
$ret['assoc_handle'] = $handle;
$ret['expires_in'] = $expiresIn;
$this->_storage->addAssociation($handle,
$macFunc, $secret, time() + $expiresIn);
return $ret;
}
/**
* Performs authentication (or authentication check).
*
* @param float $version OpenID version
* @param array $params GET or POST request variables
* @param bool $immediate enables or disables interaction with user
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response
* @return array
*/
protected function _checkId($version, $params, $immediate, $extensions=null,
Zend_Controller_Response_Abstract $response = null)
{
$ret = array();
if ($version >= 2.0) {
$ret['openid.ns'] = Zend_OpenId::NS_2_0;
}
$root = $this->getSiteRoot($params);
if ($root === false) {
return false;
}
if (isset($params['openid_identity']) &&
!$this->_storage->hasUser($params['openid_identity'])) {
$ret['openid.mode'] = ($immediate && $version >= 2.0) ? 'setup_needed': 'cancel';
return $ret;
}
/* Check if user already logged in into the server */
if (!isset($params['openid_identity']) ||
$this->_user->getLoggedInUser() !== $params['openid_identity']) {
$params2 = array();
foreach ($params as $key => $val) {
if (strpos($key, 'openid_ns_') === 0) {
$key = 'openid.ns.' . substr($key, strlen('openid_ns_'));
} else if (strpos($key, 'openid_sreg_') === 0) {
$key = 'openid.sreg.' . substr($key, strlen('openid_sreg_'));
} else if (strpos($key, 'openid_') === 0) {
$key = 'openid.' . substr($key, strlen('openid_'));
}
$params2[$key] = $val;
}
if ($immediate) {
$params2['openid.mode'] = 'checkid_setup';
$ret['openid.mode'] = ($version >= 2.0) ? 'setup_needed': 'id_res';
$ret['openid.user_setup_url'] = $this->_loginUrl
. (strpos($this->_loginUrl, '?') === false ? '?' : '&')
. Zend_OpenId::paramsToQuery($params2);
return $ret;
} else {
/* Redirect to Server Login Screen */
Zend_OpenId::redirect($this->_loginUrl, $params2, $response);
return true;
}
}
if (!Zend_OpenId_Extension::forAll($extensions, 'parseRequest', $params)) {
$ret['openid.mode'] = ($immediate && $version >= 2.0) ? 'setup_needed': 'cancel';
return $ret;
}
/* Check if user trusts to the consumer */
$trusted = null;
$sites = $this->_storage->getTrustedSites($params['openid_identity']);
if (isset($params['openid_return_to'])) {
$root = $params['openid_return_to'];
}
if (isset($sites[$root])) {
$trusted = $sites[$root];
} else {
foreach ($sites as $site => $t) {
if (strpos($root, $site) === 0) {
$trusted = $t;
break;
} else {
/* OpenID 2.0 (9.2) check for realm wild-card matching */
$n = strpos($site, '://*.');
if ($n != false) {
$regex = '/^'
. preg_quote(substr($site, 0, $n+3), '/')
. '[A-Za-z1-9_\.]+?'
. preg_quote(substr($site, $n+4), '/')
. '/';
if (preg_match($regex, $root)) {
$trusted = $t;
break;
}
}
}
}
}
if (is_array($trusted)) {
if (!Zend_OpenId_Extension::forAll($extensions, 'checkTrustData', $trusted)) {
$trusted = null;
}
}
if ($trusted === false) {
$ret['openid.mode'] = 'cancel';
return $ret;
} else if (is_null($trusted)) {
/* Redirect to Server Trust Screen */
$params2 = array();
foreach ($params as $key => $val) {
if (strpos($key, 'openid_ns_') === 0) {
$key = 'openid.ns.' . substr($key, strlen('openid_ns_'));
} else if (strpos($key, 'openid_sreg_') === 0) {
$key = 'openid.sreg.' . substr($key, strlen('openid_sreg_'));
} else if (strpos($key, 'openid_') === 0) {
$key = 'openid.' . substr($key, strlen('openid_'));
}
$params2[$key] = $val;
}
if ($immediate) {
$params2['openid.mode'] = 'checkid_setup';
$ret['openid.mode'] = ($version >= 2.0) ? 'setup_needed': 'id_res';
$ret['openid.user_setup_url'] = $this->_trustUrl
. (strpos($this->_trustUrl, '?') === false ? '?' : '&')
. Zend_OpenId::paramsToQuery($params2);
return $ret;
} else {
Zend_OpenId::redirect($this->_trustUrl, $params2, $response);
return true;
}
}
return $this->_respond($version, $ret, $params, $extensions);
}
/**
* Perepares information to send back to consumer's authentication request,
* signs it using shared secret and send back through HTTP redirection
*
* @param array $params GET or POST request variables
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
* @return bool
*/
public function respondToConsumer($params, $extensions=null,
Zend_Controller_Response_Abstract $response = null)
{
$version = 1.1;
if (isset($params['openid_ns']) &&
$params['openid_ns'] == Zend_OpenId::NS_2_0) {
$version = 2.0;
}
$ret = array();
if ($version >= 2.0) {
$ret['openid.ns'] = Zend_OpenId::NS_2_0;
}
$ret = $this->_respond($version, $ret, $params, $extensions);
if (!empty($params['openid_return_to'])) {
Zend_OpenId::redirect($params['openid_return_to'], $ret, $response);
}
return true;
}
/**
* Perepares information to send back to consumer's authentication request
* and signs it using shared secret.
*
* @param float $version OpenID protcol version
* @param array $ret arguments to be send back to consumer
* @param array $params GET or POST request variables
* @param mixed $extensions extension object or array of extensions objects
* @return array
*/
protected function _respond($version, $ret, $params, $extensions=null)
{
if (empty($params['openid_assoc_handle']) ||
!$this->_storage->getAssociation($params['openid_assoc_handle'],
$macFunc, $secret, $expires)) {
/* Use dumb mode */
if (!empty($params['openid_assoc_handle'])) {
$ret['openid.invalidate_handle'] = $params['openid_assoc_handle'];
}
$macFunc = $version >= 2.0 ? 'sha256' : 'sha1';
$secret = $this->_genSecret($macFunc);
$handle = uniqid();
$expiresIn = $this->_sessionTtl;
$this->_storage->addAssociation($handle,
$macFunc, $secret, time() + $expiresIn);
$ret['openid.assoc_handle'] = $handle;
} else {
$ret['openid.assoc_handle'] = $params['openid_assoc_handle'];
}
if (isset($params['openid_return_to'])) {
$ret['openid.return_to'] = $params['openid_return_to'];
}
if (isset($params['openid_claimed_id'])) {
$ret['openid.claimed_id'] = $params['openid_claimed_id'];
}
if (isset($params['openid_identity'])) {
$ret['openid.identity'] = $params['openid_identity'];
}
if ($version >= 2.0) {
if (!empty($this->_opEndpoint)) {
$ret['openid.op_endpoint'] = $this->_opEndpoint;
} else {
$ret['openid.op_endpoint'] = Zend_OpenId::selfUrl();
}
}
$ret['openid.response_nonce'] = gmdate('Y-m-d\TH:i:s\Z') . uniqid();
$ret['openid.mode'] = 'id_res';
Zend_OpenId_Extension::forAll($extensions, 'prepareResponse', $ret);
$signed = '';
$data = '';
foreach ($ret as $key => $val) {
if (strpos($key, 'openid.') === 0) {
$key = substr($key, strlen('openid.'));
if (!empty($signed)) {
$signed .= ',';
}
$signed .= $key;
$data .= $key . ':' . $val . "\n";
}
}
$signed .= ',signed';
$data .= 'signed:' . $signed . "\n";
$ret['openid.signed'] = $signed;
$ret['openid.sig'] = base64_encode(
Zend_OpenId::hashHmac($macFunc, $data, $secret));
return $ret;
}
/**
* Performs authentication validation for dumb consumers
* Returns array of variables to push back to consumer.
* It MUST contain 'is_valid' variable with value 'true' or 'false'.
*
* @param float $version OpenID version
* @param array $params GET or POST request variables
* @return array
*/
protected function _checkAuthentication($version, $params)
{
$ret = array();
if ($version >= 2.0) {
$ret['ns'] = Zend_OpenId::NS_2_0;
}
$ret['openid.mode'] = 'id_res';
if (empty($params['openid_assoc_handle']) ||
empty($params['openid_signed']) ||
empty($params['openid_sig']) ||
!$this->_storage->getAssociation($params['openid_assoc_handle'],
$macFunc, $secret, $expires)) {
$ret['is_valid'] = 'false';
return $ret;
}
$signed = explode(',', $params['openid_signed']);
$data = '';
foreach ($signed as $key) {
$data .= $key . ':';
if ($key == 'mode') {
$data .= "id_res\n";
} else {
$data .= $params['openid_' . strtr($key,'.','_')]."\n";
}
}
if (base64_decode($params['openid_sig']) ===
Zend_OpenId::hashHmac($macFunc, $data, $secret)) {
$ret['is_valid'] = 'true';
} else {
$ret['is_valid'] = 'false';
}
return $ret;
}
}
OpenId/Provider/Storage.php 0000604 00000006517 15071256135 0011643 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Provider
* @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: Storage.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Abstract class to implement external storage for OpenID consumer
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Provider
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_OpenId_Provider_Storage
{
/**
* Stores information about session identified by $handle
*
* @param string $handle assiciation handle
* @param string $macFunc HMAC function (sha1 or sha256)
* @param string $secret shared secret
* @param string $expires expiration UNIX time
* @return void
*/
abstract public function addAssociation($handle, $macFunc, $secret, $expires);
/**
* Gets information about association identified by $handle
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $handle assiciation handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param string &$expires expiration UNIX time
* @return bool
*/
abstract public function getAssociation($handle, &$macFunc, &$secret, &$expires);
/**
* Register new user with given $id and $password
* Returns true in case of success and false if user with given $id already
* exists
*
* @param string $id user identity URL
* @param string $password encoded user password
* @return bool
*/
abstract public function addUser($id, $password);
/**
* Returns true if user with given $id exists and false otherwise
*
* @param string $id user identity URL
* @return bool
*/
abstract public function hasUser($id);
/**
* Verify if user with given $id exists and has specified $password
*
* @param string $id user identity URL
* @param string $password user password
* @return bool
*/
abstract public function checkUser($id, $password);
/**
* Returns array of all trusted/untrusted sites for given user identified
* by $id
*
* @param string $id user identity URL
* @return array
*/
abstract public function getTrustedSites($id);
/**
* Stores information about trusted/untrusted site for given user
*
* @param string $id user identity URL
* @param string $site site URL
* @param mixed $trusted trust data from extensions or just a boolean value
* @return bool
*/
abstract public function addSite($id, $site, $trusted);
}
OpenId/Provider/User/Session.php 0000604 00000005337 15071256135 0012577 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Provider
* @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: Session.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_OpenId_Provider_User
*/
require_once "Zend/OpenId/Provider/User.php";
/**
* @see Zend_Session_Namespace
*/
require_once "Zend/Session/Namespace.php";
/**
* Class to get/store information about logged in user in Web Browser using
* PHP session
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Provider
* @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_OpenId_Provider_User_Session extends Zend_OpenId_Provider_User
{
/**
* Reference to an implementation of Zend_Session_Namespace object
*
* @var Zend_Session_Namespace $_session
*/
private $_session = null;
/**
* Creates Zend_OpenId_Provider_User_Session object with given session
* namespace or creates new session namespace named "openid"
*
* @param Zend_Session_Namespace $session
*/
public function __construct(Zend_Session_Namespace $session = null)
{
if ($session === null) {
$this->_session = new Zend_Session_Namespace("openid");
} else {
$this->_session = $session;
}
}
/**
* Stores information about logged in user in session data
*
* @param string $id user identity URL
* @return bool
*/
public function setLoggedInUser($id)
{
$this->_session->logged_in = $id;
return true;
}
/**
* Returns identity URL of logged in user or false
*
* @return mixed
*/
public function getLoggedInUser()
{
if (isset($this->_session->logged_in)) {
return $this->_session->logged_in;
}
return false;
}
/**
* Performs logout. Clears information about logged in user.
*
* @return bool
*/
public function delLoggedInUser()
{
unset($this->_session->logged_in);
return true;
}
}
OpenId/Provider/User.php 0000604 00000003166 15071256135 0011152 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Provider
* @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: User.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Abstract class to get/store information about logged in user in Web Browser
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Provider
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_OpenId_Provider_User
{
/**
* Stores information about logged in user
*
* @param string $id user identity URL
* @return bool
*/
abstract public function setLoggedInUser($id);
/**
* Returns identity URL of logged in user or false
*
* @return mixed
*/
abstract public function getLoggedInUser();
/**
* Performs logout. Clears information about logged in user.
*
* @return bool
*/
abstract public function delLoggedInUser();
}
OpenId/Provider/Storage/File.php 0000604 00000026455 15071256135 0012525 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Provider
* @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: File.php 8456 2008-02-29 11:01:12Z dmitry $
*/
/**
* @see Zend_OpenId_Provider_Storage
*/
require_once "Zend/OpenId/Provider/Storage.php";
/**
* External storage implemmentation using serialized files
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Provider
* @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_OpenId_Provider_Storage_File extends Zend_OpenId_Provider_Storage
{
/**
* Directory name to store data files in
*
* @var string $_dir
*/
private $_dir;
/**
* Constructs storage object and creates storage directory
*
* @param string $dir directory name to store data files in
* @throws Zend_OpenId_Exception
*/
public function __construct($dir = null)
{
if (is_null($dir)) {
$tmp = getenv('TMP');
if (empty($tmp)) {
$tmp = getenv('TEMP');
if (empty($tmp)) {
$tmp = "/tmp";
}
}
$user = get_current_user();
if (is_string($user) && !empty($user)) {
$tmp .= '/' . $user;
}
$dir = $tmp . '/openid/provider';
}
$this->_dir = $dir;
if (!is_dir($this->_dir)) {
if (!@mkdir($this->_dir, 0700, 1)) {
throw new Zend_OpenId_Exception(
"Cannot access storage directory $dir",
Zend_OpenId_Exception::ERROR_STORAGE);
}
}
if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) {
throw new Zend_OpenId_Exception(
'Cannot create a lock file in the directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/user.lock', 'w+')) === null) {
throw new Zend_OpenId_Exception(
'Cannot create a lock file in the directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
fclose($f);
}
/**
* Stores information about session identified by $handle
*
* @param string $handle assiciation handle
* @param string $macFunc HMAC function (sha1 or sha256)
* @param string $secret shared secret
* @param string $expires expiration UNIX time
* @return bool
*/
public function addAssociation($handle, $macFunc, $secret, $expires)
{
$name = $this->_dir . '/assoc_' . md5($handle);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'w+');
if ($f === false) {
fclose($lock);
return false;
}
$data = serialize(array($handle, $macFunc, $secret, $expires));
fwrite($f, $data);
fclose($f);
fclose($lock);
return true;
}
/**
* Gets information about association identified by $handle
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $handle assiciation handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param string &$expires expiration UNIX time
* @return bool
*/
public function getAssociation($handle, &$macFunc, &$secret, &$expires)
{
$name = $this->_dir . '/assoc_' . md5($handle);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedHandle, $macFunc, $secret, $expires) = unserialize($data);
if ($handle === $storedHandle && $expires > time()) {
$ret = true;
} else {
fclose($f);
@unlink($name);
fclose($lock);
return false;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Removes information about association identified by $handle
*
* @param string $handle assiciation handle
* @return bool
*/
public function delAssociation($handle)
{
$name = $this->_dir . '/assoc_' . md5($handle);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
@unlink($name);
fclose($lock);
return true;
}
/**
* Register new user with given $id and $password
* Returns true in case of success and false if user with given $id already
* exists
*
* @param string $id user identity URL
* @param string $password encoded user password
* @return bool
*/
public function addUser($id, $password)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'x');
if ($f === false) {
fclose($lock);
return false;
}
$data = serialize(array($id, $password, array()));
fwrite($f, $data);
fclose($f);
fclose($lock);
return true;
}
/**
* Returns true if user with given $id exists and false otherwise
*
* @param string $id user identity URL
* @return bool
*/
public function hasUser($id)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_SH)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedId, $storedPassword, $trusted) = unserialize($data);
if ($id === $storedId) {
$ret = true;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Verify if user with given $id exists and has specified $password
*
* @param string $id user identity URL
* @param string $password user password
* @return bool
*/
public function checkUser($id, $password)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_SH)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedId, $storedPassword, $trusted) = unserialize($data);
if ($id === $storedId && $password === $storedPassword) {
$ret = true;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Removes information abou specified user
*
* @param string $id user identity URL
* @return bool
*/
public function delUser($id)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
@unlink($name);
fclose($lock);
return true;
}
/**
* Returns array of all trusted/untrusted sites for given user identified
* by $id
*
* @param string $id user identity URL
* @return array
*/
public function getTrustedSites($id)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_SH)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedId, $storedPassword, $trusted) = unserialize($data);
if ($id === $storedId) {
$ret = $trusted;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Stores information about trusted/untrusted site for given user
*
* @param string $id user identity URL
* @param string $site site URL
* @param mixed $trusted trust data from extension or just a boolean value
* @return bool
*/
public function addSite($id, $site, $trusted)
{
$name = $this->_dir . '/user_' . md5($id);
$lock = @fopen($this->_dir . '/user.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r+');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedId, $storedPassword, $sites) = unserialize($data);
if ($id === $storedId) {
if (is_null($trusted)) {
unset($sites[$site]);
} else {
$sites[$site] = $trusted;
}
rewind($f);
ftruncate($f, 0);
$data = serialize(array($id, $storedPassword, $sites));
fwrite($f, $data);
$ret = true;
}
}
fclose($f);
fclose($lock);
return $ret;
}
}
OpenId/Extension/Sreg.php 0000604 00000021406 15071256135 0011313 0 ustar 00 <?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_OpenId
* @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: Sreg.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_OpenId_Extension
*/
require_once "Zend/OpenId/Extension.php";
/**
* 'Simple Refistration Extension' for Zend_OpenId
*
* @category Zend
* @package Zend_OpenId
* @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_OpenId_Extension_Sreg extends Zend_OpenId_Extension
{
/**
* SREG 1.1 namespace. All OpenID SREG 1.1 messages MUST contain variable
* openid.ns.sreg with its value.
*/
const NAMESPACE_1_1 = "http://openid.net/extensions/sreg/1.1";
private $_props;
private $_policy_url;
private $_version;
/**
* Creates SREG extension object
*
* @param array $props associative array of SREG variables
* @param string $policy_url SREG policy URL
* @param float $version SREG version
* @return array
*/
public function __construct(array $props=null, $policy_url=null, $version=1.0)
{
$this->_props = $props;
$this->_policy_url = $policy_url;
$this->_version = $version;
}
/**
* Returns associative array of SREG variables
*
* @return array
*/
public function getProperties() {
if (is_array($this->_props)) {
return $this->_props;
} else {
return array();
}
}
/**
* Returns SREG policy URL
*
* @return string
*/
public function getPolicyUrl() {
return $this->_policy_url;
}
/**
* Returns SREG protocol version
*
* @return float
*/
public function getVersion() {
return $this->_version;
}
/**
* Returns array of allowed SREG variable names.
*
* @return array
*/
public static function getSregProperties()
{
return array(
"nickname",
"email",
"fullname",
"dob",
"gender",
"postcode",
"country",
"language",
"timezone"
);
}
/**
* Adds additional SREG data to OpenId 'checkid_immediate' or
* 'checkid_setup' request.
*
* @param array &$params request's var/val pairs
* @return bool
*/
public function prepareRequest(&$params)
{
if (is_array($this->_props) && count($this->_props) > 0) {
foreach ($this->_props as $prop => $req) {
if ($req) {
if (isset($required)) {
$required .= ','.$prop;
} else {
$required = $prop;
}
} else {
if (isset($optional)) {
$optional .= ','.$prop;
} else {
$optional = $prop;
}
}
}
if ($this->_version >= 1.1) {
$params['openid.ns.sreg'] = Zend_OpenId_Extension_Sreg::NAMESPACE_1_1;
}
if (!empty($required)) {
$params['openid.sreg.required'] = $required;
}
if (!empty($optional)) {
$params['openid.sreg.optional'] = $optional;
}
if (!empty($this->_policy_url)) {
$params['openid.sreg.policy_url'] = $this->_policy_url;
}
}
return true;
}
/**
* Parses OpenId 'checkid_immediate' or 'checkid_setup' request,
* extracts SREG variables and sets ovject properties to corresponding
* values.
*
* @param array $params request's var/val pairs
* @return bool
*/
public function parseRequest($params)
{
if (isset($params['openid_ns_sreg']) &&
$params['openid_ns_sreg'] === Zend_OpenId_Extension_Sreg::NAMESPACE_1_1) {
$this->_version= 1.1;
} else {
$this->_version= 1.0;
}
if (!empty($params['openid_sreg_policy_url'])) {
$this->_policy_url = $params['openid_sreg_policy_url'];
} else {
$this->_policy_url = null;
}
$props = array();
if (!empty($params['openid_sreg_optional'])) {
foreach (explode(',', $params['openid_sreg_optional']) as $prop) {
$prop = trim($prop);
$props[$prop] = false;
}
}
if (!empty($params['openid_sreg_required'])) {
foreach (explode(',', $params['openid_sreg_required']) as $prop) {
$prop = trim($prop);
$props[$prop] = true;
}
}
$props2 = array();
foreach (self::getSregProperties() as $prop) {
if (isset($props[$prop])) {
$props2[$prop] = $props[$prop];
}
}
$this->_props = (count($props2) > 0) ? $props2 : null;
return true;
}
/**
* Adds additional SREG data to OpenId 'id_res' response.
*
* @param array &$params response's var/val pairs
* @return bool
*/
public function prepareResponse(&$params)
{
if (is_array($this->_props) && count($this->_props) > 0) {
if ($this->_version >= 1.1) {
$params['openid.ns.sreg'] = Zend_OpenId_Extension_Sreg::NAMESPACE_1_1;
}
foreach (self::getSregProperties() as $prop) {
if (!empty($this->_props[$prop])) {
$params['openid.sreg.' . $prop] = $this->_props[$prop];
}
}
}
return true;
}
/**
* Parses OpenId 'id_res' response and sets object's properties according
* to 'openid.sreg.*' variables in response
*
* @param array $params response's var/val pairs
* @return bool
*/
public function parseResponse($params)
{
if (isset($params['openid_ns_sreg']) &&
$params['openid_ns_sreg'] === Zend_OpenId_Extension_Sreg::NAMESPACE_1_1) {
$this->_version= 1.1;
} else {
$this->_version= 1.0;
}
$props = array();
foreach (self::getSregProperties() as $prop) {
if (!empty($params['openid_sreg_' . $prop])) {
$props[$prop] = $params['openid_sreg_' . $prop];
}
}
if (isset($this->_props) && is_array($this->_props)) {
foreach (self::getSregProperties() as $prop) {
if (isset($this->_props[$prop]) &&
$this->_props[$prop] &&
!isset($props[$prop])) {
return false;
}
}
}
$this->_props = (count($props) > 0) ? $props : null;
return true;
}
/**
* Addes SREG properties that are allowed to be send to consumer to
* the given $data argument.
*
* @param array &$data data to be stored in tusted servers database
* @return bool
*/
public function getTrustData(&$data)
{
$data[get_class()] = $this->getProperties();
return true;
}
/**
* Check if given $data contains necessury SREG properties to sutisfy
* OpenId request. On success sets SREG response properties from given
* $data and returns true, on failure returns false.
*
* @param array $data data from tusted servers database
* @return bool
*/
public function checkTrustData($data)
{
if (is_array($this->_props) && count($this->_props) > 0) {
$props = array();
$name = get_class();
if (isset($data[$name])) {
$props = $data[$name];
} else {
$props = array();
}
$props2 = array();
foreach ($this->_props as $prop => $req) {
if (empty($props[$prop])) {
if ($req) {
return false;
}
} else {
$props2[$prop] = $props[$prop];
}
}
$this->_props = (count($props2) > 0) ? $props2 : null;
}
return true;
}
}
OpenId/Extension.php 0000604 00000007774 15071256135 0010427 0 ustar 00 <?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_OpenId
* @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: Extension.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Abstract extension class for Zend_OpenId
*
* @category Zend
* @package Zend_OpenId
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_OpenId_Extension
{
/**
* Calls given function with given argument for all extensions
*
* @param mixed $extensions list of extensions or one extension
* @param string $func function to be called
* @param mixed &$params argument to pass to given funcion
* @return bool
*/
static public function forAll($extensions, $func, &$params)
{
if (!is_null($extensions)) {
if (is_array($extensions)) {
foreach ($extensions as $ext) {
if ($ext instanceof Zend_OpenId_Extension) {
if (!$ext->$func($params)) {
return false;
}
} else {
return false;
}
}
} else if (!is_object($extensions) ||
!($extensions instanceof Zend_OpenId_Extension) ||
!$extensions->$func($params)) {
return false;
}
}
return true;
}
/**
* Method to add additional data to OpenId 'checkid_immediate' or
* 'checkid_setup' request. This method addes nothing but inherited class
* may add additional data into request.
*
* @param array &$params request's var/val pairs
* @return bool
*/
public function prepareRequest(&$params)
{
return true;
}
/**
* Method to parse OpenId 'checkid_immediate' or 'checkid_setup' request
* and initialize object with passed data. This method parses nothing but
* inherited class may override this method to do somthing.
*
* @param array $params request's var/val pairs
* @return bool
*/
public function parseRequest($params)
{
return true;
}
/**
* Method to add additional data to OpenId 'id_res' response. This method
* addes nothing but inherited class may add additional data into response.
*
* @param array &$params response's var/val pairs
* @return bool
*/
public function prepareResponse(&$params)
{
return true;
}
/**
* Method to parse OpenId 'id_res' response and initialize object with
* passed data. This method parses nothing but inherited class may override
* this method to do somthing.
*
* @param array $params response's var/val pairs
* @return bool
*/
public function parseResponse($params)
{
return true;
}
/**
* Method to prepare data to store it in trusted servers database.
*
* @param array &$data data to be stored in tusted servers database
* @return bool
*/
public function getTrustData(&$data)
{
return true;
}
/**
* Method to check if data from trusted servers database is enough to
* sutisfy request.
*
* @param array $data data from tusted servers database
* @return bool
*/
public function checkTrustData($data)
{
return true;
}
}
OpenId/Consumer/Storage/File.php 0000604 00000033743 15071256135 0012524 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Consumer
* @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: File.php 12970 2008-12-01 12:55:17Z dmitry $
*/
/**
* @see Zend_OpenId_Consumer_Storage
*/
require_once "Zend/OpenId/Consumer/Storage.php";
/**
* External storage implemmentation using serialized files
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Consumer
* @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_OpenId_Consumer_Storage_File extends Zend_OpenId_Consumer_Storage
{
/**
* Directory name to store data files in
*
* @var string $_dir
*/
private $_dir;
/**
* Constructs storage object and creates storage directory
*
* @param string $dir directory name to store data files in
* @throws Zend_OpenId_Exception
*/
public function __construct($dir = null)
{
if (is_null($dir)) {
$tmp = getenv('TMP');
if (empty($tmp)) {
$tmp = getenv('TEMP');
if (empty($tmp)) {
$tmp = "/tmp";
}
}
$user = get_current_user();
if (is_string($user) && !empty($user)) {
$tmp .= '/' . $user;
}
$dir = $tmp . '/openid/consumer';
}
$this->_dir = $dir;
if (!is_dir($this->_dir)) {
if (!@mkdir($this->_dir, 0700, 1)) {
/**
* @see Zend_OpenId_Exception
*/
require_once 'Zend/OpenId/Exception.php';
throw new Zend_OpenId_Exception(
'Cannot access storage directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
}
if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) {
/**
* @see Zend_OpenId_Exception
*/
require_once 'Zend/OpenId/Exception.php';
throw new Zend_OpenId_Exception(
'Cannot create a lock file in the directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/discovery.lock', 'w+')) === null) {
/**
* @see Zend_OpenId_Exception
*/
require_once 'Zend/OpenId/Exception.php';
throw new Zend_OpenId_Exception(
'Cannot create a lock file in the directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
fclose($f);
if (($f = fopen($this->_dir.'/nonce.lock', 'w+')) === null) {
/**
* @see Zend_OpenId_Exception
*/
require_once 'Zend/OpenId/Exception.php';
throw new Zend_OpenId_Exception(
'Cannot create a lock file in the directory ' . $dir,
Zend_OpenId_Exception::ERROR_STORAGE);
}
fclose($f);
}
/**
* Stores information about association identified by $url/$handle
*
* @param string $url OpenID server URL
* @param string $handle assiciation handle
* @param string $macFunc HMAC function (sha1 or sha256)
* @param string $secret shared secret
* @param long $expires expiration UNIX time
* @return bool
*/
public function addAssociation($url, $handle, $macFunc, $secret, $expires)
{
$name1 = $this->_dir . '/assoc_url_' . md5($url);
$name2 = $this->_dir . '/assoc_handle_' . md5($handle);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name1, 'w+');
if ($f === false) {
fclose($lock);
return false;
}
$data = serialize(array($url, $handle, $macFunc, $secret, $expires));
fwrite($f, $data);
if (function_exists('symlink')) {
@unlink($name2);
if (symlink($name1, $name2)) {
fclose($f);
fclose($lock);
return true;
}
}
$f2 = @fopen($name2, 'w+');
if ($f2) {
fwrite($f2, $data);
fclose($f2);
@unlink($name1);
$ret = true;
} else {
$ret = false;
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Gets information about association identified by $url
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $url OpenID server URL
* @param string &$handle assiciation handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param long &$expires expiration UNIX time
* @return bool
*/
public function getAssociation($url, &$handle, &$macFunc, &$secret, &$expires)
{
$name1 = $this->_dir . '/assoc_url_' . md5($url);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name1, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedUrl, $handle, $macFunc, $secret, $expires) = unserialize($data);
if ($url === $storedUrl && $expires > time()) {
$ret = true;
} else {
$name2 = $this->_dir . '/assoc_handle_' . md5($handle);
fclose($f);
@unlink($name2);
@unlink($name1);
fclose($lock);
return false;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Gets information about association identified by $handle
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $handle assiciation handle
* @param string &$url OpenID server URL
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param long &$expires expiration UNIX time
* @return bool
*/
public function getAssociationByHandle($handle, &$url, &$macFunc, &$secret, &$expires)
{
$name2 = $this->_dir . '/assoc_handle_' . md5($handle);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name2, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($url, $storedHandle, $macFunc, $secret, $expires) = unserialize($data);
if ($handle === $storedHandle && $expires > time()) {
$ret = true;
} else {
fclose($f);
@unlink($name2);
$name1 = $this->_dir . '/assoc_url_' . md5($url);
@unlink($name1);
fclose($lock);
return false;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Deletes association identified by $url
*
* @param string $url OpenID server URL
* @return bool
*/
public function delAssociation($url)
{
$name1 = $this->_dir . '/assoc_url_' . md5($url);
$lock = @fopen($this->_dir . '/assoc.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name1, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedUrl, $handle, $macFunc, $secret, $expires) = unserialize($data);
if ($url === $storedUrl) {
$name2 = $this->_dir . '/assoc_handle_' . md5($handle);
fclose($f);
@unlink($name2);
@unlink($name1);
fclose($lock);
return true;
}
}
fclose($f);
fclose($lock);
return true;
}
/**
* Stores information discovered from identity $id
*
* @param string $id identity
* @param string $realId discovered real identity URL
* @param string $server discovered OpenID server URL
* @param float $version discovered OpenID protocol version
* @param long $expires expiration UNIX time
* @return bool
*/
public function addDiscoveryInfo($id, $realId, $server, $version, $expires)
{
$name = $this->_dir . '/discovery_' . md5($id);
$lock = @fopen($this->_dir . '/discovery.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'w+');
if ($f === false) {
fclose($lock);
return false;
}
$data = serialize(array($id, $realId, $server, $version, $expires));
fwrite($f, $data);
fclose($f);
fclose($lock);
return true;
}
/**
* Gets information discovered from identity $id
* Returns true if such information exists and false otherwise
*
* @param string $id identity
* @param string &$realId discovered real identity URL
* @param string &$server discovered OpenID server URL
* @param float &$version discovered OpenID protocol version
* @param long &$expires expiration UNIX time
* @return bool
*/
public function getDiscoveryInfo($id, &$realId, &$server, &$version, &$expires)
{
$name = $this->_dir . '/discovery_' . md5($id);
$lock = @fopen($this->_dir . '/discovery.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'r');
if ($f === false) {
fclose($lock);
return false;
}
$ret = false;
$data = stream_get_contents($f);
if (!empty($data)) {
list($storedId, $realId, $server, $version, $expires) = unserialize($data);
if ($id === $storedId && $expires > time()) {
$ret = true;
} else {
fclose($f);
@unlink($name);
fclose($lock);
return false;
}
}
fclose($f);
fclose($lock);
return $ret;
}
/**
* Removes cached information discovered from identity $id
*
* @param string $id identity
* @return bool
*/
public function delDiscoveryInfo($id)
{
$name = $this->_dir . '/discovery_' . md5($id);
$lock = @fopen($this->_dir . '/discovery.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
@unlink($name);
fclose($lock);
return true;
}
/**
* The function checks the uniqueness of openid.response_nonce
*
* @param string $provider openid.openid_op_endpoint field from authentication response
* @param string $nonce openid.response_nonce field from authentication response
* @return bool
*/
public function isUniqueNonce($provider, $nonce)
{
$name = $this->_dir . '/nonce_' . md5($provider.';'.$nonce);
$lock = @fopen($this->_dir . '/nonce.lock', 'w+');
if ($lock === false) {
return false;
}
if (!flock($lock, LOCK_EX)) {
fclose($lock);
return false;
}
$f = @fopen($name, 'x');
if ($f === false) {
fclose($lock);
return false;
}
fwrite($f, $provider.';'.$nonce);
fclose($f);
fclose($lock);
return true;
}
/**
* Removes data from the uniqueness database that is older then given date
*
* @param mixed $date date of expired data
*/
public function purgeNonces($date=null)
{
$lock = @fopen($this->_dir . '/nonce.lock', 'w+');
if ($lock !== false) {
flock($lock, LOCK_EX);
}
if (!is_int($date) && !is_string($date)) {
foreach (glob($this->_dir . '/nonce_*') as $name) {
@unlink($name);
}
} else {
if (is_string($date)) {
$time = time($date);
} else {
$time = $date;
}
foreach (glob($this->_dir . '/nonce_*') as $name) {
if (filemtime($name) < $time) {
@unlink($name);
}
}
}
if ($lock !== false) {
fclose($lock);
}
}
}
OpenId/Consumer/Storage.php 0000604 00000010775 15071256135 0011645 0 ustar 00 <?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_OpenId
* @subpackage Zend_OpenId_Consumer
* @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: Storage.php 9239 2008-04-18 12:09:31Z dmitry $
*/
/**
* Abstract class to implement external storage for OpenID consumer
*
* @category Zend
* @package Zend_OpenId
* @subpackage Zend_OpenId_Consumer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_OpenId_Consumer_Storage
{
/**
* Stores information about association identified by $url/$handle
*
* @param string $url OpenID server URL
* @param string $handle assiciation handle
* @param string $macFunc HMAC function (sha1 or sha256)
* @param string $secret shared secret
* @param long $expires expiration UNIX time
* @return void
*/
abstract public function addAssociation($url, $handle, $macFunc, $secret, $expires);
/**
* Gets information about association identified by $url
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $url OpenID server URL
* @param string &$handle assiciation handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param long &$expires expiration UNIX time
* @return bool
*/
abstract public function getAssociation($url, &$handle, &$macFunc, &$secret, &$expires);
/**
* Gets information about association identified by $handle
* Returns true if given association found and not expired and false
* othverwise
*
* @param string $handle assiciation handle
* @param string &$url OpenID server URL
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param long &$expires expiration UNIX time
* @return bool
*/
abstract public function getAssociationByHandle($handle, &$url, &$macFunc, &$secret, &$expires);
/**
* Deletes association identified by $url
*
* @param string $url OpenID server URL
* @return void
*/
abstract public function delAssociation($url);
/**
* Stores information discovered from identity $id
*
* @param string $id identity
* @param string $realId discovered real identity URL
* @param string $server discovered OpenID server URL
* @param float $version discovered OpenID protocol version
* @param long $expires expiration UNIX time
* @return void
*/
abstract public function addDiscoveryInfo($id, $realId, $server, $version, $expires);
/**
* Gets information discovered from identity $id
* Returns true if such information exists and false otherwise
*
* @param string $id identity
* @param string &$realId discovered real identity URL
* @param string &$server discovered OpenID server URL
* @param float &$version discovered OpenID protocol version
* @param long &$expires expiration UNIX time
* @return bool
*/
abstract public function getDiscoveryInfo($id, &$realId, &$server, &$version, &$expires);
/**
* Removes cached information discovered from identity $id
*
* @param string $id identity
* @return bool
*/
abstract public function delDiscoveryInfo($id);
/**
* The function checks the uniqueness of openid.response_nonce
*
* @param string $provider openid.openid_op_endpoint field from authentication response
* @param string $nonce openid.response_nonce field from authentication response
* @return bool
*/
abstract public function isUniqueNonce($provider, $nonce);
/**
* Removes data from the uniqueness database that is older then given date
*
* @param string $date Date of expired data
*/
abstract public function purgeNonces($date=null);
}
Console/Getopt.php 0000604 00000075005 15071256135 0010131 0 ustar 00 <?php
/**
* Zend_Console_Getopt is a class to parse options for command-line
* applications.
*
* 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_Console_Getopt
* @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: $
*/
/**
* @see Zend_Console_Getopt_Exception
*/
require_once 'Zend/Console/Getopt/Exception.php';
/**
* Zend_Console_Getopt is a class to parse options for command-line
* applications.
*
* Terminology:
* Argument: an element of the argv array. This may be part of an option,
* or it may be a non-option command-line argument.
* Flag: the letter or word set off by a '-' or '--'. Example: in '--output filename',
* '--output' is the flag.
* Parameter: the additional argument that is associated with the option.
* Example: in '--output filename', the 'filename' is the parameter.
* Option: the combination of a flag and its parameter, if any.
* Example: in '--output filename', the whole thing is the option.
*
* The following features are supported:
*
* - Short flags like '-a'. Short flags are preceded by a single
* dash. Short flags may be clustered e.g. '-abc', which is the
* same as '-a' '-b' '-c'.
* - Long flags like '--verbose'. Long flags are preceded by a
* double dash. Long flags may not be clustered.
* - Options may have a parameter, e.g. '--output filename'.
* - Parameters for long flags may also be set off with an equals sign,
* e.g. '--output=filename'.
* - Parameters for long flags may be checked as string, word, or integer.
* - Automatic generation of a helpful usage message.
* - Signal end of options with '--'; subsequent arguments are treated
* as non-option arguments, even if they begin with '-'.
* - Raise exception Zend_Console_Getopt_Exception in several cases
* when invalid flags or parameters are given. Usage message is
* returned in the exception object.
*
* The format for specifying options uses a PHP associative array.
* The key is has the format of a list of pipe-separated flag names,
* followed by an optional '=' to indicate a required parameter or
* '-' to indicate an optional parameter. Following that, the type
* of parameter may be specified as 's' for string, 'w' for word,
* or 'i' for integer.
*
* Examples:
* - 'user|username|u=s' this means '--user' or '--username' or '-u'
* are synonyms, and the option requires a string parameter.
* - 'p=i' this means '-p' requires an integer parameter. No synonyms.
* - 'verbose|v-i' this means '--verbose' or '-v' are synonyms, and
* they take an optional integer parameter.
* - 'help|h' this means '--help' or '-h' are synonyms, and
* they take no parameter.
*
* The values in the associative array are strings that are used as
* brief descriptions of the options when printing a usage message.
*
* The simpler format for specifying options used by PHP's getopt()
* function is also supported. This is similar to GNU getopt and shell
* getopt format.
*
* Example: 'abc:' means options '-a', '-b', and '-c'
* are legal, and the latter requires a string parameter.
*
* @category Zend
* @package Zend_Console_Getopt
* @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 Release: @package_version@
* @since Class available since Release 0.6.0
*
* @todo Handle params with multiple values, e.g. --colors=red,green,blue
* Set value of parameter to the array of values. Allow user to specify
* the separator with Zend_Console_Getopt::CONFIG_PARAMETER_SEPARATOR.
* If this config value is null or empty string, do not split values
* into arrays. Default separator is comma (',').
*
* @todo Handle params with multiple values specified with separate options
* e.g. --colors red --colors green --colors blue should give one
* option with an array(red, green, blue).
* Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_PARAMETERS.
* Default is that subsequent options overwrite the parameter value.
*
* @todo Handle flags occurring multiple times, e.g. -v -v -v
* Set value of the option's parameter to the integer count of instances
* instead of a boolean.
* Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_FLAGS.
* Default is that the value is simply boolean true regardless of
* how many instances of the flag appear.
*
* @todo Handle flags that implicitly print usage message, e.g. --help
*
* @todo Handle freeform options, e.g. --set-variable
* Enable with Zend_Console_Getopt::CONFIG_FREEFORM_FLAGS
* All flag-like syntax is recognized, no flag generates an exception.
*
* @todo Handle numeric options, e.g. -1, -2, -3, -1000
* Enable with Zend_Console_Getopt::CONFIG_NUMERIC_FLAGS
* The rule must specify a named flag and the '#' symbol as the
* parameter type. e.g., 'lines=#'
*
* @todo Enable user to specify header and footer content in the help message.
*
* @todo Feature request to handle option interdependencies.
* e.g. if -b is specified, -a must be specified or else the
* usage is invalid.
*
* @todo Feature request to implement callbacks.
* e.g. if -a is specified, run function 'handleOptionA'().
*/
class Zend_Console_Getopt
{
/**
* The options for a given application can be in multiple formats.
* modeGnu is for traditional 'ab:c:' style getopt format.
* modeZend is for a more structured format.
*/
const MODE_ZEND = 'zend';
const MODE_GNU = 'gnu';
/**
* Constant tokens for various symbols used in the mode_zend
* rule format.
*/
const PARAM_REQUIRED = '=';
const PARAM_OPTIONAL = '-';
const TYPE_STRING = 's';
const TYPE_WORD = 'w';
const TYPE_INTEGER = 'i';
/**
* These are constants for optional behavior of this class.
* ruleMode is either 'zend' or 'gnu' or a user-defined mode.
* dashDash is true if '--' signifies the end of command-line options.
* ignoreCase is true if '--opt' and '--OPT' are implicitly synonyms.
*/
const CONFIG_RULEMODE = 'ruleMode';
const CONFIG_DASHDASH = 'dashDash';
const CONFIG_IGNORECASE = 'ignoreCase';
/**
* Defaults for getopt configuration are:
* ruleMode is 'zend' format,
* dashDash (--) token is enabled,
* ignoreCase is not enabled.
*
* @var array Config
*/
protected $_getoptConfig = array(
self::CONFIG_RULEMODE => self::MODE_ZEND,
self::CONFIG_DASHDASH => true,
self::CONFIG_IGNORECASE => false
);
/**
* Stores the command-line arguments for the calling applicaion.
*
* @var array
*/
protected $_argv = array();
/**
* Stores the name of the calling applicaion.
*
* @var string
*/
protected $_progname = '';
/**
* Stores the list of legal options for this application.
*
* @var array
*/
protected $_rules = array();
/**
* Stores alternate spellings of legal options.
*
* @var array
*/
protected $_ruleMap = array();
/**
* Stores options given by the user in the current invocation
* of the application, as well as parameters given in options.
*
* @var array
*/
protected $_options = array();
/**
* Stores the command-line arguments other than options.
*
* @var array
*/
protected $_remainingArgs = array();
/**
* State of the options: parsed or not yet parsed?
*
* @var boolean
*/
protected $_parsed = false;
/**
* The constructor takes one to three parameters.
*
* The first parameter is $rules, which may be a string for
* gnu-style format, or a structured array for Zend-style format.
*
* The second parameter is $argv, and it is optional. If not
* specified, $argv is inferred from the global argv.
*
* The third parameter is an array of configuration parameters
* to control the behavior of this instance of Getopt; it is optional.
*
* @param array $rules
* @param array $argv
* @param array $getoptConfig
* @return void
*/
public function __construct($rules, $argv = null, $getoptConfig = array())
{
$this->_progname = $_SERVER['argv'][0];
$this->setOptions($getoptConfig);
$this->addRules($rules);
if (!is_array($argv)) {
$argv = array_slice($_SERVER['argv'], 1);
}
if (isset($argv)) {
$this->addArguments((array)$argv);
}
}
/**
* Return the state of the option seen on the command line of the
* current application invocation. This function returns true, or the
* parameter to the option, if any. If the option was not given,
* this function returns null.
*
* The magic __get method works in the context of naming the option
* as a virtual member of this class.
*
* @param string $key
* @return string
*/
public function __get($key)
{
return $this->getOption($key);
}
/**
* Test whether a given option has been seen.
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
return isset($this->_options[$key]);
}
return false;
}
/**
* Set the value for a given option.
*
* @param string $key
* @param string $value
* @return void
*/
public function __set($key, $value)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
$this->_options[$key] = $value;
}
}
/**
* Return the current set of options and parameters seen as a string.
*
* @return string
*/
public function __toString()
{
return $this->toString();
}
/**
* Unset an option.
*
* @param string $key
* @return void
*/
public function __unset($key)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
unset($this->_options[$key]);
}
}
/**
* Define additional command-line arguments.
* These are appended to those defined when the constructor was called.
*
* @param array $argv
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function addArguments($argv)
{
$this->_argv = array_merge($this->_argv, $argv);
$this->_parsed = false;
return $this;
}
/**
* Define full set of command-line arguments.
* These replace any currently defined.
*
* @param array $argv
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setArguments($argv)
{
$this->_argv = $argv;
$this->_parsed = false;
return $this;
}
/**
* Define multiple configuration options from an associative array.
* These are not program options, but properties to configure
* the behavior of Zend_Console_Getopt.
*
* @param array $getoptConfig
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setOptions($getoptConfig)
{
if (isset($getoptConfig)) {
foreach ($getoptConfig as $key => $value) {
$this->setOption($key, $value);
}
}
return $this;
}
/**
* Define one configuration option as a key/value pair.
* These are not program options, but properties to configure
* the behavior of Zend_Console_Getopt.
*
* @param string $configKey
* @param string $configValue
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setOption($configKey, $configValue)
{
if ($configKey !== null) {
$this->_getoptConfig[$configKey] = $configValue;
}
return $this;
}
/**
* Define additional option rules.
* These are appended to the rules defined when the constructor was called.
*
* @param array $rules
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function addRules($rules)
{
$ruleMode = $this->_getoptConfig['ruleMode'];
switch ($this->_getoptConfig['ruleMode']) {
case self::MODE_ZEND:
if (is_array($rules)) {
$this->_addRulesModeZend($rules);
break;
}
// intentional fallthrough
case self::MODE_GNU:
$this->_addRulesModeGnu($rules);
break;
default:
/**
* Call addRulesModeFoo() for ruleMode 'foo'.
* The developer should subclass Getopt and
* provide this method.
*/
$method = '_addRulesMode' . ucfirst($ruleMode);
$this->$method($rules);
}
$this->_parsed = false;
return $this;
}
/**
* Return the current set of options and parameters seen as a string.
*
* @return string
*/
public function toString()
{
$this->parse();
$s = array();
foreach ($this->_options as $flag => $value) {
$s[] = $flag . '=' . ($value === true ? 'true' : $value);
}
return implode(' ', $s);
}
/**
* Return the current set of options and parameters seen
* as an array of canonical options and parameters.
*
* Clusters have been expanded, and option aliases
* have been mapped to their primary option names.
*
* @return array
*/
public function toArray()
{
$this->parse();
$s = array();
foreach ($this->_options as $flag => $value) {
$s[] = $flag;
if ($value !== true) {
$s[] = $value;
}
}
return $s;
}
/**
* Return the current set of options and parameters seen in Json format.
*
* @return string
*/
public function toJson()
{
$this->parse();
$j = array();
foreach ($this->_options as $flag => $value) {
$j['options'][] = array(
'option' => array(
'flag' => $flag,
'parameter' => $value
)
);
}
/**
* @see Zend_Json
*/
require_once 'Zend/Json.php';
$json = Zend_Json::encode($j);
return $json;
}
/**
* Return the current set of options and parameters seen in XML format.
*
* @return string
*/
public function toXml()
{
$this->parse();
$doc = new DomDocument('1.0', 'utf-8');
$optionsNode = $doc->createElement('options');
$doc->appendChild($optionsNode);
foreach ($this->_options as $flag => $value) {
$optionNode = $doc->createElement('option');
$optionNode->setAttribute('flag', utf8_encode($flag));
if ($value !== true) {
$optionNode->setAttribute('parameter', utf8_encode($value));
}
$optionsNode->appendChild($optionNode);
}
$xml = $doc->saveXML();
return $xml;
}
/**
* Return a list of options that have been seen in the current argv.
*
* @return array
*/
public function getOptions()
{
$this->parse();
return array_keys($this->_options);
}
/**
* Return the state of the option seen on the command line of the
* current application invocation.
*
* This function returns true, or the parameter value to the option, if any.
* If the option was not given, this function returns false.
*
* @param string $flag
* @return mixed
*/
public function getOption($flag)
{
$this->parse();
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
if (isset($this->_ruleMap[$flag])) {
$flag = $this->_ruleMap[$flag];
if (isset($this->_options[$flag])) {
return $this->_options[$flag];
}
}
return null;
}
/**
* Return the arguments from the command-line following all options found.
*
* @return array
*/
public function getRemainingArgs()
{
$this->parse();
return $this->_remainingArgs;
}
/**
* Return a useful option reference, formatted for display in an
* error message.
*
* Note that this usage information is provided in most Exceptions
* generated by this class.
*
* @return string
*/
public function getUsageMessage()
{
$usage = "Usage: {$this->_progname} [ options ]\n";
$maxLen = 20;
foreach ($this->_rules as $rule) {
$flags = array();
if (is_array($rule['alias'])) {
foreach ($rule['alias'] as $flag) {
$flags[] = (strlen($flag) == 1 ? '-' : '--') . $flag;
}
}
$linepart['name'] = implode('|', $flags);
if (isset($rule['param']) && $rule['param'] != 'none') {
$linepart['name'] .= ' ';
switch ($rule['param']) {
case 'optional':
$linepart['name'] .= "[ <{$rule['paramType']}> ]";
break;
case 'required':
$linepart['name'] .= "<{$rule['paramType']}>";
break;
}
}
if (strlen($linepart['name']) > $maxLen) {
$maxLen = strlen($linepart['name']);
}
$linepart['help'] = '';
if (isset($rule['help'])) {
$linepart['help'] .= $rule['help'];
}
$lines[] = $linepart;
}
foreach ($lines as $linepart) {
$usage .= sprintf("%s %s\n",
str_pad($linepart['name'], $maxLen),
$linepart['help']);
}
return $usage;
}
/**
* Define aliases for options.
*
* The parameter $aliasMap is an associative array
* mapping option name (short or long) to an alias.
*
* @param array $aliasMap
* @throws Zend_Console_Getopt_Exception
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setAliases($aliasMap)
{
foreach ($aliasMap as $flag => $alias)
{
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
$alias = strtolower($alias);
}
if (!isset($this->_ruleMap[$flag])) {
continue;
}
$flag = $this->_ruleMap[$flag];
if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) {
$o = (strlen($alias) == 1 ? '-' : '--') . $alias;
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"$o\" is being defined more than once.");
}
$this->_rules[$flag]['alias'][] = $alias;
$this->_ruleMap[$alias] = $flag;
}
return $this;
}
/**
* Define help messages for options.
*
* The parameter $help_map is an associative array
* mapping option name (short or long) to the help string.
*
* @param array $helpMap
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setHelp($helpMap)
{
foreach ($helpMap as $flag => $help)
{
if (!isset($this->_ruleMap[$flag])) {
continue;
}
$flag = $this->_ruleMap[$flag];
$this->_rules[$flag]['help'] = $help;
}
return $this;
}
/**
* Parse command-line arguments and find both long and short
* options.
*
* Also find option parameters, and remaining arguments after
* all options have been parsed.
*
* @return Zend_Console_Getopt|null Provides a fluent interface
*/
public function parse()
{
if ($this->_parsed === true) {
return;
}
$argv = $this->_argv;
$this->_options = array();
$this->_remainingArgs = array();
while (count($argv) > 0) {
if ($argv[0] == '--') {
array_shift($argv);
if ($this->_getoptConfig[self::CONFIG_DASHDASH]) {
$this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
break;
}
}
if (substr($argv[0], 0, 2) == '--') {
$this->_parseLongOption($argv);
} else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) {
$this->_parseShortOptionCluster($argv);
} else {
$this->_remainingArgs[] = array_shift($argv);
}
}
$this->_parsed = true;
return $this;
}
/**
* Parse command-line arguments for a single long option.
* A long option is preceded by a double '--' character.
* Long options may not be clustered.
*
* @param mixed &$argv
* @return void
*/
protected function _parseLongOption(&$argv)
{
$optionWithParam = ltrim(array_shift($argv), '-');
$l = explode('=', $optionWithParam);
$flag = array_shift($l);
$param = array_shift($l);
if (isset($param)) {
array_unshift($argv, $param);
}
$this->_parseSingleOption($flag, $argv);
}
/**
* Parse command-line arguments for short options.
* Short options are those preceded by a single '-' character.
* Short options may be clustered.
*
* @param mixed &$argv
* @return void
*/
protected function _parseShortOptionCluster(&$argv)
{
$flagCluster = ltrim(array_shift($argv), '-');
foreach (str_split($flagCluster) as $flag) {
$this->_parseSingleOption($flag, $argv);
}
}
/**
* Parse command-line arguments for a single option.
*
* @param string $flag
* @param mixed $argv
* @throws Zend_Console_Getopt_Exception
* @return void
*/
protected function _parseSingleOption($flag, &$argv)
{
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
if (!isset($this->_ruleMap[$flag])) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" is not recognized.",
$this->getUsageMessage());
}
$realFlag = $this->_ruleMap[$flag];
switch ($this->_rules[$realFlag]['param']) {
case 'required':
if (count($argv) > 0) {
$param = array_shift($argv);
$this->_checkParameterType($realFlag, $param);
} else {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires a parameter.",
$this->getUsageMessage());
}
break;
case 'optional':
if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
$param = array_shift($argv);
$this->_checkParameterType($realFlag, $param);
} else {
$param = true;
}
break;
default:
$param = true;
}
$this->_options[$realFlag] = $param;
}
/**
* Return true if the parameter is in a valid format for
* the option $flag.
* Throw an exception in most other cases.
*
* @param string $flag
* @param string $param
* @throws Zend_Console_Getopt_Exception
* @return bool
*/
protected function _checkParameterType($flag, $param)
{
$type = 'string';
if (isset($this->_rules[$flag]['paramType'])) {
$type = $this->_rules[$flag]['paramType'];
}
switch ($type) {
case 'word':
if (preg_match('/\W/', $param)) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires a single-word parameter, but was given \"$param\".",
$this->getUsageMessage());
}
break;
case 'integer':
if (preg_match('/\D/', $param)) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires an integer parameter, but was given \"$param\".",
$this->getUsageMessage());
}
break;
case 'string':
default:
break;
}
return true;
}
/**
* Define legal options using the gnu-style format.
*
* @param string $rules
* @return void
*/
protected function _addRulesModeGnu($rules)
{
$ruleArray = array();
/**
* Options may be single alphanumeric characters.
* Options may have a ':' which indicates a required string parameter.
* No long options or option aliases are supported in GNU style.
*/
preg_match_all('/([a-zA-Z0-9]:?)/', $rules, $ruleArray);
foreach ($ruleArray[1] as $rule) {
$r = array();
$flag = substr($rule, 0, 1);
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
$r['alias'][] = $flag;
if (substr($rule, 1, 1) == ':') {
$r['param'] = 'required';
$r['paramType'] = 'string';
} else {
$r['param'] = 'none';
}
$this->_rules[$flag] = $r;
$this->_ruleMap[$flag] = $flag;
}
}
/**
* Define legal options using the Zend-style format.
*
* @param array $rules
* @throws Zend_Console_Getopt_Exception
* @return void
*/
protected function _addRulesModeZend($rules)
{
foreach ($rules as $ruleCode => $helpMessage)
{
// this may have to translate the long parm type if there
// are any complaints that =string will not work (even though that use
// case is not documented)
if (in_array(substr($ruleCode, -2, 1), array('-', '='))) {
$flagList = substr($ruleCode, 0, -2);
$delimiter = substr($ruleCode, -2, 1);
$paramType = substr($ruleCode, -1);
} else {
$flagList = $ruleCode;
$delimiter = $paramType = null;
}
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flagList = strtolower($flagList);
}
$flags = explode('|', $flagList);
$rule = array();
$mainFlag = $flags[0];
foreach ($flags as $flag) {
if (empty($flag)) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Blank flag not allowed in rule \"$ruleCode\".");
}
if (strlen($flag) == 1) {
if (isset($this->_ruleMap[$flag])) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"-$flag\" is being defined more than once.");
}
$this->_ruleMap[$flag] = $mainFlag;
$rule['alias'][] = $flag;
} else {
if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) {
/**
* @see Zend_Console_Getopt_Exception
*/
throw new Zend_Console_Getopt_Exception(
"Option \"--$flag\" is being defined more than once.");
}
$this->_ruleMap[$flag] = $mainFlag;
$rule['alias'][] = $flag;
}
}
if (isset($delimiter)) {
switch ($delimiter) {
case self::PARAM_REQUIRED:
$rule['param'] = 'required';
break;
case self::PARAM_OPTIONAL:
default:
$rule['param'] = 'optional';
}
switch (substr($paramType, 0, 1)) {
case self::TYPE_WORD:
$rule['paramType'] = 'word';
break;
case self::TYPE_INTEGER:
$rule['paramType'] = 'integer';
break;
case self::TYPE_STRING:
default:
$rule['paramType'] = 'string';
}
} else {
$rule['param'] = 'none';
}
$rule['help'] = $helpMessage;
$this->_rules[$mainFlag] = $rule;
}
}
}
Console/Getopt/Exception.php 0000604 00000003021 15071256135 0012054 0 ustar 00 <?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_Console_Getopt
* @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 Zend_Console_Getopt_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Console_Getopt
* @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_Console_Getopt_Exception extends Zend_Exception
{
/**
* Usage
*
* @var string
*/
protected $usage = '';
/**
* Constructor
*
* @param string $message
* @param string $usage
* @return void
*/
public function __construct($message, $usage = '')
{
$this->usage = $usage;
parent::__construct($message);
}
/**
* Returns the usage
*
* @return string
*/
public function getUsageMessage()
{
return $this->usage;
}
}
Cache/Backend/File.php 0000604 00000102677 15071256135 0010504 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
/**
* Available options
*
* =====> (string) cache_dir :
* - Directory where to put the cache files
*
* =====> (boolean) file_locking :
* - Enable / disable file_locking
* - Can avoid cache corruption under bad circumstances but it doesn't work on multithread
* webservers and on NFS filesystems for example
*
* =====> (boolean) read_control :
* - Enable / disable read control
* - If enabled, a control key is embeded in cache file and this key is compared with the one
* calculated after the reading.
*
* =====> (string) read_control_type :
* - Type of read control (only if read control is enabled). Available values are :
* 'md5' for a md5 hash control (best but slowest)
* 'crc32' for a crc32 hash control (lightly less safe but faster, better choice)
* 'adler32' for an adler32 hash control (excellent choice too, faster than crc32)
* 'strlen' for a length only test (fastest)
*
* =====> (int) hashed_directory_level :
* - Hashed directory level
* - Set the hashed directory structure level. 0 means "no hashed directory
* structure", 1 means "one level of directory", 2 means "two levels"...
* This option can speed up the cache only when you have many thousands of
* cache file. Only specific benchs can help you to choose the perfect value
* for you. Maybe, 1 or 2 is a good start.
*
* =====> (int) hashed_directory_umask :
* - Umask for hashed directory structure
*
* =====> (string) file_name_prefix :
* - prefix for cache files
* - be really carefull with this option because a too generic value in a system cache dir
* (like /tmp) can cause disasters when cleaning the cache
*
* =====> (int) cache_file_umask :
* - Umask for cache files
*
* =====> (int) metatadatas_array_max_size :
* - max size for the metadatas array (don't change this value unless you
* know what you are doing)
*
* @var array available options
*/
protected $_options = array(
'cache_dir' => null,
'file_locking' => true,
'read_control' => true,
'read_control_type' => 'crc32',
'hashed_directory_level' => 0,
'hashed_directory_umask' => 0700,
'file_name_prefix' => 'zend_cache',
'cache_file_umask' => 0600,
'metadatas_array_max_size' => 100
);
/**
* Array of metadatas (each item is an associative array)
*
* @var array
*/
private $_metadatasArray = array();
/**
* Constructor
*
* @param array $options associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
parent::__construct($options);
if (!is_null($this->_options['cache_dir'])) { // particular case for this option
$this->setCacheDir($this->_options['cache_dir']);
} else {
$this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false);
}
if (isset($this->_options['file_name_prefix'])) { // particular case for this option
if (!preg_match('~^[\w]+$~', $this->_options['file_name_prefix'])) {
Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-A0-9_]');
}
}
if ($this->_options['metadatas_array_max_size'] < 10) {
Zend_Cache::throwException('Invalid metadatas_array_max_size, must be > 10');
}
if (isset($options['hashed_directory_umask']) && is_string($options['hashed_directory_umask'])) {
// See #ZF-4422
$this->_options['hashed_directory_umask'] = octdec($this->_options['hashed_directory_umask']);
}
if (isset($options['cache_file_umask']) && is_string($options['cache_file_umask'])) {
// See #ZF-4422
$this->_options['cache_file_umask'] = octdec($this->_options['cache_file_umask']);
}
}
/**
* Set the cache_dir (particular case of setOption() method)
*
* @param string $value
* @param boolean $trailingSeparator If true, add a trailing separator is necessary
* @throws Zend_Cache_Exception
* @return void
*/
public function setCacheDir($value, $trailingSeparator = true)
{
if (!is_dir($value)) {
Zend_Cache::throwException('cache_dir must be a directory');
}
if (!is_writable($value)) {
Zend_Cache::throwException('cache_dir is not writable');
}
if ($trailingSeparator) {
// add a trailing DIRECTORY_SEPARATOR if necessary
$value = rtrim(realpath($value), '\\/') . DIRECTORY_SEPARATOR;
}
$this->_options['cache_dir'] = $value;
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id cache id
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
* @return string|false cached datas
*/
public function load($id, $doNotTestCacheValidity = false)
{
if (!($this->_test($id, $doNotTestCacheValidity))) {
// The cache is not hit !
return false;
}
$metadatas = $this->_getMetadatas($id);
$file = $this->_file($id);
$data = $this->_fileGetContents($file);
if ($this->_options['read_control']) {
$hashData = $this->_hash($data, $this->_options['read_control_type']);
$hashControl = $metadatas['hash'];
if ($hashData != $hashControl) {
// Problem detected by the read control !
$this->_log('Zend_Cache_Backend_File::load() / read_control : stored hash and computed hash do not match');
$this->remove($id);
return false;
}
}
return $data;
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id cache id
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
clearstatcache();
return $this->_test($id, false);
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
clearstatcache();
$file = $this->_file($id);
$path = $this->_path($id);
if ($this->_options['hashed_directory_level'] > 0) {
if (!is_writable($path)) {
// maybe, we just have to build the directory structure
$this->_recursiveMkdirAndChmod($id);
}
if (!is_writable($path)) {
return false;
}
}
if ($this->_options['read_control']) {
$hash = $this->_hash($data, $this->_options['read_control_type']);
} else {
$hash = '';
}
$metadatas = array(
'hash' => $hash,
'mtime' => time(),
'expire' => $this->_expireTime($this->getLifetime($specificLifetime)),
'tags' => $tags
);
$res = $this->_setMetadatas($id, $metadatas);
if (!$res) {
$this->_log('Zend_Cache_Backend_File::save() / error on saving metadata');
return false;
}
$res = $this->_filePutContents($file, $data);
return $res;
}
/**
* Remove a cache record
*
* @param string $id cache id
* @return boolean true if no problem
*/
public function remove($id)
{
$file = $this->_file($id);
return ($this->_delMetadatas($id) && $this->_remove($file));
}
/**
* Clean some cache records
*
* Available modes are :
* 'all' (default) => remove all cache entries ($tags is not used)
* 'old' => remove too old cache entries ($tags is not used)
* 'matchingTag' => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* 'notMatchingTag' => remove cache entries not matching one of the given tags
* ($tags can be an array of strings or a single string)
* 'matchingAnyTag' => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode clean mode
* @param tags array $tags array of tags
* @return boolean true if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
// We use this private method to hide the recursive stuff
clearstatcache();
return $this->_clean($this->_options['cache_dir'], $mode, $tags);
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
return $this->_get($this->_options['cache_dir'], 'ids', array());
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
return $this->_get($this->_options['cache_dir'], 'tags', array());
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
return $this->_get($this->_options['cache_dir'], 'matching', $tags);
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
return $this->_get($this->_options['cache_dir'], 'notMatching', $tags);
}
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array())
{
return $this->_get($this->_options['cache_dir'], 'matchingAny', $tags);
}
/**
* Return the filling percentage of the backend storage
*
* @throws Zend_Cache_Exception
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
$free = disk_free_space($this->_options['cache_dir']);
$total = disk_total_space($this->_options['cache_dir']);
if ($total == 0) {
Zend_Cache::throwException('can\'t get disk_total_space');
} else {
if ($free >= $total) {
return 100;
}
return ((int) (100. * ($total - $free) / $total));
}
}
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id)
{
$metadatas = $this->_getMetadatas($id);
if (!$metadatas) {
return false;
}
if (time() > $metadatas['expire']) {
return false;
}
return array(
'expire' => $metadatas['expire'],
'tags' => $metadatas['tags'],
'mtime' => $metadatas['mtime']
);
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
$metadatas = $this->_getMetadatas($id);
if (!$metadatas) {
return false;
}
if (time() > $metadatas['expire']) {
return false;
}
$newMetadatas = array(
'hash' => $metadatas['hash'],
'mtime' => time(),
'expire' => $metadatas['expire'] + $extraLifetime,
'tags' => $metadatas['tags']
);
$res = $this->_setMetadatas($id, $newMetadatas);
if (!$res) {
return false;
}
return true;
}
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities()
{
return array(
'automatic_cleaning' => true,
'tags' => true,
'expired_read' => true,
'priority' => false,
'infinite_lifetime' => true,
'get_list' => true
);
}
/**
* PUBLIC METHOD FOR UNIT TESTING ONLY !
*
* Force a cache record to expire
*
* @param string $id cache id
*/
public function ___expire($id)
{
$metadatas = $this->_getMetadatas($id);
if ($metadatas) {
$metadatas['expire'] = 1;
$this->_setMetadatas($id, $metadatas);
}
}
/**
* Get a metadatas record
*
* @param string $id Cache id
* @return array|false Associative array of metadatas
*/
private function _getMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
return $this->_metadatasArray[$id];
} else {
$metadatas = $this->_loadMetadatas($id);
if (!$metadatas) {
return false;
}
$this->_setMetadatas($id, $metadatas, false);
return $metadatas;
}
}
/**
* Set a metadatas record
*
* @param string $id Cache id
* @param array $metadatas Associative array of metadatas
* @param boolean $save optional pass false to disable saving to file
* @return boolean True if no problem
*/
private function _setMetadatas($id, $metadatas, $save = true)
{
if (count($this->_metadatasArray) >= $this->_options['metadatas_array_max_size']) {
$n = (int) ($this->_options['metadatas_array_max_size'] / 10);
$this->_metadatasArray = array_slice($this->_metadatasArray, $n);
}
if ($save) {
$result = $this->_saveMetadatas($id, $metadatas);
if (!$result) {
return false;
}
}
$this->_metadatasArray[$id] = $metadatas;
return true;
}
/**
* Drop a metadata record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
private function _delMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
unset($this->_metadatasArray[$id]);
}
$file = $this->_metadatasFile($id);
return $this->_remove($file);
}
/**
* Clear the metadatas array
*
* @return void
*/
private function _cleanMetadatas()
{
$this->_metadatasArray = array();
}
/**
* Load metadatas from disk
*
* @param string $id Cache id
* @return array|false Metadatas associative array
*/
private function _loadMetadatas($id)
{
$file = $this->_metadatasFile($id);
$result = $this->_fileGetContents($file);
if (!$result) {
return false;
}
$tmp = @unserialize($result);
return $tmp;
}
/**
* Save metadatas to disk
*
* @param string $id Cache id
* @param array $metadatas Associative array
* @return boolean True if no problem
*/
private function _saveMetadatas($id, $metadatas)
{
$file = $this->_metadatasFile($id);
$result = $this->_filePutContents($file, serialize($metadatas));
if (!$result) {
return false;
}
return true;
}
/**
* Make and return a file name (with path) for metadatas
*
* @param string $id Cache id
* @return string Metadatas file name (with path)
*/
private function _metadatasFile($id)
{
$path = $this->_path($id);
$fileName = $this->_idToFileName('internal-metadatas---' . $id);
return $path . $fileName;
}
/**
* Check if the given filename is a metadatas one
*
* @param string $fileName File name
* @return boolean True if it's a metadatas one
*/
private function _isMetadatasFile($fileName)
{
$id = $this->_fileNameToId($fileName);
if (substr($id, 0, 21) == 'internal-metadatas---') {
return true;
} else {
return false;
}
}
/**
* Remove a file
*
* If we can't remove the file (because of locks or any problem), we will touch
* the file to invalidate it
*
* @param string $file Complete file path
* @return boolean True if ok
*/
private function _remove($file)
{
if (!is_file($file)) {
return false;
}
if (!@unlink($file)) {
# we can't remove the file (because of locks or any problem)
$this->_log("Zend_Cache_Backend_File::_remove() : we can't remove $file");
return false;
}
return true;
}
/**
* Clean some cache records (private method used for recursive stuff)
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $dir Directory to clean
* @param string $mode Clean mode
* @param array $tags Array of tags
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
private function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
if (!is_dir($dir)) {
return false;
}
$result = true;
$prefix = $this->_options['file_name_prefix'];
$glob = @glob($dir . $prefix . '--*');
if ($glob === false) {
return true;
}
foreach ($glob as $file) {
if (is_file($file)) {
$fileName = basename($file);
if ($this->_isMetadatasFile($fileName)) {
// in CLEANING_MODE_ALL, we drop anything, even remainings old metadatas files
if ($mode != Zend_Cache::CLEANING_MODE_ALL) {
continue;
}
}
$id = $this->_fileNameToId($fileName);
$metadatas = $this->_getMetadatas($id);
if ($metadatas === FALSE) {
$metadatas = array('expire' => 1, 'tags' => array());
}
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
$res = $this->remove($id);
if (!$res) {
// in this case only, we accept a problem with the metadatas file drop
$res = $this->_remove($file);
}
$result = $result && $res;
break;
case Zend_Cache::CLEANING_MODE_OLD:
if (time() > $metadatas['expire']) {
$result = ($result) && ($this->remove($id));
}
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
$matching = true;
foreach ($tags as $tag) {
if (!in_array($tag, $metadatas['tags'])) {
$matching = false;
break;
}
}
if ($matching) {
$result = ($result) && ($this->remove($id));
}
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
$matching = false;
foreach ($tags as $tag) {
if (in_array($tag, $metadatas['tags'])) {
$matching = true;
break;
}
}
if (!$matching) {
$result = ($result) && $this->remove($id);
}
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$matching = false;
foreach ($tags as $tag) {
if (in_array($tag, $metadatas['tags'])) {
$matching = true;
break;
}
}
if ($matching) {
$result = ($result) && ($this->remove($id));
}
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
// Recursive call
$result = ($result) && ($this->_clean($file . DIRECTORY_SEPARATOR, $mode, $tags));
if ($mode=='all') {
// if mode=='all', we try to drop the structure too
@rmdir($file);
}
}
}
return $result;
}
private function _get($dir, $mode, $tags = array())
{
if (!is_dir($dir)) {
return false;
}
$result = array();
$prefix = $this->_options['file_name_prefix'];
$glob = @glob($dir . $prefix . '--*');
if ($glob === false) {
return true;
}
foreach ($glob as $file) {
if (is_file($file)) {
$fileName = basename($file);
$id = $this->_fileNameToId($fileName);
$metadatas = $this->_getMetadatas($id);
if ($metadatas === FALSE) {
continue;
}
if (time() > $metadatas['expire']) {
continue;
}
switch ($mode) {
case 'ids':
$result[] = $id;
break;
case 'tags':
$result = array_unique(array_merge($result, $metadatas['tags']));
break;
case 'matching':
$matching = true;
foreach ($tags as $tag) {
if (!in_array($tag, $metadatas['tags'])) {
$matching = false;
break;
}
}
if ($matching) {
$result[] = $id;
}
break;
case 'notMatching':
$matching = false;
foreach ($tags as $tag) {
if (in_array($tag, $metadatas['tags'])) {
$matching = true;
break;
}
}
if (!$matching) {
$result[] = $id;
}
break;
case 'matchingAny':
$matching = false;
foreach ($tags as $tag) {
if (in_array($tag, $metadatas['tags'])) {
$matching = true;
break;
}
}
if ($matching) {
$result[] = $id;
}
break;
default:
Zend_Cache::throwException('Invalid mode for _get() method');
break;
}
}
if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) {
// Recursive call
$result = array_unique(array_merge($result, $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags)));
}
}
return array_unique($result);
}
/**
* Compute & return the expire time
*
* @return int expire time (unix timestamp)
*/
private function _expireTime($lifetime)
{
if (is_null($lifetime)) {
return 9999999999;
}
return time() + $lifetime;
}
/**
* Make a control key with the string containing datas
*
* @param string $data Data
* @param string $controlType Type of control 'md5', 'crc32' or 'strlen'
* @throws Zend_Cache_Exception
* @return string Control key
*/
private function _hash($data, $controlType)
{
switch ($controlType) {
case 'md5':
return md5($data);
case 'crc32':
return crc32($data);
case 'strlen':
return strlen($data);
case 'adler32':
return hash('adler32', $data);
default:
Zend_Cache::throwException("Incorrect hash function : $controlType");
}
}
/**
* Transform a cache id into a file name and return it
*
* @param string $id Cache id
* @return string File name
*/
private function _idToFileName($id)
{
$prefix = $this->_options['file_name_prefix'];
$result = $prefix . '---' . $id;
return $result;
}
/**
* Make and return a file name (with path)
*
* @param string $id Cache id
* @return string File name (with path)
*/
private function _file($id)
{
$path = $this->_path($id);
$fileName = $this->_idToFileName($id);
return $path . $fileName;
}
/**
* Return the complete directory path of a filename (including hashedDirectoryStructure)
*
* @param string $id Cache id
* @param boolean $parts if true, returns array of directory parts instead of single string
* @return string Complete directory path
*/
private function _path($id, $parts = false)
{
$partsArray = array();
$root = $this->_options['cache_dir'];
$prefix = $this->_options['file_name_prefix'];
if ($this->_options['hashed_directory_level']>0) {
$hash = hash('adler32', $id);
for ($i=0 ; $i < $this->_options['hashed_directory_level'] ; $i++) {
$root = $root . $prefix . '--' . substr($hash, 0, $i + 1) . DIRECTORY_SEPARATOR;
$partsArray[] = $root;
}
}
if ($parts) {
return $partsArray;
} else {
return $root;
}
}
/**
* Make the directory strucuture for the given id
*
* @param string $id cache id
* @return boolean true
*/
private function _recursiveMkdirAndChmod($id)
{
if ($this->_options['hashed_directory_level'] <=0) {
return true;
}
$partsArray = $this->_path($id, true);
foreach ($partsArray as $part) {
if (!is_dir($part)) {
@mkdir($part, $this->_options['hashed_directory_umask']);
@chmod($part, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)
}
}
return true;
}
/**
* Test if the given cache id is available (and still valid as a cache record)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return boolean|mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
private function _test($id, $doNotTestCacheValidity)
{
$metadatas = $this->_getMetadatas($id);
if (!$metadatas) {
return false;
}
if ($doNotTestCacheValidity || (time() <= $metadatas['expire'])) {
return $metadatas['mtime'];
}
return false;
}
/**
* Return the file content of the given file
*
* @param string $file File complete path
* @return string File content (or false if problem)
*/
private function _fileGetContents($file)
{
$result = false;
if (!is_file($file)) {
return false;
}
if (function_exists('get_magic_quotes_runtime')) {
$mqr = @get_magic_quotes_runtime();
@set_magic_quotes_runtime(0);
}
$f = @fopen($file, 'rb');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_SH);
$result = stream_get_contents($f);
if ($this->_options['file_locking']) @flock($f, LOCK_UN);
@fclose($f);
}
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime($mqr);
}
return $result;
}
/**
* Put the given string into the given file
*
* @param string $file File complete path
* @param string $string String to put in file
* @return boolean true if no problem
*/
private function _filePutContents($file, $string)
{
$result = false;
$f = @fopen($file, 'ab+');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_EX);
fseek($f, 0);
ftruncate($f, 0);
$tmp = @fwrite($f, $string);
if (!($tmp === FALSE)) {
$result = true;
}
@fclose($f);
}
@chmod($file, $this->_options['cache_file_umask']);
return $result;
}
/**
* Transform a file name into cache id and return it
*
* @param string $fileName File name
* @return string Cache id
*/
private function _fileNameToId($fileName)
{
$prefix = $this->_options['file_name_prefix'];
return preg_replace('~^' . $prefix . '---(.*)$~', '$1', $fileName);
}
}
Cache/Backend/ZendPlatform.php 0000604 00000027204 15071256135 0012222 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend.php';
/**
* @see Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/Interface.php';
/**
* Impementation of Zend Cache Backend using the Zend Platform (Output Content Caching)
*
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
{
/**
* internal ZP prefix
*/
const TAGS_PREFIX = "internal_ZPtag:";
/**
* Constructor
* Validate that the Zend Platform is loaded and licensed
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
if (!function_exists('accelerator_license_info')) {
Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
}
if (!function_exists('accelerator_get_configuration')) {
$licenseInfo = accelerator_license_info();
Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: '.$licenseInfo['failure_reason']);
}
$accConf = accelerator_get_configuration();
if (@!$accConf['output_cache_licensed']) {
Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
}
if (@!$accConf['output_cache_enabled']) {
Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
}
if (!is_writable($accConf['output_cache_dir'])) {
Zend_Cache::throwException('The cache copies directory \''. ini_get('zend_accelerator.output_cache_dir') .'\' must be writable !');
}
parent:: __construct($options);
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string Cached data (or false)
*/
public function load($id, $doNotTestCacheValidity = false)
{
// doNotTestCacheValidity implemented by giving zero lifetime to the cache
if ($doNotTestCacheValidity) {
$lifetime = 0;
} else {
$lifetime = $this->_directives['lifetime'];
}
$res = output_cache_get($id, $lifetime);
if($res) {
return $res[0];
} else {
return false;
}
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id Cache id
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$result = output_cache_get($id, $this->_directives['lifetime']);
if ($result) {
return $result[1];
}
return false;
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Data to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
if (!($specificLifetime === false)) {
$this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend");
}
$lifetime = $this->_directives['lifetime'];
$result1 = output_cache_put($id, array($data, time()));
$result2 = (count($tags) == 0);
foreach ($tags as $tag) {
$tagid = self::TAGS_PREFIX.$tag;
$old_tags = output_cache_get($tagid, $lifetime);
if ($old_tags === false) {
$old_tags = array();
}
$old_tags[$id] = $id;
output_cache_remove_key($tagid);
$result2 = output_cache_put($tagid, $old_tags);
}
return $result1 && $result2;
}
/**
* Remove a cache record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id)
{
return output_cache_remove_key($id);
}
/**
* Clean some cache records
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* This mode is not supported in this backend
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
case Zend_Cache::CLEANING_MODE_OLD:
$cache_dir = ini_get('zend_accelerator.output_cache_dir');
if (!$cache_dir) {
return false;
}
$cache_dir .= '/.php_cache_api/';
return $this->_clean($cache_dir, $mode);
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
$idlist = null;
foreach ($tags as $tag) {
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
if ($idlist) {
$idlist = array_intersect_assoc($idlist, $next_idlist);
} else {
$idlist = $next_idlist;
}
if (count($idlist) == 0) {
// if ID list is already empty - we may skip checking other IDs
$idlist = null;
break;
}
}
if ($idlist) {
foreach ($idlist as $id) {
output_cache_remove_key($id);
}
}
return true;
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
$this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend");
return false;
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$idlist = null;
foreach ($tags as $tag) {
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
if ($idlist) {
$idlist = array_merge_recursive($idlist, $next_idlist);
} else {
$idlist = $next_idlist;
}
if (count($idlist) == 0) {
// if ID list is already empty - we may skip checking other IDs
$idlist = null;
break;
}
}
if ($idlist) {
foreach ($idlist as $id) {
output_cache_remove_key($id);
}
}
return true;
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
/**
* Clean a directory and recursivly go over it's subdirectories
*
* Remove all the cached files that need to be cleaned (according to mode and files mtime)
*
* @param string $dir Path of directory ot clean
* @param string $mode The same parameter as in Zend_Cache_Backend_ZendPlatform::clean()
* @return boolean True if ok
*/
private function _clean($dir, $mode)
{
$d = @dir($dir);
if (!$d) {
return false;
}
$result = true;
while (false !== ($file = $d->read())) {
if ($file == '.' || $file == '..') {
continue;
}
$file = $d->path . $file;
if (is_dir($file)) {
$result = ($this->_clean($file .'/', $mode)) && ($result);
} else {
if ($mode == Zend_Cache::CLEANING_MODE_ALL) {
$result = ($this->_remove($file)) && ($result);
} else if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
// Files older than lifetime get deleted from cache
if (!is_null($this->_directives['lifetime'])) {
if ((time() - @filemtime($file)) > $this->_directives['lifetime']) {
$result = ($this->_remove($file)) && ($result);
}
}
}
}
}
$d->close();
return $result;
}
/**
* Remove a file
*
* If we can't remove the file (because of locks or any problem), we will touch
* the file to invalidate it
*
* @param string $file Complete file path
* @return boolean True if ok
*/
private function _remove($file)
{
if (!@unlink($file)) {
# If we can't remove the file (because of locks or any problem), we will touch
# the file to invalidate it
$this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
if (is_null($this->_directives['lifetime'])) {
return false;
}
if (!file_exists($file)) {
return false;
}
return @touch($file, time() - 2*abs($this->_directives['lifetime']));
}
return true;
}
}
Cache/Backend/TwoLevels.php 0000604 00000044345 15071256135 0011546 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_ExtendedInterface
*/
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
/**
* Available options
*
* =====> (string) slow_backend :
* - Slow backend name
* - Must implement the Zend_Cache_Backend_ExtendedInterface
* - Should provide a big storage
*
* =====> (string) fast_backend :
* - Flow backend name
* - Must implement the Zend_Cache_Backend_ExtendedInterface
* - Must be much faster than slow_backend
*
* =====> (array) slow_backend_options :
* - Slow backend options (see corresponding backend)
*
* =====> (array) fast_backend_options :
* - Fast backend options (see corresponding backend)
*
* =====> (int) stats_update_factor :
* - Disable / Tune the computation of the fast backend filling percentage
* - When saving a record into cache :
* 1 => systematic computation of the fast backend filling percentage
* x (integer) > 1 => computation of the fast backend filling percentage randomly 1 times on x cache write
*
* =====> (boolean) slow_backend_custom_naming :
* =====> (boolean) fast_backend_custom_naming :
* =====> (boolean) slow_backend_autoload :
* =====> (boolean) fast_backend_autoload :
* - See Zend_Cache::factory() method
*
* =====> (boolean) auto_refresh_fast_cache
* - If true, auto refresh the fast cache when a cache record is hit
*
* @var array available options
*/
protected $_options = array(
'slow_backend' => 'File',
'fast_backend' => 'Apc',
'slow_backend_options' => array(),
'fast_backend_options' => array(),
'stats_update_factor' => 10,
'slow_backend_custom_naming' => false,
'fast_backend_custom_naming' => false,
'slow_backend_autoload' => false,
'fast_backend_autoload' => false,
'auto_refresh_fast_cache' => true
);
/**
* Slow Backend
*
* @var Zend_Cache_Backend
*/
private $_slowBackend;
/**
* Fast Backend
*
* @var Zend_Cache_Backend
*/
private $_fastBackend;
/**
* Cache for the fast backend filling percentage
*
* @var int
*/
private $_fastBackendFillingPercentage = null;
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
parent::__construct($options);
if (is_null($this->_options['slow_backend'])) {
Zend_Cache::throwException('slow_backend option has to set');
}
if (is_null($this->_options['fast_backend'])) {
Zend_Cache::throwException('fast_backend option has to set');
}
$this->_slowBackend = Zend_Cache::_makeBackend($this->_options['slow_backend'], $this->_options['slow_backend_options'], $this->_options['slow_backend_custom_naming'], $this->_options['slow_backend_autoload']);
$this->_fastBackend = Zend_Cache::_makeBackend($this->_options['fast_backend'], $this->_options['fast_backend_options'], $this->_options['fast_backend_custom_naming'], $this->_options['fast_backend_autoload']);
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
}
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
}
$this->_slowBackend->setDirectives($this->_directives);
$this->_fastBackend->setDirectives($this->_directives);
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id cache id
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$fastTest = $this->_fastBackend->test($id);
if ($fastTest) {
return $fastTest;
} else {
return $this->_slowBackend->test($id);
}
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false, $priority = 8)
{
$usage = $this->_getFastFillingPercentage('saving');
$boolFast = true;
$lifetime = $this->getLifetime($specificLifetime);
$preparedData = $this->_prepareData($data, $lifetime, $priority);
if (($priority > 0) && (10 * $priority >= $usage)) {
$fastLifetime = $this->_getFastLifetime($lifetime, $priority);
$boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
}
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
return ($boolFast && $boolSlow);
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* Note : return value is always "string" (unserialization is done by the core not by the backend)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string|false cached datas
*/
public function load($id, $doNotTestCacheValidity = false)
{
$res = $this->_fastBackend->load($id, $doNotTestCacheValidity);
if ($res === false) {
$res = $this->_slowBackend->load($id, $doNotTestCacheValidity);
if ($res === false) {
// there is no cache at all for this id
return false;
}
}
$array = unserialize($res);
// maybe, we have to refresh the fast cache ?
if ($this->_options['auto_refresh_fast_cache']) {
if ($array['priority'] == 10) {
// no need to refresh the fast cache with priority = 10
return $array['data'];
}
$newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
// we have the time to refresh the fast cache
$usage = $this->_getFastFillingPercentage('loading');
if (($array['priority'] > 0) && (10 * $array['priority'] >= $usage)) {
// we can refresh the fast cache
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
$this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
}
}
return $array['data'];
}
/**
* Remove a cache record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id)
{
$this->_fastBackend->remove($id);
return $this->_slowBackend->remove($id);
}
/**
* Clean some cache records
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @throws Zend_Cache_Exception
* @return boolean true if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
$boolFast = $this->_fastBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
$boolSlow = $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
return $boolFast && $boolSlow;
break;
case Zend_Cache::CLEANING_MODE_OLD:
return $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_OLD);
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
$ids = $this->_slowBackend->getIdsMatchingTags($tags);
$res = true;
foreach ($ids as $id) {
$res = $res && $this->_slowBackend->remove($id) && $this->_fastBackend->remove($id);
}
return $res;
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
$ids = $this->_slowBackend->getIdsNotMatchingTags($tags);
$res = true;
foreach ($ids as $id) {
$res = $res && $this->_slowBackend->remove($id) && $this->_fastBackend->remove($id);
}
return $res;
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$ids = $this->_slowBackend->getIdsMatchingAnyTags($tags);
$res = true;
foreach ($ids as $id) {
$res = $res && $this->_slowBackend->remove($id) && $this->_fastBackend->remove($id);
}
return $res;
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
return $this->_slowBackend->getIds();
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
return $this->_slowBackend->getTags();
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
return $this->_slowBackend->getIdsMatchingTags($tags);
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
return $this->_slowBackend->getIdsNotMatchingTags($tags);
}
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array())
{
return $this->_slowBackend->getIdsMatchingAnyTags($tags);
}
/**
* Return the filling percentage of the backend storage
*
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
return $this->_slowBackend->getFillingPercentage();
}
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id)
{
return $this->_slowBackend->getMetadatas($id);
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
return $this->_slowBackend->touch($id, $extraLifetime);
}
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities()
{
$slowBackendCapabilities = $this->_slowBackend->getCapabilities();
return array(
'automatic_cleaning' => $slowBackendCapabilities['automatic_cleaning'],
'tags' => $slowBackendCapabilities['tags'],
'expired_read' => $slowBackendCapabilities['expired_read'],
'priority' => $slowBackendCapabilities['priority'],
'infinite_lifetime' => $slowBackendCapabilities['infinite_lifetime'],
'get_list' => $slowBackendCapabilities['get_list']
);
}
/**
* Prepare a serialized array to store datas and metadatas informations
*
* @param string $data data to store
* @param int $lifetime original lifetime
* @param int $priority priority
* @return string serialize array to store into cache
*/
private function _prepareData($data, $lifetime, $priority)
{
$lt = $lifetime;
if (is_null($lt)) {
$lt = 9999999999;
}
return serialize(array(
'data' => $data,
'lifetime' => $lifetime,
'expire' => time() + $lt,
'priority' => $priority
));
}
/**
* Compute and return the lifetime for the fast backend
*
* @param int $lifetime original lifetime
* @param int $priority priority
* @param int $maxLifetime maximum lifetime
* @return int lifetime for the fast backend
*/
private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
{
if (is_null($lifetime)) {
// if lifetime is null, we have an infinite lifetime
// we need to use arbitrary lifetimes
$fastLifetime = (int) (2592000 / (11 - $priority));
} else {
$fastLifetime = (int) ($lifetime / (11 - $priority));
}
if (!is_null($maxLifetime) && ($maxLifetime >= 0)) {
if ($fastLifetime > $maxLifetime) {
return $maxLifetime;
}
}
return $fastLifetime;
}
/**
* PUBLIC METHOD FOR UNIT TESTING ONLY !
*
* Force a cache record to expire
*
* @param string $id cache id
*/
public function ___expire($id)
{
$this->_fastBackend->remove($id);
$this->_slowBackend->___expire($id);
}
private function _getFastFillingPercentage($mode)
{
if ($mode == 'saving') {
// mode saving
if (is_null($this->_fastBackendFillingPercentage)) {
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
} else {
$rand = rand(1, $this->_options['stats_update_factor']);
if ($rand == 1) {
// we force a refresh
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
}
}
} else {
// mode loading
// we compute the percentage only if it's not available in cache
if (is_null($this->_fastBackendFillingPercentage)) {
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
}
}
return $this->_fastBackendFillingPercentage;
}
}
Cache/Backend/Sqlite.php 0000604 00000054760 15071256135 0011065 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
/**
* Available options
*
* =====> (string) cache_db_complete_path :
* - the complete path (filename included) of the SQLITE database
*
* ====> (int) automatic_vacuum_factor :
* - Disable / Tune the automatic vacuum process
* - The automatic vacuum process defragment the database file (and make it smaller)
* when a clean() or delete() is called
* 0 => no automatic vacuum
* 1 => systematic vacuum (when delete() or clean() methods are called)
* x (integer) > 1 => automatic vacuum randomly 1 times on x clean() or delete()
*
* @var array Available options
*/
protected $_options = array(
'cache_db_complete_path' => null,
'automatic_vacuum_factor' => 10
);
/**
* DB ressource
*
* @var mixed $_db
*/
private $_db = null;
/**
* Boolean to store if the structure has benn checked or not
*
* @var boolean $_structureChecked
*/
private $_structureChecked = false;
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
parent::__construct($options);
if (is_null($this->_options['cache_db_complete_path'])) {
Zend_Cache::throwException('cache_db_complete_path option has to set');
}
if (!extension_loaded('sqlite')) {
Zend_Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
}
$this->_getConnection();
}
/**
* Destructor
*
* @return void
*/
public function __destruct()
{
@sqlite_close($this->_getConnection());
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string|false Cached datas
*/
public function load($id, $doNotTestCacheValidity = false)
{
$this->_checkAndBuildStructure();
$sql = "SELECT content FROM cache WHERE id='$id'";
if (!$doNotTestCacheValidity) {
$sql = $sql . " AND (expire=0 OR expire>" . time() . ')';
}
$result = $this->_query($sql);
$row = @sqlite_fetch_array($result);
if ($row) {
return $row['content'];
}
return false;
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id Cache id
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$this->_checkAndBuildStructure();
$sql = "SELECT lastModified FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
$result = $this->_query($sql);
$row = @sqlite_fetch_array($result);
if ($row) {
return ((int) $row['lastModified']);
}
return false;
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$this->_checkAndBuildStructure();
$lifetime = $this->getLifetime($specificLifetime);
$data = @sqlite_escape_string($data);
$mktime = time();
if (is_null($lifetime)) {
$expire = 0;
} else {
$expire = $mktime + $lifetime;
}
$this->_query("DELETE FROM cache WHERE id='$id'");
$sql = "INSERT INTO cache (id, content, lastModified, expire) VALUES ('$id', '$data', $mktime, $expire)";
$res = $this->_query($sql);
if (!$res) {
$this->_log("Zend_Cache_Backend_Sqlite::save() : impossible to store the cache id=$id");
return false;
}
$res = true;
foreach ($tags as $tag) {
$res = $res && $this->_registerTag($id, $tag);
}
return $res;
}
/**
* Remove a cache record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id)
{
$this->_checkAndBuildStructure();
$res = $this->_query("SELECT COUNT(*) AS nbr FROM cache WHERE id='$id'");
$result1 = @sqlite_fetch_single($res);
$result2 = $this->_query("DELETE FROM cache WHERE id='$id'");
$result3 = $this->_query("DELETE FROM tag WHERE id='$id'");
$this->_automaticVacuum();
return ($result1 && $result2 && $result3);
}
/**
* Clean some cache records
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @return boolean True if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
$this->_checkAndBuildStructure();
$return = $this->_clean($mode, $tags);
$this->_automaticVacuum();
return $return;
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
$this->_checkAndBuildStructure();
$res = $this->_query("SELECT id FROM cache WHERE (expire=0 OR expire>" . time() . ")");
$result = array();
while ($id = @sqlite_fetch_single($res)) {
$result[] = $id;
}
return $result;
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
$this->_checkAndBuildStructure();
$res = $this->_query("SELECT DISTINCT(name) AS name FROM tag");
$result = array();
while ($id = @sqlite_fetch_single($res)) {
$result[] = $id;
}
return $result;
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
$first = true;
$ids = array();
foreach ($tags as $tag) {
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
if (!$res) {
return array();
}
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
$ids2 = array();
foreach ($rows as $row) {
$ids2[] = $row['id'];
}
if ($first) {
$ids = $ids2;
$first = false;
} else {
$ids = array_intersect($ids, $ids2);
}
}
$result = array();
foreach ($ids as $id) {
$result[] = $id;
}
return $result;
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
$res = $this->_query("SELECT id FROM cache");
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
$result = array();
foreach ($rows as $row) {
$id = $row['id'];
$matching = false;
foreach ($tags as $tag) {
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
if (!$res) {
return array();
}
$nbr = (int) @sqlite_fetch_single($res);
if ($nbr > 0) {
$matching = true;
}
}
if (!$matching) {
$result[] = $id;
}
}
return $result;
}
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array())
{
$first = true;
$ids = array();
foreach ($tags as $tag) {
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
if (!$res) {
return array();
}
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
$ids2 = array();
foreach ($rows as $row) {
$ids2[] = $row['id'];
}
if ($first) {
$ids = $ids2;
$first = false;
} else {
$ids = array_merge($ids, $ids2);
}
}
$result = array();
foreach ($ids as $id) {
$result[] = $id;
}
return $result;
}
/**
* Return the filling percentage of the backend storage
*
* @throws Zend_Cache_Exception
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
$dir = dirname($this->_options['cache_db_complete_path']);
$free = disk_free_space($dir);
$total = disk_total_space($dir);
if ($total == 0) {
Zend_Cache::throwException('can\'t get disk_total_space');
} else {
if ($free >= $total) {
return 100;
}
return ((int) (100. * ($total - $free) / $total));
}
}
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id)
{
$tags = array();
$res = $this->_query("SELECT name FROM tag WHERE id='$id'");
if ($res) {
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
foreach ($rows as $row) {
$tags[] = $row['name'];
}
}
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
$res = $this->_query("SELECT lastModified,expire FROM cache WHERE id='$id'");
if (!$res) {
return false;
}
$row = @sqlite_fetch_array($res, SQLITE_ASSOC);
return array(
'tags' => $tags,
'mtime' => $row['lastModified'],
'expire' => $row['expire']
);
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
$sql = "SELECT expire FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
$res = $this->_query($sql);
if (!$res) {
return false;
}
$expire = @sqlite_fetch_single($res);
$newExpire = $expire + $extraLifetime;
$res = $this->_query("UPDATE cache SET lastModified=" . time() . ", expire=$newExpire WHERE id='$id'");
if ($res) {
return true;
} else {
return false;
}
}
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities()
{
return array(
'automatic_cleaning' => true,
'tags' => true,
'expired_read' => true,
'priority' => false,
'infinite_lifetime' => true,
'get_list' => true
);
}
/**
* PUBLIC METHOD FOR UNIT TESTING ONLY !
*
* Force a cache record to expire
*
* @param string $id Cache id
*/
public function ___expire($id)
{
$time = time() - 1;
$this->_query("UPDATE cache SET lastModified=$time, expire=$time WHERE id='$id'");
}
/**
* Return the connection resource
*
* If we are not connected, the connection is made
*
* @throws Zend_Cache_Exception
* @return resource Connection resource
*/
private function _getConnection()
{
if (is_resource($this->_db)) {
return $this->_db;
} else {
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
if (!(is_resource($this->_db))) {
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
}
return $this->_db;
}
}
/**
* Execute an SQL query silently
*
* @param string $query SQL query
* @return mixed|false query results
*/
private function _query($query)
{
$db = $this->_getConnection();
if (is_resource($db)) {
$res = @sqlite_query($db, $query);
if ($res === false) {
return false;
} else {
return $res;
}
}
return false;
}
/**
* Deal with the automatic vacuum process
*
* @return void
*/
private function _automaticVacuum()
{
if ($this->_options['automatic_vacuum_factor'] > 0) {
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
if ($rand == 1) {
$this->_query('VACUUM');
@sqlite_close($this->_getConnection());
}
}
}
/**
* Register a cache id with the given tag
*
* @param string $id Cache id
* @param string $tag Tag
* @return boolean True if no problem
*/
private function _registerTag($id, $tag) {
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
if (!$res) {
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
return false;
}
return true;
}
/**
* Build the database structure
*
* @return false
*/
private function _buildStructure()
{
$this->_query('DROP INDEX tag_id_index');
$this->_query('DROP INDEX tag_name_index');
$this->_query('DROP INDEX cache_id_expire_index');
$this->_query('DROP TABLE version');
$this->_query('DROP TABLE cache');
$this->_query('DROP TABLE tag');
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
$this->_query('INSERT INTO version (num) VALUES (1)');
}
/**
* Check if the database structure is ok (with the good version)
*
* @return boolean True if ok
*/
private function _checkStructureVersion()
{
$result = $this->_query("SELECT num FROM version");
if (!$result) return false;
$row = @sqlite_fetch_array($result);
if (!$row) {
return false;
}
if (((int) $row['num']) != 1) {
// old cache structure
$this->_log('Zend_Cache_Backend_Sqlite::_checkStructureVersion() : old cache structure version detected => the cache is going to be dropped');
return false;
}
return true;
}
/**
* Clean some cache records
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @return boolean True if no problem
*/
private function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
$res1 = $this->_query('DELETE FROM cache');
$res2 = $this->_query('DELETE FROM tag');
return $res1 && $res2;
break;
case Zend_Cache::CLEANING_MODE_OLD:
$mktime = time();
$res1 = $this->_query("DELETE FROM tag WHERE id IN (SELECT id FROM cache WHERE expire>0 AND expire<=$mktime)");
$res2 = $this->_query("DELETE FROM cache WHERE expire>0 AND expire<=$mktime");
return $res1 && $res2;
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
$ids = $this->getIdsMatchingTags($tags);
$result = true;
foreach ($ids as $id) {
$result = $result && ($this->remove($id));
}
return $result;
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
$ids = $this->getIdsNotMatchingTags($tags);
$result = true;
foreach ($ids as $id) {
$result = $result && ($this->remove($id));
}
return $result;
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$ids = $this->getIdsMatchingAnyTags($tags);
$result = true;
foreach ($ids as $id) {
$result = $result && ($this->remove($id));
}
return $result;
break;
default:
break;
}
return false;
}
/**
* Check if the database structure is ok (with the good version), if no : build it
*
* @throws Zend_Cache_Exception
* @return boolean True if ok
*/
private function _checkAndBuildStructure()
{
if (!($this->_structureChecked)) {
if (!$this->_checkStructureVersion()) {
$this->_buildStructure();
if (!$this->_checkStructureVersion()) {
Zend_Cache::throwException("Impossible to build cache structure in " . $this->_options['cache_db_complete_path']);
}
}
$this->_structureChecked = true;
}
return true;
}
}
Cache/Backend/Memcached.php 0000604 00000036400 15071256135 0011461 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
/**
* Default Values
*/
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = 11211;
const DEFAULT_PERSISTENT = true;
const DEFAULT_WEIGHT = 1;
const DEFAULT_TIMEOUT = 5;//Hypothesis
const DEFAULT_RETRY_INTERVAL = 15;
const DEFAULT_STATUS = true;
/**
* Log message
*/
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
/**
* Available options
*
* =====> (array) servers :
* an array of memcached server ; each memcached server is described by an associative array :
* 'host' => (string) : the name of the memcached server
* 'port' => (int) : the port of the memcached server
* 'persistent' => (bool) : use or not persistent connections to this memcached server
*
* =====> (boolean) compression :
* true if you want to use on-the-fly compression
*
* @var array available options
*/
protected $_options = array(
'servers' => array(array(
'host' => self::DEFAULT_HOST,
'port' => self::DEFAULT_PORT,
'persistent' => self::DEFAULT_PERSISTENT,
'weight' => self::DEFAULT_WEIGHT,
'timeout' => self::DEFAULT_TIMEOUT,
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
'status' => self::DEFAULT_STATUS
)),
'compression' => false
);
/**
* Memcache object
*
* @var mixed memcache object
*/
protected $_memcache = null;
/**
* Constructor
*
* @param array $options associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
if (!extension_loaded('memcache')) {
Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
}
parent::__construct($options);
if (isset($this->_options['servers'])) {
$value= $this->_options['servers'];
if (isset($value['host'])) {
// in this case, $value seems to be a simple associative array (one server only)
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
}
$this->setOption('servers', $value);
}
$this->_memcache = new Memcache;
foreach ($this->_options['servers'] as $server) {
if (!array_key_exists('port', $server)) {
$server['port'] = self::DEFAULT_PORT;
}
if (!array_key_exists('persistent', $server)) {
$server['persistent'] = self::DEFAULT_PERSISTENT;
}
if (!array_key_exists('weight', $server)) {
$server['weight'] = self::DEFAULT_WEIGHT;
}
if (!array_key_exists('timeout', $server)) {
$server['timeout'] = self::DEFAULT_TIMEOUT;
}
if (!array_key_exists('retry_interval', $server)) {
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
}
if (!array_key_exists('status', $server)) {
$server['status'] = self::DEFAULT_STATUS;
}
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
$server['weight'], $server['timeout'],
$server['retry_interval'], $server['status']
);
}
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string|false cached datas
*/
public function load($id, $doNotTestCacheValidity = false)
{
$tmp = $this->_memcache->get($id);
if (is_array($tmp)) {
return $tmp[0];
}
return false;
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id Cache id
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$tmp = $this->_memcache->get($id);
if (is_array($tmp)) {
return $tmp[1];
}
return false;
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean True if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$lifetime = $this->getLifetime($specificLifetime);
if ($this->_options['compression']) {
$flag = MEMCACHE_COMPRESSED;
} else {
$flag = 0;
}
if ($this->test($id)) {
// because set and replace seems to have different behaviour
$result = $this->_memcache->replace($id, array($data, time(), $lifetime), $flag, $lifetime);
} else {
$result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
}
if (count($tags) > 0) {
$this->_log("Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend");
}
return $result;
}
/**
* Remove a cache record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id)
{
return $this->_memcache->delete($id);
}
/**
* Clean some cache records
*
* Available modes are :
* 'all' (default) => remove all cache entries ($tags is not used)
* 'old' => unsupported
* 'matchingTag' => unsupported
* 'notMatchingTag' => unsupported
* 'matchingAnyTag' => unsupported
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
return $this->_memcache->flush();
break;
case Zend_Cache::CLEANING_MODE_OLD:
$this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
/**
* Return true if the automatic cleaning is available for the backend
*
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return false;
}
/**
* Set the frontend directives
*
* @param array $directives Assoc of directives
* @throws Zend_Cache_Exception
* @return void
*/
public function setDirectives($directives)
{
parent::setDirectives($directives);
$lifetime = $this->getLifetime(false);
if ($lifetime > 2592000) {
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
}
if (is_null($lifetime)) {
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
parent::setDirectives(array('lifetime' => 0));
}
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
return array();
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
return array();
}
/**
* Return the filling percentage of the backend storage
*
* @throws Zend_Cache_Exception
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
$mem = $this->_memcache->getStats();
$memSize = $mem['limit_maxbytes'];
$memUsed= $mem['bytes'];
if ($memSize == 0) {
Zend_Cache::throwException('can\'t get memcache memory size');
}
if ($memUsed > $memSize) {
return 100;
}
return ((int) (100. * ($memUsed / $memSize)));
}
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id)
{
$tmp = $this->_memcache->get($id);
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
if (!isset($tmp[2])) {
// because this record is only with 1.7 release
// if old cache records are still there...
return false;
}
$lifetime = $tmp[2];
return array(
'expire' => $mtime + $lifetime,
'tags' => array(),
'mtime' => $mtime
);
}
return false;
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
if ($this->_options['compression']) {
$flag = MEMCACHE_COMPRESSED;
} else {
$flag = 0;
}
$tmp = $this->_memcache->get($id);
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
if (!isset($tmp[2])) {
// because this record is only with 1.7 release
// if old cache records are still there...
return false;
}
$lifetime = $tmp[2];
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
if ($newLifetime <=0) {
return false;
}
if ($this->test($id)) {
// because set and replace seems to have different behaviour
$result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime);
} else {
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
}
return true;
}
return false;
}
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities()
{
return array(
'automatic_cleaning' => false,
'tags' => false,
'expired_read' => false,
'priority' => false,
'infinite_lifetime' => false,
'get_list' => false
);
}
}
Cache/Backend/Apc.php 0000604 00000025564 15071256135 0010327 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
{
/**
* Log message
*/
const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend';
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend';
/**
* Constructor
*
* @param array $options associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
if (!extension_loaded('apc')) {
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
}
parent::__construct($options);
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* WARNING $doNotTestCacheValidity=true is unsupported by the Apc backend
*
* @param string $id cache id
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
* @return string cached datas (or false)
*/
public function load($id, $doNotTestCacheValidity = false)
{
$tmp = apc_fetch($id);
if (is_array($tmp)) {
return $tmp[0];
}
return false;
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id cache id
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$tmp = apc_fetch($id);
if (is_array($tmp)) {
return $tmp[1];
}
return false;
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data datas to cache
* @param string $id cache id
* @param array $tags array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$lifetime = $this->getLifetime($specificLifetime);
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
if (count($tags) > 0) {
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
}
return $result;
}
/**
* Remove a cache record
*
* @param string $id cache id
* @return boolean true if no problem
*/
public function remove($id)
{
return apc_delete($id);
}
/**
* Clean some cache records
*
* Available modes are :
* 'all' (default) => remove all cache entries ($tags is not used)
* 'old' => unsupported
* 'matchingTag' => unsupported
* 'notMatchingTag' => unsupported
* 'matchingAnyTag' => unsupported
*
* @param string $mode clean mode
* @param array $tags array of tags
* @throws Zend_Cache_Exception
* @return boolean true if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
return apc_clear_cache('user');
break;
case Zend_Cache::CLEANING_MODE_OLD:
$this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
/**
* Return true if the automatic cleaning is available for the backend
*
* DEPRECATED : use getCapabilities() instead
*
* @deprecated
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return false;
}
/**
* Return the filling percentage of the backend storage
*
* @throws Zend_Cache_Exception
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
$mem = apc_sma_info(true);
$memSize = $mem['num_seg'] * $mem['seg_size'];
$memAvailable= $mem['avail_mem'];
$memUsed = $memSize - $memAvailable;
if ($memSize == 0) {
Zend_Cache::throwException('can\'t get apc memory size');
}
if ($memUsed > $memSize) {
return 100;
}
return ((int) (100. * ($memUsed / $memSize)));
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
return array();
}
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array())
{
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
return array();
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
$res = array();
$array = apc_cache_info('user', false);
$records = $array['cache_list'];
foreach ($records as $record) {
$res[] = $record['info'];
}
return $res;
}
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id)
{
$tmp = apc_fetch($id);
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
if (!isset($tmp[2])) {
// because this record is only with 1.7 release
// if old cache records are still there...
return false;
}
$lifetime = $tmp[2];
return array(
'expire' => $mtime + $lifetime,
'tags' => array(),
'mtime' => $mtime
);
}
return false;
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
$tmp = apc_fetch($id);
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
if (!isset($tmp[2])) {
// because this record is only with 1.7 release
// if old cache records are still there...
return false;
}
$lifetime = $tmp[2];
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
if ($newLifetime <=0) {
return false;
}
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
return true;
}
return false;
}
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities()
{
return array(
'automatic_cleaning' => false,
'tags' => false,
'expired_read' => false,
'priority' => false,
'infinite_lifetime' => false,
'get_list' => true
);
}
}
Cache/Backend/Xcache.php 0000604 00000015770 15071256135 0011015 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/Interface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
{
/**
* Log message
*/
const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend';
const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend';
/**
* Available options
*
* =====> (string) user :
* xcache.admin.user (necessary for the clean() method)
*
* =====> (string) password :
* xcache.admin.pass (clear, not MD5) (necessary for the clean() method)
*
* @var array available options
*/
protected $_options = array(
'user' => null,
'password' => null
);
/**
* Constructor
*
* @param array $options associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
if (!extension_loaded('xcache')) {
Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
}
parent::__construct($options);
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend
*
* @param string $id cache id
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
* @return string cached datas (or false)
*/
public function load($id, $doNotTestCacheValidity = false)
{
if ($doNotTestCacheValidity) {
$this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend");
}
$tmp = xcache_get($id);
if (is_array($tmp)) {
return $tmp[0];
}
return false;
}
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id cache id
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
if (xcache_isset($id)) {
$tmp = xcache_get($id);
if (is_array($tmp)) {
return $tmp[1];
}
}
return false;
}
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data datas to cache
* @param string $id cache id
* @param array $tags array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$lifetime = $this->getLifetime($specificLifetime);
$result = xcache_set($id, array($data, time()), $lifetime);
if (count($tags) > 0) {
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND);
}
return $result;
}
/**
* Remove a cache record
*
* @param string $id cache id
* @return boolean true if no problem
*/
public function remove($id)
{
return xcache_unset($id);
}
/**
* Clean some cache records
*
* Available modes are :
* 'all' (default) => remove all cache entries ($tags is not used)
* 'old' => unsupported
* 'matchingTag' => unsupported
* 'notMatchingTag' => unsupported
* 'matchingAnyTag' => unsupported
*
* @param string $mode clean mode
* @param array $tags array of tags
* @throws Zend_Cache_Exception
* @return boolean true if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
// Necessary because xcache_clear_cache() need basic authentification
$backup = array();
if (isset($_SERVER['PHP_AUTH_USER'])) {
$backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
}
if ($this->_options['user']) {
$_SERVER['PHP_AUTH_USER'] = $this->_options['user'];
}
if ($this->_options['password']) {
$_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
}
xcache_clear_cache(XC_TYPE_VAR, 0);
if (isset($backup['PHP_AUTH_USER'])) {
$_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
$_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
}
return true;
break;
case Zend_Cache::CLEANING_MODE_OLD:
$this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend");
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND);
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method');
break;
}
}
/**
* Return true if the automatic cleaning is available for the backend
*
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return false;
}
}
Cache/Backend/Interface.php 0000604 00000007373 15071256135 0011522 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Cache_Backend_Interface
{
/**
* Set the frontend directives
*
* @param array $directives assoc of directives
*/
public function setDirectives($directives);
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* Note : return value is always "string" (unserialization is done by the core not by the backend)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string|false cached datas
*/
public function load($id, $doNotTestCacheValidity = false);
/**
* Test if a cache is available or not (for the given id)
*
* @param string $id cache id
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id);
/**
* Save some string datas into a cache record
*
* Note : $data is always "string" (serialization is done by the
* core not by the backend)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean true if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false);
/**
* Remove a cache record
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id);
/**
* Clean some cache records
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @return boolean true if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array());
}
Cache/Backend/Test.php 0000604 00000017122 15071256135 0010532 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/Interface.php';
/**
* @see Zend_Cache_Backend
*/
require_once 'Zend/Cache/Backend.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
{
/**
* Available options
*
* @var array available options
*/
protected $_options = array();
/**
* Frontend or Core directives
*
* @var array directives
*/
protected $_directives = array();
/**
* Array to log actions
*
* @var array $_log
*/
private $_log = array();
/**
* Current index for log array
*
* @var int $_index
*/
private $_index = 0;
/**
* Constructor
*
* @param array $options associative array of options
* @return void
*/
public function __construct($options = array())
{
$this->_addLog('construct', array($options));
}
/**
* Set the frontend directives
*
* @param array $directives assoc of directives
* @return void
*/
public function setDirectives($directives)
{
$this->_addLog('setDirectives', array($directives));
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* For this test backend only, if $id == 'false', then the method will return false
* if $id == 'serialized', the method will return a serialized array
* ('foo' else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @return string Cached datas (or false)
*/
public function load($id, $doNotTestCacheValidity = false)
{
$this->_addLog('get', array($id, $doNotTestCacheValidity));
if ($id=='false') {
return false;
}
if ($id=='serialized') {
return serialize(array('foo'));
}
if ($id=='serialized2') {
return serialize(array('headers' => array(), 'data' => 'foo'));
}
if (($id=='71769f39054f75894288e397df04e445') or ($id=='615d222619fb20b527168340cebd0578')) {
return serialize(array('foo', 'bar'));
}
if (($id=='8a02d218a5165c467e7a5747cc6bd4b6') or ($id=='648aca1366211d17cbf48e65dc570bee')) {
return serialize(array('foo', 'bar'));
}
return 'foo';
}
/**
* Test if a cache is available or not (for the given id)
*
* For this test backend only, if $id == 'false', then the method will return false
* (123456 else)
*
* @param string $id Cache id
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
*/
public function test($id)
{
$this->_addLog('test', array($id));
if ($id=='false') {
return false;
}
if (($id=='d8523b3ee441006261eeffa5c3d3a0a7') or ($id=='3c439c922209e2cb0b54d6deffccd75a')) {
return false;
}
if (($id=='40f649b94977c0a6e76902e2a0b43587') or ($id=='e83249ea22178277d5befc2c5e2e9ace')) {
return false;
}
return 123456;
}
/**
* Save some string datas into a cache record
*
* For this test backend only, if $id == 'false', then the method will return false
* (true else)
*
* @param string $data Datas to cache
* @param string $id Cache id
* @param array $tags Array of strings, the cache record will be tagged by each string entry
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @return boolean True if no problem
*/
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$this->_addLog('save', array($data, $id, $tags));
if ($id=='false') {
return false;
}
return true;
}
/**
* Remove a cache record
*
* For this test backend only, if $id == 'false', then the method will return false
* (true else)
*
* @param string $id Cache id
* @return boolean True if no problem
*/
public function remove($id)
{
$this->_addLog('remove', array($id));
if ($id=='false') {
return false;
}
return true;
}
/**
* Clean some cache records
*
* For this test backend only, if $mode == 'false', then the method will return false
* (true else)
*
* Available modes are :
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
* ($tags can be an array of strings or a single string)
*
* @param string $mode Clean mode
* @param array $tags Array of tags
* @return boolean True if no problem
*/
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
$this->_addLog('clean', array($mode, $tags));
if ($mode=='false') {
return false;
}
return true;
}
/**
* Get the last log
*
* @return string The last log
*/
public function getLastLog()
{
return $this->_log[$this->_index - 1];
}
/**
* Get the log index
*
* @return int Log index
*/
public function getLogIndex()
{
return $this->_index;
}
/**
* Get the complete log array
*
* @return array Complete log array
*/
public function getAllLogs()
{
return $this->_log;
}
/**
* Return true if the automatic cleaning is available for the backend
*
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return true;
}
/**
* Add an event to the log array
*
* @param string $methodName MethodName
* @param array $args Arguments
* @return void
*/
private function _addLog($methodName, $args)
{
$this->_log[$this->_index] = array(
'methodName' => $methodName,
'args' => $args
);
$this->_index = $this->_index + 1;
}
}
Cache/Backend/ExtendedInterface.php 0000604 00000007626 15071256135 0013204 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @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 Zend_Cache_Backend_Interface
*/
require_once 'Zend/Cache/Backend/Interface.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
{
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds();
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags();
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array());
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array());
/**
* Return an array of stored cache ids which match any given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of any matching cache ids (string)
*/
public function getIdsMatchingAnyTags($tags = array());
/**
* Return the filling percentage of the backend storage
*
* @return int integer between 0 and 100
*/
public function getFillingPercentage();
/**
* Return an array of metadatas for the given cache id
*
* The array must include these keys :
* - expire : the expire timestamp
* - tags : a string array of tags
* - mtime : timestamp of last modification time
*
* @param string $id cache id
* @return array array of metadatas (false if the cache id is not found)
*/
public function getMetadatas($id);
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime);
/**
* Return an associative array of capabilities (booleans) of the backend
*
* The array must include these keys :
* - automatic_cleaning (is automating cleaning necessary)
* - tags (are tags supported)
* - expired_read (is it possible to read expired cache records
* (for doNotTestCacheValidity option for example))
* - priority does the backend deal with priority when saving
* - infinite_lifetime (is infinite lifetime can work with this backend)
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
*
* @return array associative of with capabilities
*/
public function getCapabilities();
}
Cache/Frontend/Function.php 0000604 00000010601 15071256135 0011623 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Frontend
* @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 Zend_Cache_Core
*/
require_once 'Zend/Cache/Core.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Frontend
* @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_Cache_Frontend_Function extends Zend_Cache_Core
{
/**
* This frontend specific options
*
* ====> (boolean) cache_by_default :
* - if true, function calls will be cached by default
*
* ====> (array) cached_functions :
* - an array of function names which will be cached (even if cache_by_default = false)
*
* ====> (array) non_cached_functions :
* - an array of function names which won't be cached (even if cache_by_default = true)
*
* @var array options
*/
protected $_specificOptions = array(
'cache_by_default' => true,
'cached_functions' => array(),
'non_cached_functions' => array()
);
/**
* Constructor
*
* @param array $options Associative array of options
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$this->setOption($name, $value);
}
$this->setOption('automatic_serialization', true);
}
/**
* Main method : call the specified function or get the result from cache
*
* @param string $name Function name
* @param array $parameters Function parameters
* @param array $tags Cache tags
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
* @return mixed Result
*/
public function call($name, $parameters = array(), $tags = array(), $specificLifetime = false, $priority = 8)
{
$cacheBool1 = $this->_specificOptions['cache_by_default'];
$cacheBool2 = in_array($name, $this->_specificOptions['cached_functions']);
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_functions']);
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
if (!$cache) {
// We do not have not cache
return call_user_func_array($name, $parameters);
}
$id = $this->_makeId($name, $parameters);
if ($this->test($id)) {
// A cache is available
$result = $this->load($id);
$output = $result[0];
$return = $result[1];
} else {
// A cache is not available
ob_start();
ob_implicit_flush(false);
$return = call_user_func_array($name, $parameters);
$output = ob_get_contents();
ob_end_clean();
$data = array($output, $return);
$this->save($data, $id, $tags, $specificLifetime, $priority);
}
echo $output;
return $return;
}
/**
* Make a cache id from the function name and parameters
*
* @param string $name Function name
* @param array $parameters Function parameters
* @throws Zend_Cache_Exception
* @return string Cache id
*/
private function _makeId($name, $parameters)
{
if (!is_string($name)) {
Zend_Cache::throwException('Incorrect function name');
}
if (!is_array($parameters)) {
Zend_Cache::throwException('parameters argument must be an array');
}
return md5($name . serialize($parameters));
}
}
Cache/Frontend/Class.php 0000604 00000016076 15071256135 0011117 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Frontend
* @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 Zend_Cache_Core
*/
require_once 'Zend/Cache/Core.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Frontend
* @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_Cache_Frontend_Class extends Zend_Cache_Core
{
/**
* Available options
*
* ====> (mixed) cached_entity :
* - if set to a class name, we will cache an abstract class and will use only static calls
* - if set to an object, we will cache this object methods
*
* ====> (boolean) cache_by_default :
* - if true, method calls will be cached by default
*
* ====> (array) cached_methods :
* - an array of method names which will be cached (even if cache_by_default = false)
*
* ====> (array) non_cached_methods :
* - an array of method names which won't be cached (even if cache_by_default = true)
*
* @var array available options
*/
protected $_specificOptions = array(
'cached_entity' => null,
'cache_by_default' => true,
'cached_methods' => array(),
'non_cached_methods' => array()
);
/**
* Tags array
*
* @var array
*/
private $_tags = array();
/**
* SpecificLifetime value
*
* false => no specific life time
*
* @var int
*/
private $_specificLifetime = false;
/**
* The cached object or the name of the cached abstract class
*
* @var mixed
*/
private $_cachedEntity = null;
/**
* The class name of the cached object or cached abstract class
*
* Used to differentiate between different classes with the same method calls.
*
* @var string
*/
private $_cachedEntityLabel = '';
/**
* Priority (used by some particular backends)
*
* @var int
*/
private $_priority = 8;
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$this->setOption($name, $value);
}
if (is_null($this->_specificOptions['cached_entity'])) {
Zend_Cache::throwException('cached_entity must be set !');
}
$this->setCachedEntity($this->_specificOptions['cached_entity']);
$this->setOption('automatic_serialization', true);
}
/**
* Set a specific life time
*
* @param int $specificLifetime
* @return void
*/
public function setSpecificLifetime($specificLifetime = false)
{
$this->_specificLifetime = $specificLifetime;
}
/**
* Set the priority (used by some particular backends)
*
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority)
*/
public function setPriority($priority)
{
$this->_priority = $priority;
}
/**
* Public frontend to set an option
*
* Just a wrapper to get a specific behaviour for cached_entity
*
* @param string $name Name of the option
* @param mixed $value Value of the option
* @throws Zend_Cache_Exception
* @return void
*/
public function setOption($name, $value)
{
if ($name == 'cached_entity') {
$this->setCachedEntity($value);
} else {
parent::setOption($name, $value);
}
}
/**
* Specific method to set the cachedEntity
*
* if set to a class name, we will cache an abstract class and will use only static calls
* if set to an object, we will cache this object methods
*
* @param mixed $cachedEntity
*/
public function setCachedEntity($cachedEntity)
{
if (!is_string($cachedEntity) && !is_object($cachedEntity)) {
Zend_Cache::throwException('cached_entity must be an object or a class name');
}
$this->_cachedEntity = $cachedEntity;
$this->_specificOptions['cached_entity'] = $cachedEntity;
if (is_string($this->_cachedEntity)){
$this->_cachedEntityLabel = $this->_cachedEntity;
} else {
$ro = new ReflectionObject($this->_cachedEntity);
$this->_cachedEntityLabel = $ro->getName();
}
}
/**
* Set the cache array
*
* @param array $tags
* @return void
*/
public function setTagsArray($tags = array())
{
$this->_tags = $tags;
}
/**
* Main method : call the specified method or get the result from cache
*
* @param string $name Method name
* @param array $parameters Method parameters
* @return mixed Result
*/
public function __call($name, $parameters)
{
$cacheBool1 = $this->_specificOptions['cache_by_default'];
$cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']);
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']);
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
if (!$cache) {
// We do not have not cache
return call_user_func_array(array($this->_cachedEntity, $name), $parameters);
}
$id = $this->_makeId($name, $parameters);
if ($this->test($id)) {
// A cache is available
$result = $this->load($id);
$output = $result[0];
$return = $result[1];
} else {
// A cache is not available
ob_start();
ob_implicit_flush(false);
$return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
$output = ob_get_contents();
ob_end_clean();
$data = array($output, $return);
$this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);
}
echo $output;
return $return;
}
/**
* Make a cache id from the method name and parameters
*
* @param string $name Method name
* @param array $parameters Method parameters
* @return string Cache id
*/
private function _makeId($name, $parameters)
{
return md5($this->_cachedEntityLabel . '__' . $name . '__' . serialize($parameters));
}
}
Cache/Frontend/Page.php 0000604 00000033524 15071256135 0010723 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Frontend
* @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 Zend_Cache_Core
*/
require_once 'Zend/Cache/Core.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Frontend
* @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_Cache_Frontend_Page extends Zend_Cache_Core
{
/**
* This frontend specific options
*
* ====> (boolean) http_conditional :
* - if true, http conditional mode is on
* WARNING : http_conditional OPTION IS NOT IMPLEMENTED FOR THE MOMENT (TODO)
*
* ====> (boolean) debug_header :
* - if true, a debug text is added before each cached pages
*
* ====> (boolean) content_type_memorization :
* - deprecated => use memorize_headers instead
* - if the Content-Type header is sent after the cache was started, the
* corresponding value can be memorized and replayed when the cache is hit
* (if false (default), the frontend doesn't take care of Content-Type header)
*
* ====> (array) memorize_headers :
* - an array of strings corresponding to some HTTP headers name. Listed headers
* will be stored with cache datas and "replayed" when the cache is hit
*
* ====> (array) default_options :
* - an associative array of default options :
* - (boolean) cache : cache is on by default if true
* - (boolean) cacheWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
* if true, cache is still on even if there are some variables in this superglobal array
* if false, cache is off if there are some variables in this superglobal array
* - (boolean) makeIdWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
* if true, we have to use the content of this superglobal array to make a cache id
* if false, the cache id won't be dependent of the content of this superglobal array
* - (int) specific_lifetime : cache specific lifetime
* (false => global lifetime is used, null => infinite lifetime,
* integer => this lifetime is used), this "lifetime" is probably only
* usefull when used with "regexps" array
* - (array) tags : array of tags (strings)
* - (int) priority : integer between 0 (very low priority) and 10 (maximum priority) used by
* some particular backends
*
* ====> (array) regexps :
* - an associative array to set options only for some REQUEST_URI
* - keys are (pcre) regexps
* - values are associative array with specific options to set if the regexp matchs on $_SERVER['REQUEST_URI']
* (see default_options for the list of available options)
* - if several regexps match the $_SERVER['REQUEST_URI'], only the last one will be used
*
* @var array options
*/
protected $_specificOptions = array(
'http_conditional' => false,
'debug_header' => false,
'content_type_memorization' => false,
'memorize_headers' => array(),
'default_options' => array(
'cache_with_get_variables' => false,
'cache_with_post_variables' => false,
'cache_with_session_variables' => false,
'cache_with_files_variables' => false,
'cache_with_cookie_variables' => false,
'make_id_with_get_variables' => true,
'make_id_with_post_variables' => true,
'make_id_with_session_variables' => true,
'make_id_with_files_variables' => true,
'make_id_with_cookie_variables' => true,
'cache' => true,
'specific_lifetime' => false,
'tags' => array(),
'priority' => null
),
'regexps' => array()
);
/**
* Internal array to store some options
*
* @var array associative array of options
*/
protected $_activeOptions = array();
/**
* If true, the page won't be cached
*
* @var boolean
*/
private $_cancel = false;
/**
* Constructor
*
* @param array $options Associative array of options
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$name = strtolower($name);
switch ($name) {
case 'regexps':
$this->_setRegexps($value);
break;
case 'default_options':
$this->_setDefaultOptions($value);
break;
case 'content_type_memorization':
$this->_setContentTypeMemorization($value);
break;
default:
$this->setOption($name, $value);
}
}
if (isset($this->_specificOptions['http_conditional'])) {
if ($this->_specificOptions['http_conditional']) {
Zend_Cache::throwException('http_conditional is not implemented for the moment !');
}
}
$this->setOption('automatic_serialization', true);
}
/**
* Specific setter for the 'default_options' option (with some additional tests)
*
* @param array $options Associative array
* @throws Zend_Cache_Exception
* @return void
*/
protected function _setDefaultOptions($options)
{
if (!is_array($options)) {
Zend_Cache::throwException('default_options must be an array !');
}
foreach ($options as $key=>$value) {
if (!is_string($key)) {
Zend_Cache::throwException("invalid option [$key] !");
}
$key = strtolower($key);
if (isset($this->_specificOptions['default_options'][$key])) {
$this->_specificOptions['default_options'][$key] = $value;
}
}
}
/**
* Set the deprecated contentTypeMemorization option
*
* @param boolean $value value
* @return void
* @deprecated
*/
protected function _setContentTypeMemorization($value)
{
$found = null;
foreach ($this->_specificOptions['memorize_headers'] as $key => $value) {
if (strtolower($value) == 'content-type') {
$found = $key;
}
}
if ($value) {
if (!$found) {
$this->_specificOptions['memorize_headers'][] = 'Content-Type';
}
} else {
if ($found) {
unset($this->_specificOptions['memorize_headers'][$found]);
}
}
}
/**
* Specific setter for the 'regexps' option (with some additional tests)
*
* @param array $options Associative array
* @throws Zend_Cache_Exception
* @return void
*/
protected function _setRegexps($regexps)
{
if (!is_array($regexps)) {
Zend_Cache::throwException('regexps option must be an array !');
}
foreach ($regexps as $regexp=>$conf) {
if (!is_array($conf)) {
Zend_Cache::throwException('regexps option must be an array of arrays !');
}
$validKeys = array_keys($this->_specificOptions['default_options']);
foreach ($conf as $key=>$value) {
if (!is_string($key)) {
Zend_Cache::throwException("unknown option [$key] !");
}
$key = strtolower($key);
if (!in_array($key, $validKeys)) {
unset($regexps[$regexp][$key]);
}
}
}
$this->setOption('regexps', $regexps);
}
/**
* Start the cache
*
* @param string $id (optional) A cache id (if you set a value here, maybe you have to use Output frontend instead)
* @param boolean $doNotDie For unit testing only !
* @return boolean True if the cache is hit (false else)
*/
public function start($id = false, $doNotDie = false)
{
$this->_cancel = false;
$lastMatchingRegexp = null;
foreach ($this->_specificOptions['regexps'] as $regexp => $conf) {
if (preg_match("`$regexp`", $_SERVER['REQUEST_URI'])) {
$lastMatchingRegexp = $regexp;
}
}
$this->_activeOptions = $this->_specificOptions['default_options'];
if (!is_null($lastMatchingRegexp)) {
$conf = $this->_specificOptions['regexps'][$lastMatchingRegexp];
foreach ($conf as $key=>$value) {
$this->_activeOptions[$key] = $value;
}
}
if (!($this->_activeOptions['cache'])) {
return false;
}
if (!$id) {
$id = $this->_makeId();
if (!$id) {
return false;
}
}
$array = $this->load($id);
if ($array !== false) {
$data = $array['data'];
$headers = $array['headers'];
if ($this->_specificOptions['debug_header']) {
echo 'DEBUG HEADER : This is a cached page !';
}
if (!headers_sent()) {
foreach ($headers as $key=>$headerCouple) {
$name = $headerCouple[0];
$value = $headerCouple[1];
header("$name: $value");
}
}
echo $data;
if ($doNotDie) {
return true;
}
die();
}
ob_start(array($this, '_flush'));
ob_implicit_flush(false);
return false;
}
/**
* Cancel the current caching process
*/
public function cancel()
{
$this->_cancel = true;
}
/**
* callback for output buffering
* (shouldn't really be called manually)
*
* @param string $data Buffered output
* @return string Data to send to browser
*/
public function _flush($data)
{
if ($this->_cancel) {
return $data;
}
$contentType = null;
$storedHeaders = array();
$headersList = headers_list();
foreach($this->_specificOptions['memorize_headers'] as $key=>$headerName) {
foreach ($headersList as $headerSent) {
$tmp = split(':', $headerSent);
$headerSentName = trim(array_shift($tmp));
if (strtolower($headerName) == strtolower($headerSentName)) {
$headerSentValue = trim(implode(':', $tmp));
$storedHeaders[] = array($headerSentName, $headerSentValue);
}
}
}
$array = array(
'data' => $data,
'headers' => $storedHeaders
);
$this->save($array, null, $this->_activeOptions['tags'], $this->_activeOptions['specific_lifetime'], $this->_activeOptions['priority']);
return $data;
}
/**
* Make an id depending on REQUEST_URI and superglobal arrays (depending on options)
*
* @return mixed|false a cache id (string), false if the cache should have not to be used
*/
protected function _makeId()
{
$tmp = $_SERVER['REQUEST_URI'];
foreach (array('Get', 'Post', 'Session', 'Files', 'Cookie') as $arrayName) {
$tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']);
if ($tmp2===false) {
return false;
}
$tmp = $tmp . $tmp2;
}
return md5($tmp);
}
/**
* Make a partial id depending on options
*
* @param string $arrayName Superglobal array name
* @param bool $bool1 If true, cache is still on even if there are some variables in the superglobal array
* @param bool $bool2 If true, we have to use the content of the superglobal array to make a partial id
* @return mixed|false Partial id (string) or false if the cache should have not to be used
*/
protected function _makePartialId($arrayName, $bool1, $bool2)
{
switch ($arrayName) {
case 'Get':
$var = $_GET;
break;
case 'Post':
$var = $_POST;
break;
case 'Session':
if (isset($_SESSION)) {
$var = $_SESSION;
} else {
$var = null;
}
break;
case 'Cookie':
if (isset($_COOKIE)) {
$var = $_COOKIE;
} else {
$var = null;
}
break;
case 'Files':
$var = $_FILES;
break;
default:
return false;
}
if ($bool1) {
if ($bool2) {
return serialize($var);
}
return '';
}
if (count($var) > 0) {
return false;
}
return '';
}
}
Cache/Frontend/File.php 0000604 00000010166 15071256135 0010723 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Frontend
* @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 Zend_Cache_Core
*/
require_once 'Zend/Cache/Core.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Frontend
* @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_Cache_Frontend_File extends Zend_Cache_Core
{
/**
* Available options
*
* ====> (string) master_file :
* - the complete path and name of the master file
* - this option has to be set !
*
* @var array available options
*/
protected $_specificOptions = array(
'master_file' => ''
);
/**
* Master file mtime
*
* @var int
*/
private $_masterFile_mtime = null;
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$this->setOption($name, $value);
}
if (!isset($this->_specificOptions['master_file'])) {
Zend_Cache::throwException('master_file option must be set');
}
$this->setMasterFile($this->_specificOptions['master_file']);
}
/**
* Change the master_file option
*
* @param string $masterFile the complete path and name of the master file
*/
public function setMasterFile($masterFile)
{
clearstatcache();
$this->_specificOptions['master_file'] = $masterFile;
if (!($this->_masterFile_mtime = @filemtime($masterFile))) {
Zend_Cache::throwException('Unable to read master_file : '.$masterFile);
}
}
/**
* Public frontend to set an option
*
* Just a wrapper to get a specific behaviour for master_file
*
* @param string $name Name of the option
* @param mixed $value Value of the option
* @throws Zend_Cache_Exception
* @return void
*/
public function setOption($name, $value)
{
if ($name == 'master_file') {
$this->setMasterFile($value);
} else {
parent::setOption($name, $value);
}
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
* @return mixed|false Cached datas
*/
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
{
if (!$doNotTestCacheValidity) {
if ($this->test($id)) {
return parent::load($id, true, $doNotUnserialize);
}
return false;
}
return parent::load($id, true, $doNotUnserialize);
}
/**
* Test if a cache is available for the given id
*
* @param string $id Cache id
* @return boolean True is a cache is available, false else
*/
public function test($id)
{
$lastModified = parent::test($id);
if ($lastModified) {
if ($lastModified > $this->_masterFile_mtime) {
return $lastModified;
}
}
return false;
}
}
Cache/Frontend/Output.php 0000604 00000006551 15071256135 0011347 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Frontend
* @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 Zend_Cache_Core
*/
require_once 'Zend/Cache/Core.php';
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Frontend
* @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_Cache_Frontend_Output extends Zend_Cache_Core
{
private $_idStack = array();
/**
* Constructor
*
* @param array $options Associative array of options
* @return void
*/
public function __construct(array $options = array())
{
parent::__construct($options);
$this->_idStack = array();
}
/**
* Start the cache
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simpy returned else)
* @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
*/
public function start($id, $doNotTestCacheValidity = false, $echoData = true)
{
$data = $this->load($id, $doNotTestCacheValidity);
if ($data !== false) {
if ( $echoData ) {
echo($data);
return true;
} else {
return $data;
}
}
ob_start();
ob_implicit_flush(false);
$this->_idStack[] = $id;
return false;
}
/**
* Stop the cache
*
* @param array $tags Tags array
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @param string $forcedDatas If not null, force written datas with this
* @param boolean $echoData If set to true, datas are sent to the browser
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
* @return void
*/
public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
{
if (is_null($forcedDatas)) {
$data = ob_get_contents();
ob_end_clean();
} else {
$data =& $forcedDatas;
}
$id = array_pop($this->_idStack);
if (is_null($id)) {
Zend_Cache::throwException('use of end() without a start()');
}
$this->save($data, $id, $tags, $specificLifetime, $priority);
if ($echoData) {
echo($data);
}
}
}
Cache/Exception.php 0000604 00000001746 15071256135 0010227 0 ustar 00 <?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_Cache
* @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 Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @package Zend_Cache
* @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_Cache_Exception extends Zend_Exception {}
Cache/Backend.php 0000604 00000014371 15071256135 0007616 0 ustar 00 <?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_Cache
* @subpackage Zend_Cache_Backend
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @package Zend_Cache
* @subpackage Zend_Cache_Backend
* @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_Cache_Backend
{
/**
* Frontend or Core directives
*
* =====> (int) lifetime :
* - Cache lifetime (in seconds)
* - If null, the cache is valid forever
*
* =====> (int) logging :
* - if set to true, a logging is activated throw Zend_Log
*
* @var array directives
*/
protected $_directives = array(
'lifetime' => 3600,
'logging' => false,
'logger' => null
);
/**
* Available options
*
* @var array available options
*/
protected $_options = array();
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$this->setOption($name, $value);
}
}
/**
* Set the frontend directives
*
* @param array $directives Assoc of directives
* @throws Zend_Cache_Exception
* @return void
*/
public function setDirectives($directives)
{
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
while (list($name, $value) = each($directives)) {
if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name");
}
$name = strtolower($name);
if (array_key_exists($name, $this->_directives)) {
$this->_directives[$name] = $value;
}
}
$this->_loggerSanity();
}
/**
* Set an option
*
* @param string $name
* @param mixed $value
* @throws Zend_Cache_Exception
* @return void
*/
public function setOption($name, $value)
{
if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name");
}
$name = strtolower($name);
if (array_key_exists($name, $this->_options)) {
$this->_options[$name] = $value;
}
}
/**
* Get the life time
*
* if $specificLifetime is not false, the given specific life time is used
* else, the global lifetime is used
*
* @param int $specificLifetime
* @return int Cache life time
*/
public function getLifetime($specificLifetime)
{
if ($specificLifetime === false) {
return $this->_directives['lifetime'];
}
return $specificLifetime;
}
/**
* Return true if the automatic cleaning is available for the backend
*
* DEPRECATED : use getCapabilities() instead
*
* @deprecated
* @return boolean
*/
public function isAutomaticCleaningAvailable()
{
return true;
}
/**
* Return a system-wide tmp directory
*
* @return string System-wide tmp directory
*/
static function getTmpDir()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// windows...
foreach (array($_ENV, $_SERVER) as $tab) {
foreach (array('TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
if (isset($tab[$key])) {
$result = $tab[$key];
if (($key == 'windir') or ($key == 'SystemRoot')) {
$result = $result . '\\temp';
}
return $result;
}
}
}
return '\\temp';
} else {
// unix...
if (isset($_ENV['TMPDIR'])) return $_ENV['TMPDIR'];
if (isset($_SERVER['TMPDIR'])) return $_SERVER['TMPDIR'];
return '/tmp';
}
}
/**
* Make sure if we enable logging that the Zend_Log class
* is available.
* Create a default log object if none is set.
*
* @throws Zend_Cache_Exception
* @return void
*/
protected function _loggerSanity()
{
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
return;
}
try {
/**
* @see Zend_Log
*/
require_once 'Zend/Log.php';
} catch (Zend_Exception $e) {
Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available');
}
if (isset($this->_directives['logger']) && $this->_directives['logger'] instanceof Zend_Log) {
return;
}
// Create a default logger to the standard output stream
require_once 'Zend/Log/Writer/Stream.php';
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
$this->_directives['logger'] = $logger;
}
/**
* Log a message at the WARN (4) priority.
*
* @param string $message
* @throws Zend_Cache_Exception
* @return void
*/
protected function _log($message, $priority = 4)
{
if (!$this->_directives['logging']) {
return;
}
if (!(isset($this->_directives['logger']) || $this->_directives['logger'] instanceof Zend_Log)) {
Zend_Cache::throwException('Logging is enabled but logger is not set');
}
$logger = $this->_directives['logger'];
$logger->log($message, $priority);
}
}
Cache/Core.php 0000604 00000052603 15071256135 0007157 0 ustar 00 <?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_Cache
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @package Zend_Cache
* @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_Cache_Core
{
/**
* Backend Object
*
* @var object $_backend
*/
protected $_backend = null;
/**
* Available options
*
* ====> (boolean) write_control :
* - Enable / disable write control (the cache is read just after writing to detect corrupt entries)
* - Enable write control will lightly slow the cache writing but not the cache reading
* Write control can detect some corrupt cache files but maybe it's not a perfect control
*
* ====> (boolean) caching :
* - Enable / disable caching
* (can be very useful for the debug of cached scripts)
*
* =====> (string) cache_id_prefix :
* - prefix for cache ids (namespace)
*
* ====> (boolean) automatic_serialization :
* - Enable / disable automatic serialization
* - It can be used to save directly datas which aren't strings (but it's slower)
*
* ====> (int) automatic_cleaning_factor :
* - Disable / Tune the automatic cleaning process
* - The automatic cleaning process destroy too old (for the given life time)
* cache files when a new cache file is written :
* 0 => no automatic cache cleaning
* 1 => systematic cache cleaning
* x (integer) > 1 => automatic cleaning randomly 1 times on x cache write
*
* ====> (int) lifetime :
* - Cache lifetime (in seconds)
* - If null, the cache is valid forever.
*
* ====> (boolean) logging :
* - If set to true, logging is activated (but the system is slower)
*
* ====> (boolean) ignore_user_abort
* - If set to true, the core will set the ignore_user_abort PHP flag inside the
* save() method to avoid cache corruptions in some cases (default false)
*
* @var array $_options available options
*/
protected $_options = array(
'write_control' => true,
'caching' => true,
'cache_id_prefix' => null,
'automatic_serialization' => false,
'automatic_cleaning_factor' => 10,
'lifetime' => 3600,
'logging' => false,
'logger' => null,
'ignore_user_abort' => false
);
/**
* Array of options which have to be transfered to backend
*
* @var array $_directivesList
*/
protected static $_directivesList = array('lifetime', 'logging', 'logger');
/**
* Not used for the core, just a sort a hint to get a common setOption() method (for the core and for frontends)
*
* @var array $_specificOptions
*/
protected $_specificOptions = array();
/**
* Last used cache id
*
* @var string $_lastId
*/
private $_lastId = null;
/**
* True if the backend implements Zend_Cache_Backend_ExtendedInterface
*
* @var boolean $_extendedBackend
*/
protected $_extendedBackend = false;
/**
* Array of capabilities of the backend (only if it implements Zend_Cache_Backend_ExtendedInterface)
*
* @var array
*/
protected $_backendCapabilities = array();
/**
* Constructor
*
* @param array $options Associative array of options
* @throws Zend_Cache_Exception
* @return void
*/
public function __construct(array $options = array())
{
while (list($name, $value) = each($options)) {
$this->setOption($name, $value);
}
$this->_loggerSanity();
}
/**
* Set the backend
*
* @param object $backendObject
* @throws Zend_Cache_Exception
* @return void
*/
public function setBackend(Zend_Cache_Backend $backendObject)
{
$this->_backend= $backendObject;
// some options (listed in $_directivesList) have to be given
// to the backend too (even if they are not "backend specific")
$directives = array();
foreach (Zend_Cache_Core::$_directivesList as $directive) {
$directives[$directive] = $this->_options[$directive];
}
$this->_backend->setDirectives($directives);
if (in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_backend))) {
$this->_extendedBackend = true;
$this->_backendCapabilities = $this->_backend->getCapabilities();
}
}
/**
* Returns the backend
*
* @return object backend object
*/
public function getBackend()
{
return $this->_backend;
}
/**
* Public frontend to set an option
*
* There is an additional validation (relatively to the protected _setOption method)
*
* @param string $name Name of the option
* @param mixed $value Value of the option
* @throws Zend_Cache_Exception
* @return void
*/
public function setOption($name, $value)
{
if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name");
}
$name = strtolower($name);
if (array_key_exists($name, $this->_options)) {
// This is a Core option
$this->_setOption($name, $value);
return;
}
if (array_key_exists($name, $this->_specificOptions)) {
// This a specic option of this frontend
$this->_specificOptions[$name] = $value;
return;
}
}
/**
* Public frontend to get an option value
*
* @param string $name Name of the option
* @throws Zend_Cache_Exception
* @return mixed option value
*/
public function getOption($name)
{
if (is_string($name)) {
$name = strtolower($name);
if (array_key_exists($name, $this->_options)) {
// This is a Core option
return $this->_options[$name];
}
if (array_key_exists($name, $this->_specificOptions)) {
// This a specic option of this frontend
return $this->_specificOptions[$name];
}
}
Zend_Cache::throwException("Incorrect option name : $name");
}
/**
* Set an option
*
* @param string $name Name of the option
* @param mixed $value Value of the option
* @throws Zend_Cache_Exception
* @return void
*/
private function _setOption($name, $value)
{
if (!is_string($name) || !array_key_exists($name, $this->_options)) {
Zend_Cache::throwException("Incorrect option name : $name");
}
$this->_options[$name] = $value;
}
/**
* Force a new lifetime
*
* The new value is set for the core/frontend but for the backend too (directive)
*
* @param int $newLifetime New lifetime (in seconds)
* @return void
*/
public function setLifetime($newLifetime)
{
$this->_options['lifetime'] = $newLifetime;
$this->_backend->setDirectives(array(
'lifetime' => $newLifetime
));
}
/**
* Test if a cache is available for the given id and (if yes) return it (false else)
*
* @param string $id Cache id
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
* @return mixed|false Cached datas
*/
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
{
if (!$this->_options['caching']) {
return false;
}
$id = $this->_id($id); // cache id may need prefix
$this->_lastId = $id;
self::_validateIdOrTag($id);
$data = $this->_backend->load($id, $doNotTestCacheValidity);
if ($data===false) {
// no cache available
return false;
}
if ((!$doNotUnserialize) && $this->_options['automatic_serialization']) {
// we need to unserialize before sending the result
return unserialize($data);
}
return $data;
}
/**
* Test if a cache is available for the given id
*
* @param string $id Cache id
* @return boolean True is a cache is available, false else
*/
public function test($id)
{
if (!$this->_options['caching']) {
return false;
}
$id = $this->_id($id); // cache id may need prefix
self::_validateIdOrTag($id);
$this->_lastId = $id;
return $this->_backend->test($id);
}
/**
* Save some data in a cache
*
* @param mixed $data Data to put in cache (can be another type than string if automatic_serialization is on)
* @param string $id Cache id (if not set, the last cache id will be used)
* @param array $tags Cache tags
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
* @throws Zend_Cache_Exception
* @return boolean True if no problem
*/
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
{
if (!$this->_options['caching']) {
return true;
}
if (is_null($id)) {
$id = $this->_lastId;
} else {
$id = $this->_id($id);
}
self::_validateIdOrTag($id);
self::_validateTagsArray($tags);
if ($this->_options['automatic_serialization']) {
// we need to serialize datas before storing them
$data = serialize($data);
} else {
if (!is_string($data)) {
Zend_Cache::throwException("Datas must be string or set automatic_serialization = true");
}
}
// automatic cleaning
if ($this->_options['automatic_cleaning_factor'] > 0) {
$rand = rand(1, $this->_options['automatic_cleaning_factor']);
if ($rand==1) {
if ($this->_extendedBackend) {
// New way
if ($this->_backendCapabilities['automatic_cleaning']) {
$this->clean(Zend_Cache::CLEANING_MODE_OLD);
} else {
$this->_log('Zend_Cache_Core::save() / automatic cleaning is not available/necessary with this backend');
}
} else {
// Deprecated way (will be removed in next major version)
if (method_exists($this->_backend, 'isAutomaticCleaningAvailable') && ($this->_backend->isAutomaticCleaningAvailable())) {
$this->clean(Zend_Cache::CLEANING_MODE_OLD);
} else {
$this->_log('Zend_Cache_Core::save() / automatic cleaning is not available/necessary with this backend');
}
}
}
}
if ($this->_options['ignore_user_abort']) {
$abort = ignore_user_abort(true);
}
if (($this->_extendedBackend) && ($this->_backendCapabilities['priority'])) {
$result = $this->_backend->save($data, $id, $tags, $specificLifetime, $priority);
} else {
$result = $this->_backend->save($data, $id, $tags, $specificLifetime);
}
if ($this->_options['ignore_user_abort']) {
ignore_user_abort($abort);
}
if (!$result) {
// maybe the cache is corrupted, so we remove it !
if ($this->_options['logging']) {
$this->_log("Zend_Cache_Core::save() : impossible to save cache (id=$id)");
}
$this->remove($id);
return false;
}
if ($this->_options['write_control']) {
$data2 = $this->_backend->load($id, true);
if ($data!=$data2) {
$this->_log('Zend_Cache_Core::save() / write_control : written and read data do not match');
$this->_backend->remove($id);
return false;
}
}
return true;
}
/**
* Remove a cache
*
* @param string $id Cache id to remove
* @return boolean True if ok
*/
public function remove($id)
{
if (!$this->_options['caching']) {
return true;
}
$id = $this->_id($id); // cache id may need prefix
self::_validateIdOrTag($id);
return $this->_backend->remove($id);
}
/**
* Clean cache entries
*
* Available modes are :
* 'all' (default) => remove all cache entries ($tags is not used)
* 'old' => remove too old cache entries ($tags is not used)
* 'matchingTag' => remove cache entries matching all given tags
* ($tags can be an array of strings or a single string)
* 'notMatchingTag' => remove cache entries not matching one of the given tags
* ($tags can be an array of strings or a single string)
* 'matchingAnyTag' => remove cache entries matching any given tags
* ($tags can be an array of strings or a single string)
*
* @param string $mode
* @param array|string $tags
* @throws Zend_Cache_Exception
* @return boolean True if ok
*/
public function clean($mode = 'all', $tags = array())
{
if (!$this->_options['caching']) {
return true;
}
if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL,
Zend_Cache::CLEANING_MODE_OLD,
Zend_Cache::CLEANING_MODE_MATCHING_TAG,
Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
Zend_Cache::throwException('Invalid cleaning mode');
}
self::_validateTagsArray($tags);
return $this->_backend->clean($mode, $tags);
}
/**
* Return an array of stored cache ids which match given tags
*
* In case of multiple tags, a logical AND is made between tags
*
* @param array $tags array of tags
* @return array array of matching cache ids (string)
*/
public function getIdsMatchingTags($tags = array())
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
if (!($this->_backendCapabilities['tags'])) {
Zend_Cache::throwException('tags are not supported by the current backend');
}
return $this->_backend->getIdsMatchingTags($tags);
}
/**
* Return an array of stored cache ids which don't match given tags
*
* In case of multiple tags, a logical OR is made between tags
*
* @param array $tags array of tags
* @return array array of not matching cache ids (string)
*/
public function getIdsNotMatchingTags($tags = array())
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
if (!($this->_backendCapabilities['tags'])) {
Zend_Cache::throwException('tags are not supported by the current backend');
}
return $this->_backend->getIdsNotMatchingTags($tags);
}
/**
* Return an array of stored cache ids
*
* @return array array of stored cache ids (string)
*/
public function getIds()
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
return $this->_backend->getIds();
}
/**
* Return an array of stored tags
*
* @return array array of stored tags (string)
*/
public function getTags()
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
if (!($this->_backendCapabilities['tags'])) {
Zend_Cache::throwException('tags are not supported by the current backend');
}
return $this->_backend->getTags();
}
/**
* Return the filling percentage of the backend storage
*
* @return int integer between 0 and 100
*/
public function getFillingPercentage()
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
return $this->_backend->getFillingPercentage();
}
/**
* Give (if possible) an extra lifetime to the given cache id
*
* @param string $id cache id
* @param int $extraLifetime
* @return boolean true if ok
*/
public function touch($id, $extraLifetime)
{
if (!$this->_extendedBackend) {
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
}
return $this->_backend->touch($id, $extraLifetime);
}
/**
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
*
* Throw an exception if a problem is found
*
* @param string $string Cache id or tag
* @throws Zend_Cache_Exception
* @return void
*/
private static function _validateIdOrTag($string)
{
if (!is_string($string)) {
Zend_Cache::throwException('Invalid id or tag : must be a string');
}
if (substr($string, 0, 9) == 'internal-') {
Zend_Cache::throwException('"internal-*" ids or tags are reserved');
}
if (!preg_match('~^[\w]+$~D', $string)) {
Zend_Cache::throwException("Invalid id or tag '$string' : must use only [a-zA-Z0-9_]");
}
}
/**
* Validate a tags array (security, reliable filenames, reserved prefixes...)
*
* Throw an exception if a problem is found
*
* @param array $tags Array of tags
* @throws Zend_Cache_Exception
* @return void
*/
private static function _validateTagsArray($tags)
{
if (!is_array($tags)) {
Zend_Cache::throwException('Invalid tags array : must be an array');
}
foreach($tags as $tag) {
self::_validateIdOrTag($tag);
}
reset($tags);
}
/**
* Make sure if we enable logging that the Zend_Log class
* is available.
* Create a default log object if none is set.
*
* @throws Zend_Cache_Exception
* @return void
*/
protected function _loggerSanity()
{
if (!isset($this->_options['logging']) || !$this->_options['logging']) {
return;
}
if (isset($this->_options['logger']) && $this->_options['logger'] instanceof Zend_Log) {
return;
}
// Create a default logger to the standard output stream
require_once 'Zend/Log/Writer/Stream.php';
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
$this->_options['logger'] = $logger;
}
/**
* Log a message at the WARN (4) priority.
*
* @param string $message
* @throws Zend_Cache_Exception
* @return void
*/
protected function _log($message, $priority = 4)
{
if (!$this->_options['logging']) {
return;
}
if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof Zend_Log)) {
Zend_Cache::throwException('Logging is enabled but logger is not set');
}
$logger = $this->_options['logger'];
$logger->log($message, $priority);
}
/**
* Make and return a cache id
*
* Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null
*
* @param string $id Cache id
* @return string Cache id (with or without prefix)
*/
private function _id($id)
{
if (!is_null($id) && isset($this->_options['cache_id_prefix'])) {
return $this->_options['cache_id_prefix'] . $id; // return with prefix
}
return $id; // no prefix, just return the $id passed
}
}
InfoCard/Adapter/Interface.php 0000604 00000004710 15071256135 0012225 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* The interface required by all Zend_InfoCard Adapter classes to implement. It represents
* a series of callback methods used by the component during processing of an information card
*
* @category Zend
* @package Zend_InfoCard_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Adapter_Interface
{
/**
* Store the assertion's claims in persistent storage
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The specific assertion ID
* @param array $conditions An array of claims to store associated with the assertion
* @return bool True on success, false on failure
*/
public function storeAssertion($assertionURI, $assertionID, $conditions);
/**
* Retrieve the claims of a given assertion from persistent storage
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The assertion ID to retrieve
* @return mixed False if the assertion ID was not found for that URI, or an array of
* conditions associated with that assertion if found in the same format
* provided
*/
public function retrieveAssertion($assertionURI, $assertionID);
/**
* Remove the claims of a given assertion from persistent storage
*
* @param string $asserionURI The assertion type URI
* @param string $assertionID The assertion ID to remove
* @return bool True on success, false on failure
*/
public function removeAssertion($asserionURI, $assertionID);
}
InfoCard/Adapter/Exception.php 0000604 00000002225 15071256135 0012262 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Exception
*/
require_once 'Zend/InfoCard/Exception.php';
/**
* @category Zend
* @subpackage Zend_InfoCard_Adapter
* @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_InfoCard_Adapter_Exception extends Zend_InfoCard_Exception
{
}
InfoCard/Adapter/Default.php 0000604 00000005552 15071256135 0011716 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @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: Default.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Adapter_Interface
*/
require_once 'Zend/InfoCard/Adapter/Interface.php';
/**
* Zend_InfoCard_Adapter_Exception
*/
require_once 'Zend/InfoCard/Adapter/Exception.php';
/**
* The default InfoCard component Adapter which serves as a pass-thru placeholder
* for developers. Initially developed to provide a callback mechanism to store and retrieve
* assertions as part of the validation process it can be used anytime callback facilities
* are necessary
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Adapter
* @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_InfoCard_Adapter_Default implements Zend_InfoCard_Adapter_Interface
{
/**
* Store the assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The specific assertion ID
* @param array $conditions An array of claims to store associated with the assertion
* @return bool Always returns true (would return false on store failure)
*/
public function storeAssertion($assertionURI, $assertionID, $conditions)
{
return true;
}
/**
* Retrieve an assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The assertion ID to retrieve
* @return mixed False if the assertion ID was not found for that URI, or an array of
* conditions associated with that assertion if found (always returns false)
*/
public function retrieveAssertion($assertionURI, $assertionID)
{
return false;
}
/**
* Remove an assertion (pass-thru does nothing)
*
* @param string $assertionURI The assertion type URI
* @param string $assertionID The assertion ID to remove
* @return bool Always returns true (false on removal failure)
*/
public function removeAssertion($assertionURI, $assertionID)
{
return null;
}
}
InfoCard/Xml/Exception.php 0000604 00000002246 15071256135 0011445 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Exception
*/
require_once 'Zend/InfoCard/Exception.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_Exception extends Zend_InfoCard_Exception
{
}
InfoCard/Xml/Security/Transform/Interface.php 0000604 00000002734 15071256135 0015173 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Interface for XML Security Transforms
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Xml_Security_Transform_Interface
{
/**
* Transform the given XML string according to the transform rules
* implemented by the object using this interface
*
* @throws Zend_InfoCard_Xml_Security_Transform_Exception
* @param string $strXmlData the input XML
* @return string the output XML
*/
public function transform($strXmlData);
}
InfoCard/Xml/Security/Transform/Exception.php 0000604 00000002362 15071256135 0015226 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Security_Exception
*/
require_once 'Zend/InfoCard/Xml/Security/Exception.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security_Transform_Exception extends Zend_InfoCard_Xml_Security_Exception
{
}
InfoCard/Xml/Security/Transform/XmlExcC14N.php 0000604 00000004076 15071256135 0015062 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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: XmlExcC14N.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Security_Transform_Interface
*/
require_once 'Zend/InfoCard/Xml/Security/Transform/Interface.php';
/**
* Zend_InfoCard_Xml_Security_Transform_Exception
*/
require_once 'Zend/InfoCard/Xml/Security/Transform/Exception.php';
/**
* A Transform to perform C14n XML Exclusive Canonicalization
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security_Transform_XmlExcC14N
implements Zend_InfoCard_Xml_Security_Transform_Interface
{
/**
* Transform the input XML based on C14n XML Exclusive Canonicalization rules
*
* @throws Zend_InfoCard_Xml_Security_Transform_Exception
* @param string $strXMLData The input XML
* @return string The output XML
*/
public function transform($strXMLData)
{
$dom = new DOMDocument();
$dom->loadXML($strXMLData);
if(method_exists($dom, 'C14N')) {
return $dom->C14N(true, false);
}
throw new Zend_InfoCard_Xml_Security_Transform_Exception("This transform requires the C14N() method to exist in the DOM extension");
}
}
InfoCard/Xml/Security/Transform/EnvelopedSignature.php 0000604 00000004117 15071256135 0017073 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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: EnvelopedSignature.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Security_Transform_Interface
*/
require_once 'Zend/InfoCard/Xml/Security/Transform/Interface.php';
/**
* Zend_InfoCard_Xml_Security_Transform_Exception
*/
require_once 'Zend/InfoCard/Xml/Security/Transform/Exception.php';
/**
* A object implementing the EnvelopedSignature XML Transform
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security_Transform_EnvelopedSignature
implements Zend_InfoCard_Xml_Security_Transform_Interface
{
/**
* Transforms the XML Document according to the EnvelopedSignature Transform
*
* @throws Zend_InfoCard_Xml_Security_Transform_Exception
* @param string $strXMLData The input XML data
* @return string the transformed XML data
*/
public function transform($strXMLData)
{
$sxe = simplexml_load_string($strXMLData);
if(!$sxe->Signature) {
throw new Zend_InfoCard_Xml_Security_Transform_Exception("Unable to locate Signature Block for EnvelopedSignature Transform");
}
unset($sxe->Signature);
return $sxe->asXML();
}
}
InfoCard/Xml/Security/Exception.php 0000604 00000002315 15071256135 0013251 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Exception
*/
require_once 'Zend/InfoCard/Xml/Exception.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security_Exception extends Zend_InfoCard_Xml_Exception
{
}
InfoCard/Xml/Security/Transform.php 0000604 00000007314 15071256135 0013272 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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: Transform.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* A class to create a transform rule set based on XML URIs and then apply those rules
* in the correct order to a given XML input
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security_Transform
{
/**
* A list of transforms to apply
*
* @var array
*/
protected $_transformList = array();
/**
* Returns the name of the transform class based on a given URI
*
* @throws Zend_InfoCard_Xml_Security_Exception
* @param string $uri The transform URI
* @return string The transform implementation class name
*/
protected function _findClassbyURI($uri)
{
switch($uri) {
case 'http://www.w3.org/2000/09/xmldsig#enveloped-signature':
return 'Zend_InfoCard_Xml_Security_Transform_EnvelopedSignature';
case 'http://www.w3.org/2001/10/xml-exc-c14n#':
return 'Zend_InfoCard_Xml_Security_Transform_XmlExcC14N';
default:
throw new Zend_InfoCard_Xml_Security_Exception("Unknown or Unsupported Transformation Requested");
}
}
/**
* Add a Transform URI to the list of transforms to perform
*
* @param string $uri The Transform URI
* @return Zend_InfoCard_Xml_Security_Transform
*/
public function addTransform($uri)
{
$class = $this->_findClassbyURI($uri);
$this->_transformList[] = array('uri' => $uri,
'class' => $class);
return $this;
}
/**
* Return the list of transforms to perform
*
* @return array The list of transforms
*/
public function getTransformList()
{
return $this->_transformList;
}
/**
* Apply the transforms in the transform list to the input XML document
*
* @param string $strXmlDocument The input XML
* @return string The XML after the transformations have been applied
*/
public function applyTransforms($strXmlDocument)
{
foreach($this->_transformList as $transform) {
Zend_Loader::loadClass($transform['class']);
$transformer = new $transform['class'];
// We can't really test this check because it would require logic changes in the component itself
// @codeCoverageIgnoreStart
if(!($transformer instanceof Zend_InfoCard_Xml_Security_Transform_Interface)) {
throw new Zend_InfoCard_Xml_Security_Exception("Transforms must implement the Transform Interface");
}
// @codeCoverageIgnoreEnd
$strXmlDocument = $transformer->transform($strXmlDocument);
}
return $strXmlDocument;
}
}
InfoCard/Xml/Assertion.php 0000604 00000005420 15071256135 0011453 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Assertion.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Exception
*/
require_once 'Zend/InfoCard/Xml/Exception.php';
/**
* Zend_InfoCard_Xml_Assertion_Interface
*/
require_once 'Zend/InfoCard/Xml/Assertion/Interface.php';
/**
* Factory object to retrieve an Assertion object based on the type of XML document provided
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
final class Zend_InfoCard_Xml_Assertion
{
/**
* The namespace for a SAML-formatted Assertion document
*/
const TYPE_SAML = 'urn:oasis:names:tc:SAML:1.0:assertion';
/**
* Constructor (disabled)
*
* @return void
*/
private function __construct()
{
}
/**
* Returns an instance of a InfoCard Assertion object based on the XML data provided
*
* @throws Zend_InfoCard_Xml_Exception
* @param string $xmlData The XML-Formatted Assertion
* @return Zend_InfoCard_Xml_Assertion_Interface
* @throws Zend_InfoCard_Xml_Exception
*/
static public function getInstance($xmlData)
{
if($xmlData instanceof Zend_InfoCard_Xml_Element) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
} else {
throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
}
$sxe = simplexml_load_string($strXmlData);
$namespaces = $sxe->getDocNameSpaces();
foreach($namespaces as $namespace) {
switch($namespace) {
case self::TYPE_SAML:
include_once 'Zend/InfoCard/Xml/Assertion/Saml.php';
return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_Assertion_Saml', null);
}
}
throw new Zend_InfoCard_Xml_Exception("Unable to determine Assertion type by Namespace");
}
}
InfoCard/Xml/Element.php 0000604 00000007073 15071256135 0011103 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Element.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Exception
*/
require_once 'Zend/InfoCard/Xml/Exception.php';
/**
* Zend_InfoCard_Xml_Element_Interface
*/
require_once 'Zend/InfoCard/Xml/Element/Interface.php';
/**
* Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* An abstract class representing a an XML data block
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Xml_Element
extends SimpleXMLElement
implements Zend_InfoCard_Xml_Element_Interface
{
/**
* Convert the object to a string by displaying its XML content
*
* @return string an XML representation of the object
*/
public function __toString()
{
return $this->asXML();
}
/**
* Converts an XML Element object into a DOM object
*
* @throws Zend_InfoCard_Xml_Exception
* @param Zend_InfoCard_Xml_Element $e The object to convert
* @return DOMElement A DOMElement representation of the same object
*/
static public function convertToDOM(Zend_InfoCard_Xml_Element $e)
{
$dom = dom_import_simplexml($e);
if(!($dom instanceof DOMElement)) {
// Zend_InfoCard_Xml_Element exntes SimpleXMLElement, so this should *never* fail
// @codeCoverageIgnoreStart
throw new Zend_InfoCard_Xml_Exception("Failed to convert between SimpleXML and DOM");
// @codeCoverageIgnoreEnd
}
return $dom;
}
/**
* Converts a DOMElement object into the specific class
*
* @throws Zend_InfoCard_Xml_Exception
* @param DOMElement $e The DOMElement object to convert
* @param string $classname The name of the class to convert it to (must inhert from Zend_InfoCard_Xml_Element)
* @return Zend_InfoCard_Xml_Element a Xml Element object from the DOM element
*/
static public function convertToObject(DOMElement $e, $classname)
{
Zend_Loader::loadClass($classname);
$reflection = new ReflectionClass($classname);
if(!$reflection->isSubclassOf('Zend_InfoCard_Xml_Element')) {
throw new Zend_InfoCard_Xml_Exception("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element");
}
$sxe = simplexml_import_dom($e, $classname);
if(!($sxe instanceof Zend_InfoCard_Xml_Element)) {
// Since we just checked to see if this was a subclass of Zend_infoCard_Xml_Element this shoudl never fail
// @codeCoverageIgnoreStart
throw new Zend_InfoCard_Xml_Exception("Failed to convert between DOM and SimpleXML");
// @codeCoverageIgnoreEnd
}
return $sxe;
}
}
InfoCard/Xml/KeyInfo/Default.php 0000604 00000004347 15071256135 0012443 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Default.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_KeyInfo_Abstract
*/
require_once 'Zend/InfoCard/Xml/KeyInfo/Abstract.php';
/**
* Zend_InfoCard_Xml_SecurityTokenReference
*/
require_once 'Zend/InfoCard/Xml/SecurityTokenReference.php';
/**
* An object representation of a XML <KeyInfo> block which doesn't provide a namespace
* In this context, it is assumed to mean that it is the type of KeyInfo block which
* contains the SecurityTokenReference
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_KeyInfo_Default extends Zend_InfoCard_Xml_KeyInfo_Abstract
{
/**
* Returns the object representation of the SecurityTokenReference block
*
* @throws Zend_InfoCard_Xml_Exception
* @return Zend_InfoCard_Xml_SecurityTokenReference
*/
public function getSecurityTokenReference()
{
$this->registerXPathNamespace('o', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
list($sectokenref) = $this->xpath('//o:SecurityTokenReference');
if(!($sectokenref instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception('Could not locate the Security Token Reference');
}
return Zend_InfoCard_Xml_SecurityTokenReference::getInstance($sectokenref);
}
}
InfoCard/Xml/KeyInfo/XmlDSig.php 0000604 00000004403 15071256135 0012357 0 ustar 00 <?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_InfoCard
* @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: XmlDSig.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_KeyInfo_Abstract
*/
require_once 'Zend/InfoCard/Xml/KeyInfo/Abstract.php';
/**
* Zend_InfoCard_Xml_EncryptedKey
*/
require_once 'Zend/InfoCard/Xml/EncryptedKey.php';
/**
* Zend_InfoCard_Xml_KeyInfo_Interface
*/
require_once 'Zend/InfoCard/Xml/KeyInfo/Interface.php';
/**
* Represents a Xml Digital Signature XML Data Block
*
* @category Zend
* @package Zend_InfoCard
* @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_InfoCard_Xml_KeyInfo_XmlDSig
extends Zend_InfoCard_Xml_KeyInfo_Abstract
implements Zend_InfoCard_Xml_KeyInfo_Interface
{
/**
* Returns an instance of the EncryptedKey Data Block
*
* @throws Zend_InfoCard_Xml_Exception
* @return Zend_InfoCard_Xml_EncryptedKey
*/
public function getEncryptedKey()
{
$this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#');
list($encryptedkey) = $this->xpath('//e:EncryptedKey');
if(!($encryptedkey instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Failed to retrieve encrypted key");
}
return Zend_InfoCard_Xml_EncryptedKey::getInstance($encryptedkey);
}
/**
* Returns the KeyInfo Block within the encrypted key
*
* @return Zend_InfoCard_Xml_KeyInfo_Default
*/
public function getKeyInfo()
{
return $this->getEncryptedKey()->getKeyInfo();
}
}
InfoCard/Xml/KeyInfo/Abstract.php 0000604 00000002273 15071256135 0012616 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Abstract.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Xml_KeyInfo_Abstract extends Zend_InfoCard_Xml_Element
{
}
InfoCard/Xml/KeyInfo/Interface.php 0000604 00000002334 15071256135 0012751 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Xml_KeyInfo_Interface
{
/**
* Return an object representing a KeyInfo data type
*
* @return Zend_InfoCard_Xml_KeyInfo
*/
public function getKeyInfo();
}
InfoCard/Xml/Element/Interface.php 0000604 00000002614 15071256135 0012777 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* The Interface used to represent an XML Data Type
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Xml_Element_Interface
{
/**
* Return the data within the object as an XML document
*/
public function asXML();
/**
* Magic function which allows us to treat the object as a string to return XML
* (same as the asXML() method)
*/
public function __toString();
}
InfoCard/Xml/EncryptedData.php 0000604 00000004631 15071256135 0012236 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: EncryptedData.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_EncryptedData
*/
require_once 'Zend/InfoCard/Xml/Exception.php';
/**
* A factory class for producing Zend_InfoCard_Xml_EncryptedData objects based on
* the type of XML document provided
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
final class Zend_InfoCard_Xml_EncryptedData
{
/**
* Constructor (disabled)
*
* @return void
*/
private function __construct()
{
}
/**
* Returns an instance of the class
*
* @param string $xmlData The XML EncryptedData String
* @return Zend_InfoCard_Xml_EncryptedData_Abstract
* @throws Zend_InfoCard_Xml_Exception
*/
static public function getInstance($xmlData)
{
if($xmlData instanceof Zend_InfoCard_Xml_Element) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
} else {
throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
}
$sxe = simplexml_load_string($strXmlData);
switch($sxe['Type']) {
case 'http://www.w3.org/2001/04/xmlenc#Element':
include_once 'Zend/InfoCard/Xml/EncryptedData/XmlEnc.php';
return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_EncryptedData_XmlEnc');
default:
throw new Zend_InfoCard_Xml_Exception("Unknown EncryptedData type found");
}
}
}
InfoCard/Xml/EncryptedKey.php 0000604 00000013134 15071256135 0012113 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: EncryptedKey.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* Zend_InfoCard_Xml_EncryptedKey
*/
require_once 'Zend/InfoCard/Xml/EncryptedKey.php';
/**
* Zend_InfoCard_Xml_KeyInfo_Interface
*/
require_once 'Zend/InfoCard/Xml/KeyInfo/Interface.php';
/**
* An object representing an Xml EncryptedKEy block
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_EncryptedKey
extends Zend_InfoCard_Xml_Element
implements Zend_InfoCard_Xml_KeyInfo_Interface
{
/**
* Return an instance of the object based on input XML Data
*
* @throws Zend_InfoCard_Xml_Exception
* @param string $xmlData The EncryptedKey XML Block
* @return Zend_InfoCard_Xml_EncryptedKey
*/
static public function getInstance($xmlData)
{
if($xmlData instanceof Zend_InfoCard_Xml_Element) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
} else {
throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
}
$sxe = simplexml_load_string($strXmlData);
if($sxe->getName() != "EncryptedKey") {
throw new Zend_InfoCard_Xml_Exception("Invalid XML Block provided for EncryptedKey");
}
return simplexml_load_string($strXmlData, "Zend_InfoCard_Xml_EncryptedKey");
}
/**
* Returns the Encyption Method Algorithm URI of the block
*
* @throws Zend_InfoCard_Xml_Exception
* @return string the Encryption method algorithm URI
*/
public function getEncryptionMethod()
{
$this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#');
list($encryption_method) = $this->xpath("//e:EncryptionMethod");
if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the e:EncryptionMethod KeyInfo encryption block");
}
$dom = self::convertToDOM($encryption_method);
if(!$dom->hasAttribute('Algorithm')) {
throw new Zend_InfoCard_Xml_Exception("Unable to determine the encryption algorithm in the Symmetric enc:EncryptionMethod XML block");
}
return $dom->getAttribute('Algorithm');
}
/**
* Returns the Digest Method Algorithm URI used
*
* @throws Zend_InfoCard_Xml_Exception
* @return string the Digest Method Algorithm URI
*/
public function getDigestMethod()
{
$this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#');
list($encryption_method) = $this->xpath("//e:EncryptionMethod");
if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the e:EncryptionMethod KeyInfo encryption block");
}
if(!($encryption_method->DigestMethod instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the DigestMethod block");
}
$dom = self::convertToDOM($encryption_method->DigestMethod);
if(!$dom->hasAttribute('Algorithm')) {
throw new Zend_InfoCard_Xml_Exception("Unable to determine the digest algorithm for the symmetric Keyinfo");
}
return $dom->getAttribute('Algorithm');
}
/**
* Returns the KeyInfo block object
*
* @throws Zend_InfoCard_Xml_Exception
* @return Zend_InfoCard_Xml_KeyInfo_Abstract
*/
public function getKeyInfo()
{
if(isset($this->KeyInfo)) {
return Zend_InfoCard_Xml_KeyInfo::getInstance($this->KeyInfo);
}
throw new Zend_InfoCard_Xml_Exception("Unable to locate a KeyInfo block");
}
/**
* Return the encrypted value of the block in base64 format
*
* @throws Zend_InfoCard_Xml_Exception
* @return string The Value of the CipherValue block in base64 format
*/
public function getCipherValue()
{
$this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#');
list($cipherdata) = $this->xpath("//e:CipherData");
if(!($cipherdata instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the e:CipherData block");
}
$cipherdata->registerXPathNameSpace('enc', 'http://www.w3.org/2001/04/xmlenc#');
list($ciphervalue) = $cipherdata->xpath("//enc:CipherValue");
if(!($ciphervalue instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to fidn the enc:CipherValue block");
}
return (string)$ciphervalue;
}
}
InfoCard/Xml/KeyInfo.php 0000604 00000005670 15071256135 0011057 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: KeyInfo.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* Factory class to return a XML KeyInfo block based on input XML
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_KeyInfo
{
/**
* Constructor (disabled)
*
* @return void
*/
private function __construct()
{
}
/**
* Returns an instance of KeyInfo object based on the input KeyInfo XML block
*
* @param string $xmlData The KeyInfo XML Block
* @return Zend_InfoCard_Xml_KeyInfo_Abstract
* @throws Zend_InfoCard_Xml_Exception
*/
static public function getInstance($xmlData)
{
if($xmlData instanceof Zend_InfoCard_Xml_Element) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
} else {
throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
}
$sxe = simplexml_load_string($strXmlData);
$namespaces = $sxe->getDocNameSpaces();
if(!empty($namespaces)) {
foreach($sxe->getDocNameSpaces() as $namespace) {
switch($namespace) {
case 'http://www.w3.org/2000/09/xmldsig#':
include_once 'Zend/InfoCard/Xml/KeyInfo/XmlDSig.php';
return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig');
default:
throw new Zend_InfoCard_Xml_Exception("Unknown KeyInfo Namespace provided");
// We are ignoring these lines, as XDebug reports each as a "non executed" line
// which breaks my coverage %
// @codeCoverageIgnoreStart
}
}
}
// @codeCoverageIgnoreEnd
include_once 'Zend/InfoCard/Xml/KeyInfo/Default.php';
return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_Default');
}
}
InfoCard/Xml/Assertion/Interface.php 0000604 00000004273 15071256135 0013360 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* The Interface required by any InfoCard Assertion Object implemented within the component
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Xml_Assertion_Interface
{
/**
* Get the Assertion ID of the assertion
*
* @return string The Assertion ID
*/
public function getAssertionID();
/**
* Return an array of attributes (claims) contained within the assertion
*
* @return array An array of attributes / claims within the assertion
*/
public function getAttributes();
/**
* Get the Assertion URI for this type of Assertion
*
* @return string the Assertion URI
*/
public function getAssertionURI();
/**
* Return an array of conditions which the assertions are predicated on
*
* @return array an array of conditions
*/
public function getConditions();
/**
* Validate the conditions array returned from the getConditions() call
*
* @param array $conditions An array of condtions for the assertion taken from getConditions()
* @return mixed Boolean true on success, an array of condition, error message on failure
*/
public function validateConditions(Array $conditions);
}
InfoCard/Xml/Assertion/Saml.php 0000604 00000021013 15071256135 0012343 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Saml.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* Zend_InfoCard_Xml_Assertion_Interface
*/
require_once 'Zend/InfoCard/Xml/Assertion/Interface.php';
/**
* A Xml Assertion Document in SAML Token format
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_Assertion_Saml
extends Zend_InfoCard_Xml_Element
implements Zend_InfoCard_Xml_Assertion_Interface
{
/**
* Audience Restriction Condition
*/
const CONDITION_AUDIENCE = 'AudienceRestrictionCondition';
/**
* The URI for a 'bearer' confirmation
*/
const CONFIRMATION_BEARER = 'urn:oasis:names:tc:SAML:1.0:cm:bearer';
/**
* The amount of time in seconds to buffer when checking conditions to ensure
* that differences between client/server clocks don't interfer too much
*/
const CONDITION_TIME_ADJ = 3600; // +- 5 minutes
protected function _getServerName() {
return $_SERVER['SERVER_NAME'];
}
protected function _getServerPort() {
return $_SERVER['SERVER_PORT'];
}
/**
* Validate the conditions array returned from the getConditions() call
*
* @param array $conditions An array of condtions for the assertion taken from getConditions()
* @return mixed Boolean true on success, an array of condition, error message on failure
*/
public function validateConditions(Array $conditions)
{
$currentTime = time();
if(!empty($conditions)) {
foreach($conditions as $condition => $conditionValue) {
switch(strtolower($condition)) {
case 'audiencerestrictioncondition':
$serverName = $this->_getServerName();
$serverPort = $this->_getServerPort();
$self_aliases[] = $serverName;
$self_aliases[] = "{{$serverName}:{$serverPort}";
$found = false;
if(is_array($conditionValue)) {
foreach($conditionValue as $audience) {
list(,,$audience) = explode('/', $audience);
if(in_array($audience, $self_aliases)) {
$found = true;
break;
}
}
}
if(!$found) {
return array($condition, 'Could not find self in allowed audience list');
}
break;
case 'notbefore':
$notbeforetime = strtotime($conditionValue);
if($currentTime < $notbeforetime) {
if($currentTime + self::CONDITION_TIME_ADJ < $notbeforetime) {
return array($condition, 'Current time is before specified window');
}
}
break;
case 'notonorafter':
$notonoraftertime = strtotime($conditionValue);
if($currentTime >= $notonoraftertime) {
if($currentTime - self::CONDITION_TIME_ADJ >= $notonoraftertime) {
return array($condition, 'Current time is after specified window');
}
}
break;
}
}
}
return true;
}
/**
* Get the Assertion URI for this type of Assertion
*
* @return string the Assertion URI
*/
public function getAssertionURI()
{
return Zend_InfoCard_Xml_Assertion::TYPE_SAML;
}
/**
* Get the Major Version of the SAML Assertion
*
* @return integer The major version number
*/
public function getMajorVersion()
{
return (int)(string)$this['MajorVersion'];
}
/**
* The Minor Version of the SAML Assertion
*
* @return integer The minor version number
*/
public function getMinorVersion()
{
return (int)(string)$this['MinorVersion'];
}
/**
* Get the Assertion ID of the assertion
*
* @return string The Assertion ID
*/
public function getAssertionID()
{
return (string)$this['AssertionID'];
}
/**
* Get the Issuer URI of the assertion
*
* @return string the URI of the assertion Issuer
*/
public function getIssuer()
{
return (string)$this['Issuer'];
}
/**
* Get the Timestamp of when the assertion was issued
*
* @return integer a UNIX timestamp representing when the assertion was issued
*/
public function getIssuedTimestamp()
{
return strtotime((string)$this['IssueInstant']);
}
/**
* Return an array of conditions which the assertions are predicated on
*
* @throws Zend_InfoCard_Xml_Exception
* @return array an array of conditions
*/
public function getConditions()
{
list($conditions) = $this->xpath("//saml:Conditions");
if(!($conditions instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the saml:Conditions block");
}
$retval = array();
foreach($conditions->children('urn:oasis:names:tc:SAML:1.0:assertion') as $key => $value) {
switch($key) {
case self::CONDITION_AUDIENCE:
foreach($value->children('urn:oasis:names:tc:SAML:1.0:assertion') as $audience_key => $audience_value) {
if($audience_key == 'Audience') {
$retval[$key][] = (string)$audience_value;
}
}
break;
}
}
$retval['NotBefore'] = (string)$conditions['NotBefore'];
$retval['NotOnOrAfter'] = (string)$conditions['NotOnOrAfter'];
return $retval;
}
/**
* Get they KeyInfo element for the Subject KeyInfo block
*
* @todo Not Yet Implemented
* @ignore
*/
public function getSubjectKeyInfo()
{
/**
* @todo Not sure if this is part of the scope for now..
*/
if($this->getConfirmationMethod() == self::CONFIRMATION_BEARER) {
throw new Zend_InfoCard_Xml_Exception("Cannot get Subject Key Info when Confirmation Method was Bearer");
}
}
/**
* Return the Confirmation Method URI used in the Assertion
*
* @return string The confirmation method URI
*/
public function getConfirmationMethod()
{
list($confirmation) = $this->xPath("//saml:ConfirmationMethod");
return (string)$confirmation;
}
/**
* Return an array of attributes (claims) contained within the assertion
*
* @return array An array of attributes / claims within the assertion
*/
public function getAttributes()
{
$attributes = $this->xPath('//saml:Attribute');
$retval = array();
foreach($attributes as $key => $value) {
$retkey = (string)$value['AttributeNamespace'].'/'.(string)$value['AttributeName'];
$retval[$retkey]['name'] = (string)$value['AttributeName'];
$retval[$retkey]['namespace'] = (string)$value['AttributeNamespace'];
list($aValue) = $value->children('urn:oasis:names:tc:SAML:1.0:assertion');
$retval[$retkey]['value'] = (string)$aValue;
}
return $retval;
}
}
InfoCard/Xml/EncryptedData/XmlEnc.php 0000604 00000004176 15071256135 0013430 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: XmlEnc.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_EncryptedData/Abstract.php
*/
require_once 'Zend/InfoCard/Xml/EncryptedData/Abstract.php';
/**
* An XmlEnc formatted EncryptedData XML block
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_EncryptedData_XmlEnc extends Zend_InfoCard_Xml_EncryptedData_Abstract
{
/**
* Returns the Encrypted CipherValue block from the EncryptedData XML document
*
* @throws Zend_InfoCard_Xml_Exception
* @return string The value of the CipherValue block base64 encoded
*/
public function getCipherValue()
{
$this->registerXPathNamespace('enc', 'http://www.w3.org/2001/04/xmlenc#');
list(,$cipherdata) = $this->xpath("//enc:CipherData");
if(!($cipherdata instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the enc:CipherData block");
}
list(,$ciphervalue) = $cipherdata->xpath("//enc:CipherValue");
if(!($ciphervalue instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to fidn the enc:CipherValue block");
}
return (string)$ciphervalue;
}
}
InfoCard/Xml/EncryptedData/Abstract.php 0000604 00000005723 15071256135 0014004 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: Abstract.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* Zend_InfoCard_Xml_KeyInfo
*/
require_once 'Zend/InfoCard/Xml/KeyInfo.php';
/**
* An abstract class representing a generic EncryptedData XML block. This class is extended
* into a specific type of EncryptedData XML block (i.e. XmlEnc) as necessary
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Xml_EncryptedData_Abstract extends Zend_InfoCard_Xml_Element
{
/**
* Returns the KeyInfo Block
*
* @return Zend_InfoCard_Xml_KeyInfo_Abstract
*/
public function getKeyInfo()
{
return Zend_InfoCard_Xml_KeyInfo::getInstance($this->KeyInfo[0]);
}
/**
* Return the Encryption method used to encrypt the assertion document
* (the symmetric cipher)
*
* @throws Zend_InfoCard_Xml_Exception
* @return string The URI of the Symmetric Encryption Method used
*/
public function getEncryptionMethod()
{
/**
* @todo This is pretty hacky unless we can always be confident that the first
* EncryptionMethod block is the correct one (the AES or compariable symetric algorithm)..
* the second is the PK method if provided.
*/
list($encryption_method) = $this->xpath("//enc:EncryptionMethod");
if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Unable to find the enc:EncryptionMethod symmetric encryption block");
}
$dom = self::convertToDOM($encryption_method);
if(!$dom->hasAttribute('Algorithm')) {
throw new Zend_InfoCard_Xml_Exception("Unable to determine the encryption algorithm in the Symmetric enc:EncryptionMethod XML block");
}
return $dom->getAttribute('Algorithm');
}
/**
* Returns the value of the encrypted block
*
* @return string the value of the encrypted CipherValue block
*/
abstract function getCipherValue();
}
InfoCard/Xml/Security.php 0000604 00000025621 15071256135 0011320 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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: Security.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Security_Exception
*/
require_once 'Zend/InfoCard/Xml/Security/Exception.php';
/**
* Zend_InfoCard_Xml_Security_Transform
*/
require_once 'Zend/InfoCard/Xml/Security/Transform.php';
/**
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml_Security
* @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_InfoCard_Xml_Security
{
/**
* ASN.1 type INTEGER class
*/
const ASN_TYPE_INTEGER = 0x02;
/**
* ASN.1 type BIT STRING class
*/
const ASN_TYPE_BITSTRING = 0x03;
/**
* ASN.1 type SEQUENCE class
*/
const ASN_TYPE_SEQUENCE = 0x30;
/**
* The URI for Canonical Method C14N Exclusive
*/
const CANONICAL_METHOD_C14N_EXC = 'http://www.w3.org/2001/10/xml-exc-c14n#';
/**
* The URI for Signature Method SHA1
*/
const SIGNATURE_METHOD_SHA1 = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1';
/**
* The URI for Digest Method SHA1
*/
const DIGEST_METHOD_SHA1 = 'http://www.w3.org/2000/09/xmldsig#sha1';
/**
* The Identifier for RSA Keys
*/
const RSA_KEY_IDENTIFIER = '300D06092A864886F70D0101010500';
/**
* Constructor (disabled)
*
* @return void
*/
private function __construct()
{
}
/**
* Validates the signature of a provided XML block
*
* @param string $strXMLInput An XML block containing a Signature
* @return bool True if the signature validated, false otherwise
* @throws Zend_InfoCard_Xml_Security_Exception
*/
static public function validateXMLSignature($strXMLInput)
{
if(!extension_loaded('openssl')) {
throw new Zend_InfoCard_Xml_Security_Exception("You must have the openssl extension installed to use this class");
}
$sxe = simplexml_load_string($strXMLInput);
if(!isset($sxe->Signature)) {
throw new Zend_InfoCard_Xml_Security_Exception("Could not identify XML Signature element");
}
if(!isset($sxe->Signature->SignedInfo)) {
throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a SignedInfo block");
}
if(!isset($sxe->Signature->SignatureValue)) {
throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a SignatureValue block");
}
if(!isset($sxe->Signature->KeyInfo)) {
throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a KeyInfo block");
}
if(!isset($sxe->Signature->KeyInfo->KeyValue)) {
throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a KeyValue block");
}
switch((string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm']) {
case self::CANONICAL_METHOD_C14N_EXC:
$cMethod = (string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm'];
break;
default:
throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported CanonicalizationMethod Requested");
}
switch((string)$sxe->Signature->SignedInfo->SignatureMethod['Algorithm']) {
case self::SIGNATURE_METHOD_SHA1:
$sMethod = (string)$sxe->Signature->SignedInfo->SignatureMethod['Algorithm'];
break;
default:
throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported SignatureMethod Requested");
}
switch((string)$sxe->Signature->SignedInfo->Reference->DigestMethod['Algorithm']) {
case self::DIGEST_METHOD_SHA1:
$dMethod = (string)$sxe->Signature->SignedInfo->Reference->DigestMethod['Algorithm'];
break;
default:
throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported DigestMethod Requested");
}
$base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>=');
if ($base64DecodeSupportsStrictParam) {
$dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue, true);
} else {
$dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue);
}
if ($base64DecodeSupportsStrictParam) {
$signatureValue = base64_decode((string)$sxe->Signature->SignatureValue, true);
} else {
$signatureValue = base64_decode((string)$sxe->Signature->SignatureValue);
}
$transformer = new Zend_InfoCard_Xml_Security_Transform();
foreach($sxe->Signature->SignedInfo->Reference->Transforms->children() as $transform) {
$transformer->addTransform((string)$transform['Algorithm']);
}
$transformed_xml = $transformer->applyTransforms($strXMLInput);
$transformed_xml_binhash = pack("H*", sha1($transformed_xml));
if($transformed_xml_binhash != $dValue) {
throw new Zend_InfoCard_Xml_Security_Exception("Locally Transformed XML does not match XML Document. Cannot Verify Signature");
}
$public_key = null;
switch(true) {
case isset($sxe->Signature->KeyInfo->KeyValue->X509Certificate):
$certificate = (string)$sxe->Signature->KeyInfo->KeyValue->X509Certificate;
$pem = "-----BEGIN CERTIFICATE-----\n" .
wordwrap($certificate, 64, "\n", true) .
"\n-----END CERTIFICATE-----";
$public_key = openssl_pkey_get_public($pem);
if(!$public_key) {
throw new Zend_InfoCard_Xml_Security_Exception("Unable to extract and prcoess X509 Certificate from KeyValue");
}
break;
case isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue):
if(!isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Modulus) ||
!isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Exponent)) {
throw new Zend_InfoCard_Xml_Security_Exception("RSA Key Value not in Modulus/Exponent form");
}
$modulus = base64_decode((string)$sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Modulus);
$exponent = base64_decode((string)$sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Exponent);
$pem_public_key = self::_getPublicKeyFromModExp($modulus, $exponent);
$public_key = openssl_pkey_get_public ($pem_public_key);
break;
default:
throw new Zend_InfoCard_Xml_Security_Exception("Unable to determine or unsupported representation of the KeyValue block");
}
$transformer = new Zend_InfoCard_Xml_Security_Transform();
$transformer->addTransform((string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm']);
// The way we are doing our XML processing requires that we specifically add this
// (even though it's in the <Signature> parent-block).. otherwise, our canonical form
// fails signature verification
$sxe->Signature->SignedInfo->addAttribute('xmlns', 'http://www.w3.org/2000/09/xmldsig#');
$canonical_signedinfo = $transformer->applyTransforms($sxe->Signature->SignedInfo->asXML());
if(@openssl_verify($canonical_signedinfo, $signatureValue, $public_key)) {
return (string)$sxe->Signature->SignedInfo->Reference['URI'];
}
return false;
}
/**
* Transform an RSA Key in Modulus/Exponent format into a PEM encoding and
* return an openssl resource for it
*
* @param string $modulus The RSA Modulus in binary format
* @param string $exponent The RSA exponent in binary format
* @return string The PEM encoded version of the key
*/
static protected function _getPublicKeyFromModExp($modulus, $exponent)
{
$modulusInteger = self::_encodeValue($modulus, self::ASN_TYPE_INTEGER);
$exponentInteger = self::_encodeValue($exponent, self::ASN_TYPE_INTEGER);
$modExpSequence = self::_encodeValue($modulusInteger . $exponentInteger, self::ASN_TYPE_SEQUENCE);
$modExpBitString = self::_encodeValue($modExpSequence, self::ASN_TYPE_BITSTRING);
$binRsaKeyIdentifier = pack( "H*", self::RSA_KEY_IDENTIFIER );
$publicKeySequence = self::_encodeValue($binRsaKeyIdentifier . $modExpBitString, self::ASN_TYPE_SEQUENCE);
$publicKeyInfoBase64 = base64_encode( $publicKeySequence );
$publicKeyString = "-----BEGIN PUBLIC KEY-----\n";
$publicKeyString .= wordwrap($publicKeyInfoBase64, 64, "\n", true);
$publicKeyString .= "\n-----END PUBLIC KEY-----\n";
return $publicKeyString;
}
/**
* Encode a limited set of data types into ASN.1 encoding format
* which is used in X.509 certificates
*
* @param string $data The data to encode
* @param const $type The encoding format constant
* @return string The encoded value
* @throws Zend_InfoCard_Xml_Security_Exception
*/
static protected function _encodeValue($data, $type)
{
// Null pad some data when we get it (integer values > 128 and bitstrings)
if( (($type == self::ASN_TYPE_INTEGER) && (ord($data) > 0x7f)) ||
($type == self::ASN_TYPE_BITSTRING)) {
$data = "\0$data";
}
$len = strlen($data);
// encode the value based on length of the string
// I'm fairly confident that this is by no means a complete implementation
// but it is enough for our purposes
switch(true) {
case ($len < 128):
return sprintf("%c%c%s", $type, $len, $data);
case ($len < 0x0100):
return sprintf("%c%c%c%s", $type, 0x81, $len, $data);
case ($len < 0x010000):
return sprintf("%c%c%c%c%s", $type, 0x82, $len / 0x0100, $len % 0x0100, $data);
default:
throw new Zend_InfoCard_Xml_Security_Exception("Could not encode value");
}
throw new Zend_InfoCard_Xml_Security_Exception("Invalid code path");
}
} InfoCard/Xml/SecurityTokenReference.php 0000604 00000012701 15071256135 0014133 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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: SecurityTokenReference.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Xml_Element
*/
require_once 'Zend/InfoCard/Xml/Element.php';
/**
* Represents a SecurityTokenReference XML block
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @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_InfoCard_Xml_SecurityTokenReference extends Zend_InfoCard_Xml_Element
{
/**
* Base64 Binary Encoding URI
*/
const ENCODING_BASE64BIN = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
/**
* Return an instance of the object based on the input XML
*
* @param string $xmlData The SecurityTokenReference XML Block
* @return Zend_InfoCard_Xml_SecurityTokenReference
* @throws Zend_InfoCard_Xml_Exception
*/
static public function getInstance($xmlData)
{
if($xmlData instanceof Zend_InfoCard_Xml_Element) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
} else {
throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
}
$sxe = simplexml_load_string($strXmlData);
if($sxe->getName() != "SecurityTokenReference") {
throw new Zend_InfoCard_Xml_Exception("Invalid XML Block provided for SecurityTokenReference");
}
return simplexml_load_string($strXmlData, "Zend_InfoCard_Xml_SecurityTokenReference");
}
/**
* Return the Key Identifier XML Object
*
* @return Zend_InfoCard_Xml_Element
* @throws Zend_InfoCard_Xml_Exception
*/
protected function _getKeyIdentifier()
{
$this->registerXPathNamespace('o', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
list($keyident) = $this->xpath('//o:KeyIdentifier');
if(!($keyident instanceof Zend_InfoCard_Xml_Element)) {
throw new Zend_InfoCard_Xml_Exception("Failed to retrieve Key Identifier");
}
return $keyident;
}
/**
* Return the Key URI identifying the thumbprint type used
*
* @return string The thumbprint type URI
* @throws Zend_InfoCard_Xml_Exception
*/
public function getKeyThumbprintType()
{
$keyident = $this->_getKeyIdentifier();
$dom = self::convertToDOM($keyident);
if(!$dom->hasAttribute('ValueType')) {
throw new Zend_InfoCard_Xml_Exception("Key Identifier did not provide a type for the value");
}
return $dom->getAttribute('ValueType');
}
/**
* Return the thumbprint encoding type used as a URI
*
* @return string the URI of the thumbprint encoding used
* @throws Zend_InfoCard_Xml_Exception
*/
public function getKeyThumbprintEncodingType()
{
$keyident = $this->_getKeyIdentifier();
$dom = self::convertToDOM($keyident);
if(!$dom->hasAttribute('EncodingType')) {
throw new Zend_InfoCard_Xml_Exception("Unable to determine the encoding type for the key identifier");
}
return $dom->getAttribute('EncodingType');
}
/**
* Get the key reference data used to identify the public key
*
* @param bool $decode if true, will return a decoded version of the key
* @return string the key reference thumbprint, either in binary or encoded form
* @throws Zend_InfoCard_Xml_Exception
*/
public function getKeyReference($decode = true)
{
$keyIdentifier = $this->_getKeyIdentifier();
$dom = self::convertToDOM($keyIdentifier);
$encoded = $dom->nodeValue;
if(empty($encoded)) {
throw new Zend_InfoCard_Xml_Exception("Could not find the Key Reference Encoded Value");
}
if($decode) {
$decoded = "";
switch($this->getKeyThumbprintEncodingType()) {
case self::ENCODING_BASE64BIN:
if(version_compare(PHP_VERSION, "5.2.0", ">=")) {
$decoded = base64_decode($encoded, true);
} else {
$decoded = base64_decode($encoded);
}
break;
default:
throw new Zend_InfoCard_Xml_Exception("Unknown Key Reference Encoding Type: {$this->getKeyThumbprintEncodingType()}");
}
if(!$decoded || empty($decoded)) {
throw new Zend_InfoCard_Xml_Exception("Failed to decode key reference");
}
return $decoded;
}
return $encoded;
}
}
InfoCard/Cipher/Pki/Adapter/Abstract.php 0000604 00000004731 15071256135 0014030 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Abstract.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Pki_Interface
*/
require_once 'Zend/InfoCard/Cipher/Pki/Interface.php';
/**
* Zend_InfoCard_Cipher_Exception
*/
require_once 'Zend/InfoCard/Cipher/Exception.php';
/**
* An abstract class for public-key ciphers
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Cipher_Pki_Adapter_Abstract implements Zend_InfoCard_Cipher_Pki_Interface
{
/**
* OAEP Padding public key encryption
*/
const OAEP_PADDING = 1;
/**
* No padding public key encryption
*/
const NO_PADDING = 2;
/**
* The type of padding to use
*
* @var integer one of the padding constants in this class
*/
protected $_padding;
/**
* Set the padding of the public key encryption
*
* @throws Zend_InfoCard_Cipher_Exception
* @param integer $padding One of the constnats in this class
* @return Zend_InfoCard_Pki_Adapter_Abstract
*/
public function setPadding($padding)
{
switch($padding) {
case self::OAEP_PADDING:
case self::NO_PADDING:
$this->_padding = $padding;
break;
default:
throw new Zend_InfoCard_Cipher_Exception("Invalid Padding Type Provided");
}
return $this;
}
/**
* Retruns the public-key padding used
*
* @return integer One of the padding constants in this class
*/
public function getPadding()
{
return $this->_padding;
}
}
InfoCard/Cipher/Pki/Adapter/Rsa.php 0000604 00000007543 15071256135 0013016 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Rsa.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Pki_Adapter_Abstract
*/
require_once 'Zend/InfoCard/Cipher/Pki/Adapter/Abstract.php';
/**
* Zend_InfoCard_Cipher_Pki_Rsa_Interface
*/
require_once 'Zend/InfoCard/Cipher/Pki/Rsa/Interface.php';
/**
* RSA Public Key Encryption Cipher Object for the InfoCard component. Relies on OpenSSL
* to implement the RSA algorithm
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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_InfoCard_Cipher_Pki_Adapter_Rsa
extends Zend_InfoCard_Cipher_Pki_Adapter_Abstract
implements Zend_InfoCard_Cipher_Pki_Rsa_Interface
{
/**
* Object Constructor
*
* @param integer $padding The type of Padding to use
*/
public function __construct($padding = Zend_InfoCard_Cipher_Pki_Adapter_Abstract::NO_PADDING)
{
// Can't test this..
// @codeCoverageIgnoreStart
if(!extension_loaded('openssl')) {
throw new Zend_InfoCard_Cipher_Exception("Use of this PKI RSA Adapter requires the openssl extension loaded");
}
// @codeCoverageIgnoreEnd
$this->setPadding($padding);
}
/**
* Decrypts RSA encrypted data using the given private key
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $encryptedData The encrypted data in binary format
* @param string $privateKey The private key in binary format
* @param string $password The private key passphrase
* @param integer $padding The padding to use during decryption (of not provided object value will be used)
* @return string The decrypted data
*/
public function decrypt($encryptedData, $privateKey, $password = null, $padding = null)
{
$private_key = openssl_pkey_get_private(array($privateKey, $password));
if(!$private_key) {
throw new Zend_InfoCard_Cipher_Exception("Failed to load private key");
}
if(!is_null($padding)) {
try {
$this->setPadding($padding);
} catch(Exception $e) {
openssl_free_key($private_key);
throw $e;
}
}
switch($this->getPadding()) {
case self::NO_PADDING:
$openssl_padding = OPENSSL_NO_PADDING;
break;
case self::OAEP_PADDING:
$openssl_padding = OPENSSL_PKCS1_OAEP_PADDING;
break;
}
$result = openssl_private_decrypt($encryptedData, $decryptedData, $private_key, $openssl_padding);
openssl_free_key($private_key);
if(!$result) {
throw new Zend_InfoCard_Cipher_Exception("Unable to Decrypt Value using provided private key");
}
if($this->getPadding() == self::NO_PADDING) {
$decryptedData = substr($decryptedData, 2);
$start = strpos($decryptedData, 0) + 1;
$decryptedData = substr($decryptedData, $start);
}
return $decryptedData;
}
}
InfoCard/Cipher/Pki/Interface.php 0000604 00000002171 15071256135 0012601 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Empty Interface represents a Pki cipher object
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Cipher_Pki_Interface
{
}
InfoCard/Cipher/Pki/Rsa/Interface.php 0000604 00000003564 15071256135 0013335 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_PKI_Adapter_Abstract
*/
require_once 'Zend/InfoCard/Cipher/Pki/Adapter/Abstract.php';
/**
* The interface which defines the RSA Public-key encryption object
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Cipher_Pki_Rsa_Interface
{
/**
* Decrypts RSA encrypted data using the given private key
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $encryptedData The encrypted data in binary format
* @param string $privateKey The private key in binary format
* @param string $password The private key passphrase
* @param integer $padding The padding to use during decryption (of not provided object value will be used)
* @return string The decrypted data
*/
public function decrypt($encryptedData, $privateKey, $password = null, $padding = Zend_InfoCard_Cipher_Pki_Adapter_Abstract::NO_PADDING);
}
InfoCard/Cipher/Exception.php 0000604 00000002260 15071256135 0012113 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Exception
*/
require_once 'Zend/InfoCard/Exception.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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_InfoCard_Cipher_Exception extends Zend_InfoCard_Exception
{
}
InfoCard/Cipher/Symmetric/Interface.php 0000604 00000002115 15071256135 0014030 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Cipher_Symmetric_Interface
{
}
InfoCard/Cipher/Symmetric/Adapter/Aes128cbc.php 0000604 00000002545 15071256135 0015132 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Aes128cbc.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes256cbc.php';
/**
* Implements AES128 with CBC encryption implemented using the mCrypt extension
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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_InfoCard_Cipher_Symmetric_Adapter_Aes128cbc
extends Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
{
}
InfoCard/Cipher/Symmetric/Adapter/Abstract.php 0000604 00000002403 15071256135 0015253 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Abstract.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Interface
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Interface.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
implements Zend_InfoCard_Cipher_Symmetric_Interface
{
}
InfoCard/Cipher/Symmetric/Adapter/Aes256cbc.php 0000604 00000007126 15071256135 0015134 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Aes256cbc.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Abstract.php';
/**
* Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Aes256cbc/Interface.php';
/**
* Zend_InfoCard_Cipher_Exception
*/
require_once 'Zend/InfoCard/Cipher/Exception.php';
/**
* Implements AES256 with CBC encryption implemented using the mCrypt extension
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc
extends Zend_InfoCard_Cipher_Symmetric_Adapter_Abstract
implements Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
{
/**
* The MCRYPT Cipher constant for this encryption
*/
const MCRYPT_CIPHER = MCRYPT_RIJNDAEL_128;
/**
* The MCRYPT Mode constant for this encryption
*/
const MCRYPT_MODE = MCRYPT_MODE_CBC;
/**
* The default length of the IV to use
*/
const IV_LENGTH = 16;
/**
* The object constructor
*
* @throws Zend_InfoCard_Cipher_Exception
*/
public function __construct()
{
// Can't test for this
// @codeCoverageIgnoreStart
if(!extension_loaded('mcrypt')) {
throw new Zend_InfoCard_Cipher_Exception("Use of the AES256CBC Cipher requires the mcrypt extension");
}
// @codeCoveregIgnoreEnd
}
/**
* Decrypts data using the AES Algorithm using the mCrypt extension
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $encryptedData The encrypted data in binary format
* @param string $decryptionKey The decryption key
* @param integer $iv_length The IV length to use
* @return string the decrypted data with any terminating nulls removed
*/
public function decrypt($encryptedData, $decryptionKey, $iv_length = null)
{
$iv_length = is_null($iv_length) ? self::IV_LENGTH : $iv_length;
$mcrypt_iv = null;
if($iv_length > 0) {
$mcrypt_iv = substr($encryptedData, 0, $iv_length);
$encryptedData = substr($encryptedData, $iv_length);
}
$decrypted = mcrypt_decrypt(self::MCRYPT_CIPHER, $decryptionKey, $encryptedData, self::MCRYPT_MODE, $mcrypt_iv);
if(!$decrypted) {
throw new Zend_InfoCard_Cipher_Exception("Failed to decrypt data using AES256CBC Algorithm");
}
$decryptedLength = strlen($decrypted);
$paddingLength = substr($decrypted, $decryptedLength -1, 1);
$decrypted = substr($decrypted, 0, $decryptedLength - ord($paddingLength));
return rtrim($decrypted, "\0");
}
}
InfoCard/Cipher/Symmetric/Aes128cbc/Interface.php 0000604 00000002435 15071256135 0015450 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
*/
require_once 'Zend/InfoCard/Cipher/Symmetric/Aes256cbc/Interface.php';
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Cipher_Symmetric_Aes128cbc_Interface
extends Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
{
}
InfoCard/Cipher/Symmetric/Aes256cbc/Interface.php 0000604 00000002246 15071256135 0015452 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Interface.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_InfoCard_Cipher_Symmetric_Aes256cbc_Interface
{
public function decrypt($encryptedData, $decryptionKey, $iv_length = null);
}
InfoCard/Exception.php 0000604 00000002506 15071256135 0010704 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard
* @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 9094 2008-03-30 18:36:55Z thomas $
*/
if (class_exists("Zend_Exception")) {
abstract class Zend_InfoCard_Exception_Abstract extends Zend_Exception
{
}
} else {
abstract class Zend_InfoCard_Exception_Abstract extends Exception
{
}
}
/**
* Base Exception class for the InfoCard component
*
* @category Zend
* @package Zend_InfoCard
* @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_InfoCard_Exception extends Zend_InfoCard_Exception_Abstract
{
}
InfoCard/Claims.php 0000604 00000020105 15071256135 0010151 0 ustar 00 <?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_InfoCard
* @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: Claims.php 9094 2008-03-30 18:36:55Z thomas $
*/
/**
* Zend_InfoCard_Exception
*/
require_once 'Zend/InfoCard/Exception.php';
/**
* Result value of the InfoCard component, contains any error messages and claims
* from the processing of an information card.
*
* @category Zend
* @package Zend_InfoCard
* @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_InfoCard_Claims
{
/**
* Successful validation and extraion of claims
*/
const RESULT_SUCCESS = 1;
/**
* Indicates there was an error processing the XML document
*/
const RESULT_PROCESSING_FAILURE = 2;
/**
* Indicates that the signature values within the XML document failed verification
*/
const RESULT_VALIDATION_FAILURE = 3;
/**
* The default namespace to assume in these claims
*
* @var string
*/
protected $_defaultNamespace = null;
/**
* A boolean indicating if the claims should be consider "valid" or not based on processing
*
* @var bool
*/
protected $_isValid = true;
/**
* The error message if any
*
* @var string
*/
protected $_error = "";
/**
* An array of claims taken from the information card
*
* @var array
*/
protected $_claims;
/**
* The result code of processing the information card as defined by the constants of this class
*
* @var integer
*/
protected $_code;
/**
* Override for the safeguard which ensures that you don't use claims which failed validation.
* Used in situations when there was a validation error you'd like to ignore
*
* @return Zend_InfoCard_Claims
*/
public function forceValid()
{
trigger_error("Forcing Claims to be valid although it is a security risk", E_USER_WARNING);
$this->_isValid = true;
return $this;
}
/**
* Retrieve the PPI (Private Personal Identifier) associated with the information card
*
* @return string the private personal identifier
*/
public function getCardID()
{
return $this->getClaim('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier');
}
/**
* Retrieves the default namespace used in this information card. If a default namespace was not
* set, it figures out which one to consider 'default' by taking the first namespace sorted by use-count
* in claims
*
* @throws Zend_InfoCard_Exception
* @return string The default namespace
*/
public function getDefaultNamespace()
{
if(is_null($this->_defaultNamespace)) {
$namespaces = array();
$leader = '';
foreach($this->_claims as $claim) {
if(!isset($namespaces[$claim['namespace']])) {
$namespaces[$claim['namespace']] = 1;
} else {
$namespaces[$claim['namespace']]++;
}
if(empty($leader) || ($namespaces[$claim['namespace']] > $leader)) {
$leader = $claim['namespace'];
}
}
if(empty($leader)) {
throw new Zend_InfoCard_Exception("Failed to determine default namespace");
}
$this->setDefaultNamespace($leader);
}
return $this->_defaultNamespace;
}
/**
* Set the default namespace, overriding any existing default
*
* @throws Zend_InfoCard_Exception
* @param string $namespace The default namespace to use
* @return Zend_InfoCard_Claims
*/
public function setDefaultNamespace($namespace)
{
foreach($this->_claims as $claim) {
if($namespace == $claim['namespace']) {
$this->_defaultNamespace = $namespace;
return $this;
}
}
throw new Zend_InfoCard_Exception("At least one claim must exist in specified namespace to make it the default namespace");
}
/**
* Indicates if this claim object contains validated claims or not
*
* @return bool
*/
public function isValid()
{
return $this->_isValid;
}
/**
* Set the error message contained within the claims object
*
* @param string $error The error message
* @return Zend_InfoCard_Claims
*/
public function setError($error)
{
$this->_error = $error;
$this->_isValid = false;
return $this;
}
/**
* Retrieve the error message contained within the claims object
*
* @return string The error message
*/
public function getErrorMsg()
{
return $this->_error;
}
/**
* Set the claims for the claims object. Can only be set once and is done
* by the component itself. Internal use only.
*
* @throws Zend_InfoCard_Exception
* @param array $claims
* @return Zend_InfoCard_Claims
*/
public function setClaims(Array $claims)
{
if(!is_null($this->_claims)) {
throw new Zend_InfoCard_Exception("Claim objects are read-only");
}
$this->_claims = $claims;
return $this;
}
/**
* Set the result code of the claims object.
*
* @throws Zend_InfoCard_Exception
* @param int $code The result code
* @return Zend_InfoCard_Claims
*/
public function setCode($code)
{
switch($code) {
case self::RESULT_PROCESSING_FAILURE:
case self::RESULT_SUCCESS:
case self::RESULT_VALIDATION_FAILURE:
$this->_code = $code;
return $this;
}
throw new Zend_InfoCard_Exception("Attempted to set unknown error code");
}
/**
* Gets the result code of the claims object
*
* @return integer The result code
*/
public function getCode()
{
return $this->_code;
}
/**
* Get a claim by providing its complete claim URI
*
* @param string $claimURI The complete claim URI to retrieve
* @return mixed The claim matching that specific URI or null if not found
*/
public function getClaim($claimURI)
{
if($this->claimExists($claimURI)) {
return $this->_claims[$claimURI]['value'];
}
return null;
}
/**
* Indicates if a specific claim URI exists or not within the object
*
* @param string $claimURI The complete claim URI to check
* @return bool true if the claim exists, false if not found
*/
public function claimExists($claimURI)
{
return isset($this->_claims[$claimURI]);
}
/**
* Magic helper function
* @throws Zend_InfoCard_Exception
*/
public function __unset($k)
{
throw new Zend_InfoCard_Exception("Claim objects are read-only");
}
/**
* Magic helper function
*/
public function __isset($k)
{
return $this->claimExists("{$this->getDefaultNamespace()}/$k");
}
/**
* Magic helper function
*/
public function __get($k)
{
return $this->getClaim("{$this->getDefaultNamespace()}/$k");
}
/**
* Magic helper function
* @throws Zend_InfoCard_Exception
*/
public function __set($k, $v)
{
throw new Zend_InfoCard_Exception("Claim objects are read-only");
}
}
InfoCard/Cipher.php 0000604 00000006625 15071256135 0010166 0 ustar 00 <?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_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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: Cipher.php 11747 2008-10-08 18:33:58Z norm2782 $
*/
/**
* Zend_InfoCard_Cipher_Exception
*/
require_once 'Zend/InfoCard/Cipher/Exception.php';
/**
* Provides an abstraction for encryption ciphers used in an Information Card
* implementation
*
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @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_InfoCard_Cipher
{
/**
* AES 256 Encryption with CBC
*/
const ENC_AES256CBC = 'http://www.w3.org/2001/04/xmlenc#aes256-cbc';
/**
* AES 128 Encryption with CBC
*/
const ENC_AES128CBC = 'http://www.w3.org/2001/04/xmlenc#aes128-cbc';
/**
* RSA Public Key Encryption with OAEP Padding
*/
const ENC_RSA_OAEP_MGF1P = 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p';
/**
* RSA Public Key Encryption with no padding
*/
const ENC_RSA = 'http://www.w3.org/2001/04/xmlenc#rsa-1_5';
/**
* Constructor (disabled)
*
* @return void
* @codeCoverageIgnoreStart
*/
protected function __construct()
{
}
// @codeCoverageIgnoreEnd
/**
* Returns an instance of a cipher object supported based on the URI provided
*
* @throws Zend_InfoCard_Cipher_Exception
* @param string $uri The URI of the encryption method wantde
* @return mixed an Instance of Zend_InfoCard_Cipher_Symmetric_Interface or Zend_InfoCard_Cipher_Pki_Interface
* depending on URI
*/
static public function getInstanceByURI($uri)
{
switch($uri) {
case self::ENC_AES256CBC:
include_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes256cbc.php';
return new Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc();
case self::ENC_AES128CBC:
include_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes128cbc.php';
return new Zend_InfoCard_Cipher_Symmetric_Adapter_Aes128cbc();
case self::ENC_RSA_OAEP_MGF1P:
include_once 'Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php';
return new Zend_InfoCard_Cipher_Pki_Adapter_Rsa(Zend_InfoCard_Cipher_Pki_Adapter_Rsa::OAEP_PADDING);
break;
case self::ENC_RSA:
include_once 'Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php';
return new Zend_InfoCard_Cipher_Pki_Adapter_Rsa(Zend_InfoCard_Cipher_Pki_Adapter_Rsa::NO_PADDING);
break;
default:
throw new Zend_InfoCard_Cipher_Exception("Unknown Cipher URI");
}
}
}
File/Transfer/Exception.php 0000604 00000002747 15071256135 0011671 0 ustar 00 <?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_File_Transfer
* @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: $
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Exception class for Zend_File_Transfer
*
* @category Zend
* @package Zend_File_Transfer
* @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_File_Transfer_Exception extends Zend_Exception
{
protected $_fileerror = null;
public function __construct($message, $fileerror = 0)
{
$this->_fileerror = $fileerror;
parent::__construct($message);
}
/**
* Returns the transfer error code for the exception
* This is not the exception code !!!
*
* @return integer
*/
public function getFileError()
{
return $this->_fileerror;
}
}
File/Transfer/Adapter/Http.php 0000604 00000016430 15071256135 0012224 0 ustar 00 <?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_File_Transfer
* @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: $
*/
require_once 'Zend/File/Transfer/Adapter/Abstract.php';
/**
* File transfer adapter class for the HTTP protocol
*
* @category Zend
* @package Zend_File_Transfer
* @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_File_Transfer_Adapter_Http extends Zend_File_Transfer_Adapter_Abstract
{
/**
* Constructor for Http File Transfers
*
* @param array $options OPTIONAL Options to set
*/
public function __construct($options = array())
{
if (ini_get('file_uploads') == false) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('File uploads are not allowed in your php config!');
}
$this->_files = $this->_prepareFiles($_FILES);
$this->addValidator('Upload', false, $this->_files);
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Sets a validator for the class, erasing all previous set
*
* @param string|array $validator Validator to set
* @param string|array $files Files to limit this validator to
* @return Zend_File_Transfer_Adapter
*/
public function setValidators(array $validators, $files = null)
{
$this->clearValidators();
$this->addValidator('Upload', false, $this->_files);
return $this->addValidators($validators, $files);
}
/**
* Send the file to the client (Download)
*
* @param string|array $options Options for the file(s) to send
* @return void
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function send($options = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Receive the file from the client (Upload)
*
* @param string|array $files (Optional) Files to receive
* @return bool
*/
public function receive($files = null)
{
if (!$this->isValid($files)) {
return false;
}
$check = $this->_getFiles($files);
foreach ($check as $file => $content) {
if (!$content['received']) {
$directory = '';
$destination = $this->getDestination($file);
if ($destination !== null) {
$directory = $destination . DIRECTORY_SEPARATOR;
}
// Should never return false when it's tested by the upload validator
if (!move_uploaded_file($content['tmp_name'], ($directory . $content['name']))) {
if ($content['options']['ignoreNoFile']) {
$this->_files[$file]['received'] = true;
$this->_files[$file]['filtered'] = true;
continue;
}
$this->_files[$file]['received'] = false;
return false;
}
$this->_files[$file]['received'] = true;
}
if (!$content['filtered']) {
if (!$this->_filter($file)) {
$this->_files[$file]['filtered'] = false;
return false;
}
$this->_files[$file]['filtered'] = true;
}
}
return true;
}
/**
* Checks if the file was already sent
*
* @param string|array $file Files to check
* @return bool
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function isSent($files = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Checks if the file was already received
*
* @param string|array $files (Optional) Files to check
* @return bool
*/
public function isReceived($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $content) {
if ($content['received'] !== true) {
return false;
}
}
return true;
}
/**
* Checks if the file was already filtered
*
* @param string|array $files (Optional) Files to check
* @return bool
*/
public function isFiltered($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $content) {
if ($content['filtered'] !== true) {
return false;
}
}
return true;
}
/**
* Has a file been uploaded ?
*
* @param array|string|null $file
* @return bool
*/
public function isUploaded($files = null)
{
$files = $this->_getFiles($files);
foreach ($files as $file) {
if (empty($file['name'])) {
return false;
}
}
return true;
}
/**
* Returns the actual progress of file up-/downloads
*
* @return string Returns the state
* @return int
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function getProgress()
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Prepare the $_FILES array to match the internal syntax of one file per entry
*
* @param array $files
* @return array
*/
protected function _prepareFiles(array $files = array())
{
$result = array();
foreach ($files as $form => $content) {
if (is_array($content['name'])) {
foreach ($content as $param => $file) {
foreach ($file as $number => $target) {
$result[$form . '_' . $number . '_'][$param] = $target;
$result[$form . '_' . $number . '_']['options'] = $this->_options;
$result[$form . '_' . $number . '_']['validated'] = false;
$result[$form . '_' . $number . '_']['received'] = false;
$result[$form . '_' . $number . '_']['filtered'] = false;
}
}
} else {
$result[$form] = $content;
$result[$form]['options'] = $this->_options;
$result[$form]['validated'] = false;
$result[$form]['received'] = false;
$result[$form]['filtered'] = false;
}
}
return $result;
}
}
File/Transfer/Adapter/Abstract.php 0000604 00000117405 15071256135 0013054 0 ustar 00 <?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_File_Transfer
* @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: $
*/
/**
* Abstract class for file transfers (Downloads and Uploads)
*
* @category Zend
* @package Zend_File_Transfer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_File_Transfer_Adapter_Abstract
{
/**@+
* @const string Plugin loader Constants
*/
const FILTER = 'FILTER';
const VALIDATE = 'VALIDATE';
/**@-*/
/**
* Internal list of breaks
*
* @var array
*/
protected $_break = array();
/**
* Internal list of filters
*
* @var array
*/
protected $_filters = array();
/**
* Plugin loaders for filter and validation chains
*
* @var array
*/
protected $_loaders = array();
/**
* Internal list of messages
*
* @var array
*/
protected $_messages = array();
/**
* @var Zend_Translate
*/
protected $_translator;
/**
* Is translation disabled?
*
* @var bool
*/
protected $_translatorDisabled = false;
/**
* Internal list of validators
* @var array
*/
protected $_validators = array();
/**
* Internal list of files
* This array looks like this:
* array(form => array( - Form is the name within the form or, if not set the filename
* name, - Original name of this file
* type, - Mime type of this file
* size, - Filesize in bytes
* tmp_name, - Internalally temporary filename for uploaded files
* error, - Error which has occured
* destination, - New destination for this file
* validators, - Set validator names for this file
* files - Set file names for this file
* ))
*
* @var array
*/
protected $_files = array();
/**
* TMP directory
* @var string
*/
protected $_tmpDir;
/**
* Available options for file transfers
*/
protected $_options = array(
'ignoreNoFile' => false
);
/**
* Send file
*
* @param mixed $options
* @return bool
*/
abstract public function send($options = null);
/**
* Receive file
*
* @param mixed $options
* @return bool
*/
abstract public function receive($options = null);
/**
* Is file sent?
*
* @param array|string|null $files
* @return bool
*/
abstract public function isSent($files = null);
/**
* Is file received?
*
* @param array|string|null $files
* @return bool
*/
abstract public function isReceived($files = null);
/**
* Has a file been uploaded ?
*
* @param array|string|null $files
* @return bool
*/
abstract public function isUploaded($files = null);
/**
* Has the file been filtered ?
*
* @param array|string|null $files
* @return bool
*/
abstract public function isFiltered($files = null);
/**
* Retrieve progress of transfer
*
* @return float
*/
abstract public function getProgress();
/**
* Set plugin loader to use for validator or filter chain
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type 'filter', or 'validate'
* @return Zend_File_Transfer_Adapter_Abstract
* @throws Zend_File_Transfer_Exception on invalid type
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
{
$type = strtoupper($type);
switch ($type) {
case self::FILTER:
case self::VALIDATE:
$this->_loaders[$type] = $loader;
return $this;
default:
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));
}
}
/**
* Retrieve plugin loader for validator or filter chain
*
* Instantiates with default rules if none available for that type. Use
* 'filter' or 'validate' for $type.
*
* @param string $type
* @return Zend_Loader_PluginLoader
* @throws Zend_File_Transfer_Exception on invalid type.
*/
public function getPluginLoader($type)
{
$type = strtoupper($type);
switch ($type) {
case self::FILTER:
case self::VALIDATE:
$prefixSegment = ucfirst(strtolower($type));
$pathSegment = $prefixSegment;
if (!isset($this->_loaders[$type])) {
$paths = array(
'Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/',
'Zend_' . $prefixSegment . '_File' => 'Zend/' . $pathSegment . '/File',
);
require_once 'Zend/Loader/PluginLoader.php';
$this->_loaders[$type] = new Zend_Loader_PluginLoader($paths);
} else {
$loader = $this->_loaders[$type];
$prefix = 'Zend_' . $prefixSegment . '_File_';
if (!$loader->getPaths($prefix)) {
$loader->addPrefixPath($prefix, str_replace('_', '/', $prefix));
}
}
return $this->_loaders[$type];
default:
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
}
/**
* Add prefix path for plugin loader
*
* If no $type specified, assumes it is a base path for both filters and
* validators, and sets each according to the following rules:
* - filters: $prefix = $prefix . '_Filter'
* - validators: $prefix = $prefix . '_Validate'
*
* Otherwise, the path prefix is set on the appropriate plugin loader.
*
* @param string $path
* @return Zend_File_Transfer_Adapter_Abstract
* @throws Zend_File_Transfer_Exception for invalid type
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case self::FILTER:
case self::VALIDATE:
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
case null:
$prefix = rtrim($prefix, '_');
$path = rtrim($path, DIRECTORY_SEPARATOR);
foreach (array(self::FILTER, self::VALIDATE) as $type) {
$cType = ucfirst(strtolower($type));
$pluginPath = $path . DIRECTORY_SEPARATOR . $cType . DIRECTORY_SEPARATOR;
$pluginPrefix = $prefix . '_' . $cType;
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
}
return $this;
default:
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
}
/**
* Add many prefix paths at once
*
* @param array $spec
* @return Zend_File_Transfer_Exception
*/
public function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
return $this->addPrefixPath($spec['prefix'], $spec['path']);
}
foreach ($spec as $type => $paths) {
if (is_numeric($type) && is_array($paths)) {
$type = null;
if (isset($paths['prefix']) && isset($paths['path'])) {
if (isset($paths['type'])) {
$type = $paths['type'];
}
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
} elseif (!is_numeric($type)) {
if (!isset($paths['prefix']) || !isset($paths['path'])) {
foreach ($paths as $prefix => $spec) {
if (is_array($spec)) {
foreach ($spec as $path) {
if (!is_string($path)) {
continue;
}
$this->addPrefixPath($prefix, $path, $type);
}
} elseif (is_string($spec)) {
$this->addPrefixPath($prefix, $spec, $type);
}
}
} else {
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
}
}
return $this;
}
/**
* Adds a new validator for this class
*
* @param string|array $validator Type of validator to add
* @param boolean $breakChainOnFailure If the validation chain should stop an failure
* @param string|array $options Options to set for the validator
* @param string|array $files Files to limit this validator to
* @return Zend_File_Transfer_Adapter
*/
public function addValidator($validator, $breakChainOnFailure = false, $options = null, $files = null)
{
if ($validator instanceof Zend_Validate_Interface) {
$name = get_class($validator);
} elseif (is_string($validator)) {
$name = $this->getPluginLoader(self::VALIDATE)->load($validator);
$validator = new $name($options);
} else {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Invalid validator provided to addValidator; must be string or Zend_Validate_Interface');
}
$this->_validators[$name] = $validator;
$this->_break[$name] = $breakChainOnFailure;
$files = $this->_getFiles($files, true, true);
foreach ($files as $file) {
$this->_files[$file]['validators'][] = $name;
$this->_files[$file]['validated'] = false;
}
return $this;
}
/**
* Add Multiple validators at once
*
* @param array $validators
* @param string|array $files
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function addValidators(array $validators, $files = null)
{
foreach ($validators as $name => $validatorInfo) {
if ($validatorInfo instanceof Zend_Validate_Interface) {
$this->addValidator($validatorInfo, null, null, $files);
} else if (is_string($validatorInfo)) {
if (!is_int($name)) {
$this->addValidator($name, null, $validatorInfo, $files);
} else {
$this->addValidator($validatorInfo, null, null, $files);
}
} else if (is_array($validatorInfo)) {
$argc = count($validatorInfo);
$breakChainOnFailure = false;
$options = array();
if (isset($validatorInfo['validator'])) {
$validator = $validatorInfo['validator'];
if (isset($validatorInfo['breakChainOnFailure'])) {
$breakChainOnFailure = $validatorInfo['breakChainOnFailure'];
}
if (isset($validatorInfo['options'])) {
$options = $validatorInfo['options'];
}
$this->addValidator($validator, $breakChainOnFailure, $options, $files);
} else {
if (is_string($name)) {
$validator = $name;
$options = $validatorInfo;
$this->addValidator($validator, $breakChainOnFailure, $options, $files);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$validator = array_shift($validatorInfo);
case (2 <= $argc):
$breakChainOnFailure = array_shift($validatorInfo);
case (3 <= $argc):
$options = array_shift($validatorInfo);
case (4 <= $argc):
$files = array_shift($validatorInfo);
default:
$this->addValidator($validator, $breakChainOnFailure, $options, $files);
break;
}
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid validator passed to addValidators()');
}
}
return $this;
}
/**
* Sets a validator for the class, erasing all previous set
*
* @param string|array $validator Validator to set
* @param string|array $files Files to limit this validator to
* @return Zend_File_Transfer_Adapter
*/
public function setValidators(array $validators, $files = null)
{
$this->clearValidators();
return $this->addValidators($validators, $files);
}
/**
* Determine if a given validator has already been registered
*
* @param string $name
* @return bool
*/
public function hasValidator($name)
{
return (false !== $this->_getValidatorIdentifier($name));
}
/**
* Retrieve individual validator
*
* @param string $name
* @return Zend_Validate_Interface|null
*/
public function getValidator($name)
{
if (false === ($identifier = $this->_getValidatorIdentifier($name))) {
return null;
}
return $this->_validators[$identifier];
}
/**
* Returns all set validators
*
* @param string|array $files (Optional) Returns the validator for this files
* @return null|array List of set validators
*/
public function getValidators($files = null)
{
$files = $this->_getFiles($files, true, true);
if (empty($files)) {
return $this->_validators;
}
$validators = array();
foreach ($files as $file) {
if (!empty($this->_files[$file]['validators'])) {
$validators += $this->_files[$file]['validators'];
}
}
$validators = array_unique($validators);
$result = array();
foreach ($validators as $validator) {
$result[$validator] = $this->_validators[$validator];
}
return $result;
}
/**
* Remove an individual validator
*
* @param string $name
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function removeValidator($name)
{
if (false === ($key = $this->_getValidatorIdentifier($name))) {
return $this;
}
unset($this->_validators[$key]);
foreach (array_keys($this->_files) as $file) {
if (!$index = array_search($key, $this->_files[$file]['validators'])) {
continue;
}
unset($this->_files[$file]['validators'][$index]);
$this->_files[$file]['validated'] = false;
}
return $this;
}
/**
* Remove all validators
*
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function clearValidators()
{
$this->_validators = array();
foreach (array_keys($this->_files) as $file) {
$this->_files[$file]['validators'] = array();
$this->_files[$file]['validated'] = false;
}
return $this;
}
/**
* Sets Options for adapters
*
* @param array $options Options to set
* @param array $files (Optional) Files to set the options for
*/
public function setOptions($options = array(), $files = null) {
$file = $this->_getFiles($files, false, true);
if (is_array($options)) {
foreach ($options as $name => $value) {
foreach ($file as $key => $content) {
if (array_key_exists($name, $this->_options)) {
$this->_files[$key]['options'][$name] = (boolean) $value;
} else {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception("Unknown option: $name = $value");
}
}
}
}
return $this;
}
/**
* Returns set options for adapters or files
*
* @param array $files (Optional) Files to return the options for
* @return array Options for given files
*/
public function getOptions($files = null) {
$file = $this->_getFiles($files, false, true);
foreach ($file as $key => $content) {
if (isset($this->_files[$key]['options'])) {
$options[$key] = $this->_files[$key]['options'];
} else {
$options[$key] = array();
}
}
return $options;
}
/**
* Checks if the files are valid
*
* @param string|array $files (Optional) Files to check
* @return boolean True if all checks are valid
*/
public function isValid($files = null)
{
$check = $this->_getFiles($files);
$translator = $this->getTranslator();
$this->_messages = array();
$break = false;
foreach ($check as $key => $content) {
$fileerrors = array();
if ($content['validated'] === true) {
continue;
}
if (array_key_exists('validators', $content)) {
foreach ($content['validators'] as $class) {
$validator = $this->_validators[$class];
if (method_exists($validator, 'setTranslator')) {
$validator->setTranslator($translator);
}
$tocheck = $content['tmp_name'];
if (($class === 'Zend_Validate_File_Upload') and (empty($content['tmp_name']))) {
$tocheck = $key;
}
if (!$validator->isValid($tocheck, $content)) {
$fileerrors += $validator->getMessages();
}
if (!empty($content['options']['ignoreNoFile']) and (isset($fileerrors['fileUploadErrorNoFile']))) {
unset($fileerrors['fileUploadErrorNoFile']);
break;
}
if (($class === 'Zend_Validate_File_Upload') and (count($fileerrors) > 0)) {
break;
}
if (($this->_break[$class]) and (count($fileerrors) > 0)) {
$break = true;
break;
}
}
}
if (count($fileerrors) > 0) {
$this->_files[$key]['validated'] = false;
} else {
$this->_files[$key]['validated'] = true;
}
$this->_messages += $fileerrors;
if ($break) {
break;
}
}
if (count($this->_messages) > 0) {
return false;
}
return true;
}
/**
* Returns found validation messages
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
/**
* Retrieve error codes
*
* @return array
*/
public function getErrors()
{
return array_keys($this->_messages);
}
/**
* Are there errors registered?
*
* @return boolean
*/
public function hasErrors()
{
return (!empty($this->_messages));
}
/**
* Adds a new filter for this class
*
* @param string|array $filter Type of filter to add
* @param string|array $options Options to set for the filter
* @param string|array $files Files to limit this filter to
* @return Zend_File_Transfer_Adapter
*/
public function addFilter($filter, $options = null, $files = null)
{
if ($filter instanceof Zend_Filter_Interface) {
$class = get_class($filter);
} elseif (is_string($filter)) {
$class = $this->getPluginLoader(self::FILTER)->load($filter);
$filter = new $class($options);
} else {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Invalid filter specified');
}
$this->_filters[$class] = $filter;
$files = $this->_getFiles($files, true, true);
foreach ($files as $file) {
$this->_files[$file]['filters'][] = $class;
}
return $this;
}
/**
* Add Multiple filters at once
*
* @param array $filters
* @param string|array $files
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function addFilters(array $filters, $files = null)
{
foreach ($filters as $key => $spec) {
if ($spec instanceof Zend_Filter_Interface) {
$this->addFilter($spec, null, $files);
continue;
}
if (is_string($key)) {
$this->addFilter($key, $spec, $files);
continue;
}
if (is_int($key)) {
if (is_string($spec)) {
$this->addFilter($spec, null, $files);
continue;
}
if (is_array($spec)) {
if (!array_key_exists('filter', $spec)) {
continue;
}
$filter = $spec['filter'];
unset($spec['filter']);
$this->addFilter($filter, $spec, $files);
continue;
}
continue;
}
}
return $this;
}
/**
* Sets a filter for the class, erasing all previous set
*
* @param string|array $filter Filter to set
* @param string|array $files Files to limit this filter to
* @return Zend_File_Transfer_Adapter
*/
public function setFilters(array $filters, $files = null)
{
$this->clearFilters();
return $this->addFilters($filters, $files);
}
/**
* Determine if a given filter has already been registered
*
* @param string $name
* @return bool
*/
public function hasFilter($name)
{
return (false !== $this->_getFilterIdentifier($name));
}
/**
* Retrieve individual filter
*
* @param string $name
* @return Zend_Filter_Interface|null
*/
public function getFilter($name)
{
if (false === ($identifier = $this->_getFilterIdentifier($name))) {
return null;
}
return $this->_filters[$identifier];
}
/**
* Returns all set filters
*
* @param string|array $files (Optional) Returns the filter for this files
* @return array List of set filters
* @throws Zend_File_Transfer_Exception When file not found
*/
public function getFilters($files = null)
{
if ($files === null) {
return $this->_filters;
}
$files = $this->_getFiles($files, true, true);
$filters = array();
foreach ($files as $file) {
if (!empty($this->_files[$file]['filters'])) {
$filters += $this->_files[$file]['filters'];
}
}
$filters = array_unique($filters);
$result = array();
foreach ($filters as $filter) {
$result[] = $this->_filters[$filter];
}
return $result;
}
/**
* Remove an individual filter
*
* @param string $name
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function removeFilter($name)
{
if (false === ($key = $this->_getFilterIdentifier($name))) {
return $this;
}
unset($this->_filters[$key]);
foreach (array_keys($this->_files) as $file) {
if (!$index = array_search($key, $this->_files[$file]['filters'])) {
continue;
}
unset($this->_files[$file]['filters'][$index]);
}
return $this;
}
/**
* Remove all filters
*
* @return Zend_File_Transfer_Adapter_Abstract
*/
public function clearFilters()
{
$this->_filters = array();
foreach (array_keys($this->_files) as $file) {
$this->_files[$file]['filters'] = array();
}
return $this;
}
/**
* Returns all set files
*
* @return array List of set files
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function getFile()
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Retrieves the filename of transferred files.
*
* @param string $fileelement (Optional) Element to return the filename for
* @param boolean $path (Optional) Should the path also be returned ?
* @return string|array
*/
public function getFileName($file = null, $path = true)
{
$files = $this->_getFiles($file, true, true);
$result = array();
$directory = "";
foreach($files as $file) {
if (empty($this->_files[$file]['name'])) {
continue;
}
if ($path === true) {
$directory = $this->getDestination($file) . DIRECTORY_SEPARATOR;
}
$result[$file] = $directory . $this->_files[$file]['name'];
}
if (count($result) == 1) {
return current($result);
}
return $result;
}
/**
* Retrieve additional internal file informations for files
*
* @param string $file (Optional) File to get informations for
* @return array
*/
public function getFileInfo($file = null)
{
return $this->_getFiles($file);
}
/**
* Adds one or more files
*
* @param string|array $file File to add
* @param string|array $validator Validators to use for this file, must be set before
* @param string|array $filter Filters to use for this file, must be set before
* @return Zend_File_Transfer_Adapter_Abstract
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function addFile($file, $validator = null, $filter = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Returns all set types
*
* @return array List of set types
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function getType()
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Adds one or more type of files
*
* @param string|array $type Type of files to add
* @param string|array $validator Validators to use for this file, must be set before
* @param string|array $filter Filters to use for this file, must be set before
* @return Zend_File_Transfer_Adapter_Abstract
* @throws Zend_File_Transfer_Exception Not implemented
*/
public function addType($type, $validator = null, $filter = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Method not implemented');
}
/**
* Sets a new destination for the given files
*
* @deprecated Will be changed to be a filter!!!
* @param string $destination New destination directory
* @param string|array $files Files to set the new destination for
* @return Zend_File_Transfer_Abstract
* @throws Zend_File_Transfer_Exception when the given destination is not a directory or does not exist
*/
public function setDestination($destination, $files = null)
{
$orig = $files;
$destination = rtrim($destination, "/\\");
if (!is_dir($destination)) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('The given destination is no directory or does not exist');
}
if (!is_writable($destination)) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('The given destination is not writeable');
}
if ($files === null) {
foreach ($this->_files as $file => $content) {
$this->_files[$file]['destination'] = $destination;
}
} else {
$files = $this->_getFiles($files, true, true);
if (empty($this->_files) and is_string($orig)) {
$this->_files[$orig]['destination'] = $destination;
}
foreach ($files as $file) {
$this->_files[$file]['destination'] = $destination;
}
}
return $this;
}
/**
* Retrieve destination directory value
*
* @param null|string|array $files
* @return null|string|array
*/
public function getDestination($files = null)
{
$files = $this->_getFiles($files, false);
$destinations = array();
foreach ($files as $key => $content) {
if (isset($this->_files[$key]['destination'])) {
$destinations[$key] = $this->_files[$key]['destination'];
} else {
$tmpdir = $this->_getTmpDir();
$this->setDestination($tmpdir, $key);
$destinations[$key] = $tmpdir;
}
}
if (empty($destinations)) {
$destinations = $this->_getTmpDir();
} else if (count($destinations) == 1) {
$destinations = current($destinations);
}
return $destinations;
}
/**
* Set translator object for localization
*
* @param Zend_Translate|null $translator
* @return Zend_File_Transfer_Abstract
*/
public function setTranslator($translator = null)
{
if (null === $translator) {
$this->_translator = null;
} elseif ($translator instanceof Zend_Translate_Adapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Invalid translator specified');
}
return $this;
}
/**
* Retrieve localization translator object
*
* @return Zend_Translate_Adapter|null
*/
public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
return $this->_translator;
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_File_Transfer_Abstract
*/
public function setDisableTranslator($flag)
{
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
return $this->_translatorDisabled;
}
/**
* Returns the hash for a given file
*
* @param string $hash Hash algorithm to use
* @param string|array $files Files to return the hash for
* @return string|array Hashstring
* @throws Zend_File_Transfer_Exception On unknown hash algorithm
*/
public function getHash($hash = 'crc32', $files = null)
{
if (!in_array($hash, hash_algos())) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Unknown hash algorithm');
}
$files = $this->_getFiles($files);
$result = array();
foreach($files as $key => $value) {
if (file_exists($value['name'])) {
$result[$key] = hash_file($hash, $value['name']);
} else if (file_exists($value['tmp_name'])) {
$result[$key] = hash_file($hash, $value['tmp_name']);
}
}
if (count($result) == 1) {
return current($result);
}
return $result;
}
/**
* Internal function to filter all given files
*
* @param string|array $files (Optional) Files to check
* @return boolean False on error
*/
protected function _filter($files = null)
{
$check = $this->_getFiles($files);
foreach ($check as $name => $content) {
if (array_key_exists('filters', $content)) {
foreach ($content['filters'] as $class) {
$filter = $this->_filters[$class];
try {
$result = $filter->filter($this->getFileName($name));
$this->_files[$name]['destination'] = dirname($result);
$this->_files[$name]['name'] = basename($result);
} catch (Zend_Filter_Exception $e) {
$this->_messages += array($e->getMessage());
}
}
}
}
if (count($this->_messages) > 0) {
return false;
}
return true;
}
/**
* Determine system TMP directory and detect if we have read access
*
* @return string
* @throws Zend_File_Transfer_Exception if unable to determine directory
*/
protected function _getTmpDir()
{
if (null === $this->_tmpDir) {
$tmpdir = array();
if (function_exists('sys_get_temp_dir')) {
$tmpdir[] = sys_get_temp_dir();
}
if (!empty($_ENV['TMP'])) {
$tmpdir[] = realpath($_ENV['TMP']);
}
if (!empty($_ENV['TMPDIR'])) {
$tmpdir[] = realpath($_ENV['TMPDIR']);
}
if (!empty($_ENV['TEMP'])) {
$tmpdir[] = realpath($_ENV['TEMP']);
}
$upload = ini_get('upload_tmp_dir');
if ($upload) {
$tmpdir[] = realpath($upload);
}
foreach($tmpdir as $directory) {
if ($this->_isPathWriteable($directory)) {
$this->_tmpDir = $directory;
}
}
if (empty($this->_tmpDir)) {
// Attemp to detect by creating a temporary file
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
if ($tempFile) {
$this->_tmpDir = realpath(dirname($tempFile));
unlink($tempFile);
} else {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Could not determine temp directory');
}
}
$this->_tmpDir = rtrim($this->_tmpDir, "/\\");
}
return $this->_tmpDir;
}
/**
* Tries to detect if we can read and write to the given path
*
* @param string $path
*/
protected function _isPathWriteable($path)
{
$tempFile = rtrim($path, "/\\");
$tempFile .= '/' . 'test.1';
$result = @file_put_contents($tempFile, 'TEST');
if ($result == false) {
return false;
}
$result = @unlink($tempFile);
if ($result == false) {
return false;
}
return true;
}
/**
* Returns found files based on internal file array and given files
*
* @param string|array $files (Optional) Files to return
* @param boolean $names (Optional) Returns only names on true, else complete info
* @param boolean $noexception (Optional) Allows throwing an exception, otherwise returns an empty array
* @return array Found files
* @throws Zend_File_Transfer_Exception On false filename
*/
protected function _getFiles($files, $names = false, $noexception = false)
{
$check = array();
if (is_string($files)) {
$files = array($files);
}
if (is_array($files)) {
foreach ($files as $find) {
$found = array();
foreach ($this->_files as $file => $content) {
if ($file === $find) {
$found[] = $file;
break;
}
if (strpos($file, ($find . '_')) !== false) {
$found[] = $file;
}
if (!isset($content['name'])) {
continue;
}
if ($content['name'] === $find) {
$found[] = $file;
break;
}
}
if (empty($found)) {
if ($noexception !== false) {
return array();
}
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception(sprintf('"%s" not found by file transfer adapter', $find));
}
foreach ($found as $checked) {
$check[$checked] = $this->_files[$checked];
}
}
}
if ($files === null) {
$check = $this->_files;
}
if ($names) {
$check = array_keys($check);
}
return $check;
}
/**
* Retrieve internal identifier for a named validator
*
* @param string $name
* @return string
*/
protected function _getValidatorIdentifier($name)
{
if (array_key_exists($name, $this->_validators)) {
return $name;
}
foreach (array_keys($this->_validators) as $test) {
if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
return $test;
}
}
return false;
}
/**
* Retrieve internal identifier for a named filter
*
* @param string $name
* @return string
*/
protected function _getFilterIdentifier($name)
{
if (array_key_exists($name, $this->_filters)) {
return $name;
}
foreach (array_keys($this->_filters) as $test) {
if (preg_match('/' . preg_quote($name) . '$/i', $test)) {
return $test;
}
}
return false;
}
}
File/Transfer.php 0000604 00000003522 15071256135 0007723 0 ustar 00 <?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_File_Transfer
* @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: $
*/
/**
* Base class for all protocols supporting file transfers
*
* @category Zend
* @package Zend_File_Transfer
* @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_File_Transfer
{
/**
* Creates a file processing handler
*
* @param string $protocol Protocol to use
*/
public function __construct($protocol = null)
{
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception('Implementation in progress');
switch (strtoupper($protocol)) {
default:
$adapter = 'Zend_File_Transfer_Adapter_Http';
break;
}
Zend_Loader::loadClass($adapter);
$this->_adapter = new $adapter();
if (!$this->_adapter instanceof Zend_File_Transfer_Adapter) {
require_once 'Zend/File/Transfer/Exception.php';
throw new Zend_File_Transfer_Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter'");
}
return $this->_adapter;
}
}
XmlRpc/Server.php 0000604 00000040376 15071256135 0007743 0 ustar 00 <?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_XmlRpc
* @subpackage Server
* @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: Server.php 12195 2008-10-30 13:34:35Z matthew $
*/
/**
* Extends Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
/**
* Exception this class throws
*/
require_once 'Zend/XmlRpc/Server/Exception.php';
/**
* XMLRPC Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XMLRPC Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* XMLRPC HTTP Response
*/
require_once 'Zend/XmlRpc/Response/Http.php';
/**
* XMLRPC server fault class
*/
require_once 'Zend/XmlRpc/Server/Fault.php';
/**
* XMLRPC server system methods class
*/
require_once 'Zend/XmlRpc/Server/System.php';
/**
* Convert PHP to and from xmlrpc native types
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Reflection API for function/method introspection
*/
require_once 'Zend/Server/Reflection.php';
/**
* Zend_Server_Reflection_Function_Abstract
*/
require_once 'Zend/Server/Reflection/Function/Abstract.php';
/**
* Specifically grab the Zend_Server_Reflection_Method for manually setting up
* system.* methods and handling callbacks in {@link loadFunctions()}.
*/
require_once 'Zend/Server/Reflection/Method.php';
/**
* An XML-RPC server implementation
*
* Example:
* <code>
* require_once 'Zend/XmlRpc/Server.php';
* require_once 'Zend/XmlRpc/Server/Cache.php';
* require_once 'Zend/XmlRpc/Server/Fault.php';
* require_once 'My/Exception.php';
* require_once 'My/Fault/Observer.php';
*
* // Instantiate server
* $server = new Zend_XmlRpc_Server();
*
* // Allow some exceptions to report as fault responses:
* Zend_XmlRpc_Server_Fault::attachFaultException('My_Exception');
* Zend_XmlRpc_Server_Fault::attachObserver('My_Fault_Observer');
*
* // Get or build dispatch table:
* if (!Zend_XmlRpc_Server_Cache::get($filename, $server)) {
* require_once 'Some/Service/Class.php';
* require_once 'Another/Service/Class.php';
*
* // Attach Some_Service_Class in 'some' namespace
* $server->setClass('Some_Service_Class', 'some');
*
* // Attach Another_Service_Class in 'another' namespace
* $server->setClass('Another_Service_Class', 'another');
*
* // Create dispatch table cache file
* Zend_XmlRpc_Server_Cache::save($filename, $server);
* }
*
* $response = $server->handle();
* echo $response;
* </code>
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @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_XmlRpc_Server extends Zend_Server_Abstract
{
/**
* Character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Request processed
* @var null|Zend_XmlRpc_Request
*/
protected $_request = null;
/**
* Class to use for responses; defaults to {@link Zend_XmlRpc_Response_Http}
* @var string
*/
protected $_responseClass = 'Zend_XmlRpc_Response_Http';
/**
* Dispatch table of name => method pairs
* @var Zend_XmlRpc_Server_ServerDefinition
*/
protected $_table;
/**
* PHP types => XML-RPC types
* @var array
*/
protected $_typeMap = array(
'i4' => 'i4',
'int' => 'int',
'integer' => 'int',
'double' => 'double',
'float' => 'double',
'real' => 'double',
'boolean' => 'boolean',
'bool' => 'boolean',
'true' => 'boolean',
'false' => 'boolean',
'string' => 'string',
'str' => 'string',
'base64' => 'base64',
'dateTime.iso8601' => 'dateTime.iso8601',
'date' => 'dateTime.iso8601',
'time' => 'dateTime.iso8601',
'time' => 'dateTime.iso8601',
'array' => 'array',
'struct' => 'struct',
'null' => 'nil',
'nil' => 'nil',
'void' => 'void',
'mixed' => 'struct'
);
/**
* Constructor
*
* Creates system.* methods.
*
* @return void
*/
public function __construct()
{
$this->_table = new Zend_Server_Definition();
$this->_registerSystemMethods();
}
/**
* Proxy calls to system object
*
* @param string $method
* @param array $params
* @return mixed
* @throws Zend_XmlRpc_Server_Exception
*/
public function __call($method, $params)
{
$system = $this->getSystem();
if (!method_exists($system, $method)) {
throw new Zend_XmlRpc_Server_Exception('Unknown instance method called on server: ' . $method);
}
return call_user_func_array(array($system, $method), $params);
}
/**
* Attach a callback as an XMLRPC method
*
* Attaches a callback as an XMLRPC method, prefixing the XMLRPC method name
* with $namespace, if provided. Reflection is done on the callback's
* docblock to create the methodHelp for the XMLRPC method.
*
* Additional arguments to pass to the function at dispatch may be passed;
* any arguments following the namespace will be aggregated and passed at
* dispatch time.
*
* @param string|array $function Valid callback
* @param string $namespace Optional namespace prefix
* @return void
* @throws Zend_XmlRpc_Server_Exception
*/
public function addFunction($function, $namespace = '')
{
if (!is_string($function) && !is_array($function)) {
throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611);
}
$argv = null;
if (2 < func_num_args()) {
$argv = func_get_args();
$argv = array_slice($argv, 2);
}
$function = (array) $function;
foreach ($function as $func) {
if (!is_string($func) || !function_exists($func)) {
throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611);
}
$reflection = Zend_Server_Reflection::reflectFunction($func, $argv, $namespace);
$this->_buildSignature($reflection);
}
}
/**
* Attach class methods as XMLRPC method handlers
*
* $class may be either a class name or an object. Reflection is done on the
* class or object to determine the available public methods, and each is
* attached to the server as an available method; if a $namespace has been
* provided, that namespace is used to prefix the XMLRPC method names.
*
* Any additional arguments beyond $namespace will be passed to a method at
* invocation.
*
* @param string|object $class
* @param string $namespace Optional
* @param mixed $argv Optional arguments to pass to methods
* @return void
* @throws Zend_XmlRpc_Server_Exception on invalid input
*/
public function setClass($class, $namespace = '', $argv = null)
{
if (is_string($class) && !class_exists($class)) {
if (!class_exists($class)) {
throw new Zend_XmlRpc_Server_Exception('Invalid method class', 610);
}
}
$argv = null;
if (3 < func_num_args()) {
$argv = func_get_args();
$argv = array_slice($argv, 3);
}
$dispatchable = Zend_Server_Reflection::reflectClass($class, $argv, $namespace);
foreach ($dispatchable->getMethods() as $reflection) {
$this->_buildSignature($reflection, $class);
}
}
/**
* Raise an xmlrpc server fault
*
* @param string|Exception $fault
* @param int $code
* @return Zend_XmlRpc_Server_Fault
*/
public function fault($fault = null, $code = 404)
{
if (!$fault instanceof Exception) {
$fault = (string) $fault;
if (empty($fault)) {
$fault = 'Unknown error';
}
$fault = new Zend_XmlRpc_Server_Exception($fault, $code);
}
return Zend_XmlRpc_Server_Fault::getInstance($fault);
}
/**
* Handle an xmlrpc call
*
* @param Zend_XmlRpc_Request $request Optional
* @return Zend_XmlRpc_Response|Zend_XmlRpc_Fault
*/
public function handle($request = false)
{
// Get request
if ((!$request || !$request instanceof Zend_XmlRpc_Request)
&& (null === ($request = $this->getRequest()))
) {
require_once 'Zend/XmlRpc/Request/Http.php';
$request = new Zend_XmlRpc_Request_Http();
$request->setEncoding($this->getEncoding());
}
$this->setRequest($request);
if ($request->isFault()) {
$response = $request->getFault();
} else {
try {
$response = $this->_handle($request);
} catch (Exception $e) {
$response = $this->fault($e);
}
}
// Set output encoding
$response->setEncoding($this->getEncoding());
return $response;
}
/**
* Load methods as returned from {@link getFunctions}
*
* Typically, you will not use this method; it will be called using the
* results pulled from {@link Zend_XmlRpc_Server_Cache::get()}.
*
* @param array|Zend_Server_Definition $definition
* @return void
* @throws Zend_XmlRpc_Server_Exception on invalid input
*/
public function loadFunctions($definition)
{
if (!is_array($definition) && (!$definition instanceof Zend_Server_Definition)) {
if (is_object($definition)) {
$type = get_class($definition);
} else {
$type = gettype($definition);
}
throw new Zend_XmlRpc_Server_Exception('Unable to load server definition; must be an array or Zend_Server_Definition, received ' . $type, 612);
}
$this->_table->clearMethods();
$this->_registerSystemMethods();
if ($definition instanceof Zend_Server_Definition) {
$definition = $definition->getMethods();
}
foreach ($definition as $key => $method) {
if ('system.' == substr($key, 0, 7)) {
continue;
}
$this->_table->addMethod($method, $key);
}
}
/**
* Set encoding
*
* @param string $encoding
* @return Zend_XmlRpc_Server
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
return $this;
}
/**
* Retrieve current encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Do nothing; persistence is handled via {@link Zend_XmlRpc_Server_Cache}
*
* @param mixed $mode
* @return void
*/
public function setPersistence($mode)
{
}
/**
* Set the request object
*
* @param string|Zend_XmlRpc_Request $request
* @return Zend_XmlRpc_Server
* @throws Zend_XmlRpc_Server_Exception on invalid request class or object
*/
public function setRequest($request)
{
if (is_string($request) && class_exists($request)) {
$request = new $request();
if (!$request instanceof Zend_XmlRpc_Request) {
throw new Zend_XmlRpc_Server_Exception('Invalid request class');
}
$request->setEncoding($this->getEncoding());
} elseif (!$request instanceof Zend_XmlRpc_Request) {
throw new Zend_XmlRpc_Server_Exception('Invalid request object');
}
$this->_request = $request;
return $this;
}
/**
* Return currently registered request object
*
* @return null|Zend_XmlRpc_Request
*/
public function getRequest()
{
return $this->_request;
}
/**
* Set the class to use for the response
*
* @param string $class
* @return boolean True if class was set, false if not
*/
public function setResponseClass($class)
{
if (class_exists($class)) {
$reflection = new ReflectionClass($class);
if ($reflection->isSubclassOf(new ReflectionClass('Zend_XmlRpc_Response'))) {
$this->_responseClass = $class;
return true;
}
}
return false;
}
/**
* Retrieve current response class
*
* @return string
*/
public function getResponseClass()
{
return $this->_responseClass;
}
/**
* Retrieve dispatch table
*
* @return array
*/
public function getDispatchTable()
{
return $this->_table;
}
/**
* Returns a list of registered methods
*
* Returns an array of dispatchables (Zend_Server_Reflection_Function,
* _Method, and _Class items).
*
* @return array
*/
public function getFunctions()
{
return $this->_table->toArray();
}
/**
* Retrieve system object
*
* @return Zend_XmlRpc_Server_System
*/
public function getSystem()
{
return $this->_system;
}
/**
* Map PHP type to XML-RPC type
*
* @param string $type
* @return string
*/
protected function _fixType($type)
{
if (isset($this->_typeMap[$type])) {
return $this->_typeMap[$type];
}
return 'void';
}
/**
* Handle an xmlrpc call (actual work)
*
* @param Zend_XmlRpc_Request $request
* @return Zend_XmlRpc_Response
* @throws Zend_XmlRpcServer_Exception|Exception
* Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise,
* any other exception may be thrown by the callback
*/
protected function _handle(Zend_XmlRpc_Request $request)
{
$method = $request->getMethod();
// Check for valid method
if (!$this->_table->hasMethod($method)) {
throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 620);
}
$info = $this->_table->getMethod($method);
$params = $request->getParams();
$argv = $info->getInvokeArguments();
if (0 < count($argv)) {
$params = array_merge($params, $argv);
}
// Check calling parameters against signatures
$matched = false;
$sigCalled = $request->getTypes();
$sigLength = count($sigCalled);
$paramsLen = count($params);
if ($sigLength < $paramsLen) {
for ($i = $sigLength; $i < $paramsLen; ++$i) {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($params[$i]);
$sigCalled[] = $xmlRpcValue->getType();
}
}
$signatures = $info->getPrototypes();
foreach ($signatures as $signature) {
$sigParams = $signature->getParameters();
if ($sigCalled === $sigParams) {
$matched = true;
break;
}
}
if (!$matched) {
throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623);
}
$return = $this->_dispatch($info, $params);
$responseClass = $this->getResponseClass();
return new $responseClass($return);
}
/**
* Register system methods with the server
*
* @return void
*/
protected function _registerSystemMethods()
{
$system = new Zend_XmlRpc_Server_System($this);
$this->_system = $system;
$this->setClass($system, 'system');
}
}
XmlRpc/Value.php 0000604 00000034061 15071256135 0007543 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Value.php 12721 2008-11-20 18:21:58Z matthew $
*/
/** Zend_XmlRpc_Value_Exception */
require_once 'Zend/XmlRpc/Value/Exception.php';
/** Zend_XmlRpc_Value_Scalar */
require_once 'Zend/XmlRpc/Value/Scalar.php';
/** Zend_XmlRpc_Value_Base64 */
require_once 'Zend/XmlRpc/Value/Base64.php';
/** Zend_XmlRpc_Value_Boolean */
require_once 'Zend/XmlRpc/Value/Boolean.php';
/** Zend_XmlRpc_Value_DateTime */
require_once 'Zend/XmlRpc/Value/DateTime.php';
/** Zend_XmlRpc_Value_Double */
require_once 'Zend/XmlRpc/Value/Double.php';
/** Zend_XmlRpc_Value_Integer */
require_once 'Zend/XmlRpc/Value/Integer.php';
/** Zend_XmlRpc_Value_String */
require_once 'Zend/XmlRpc/Value/String.php';
/** Zend_XmlRpc_Value_Nil */
require_once 'Zend/XmlRpc/Value/Nil.php';
/** Zend_XmlRpc_Value_Collection */
require_once 'Zend/XmlRpc/Value/Collection.php';
/** Zend_XmlRpc_Value_Array */
require_once 'Zend/XmlRpc/Value/Array.php';
/** Zend_XmlRpc_Value_Struct */
require_once 'Zend/XmlRpc/Value/Struct.php';
/**
* Represent a native XML-RPC value entity, used as parameters for the methods
* called by the Zend_XmlRpc_Client object and as the return value for those calls.
*
* This object as a very important static function Zend_XmlRpc_Value::getXmlRpcValue, this
* function acts likes a factory for the Zend_XmlRpc_Value objects
*
* Using this function, users/Zend_XmlRpc_Client object can create the Zend_XmlRpc_Value objects
* from PHP variables, XML string or by specifing the exact XML-RPC natvie type
*
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value
{
/**
* The native XML-RPC representation of this object's value
*
* If the native type of this object is array or struct, this will be an array
* of Zend_XmlRpc_Value objects
*/
protected $_value;
/**
* The native XML-RPC type of this object
* One of the XMLRPC_TYPE_* constants
*/
protected $_type;
/**
* XML code representation of this object (will be calculated only once)
*/
protected $_as_xml;
/**
* DOMElement representation of object (will be calculated only once)
*/
protected $_as_dom;
/**
* Specify that the XML-RPC native type will be auto detected from a PHP variable type
*/
const AUTO_DETECT_TYPE = 'auto_detect';
/**
* Specify that the XML-RPC value will be parsed out from a given XML code
*/
const XML_STRING = 'xml';
/**
* All the XML-RPC native types
*/
const XMLRPC_TYPE_I4 = 'i4';
const XMLRPC_TYPE_INTEGER = 'int';
const XMLRPC_TYPE_DOUBLE = 'double';
const XMLRPC_TYPE_BOOLEAN = 'boolean';
const XMLRPC_TYPE_STRING = 'string';
const XMLRPC_TYPE_DATETIME = 'dateTime.iso8601';
const XMLRPC_TYPE_BASE64 = 'base64';
const XMLRPC_TYPE_ARRAY = 'array';
const XMLRPC_TYPE_STRUCT = 'struct';
const XMLRPC_TYPE_NIL = 'nil';
/**
* Get the native XML-RPC type (the type is one of the Zend_XmlRpc_Value::XMLRPC_TYPE_* constants)
*
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* Return the value of this object, convert the XML-RPC native value into a PHP variable
*
* @return mixed
*/
abstract public function getValue();
/**
* Return the XML code that represent a native MXL-RPC value
*
* @return string
*/
abstract public function saveXML();
/**
* Return DOMElement representation of object
*
* @return DOMElement
*/
public function getAsDOM()
{
if (!$this->_as_dom) {
$doc = new DOMDocument('1.0');
$doc->loadXML($this->saveXML());
$this->_as_dom = $doc->documentElement;
}
return $this->_as_dom;
}
protected function _stripXmlDeclaration(DOMDocument $dom)
{
return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $dom->saveXML());
}
/**
* Creates a Zend_XmlRpc_Value* object, representing a native XML-RPC value
* A XmlRpcValue object can be created in 3 ways:
* 1. Autodetecting the native type out of a PHP variable
* (if $type is not set or equal to Zend_XmlRpc_Value::AUTO_DETECT_TYPE)
* 2. By specifing the native type ($type is one of the Zend_XmlRpc_Value::XMLRPC_TYPE_* constants)
* 3. From a XML string ($type is set to Zend_XmlRpc_Value::XML_STRING)
*
* By default the value type is autodetected according to it's PHP type
*
* @param mixed $value
* @param Zend_XmlRpc_Value::constant $type
*
* @return Zend_XmlRpc_Value
* @static
*/
public static function getXmlRpcValue($value, $type = self::AUTO_DETECT_TYPE)
{
switch ($type) {
case self::AUTO_DETECT_TYPE:
// Auto detect the XML-RPC native type from the PHP type of $value
return self::_phpVarToNativeXmlRpc($value);
case self::XML_STRING:
// Parse the XML string given in $value and get the XML-RPC value in it
return self::_xmlStringToNativeXmlRpc($value);
case self::XMLRPC_TYPE_I4:
// fall through to the next case
case self::XMLRPC_TYPE_INTEGER:
return new Zend_XmlRpc_Value_Integer($value);
case self::XMLRPC_TYPE_DOUBLE:
return new Zend_XmlRpc_Value_Double($value);
case self::XMLRPC_TYPE_BOOLEAN:
return new Zend_XmlRpc_Value_Boolean($value);
case self::XMLRPC_TYPE_STRING:
return new Zend_XmlRpc_Value_String($value);
case self::XMLRPC_TYPE_BASE64:
return new Zend_XmlRpc_Value_Base64($value);
case self::XMLRPC_TYPE_NIL:
return new Zend_XmlRpc_Value_Nil();
case self::XMLRPC_TYPE_DATETIME:
return new Zend_XmlRpc_Value_DateTime($value);
case self::XMLRPC_TYPE_ARRAY:
return new Zend_XmlRpc_Value_Array($value);
case self::XMLRPC_TYPE_STRUCT:
return new Zend_XmlRpc_Value_Struct($value);
default:
throw new Zend_XmlRpc_Value_Exception('Given type is not a '. __CLASS__ .' constant');
}
}
/**
* Transform a PHP native variable into a XML-RPC native value
*
* @param mixed $value The PHP variable for convertion
*
* @return Zend_XmlRpc_Value
* @static
*/
private static function _phpVarToNativeXmlRpc($value)
{
switch (gettype($value)) {
case 'object':
// Check to see if it's an XmlRpc value
if ($value instanceof Zend_XmlRpc_Value) {
return $value;
}
// Otherwise, we convert the object into a struct
$value = get_object_vars($value);
// Break intentionally omitted
case 'array':
// Default native type for a PHP array (a simple numeric array) is 'array'
$obj = 'Zend_XmlRpc_Value_Array';
// Determine if this is an associative array
if (!empty($value) && is_array($value) && (array_keys($value) !== range(0, count($value) - 1))) {
$obj = 'Zend_XmlRpc_Value_Struct';
}
return new $obj($value);
case 'integer':
return new Zend_XmlRpc_Value_Integer($value);
case 'double':
return new Zend_XmlRpc_Value_Double($value);
case 'boolean':
return new Zend_XmlRpc_Value_Boolean($value);
case 'NULL':
case 'null':
return new Zend_XmlRpc_Value_Nil();
case 'string':
// Fall through to the next case
default:
// If type isn't identified (or identified as string), it treated as string
return new Zend_XmlRpc_Value_String($value);
}
}
/**
* Transform an XML string into a XML-RPC native value
*
* @param string|SimpleXMLElement $simple_xml A SimpleXMLElement object represent the XML string
* It can be also a valid XML string for convertion
*
* @return Zend_XmlRpc_Value
* @static
*/
private static function _xmlStringToNativeXmlRpc($simple_xml)
{
if (!$simple_xml instanceof SimpleXMLElement) {
try {
$simple_xml = @new SimpleXMLElement($simple_xml);
} catch (Exception $e) {
// The given string is not a valid XML
throw new Zend_XmlRpc_Value_Exception('Failed to create XML-RPC value from XML string: '.$e->getMessage(),$e->getCode());
}
}
// Get the key (tag name) and value from the simple xml object and convert the value to an XML-RPC native value
list($type, $value) = each($simple_xml);
if (!$type) { // If no type was specified, the default is string
$type = self::XMLRPC_TYPE_STRING;
}
switch ($type) {
// All valid and known XML-RPC native values
case self::XMLRPC_TYPE_I4:
// Fall through to the next case
case self::XMLRPC_TYPE_INTEGER:
$xmlrpc_val = new Zend_XmlRpc_Value_Integer($value);
break;
case self::XMLRPC_TYPE_DOUBLE:
$xmlrpc_val = new Zend_XmlRpc_Value_Double($value);
break;
case self::XMLRPC_TYPE_BOOLEAN:
$xmlrpc_val = new Zend_XmlRpc_Value_Boolean($value);
break;
case self::XMLRPC_TYPE_STRING:
$xmlrpc_val = new Zend_XmlRpc_Value_String($value);
break;
case self::XMLRPC_TYPE_DATETIME: // The value should already be in a iso8601 format
$xmlrpc_val = new Zend_XmlRpc_Value_DateTime($value);
break;
case self::XMLRPC_TYPE_BASE64: // The value should already be base64 encoded
$xmlrpc_val = new Zend_XmlRpc_Value_Base64($value ,true);
break;
case self::XMLRPC_TYPE_NIL: // The value should always be NULL
$xmlrpc_val = new Zend_XmlRpc_Value_Nil();
break;
case self::XMLRPC_TYPE_ARRAY:
// If the XML is valid, $value must be an SimpleXML element and contain the <data> tag
if (!$value instanceof SimpleXMLElement) {
throw new Zend_XmlRpc_Value_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type');
}
// PHP 5.2.4 introduced a regression in how empty($xml->value)
// returns; need to look for the item specifically
$data = null;
foreach ($value->children() as $key => $value) {
if ('data' == $key) {
$data = $value;
break;
}
}
if (null === $data) {
throw new Zend_XmlRpc_Value_Exception('Invalid XML for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type: ARRAY tag must contain DATA tag');
}
$values = array();
// Parse all the elements of the array from the XML string
// (simple xml element) to Zend_XmlRpc_Value objects
foreach ($data->value as $element) {
$values[] = self::_xmlStringToNativeXmlRpc($element);
}
$xmlrpc_val = new Zend_XmlRpc_Value_Array($values);
break;
case self::XMLRPC_TYPE_STRUCT:
// If the XML is valid, $value must be an SimpleXML
if ((!$value instanceof SimpleXMLElement)) {
throw new Zend_XmlRpc_Value_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_STRUCT .' type');
}
$values = array();
// Parse all the memebers of the struct from the XML string
// (simple xml element) to Zend_XmlRpc_Value objects
foreach ($value->member as $member) {
// @todo? If a member doesn't have a <value> tag, we don't add it to the struct
// Maybe we want to throw an exception here ?
if ((!$member->value instanceof SimpleXMLElement)) {
continue;
//throw new Zend_XmlRpc_Value_Exception('Member of the '. self::XMLRPC_TYPE_STRUCT .' XML-RPC native type must contain a VALUE tag');
}
$values[(string)$member->name] = self::_xmlStringToNativeXmlRpc($member->value);
}
$xmlrpc_val = new Zend_XmlRpc_Value_Struct($values);
break;
default:
throw new Zend_XmlRpc_Value_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type');
break;
}
$xmlrpc_val->_setXML($simple_xml->asXML());
return $xmlrpc_val;
}
private function _setXML($xml)
{
$this->_as_xml = $xml;
}
}
XmlRpc/Request.php 0000604 00000027524 15071256135 0010125 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XmlRpc Request object
*
* Encapsulates an XmlRpc request, holding the method call and all parameters.
* Provides accessors for these, as well as the ability to load from XML and to
* create the XML request string.
*
* Additionally, if errors occur setting the method or parsing XML, a fault is
* generated and stored in {@link $_fault}; developers may check for it using
* {@link isFault()} and {@link getFault()}.
*
* @category Zend
* @package Zend_XmlRpc
* @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: Request.php 8997 2008-03-22 17:17:05Z matthew $
*/
class Zend_XmlRpc_Request
{
/**
* Request character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Method to call
* @var string
*/
protected $_method;
/**
* XML request
* @var string
*/
protected $_xml;
/**
* Method parameters
* @var array
*/
protected $_params = array();
/**
* Fault object, if any
* @var Zend_XmlRpc_Fault
*/
protected $_fault = null;
/**
* XML-RPC type for each param
* @var array
*/
protected $_types = array();
/**
* XML-RPC request params
* @var array
*/
protected $_xmlRpcParams = array();
/**
* Create a new XML-RPC request
*
* @param string $method (optional)
* @param array $params (optional)
*/
public function __construct($method = null, $params = null)
{
if ($method !== null) {
$this->setMethod($method);
}
if ($params !== null) {
$this->setParams($params);
}
}
/**
* Set encoding to use in request
*
* @param string $encoding
* @return Zend_XmlRpc_Request
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
return $this;
}
/**
* Retrieve current request encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set method to call
*
* @param string $method
* @return boolean Returns true on success, false if method name is invalid
*/
public function setMethod($method)
{
if (!is_string($method) || !preg_match('/^[a-z0-9_.:\/]+$/i', $method)) {
$this->_fault = new Zend_XmlRpc_Fault(634, 'Invalid method name ("' . $method . '")');
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->_method = $method;
return true;
}
/**
* Retrieve call method
*
* @return string
*/
public function getMethod()
{
return $this->_method;
}
/**
* Add a parameter to the parameter stack
*
* Adds a parameter to the parameter stack, associating it with the type
* $type if provided
*
* @param mixed $value
* @param string $type Optional; type hinting
* @return void
*/
public function addParam($value, $type = null)
{
$this->_params[] = $value;
if (null === $type) {
// Detect type if not provided explicitly
if ($value instanceof Zend_XmlRpc_Value) {
$type = $value->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($value);
$type = $xmlRpcValue->getType();
}
}
$this->_types[] = $type;
$this->_xmlRpcParams[] = array('value' => $value, 'type' => $type);
}
/**
* Set the parameters array
*
* If called with a single, array value, that array is used to set the
* parameters stack. If called with multiple values or a single non-array
* value, the arguments are used to set the parameters stack.
*
* Best is to call with array of the format, in order to allow type hinting
* when creating the XMLRPC values for each parameter:
* <code>
* $array = array(
* array(
* 'value' => $value,
* 'type' => $type
* )[, ... ]
* );
* </code>
*
* @access public
* @return void
*/
public function setParams()
{
$argc = func_num_args();
$argv = func_get_args();
if (0 == $argc) {
return;
}
if ((1 == $argc) && is_array($argv[0])) {
$params = array();
$types = array();
$wellFormed = true;
foreach ($argv[0] as $arg) {
if (!is_array($arg) || !isset($arg['value'])) {
$wellFormed = false;
break;
}
$params[] = $arg['value'];
if (!isset($arg['type'])) {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg['value']);
$arg['type'] = $xmlRpcValue->getType();
}
$types[] = $arg['type'];
}
if ($wellFormed) {
$this->_xmlRpcParams = $argv[0];
$this->_params = $params;
$this->_types = $types;
} else {
$this->_params = $argv[0];
$this->_types = array();
$xmlRpcParams = array();
foreach ($argv[0] as $arg) {
if ($arg instanceof Zend_XmlRpc_Value) {
$type = $arg->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
$type = $xmlRpcValue->getType();
}
$xmlRpcParams[] = array('value' => $arg, 'type' => $type);
$this->_types[] = $type;
}
$this->_xmlRpcParams = $xmlRpcParams;
}
return;
}
$this->_params = $argv;
$this->_types = array();
$xmlRpcParams = array();
foreach ($argv as $arg) {
if ($arg instanceof Zend_XmlRpc_Value) {
$type = $arg->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
$type = $xmlRpcValue->getType();
}
$xmlRpcParams[] = array('value' => $arg, 'type' => $type);
$this->_types[] = $type;
}
$this->_xmlRpcParams = $xmlRpcParams;
}
/**
* Retrieve the array of parameters
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
/**
* Return parameter types
*
* @return array
*/
public function getTypes()
{
return $this->_types;
}
/**
* Load XML and parse into request components
*
* @param string $request
* @return boolean True on success, false if an error occurred.
*/
public function loadXml($request)
{
if (!is_string($request)) {
$this->_fault = new Zend_XmlRpc_Fault(635);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$xml = @new SimpleXMLElement($request);
} catch (Exception $e) {
// Not valid XML
$this->_fault = new Zend_XmlRpc_Fault(631);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
// Check for method name
if (empty($xml->methodName)) {
// Missing method name
$this->_fault = new Zend_XmlRpc_Fault(632);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->_method = (string) $xml->methodName;
// Check for parameters
if (!empty($xml->params)) {
$types = array();
$argv = array();
foreach ($xml->params->children() as $param) {
if (! $param->value instanceof SimpleXMLElement) {
$this->_fault = new Zend_XmlRpc_Fault(633);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$param = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING);
$types[] = $param->getType();
$argv[] = $param->getValue();
} catch (Exception $e) {
$this->_fault = new Zend_XmlRpc_Fault(636);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
}
$this->_types = $types;
$this->_params = $argv;
}
$this->_xml = $request;
return true;
}
/**
* Does the current request contain errors and should it return a fault
* response?
*
* @return boolean
*/
public function isFault()
{
return $this->_fault instanceof Zend_XmlRpc_Fault;
}
/**
* Retrieve the fault response, if any
*
* @return null|Zend_XmlRpc_Fault
*/
public function getFault()
{
return $this->_fault;
}
/**
* Retrieve method parameters as XMLRPC values
*
* @return array
*/
protected function _getXmlRpcParams()
{
$params = array();
if (is_array($this->_xmlRpcParams)) {
foreach ($this->_xmlRpcParams as $param) {
$value = $param['value'];
$type = isset($param['type']) ? $param['type'] : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
if (!$value instanceof Zend_XmlRpc_Value) {
$value = Zend_XmlRpc_Value::getXmlRpcValue($value, $type);
}
$params[] = $value;
}
}
return $params;
}
/**
* Create XML request
*
* @return string
*/
public function saveXML()
{
$args = $this->_getXmlRpcParams();
$method = $this->getMethod();
$dom = new DOMDocument('1.0', $this->getEncoding());
$mCall = $dom->appendChild($dom->createElement('methodCall'));
$mName = $mCall->appendChild($dom->createElement('methodName', $method));
if (is_array($args) && count($args)) {
$params = $mCall->appendChild($dom->createElement('params'));
foreach ($args as $arg) {
/* @var $arg Zend_XmlRpc_Value */
$argDOM = new DOMDocument('1.0', $this->getEncoding());
$argDOM->loadXML($arg->saveXML());
$param = $params->appendChild($dom->createElement('param'));
$param->appendChild($dom->importNode($argDOM->documentElement, 1));
}
}
return $dom->saveXML();
}
/**
* Return XML request
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}
XmlRpc/Value/Collection.php 0000604 00000004555 15071256135 0011643 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Collection.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value_Collection extends Zend_XmlRpc_Value
{
/**
* Set the value of a collection type (array and struct) native types
*
* @param array $value
*/
public function __construct($value)
{
$values = (array)$value; // Make sure that the value is an array
foreach ($values as $key => $value) {
// If the elements of the given array are not Zend_XmlRpc_Value objects,
// we need to convert them as such (using auto-detection from PHP value)
if (!$value instanceof parent) {
$value = self::getXmlRpcValue($value, self::AUTO_DETECT_TYPE);
}
$this->_value[$key] = $value;
}
}
/**
* Return the value of this object, convert the XML-RPC native collection values into a PHP array
*
* @return arary
*/
public function getValue()
{
$values = (array)$this->_value;
foreach ($values as $key => $value) {
/* @var $value Zend_XmlRpc_Value */
if (!$value instanceof parent) {
throw new Zend_XmlRpc_Value_Exception('Values of '. get_class($this) .' type must be Zend_XmlRpc_Value objects');
}
$values[$key] = $value->getValue();
}
return $values;
}
}
XmlRpc/Value/String.php 0000604 00000004027 15071256135 0011010 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: String.php 9095 2008-03-30 18:52:31Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_String extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a string native type
*
* @param string $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_STRING;
// Make sure this value is string and all XML characters are encoded
$this->_value = $this->_xml_entities($value);
}
/**
* Return the value of this object, convert the XML-RPC native string value into a PHP string
* Decode all encoded risky XML entities back to normal characters
*
* @return string
*/
public function getValue()
{
return html_entity_decode($this->_value, ENT_QUOTES, 'UTF-8');
}
/**
* Make sure a string will be safe for XML, convert risky characters to HTML entities
*
* @param string $str
* @return string
*/
private function _xml_entities($str)
{
return htmlentities($str, ENT_QUOTES, 'UTF-8');
}
}
XmlRpc/Value/Nil.php 0000604 00000004056 15071256135 0010266 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Nil.php 9095 2008-03-30 18:52:31Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Nil extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a nil native type
*
*/
public function __construct()
{
$this->_type = self::XMLRPC_TYPE_NIL;
$this->_value = null;
}
/**
* Return the value of this object, convert the XML-RPC native nill value into a PHP NULL
*
* @return null
*/
public function getValue()
{
return null;
}
/**
* Return the XML code representing the nil
*
* @return string
*/
public function saveXML()
{
if (! $this->_as_xml) { // The XML was not generated yet
$dom = new DOMDocument('1.0', 'UTF-8');
$value = $dom->appendChild($dom->createElement('value'));
$type = $value->appendChild($dom->createElement($this->_type));
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Value/Boolean.php 0000604 00000004661 15071256135 0011125 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Boolean.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Boolean extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a boolean native type
* We hold the boolean type as an integer (0 or 1)
*
* @param bool $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_BOOLEAN;
// Make sure the value is boolean and then convert it into a integer
// The double convertion is because a bug in the ZendOptimizer in PHP version 5.0.4
$this->_value = (int)(bool)$value;
}
/**
* Return the value of this object, convert the XML-RPC native boolean value into a PHP boolean
*
* @return bool
*/
public function getValue()
{
return (bool)$this->_value;
}
/**
* Return the XML-RPC serialization of the boolean value
*
* @return string
*/
public function saveXML()
{
if (! $this->_as_xml) { // The XML was not generated yet
$dom = new DOMDocument('1.0', 'UTF-8');
$value = $dom->appendChild($dom->createElement('value'));
$type = $value->appendChild($dom->createElement($this->_type));
$type->appendChild($dom->createTextNode($this->_value));
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Value/Base64.php 0000604 00000005156 15071256135 0010572 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Base64.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Base64 extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a base64 native type
* We keep this value in base64 encoding
*
* @param string $value
* @param bool $already_encoded If set, it means that the given string is already base64 encoded
*/
public function __construct($value, $already_encoded=false)
{
$this->_type = self::XMLRPC_TYPE_BASE64;
$value = (string)$value; // Make sure this value is string
if (!$already_encoded) {
$value = base64_encode($value); // We encode it in base64
}
$this->_value = $value;
}
/**
* Return the value of this object, convert the XML-RPC native base64 value into a PHP string
* We return this value decoded (a normal string)
*
* @return string
*/
public function getValue()
{
return base64_decode($this->_value);
}
/**
* Return the XML code representing the base64-encoded value
*
* @return string
*/
public function saveXML()
{
if (! $this->_as_xml) { // The XML was not generated yet
$dom = new DOMDocument('1.0', 'UTF-8');
$value = $dom->appendChild($dom->createElement('value'));
$type = $value->appendChild($dom->createElement($this->_type));
$type->appendChild($dom->createTextNode($this->_value));
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Value/DateTime.php 0000604 00000005060 15071256135 0011234 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: DateTime.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a dateTime.iso8601 native type
*
* The value is in iso8601 format, minus any timezone information or dashes
*
* @param mixed $value Integer of the unix timestamp or any string that can be parsed
* to a unix timestamp using the PHP strtotime() function
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_DATETIME;
// If the value is not numeric, we try to convert it to a timestamp (using the strtotime function)
if (is_numeric($value)) { // The value is numeric, we make sure it is an integer
$value = (int)$value;
} else {
$value = strtotime($value);
if ($value === false || $value == -1) { // cannot convert the value to a timestamp
throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp');
}
}
$value = date('c', $value); // Convert the timestamp to iso8601 format
// Strip out TZ information and dashes
$value = preg_replace('/(\+|-)\d{2}:\d{2}$/', '', $value);
$value = str_replace('-', '', $value);
$this->_value = $value;
}
/**
* Return the value of this object as iso8601 dateTime value
*
* @return int As a Unix timestamp
*/
public function getValue()
{
return $this->_value;
}
}
XmlRpc/Value/Exception.php 0000604 00000002205 15071256135 0011474 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Exception extends Zend_XmlRpc_Exception
{}
XmlRpc/Value/Struct.php 0000604 00000004544 15071256135 0011032 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Struct.php 9095 2008-03-30 18:52:31Z thomas $
*/
/**
* Zend_XmlRpc_Value_Collection
*/
require_once 'Zend/XmlRpc/Value/Collection.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Struct extends Zend_XmlRpc_Value_Collection
{
/**
* Set the value of an struct native type
*
* @param array $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_STRUCT;
parent::__construct($value);
}
/**
* Return the XML code that represent struct native MXL-RPC value
*
* @return string
*/
public function saveXML()
{
if (!$this->_as_xml) { // The XML code was not calculated yet
$dom = new DOMDocument('1.0');
$value = $dom->appendChild($dom->createElement('value'));
$struct = $value->appendChild($dom->createElement('struct'));
if (is_array($this->_value)) {
foreach ($this->_value as $name => $val) {
/* @var $val Zend_XmlRpc_Value */
$member = $struct->appendChild($dom->createElement('member'));
$member->appendChild($dom->createElement('name', $name));
$member->appendChild($dom->importNode($val->getAsDOM(), 1));
}
}
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Value/Integer.php 0000604 00000003165 15071256135 0011141 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Integer.php 9095 2008-03-30 18:52:31Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Integer extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of an integer native type
*
* @param int $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_INTEGER;
$this->_value = (int)$value; // Make sure this value is integer
}
/**
* Return the value of this object, convert the XML-RPC native integer value into a PHP integer
*
* @return int
*/
public function getValue()
{
return $this->_value;
}
}
XmlRpc/Value/Double.php 0000604 00000003263 15071256135 0010755 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Double.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Double extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a double native type
*
* @param float $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_DOUBLE;
$this->_value = sprintf('%f',(float)$value); // Make sure this value is float (double) and without the scientific notation
}
/**
* Return the value of this object, convert the XML-RPC native double value into a PHP float
*
* @return float
*/
public function getValue()
{
return (float)$this->_value;
}
}
XmlRpc/Value/Array.php 0000604 00000004374 15071256135 0010625 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Array.php 9096 2008-03-30 19:04:05Z thomas $
*/
/**
* Zend_XmlRpc_Value_Collection
*/
require_once 'Zend/XmlRpc/Value/Collection.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @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_XmlRpc_Value_Array extends Zend_XmlRpc_Value_Collection
{
/**
* Set the value of an array native type
*
* @param array $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_ARRAY;
parent::__construct($value);
}
/**
* Return the XML code that represent an array native MXL-RPC value
*
* @return string
*/
public function saveXML()
{
if (!$this->_as_xml) { // The XML code was not calculated yet
$dom = new DOMDocument('1.0');
$value = $dom->appendChild($dom->createElement('value'));
$array = $value->appendChild($dom->createElement('array'));
$data = $array->appendChild($dom->createElement('data'));
if (is_array($this->_value)) {
foreach ($this->_value as $val) {
/* @var $val Zend_XmlRpc_Value */
$data->appendChild($dom->importNode($val->getAsDOM(), true));
}
}
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Value/Scalar.php 0000604 00000003376 15071256135 0010755 0 ustar 00 <?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_XmlRpc
* @subpackage Value
* @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: Scalar.php 9095 2008-03-30 18:52:31Z thomas $
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value_Scalar extends Zend_XmlRpc_Value
{
/**
* Return the XML code that represent a scalar native MXL-RPC value
*
* @return string
*/
public function saveXML()
{
if (!$this->_as_xml) { // The XML code was not calculated yet
$dom = new DOMDocument('1.0');
$value = $dom->appendChild($dom->createElement('value'));
$type = $value->appendChild($dom->createElement($this->_type));
$type->appendChild($dom->createTextNode($this->getValue()));
$this->_as_dom = $value;
$this->_as_xml = $this->_stripXmlDeclaration($dom);
}
return $this->_as_xml;
}
}
XmlRpc/Response.php 0000604 00000014440 15071256135 0010264 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XmlRpc Response
*
* Container for accessing an XMLRPC return value and creating the XML response.
*
* @category Zend
* @package Zend_XmlRpc
* @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: Response.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_XmlRpc_Response
{
/**
* Return value
* @var mixed
*/
protected $_return;
/**
* Return type
* @var string
*/
protected $_type;
/**
* Response character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Fault, if response is a fault response
* @var null|Zend_XmlRpc_Fault
*/
protected $_fault = null;
/**
* Constructor
*
* Can optionally pass in the return value and type hinting; otherwise, the
* return value can be set via {@link setReturnValue()}.
*
* @param mixed $return
* @param string $type
* @return void
*/
public function __construct($return = null, $type = null)
{
$this->setReturnValue($return, $type);
}
/**
* Set encoding to use in response
*
* @param string $encoding
* @return Zend_XmlRpc_Response
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
return $this;
}
/**
* Retrieve current response encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set the return value
*
* Sets the return value, with optional type hinting if provided.
*
* @param mixed $value
* @param string $type
* @return void
*/
public function setReturnValue($value, $type = null)
{
$this->_return = $value;
$this->_type = (string) $type;
}
/**
* Retrieve the return value
*
* @return mixed
*/
public function getReturnValue()
{
return $this->_return;
}
/**
* Retrieve the XMLRPC value for the return value
*
* @return Zend_XmlRpc_Value
*/
protected function _getXmlRpcReturn()
{
return Zend_XmlRpc_Value::getXmlRpcValue($this->_return);
}
/**
* Is the response a fault response?
*
* @return boolean
*/
public function isFault()
{
return $this->_fault instanceof Zend_XmlRpc_Fault;
}
/**
* Returns the fault, if any.
*
* @return null|Zend_XmlRpc_Fault
*/
public function getFault()
{
return $this->_fault;
}
/**
* Load a response from an XML response
*
* Attempts to load a response from an XMLRPC response, autodetecting if it
* is a fault response.
*
* @param string $response
* @return boolean True if a valid XMLRPC response, false if a fault
* response or invalid input
*/
public function loadXml($response)
{
if (!is_string($response)) {
$this->_fault = new Zend_XmlRpc_Fault(650);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$xml = @new SimpleXMLElement($response);
} catch (Exception $e) {
// Not valid XML
$this->_fault = new Zend_XmlRpc_Fault(651);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
if (!empty($xml->fault)) {
// fault response
$this->_fault = new Zend_XmlRpc_Fault();
$this->_fault->setEncoding($this->getEncoding());
$this->_fault->loadXml($response);
return false;
}
if (empty($xml->params)) {
// Invalid response
$this->_fault = new Zend_XmlRpc_Fault(652);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) {
throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML');
}
$valueXml = $xml->params->param->value->asXML();
$valueXml = preg_replace('/<\?xml version=.*?\?>/i', '', $valueXml);
$value = Zend_XmlRpc_Value::getXmlRpcValue(trim($valueXml), Zend_XmlRpc_Value::XML_STRING);
} catch (Zend_XmlRpc_Value_Exception $e) {
$this->_fault = new Zend_XmlRpc_Fault(653);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->setReturnValue($value->getValue());
return true;
}
/**
* Return response as XML
*
* @return string
*/
public function saveXML()
{
$value = $this->_getXmlRpcReturn();
$valueDOM = new DOMDocument('1.0', $this->getEncoding());
$valueDOM->loadXML($value->saveXML());
$dom = new DOMDocument('1.0', $this->getEncoding());
$response = $dom->appendChild($dom->createElement('methodResponse'));
$params = $response->appendChild($dom->createElement('params'));
$param = $params->appendChild($dom->createElement('param'));
$param->appendChild($dom->importNode($valueDOM->documentElement, true));
return $dom->saveXML();
}
/**
* Return XML response
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}
XmlRpc/Fault.php 0000604 00000017543 15071256135 0007550 0 ustar 00 <?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.
*
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* XMLRPC Faults
*
* Container for XMLRPC faults, containing both a code and a message;
* additionally, has methods for determining if an XML response is an XMLRPC
* fault, as well as generating the XML for an XMLRPC fault response.
*
* To allow method chaining, you may only use the {@link getInstance()} factory
* to instantiate a Zend_XmlRpc_Server_Fault.
*
* @category Zend
* @package Zend_XmlRpc
* @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_XmlRpc_Fault
{
/**
* Fault code
* @var int
*/
protected $_code;
/**
* Fault character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Fault message
* @var string
*/
protected $_message;
/**
* Internal fault codes => messages
* @var array
*/
protected $_internal = array(
404 => 'Unknown Error',
// 610 - 619 reflection errors
610 => 'Invalid method class',
611 => 'Unable to attach function or callback; not callable',
612 => 'Unable to load array; not an array',
613 => 'One or more method records are corrupt or otherwise unusable',
// 620 - 629 dispatch errors
620 => 'Method does not exist',
621 => 'Error instantiating class to invoke method',
622 => 'Method missing implementation',
623 => 'Calling parameters do not match signature',
// 630 - 639 request errors
630 => 'Unable to read request',
631 => 'Failed to parse request',
632 => 'Invalid request, no method passed; request must contain a \'methodName\' tag',
633 => 'Param must contain a value',
634 => 'Invalid method name',
635 => 'Invalid XML provided to request',
636 => 'Error creating xmlrpc value',
// 640 - 649 system.* errors
640 => 'Method does not exist',
// 650 - 659 response errors
650 => 'Invalid XML provided for response',
651 => 'Failed to parse response',
652 => 'Invalid response',
653 => 'Invalid XMLRPC value in response',
);
/**
* Constructor
*
* @return Zend_XmlRpc_Fault
*/
public function __construct($code = 404, $message = '')
{
$this->setCode($code);
$code = $this->getCode();
if (empty($message) && isset($this->_internal[$code])) {
$message = $this->_internal[$code];
} elseif (empty($message)) {
$message = 'Unknown error';
}
$this->setMessage($message);
}
/**
* Set the fault code
*
* @param int $code
* @return Zend_XmlRpc_Fault
*/
public function setCode($code)
{
$this->_code = (int) $code;
return $this;
}
/**
* Return fault code
*
* @return int
*/
public function getCode()
{
return $this->_code;
}
/**
* Retrieve fault message
*
* @param string
* @return Zend_XmlRpc_Fault
*/
public function setMessage($message)
{
$this->_message = (string) $message;
return $this;
}
/**
* Retrieve fault message
*
* @return string
*/
public function getMessage()
{
return $this->_message;
}
/**
* Set encoding to use in fault response
*
* @param string $encoding
* @return Zend_XmlRpc_Fault
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
return $this;
}
/**
* Retrieve current fault encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Load an XMLRPC fault from XML
*
* @param string $fault
* @return boolean Returns true if successfully loaded fault response, false
* if response was not a fault response
* @throws Zend_XmlRpc_Exception if no or faulty XML provided, or if fault
* response does not contain either code or message
*/
public function loadXml($fault)
{
if (!is_string($fault)) {
throw new Zend_XmlRpc_Exception('Invalid XML provided to fault');
}
try {
$xml = @new SimpleXMLElement($fault);
} catch (Exception $e) {
// Not valid XML
throw new Zend_XmlRpc_Exception('Failed to parse XML fault: ' . $e->getMessage(), 500);
}
// Check for fault
if (!$xml->fault) {
// Not a fault
return false;
}
if (!$xml->fault->value->struct) {
// not a proper fault
throw new Zend_XmlRpc_Exception('Invalid fault structure', 500);
}
$structXml = $xml->fault->value->asXML();
$structXml = preg_replace('/<\?xml version=.*?\?>/i', '', $structXml);
$struct = Zend_XmlRpc_Value::getXmlRpcValue(trim($structXml), Zend_XmlRpc_Value::XML_STRING);
$struct = $struct->getValue();
if (isset($struct['faultCode'])) {
$code = $struct['faultCode'];
}
if (isset($struct['faultString'])) {
$message = $struct['faultString'];
}
if (empty($code) && empty($message)) {
throw new Zend_XmlRpc_Exception('Fault code and string required');
}
if (empty($code)) {
$code = '404';
}
if (empty($message)) {
if (isset($this->_internal[$code])) {
$message = $this->_internal[$code];
} else {
$message = 'Unknown Error';
}
}
$this->setCode($code);
$this->setMessage($message);
return true;
}
/**
* Determine if an XML response is an XMLRPC fault
*
* @param string $xml
* @return boolean
*/
public static function isFault($xml)
{
$fault = new self();
try {
$isFault = $fault->loadXml($xml);
} catch (Zend_XmlRpc_Exception $e) {
$isFault = false;
}
return $isFault;
}
/**
* Serialize fault to XML
*
* @return string
*/
public function saveXML()
{
// Create fault value
$faultStruct = array(
'faultCode' => $this->getCode(),
'faultString' => $this->getMessage()
);
$value = Zend_XmlRpc_Value::getXmlRpcValue($faultStruct);
$valueDOM = new DOMDocument('1.0', $this->getEncoding());
$valueDOM->loadXML($value->saveXML());
// Build response XML
$dom = new DOMDocument('1.0', $this->getEncoding());
$r = $dom->appendChild($dom->createElement('methodResponse'));
$f = $r->appendChild($dom->createElement('fault'));
$f->appendChild($dom->importNode($valueDOM->documentElement, 1));
return $dom->saveXML();
}
/**
* Return XML fault response
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}
XmlRpc/Client/ServerProxy.php 0000604 00000004557 15071256135 0012224 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* The namespace decorator enables object chaining to permit
* calling XML-RPC namespaced functions like "foo.bar.baz()"
* as "$remote->foo->bar->baz()".
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_ServerProxy
{
/**
* @var Zend_XmlRpc_Client
*/
private $_client = null;
/**
* @var string
*/
private $_namespace = '';
/**
* @var array of Zend_XmlRpc_Client_ServerProxy
*/
private $_cache = array();
/**
* Class constructor
*
* @param string $namespace
* @param Zend_XmlRpc_Client $client
*/
public function __construct($client, $namespace = '')
{
$this->_namespace = $namespace;
$this->_client = $client;
}
/**
* Get the next successive namespace
*
* @param string $name
* @return Zend_XmlRpc_Client_ServerProxy
*/
public function __get($namespace)
{
$namespace = ltrim("$this->_namespace.$namespace", '.');
if (!isset($this->_cache[$namespace])) {
$this->_cache[$namespace] = new $this($this->_client, $namespace);
}
return $this->_cache[$namespace];
}
/**
* Call a method in this namespace.
*
* @param string $methodN
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
$method = ltrim("$this->_namespace.$method", '.');
return $this->_client->call($method, $args);
}
}
XmlRpc/Client/FaultException.php 0000604 00000002247 15071256135 0012640 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_XmlRpc_Client_Exception */
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client when an XML-RPC fault response is returned.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_FaultException extends Zend_XmlRpc_Client_Exception
{}
XmlRpc/Client/Exception.php 0000604 00000002173 15071256135 0011642 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* Base class for all Zend_XmlRpc_Client_* exceptions
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_Exception extends Zend_XmlRpc_Exception
{}
XmlRpc/Client/IntrospectException.php 0000604 00000002251 15071256135 0013712 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Client_Exception
*/
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client_Introspection when any error occurs.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_IntrospectException extends Zend_XmlRpc_Client_Exception
{}
XmlRpc/Client/HttpException.php 0000604 00000002263 15071256135 0012502 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client when an HTTP error occurs during an
* XML-RPC method call.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_HttpException extends Zend_XmlRpc_Client_Exception
{}
XmlRpc/Client/ServerIntrospection.php 0000604 00000011215 15071256135 0013730 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_XmlRpc_Client_IntrospectException */
require_once 'Zend/XmlRpc/Client/IntrospectException.php';
/**
* Wraps the XML-RPC system.* introspection methods
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client_ServerIntrospection
{
/**
* @var Zend_XmlRpc_Client_ServerProxy
*/
private $_system = null;
/**
* @param Zend_XmlRpc_Client $client
*/
public function __construct(Zend_XmlRpc_Client $client)
{
$this->_system = $client->getProxy('system');
}
/**
* Returns the signature for each method on the server,
* autodetecting whether system.multicall() is supported and
* using it if so.
*
* @return array
*/
public function getSignatureForEachMethod()
{
$methods = $this->listMethods();
try {
$signatures = $this->getSignatureForEachMethodByMulticall($methods);
} catch (Zend_XmlRpc_Client_FaultException $e) {
// degrade to looping
}
if (empty($signatures)) {
$signatures = $this->getSignatureForEachMethodByLooping($methods);
}
return $signatures;
}
/**
* Attempt to get the method signatures in one request via system.multicall().
* This is a boxcar feature of XML-RPC and is found on fewer servers. However,
* can significantly improve performance if present.
*
* @param array $methods
* @return array array(array(return, param, param, param...))
*/
public function getSignatureForEachMethodByMulticall($methods = null)
{
if ($methods === null) {
$methods = $this->listMethods();
}
$multicallParams = array();
foreach ($methods as $method) {
$multicallParams[] = array('methodName' => 'system.methodSignature',
'params' => array($method));
}
$serverSignatures = $this->_system->multicall($multicallParams);
if (! is_array($serverSignatures)) {
$type = gettype($serverSignatures);
$error = "Multicall return is malformed. Expected array, got $type";
throw new Zend_XmlRpc_Client_IntrospectException($error);
}
if (count($serverSignatures) != count($methods)) {
$error = 'Bad number of signatures received from multicall';
throw new Zend_XmlRpc_Client_IntrospectException($error);
}
// Create a new signatures array with the methods name as keys and the signature as value
$signatures = array();
foreach ($serverSignatures as $i => $signature) {
$signatures[$methods[$i]] = $signature;
}
return $signatures;
}
/**
* Get the method signatures for every method by
* successively calling system.methodSignature
*
* @param array $methods
* @return array
*/
public function getSignatureForEachMethodByLooping($methods = null)
{
if ($methods === null) {
$methods = $this->listMethods();
}
$signatures = array();
foreach ($methods as $method) {
$signatures[$method] = $this->getMethodSignature($method);
}
return $signatures;
}
/**
* Call system.methodSignature() for the given method
*
* @param array $method
* @return array array(array(return, param, param, param...))
*/
public function getMethodSignature($method)
{
$signature = $this->_system->methodSignature($method);
return $signature;
}
/**
* Call system.listMethods()
*
* @param array $method
* @return array array(method, method, method...)
*/
public function listMethods()
{
return $this->_system->listMethods();
}
}
XmlRpc/Client.php 0000604 00000023443 15071256135 0007707 0 ustar 00 <?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_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* For handling the HTTP connection to the XML-RPC service
* @see Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* Enables object chaining for calling namespaced XML-RPC methods.
* @see Zend_XmlRpc_Client_ServerProxy
*/
require_once 'Zend/XmlRpc/Client/ServerProxy.php';
/**
* Introspects remote servers using the XML-RPC de facto system.* methods
* @see Zend_XmlRpc_Client_ServerIntrospection
*/
require_once 'Zend/XmlRpc/Client/ServerIntrospection.php';
/**
* Represent a native XML-RPC value, used both in sending parameters
* to methods and as the parameters retrieve from method calls
* @see Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* XML-RPC Request
* @see Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XML-RPC Response
* @see Zend_XmlRpc_Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* XML-RPC Fault
* @see Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* An XML-RPC client implementation
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @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_XmlRpc_Client
{
/**
* Full address of the XML-RPC service
* @var string
* @example http://time.xmlrpc.com/RPC2
*/
protected $_serverAddress;
/**
* HTTP Client to use for requests
* @var Zend_Http_Client
*/
protected $_httpClient = null;
/**
* Introspection object
* @var Zend_Http_Client_Introspector
*/
protected $_introspector = null;
/**
* Request of the last method call
* @var Zend_XmlRpc_Request
*/
protected $_lastRequest = null;
/**
* Response received from the last method call
* @var Zend_XmlRpc_Response
*/
protected $_lastResponse = null;
/**
* Proxy object for more convenient method calls
* @var array of Zend_XmlRpc_Client_ServerProxy
*/
protected $_proxyCache = array();
/**
* Flag for skipping system lookup
* @var bool
*/
protected $_skipSystemLookup = false;
/**
* Create a new XML-RPC client to a remote server
*
* @param string $server Full address of the XML-RPC service
* (e.g. http://time.xmlrpc.com/RPC2)
* @param Zend_Http_Client $httpClient HTTP Client to use for requests
* @return void
*/
public function __construct($server, Zend_Http_Client $httpClient = null)
{
if ($httpClient === null) {
$this->_httpClient = new Zend_Http_Client();
} else {
$this->_httpClient = $httpClient;
}
$this->_introspector = new Zend_XmlRpc_Client_ServerIntrospection($this);
$this->_serverAddress = $server;
}
/**
* Sets the HTTP client object to use for connecting the XML-RPC server.
*
* @param Zend_Http_Client $httpClient
* @return Zend_Http_Client
*/
public function setHttpClient(Zend_Http_Client $httpClient)
{
return $this->_httpClient = $httpClient;
}
/**
* Gets the HTTP client object.
*
* @return Zend_Http_Client
*/
public function getHttpClient()
{
return $this->_httpClient;
}
/**
* Sets the object used to introspect remote servers
*
* @param Zend_XmlRpc_Client_ServerIntrospection
* @return Zend_XmlRpc_Client_ServerIntrospection
*/
public function setIntrospector(Zend_XmlRpc_Client_ServerIntrospection $introspector)
{
return $this->_introspector = $introspector;
}
/**
* Gets the introspection object.
*
* @return Zend_XmlRpc_Client_ServerIntrospection
*/
public function getIntrospector()
{
return $this->_introspector;
}
/**
* The request of the last method call
*
* @return Zend_XmlRpc_Request
*/
public function getLastRequest()
{
return $this->_lastRequest;
}
/**
* The response received from the last method call
*
* @return Zend_XmlRpc_Response
*/
public function getLastResponse()
{
return $this->_lastResponse;
}
/**
* Returns a proxy object for more convenient method calls
*
* @param $namespace Namespace to proxy or empty string for none
* @return Zend_XmlRpc_Client_ServerProxy
*/
public function getProxy($namespace = '')
{
if (empty($this->_proxyCache[$namespace])) {
$proxy = new Zend_XmlRpc_Client_ServerProxy($this, $namespace);
$this->_proxyCache[$namespace] = $proxy;
}
return $this->_proxyCache[$namespace];
}
/**
* Set skip system lookup flag
*
* @param bool $flag
* @return Zend_XmlRpc_Client
*/
public function setSkipSystemLookup($flag = true)
{
$this->_skipSystemLookup = (bool) $flag;
return $this;
}
/**
* Skip system lookup when determining if parameter should be array or struct?
*
* @return bool
*/
public function skipSystemLookup()
{
return $this->_skipSystemLookup;
}
/**
* Perform an XML-RPC request and return a response.
*
* @param Zend_XmlRpc_Request $request
* @param null|Zend_XmlRpc_Response $response
* @return void
* @throws Zend_XmlRpc_Client_HttpException
*/
public function doRequest($request, $response = null)
{
$this->_lastRequest = $request;
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
$http = $this->getHttpClient();
if($http->getUri() === null) {
$http->setUri($this->_serverAddress);
}
$http->setHeaders(array(
'Content-Type: text/xml; charset=utf-8',
'User-Agent: Zend_XmlRpc_Client',
'Accept: text/xml',
));
$xml = $this->_lastRequest->__toString();
$http->setRawData($xml);
$httpResponse = $http->request(Zend_Http_Client::POST);
if (! $httpResponse->isSuccessful()) {
/**
* Exception thrown when an HTTP error occurs
* @see Zend_XmlRpc_Client_HttpException
*/
require_once 'Zend/XmlRpc/Client/HttpException.php';
throw new Zend_XmlRpc_Client_HttpException(
$httpResponse->getMessage(),
$httpResponse->getStatus());
}
if ($response === null) {
$response = new Zend_XmlRpc_Response();
}
$this->_lastResponse = $response;
$this->_lastResponse->loadXml($httpResponse->getBody());
}
/**
* Send an XML-RPC request to the service (for a specific method)
*
* @param string $method Name of the method we want to call
* @param array $params Array of parameters for the method
* @throws Zend_XmlRpc_Client_FaultException
*/
public function call($method, $params=array())
{
if (!$this->skipSystemLookup() && ('system.' != substr($method, 0, 7))) {
// Ensure empty array/struct params are cast correctly
// If system.* methods are not available, bypass. (ZF-2978)
$success = true;
try {
$signatures = $this->getIntrospector()->getMethodSignature($method);
} catch (Zend_XmlRpc_Exception $e) {
$success = false;
}
if ($success) {
foreach ($params as $key => $param) {
if (is_array($param) && empty($param)) {
$type = 'array';
foreach ($signatures as $signature) {
if (!is_array($signature)) {
continue;
}
if (array_key_exists($key + 1, $signature)) {
$type = $signature[$key + 1];
$type = (in_array($type, array('array', 'struct'))) ? $type : 'array';
break;
}
}
$params[$key] = array(
'type' => $type,
'value' => $param
);
}
}
}
}
$request = new Zend_XmlRpc_Request($method, $params);
$this->doRequest($request);
if ($this->_lastResponse->isFault()) {
$fault = $this->_lastResponse->getFault();
/**
* Exception thrown when an XML-RPC fault is returned
* @see Zend_XmlRpc_Client_FaultException
*/
require_once 'Zend/XmlRpc/Client/FaultException.php';
throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(),
$fault->getCode());
}
return $this->_lastResponse->getReturnValue();
}
}
XmlRpc/Server/Fault.php 0000604 00000012637 15071256135 0011015 0 ustar 00 <?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_XmlRpc
* @subpackage Server
* @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: Fault.php 9102 2008-03-30 20:27:03Z thomas $
*/
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XMLRPC Server Faults
*
* Encapsulates an exception for use as an XMLRPC fault response. Valid
* exception classes that may be used for generating the fault code and fault
* string can be attached using {@link attachFaultException()}; all others use a
* generic '404 Unknown error' response.
*
* You may also attach fault observers, which would allow you to monitor
* particular fault cases; this is done via {@link attachObserver()}. Observers
* need only implement a static 'observe' method.
*
* To allow method chaining, you may use the {@link getInstance()} factory
* to instantiate a Zend_XmlRpc_Server_Fault.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @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_XmlRpc_Server_Fault extends Zend_XmlRpc_Fault
{
/**
* @var Exception
*/
protected $_exception;
/**
* @var array Array of exception classes that may define xmlrpc faults
*/
protected static $_faultExceptionClasses = array('Zend_XmlRpc_Server_Exception' => true);
/**
* @var array Array of fault observers
*/
protected static $_observers = array();
/**
* Constructor
*
* @param Exception $e
* @return Zend_XmlRpc_Server_Fault
*/
public function __construct(Exception $e)
{
$this->_exception = $e;
$code = 404;
$message = 'Unknown error';
$exceptionClass = get_class($e);
foreach (array_keys(self::$_faultExceptionClasses) as $class) {
if ($e instanceof $class) {
$code = $e->getCode();
$message = $e->getMessage();
break;
}
}
parent::__construct($code, $message);
// Notify exception observers, if present
if (!empty(self::$_observers)) {
foreach (array_keys(self::$_observers) as $observer) {
call_user_func(array($observer, 'observe'), $this);
}
}
}
/**
* Return Zend_XmlRpc_Server_Fault instance
*
* @param Exception $e
* @return Zend_XmlRpc_Server_Fault
*/
public static function getInstance(Exception $e)
{
return new self($e);
}
/**
* Attach valid exceptions that can be used to define xmlrpc faults
*
* @param string|array $classes Class name or array of class names
* @return void
*/
public static function attachFaultException($classes)
{
if (!is_array($classes)) {
$classes = (array) $classes;
}
foreach ($classes as $class) {
if (is_string($class) && class_exists($class)) {
self::$_faultExceptionClasses[$class] = true;
}
}
}
/**
* Detach fault exception classes
*
* @param string|array $classes Class name or array of class names
* @return void
*/
public static function detachFaultException($classes)
{
if (!is_array($classes)) {
$classes = (array) $classes;
}
foreach ($classes as $class) {
if (is_string($class) && isset(self::$_faultExceptionClasses[$class])) {
unset(self::$_faultExceptionClasses[$class]);
}
}
}
/**
* Attach an observer class
*
* Allows observation of xmlrpc server faults, thus allowing logging or mail
* notification of fault responses on the xmlrpc server.
*
* Expects a valid class name; that class must have a public static method
* 'observe' that accepts an exception as its sole argument.
*
* @param string $class
* @return boolean
*/
public static function attachObserver($class)
{
if (!is_string($class)
|| !class_exists($class)
|| !is_callable(array($class, 'observe')))
{
return false;
}
if (!isset(self::$_observers[$class])) {
self::$_observers[$class] = true;
}
return true;
}
/**
* Detach an observer
*
* @param string $class
* @return boolean
*/
public static function detachObserver($class)
{
if (!isset(self::$_observers[$class])) {
return false;
}
unset(self::$_observers[$class]);
return true;
}
/**
* Retrieve the exception
*
* @access public
* @return Exception
*/
public function getException()
{
return $this->_exception;
}
}
XmlRpc/Server/Cache.php 0000604 00000002671 15071256135 0010742 0 ustar 00 <?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_XmlRpc
* @subpackage Server
* @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: Cache.php 12195 2008-10-30 13:34:35Z matthew $
*/
/** Zend_Server_Cache */
require_once 'Zend/Server/Cache.php';
/**
* Zend_XmlRpc_Server_Cache: cache Zend_XmlRpc_Server server definition
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @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_XmlRpc_Server_Cache extends Zend_Server_Cache
{
/**
* @var array Skip system methods when caching XML-RPC server
*/
protected static $_skipMethods = array(
'system.listMethods',
'system.methodHelp',
'system.methodSignature',
'system.multicall',
);
}
XmlRpc/Server/System.php 0000604 00000011167 15071256135 0011223 0 ustar 00 <?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_XmlRpc
* @subpackage Server
* @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$
*/
/**
* XML-RPC system.* methods
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @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_XmlRpc_Server_System
{
/**
* Constructor
*
* @param Zend_XmlRpc_Server $server
* @return void
*/
public function __construct(Zend_XmlRpc_Server $server)
{
$this->_server = $server;
}
/**
* List all available XMLRPC methods
*
* Returns an array of methods.
*
* @return array
*/
public function listMethods()
{
$table = $this->_server->getDispatchTable()->getMethods();
return array_keys($table);
}
/**
* Display help message for an XMLRPC method
*
* @param string $method
* @return string
*/
public function methodHelp($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);
}
return $table->getMethod($method)->getMethodHelp();
}
/**
* Return a method signature
*
* @param string $method
* @return array
*/
public function methodSignature($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
throw new Zend_Server_Exception('Method "' . $method . '"does not exist', 640);
}
$method = $table->getMethod($method)->toArray();
return $method['prototypes'];
}
/**
* Multicall - boxcar feature of XML-RPC for calling multiple methods
* in a single request.
*
* Expects a an array of structs representing method calls, each element
* having the keys:
* - methodName
* - params
*
* Returns an array of responses, one for each method called, with the value
* returned by the method. If an error occurs for a given method, returns a
* struct with a fault response.
*
* @see http://www.xmlrpc.com/discuss/msgReader$1208
* @param array $methods
* @return array
*/
public function multicall($methods)
{
$responses = array();
foreach ($methods as $method) {
$fault = false;
if (!is_array($method)) {
$fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
} elseif (!isset($method['methodName'])) {
$fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
} elseif (!isset($method['params'])) {
$fault = $this->_server->fault('Missing params', 603);
} elseif (!is_array($method['params'])) {
$fault = $this->_server->fault('Params must be an array', 604);
} else {
if ('system.multicall' == $method['methodName']) {
// don't allow recursive calls to multicall
$fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
}
}
if (!$fault) {
try {
$request = new Zend_XmlRpc_Request();
$request->setMethod($method['methodName']);
$request->setParams($method['params']);
$response = $this->_server->handle($request);
$responses[] = $response->getReturnValue();
} catch (Exception $e) {
$fault = $this->_server->fault($e);
}
}
if ($fault) {
$responses[] = array(
'faultCode' => $fault->getCode(),
'faultString' => $fault->getMessage()
);
}
}
return $responses;
}
}
XmlRpc/Server/Exception.php 0000604 00000002254 15071256135 0011672 0 ustar 00 <?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_XmlRpc
* @subpackage Server
* @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 9102 2008-03-30 20:27:03Z thomas $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* Zend_XmlRpc_Server_Exception
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @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_XmlRpc_Server_Exception extends Zend_XmlRpc_Exception
{
}
XmlRpc/Response/Http.php 0000604 00000002701 15071256135 0011200 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* HTTP response
*
* @uses Zend_XmlRpc_Response
* @category Zend
* @package Zend_XmlRpc
* @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: Http.php 9343 2008-04-28 19:51:02Z matthew $
*/
class Zend_XmlRpc_Response_Http extends Zend_XmlRpc_Response
{
/**
* Override __toString() to send HTTP Content-Type header
*
* @return string
*/
public function __toString()
{
if (!headers_sent()) {
header('Content-Type: text/xml; charset=' . strtolower($this->getEncoding()));
}
return parent::__toString();
}
}
XmlRpc/Request/Stdin.php 0000604 00000004247 15071256135 0011203 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XmlRpc Request object -- Request via STDIN
*
* Extends {@link Zend_XmlRpc_Request} to accept a request via STDIN. Request is
* built at construction time using data from STDIN; if no data is available, the
* request is declared a fault.
*
* @category Zend
* @package Zend_XmlRpc
* @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: Stdin.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_XmlRpc_Request_Stdin extends Zend_XmlRpc_Request
{
/**
* Raw XML as received via request
* @var string
*/
protected $_xml;
/**
* Constructor
*
* Attempts to read from php://stdin to get raw POST request; if an error
* occurs in doing so, or if the XML is invalid, the request is declared a
* fault.
*
* @return void
*/
public function __construct()
{
$fh = fopen('php://stdin', 'r');
if (!$fh) {
$this->_fault = new Zend_XmlRpc_Server_Exception(630);
return;
}
$xml = '';
while (!feof($fh)) {
$xml .= fgets($fh);
}
fclose($fh);
$this->_xml = $xml;
$this->loadXml($xml);
}
/**
* Retrieve the raw XML request
*
* @return string
*/
public function getRawRequest()
{
return $this->_xml;
}
}
XmlRpc/Request/Http.php 0000604 00000006275 15071256135 0011044 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XmlRpc Request object -- Request via HTTP
*
* Extends {@link Zend_XmlRpc_Request} to accept a request via HTTP. Request is
* built at construction time using a raw POST; if no data is available, the
* request is declared a fault.
*
* @category Zend
* @package Zend_XmlRpc
* @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: Http.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_XmlRpc_Request_Http extends Zend_XmlRpc_Request
{
/**
* Array of headers
* @var array
*/
protected $_headers;
/**
* Raw XML as received via request
* @var string
*/
protected $_xml;
/**
* Constructor
*
* Attempts to read from php://input to get raw POST request; if an error
* occurs in doing so, or if the XML is invalid, the request is declared a
* fault.
*
* @return void
*/
public function __construct()
{
$fh = fopen('php://input', 'r');
if (!$fh) {
$this->_fault = new Zend_XmlRpc_Server_Exception(630);
return;
}
$xml = '';
while (!feof($fh)) {
$xml .= fgets($fh);
}
fclose($fh);
$this->_xml = $xml;
$this->loadXml($xml);
}
/**
* Retrieve the raw XML request
*
* @return string
*/
public function getRawRequest()
{
return $this->_xml;
}
/**
* Get headers
*
* Gets all headers as key => value pairs and returns them.
*
* @return array
*/
public function getHeaders()
{
if (null === $this->_headers) {
$this->_headers = array();
foreach ($_SERVER as $key => $value) {
if ('HTTP_' == substr($key, 0, 5)) {
$header = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
$this->_headers[$header] = $value;
}
}
}
return $this->_headers;
}
/**
* Retrieve the full HTTP request, including headers and XML
*
* @return string
*/
public function getFullRequest()
{
$request = '';
foreach ($this->getHeaders() as $key => $value) {
$request .= $key . ': ' . $value . "\n";
}
$request .= $this->_xml;
return $request;
}
}
XmlRpc/Exception.php 0000604 00000001773 15071256135 0010431 0 ustar 00 <?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_XmlRpc
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @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_XmlRpc_Exception extends Zend_Exception
{}
Request/Interface.php 0000604 00000005143 15071256135 0010611 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Request
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Request_Interface
{
/**
* Overloading for accessing class property values
*
* @param string $key
* @return mixed
*/
public function __get($key);
/**
* Overloading for setting class property values
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set($key, $value);
/**
* Overloading to determine if a property is set
*
* @param string $key
* @return boolean
*/
public function __isset($key);
/**
* Alias for __get()
*
* @param string $key
* @return mixed
*/
public function get($key);
/**
* Alias for __set()
*
* @param string $key
* @param mixed $value
* @return void
*/
public function set($key, $value);
/**
* Alias for __isset()
*
* @param string $key
* @return boolean
*/
public function has($key);
/**
* Either alias for __get(), or provides ability to maintain separate
* configuration registry for request object.
*
* @param string $key
* @return mixed
*/
public function getParam($key);
/**
* Either alias for __set(), or provides ability to maintain separate
* configuration registry for request object.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function setParam($key, $value);
/**
* Get all params handled by get/setParam()
*
* @return array
*/
public function getParams();
/**
* Set all values handled by get/setParam()
*
* @param array $params
* @return void
*/
public function setParams(array $params);
}
Form.php 0000604 00000242742 15071256135 0006174 0 ustar 00 <?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_Form
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Validate_Interface */
require_once 'Zend/Validate/Interface.php';
/**
* Zend_Form
*
* @category Zend
* @package Zend_Form
* @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: Form.php 12787 2008-11-23 14:17:44Z matthew $
*/
class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
{
/**#@+
* Plugin loader type constants
*/
const DECORATOR = 'DECORATOR';
const ELEMENT = 'ELEMENT';
/**#@-*/
/**#@+
* Method type constants
*/
const METHOD_DELETE = 'delete';
const METHOD_GET = 'get';
const METHOD_POST = 'post';
const METHOD_PUT = 'put';
/**#@-*/
/**#@+
* Encoding type constants
*/
const ENCTYPE_URLENCODED = 'application/x-www-form-urlencoded';
const ENCTYPE_MULTIPART = 'multipart/form-data';
/**#@-*/
/**
* Form metadata and attributes
* @var array
*/
protected $_attribs = array();
/**
* Decorators for rendering
* @var array
*/
protected $_decorators = array();
/**
* Default display group class
* @var string
*/
protected $_defaultDisplayGroupClass = 'Zend_Form_DisplayGroup';
/**
* Form description
* @var string
*/
protected $_description;
/**
* Should we disable loading the default decorators?
* @var bool
*/
protected $_disableLoadDefaultDecorators = false;
/**
* Display group prefix paths
* @var array
*/
protected $_displayGroupPrefixPaths = array();
/**
* Groups of elements grouped for display purposes
* @var array
*/
protected $_displayGroups = array();
/**
* Prefix paths to use when creating elements
* @var array
*/
protected $_elementPrefixPaths = array();
/**
* Form elements
* @var array
*/
protected $_elements = array();
/**
* Array to which elements belong (if any)
* @var string
*/
protected $_elementsBelongTo;
/**
* Custom form-level error messages
* @var array
*/
protected $_errorMessages = array();
/**
* Are there errors in the form?
* @var bool
*/
protected $_errorsExist = false;
/**
* Form order
* @var int|null
*/
protected $_formOrder;
/**
* Whether or not form elements are members of an array
* @var bool
*/
protected $_isArray = false;
/**
* Form legend
* @var string
*/
protected $_legend;
/**
* Plugin loaders
* @var array
*/
protected $_loaders = array();
/**
* Allowed form methods
* @var array
*/
protected $_methods = array('delete', 'get', 'post', 'put');
/**
* Order in which to display and iterate elements
* @var array
*/
protected $_order = array();
/**
* Whether internal order has been updated or not
* @var bool
*/
protected $_orderUpdated = false;
/**
* Sub form prefix paths
* @var array
*/
protected $_subFormPrefixPaths = array();
/**
* Sub forms
* @var array
*/
protected $_subForms = array();
/**
* @var Zend_Translate
*/
protected $_translator;
/**
* Global default translation adapter
* @var Zend_Translate
*/
protected static $_translatorDefault;
/**
* is the translator disabled?
* @var bool
*/
protected $_translatorDisabled = false;
/**
* @var Zend_View_Interface
*/
protected $_view;
/**
* Constructor
*
* Registers form view helper as decorator
*
* @param mixed $options
* @return void
*/
public function __construct($options = null)
{
if (is_array($options)) {
$this->setOptions($options);
} elseif ($options instanceof Zend_Config) {
$this->setConfig($options);
}
// Extensions...
$this->init();
$this->loadDefaultDecorators();
}
/**
* Clone form object and all children
*
* @return void
*/
public function __clone()
{
$elements = array();
foreach ($this->getElements() as $name => $element) {
$elements[] = clone $element;
}
$this->setElements($elements);
$subForms = array();
foreach ($this->getSubForms() as $name => $subForm) {
$subForms[$name] = clone $subForm;
}
$this->setSubForms($subForms);
$displayGroups = array();
foreach ($this->_displayGroups as $group) {
$clone = clone $group;
$elements = array();
foreach ($clone->getElements() as $name => $e) {
$elements[] = $this->getElement($name);
}
$clone->setElements($elements);
$displayGroups[] = $clone;
}
$this->setDisplayGroups($displayGroups);
}
/**
* Reset values of form
*
* @return Zend_Form
*/
public function reset()
{
foreach ($this->getElements() as $element) {
$element->setValue(null);
}
foreach ($this->getSubForms() as $subForm) {
$subForm->reset();
}
return $this;
}
/**
* Initialize form (used by extending classes)
*
* @return void
*/
public function init()
{
}
/**
* Set form state from options array
*
* @param array $options
* @return Zend_Form
*/
public function setOptions(array $options)
{
if (isset($options['prefixPath'])) {
$this->addPrefixPaths($options['prefixPath']);
unset($options['prefixPath']);
}
if (isset($options['elementPrefixPath'])) {
$this->addElementPrefixPaths($options['elementPrefixPath']);
unset($options['elementPrefixPath']);
}
if (isset($options['displayGroupPrefixPath'])) {
$this->addDisplayGroupPrefixPaths($options['displayGroupPrefixPath']);
unset($options['displayGroupPrefixPath']);
}
if (isset($options['elements'])) {
$this->setElements($options['elements']);
unset($options['elements']);
}
if (isset($options['elementDecorators'])) {
$elementDecorators = $options['elementDecorators'];
unset($options['elementDecorators']);
}
if (isset($options['defaultDisplayGroupClass'])) {
$this->setDefaultDisplayGroupClass($options['defaultDisplayGroupClass']);
unset($options['defaultDisplayGroupClass']);
}
if (isset($options['displayGroupDecorators'])) {
$displayGroupDecorators = $options['displayGroupDecorators'];
unset($options['displayGroupDecorators']);
}
if (isset($options['elementsBelongTo'])) {
$elementsBelongTo = $options['elementsBelongTo'];
unset($options['elementsBelongTo']);
}
if (isset($options['attribs'])) {
$this->addAttribs($options['attribs']);
unset($options['attribs']);
}
$forbidden = array(
'Options', 'Config', 'PluginLoader', 'SubForms', 'View', 'Translator',
'Attrib', 'Default',
);
foreach ($options as $key => $value) {
$normalized = ucfirst($key);
if (in_array($normalized, $forbidden)) {
continue;
}
$method = 'set' . $normalized;
if (method_exists($this, $method)) {
$this->$method($value);
} else {
$this->setAttrib($key, $value);
}
}
if (isset($elementDecorators)) {
$this->setElementDecorators($elementDecorators);
}
if (isset($displayGroupDecorators)) {
$this->setDisplayGroupDecorators($displayGroupDecorators);
}
if (isset($elementsBelongTo)) {
$this->setElementsBelongTo($elementsBelongTo);
}
return $this;
}
/**
* Set form state from config object
*
* @param Zend_Config $config
* @return Zend_Form
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
// Loaders
/**
* Set plugin loaders for use with decorators and elements
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @param string $type 'decorator' or 'element'
* @return Zend_Form
* @throws Zend_Form_Exception on invalid type
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case self::DECORATOR:
case self::ELEMENT:
$this->_loaders[$type] = $loader;
return $this;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));
}
}
/**
* Retrieve plugin loader for given type
*
* $type may be one of:
* - decorator
* - element
*
* If a plugin loader does not exist for the given type, defaults are
* created.
*
* @param string $type
* @return Zend_Loader_PluginLoader_Interface
*/
public function getPluginLoader($type = null)
{
$type = strtoupper($type);
if (!isset($this->_loaders[$type])) {
switch ($type) {
case self::DECORATOR:
$prefixSegment = 'Form_Decorator';
$pathSegment = 'Form/Decorator';
break;
case self::ELEMENT:
$prefixSegment = 'Form_Element';
$pathSegment = 'Form/Element';
break;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
require_once 'Zend/Loader/PluginLoader.php';
$this->_loaders[$type] = new Zend_Loader_PluginLoader(
array('Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/')
);
}
return $this->_loaders[$type];
}
/**
* Add prefix path for plugin loader
*
* If no $type specified, assumes it is a base path for both filters and
* validators, and sets each according to the following rules:
* - decorators: $prefix = $prefix . '_Decorator'
* - elements: $prefix = $prefix . '_Element'
*
* Otherwise, the path prefix is set on the appropriate plugin loader.
*
* If $type is 'decorators', sets the path in the decorator plugin loader
* for all elements. Additionally, if no $type is provided,
* {@link Zend_Form_Element::addPrefixPath()} is called on each element.
*
* @param string $path
* @return Zend_Form
* @throws Zend_Form_Exception for invalid type
*/
public function addPrefixPath($prefix, $path, $type = null)
{
$type = strtoupper($type);
switch ($type) {
case self::DECORATOR:
case self::ELEMENT:
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($prefix, $path);
return $this;
case null:
$prefix = rtrim($prefix, '_');
$path = rtrim($path, DIRECTORY_SEPARATOR);
foreach (array(self::DECORATOR, self::ELEMENT) as $type) {
$cType = ucfirst(strtolower($type));
$pluginPath = $path . DIRECTORY_SEPARATOR . $cType . DIRECTORY_SEPARATOR;
$pluginPrefix = $prefix . '_' . $cType;
$loader = $this->getPluginLoader($type);
$loader->addPrefixPath($pluginPrefix, $pluginPath);
}
return $this;
default:
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));
}
}
/**
* Add many prefix paths at once
*
* @param array $spec
* @return Zend_Form
*/
public function addPrefixPaths(array $spec)
{
if (isset($spec['prefix']) && isset($spec['path'])) {
return $this->addPrefixPath($spec['prefix'], $spec['path']);
}
foreach ($spec as $type => $paths) {
if (is_numeric($type) && is_array($paths)) {
$type = null;
if (isset($paths['prefix']) && isset($paths['path'])) {
if (isset($paths['type'])) {
$type = $paths['type'];
}
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
} elseif (!is_numeric($type)) {
if (!isset($paths['prefix']) || !isset($paths['path'])) {
continue;
}
$this->addPrefixPath($paths['prefix'], $paths['path'], $type);
}
}
return $this;
}
/**
* Add prefix path for all elements
*
* @param string $prefix
* @param string $path
* @param string $type
* @return Zend_Form
*/
public function addElementPrefixPath($prefix, $path, $type = null)
{
$this->_elementPrefixPaths[] = array(
'prefix' => $prefix,
'path' => $path,
'type' => $type,
);
foreach ($this->getElements() as $element) {
$element->addPrefixPath($prefix, $path, $type);
}
foreach ($this->getSubForms() as $subForm) {
$subForm->addElementPrefixPath($prefix, $path, $type);
}
return $this;
}
/**
* Add prefix paths for all elements
*
* @param array $spec
* @return Zend_Form
*/
public function addElementPrefixPaths(array $spec)
{
$this->_elementPrefixPaths = $this->_elementPrefixPaths + $spec;
foreach ($this->getElements() as $element) {
$element->addPrefixPaths($spec);
}
return $this;
}
/**
* Add prefix path for all display groups
*
* @param string $prefix
* @param string $path
* @return Zend_Form
*/
public function addDisplayGroupPrefixPath($prefix, $path)
{
$this->_displayGroupPrefixPaths[] = array(
'prefix' => $prefix,
'path' => $path,
);
foreach ($this->getDisplayGroups() as $group) {
$group->addPrefixPath($prefix, $path);
}
return $this;
}
/**
* Add multiple display group prefix paths at once
*
* @param array $spec
* @return Zend_Form
*/
public function addDisplayGroupPrefixPaths(array $spec)
{
foreach ($spec as $key => $value) {
if (is_string($value) && !is_numeric($key)) {
$this->addDisplayGroupPrefixPath($key, $value);
continue;
}
if (is_string($value) && is_numeric($key)) {
continue;
}
if (is_array($value)) {
$count = count($value);
if (array_keys($value) === range(0, $count - 1)) {
if ($count < 2) {
continue;
}
$prefix = array_shift($value);
$path = array_shift($value);
$this->addDisplayGroupPrefixPath($prefix, $path);
continue;
}
if (array_key_exists('prefix', $value) && array_key_exists('path', $value)) {
$this->addDisplayGroupPrefixPath($value['prefix'], $value['path']);
}
}
}
return $this;
}
// Form metadata:
/**
* Set form attribute
*
* @param string $key
* @param mixed $value
* @return Zend_Form
*/
public function setAttrib($key, $value)
{
$key = (string) $key;
$this->_attribs[$key] = $value;
return $this;
}
/**
* Add multiple form attributes at once
*
* @param array $attribs
* @return Zend_Form
*/
public function addAttribs(array $attribs)
{
foreach ($attribs as $key => $value) {
$this->setAttrib($key, $value);
}
return $this;
}
/**
* Set multiple form attributes at once
*
* Overwrites any previously set attributes.
*
* @param array $attribs
* @return Zend_Form
*/
public function setAttribs(array $attribs)
{
$this->clearAttribs();
return $this->addAttribs($attribs);
}
/**
* Retrieve a single form attribute
*
* @param string $key
* @return mixed
*/
public function getAttrib($key)
{
$key = (string) $key;
if (!isset($this->_attribs[$key])) {
return null;
}
return $this->_attribs[$key];
}
/**
* Retrieve all form attributes/metadata
*
* @return array
*/
public function getAttribs()
{
return $this->_attribs;
}
/**
* Remove attribute
*
* @param string $key
* @return bool
*/
public function removeAttrib($key)
{
if (isset($this->_attribs[$key])) {
unset($this->_attribs[$key]);
return true;
}
return false;
}
/**
* Clear all form attributes
*
* @return Zend_Form
*/
public function clearAttribs()
{
$this->_attribs = array();
return $this;
}
/**
* Set form action
*
* @param string $action
* @return Zend_Form
*/
public function setAction($action)
{
return $this->setAttrib('action', (string) $action);
}
/**
* Get form action
*
* Sets default to '' if not set.
*
* @return string
*/
public function getAction()
{
$action = $this->getAttrib('action');
if (null === $action) {
$action = '';
$this->setAction($action);
}
return $action;
}
/**
* Set form method
*
* Only values in {@link $_methods()} allowed
*
* @param string $method
* @return Zend_Form
* @throws Zend_Form_Exception
*/
public function setMethod($method)
{
$method = strtolower($method);
if (!in_array($method, $this->_methods)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('"%s" is an invalid form method', $method));
}
$this->setAttrib('method', $method);
return $this;
}
/**
* Retrieve form method
*
* @return string
*/
public function getMethod()
{
if (null === ($method = $this->getAttrib('method'))) {
$method = self::METHOD_POST;
$this->setAttrib('method', $method);
}
return strtolower($method);
}
/**
* Set encoding type
*
* @param string $value
* @return Zend_Form
*/
public function setEnctype($value)
{
$this->setAttrib('enctype', $value);
return $this;
}
/**
* Get encoding type
*
* @return string
*/
public function getEnctype()
{
if (null === ($enctype = $this->getAttrib('enctype'))) {
$enctype = self::ENCTYPE_URLENCODED;
$this->setAttrib('enctype', $enctype);
}
return $this->getAttrib('enctype');
}
/**
* Filter a name to only allow valid variable characters
*
* @param string $value
* @param bool $allowBrackets
* @return string
*/
public function filterName($value, $allowBrackets = false)
{
$charset = '^a-zA-Z0-9_\x7f-\xff';
if ($allowBrackets) {
$charset .= '\[\]';
}
return preg_replace('/[' . $charset . ']/', '', (string) $value);
}
/**
* Set form name
*
* @param string $name
* @return Zend_Form
*/
public function setName($name)
{
$name = $this->filterName($name);
if (('0' !== $name) && empty($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty');
}
return $this->setAttrib('name', $name);
}
/**
* Get name attribute
*
* @return null|string
*/
public function getName()
{
return $this->getAttrib('name');
}
/**
* Get fully qualified name
*
* Places name as subitem of array and/or appends brackets.
*
* @return string
*/
public function getFullyQualifiedName()
{
return $this->getName();
}
/**
* Get element id
*
* @return string
*/
public function getId()
{
if (null !== ($id = $this->getAttrib('id'))) {
return $id;
}
$id = $this->getFullyQualifiedName();
// Bail early if no array notation detected
if (!strstr($id, '[')) {
return $id;
}
// Strip array notation
if ('[]' == substr($id, -2)) {
$id = substr($id, 0, strlen($id) - 2);
}
$id = str_replace('][', '-', $id);
$id = str_replace(array(']', '['), '-', $id);
$id = trim($id, '-');
return $id;
}
/**
* Set form legend
*
* @param string $value
* @return Zend_Form
*/
public function setLegend($value)
{
$this->_legend = (string) $value;
return $this;
}
/**
* Get form legend
*
* @return string
*/
public function getLegend()
{
return $this->_legend;
}
/**
* Set form description
*
* @param string $value
* @return Zend_Form
*/
public function setDescription($value)
{
$this->_description = (string) $value;
return $this;
}
/**
* Retrieve form description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
/**
* Set form order
*
* @param int $index
* @return Zend_Form
*/
public function setOrder($index)
{
$this->_formOrder = (int) $index;
return $this;
}
/**
* Get form order
*
* @return int|null
*/
public function getOrder()
{
return $this->_formOrder;
}
// Element interaction:
/**
* Add a new element
*
* $element may be either a string element type, or an object of type
* Zend_Form_Element. If a string element type is provided, $name must be
* provided, and $options may be optionally provided for configuring the
* element.
*
* If a Zend_Form_Element is provided, $name may be optionally provided,
* and any provided $options will be ignored.
*
* @param string|Zend_Form_Element $element
* @param string $name
* @param array|Zend_Config $options
* @return Zend_Form
*/
public function addElement($element, $name = null, $options = null)
{
if (is_string($element)) {
if (null === $name) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Elements specified by string must have an accompanying name');
}
$this->_elements[$name] = $this->createElement($element, $name, $options);
} elseif ($element instanceof Zend_Form_Element) {
$prefixPaths = array();
$prefixPaths['decorator'] = $this->getPluginLoader('decorator')->getPaths();
if (!empty($this->_elementPrefixPaths)) {
$prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths);
}
if (null === $name) {
$name = $element->getName();
}
$this->_elements[$name] = $element;
$this->_elements[$name]->addPrefixPaths($prefixPaths);
}
$this->_order[$name] = $this->_elements[$name]->getOrder();
$this->_orderUpdated = true;
$this->_setElementsBelongTo($name);
return $this;
}
/**
* Create an element
*
* Acts as a factory for creating elements. Elements created with this
* method will not be attached to the form, but will contain element
* settings as specified in the form object (including plugin loader
* prefix paths, default decorators, etc.).
*
* @param string $type
* @param string $name
* @param array|Zend_Config $options
* @return Zend_Form_Element
*/
public function createElement($type, $name, $options = null)
{
if (!is_string($type)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Element type must be a string indicating type');
}
if (!is_string($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Element name must be a string');
}
$prefixPaths = array();
$prefixPaths['decorator'] = $this->getPluginLoader('decorator')->getPaths();
if (!empty($this->_elementPrefixPaths)) {
$prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths);
}
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if ((null === $options) || !is_array($options)) {
$options = array('prefixPath' => $prefixPaths);
} elseif (is_array($options)) {
if (array_key_exists('prefixPath', $options)) {
$options['prefixPath'] = array_merge($prefixPaths, $options['prefixPath']);
} else {
$options['prefixPath'] = $prefixPaths;
}
}
$class = $this->getPluginLoader(self::ELEMENT)->load($type);
$element = new $class($name, $options);
return $element;
}
/**
* Add multiple elements at once
*
* @param array $elements
* @return Zend_Form
*/
public function addElements(array $elements)
{
foreach ($elements as $key => $spec) {
$name = null;
if (!is_numeric($key)) {
$name = $key;
}
if (is_string($spec) || ($spec instanceof Zend_Form_Element)) {
$this->addElement($spec, $name);
continue;
}
if (is_array($spec)) {
$argc = count($spec);
$options = array();
if (isset($spec['type'])) {
$type = $spec['type'];
if (isset($spec['name'])) {
$name = $spec['name'];
}
if (isset($spec['options'])) {
$options = $spec['options'];
}
$this->addElement($type, $name, $options);
} else {
switch ($argc) {
case 0:
continue;
case (1 <= $argc):
$type = array_shift($spec);
case (2 <= $argc):
if (null === $name) {
$name = array_shift($spec);
} else {
$options = array_shift($spec);
}
case (3 <= $argc):
if (empty($options)) {
$options = array_shift($spec);
}
default:
$this->addElement($type, $name, $options);
}
}
}
}
return $this;
}
/**
* Set form elements (overwrites existing elements)
*
* @param array $elements
* @return Zend_Form
*/
public function setElements(array $elements)
{
$this->clearElements();
return $this->addElements($elements);
}
/**
* Retrieve a single element
*
* @param string $name
* @return Zend_Form_Element|null
*/
public function getElement($name)
{
if (array_key_exists($name, $this->_elements)) {
return $this->_elements[$name];
}
return null;
}
/**
* Retrieve all elements
*
* @return array
*/
public function getElements()
{
return $this->_elements;
}
/**
* Remove element
*
* @param string $name
* @return boolean
*/
public function removeElement($name)
{
$name = (string) $name;
if (isset($this->_elements[$name])) {
unset($this->_elements[$name]);
if (array_key_exists($name, $this->_order)) {
unset($this->_order[$name]);
$this->_orderUpdated = true;
} else {
foreach ($this->_displayGroups as $group) {
if (null !== $group->getElement($name)) {
$group->removeElement($name);
}
}
}
return true;
}
return false;
}
/**
* Remove all form elements
*
* @return Zend_Form
*/
public function clearElements()
{
foreach (array_keys($this->_elements) as $key) {
if (array_key_exists($key, $this->_order)) {
unset($this->_order[$key]);
}
}
$this->_elements = array();
$this->_orderUpdated = true;
return $this;
}
/**
* Set default values for elements
*
* If an element's name is not specified as a key in the array, its value
* is set to null.
*
* @param array $defaults
* @return Zend_Form
*/
public function setDefaults(array $defaults)
{
foreach ($this->getElements() as $name => $element) {
if (array_key_exists($name, $defaults)) {
$this->setDefault($name, $defaults[$name]);
}
}
foreach ($this->getSubForms() as $name => $form) {
if (array_key_exists($name, $defaults)) {
$form->setDefaults($defaults[$name]);
} else {
$form->setDefaults($defaults);
}
}
return $this;
}
/**
* Set default value for an element
*
* @param string $name
* @param mixed $value
* @return Zend_Form
*/
public function setDefault($name, $value)
{
$name = (string) $name;
if ($element = $this->getElement($name)) {
$element->setValue($value);
} else {
if (is_scalar($value)) {
foreach ($this->getSubForms() as $subForm) {
$subForm->setDefault($name, $value);
}
} elseif (is_array($value) && ($subForm = $this->getSubForm($name))) {
$subForm->setDefaults($value);
}
}
return $this;
}
/**
* Retrieve value for single element
*
* @param string $name
* @return mixed
*/
public function getValue($name)
{
if ($element = $this->getElement($name)) {
return $element->getValue();
}
if ($subForm = $this->getSubForm($name)) {
return $subForm->getValues(true);
}
foreach ($this->getSubForms() as $subForm) {
if ($name == $subForm->getElementsBelongTo()) {
return $subForm->getValues(true);
}
}
return null;
}
/**
* Retrieve all form element values
*
* @param bool $suppressArrayNotation
* @return array
*/
public function getValues($suppressArrayNotation = false)
{
$values = array();
foreach ($this->getElements() as $key => $element) {
if (!$element->getIgnore()) {
$values[$key] = $element->getValue();
}
}
foreach ($this->getSubForms() as $key => $subForm) {
$fValues = $this->_attachToArray($subForm->getValues(true), $subForm->getElementsBelongTo());
$values = array_merge($values, $fValues);
}
if (!$suppressArrayNotation && $this->isArray()) {
$values = $this->_attachToArray($values, $this->getElementsBelongTo());
}
return $values;
}
/**
* Get unfiltered element value
*
* @param string $name
* @return mixed
*/
public function getUnfilteredValue($name)
{
if ($element = $this->getElement($name)) {
return $element->getUnfilteredValue();
}
return null;
}
/**
* Retrieve all unfiltered element values
*
* @return array
*/
public function getUnfilteredValues()
{
$values = array();
foreach ($this->getElements() as $key => $element) {
$values[$key] = $element->getUnfilteredValue();
}
return $values;
}
/**
* Set all elements' filters
*
* @param array $filters
* @return Zend_Form
*/
public function setElementFilters(array $filters)
{
foreach ($this->getElements() as $element) {
$element->setFilters($filters);
}
return $this;
}
/**
* Set name of array elements belong to
*
* @param string $array
* @return Zend_Form
*/
public function setElementsBelongTo($array)
{
$origName = $this->getElementsBelongTo();
$name = $this->filterName($array, true);
if (empty($name)) {
$name = null;
}
$this->_elementsBelongTo = $name;
if (null === $name) {
$this->setIsArray(false);
if (null !== $origName) {
$this->_setElementsBelongTo();
}
} else {
$this->setIsArray(true);
$this->_setElementsBelongTo();
}
return $this;
}
/**
* Set array to which elements belong
*
* @param string $name Element name
* @return void
*/
protected function _setElementsBelongTo($name = null)
{
$array = $this->getElementsBelongTo();
if (null === $array) {
return;
}
if (null === $name) {
foreach ($this->getElements() as $element) {
$element->setBelongsTo($array);
}
} else {
if (null !== ($element = $this->getElement($name))) {
$element->setBelongsTo($array);
}
}
}
/**
* Get name of array elements belong to
*
* @return string|null
*/
public function getElementsBelongTo()
{
if ((null === $this->_elementsBelongTo) && $this->isArray()) {
$name = $this->getName();
if (!empty($name)) {
return $name;
}
}
return $this->_elementsBelongTo;
}
/**
* Set flag indicating elements belong to array
*
* @param bool $flag Value of flag
* @return Zend_Form
*/
public function setIsArray($flag)
{
$this->_isArray = (bool) $flag;
return $this;
}
/**
* Get flag indicating if elements belong to an array
*
* @return bool
*/
public function isArray()
{
return $this->_isArray;
}
// Element groups:
/**
* Add a form group/subform
*
* @param Zend_Form $form
* @param string $name
* @param int $order
* @return Zend_Form
*/
public function addSubForm(Zend_Form $form, $name, $order = null)
{
$name = (string) $name;
foreach ($this->_loaders as $type => $loader) {
$loaderPaths = $loader->getPaths();
foreach ($loaderPaths as $prefix => $paths) {
foreach ($paths as $path) {
$form->addPrefixPath($prefix, $path, $type);
}
}
}
if (!empty($this->_elementPrefixPaths)) {
foreach ($this->_elementPrefixPaths as $spec) {
list($prefix, $path, $type) = array_values($spec);
$form->addElementPrefixPath($prefix, $path, $type);
}
}
if (!empty($this->_displayGroupPrefixPaths)) {
foreach ($this->_displayGroupPrefixPaths as $spec) {
list($prefix, $path) = array_values($spec);
$form->addDisplayGroupPrefixPath($prefix, $path);
}
}
if (null !== $order) {
$form->setOrder($order);
}
$form->setName($name);
$this->_subForms[$name] = $form;
$this->_order[$name] = $order;
$this->_orderUpdated = true;
return $this;
}
/**
* Add multiple form subForms/subforms at once
*
* @param array $subForms
* @return Zend_Form
*/
public function addSubForms(array $subForms)
{
foreach ($subForms as $key => $spec) {
$name = null;
if (!is_numeric($key)) {
$name = $key;
}
if ($spec instanceof Zend_Form) {
$this->addSubForm($spec, $name);
continue;
}
if (is_array($spec)) {
$argc = count($spec);
$order = null;
switch ($argc) {
case 0:
continue;
case (1 <= $argc):
$subForm = array_shift($spec);
case (2 <= $argc):
$name = array_shift($spec);
case (3 <= $argc):
$order = array_shift($spec);
default:
$this->addSubForm($subForm, $name, $order);
}
}
}
return $this;
}
/**
* Set multiple form subForms/subforms (overwrites)
*
* @param array $subForms
* @return Zend_Form
*/
public function setSubForms(array $subForms)
{
$this->clearSubForms();
return $this->addSubForms($subForms);
}
/**
* Retrieve a form subForm/subform
*
* @param string $name
* @return Zend_Form|null
*/
public function getSubForm($name)
{
$name = (string) $name;
if (isset($this->_subForms[$name])) {
return $this->_subForms[$name];
}
return null;
}
/**
* Retrieve all form subForms/subforms
*
* @return array
*/
public function getSubForms()
{
return $this->_subForms;
}
/**
* Remove form subForm/subform
*
* @param string $name
* @return boolean
*/
public function removeSubForm($name)
{
$name = (string) $name;
if (array_key_exists($name, $this->_subForms)) {
unset($this->_subForms[$name]);
if (array_key_exists($name, $this->_order)) {
unset($this->_order[$name]);
$this->_orderUpdated = true;
}
return true;
}
return false;
}
/**
* Remove all form subForms/subforms
*
* @return Zend_Form
*/
public function clearSubForms()
{
foreach (array_keys($this->_subForms) as $key) {
if (array_key_exists($key, $this->_order)) {
unset($this->_order[$key]);
}
}
$this->_subForms = array();
$this->_orderUpdated = true;
return $this;
}
// Display groups:
/**
* Set default display group class
*
* @param string $class
* @return Zend_Form
*/
public function setDefaultDisplayGroupClass($class)
{
$this->_defaultDisplayGroupClass = (string) $class;
return $this;
}
/**
* Retrieve default display group class
*
* @return string
*/
public function getDefaultDisplayGroupClass()
{
return $this->_defaultDisplayGroupClass;
}
/**
* Add a display group
*
* Groups named elements for display purposes.
*
* If a referenced element does not yet exist in the form, it is omitted.
*
* @param array $elements
* @param string $name
* @param array|Zend_Config $options
* @return Zend_Form
* @throws Zend_Form_Exception if no valid elements provided
*/
public function addDisplayGroup(array $elements, $name, $options = null)
{
$group = array();
foreach ($elements as $element) {
if (isset($this->_elements[$element])) {
$add = $this->getElement($element);
if (null !== $add) {
unset($this->_order[$element]);
$group[] = $add;
}
}
}
if (empty($group)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('No valid elements specified for display group');
}
$name = (string) $name;
if (is_array($options)) {
$options['elements'] = $group;
} elseif ($options instanceof Zend_Config) {
$options = $options->toArray();
$options['elements'] = $group;
} else {
$options = array('elements' => $group);
}
if (isset($options['displayGroupClass'])) {
$class = $options['displayGroupClass'];
unset($options['displayGroupClass']);
} else {
$class = $this->getDefaultDisplayGroupClass();
}
if (!class_exists($class)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($class);
}
$this->_displayGroups[$name] = new $class(
$name,
$this->getPluginLoader(self::DECORATOR),
$options
);
if (!empty($this->_displayGroupPrefixPaths)) {
$this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths);
}
$this->_order[$name] = $this->_displayGroups[$name]->getOrder();
$this->_orderUpdated = true;
return $this;
}
/**
* Add a display group object (used with cloning)
*
* @param Zend_Form_DisplayGroup $group
* @param string|null $name
* @return Zend_Form
*/
protected function _addDisplayGroupObject(Zend_Form_DisplayGroup $group, $name = null)
{
if (null === $name) {
$name = $group->getName();
if (empty($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid display group added; requires name');
}
}
$this->_displayGroups[$name] = $group;
if (!empty($this->_displayGroupPrefixPaths)) {
$this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths);
}
$this->_order[$name] = $this->_displayGroups[$name]->getOrder();
$this->_orderUpdated = true;
return $this;
}
/**
* Add multiple display groups at once
*
* @param array $groups
* @return Zend_Form
*/
public function addDisplayGroups(array $groups)
{
foreach ($groups as $key => $spec) {
$name = null;
if (!is_numeric($key)) {
$name = $key;
}
if ($spec instanceof Zend_Form_DisplayGroup) {
$this->_addDisplayGroupObject($spec);
}
if (!is_array($spec) || empty($spec)) {
continue;
}
$argc = count($spec);
$options = array();
if (isset($spec['elements'])) {
$elements = $spec['elements'];
if (isset($spec['name'])) {
$name = $spec['name'];
}
if (isset($spec['options'])) {
$options = $spec['options'];
}
$this->addDisplayGroup($elements, $name, $options);
} else {
switch ($argc) {
case (1 <= $argc):
$elements = array_shift($spec);
if (!is_array($elements) && (null !== $name)) {
$elements = array_merge((array) $elements, $spec);
$this->addDisplayGroup($elements, $name);
break;
}
case (2 <= $argc):
if (null !== $name) {
$options = array_shift($spec);
$this->addDisplayGroup($elements, $name, $options);
break;
}
$name = array_shift($spec);
case (3 <= $argc):
$options = array_shift($spec);
default:
$this->addDisplayGroup($elements, $name, $options);
}
}
}
return $this;
}
/**
* Add multiple display groups (overwrites)
*
* @param array $groups
* @return Zend_Form
*/
public function setDisplayGroups(array $groups)
{
return $this->clearDisplayGroups()
->addDisplayGroups($groups);
}
/**
* Return a display group
*
* @param string $name
* @return array|null
*/
public function getDisplayGroup($name)
{
$name = (string) $name;
if (isset($this->_displayGroups[$name])) {
return $this->_displayGroups[$name];
}
return null;
}
/**
* Return all display groups
*
* @return array
*/
public function getDisplayGroups()
{
return $this->_displayGroups;
}
/**
* Remove a display group by name
*
* @param string $name
* @return boolean
*/
public function removeDisplayGroup($name)
{
$name = (string) $name;
if (array_key_exists($name, $this->_displayGroups)) {
foreach ($this->_displayGroups[$name] as $key => $element) {
if (array_key_exists($key, $this->_elements)) {
$this->_order[$key] = $element->getOrder();
$this->_orderUpdated = true;
}
}
unset($this->_displayGroups[$name]);
if (array_key_exists($name, $this->_order)) {
unset($this->_order[$name]);
$this->_orderUpdated = true;
}
return true;
}
return false;
}
/**
* Remove all display groups
*
* @return Zend_Form
*/
public function clearDisplayGroups()
{
foreach ($this->_displayGroups as $key => $group) {
if (array_key_exists($key, $this->_order)) {
unset($this->_order[$key]);
}
foreach ($group as $name => $element) {
if (isset($this->_elements[$name])) {
$this->_order[$name] = $element->getOrder();
}
$this->_order[$name] = $element->getOrder();
}
}
$this->_displayGroups = array();
$this->_orderUpdated = true;
return $this;
}
// Processing
/**
* Populate form
*
* Proxies to {@link setDefaults()}
*
* @param array $values
* @return Zend_Form
*/
public function populate(array $values)
{
return $this->setDefaults($values);
}
/**
* Determine array key name from given value
*
* Given a value such as foo[bar][baz], returns the last element (in this case, 'baz').
*
* @param string $value
* @return string
*/
protected function _getArrayName($value)
{
if (empty($value) || !is_string($value)) {
return $value;
}
if (!strstr($value, '[')) {
return $value;
}
$endPos = strlen($value) - 1;
if (']' != $value[$endPos]) {
return $value;
}
$start = strrpos($value, '[') + 1;
$name = substr($value, $start, $endPos - $start);
return $name;
}
/**
* Extract the value by walking the array using given array path.
*
* Given an array path such as foo[bar][baz], returns the value of the last
* element (in this case, 'baz').
*
* @param array $value Array to walk
* @param string $arrayPath Array notation path of the part to extract
* @return string
*/
protected function _dissolveArrayValue($value, $arrayPath)
{
// As long as we have more levels
while ($arrayPos = strpos($arrayPath, '[')) {
// Get the next key in the path
$arrayKey = trim(substr($arrayPath, 0, $arrayPos), ']');
// Set the potentially final value or the next search point in the array
if (isset($value[$arrayKey])) {
$value = $value[$arrayKey];
}
// Set the next search point in the path
$arrayPath = trim(substr($arrayPath, $arrayPos + 1), ']');
}
if (isset($value[$arrayPath])) {
$value = $value[$arrayPath];
}
return $value;
}
/**
* Converts given arrayPath to an array and attaches given value at the end of it.
*
* @param mixed $value The value to attach
* @param string $arrayPath Given array path to convert and attach to.
* @return array
*/
protected function _attachToArray($value, $arrayPath)
{
// As long as we have more levels
while ($arrayPos = strrpos($arrayPath, '[')) {
// Get the next key in the path
$arrayKey = trim(substr($arrayPath, $arrayPos + 1), ']');
// Attach
$value = array($arrayKey => $value);
// Set the next search point in the path
$arrayPath = trim(substr($arrayPath, 0, $arrayPos), ']');
}
$value = array($arrayPath => $value);
return $value;
}
/**
* Validate the form
*
* @param array $data
* @return boolean
*/
public function isValid($data)
{
if (!is_array($data)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(__CLASS__ . '::' . __METHOD__ . ' expects an array');
}
$translator = $this->getTranslator();
$valid = true;
if ($this->isArray()) {
$data = $this->_dissolveArrayValue($data, $this->getElementsBelongTo());
}
foreach ($this->getElements() as $key => $element) {
$element->setTranslator($translator);
if (!isset($data[$key])) {
$valid = $element->isValid(null, $data) && $valid;
} else {
$valid = $element->isValid($data[$key], $data) && $valid;
}
}
foreach ($this->getSubForms() as $key => $form) {
$form->setTranslator($translator);
if (isset($data[$key])) {
$valid = $form->isValid($data[$key]) && $valid;
} else {
$valid = $form->isValid($data) && $valid;
}
}
$this->_errorsExist = !$valid;
return $valid;
}
/**
* Validate a partial form
*
* Does not check for required flags.
*
* @param array $data
* @return boolean
*/
public function isValidPartial(array $data)
{
if ($this->isArray()) {
$data = $this->_dissolveArrayValue($data, $this->getElementsBelongTo());
}
$translator = $this->getTranslator();
$valid = true;
$validatedSubForms = array();
foreach ($data as $key => $value) {
if (null !== ($element = $this->getElement($key))) {
if (null !== $translator) {
$element->setTranslator($translator);
}
$valid = $element->isValid($value, $data) && $valid;
} elseif (null !== ($subForm = $this->getSubForm($key))) {
if (null !== $translator) {
$subForm->setTranslator($translator);
}
$valid = $subForm->isValidPartial($data[$key]) && $valid;
$validatedSubForms[] = $key;
}
}
foreach ($this->getSubForms() as $key => $subForm) {
if (!in_array($key, $validatedSubForms)) {
if (null !== $translator) {
$subForm->setTranslator($translator);
}
$valid = $subForm->isValidPartial($data) && $valid;
}
}
$this->_errorsExist = !$valid;
return $valid;
}
/**
* Process submitted AJAX data
*
* Checks if provided $data is valid, via {@link isValidPartial()}. If so,
* it returns JSON-encoded boolean true. If not, it returns JSON-encoded
* error messages (as returned by {@link getMessages()}).
*
* @param array $data
* @return string JSON-encoded boolean true or error messages
*/
public function processAjax(array $data)
{
require_once 'Zend/Json.php';
if ($this->isValidPartial($data)) {
return Zend_Json::encode(true);
}
$messages = $this->getMessages();
return Zend_Json::encode($messages);
}
/**
* Add a custom error message to return in the event of failed validation
*
* @param string $message
* @return Zend_Form
*/
public function addErrorMessage($message)
{
$this->_errorMessages[] = (string) $message;
return $this;
}
/**
* Add multiple custom error messages to return in the event of failed validation
*
* @param array $messages
* @return Zend_Form
*/
public function addErrorMessages(array $messages)
{
foreach ($messages as $message) {
$this->addErrorMessage($message);
}
return $this;
}
/**
* Same as addErrorMessages(), but clears custom error message stack first
*
* @param array $messages
* @return Zend_Form
*/
public function setErrorMessages(array $messages)
{
$this->clearErrorMessages();
return $this->addErrorMessages($messages);
}
/**
* Retrieve custom error messages
*
* @return array
*/
public function getErrorMessages()
{
return $this->_errorMessages;
}
/**
* Clear custom error messages stack
*
* @return Zend_Form
*/
public function clearErrorMessages()
{
$this->_errorMessages = array();
return $this;
}
/**
* Mark the element as being in a failed validation state
*
* @return Zend_Form
*/
public function markAsError()
{
$this->_errorsExist = true;
return $this;
}
/**
* Add an error message and mark element as failed validation
*
* @param string $message
* @return Zend_Form
*/
public function addError($message)
{
$this->addErrorMessage($message);
$this->markAsError();
return $this;
}
/**
* Add multiple error messages and flag element as failed validation
*
* @param array $messages
* @return Zend_Form
*/
public function addErrors(array $messages)
{
foreach ($messages as $message) {
$this->addError($message);
}
return $this;
}
/**
* Overwrite any previously set error messages and flag as failed validation
*
* @param array $messages
* @return Zend_Form
*/
public function setErrors(array $messages)
{
$this->clearErrorMessages();
return $this->addErrors($messages);
}
public function persistData()
{
}
/**
* Are there errors in the form?
*
* @return bool
*/
public function isErrors()
{
return $this->_errorsExist;
}
/**
* Get error codes for all elements failing validation
*
* @param string $name
* @return array
*/
public function getErrors($name = null)
{
$errors = array();
if ((null !== $name) && isset($this->_elements[$name])) {
$errors = $this->getElement($name)->getErrors();
} elseif ((null !== $name) && isset($this->_subForms[$name])) {
$errors = $this->getSubForm($name)->getErrors();
} else {
foreach ($this->_elements as $key => $element) {
$errors[$key] = $element->getErrors();
}
foreach ($this->getSubForms() as $key => $subForm) {
$fErrors = $this->_attachToArray($subForm->getErrors(), $subForm->getElementsBelongTo());
$errors = array_merge($errors, $fErrors);
}
}
return $errors;
}
/**
* Retrieve error messages from elements failing validations
*
* @param string $name
* @param bool $suppressArrayNotation
* @return array
*/
public function getMessages($name = null, $suppressArrayNotation = false)
{
if ((null !== $name) && isset($this->_elements[$name])) {
return $this->getElement($name)->getMessages();
}
if ((null !== $name) && isset($this->_subForms[$name])) {
return $this->getSubForm($name)->getMessages(null, true);
}
$arrayKeys = array();
foreach ($this->getSubForms() as $key => $subForm) {
$array = $this->_getArrayName($subForm->getElementsBelongTo());
if (!empty($array)) {
if ($name == $array) {
return $subForm->getMessages(null, true);
}
$arrayKeys[$key] = $subForm->getElementsBelongTo();
}
}
$customMessages = $this->_getErrorMessages();
if ($this->isErrors() && !empty($customMessages)) {
return $customMessages;
}
$messages = array();
foreach ($this->getElements() as $name => $element) {
$eMessages = $element->getMessages();
if (!empty($eMessages)) {
$messages[$name] = $eMessages;
}
}
foreach ($this->getSubForms() as $key => $subForm) {
$fMessages = $subForm->getMessages(null, true);
if (!empty($fMessages)) {
if (array_key_exists($key, $arrayKeys)) {
$fMessages = $this->_attachToArray($fMessages, $arrayKeys[$key]);
$messages = array_merge($messages, $fMessages);
} else {
$messages[$key] = $fMessages;
}
}
}
if (!$suppressArrayNotation && $this->isArray()) {
$messages = $this->_attachToArray($messages, $this->getElementsBelongTo());
}
return $messages;
}
// Rendering
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_Form
*/
public function setView(Zend_View_Interface $view = null)
{
$this->_view = $view;
return $this;
}
/**
* Retrieve view object
*
* If none registered, attempts to pull from ViewRenderer.
*
* @return Zend_View_Interface|null
*/
public function getView()
{
if (null === $this->_view) {
require_once 'Zend/Controller/Action/HelperBroker.php';
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$this->setView($viewRenderer->view);
}
return $this->_view;
}
/**
* Instantiate a decorator based on class name or class name fragment
*
* @param string $name
* @param null|array $options
* @return Zend_Form_Decorator_Interface
*/
protected function _getDecorator($name, $options)
{
$class = $this->getPluginLoader(self::DECORATOR)->load($name);
if (null === $options) {
$decorator = new $class;
} else {
$decorator = new $class($options);
}
return $decorator;
}
/**
* Add a decorator for rendering the element
*
* @param string|Zend_Form_Decorator_Interface $decorator
* @param array|Zend_Config $options Options with which to initialize decorator
* @return Zend_Form
*/
public function addDecorator($decorator, $options = null)
{
if ($decorator instanceof Zend_Form_Decorator_Interface) {
$name = get_class($decorator);
} elseif (is_string($decorator)) {
$name = $decorator;
$decorator = array(
'decorator' => $name,
'options' => $options,
);
} elseif (is_array($decorator)) {
foreach ($decorator as $name => $spec) {
break;
}
if (is_numeric($name)) {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string');
}
if (is_string($spec)) {
$decorator = array(
'decorator' => $spec,
'options' => $options,
);
} elseif ($spec instanceof Zend_Form_Decorator_Interface) {
$decorator = $spec;
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface');
}
$this->_decorators[$name] = $decorator;
return $this;
}
/**
* Add many decorators at once
*
* @param array $decorators
* @return Zend_Form
*/
public function addDecorators(array $decorators)
{
foreach ($decorators as $decoratorInfo) {
if (is_string($decoratorInfo)) {
$this->addDecorator($decoratorInfo);
} elseif ($decoratorInfo instanceof Zend_Form_Decorator_Interface) {
$this->addDecorator($decoratorInfo);
} elseif (is_array($decoratorInfo)) {
$argc = count($decoratorInfo);
$options = array();
if (isset($decoratorInfo['decorator'])) {
$decorator = $decoratorInfo['decorator'];
if (isset($decoratorInfo['options'])) {
$options = $decoratorInfo['options'];
}
$this->addDecorator($decorator, $options);
} else {
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$decorator = array_shift($decoratorInfo);
case (2 <= $argc):
$options = array_shift($decoratorInfo);
default:
$this->addDecorator($decorator, $options);
break;
}
}
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()');
}
}
return $this;
}
/**
* Overwrite all decorators
*
* @param array $decorators
* @return Zend_Form
*/
public function setDecorators(array $decorators)
{
$this->clearDecorators();
return $this->addDecorators($decorators);
}
/**
* Retrieve a registered decorator
*
* @param string $name
* @return false|Zend_Form_Decorator_Abstract
*/
public function getDecorator($name)
{
if (!isset($this->_decorators[$name])) {
$len = strlen($name);
foreach ($this->_decorators as $localName => $decorator) {
if ($len > strlen($localName)) {
continue;
}
if (0 === substr_compare($localName, $name, -$len, $len, true)) {
if (is_array($decorator)) {
return $this->_loadDecorator($decorator, $localName);
}
return $decorator;
}
}
return false;
}
if (is_array($this->_decorators[$name])) {
return $this->_loadDecorator($this->_decorators[$name], $name);
}
return $this->_decorators[$name];
}
/**
* Retrieve all decorators
*
* @return array
*/
public function getDecorators()
{
foreach ($this->_decorators as $key => $value) {
if (is_array($value)) {
$this->_loadDecorator($value, $key);
}
}
return $this->_decorators;
}
/**
* Remove a single decorator
*
* @param string $name
* @return bool
*/
public function removeDecorator($name)
{
$decorator = $this->getDecorator($name);
if ($decorator) {
if (array_key_exists($name, $this->_decorators)) {
unset($this->_decorators[$name]);
} else {
$class = get_class($decorator);
if (!array_key_exists($class, $this->_decorators)) {
return false;
}
unset($this->_decorators[$class]);
}
return true;
}
return false;
}
/**
* Clear all decorators
*
* @return Zend_Form
*/
public function clearDecorators()
{
$this->_decorators = array();
return $this;
}
/**
* Set all element decorators as specified
*
* @param array $decorators
* @param array|null $elements Specific elements to decorate or exclude from decoration
* @param bool $include Whether $elements is an inclusion or exclusion list
* @return Zend_Form
*/
public function setElementDecorators(array $decorators, array $elements = null, $include = true)
{
if (is_array($elements)) {
if ($include) {
$elementObjs = array();
foreach ($elements as $name) {
if (null !== ($element = $this->getElement($name))) {
$elementObjs[] = $element;
}
}
} else {
$elementObjs = $this->getElements();
foreach ($elements as $name) {
if (array_key_exists($name, $elementObjs)) {
unset($elementObjs[$name]);
}
}
}
} else {
$elementObjs = $this->getElements();
}
foreach ($elementObjs as $element) {
$element->setDecorators($decorators);
}
return $this;
}
/**
* Set all display group decorators as specified
*
* @param array $decorators
* @return Zend_Form
*/
public function setDisplayGroupDecorators(array $decorators)
{
foreach ($this->getDisplayGroups() as $group) {
$group->setDecorators($decorators);
}
return $this;
}
/**
* Set all subform decorators as specified
*
* @param array $decorators
* @return Zend_Form
*/
public function setSubFormDecorators(array $decorators)
{
foreach ($this->getSubForms() as $form) {
$form->setDecorators($decorators);
}
return $this;
}
/**
* Render form
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
if (null !== $view) {
$this->setView($view);
}
$content = '';
foreach ($this->getDecorators() as $decorator) {
$decorator->setElement($this);
$content = $decorator->render($content);
}
return $content;
}
/**
* Serialize as string
*
* Proxies to {@link render()}.
*
* @return string
*/
public function __toString()
{
try {
$return = $this->render();
return $return;
} catch (Exception $e) {
$message = "Exception caught by form: " . $e->getMessage()
. "\nStack Trace:\n" . $e->getTraceAsString();
trigger_error($message, E_USER_WARNING);
return '';
}
}
// Localization:
/**
* Set translator object
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return Zend_Form
*/
public function setTranslator($translator = null)
{
if (null === $translator) {
$this->_translator = null;
} elseif ($translator instanceof Zend_Translate_Adapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid translator specified');
}
return $this;
}
/**
* Set global default translator object
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return void
*/
public static function setDefaultTranslator($translator = null)
{
if (null === $translator) {
self::$_translatorDefault = null;
} elseif ($translator instanceof Zend_Translate_Adapter) {
self::$_translatorDefault = $translator;
} elseif ($translator instanceof Zend_Translate) {
self::$_translatorDefault = $translator->getAdapter();
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception('Invalid translator specified');
}
}
/**
* Retrieve translator object
*
* @return Zend_Translate|null
*/
public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
if (null === $this->_translator) {
return self::getDefaultTranslator();
}
return $this->_translator;
}
/**
* Get global default translator object
*
* @return null|Zend_Translate
*/
public static function getDefaultTranslator()
{
if (null === self::$_translatorDefault) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Translate')) {
$translator = Zend_Registry::get('Zend_Translate');
if ($translator instanceof Zend_Translate_Adapter) {
return $translator;
} elseif ($translator instanceof Zend_Translate) {
return $translator->getAdapter();
}
}
}
return self::$_translatorDefault;
}
/**
* Indicate whether or not translation should be disabled
*
* @param bool $flag
* @return Zend_Form
*/
public function setDisableTranslator($flag)
{
$this->_translatorDisabled = (bool) $flag;
return $this;
}
/**
* Is translation disabled?
*
* @return bool
*/
public function translatorIsDisabled()
{
return $this->_translatorDisabled;
}
/**
* Overloading: access to elements, form groups, and display groups
*
* @param string $name
* @return Zend_Form_Element|Zend_Form|null
*/
public function __get($name)
{
if (isset($this->_elements[$name])) {
return $this->_elements[$name];
} elseif (isset($this->_subForms[$name])) {
return $this->_subForms[$name];
} elseif (isset($this->_displayGroups[$name])) {
return $this->_displayGroups[$name];
}
return null;
}
/**
* Overloading: access to elements, form groups, and display groups
*
* @param string $name
* @param Zend_Form_Element|Zend_Form $value
* @return void
* @throws Zend_Form_Exception for invalid $value
*/
public function __set($name, $value)
{
if ($value instanceof Zend_Form_Element) {
$this->addElement($value, $name);
return;
} elseif ($value instanceof Zend_Form) {
$this->addSubForm($value, $name);
return;
} elseif (is_array($value)) {
$this->addDisplayGroup($value, $name);
return;
}
require_once 'Zend/Form/Exception.php';
if (is_object($value)) {
$type = get_class($value);
} else {
$type = gettype($value);
}
throw new Zend_Form_Exception('Only form elements and groups may be overloaded; variable of type "' . $type . '" provided');
}
/**
* Overloading: access to elements, form groups, and display groups
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
if (isset($this->_elements[$name])
|| isset($this->_subForms[$name])
|| isset($this->_displayGroups[$name]))
{
return true;
}
return false;
}
/**
* Overloading: access to elements, form groups, and display groups
*
* @param string $name
* @return void
*/
public function __unset($name)
{
if (isset($this->_elements[$name])) {
unset($this->_elements[$name]);
} elseif (isset($this->_subForms[$name])) {
unset($this->_subForms[$name]);
} elseif (isset($this->_displayGroups[$name])) {
unset($this->_displayGroups[$name]);
}
}
/**
* Overloading: allow rendering specific decorators
*
* Call renderDecoratorName() to render a specific decorator.
*
* @param string $method
* @param array $args
* @return string
* @throws Zend_Form_Exception for invalid decorator or invalid method call
*/
public function __call($method, $args)
{
if ('render' == substr($method, 0, 6)) {
$decoratorName = substr($method, 6);
if (false !== ($decorator = $this->getDecorator($decoratorName))) {
$decorator->setElement($this);
$seed = '';
if (0 < count($args)) {
$seed = array_shift($args);
}
return $decorator->render($seed);
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Decorator by name %s does not exist', $decoratorName));
}
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Method %s does not exist', $method));
}
// Interfaces: Iterator, Countable
/**
* Current element/subform/display group
*
* @return Zend_Form_Element|Zend_Form_DisplayGroup|Zend_Form
*/
public function current()
{
$this->_sort();
current($this->_order);
$key = key($this->_order);
if (isset($this->_elements[$key])) {
return $this->getElement($key);
} elseif (isset($this->_subForms[$key])) {
return $this->getSubForm($key);
} elseif (isset($this->_displayGroups[$key])) {
return $this->getDisplayGroup($key);
} else {
require_once 'Zend/Form/Exception.php';
throw new Zend_Form_Exception(sprintf('Corruption detected in form; invalid key ("%s") found in internal iterator', (string) $key));
}
}
/**
* Current element/subform/display group name
*
* @return string
*/
public function key()
{
$this->_sort();
return key($this->_order);
}
/**
* Move pointer to next element/subform/display group
*
* @return void
*/
public function next()
{
$this->_sort();
next($this->_order);
}
/**
* Move pointer to beginning of element/subform/display group loop
*
* @return void
*/
public function rewind()
{
$this->_sort();
reset($this->_order);
}
/**
* Determine if current element/subform/display group is valid
*
* @return bool
*/
public function valid()
{
$this->_sort();
return (current($this->_order) !== false);
}
/**
* Count of elements/subforms that are iterable
*
* @return int
*/
public function count()
{
return count($this->_order);
}
/**
* Set flag to disable loading default decorators
*
* @param bool $flag
* @return Zend_Form
*/
public function setDisableLoadDefaultDecorators($flag)
{
$this->_disableLoadDefaultDecorators = (bool) $flag;
return $this;
}
/**
* Should we load the default decorators?
*
* @return bool
*/
public function loadDefaultDecoratorsIsDisabled()
{
return $this->_disableLoadDefaultDecorators;
}
/**
* Load the default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
->addDecorator('Form');
}
}
/**
* Sort items according to their order
*
* @return void
*/
protected function _sort()
{
if ($this->_orderUpdated) {
$items = array();
$index = 0;
foreach ($this->_order as $key => $order) {
if (null === $order) {
if (null === ($order = $this->{$key}->getOrder())) {
while (array_search($index, $this->_order, true)) {
++$index;
}
$items[$index] = $key;
++$index;
} else {
$items[$order] = $key;
}
} else {
$items[$order] = $key;
}
}
$items = array_flip($items);
asort($items);
$this->_order = $items;
$this->_orderUpdated = false;
}
}
/**
* Lazy-load a decorator
*
* @param array $decorator Decorator type and options
* @param mixed $name Decorator name or alias
* @return Zend_Form_Decorator_Interface
*/
protected function _loadDecorator(array $decorator, $name)
{
$sameName = false;
if ($name == $decorator['decorator']) {
$sameName = true;
}
$instance = $this->_getDecorator($decorator['decorator'], $decorator['options']);
if ($sameName) {
$newName = get_class($instance);
$decoratorNames = array_keys($this->_decorators);
$order = array_flip($decoratorNames);
$order[$newName] = $order[$name];
$decoratorsExchange = array();
unset($order[$name]);
asort($order);
foreach ($order as $key => $index) {
if ($key == $newName) {
$decoratorsExchange[$key] = $instance;
continue;
}
$decoratorsExchange[$key] = $this->_decorators[$key];
}
$this->_decorators = $decoratorsExchange;
} else {
$this->_decorators[$name] = $instance;
}
return $instance;
}
/**
* Retrieve optionally translated custom error messages
*
* @return array
*/
protected function _getErrorMessages()
{
$messages = $this->getErrorMessages();
$translator = $this->getTranslator();
if (null !== $translator) {
foreach ($messages as $key => $message) {
$messages[$key] = $translator->translate($message);
}
}
return $messages;
}
}
Controller/Response/Abstract.php 0000604 00000046374 15071256135 0012760 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Controller_Response_Abstract
*
* Base class for Zend_Controller responses
*
* @package Zend_Controller
* @subpackage Response
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Response_Abstract
{
/**
* Body content
* @var array
*/
protected $_body = array();
/**
* Exception stack
* @var Exception
*/
protected $_exceptions = array();
/**
* Array of headers. Each header is an array with keys 'name' and 'value'
* @var array
*/
protected $_headers = array();
/**
* Array of raw headers. Each header is a single string, the entire header to emit
* @var array
*/
protected $_headersRaw = array();
/**
* HTTP response code to use in headers
* @var int
*/
protected $_httpResponseCode = 200;
/**
* Flag; is this response a redirect?
* @var boolean
*/
protected $_isRedirect = false;
/**
* Whether or not to render exceptions; off by default
* @var boolean
*/
protected $_renderExceptions = false;
/**
* Flag; if true, when header operations are called after headers have been
* sent, an exception will be raised; otherwise, processing will continue
* as normal. Defaults to true.
*
* @see canSendHeaders()
* @var boolean
*/
public $headersSentThrowsException = true;
/**
* Normalize a header name
*
* Normalizes a header name to X-Capitalized-Names
*
* @param string $name
* @return string
*/
protected function _normalizeHeader($name)
{
$filtered = str_replace(array('-', '_'), ' ', (string) $name);
$filtered = ucwords(strtolower($filtered));
$filtered = str_replace(' ', '-', $filtered);
return $filtered;
}
/**
* Set a header
*
* If $replace is true, replaces any headers already defined with that
* $name.
*
* @param string $name
* @param string $value
* @param boolean $replace
* @return Zend_Controller_Response_Abstract
*/
public function setHeader($name, $value, $replace = false)
{
$this->canSendHeaders(true);
$name = $this->_normalizeHeader($name);
$value = (string) $value;
if ($replace) {
foreach ($this->_headers as $key => $header) {
if ($name == $header['name']) {
unset($this->_headers[$key]);
}
}
}
$this->_headers[] = array(
'name' => $name,
'value' => $value,
'replace' => $replace
);
return $this;
}
/**
* Set redirect URL
*
* Sets Location header and response code. Forces replacement of any prior
* redirects.
*
* @param string $url
* @param int $code
* @return Zend_Controller_Response_Abstract
*/
public function setRedirect($url, $code = 302)
{
$this->canSendHeaders(true);
$this->setHeader('Location', $url, true)
->setHttpResponseCode($code);
return $this;
}
/**
* Is this a redirect?
*
* @return boolean
*/
public function isRedirect()
{
return $this->_isRedirect;
}
/**
* Return array of headers; see {@link $_headers} for format
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Clear headers
*
* @return Zend_Controller_Response_Abstract
*/
public function clearHeaders()
{
$this->_headers = array();
return $this;
}
/**
* Set raw HTTP header
*
* Allows setting non key => value headers, such as status codes
*
* @param string $value
* @return Zend_Controller_Response_Abstract
*/
public function setRawHeader($value)
{
$this->canSendHeaders(true);
if ('Location' == substr($value, 0, 8)) {
$this->_isRedirect = true;
}
$this->_headersRaw[] = (string) $value;
return $this;
}
/**
* Retrieve all {@link setRawHeader() raw HTTP headers}
*
* @return array
*/
public function getRawHeaders()
{
return $this->_headersRaw;
}
/**
* Clear all {@link setRawHeader() raw HTTP headers}
*
* @return Zend_Controller_Response_Abstract
*/
public function clearRawHeaders()
{
$this->_headersRaw = array();
return $this;
}
/**
* Clear all headers, normal and raw
*
* @return Zend_Controller_Response_Abstract
*/
public function clearAllHeaders()
{
return $this->clearHeaders()
->clearRawHeaders();
}
/**
* Set HTTP response code to use with headers
*
* @param int $code
* @return Zend_Controller_Response_Abstract
*/
public function setHttpResponseCode($code)
{
if (!is_int($code) || (100 > $code) || (599 < $code)) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Invalid HTTP response code');
}
if ((300 <= $code) && (307 >= $code)) {
$this->_isRedirect = true;
} else {
$this->_isRedirect = false;
}
$this->_httpResponseCode = $code;
return $this;
}
/**
* Retrieve HTTP response code
*
* @return int
*/
public function getHttpResponseCode()
{
return $this->_httpResponseCode;
}
/**
* Can we send headers?
*
* @param boolean $throw Whether or not to throw an exception if headers have been sent; defaults to false
* @return boolean
* @throws Zend_Controller_Response_Exception
*/
public function canSendHeaders($throw = false)
{
$ok = headers_sent($file, $line);
if ($ok && $throw && $this->headersSentThrowsException) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
}
return !$ok;
}
/**
* Send all headers
*
* Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
* has been specified, it is sent with the first header.
*
* @return Zend_Controller_Response_Abstract
*/
public function sendHeaders()
{
// Only check if we can send headers if we have headers to send
if (count($this->_headersRaw) || count($this->_headers) || (200 != $this->_httpResponseCode)) {
$this->canSendHeaders(true);
} elseif (200 == $this->_httpResponseCode) {
// Haven't changed the response code, and we have no headers
return $this;
}
$httpCodeSent = false;
foreach ($this->_headersRaw as $header) {
if (!$httpCodeSent && $this->_httpResponseCode) {
header($header, true, $this->_httpResponseCode);
$httpCodeSent = true;
} else {
header($header);
}
}
foreach ($this->_headers as $header) {
if (!$httpCodeSent && $this->_httpResponseCode) {
header($header['name'] . ': ' . $header['value'], $header['replace'], $this->_httpResponseCode);
$httpCodeSent = true;
} else {
header($header['name'] . ': ' . $header['value'], $header['replace']);
}
}
if (!$httpCodeSent) {
header('HTTP/1.1 ' . $this->_httpResponseCode);
$httpCodeSent = true;
}
return $this;
}
/**
* Set body content
*
* If $name is not passed, or is not a string, resets the entire body and
* sets the 'default' key to $content.
*
* If $name is a string, sets the named segment in the body array to
* $content.
*
* @param string $content
* @param null|string $name
* @return Zend_Controller_Response_Abstract
*/
public function setBody($content, $name = null)
{
if ((null === $name) || !is_string($name)) {
$this->_body = array('default' => (string) $content);
} else {
$this->_body[$name] = (string) $content;
}
return $this;
}
/**
* Append content to the body content
*
* @param string $content
* @param null|string $name
* @return Zend_Controller_Response_Abstract
*/
public function appendBody($content, $name = null)
{
if ((null === $name) || !is_string($name)) {
if (isset($this->_body['default'])) {
$this->_body['default'] .= (string) $content;
} else {
return $this->append('default', $content);
}
} elseif (isset($this->_body[$name])) {
$this->_body[$name] .= (string) $content;
} else {
return $this->append($name, $content);
}
return $this;
}
/**
* Clear body array
*
* With no arguments, clears the entire body array. Given a $name, clears
* just that named segment; if no segment matching $name exists, returns
* false to indicate an error.
*
* @param string $name Named segment to clear
* @return boolean
*/
public function clearBody($name = null)
{
if (null !== $name) {
$name = (string) $name;
if (isset($this->_body[$name])) {
unset($this->_body[$name]);
return true;
}
return false;
}
$this->_body = array();
return true;
}
/**
* Return the body content
*
* If $spec is false, returns the concatenated values of the body content
* array. If $spec is boolean true, returns the body content array. If
* $spec is a string and matches a named segment, returns the contents of
* that segment; otherwise, returns null.
*
* @param boolean $spec
* @return string|array|null
*/
public function getBody($spec = false)
{
if (false === $spec) {
ob_start();
$this->outputBody();
return ob_get_clean();
} elseif (true === $spec) {
return $this->_body;
} elseif (is_string($spec) && isset($this->_body[$spec])) {
return $this->_body[$spec];
}
return null;
}
/**
* Append a named body segment to the body content array
*
* If segment already exists, replaces with $content and places at end of
* array.
*
* @param string $name
* @param string $content
* @return Zend_Controller_Response_Abstract
*/
public function append($name, $content)
{
if (!is_string($name)) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
}
if (isset($this->_body[$name])) {
unset($this->_body[$name]);
}
$this->_body[$name] = (string) $content;
return $this;
}
/**
* Prepend a named body segment to the body content array
*
* If segment already exists, replaces with $content and places at top of
* array.
*
* @param string $name
* @param string $content
* @return void
*/
public function prepend($name, $content)
{
if (!is_string($name)) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
}
if (isset($this->_body[$name])) {
unset($this->_body[$name]);
}
$new = array($name => (string) $content);
$this->_body = $new + $this->_body;
return $this;
}
/**
* Insert a named segment into the body content array
*
* @param string $name
* @param string $content
* @param string $parent
* @param boolean $before Whether to insert the new segment before or
* after the parent. Defaults to false (after)
* @return Zend_Controller_Response_Abstract
*/
public function insert($name, $content, $parent = null, $before = false)
{
if (!is_string($name)) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
}
if ((null !== $parent) && !is_string($parent)) {
require_once 'Zend/Controller/Response/Exception.php';
throw new Zend_Controller_Response_Exception('Invalid body segment parent key ("' . gettype($parent) . '")');
}
if (isset($this->_body[$name])) {
unset($this->_body[$name]);
}
if ((null === $parent) || !isset($this->_body[$parent])) {
return $this->append($name, $content);
}
$ins = array($name => (string) $content);
$keys = array_keys($this->_body);
$loc = array_search($parent, $keys);
if (!$before) {
// Increment location if not inserting before
++$loc;
}
if (0 === $loc) {
// If location of key is 0, we're prepending
$this->_body = $ins + $this->_body;
} elseif ($loc >= (count($this->_body))) {
// If location of key is maximal, we're appending
$this->_body = $this->_body + $ins;
} else {
// Otherwise, insert at location specified
$pre = array_slice($this->_body, 0, $loc);
$post = array_slice($this->_body, $loc);
$this->_body = $pre + $ins + $post;
}
return $this;
}
/**
* Echo the body segments
*
* @return void
*/
public function outputBody()
{
foreach ($this->_body as $content) {
echo $content;
}
}
/**
* Register an exception with the response
*
* @param Exception $e
* @return Zend_Controller_Response_Abstract
*/
public function setException(Exception $e)
{
$this->_exceptions[] = $e;
return $this;
}
/**
* Retrieve the exception stack
*
* @return array
*/
public function getException()
{
return $this->_exceptions;
}
/**
* Has an exception been registered with the response?
*
* @return boolean
*/
public function isException()
{
return !empty($this->_exceptions);
}
/**
* Does the response object contain an exception of a given type?
*
* @param string $type
* @return boolean
*/
public function hasExceptionOfType($type)
{
foreach ($this->_exceptions as $e) {
if ($e instanceof $type) {
return true;
}
}
return false;
}
/**
* Does the response object contain an exception with a given message?
*
* @param string $message
* @return boolean
*/
public function hasExceptionOfMessage($message)
{
foreach ($this->_exceptions as $e) {
if ($message == $e->getMessage()) {
return true;
}
}
return false;
}
/**
* Does the response object contain an exception with a given code?
*
* @param int $code
* @return boolean
*/
public function hasExceptionOfCode($code)
{
$code = (int) $code;
foreach ($this->_exceptions as $e) {
if ($code == $e->getCode()) {
return true;
}
}
return false;
}
/**
* Retrieve all exceptions of a given type
*
* @param string $type
* @return false|array
*/
public function getExceptionByType($type)
{
$exceptions = array();
foreach ($this->_exceptions as $e) {
if ($e instanceof $type) {
$exceptions[] = $e;
}
}
if (empty($exceptions)) {
$exceptions = false;
}
return $exceptions;
}
/**
* Retrieve all exceptions of a given message
*
* @param string $message
* @return false|array
*/
public function getExceptionByMessage($message)
{
$exceptions = array();
foreach ($this->_exceptions as $e) {
if ($message == $e->getMessage()) {
$exceptions[] = $e;
}
}
if (empty($exceptions)) {
$exceptions = false;
}
return $exceptions;
}
/**
* Retrieve all exceptions of a given code
*
* @param mixed $code
* @return void
*/
public function getExceptionByCode($code)
{
$code = (int) $code;
$exceptions = array();
foreach ($this->_exceptions as $e) {
if ($code == $e->getCode()) {
$exceptions[] = $e;
}
}
if (empty($exceptions)) {
$exceptions = false;
}
return $exceptions;
}
/**
* Whether or not to render exceptions (off by default)
*
* If called with no arguments or a null argument, returns the value of the
* flag; otherwise, sets it and returns the current value.
*
* @param boolean $flag Optional
* @return boolean
*/
public function renderExceptions($flag = null)
{
if (null !== $flag) {
$this->_renderExceptions = $flag ? true : false;
}
return $this->_renderExceptions;
}
/**
* Send the response, including all headers, rendering exceptions if so
* requested.
*
* @return void
*/
public function sendResponse()
{
$this->sendHeaders();
if ($this->isException() && $this->renderExceptions()) {
$exceptions = '';
foreach ($this->getException() as $e) {
$exceptions .= $e->__toString() . "\n";
}
echo $exceptions;
return;
}
$this->outputBody();
}
/**
* Magic __toString functionality
*
* Proxies to {@link sendResponse()} and returns response value as string
* using output buffering.
*
* @return string
*/
public function __toString()
{
ob_start();
$this->sendResponse();
return ob_get_clean();
}
}
Controller/Response/Http.php 0000604 00000002017 15071256135 0012116 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Response_Abstract */
require_once 'Zend/Controller/Response/Abstract.php';
/**
* Zend_Controller_Response_Http
*
* HTTP response for controllers
*
* @uses Zend_Controller_Response_Abstract
* @package Zend_Controller
* @subpackage Response
*/
class Zend_Controller_Response_Http extends Zend_Controller_Response_Abstract
{
}
Controller/Response/Cli.php 0000604 00000003617 15071256135 0011715 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Response_Abstract */
require_once 'Zend/Controller/Response/Abstract.php';
/**
* Zend_Controller_Response_Cli
*
* CLI response for controllers
*
* @uses Zend_Controller_Response_Abstract
* @package Zend_Controller
* @subpackage Response
* @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_Controller_Response_Cli extends Zend_Controller_Response_Abstract
{
/**
* Flag; if true, when header operations are called after headers have been
* sent, an exception will be raised; otherwise, processing will continue
* as normal. Defaults to false.
*
* @see canSendHeaders()
* @var boolean
*/
public $headersSentThrowsException = false;
/**
* Magic __toString functionality
*
* @return string
*/
public function __toString()
{
if ($this->isException() && $this->renderExceptions()) {
$exceptions = '';
foreach ($this->getException() as $e) {
$exceptions .= $e->__toString() . "\n";
}
return $exceptions;
}
return $this->_body;
}
}
Controller/Response/Exception.php 0000604 00000002064 15071256135 0013137 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Request
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';
/**
* @package Zend_Controller
* @subpackage Response
* @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_Controller_Response_Exception extends Zend_Controller_Exception
{}
Controller/Response/HttpTestCase.php 0000604 00000006436 15071256135 0013563 0 ustar 00 <?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_Controller
* @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 Zend_Controller_Response_Http
*/
require_once 'Zend/Controller/Response/Http.php';
/**
* Zend_Controller_Response_HttpTestCase
*
* @uses Zend_Controller_Response_Http
* @package Zend_Controller
* @subpackage Request
*/
class Zend_Controller_Response_HttpTestCase extends Zend_Controller_Response_Http
{
/**
* "send" headers by returning array of all headers that would be sent
*
* @return array
*/
public function sendHeaders()
{
$headers = array();
foreach ($this->_headersRaw as $header) {
$headers[] = $header;
}
foreach ($this->_headers as $header) {
$name = $header['name'];
$key = strtolower($name);
if (array_key_exists($name, $headers)) {
if ($header['replace']) {
$headers[$key] = $header['name'] . ': ' . $header['value'];
}
} else {
$headers[$key] = $header['name'] . ': ' . $header['value'];
}
}
return $headers;
}
/**
* Can we send headers?
*
* @param bool $throw
* @return void
*/
public function canSendHeaders($throw = false)
{
return true;
}
/**
* Return the concatenated body segments
*
* @return string
*/
public function outputBody()
{
$fullContent = '';
foreach ($this->_body as $content) {
$fullContent .= $content;
}
return $fullContent;
}
/**
* Get body and/or body segments
*
* @param bool|string $spec
* @return string|array|null
*/
public function getBody($spec = false)
{
if (false === $spec) {
return $this->outputBody();
} elseif (true === $spec) {
return $this->_body;
} elseif (is_string($spec) && isset($this->_body[$spec])) {
return $this->_body[$spec];
}
return null;
}
/**
* "send" Response
*
* Concats all response headers, and then final body (separated by two
* newlines)
*
* @return string
*/
public function sendResponse()
{
$headers = $this->sendHeaders();
$content = implode("\n", $headers) . "\n\n";
if ($this->isException() && $this->renderExceptions()) {
$exceptions = '';
foreach ($this->getException() as $e) {
$exceptions .= $e->__toString() . "\n";
}
$content .= $exceptions;
} else {
$content .= $this->outputBody();
}
return $content;
}
}
Controller/Router/Route/Abstract.php 0000604 00000003154 15071256135 0013525 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Route.php 1847 2006-11-23 11:36:41Z martel $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Interface */
require_once 'Zend/Controller/Router/Route/Interface.php';
/**
* Abstract Route
*
* Implements interface and provides convenience methods
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Router_Route_Abstract implements Zend_Controller_Router_Route_Interface
{
public function getVersion() {
return 2;
}
public function chain(Zend_Controller_Router_Route_Interface $route, $separator = '/')
{
require_once 'Zend/Controller/Router/Route/Chain.php';
$chain = new Zend_Controller_Router_Route_Chain();
$chain->chain($this)->chain($route, $separator);
return $chain;
}
}
Controller/Router/Route/Interface.php 0000604 00000002357 15071256135 0013666 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Interface.php 10607 2008-08-02 12:53:16Z martel $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Config */
require_once 'Zend/Config.php';
/**
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Controller_Router_Route_Interface {
public function match($path);
public function assemble($data = array(), $reset = false, $encode = false);
public static function getInstance(Zend_Config $config);
}
Controller/Router/Route/Chain.php 0000604 00000007702 15071256135 0013007 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Route.php 1847 2006-11-23 11:36:41Z martel $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* Chain route is used for managing route chaining.
*
* @package Zend_Controller
* @subpackage Router
* @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_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
{
protected $_routes = array();
protected $_separators = array();
/**
* Instantiates route based on passed Zend_Config structure
*
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{ }
public function chain(Zend_Controller_Router_Route_Interface $route, $separator = '/') {
$this->_routes[] = $route;
$this->_separators[] = $separator;
return $this;
}
/**
* Matches a user submitted path with a previously defined route.
* Assigns and returns an array of defaults on a successful match.
*
* @param Zend_Controller_Request_Http $request Request to get the path info from
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request, $partial = null)
{
$path = $request->getPathInfo();
$values = array();
foreach ($this->_routes as $key => $route) {
// TODO: Should be an interface method. Hack for 1.0 BC
if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
$match = $request->getPathInfo();
} else {
$match = $request;
}
$res = $route->match($match);
if ($res === false) return false;
$values = $res + $values;
}
return $values;
}
/**
* Assembles a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
$value = '';
foreach ($this->_routes as $key => $route) {
if ($key > 0) {
$value .= $this->_separators[$key];
}
$value .= $route->assemble($data, $reset, $encode);
if (method_exists($route, 'getVariables')) {
$variables = $route->getVariables();
foreach ($variables as $variable) {
$data[$variable] = null;
}
}
}
return $value;
}
/**
* Set the request object for this and the child routes
*
* @param Zend_Controller_Request_Abstract|null $request
* @return void
*/
public function setRequest(Zend_Controller_Request_Abstract $request = null)
{
$this->_request = $request;
foreach ($this->_routes as $route) {
if (method_exists($route, 'setRequest')) {
$route->setRequest($request);
}
}
}
}
Controller/Router/Route/Regex.php 0000604 00000017431 15071256135 0013037 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Regex.php 12525 2008-11-10 20:18:32Z ralph $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* Regex Route
*
* @package Zend_Controller
* @subpackage Router
* @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_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Abstract
{
protected $_regex = null;
protected $_defaults = array();
protected $_reverse = null;
protected $_map = array();
protected $_values = array();
/**
* Instantiates route based on passed Zend_Config structure
*
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
$map = ($config->map instanceof Zend_Config) ? $config->map->toArray() : array();
$reverse = (isset($config->reverse)) ? $config->reverse : null;
return new self($config->route, $defs, $map, $reverse);
}
public function __construct($route, $defaults = array(), $map = array(), $reverse = null)
{
$this->_regex = '#^' . $route . '$#i';
$this->_defaults = (array) $defaults;
$this->_map = (array) $map;
$this->_reverse = $reverse;
}
public function getVersion() {
return 1;
}
/**
* Matches a user submitted path with a previously defined route.
* Assigns and returns an array of defaults on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path)
{
$path = trim(urldecode($path), '/');
$res = preg_match($this->_regex, $path, $values);
if ($res === 0) return false;
// array_filter_key()? Why isn't this in a standard PHP function set yet? :)
foreach ($values as $i => $value) {
if (!is_int($i) || $i === 0) {
unset($values[$i]);
}
}
$this->_values = $values;
$values = $this->_getMappedValues($values);
$defaults = $this->_getMappedValues($this->_defaults, false, true);
$return = $values + $defaults;
return $return;
}
/**
* Maps numerically indexed array values to it's associative mapped counterpart.
* Or vice versa. Uses user provided map array which consists of index => name
* parameter mapping. If map is not found, it returns original array.
*
* Method strips destination type of keys form source array. Ie. if source array is
* indexed numerically then every associative key will be stripped. Vice versa if reversed
* is set to true.
*
* @param array $values Indexed or associative array of values to map
* @param boolean $reversed False means translation of index to association. True means reverse.
* @param boolean $preserve Should wrong type of keys be preserved or stripped.
* @return array An array of mapped values
*/
protected function _getMappedValues($values, $reversed = false, $preserve = false)
{
if (count($this->_map) == 0) {
return $values;
}
$return = array();
foreach ($values as $key => $value) {
if (is_int($key) && !$reversed) {
if (array_key_exists($key, $this->_map)) {
$index = $this->_map[$key];
} elseif (false === ($index = array_search($key, $this->_map))) {
$index = $key;
}
$return[$index] = $values[$key];
} elseif ($reversed) {
$index = (!is_int($key)) ? array_search($key, $this->_map, true) : $key;
if (false !== $index) {
$return[$index] = $values[$key];
}
} elseif ($preserve) {
$return[$key] = $value;
}
}
return $return;
}
/**
* Assembles a URL path defined by this route
*
* @param array $data An array of name (or index) and value pairs used as parameters
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
if ($this->_reverse === null) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('Cannot assemble. Reversed route is not specified.');
}
$defaultValuesMapped = $this->_getMappedValues($this->_defaults, true, false);
$matchedValuesMapped = $this->_getMappedValues($this->_values, true, false);
$dataValuesMapped = $this->_getMappedValues($data, true, false);
// handle resets, if so requested (By null value) to do so
if (($resetKeys = array_search(null, $dataValuesMapped, true)) !== false) {
foreach ((array) $resetKeys as $resetKey) {
if (isset($matchedValuesMapped[$resetKey])) {
unset($matchedValuesMapped[$resetKey]);
unset($dataValuesMapped[$resetKey]);
}
}
}
// merge all the data together, first defaults, then values matched, then supplied
$mergedData = $defaultValuesMapped;
$mergedData = $this->_arrayMergeNumericKeys($mergedData, $matchedValuesMapped);
$mergedData = $this->_arrayMergeNumericKeys($mergedData, $dataValuesMapped);
if ($encode) {
foreach ($mergedData as $key => &$value) {
$value = urlencode($value);
}
}
ksort($mergedData);
$return = @vsprintf($this->_reverse, $mergedData);
if ($return === false) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('Cannot assemble. Too few arguments?');
}
return $return;
}
/**
* Return a single parameter of route's defaults
*
* @param string $name Array key of the parameter
* @return string Previously set default
*/
public function getDefault($name) {
if (isset($this->_defaults[$name])) {
return $this->_defaults[$name];
}
}
/**
* Return an array of defaults
*
* @return array Route defaults
*/
public function getDefaults() {
return $this->_defaults;
}
/**
* _arrayMergeNumericKeys() - allows for a strict key (numeric's included) array_merge.
* php's array_merge() lacks the ability to merge with numeric keys.
*
* @param array $array1
* @param array $array2
* @return array
*/
protected function _arrayMergeNumericKeys(Array $array1, Array $array2)
{
$returnArray = $array1;
foreach ($array2 as $array2Index => $array2Value) {
$returnArray[$array2Index] = $array2Value;
}
return $returnArray;
}
}
Controller/Router/Route/Hostname.php 0000604 00000025162 15071256135 0013543 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Route.php 9581 2008-06-01 14:08:03Z martel $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* Hostname Route
*
* @package Zend_Controller
* @subpackage Router
* @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://manuals.rubyonrails.com/read/chapter/65
*/
class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route_Abstract
{
protected $_hostVariable = ':';
protected $_regexDelimiter = '#';
protected $_defaultRegex = null;
/**
* Holds names of all route's pattern variable names. Array index holds a position in host.
* @var array
*/
protected $_variables = array();
/**
* Holds Route patterns for all host parts. In case of a variable it stores it's regex
* requirement or null. In case of a static part, it holds only it's direct value.
* @var array
*/
protected $_parts = array();
/**
* Holds user submitted default values for route's variables. Name and value pairs.
* @var array
*/
protected $_defaults = array();
/**
* Holds user submitted regular expression patterns for route's variables' values.
* Name and value pairs.
* @var array
*/
protected $_requirements = array();
/**
* Default scheme
* @var string
*/
protected $_scheme = null;
/**
* Associative array filled on match() that holds matched path values
* for given variable names.
* @var array
*/
protected $_values = array();
/**
* Current request object
*
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* Helper var that holds a count of route pattern's static parts
* for validation
* @var int
*/
private $_staticCount = 0;
/**
* Set the request object
*
* @param Zend_Controller_Request_Abstract|null $request
* @return void
*/
public function setRequest(Zend_Controller_Request_Abstract $request = null)
{
$this->_request = $request;
}
/**
* Get the request object
*
* @return Zend_Controller_Request_Abstract $request
*/
public function getRequest()
{
if ($this->_request === null) {
require_once 'Zend/Controller/Front.php';
$this->_request = Zend_Controller_Front::getInstance()->getRequest();
}
return $this->_request;
}
/**
* Instantiates route based on passed Zend_Config structure
*
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{
$reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array();
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
$scheme = (isset($config->scheme)) ? $config->scheme : null;
return new self($config->route, $defs, $reqs, $scheme);
}
/**
* Prepares the route for mapping by splitting (exploding) it
* to a corresponding atomic parts. These parts are assigned
* a position which is later used for matching and preparing values.
*
* @param string $route Map used to match with later submitted hostname
* @param array $defaults Defaults for map variables with keys as variable names
* @param array $reqs Regular expression requirements for variables (keys as variable names)
* @param string $scheme
*/
public function __construct($route, $defaults = array(), $reqs = array(), $scheme = null)
{
$route = trim($route, '.');
$this->_defaults = (array) $defaults;
$this->_requirements = (array) $reqs;
$this->_scheme = $scheme;
if ($route != '') {
foreach (explode('.', $route) as $pos => $part) {
if (substr($part, 0, 1) == $this->_hostVariable) {
$name = substr($part, 1);
$this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
$this->_variables[$pos] = $name;
} else {
$this->_parts[$pos] = $part;
$this->_staticCount++;
}
}
}
}
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param Zend_Controller_Request_Http $request Request to get the host from
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request)
{
// Check the scheme if required
if ($this->_scheme !== null) {
$scheme = $request->getScheme();
if ($scheme !== $this->_scheme) {
return false;
}
}
// Get the host and remove unnecessary port information
$host = $request->getHttpHost();
if (preg_match('#:\d+$#', $host, $result) === 1) {
$host = substr($host, 0, -strlen($result[0]));
}
$hostStaticCount = 0;
$values = array();
$host = trim($host, '.');
if ($host != '') {
$host = explode('.', $host);
foreach ($host as $pos => $hostPart) {
// Host is longer than a route, it's not a match
if (!array_key_exists($pos, $this->_parts)) {
return false;
}
$name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
$hostPart = urldecode($hostPart);
// If it's a static part, match directly
if ($name === null && $this->_parts[$pos] != $hostPart) {
return false;
}
// If it's a variable with requirement, match a regex. If not - everything matches
if ($this->_parts[$pos] !== null && !preg_match($this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', $hostPart)) {
return false;
}
// If it's a variable store it's value for later
if ($name !== null) {
$values[$name] = $hostPart;
} else {
$hostStaticCount++;
}
}
}
// Check if all static mappings have been matched
if ($this->_staticCount != $hostStaticCount) {
return false;
}
$return = $values + $this->_defaults;
// Check if all map variables have been initialized
foreach ($this->_variables as $var) {
if (!array_key_exists($var, $return)) {
return false;
}
}
$this->_values = $values;
return $return;
}
/**
* Assembles user submitted parameters forming a hostname defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
$host = array();
$flag = false;
foreach ($this->_parts as $key => $part) {
$name = isset($this->_variables[$key]) ? $this->_variables[$key] : null;
$useDefault = false;
if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) {
$useDefault = true;
}
if (isset($name)) {
if (isset($data[$name]) && !$useDefault) {
$host[$key] = $data[$name];
unset($data[$name]);
} elseif (!$reset && !$useDefault && isset($this->_values[$name])) {
$host[$key] = $this->_values[$name];
} elseif (isset($this->_defaults[$name])) {
$host[$key] = $this->_defaults[$name];
} else {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception($name . ' is not specified');
}
} else {
$host[$key] = $part;
}
}
$return = '';
foreach (array_reverse($host, true) as $key => $value) {
if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key])) {
if ($encode) $value = urlencode($value);
$return = '.' . $value . $return;
$flag = true;
}
}
$url = trim($return, '.');
if ($this->_scheme !== null) {
$scheme = $this->_scheme;
} else {
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Http) {
$scheme = $request->getScheme();
} else {
$scheme = 'http';
}
}
$hostname = implode('.', $host);
$url = $scheme . '://' . $url;
return $url;
}
/**
* Return a single parameter of route's defaults
*
* @param string $name Array key of the parameter
* @return string Previously set default
*/
public function getDefault($name) {
if (isset($this->_defaults[$name])) {
return $this->_defaults[$name];
}
return null;
}
/**
* Return an array of defaults
*
* @return array Route defaults
*/
public function getDefaults() {
return $this->_defaults;
}
/**
* Get all variables which are used by the route
*
* @return array
*/
public function getVariables()
{
return $this->_variables;
}
}
Controller/Router/Route/Module.php 0000604 00000020510 15071256135 0013202 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Module.php 12310 2008-11-05 20:49:16Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* Module Route
*
* Default route for module functionality
*
* @package Zend_Controller
* @subpackage Router
* @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://manuals.rubyonrails.com/read/chapter/65
*/
class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_Abstract
{
/**
* URI delimiter
*/
const URI_DELIMITER = '/';
/**
* Default values for the route (ie. module, controller, action, params)
* @var array
*/
protected $_defaults;
protected $_values = array();
protected $_moduleValid = false;
protected $_keysSet = false;
/**#@+
* Array keys to use for module, controller, and action. Should be taken out of request.
* @var string
*/
protected $_moduleKey = 'module';
protected $_controllerKey = 'controller';
protected $_actionKey = 'action';
/**#@-*/
/**
* @var Zend_Controller_Dispatcher_Interface
*/
protected $_dispatcher;
/**
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
public function getVersion() {
return 1;
}
/**
* Instantiates route based on passed Zend_Config structure
*/
public static function getInstance(Zend_Config $config)
{
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
return new self($defs);
}
/**
* Constructor
*
* @param array $defaults Defaults for map variables with keys as variable names
* @param Zend_Controller_Dispatcher_Interface $dispatcher Dispatcher object
* @param Zend_Controller_Request_Abstract $request Request object
*/
public function __construct(array $defaults = array(),
Zend_Controller_Dispatcher_Interface $dispatcher = null,
Zend_Controller_Request_Abstract $request = null)
{
$this->_defaults = $defaults;
if (isset($request)) {
$this->_request = $request;
}
if (isset($dispatcher)) {
$this->_dispatcher = $dispatcher;
}
}
/**
* Set request keys based on values in request object
*
* @return void
*/
protected function _setRequestKeys()
{
if (null !== $this->_request) {
$this->_moduleKey = $this->_request->getModuleKey();
$this->_controllerKey = $this->_request->getControllerKey();
$this->_actionKey = $this->_request->getActionKey();
}
if (null !== $this->_dispatcher) {
$this->_defaults += array(
$this->_controllerKey => $this->_dispatcher->getDefaultControllerName(),
$this->_actionKey => $this->_dispatcher->getDefaultAction(),
$this->_moduleKey => $this->_dispatcher->getDefaultModule()
);
}
$this->_keysSet = true;
}
/**
* Matches a user submitted path. Assigns and returns an array of variables
* on a successful match.
*
* If a request object is registered, it uses its setModuleName(),
* setControllerName(), and setActionName() accessors to set those values.
* Always returns the values as an array.
*
* @param string $path Path used to match against this routing map
* @return array An array of assigned values or a false on a mismatch
*/
public function match($path)
{
$this->_setRequestKeys();
$values = array();
$params = array();
$path = trim($path, self::URI_DELIMITER);
if ($path != '') {
$path = explode(self::URI_DELIMITER, $path);
if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
$values[$this->_moduleKey] = array_shift($path);
$this->_moduleValid = true;
}
if (count($path) && !empty($path[0])) {
$values[$this->_controllerKey] = array_shift($path);
}
if (count($path) && !empty($path[0])) {
$values[$this->_actionKey] = array_shift($path);
}
if ($numSegs = count($path)) {
for ($i = 0; $i < $numSegs; $i = $i + 2) {
$key = urldecode($path[$i]);
$val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
$params[$key] = (isset($params[$key]) ? (array_merge((array) $params[$key], array($val))): $val);
}
}
}
$this->_values = $values + $params;
return $this->_values + $this->_defaults;
}
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param bool $reset Weither to reset the current params
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = true)
{
if (!$this->_keysSet) {
$this->_setRequestKeys();
}
$params = (!$reset) ? $this->_values : array();
foreach ($data as $key => $value) {
if ($value !== null) {
$params[$key] = $value;
} elseif (isset($params[$key])) {
unset($params[$key]);
}
}
$params += $this->_defaults;
$url = '';
if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) {
if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) {
$module = $params[$this->_moduleKey];
}
}
unset($params[$this->_moduleKey]);
$controller = $params[$this->_controllerKey];
unset($params[$this->_controllerKey]);
$action = $params[$this->_actionKey];
unset($params[$this->_actionKey]);
foreach ($params as $key => $value) {
if (is_array($value)) {
foreach ($value as $arrayValue) {
if ($encode) $arrayValue = urlencode($arrayValue);
$url .= '/' . $key;
$url .= '/' . $arrayValue;
}
} else {
if ($encode) $value = urlencode($value);
$url .= '/' . $key;
$url .= '/' . $value;
}
}
if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) {
if ($encode) $action = urlencode($action);
$url = '/' . $action . $url;
}
if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
if ($encode) $controller = urlencode($controller);
$url = '/' . $controller . $url;
}
if (isset($module)) {
if ($encode) $module = urlencode($module);
$url = '/' . $module . $url;
}
return ltrim($url, self::URI_DELIMITER);
}
/**
* Return a single parameter of route's defaults
*
* @param string $name Array key of the parameter
* @return string Previously set default
*/
public function getDefault($name) {
if (isset($this->_defaults[$name])) {
return $this->_defaults[$name];
}
}
/**
* Return an array of defaults
*
* @return array Route defaults
*/
public function getDefaults() {
return $this->_defaults;
}
}
Controller/Router/Route/Static.php 0000604 00000006667 15071256135 0013225 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Route.php 1847 2006-11-23 11:36:41Z martel $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* StaticRoute is used for managing static URIs.
*
* It's a lot faster compared to the standard Route implementation.
*
* @package Zend_Controller
* @subpackage Router
* @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_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract
{
protected $_route = null;
protected $_defaults = array();
public function getVersion() {
return 1;
}
/**
* Instantiates route based on passed Zend_Config structure
*
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
return new self($config->route, $defs);
}
/**
* Prepares the route for mapping.
*
* @param string $route Map used to match with later submitted URL path
* @param array $defaults Defaults for map variables with keys as variable names
*/
public function __construct($route, $defaults = array())
{
$this->_route = trim($route, '/');
$this->_defaults = (array) $defaults;
}
/**
* Matches a user submitted path with a previously defined route.
* Assigns and returns an array of defaults on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path)
{
if (trim($path, '/') == $this->_route) {
return $this->_defaults;
}
return false;
}
/**
* Assembles a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
return $this->_route;
}
/**
* Return a single parameter of route's defaults
*
* @param string $name Array key of the parameter
* @return string Previously set default
*/
public function getDefault($name) {
if (isset($this->_defaults[$name])) {
return $this->_defaults[$name];
}
return null;
}
/**
* Return an array of defaults
*
* @return array Route defaults
*/
public function getDefaults() {
return $this->_defaults;
}
}
Controller/Router/Abstract.php 0000604 00000010656 15071256135 0012434 0 ustar 00 <?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_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Interface */
require_once 'Zend/Controller/Router/Interface.php';
/**
* Simple first implementation of a router, to be replaced
* with rules-based URI processor.
*
* @category Zend
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
{
/**
* Front controller instance
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* Array of invocation parameters to use when instantiating action
* controllers
* @var array
*/
protected $_invokeParams = array();
/**
* Constructor
*
* @param array $params
* @return void
*/
public function __construct(array $params = array())
{
$this->setParams($params);
}
/**
* Add or modify a parameter to use when instantiating an action controller
*
* @param string $name
* @param mixed $value
* @return Zend_Controller_Router
*/
public function setParam($name, $value)
{
$name = (string) $name;
$this->_invokeParams[$name] = $value;
return $this;
}
/**
* Set parameters to pass to action controller constructors
*
* @param array $params
* @return Zend_Controller_Router
*/
public function setParams(array $params)
{
$this->_invokeParams = array_merge($this->_invokeParams, $params);
return $this;
}
/**
* Retrieve a single parameter from the controller parameter stack
*
* @param string $name
* @return mixed
*/
public function getParam($name)
{
if(isset($this->_invokeParams[$name])) {
return $this->_invokeParams[$name];
}
return null;
}
/**
* Retrieve action controller instantiation parameters
*
* @return array
*/
public function getParams()
{
return $this->_invokeParams;
}
/**
* Clear the controller parameter stack
*
* By default, clears all parameters. If a parameter name is given, clears
* only that parameter; if an array of parameter names is provided, clears
* each.
*
* @param null|string|array single key or array of keys for params to clear
* @return Zend_Controller_Router
*/
public function clearParams($name = null)
{
if (null === $name) {
$this->_invokeParams = array();
} elseif (is_string($name) && isset($this->_invokeParams[$name])) {
unset($this->_invokeParams[$name]);
} elseif (is_array($name)) {
foreach ($name as $key) {
if (is_string($key) && isset($this->_invokeParams[$key])) {
unset($this->_invokeParams[$key]);
}
}
}
return $this;
}
/**
* Retrieve Front Controller
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
// Used cache version if found
if (null !== $this->_frontController) {
return $this->_frontController;
}
require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();
return $this->_frontController;
}
/**
* Set Front Controller
*
* @param Zend_Controller_Front $controller
* @return Zend_Controller_Router_Interface
*/
public function setFrontController(Zend_Controller_Front $controller)
{
$this->_frontController = $controller;
return $this;
}
}
Controller/Router/Rewrite.php 0000604 00000030371 15071256135 0012306 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Rewrite.php 12108 2008-10-24 13:02:56Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Loader */
require_once 'Zend/Loader.php';
/** Zend_Controller_Router_Abstract */
require_once 'Zend/Controller/Router/Abstract.php';
/** Zend_Controller_Router_Route */
require_once 'Zend/Controller/Router/Route.php';
/**
* Ruby routing based Router.
*
* @package Zend_Controller
* @subpackage Router
* @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://manuals.rubyonrails.com/read/chapter/65
*/
class Zend_Controller_Router_Rewrite extends Zend_Controller_Router_Abstract
{
/**
* Whether or not to use default routes
* @var boolean
*/
protected $_useDefaultRoutes = true;
/**
* Array of routes to match against
* @var array
*/
protected $_routes = array();
/**
* Currently matched route
* @var Zend_Controller_Router_Route_Interface
*/
protected $_currentRoute = null;
/**
* Global parameters given to all routes
*
* @var array
*/
protected $_globalParams = array();
/**
* Add default routes which are used to mimic basic router behaviour
*/
public function addDefaultRoutes()
{
if (!$this->hasRoute('default')) {
$dispatcher = $this->getFrontController()->getDispatcher();
$request = $this->getFrontController()->getRequest();
require_once 'Zend/Controller/Router/Route/Module.php';
$compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
$this->_routes = array_merge(array('default' => $compat), $this->_routes);
}
}
/**
* Add route to the route chain
*
* If route implements Zend_Controller_Request_Aware interface it is initialized with a request object
*
* @param string $name Name of the route
* @param Zend_Controller_Router_Route_Interface Route
*/
public function addRoute($name, Zend_Controller_Router_Route_Interface $route)
{
if (method_exists($route, 'setRequest')) {
$route->setRequest($this->getFrontController()->getRequest());
}
$this->_routes[$name] = $route;
return $this;
}
/**
* Add routes to the route chain
*
* @param array $routes Array of routes with names as keys and routes as values
*/
public function addRoutes($routes) {
foreach ($routes as $name => $route) {
$this->addRoute($name, $route);
}
return $this;
}
/**
* Create routes out of Zend_Config configuration
*
* Example INI:
* routes.archive.route = "archive/:year/*"
* routes.archive.defaults.controller = archive
* routes.archive.defaults.action = show
* routes.archive.defaults.year = 2000
* routes.archive.reqs.year = "\d+"
*
* routes.news.type = "Zend_Controller_Router_Route_Static"
* routes.news.route = "news"
* routes.news.defaults.controller = "news"
* routes.news.defaults.action = "list"
*
* And finally after you have created a Zend_Config with above ini:
* $router = new Zend_Controller_Router_Rewrite();
* $router->addConfig($config, 'routes');
*
* @param Zend_Config $config Configuration object
* @param string $section Name of the config section containing route's definitions
* @throws Zend_Controller_Router_Exception
*/
public function addConfig(Zend_Config $config, $section = null)
{
if ($section !== null) {
if ($config->{$section} === null) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("No route configuration in section '{$section}'");
}
$config = $config->{$section};
}
foreach ($config as $name => $info) {
$route = $this->_getRouteFromConfig($info);
if (isset($info->chains) && $info->chains instanceof Zend_Config) {
$this->_addChainRoutesFromConfig($name, $route, $info->chains);
} else {
$this->addRoute($name, $route);
}
}
return $this;
}
/**
* Get a route frm a config instance
*
* @param Zend_Config $info
* @return Zend_Controller_Router_Route_Interface
*/
protected function _getRouteFromConfig(Zend_Config $info)
{
$class = (isset($info->type)) ? $info->type : 'Zend_Controller_Router_Route';
Zend_Loader::loadClass($class);
$route = call_user_func(array($class, 'getInstance'), $info);
return $route;
}
/**
* Add chain routes from a config route
*
* @todo Add recursive chaining (not required yet, but later when path
* route chaining is done)
*
* @param string $name
* @param Zend_Controller_Router_Route_Interface $route
* @param Zend_Config $childRoutesInfo
* @return void
*/
protected function _addChainRoutesFromConfig($name,
Zend_Controller_Router_Route_Interface $route,
Zend_Config $childRoutesInfo)
{
foreach ($childRoutesInfo as $childRouteName => $childRouteInfo) {
$childRoute = $this->_getRouteFromConfig($childRouteInfo);
$chainRoute = $route->chain($childRoute);
$chainName = $name . '-' . $childRouteName;
$this->addRoute($chainName, $chainRoute);
}
}
/**
* Remove a route from the route chain
*
* @param string $name Name of the route
* @throws Zend_Controller_Router_Exception
*/
public function removeRoute($name) {
if (!isset($this->_routes[$name])) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Route $name is not defined");
}
unset($this->_routes[$name]);
return $this;
}
/**
* Remove all standard default routes
*
* @param Zend_Controller_Router_Route_Interface Route
*/
public function removeDefaultRoutes() {
$this->_useDefaultRoutes = false;
return $this;
}
/**
* Check if named route exists
*
* @param string $name Name of the route
* @return boolean
*/
public function hasRoute($name)
{
return isset($this->_routes[$name]);
}
/**
* Retrieve a named route
*
* @param string $name Name of the route
* @throws Zend_Controller_Router_Exception
* @return Zend_Controller_Router_Route_Interface Route object
*/
public function getRoute($name)
{
if (!isset($this->_routes[$name])) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Route $name is not defined");
}
return $this->_routes[$name];
}
/**
* Retrieve a currently matched route
*
* @throws Zend_Controller_Router_Exception
* @return Zend_Controller_Router_Route_Interface Route object
*/
public function getCurrentRoute()
{
if (!isset($this->_currentRoute)) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Current route is not defined");
}
return $this->getRoute($this->_currentRoute);
}
/**
* Retrieve a name of currently matched route
*
* @throws Zend_Controller_Router_Exception
* @return Zend_Controller_Router_Route_Interface Route object
*/
public function getCurrentRouteName()
{
if (!isset($this->_currentRoute)) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Current route is not defined");
}
return $this->_currentRoute;
}
/**
* Retrieve an array of routes added to the route chain
*
* @return array All of the defined routes
*/
public function getRoutes()
{
return $this->_routes;
}
/**
* Find a matching route to the current PATH_INFO and inject
* returning values to the Request object.
*
* @throws Zend_Controller_Router_Exception
* @return Zend_Controller_Request_Abstract Request object
*/
public function route(Zend_Controller_Request_Abstract $request)
{
if (!$request instanceof Zend_Controller_Request_Http) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object');
}
if ($this->_useDefaultRoutes) {
$this->addDefaultRoutes();
}
/** Find the matching route */
foreach (array_reverse($this->_routes) as $name => $route) {
// TODO: Should be an interface method. Hack for 1.0 BC
if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
$match = $request->getPathInfo();
} else {
$match = $request;
}
if ($params = $route->match($match)) {
$this->_setRequestParams($request, $params);
$this->_currentRoute = $name;
break;
}
}
return $request;
}
protected function _setRequestParams($request, $params)
{
foreach ($params as $param => $value) {
$request->setParam($param, $value);
if ($param === $request->getModuleKey()) {
$request->setModuleName($value);
}
if ($param === $request->getControllerKey()) {
$request->setControllerName($value);
}
if ($param === $request->getActionKey()) {
$request->setActionName($value);
}
}
}
/**
* Generates a URL path that can be used in URL creation, redirection, etc.
*
* @param array $userParams Options passed by a user used to override parameters
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @throws Zend_Controller_Router_Exception
* @return string Resulting absolute URL path
*/
public function assemble($userParams, $name = null, $reset = false, $encode = true)
{
if ($name == null) {
try {
$name = $this->getCurrentRouteName();
} catch (Zend_Controller_Router_Exception $e) {
$name = 'default';
}
}
$params = array_merge($this->_globalParams, $userParams);
$route = $this->getRoute($name);
$url = $route->assemble($params, $reset, $encode);
if (!preg_match('|^[a-z]+://|', $url)) {
$url = rtrim($this->getFrontController()->getBaseUrl(), '/') . '/' . $url;
}
return $url;
}
/**
* Set a global parameter
*
* @param string $name
* @param mixed $value
* @return Zend_Controller_Router_Rewrite
*/
public function setGlobalParam($name, $value)
{
$this->_globalParams[$name] = $value;
return $this;
}
} Controller/Router/Route.php 0000604 00000024220 15071256135 0011757 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Route.php 11073 2008-08-26 16:29:59Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Abstract */
require_once 'Zend/Controller/Router/Route/Abstract.php';
/**
* Route
*
* @package Zend_Controller
* @subpackage Router
* @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://manuals.rubyonrails.com/read/chapter/65
*/
class Zend_Controller_Router_Route extends Zend_Controller_Router_Route_Abstract
{
protected $_urlVariable = ':';
protected $_urlDelimiter = '/';
protected $_regexDelimiter = '#';
protected $_defaultRegex = null;
/**
* Holds names of all route's pattern variable names. Array index holds a position in URL.
* @var array
*/
protected $_variables = array();
/**
* Holds Route patterns for all URL parts. In case of a variable it stores it's regex
* requirement or null. In case of a static part, it holds only it's direct value.
* In case of a wildcard, it stores an asterisk (*)
* @var array
*/
protected $_parts = array();
/**
* Holds user submitted default values for route's variables. Name and value pairs.
* @var array
*/
protected $_defaults = array();
/**
* Holds user submitted regular expression patterns for route's variables' values.
* Name and value pairs.
* @var array
*/
protected $_requirements = array();
/**
* Associative array filled on match() that holds matched path values
* for given variable names.
* @var array
*/
protected $_values = array();
/**
* Associative array filled on match() that holds wildcard variable
* names and values.
* @var array
*/
protected $_wildcardData = array();
/**
* Helper var that holds a count of route pattern's static parts
* for validation
* @var int
*/
protected $_staticCount = 0;
public function getVersion() {
return 1;
}
/**
* Instantiates route based on passed Zend_Config structure
*
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{
$reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array();
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
return new self($config->route, $defs, $reqs);
}
/**
* Prepares the route for mapping by splitting (exploding) it
* to a corresponding atomic parts. These parts are assigned
* a position which is later used for matching and preparing values.
*
* @param string $route Map used to match with later submitted URL path
* @param array $defaults Defaults for map variables with keys as variable names
* @param array $reqs Regular expression requirements for variables (keys as variable names)
*/
public function __construct($route, $defaults = array(), $reqs = array())
{
$route = trim($route, $this->_urlDelimiter);
$this->_defaults = (array) $defaults;
$this->_requirements = (array) $reqs;
if ($route != '') {
foreach (explode($this->_urlDelimiter, $route) as $pos => $part) {
if (substr($part, 0, 1) == $this->_urlVariable) {
$name = substr($part, 1);
$this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex);
$this->_variables[$pos] = $name;
} else {
$this->_parts[$pos] = $part;
if ($part != '*') $this->_staticCount++;
}
}
}
}
/**
* Matches a user submitted path with parts defined by a map. Assigns and
* returns an array of variables on a successful match.
*
* @param string $path Path used to match against this routing map
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($path)
{
$pathStaticCount = 0;
$values = array();
$path = trim($path, $this->_urlDelimiter);
if ($path != '') {
$path = explode($this->_urlDelimiter, $path);
foreach ($path as $pos => $pathPart) {
// Path is longer than a route, it's not a match
if (!array_key_exists($pos, $this->_parts)) {
return false;
}
// If it's a wildcard, get the rest of URL as wildcard data and stop matching
if ($this->_parts[$pos] == '*') {
$count = count($path);
for($i = $pos; $i < $count; $i+=2) {
$var = urldecode($path[$i]);
if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) {
$this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null;
}
}
break;
}
$name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
$pathPart = urldecode($pathPart);
// If it's a static part, match directly
if ($name === null && $this->_parts[$pos] != $pathPart) {
return false;
}
// If it's a variable with requirement, match a regex. If not - everything matches
if ($this->_parts[$pos] !== null && !preg_match($this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', $pathPart)) {
return false;
}
// If it's a variable store it's value for later
if ($name !== null) {
$values[$name] = $pathPart;
} else {
$pathStaticCount++;
}
}
}
// Check if all static mappings have been matched
if ($this->_staticCount != $pathStaticCount) {
return false;
}
$return = $values + $this->_wildcardData + $this->_defaults;
// Check if all map variables have been initialized
foreach ($this->_variables as $var) {
if (!array_key_exists($var, $return)) {
return false;
}
}
$this->_values = $values;
return $return;
}
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
$url = array();
$flag = false;
foreach ($this->_parts as $key => $part) {
$name = isset($this->_variables[$key]) ? $this->_variables[$key] : null;
$useDefault = false;
if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) {
$useDefault = true;
}
if (isset($name)) {
if (isset($data[$name]) && !$useDefault) {
$url[$key] = $data[$name];
unset($data[$name]);
} elseif (!$reset && !$useDefault && isset($this->_values[$name])) {
$url[$key] = $this->_values[$name];
} elseif (!$reset && !$useDefault && isset($this->_wildcardData[$name])) {
$url[$key] = $this->_wildcardData[$name];
} elseif (isset($this->_defaults[$name])) {
$url[$key] = $this->_defaults[$name];
} else {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception($name . ' is not specified');
}
} elseif ($part != '*') {
$url[$key] = $part;
} else {
if (!$reset) $data += $this->_wildcardData;
foreach ($data as $var => $value) {
if ($value !== null) {
$url[$key++] = $var;
$url[$key++] = $value;
$flag = true;
}
}
}
}
$return = '';
foreach (array_reverse($url, true) as $key => $value) {
if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key])) {
if ($encode) $value = urlencode($value);
$return = $this->_urlDelimiter . $value . $return;
$flag = true;
}
}
return trim($return, $this->_urlDelimiter);
}
/**
* Return a single parameter of route's defaults
*
* @param string $name Array key of the parameter
* @return string Previously set default
*/
public function getDefault($name) {
if (isset($this->_defaults[$name])) {
return $this->_defaults[$name];
}
return null;
}
/**
* Return an array of defaults
*
* @return array Route defaults
*/
public function getDefaults() {
return $this->_defaults;
}
}
Controller/Router/Interface.php 0000604 00000007742 15071256135 0012573 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Controller_Router_Interface
{
/**
* Processes a request and sets its controller and action. If
* no route was possible, an exception is thrown.
*
* @param Zend_Controller_Request_Abstract
* @throws Zend_Controller_Router_Exception
* @return Zend_Controller_Request_Abstract|boolean
*/
public function route(Zend_Controller_Request_Abstract $dispatcher);
/**
* Generates a URL path that can be used in URL creation, redirection, etc.
*
* May be passed user params to override ones from URI, Request or even defaults.
* If passed parameter has a value of null, it's URL variable will be reset to
* default.
*
* If null is passed as a route name assemble will use the current Route or 'default'
* if current is not yet set.
*
* Reset is used to signal that all parameters should be reset to it's defaults.
* Ignoring all URL specified values. User specified params still get precedence.
*
* Encode tells to url encode resulting path parts.
*
* @param array $userParams Options passed by a user used to override parameters
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @throws Zend_Controller_Router_Exception
* @return string Resulting URL path
*/
public function assemble($userParams, $name = null, $reset = false, $encode = true);
/**
* Retrieve Front Controller
*
* @return Zend_Controller_Front
*/
public function getFrontController();
/**
* Set Front Controller
*
* @param Zend_Controller_Front $controller
* @return Zend_Controller_Router_Interface
*/
public function setFrontController(Zend_Controller_Front $controller);
/**
* Add or modify a parameter with which to instantiate any helper objects
*
* @param string $name
* @param mixed $param
* @return Zend_Controller_Router_Interface
*/
public function setParam($name, $value);
/**
* Set an array of a parameters to pass to helper object constructors
*
* @param array $params
* @return Zend_Controller_Router_Interface
*/
public function setParams(array $params);
/**
* Retrieve a single parameter from the controller parameter stack
*
* @param string $name
* @return mixed
*/
public function getParam($name);
/**
* Retrieve the parameters to pass to helper object constructors
*
* @return array
*/
public function getParams();
/**
* Clear the controller parameter stack
*
* By default, clears all parameters. If a parameter name is given, clears
* only that parameter; if an array of parameter names is provided, clears
* each.
*
* @param null|string|array single key or array of keys for params to clear
* @return Zend_Controller_Router_Interface
*/
public function clearParams($name = null);
}
Controller/Router/Exception.php 0000604 00000002164 15071256135 0012622 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';
/**
* @package Zend_Controller
* @subpackage Router
* @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_Controller_Router_Exception extends Zend_Controller_Exception
{}
Controller/Exception.php 0000604 00000002003 15071256135 0011332 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Controller
* @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_Controller_Exception extends Zend_Exception
{}
Controller/Dispatcher/Interface.php 0000604 00000013573 15071256135 0013400 0 ustar 00 <?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.
*
* @package Zend_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Controller_Request_Abstract
*/
require_once 'Zend/Controller/Request/Abstract.php';
/**
* Zend_Controller_Response_Abstract
*/
require_once 'Zend/Controller/Response/Abstract.php';
/**
* @package Zend_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Controller_Dispatcher_Interface
{
/**
* Formats a string into a controller name. This is used to take a raw
* controller name, such as one that would be packaged inside a request
* object, and reformat it to a proper class name that a class extending
* Zend_Controller_Action would use.
*
* @param string $unformatted
* @return string
*/
public function formatControllerName($unformatted);
/**
* Formats a string into a module name. This is used to take a raw
* module name, such as one that would be packaged inside a request
* object, and reformat it to a proper directory/class name that a class extending
* Zend_Controller_Action would use.
*
* @param string $unformatted
* @return string
*/
public function formatModuleName($unformatted);
/**
* Formats a string into an action name. This is used to take a raw
* action name, such as one that would be packaged inside a request
* object, and reformat into a proper method name that would be found
* inside a class extending Zend_Controller_Action.
*
* @param string $unformatted
* @return string
*/
public function formatActionName($unformatted);
/**
* Returns TRUE if an action can be dispatched, or FALSE otherwise.
*
* @param Zend_Controller_Request_Abstract $request
* @return boolean
*/
public function isDispatchable(Zend_Controller_Request_Abstract $request);
/**
* Add or modify a parameter with which to instantiate an Action Controller
*
* @param string $name
* @param mixed $value
* @return Zend_Controller_Dispatcher_Interface
*/
public function setParam($name, $value);
/**
* Set an array of a parameters to pass to the Action Controller constructor
*
* @param array $params
* @return Zend_Controller_Dispatcher_Interface
*/
public function setParams(array $params);
/**
* Retrieve a single parameter from the controller parameter stack
*
* @param string $name
* @return mixed
*/
public function getParam($name);
/**
* Retrieve the parameters to pass to the Action Controller constructor
*
* @return array
*/
public function getParams();
/**
* Clear the controller parameter stack
*
* By default, clears all parameters. If a parameter name is given, clears
* only that parameter; if an array of parameter names is provided, clears
* each.
*
* @param null|string|array single key or array of keys for params to clear
* @return Zend_Controller_Dispatcher_Interface
*/
public function clearParams($name = null);
/**
* Set the response object to use, if any
*
* @param Zend_Controller_Response_Abstract|null $response
* @return void
*/
public function setResponse(Zend_Controller_Response_Abstract $response = null);
/**
* Retrieve the response object, if any
*
* @return Zend_Controller_Response_Abstract|null
*/
public function getResponse();
/**
* Add a controller directory to the controller directory stack
*
* @param string $path
* @param string $args
* @return Zend_Controller_Dispatcher_Interface
*/
public function addControllerDirectory($path, $args = null);
/**
* Set the directory where controller files are stored
*
* Specify a string or an array; if an array is specified, all paths will be
* added.
*
* @param string|array $dir
* @return Zend_Controller_Dispatcher_Interface
*/
public function setControllerDirectory($path);
/**
* Return the currently set directory(ies) for controller file lookup
*
* @return array
*/
public function getControllerDirectory();
/**
* Dispatches a request object to a controller/action. If the action
* requests a forward to another action, a new request will be returned.
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @return void
*/
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response);
/**
* Whether or not a given module is valid
*
* @param string $module
* @return boolean
*/
public function isValidModule($module);
/**
* Retrieve the default module name
*
* @return string
*/
public function getDefaultModule();
/**
* Retrieve the default controller name
*
* @return string
*/
public function getDefaultControllerName();
/**
* Retrieve the default action
*
* @return string
*/
public function getDefaultAction();
}
Controller/Dispatcher/Exception.php 0000604 00000002143 15071256136 0013426 0 ustar 00 <?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_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Dispatcher
* @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_Controller_Dispatcher_Exception extends Zend_Controller_Exception
{}
Controller/Dispatcher/Standard.php 0000604 00000036446 15071256136 0013245 0 ustar 00 <?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_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Loader */
require_once 'Zend/Loader.php';
/** Zend_Controller_Dispatcher_Abstract */
require_once 'Zend/Controller/Dispatcher/Abstract.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Dispatcher
* @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_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abstract
{
/**
* Current dispatchable directory
* @var string
*/
protected $_curDirectory;
/**
* Current module (formatted)
* @var string
*/
protected $_curModule;
/**
* Controller directory(ies)
* @var array
*/
protected $_controllerDirectory = array();
/**
* Constructor: Set current module to default value
*
* @param array $params
* @return void
*/
public function __construct(array $params = array())
{
parent::__construct($params);
$this->_curModule = $this->getDefaultModule();
}
/**
* Add a single path to the controller directory stack
*
* @param string $path
* @param string $module
* @return Zend_Controller_Dispatcher_Standard
*/
public function addControllerDirectory($path, $module = null)
{
if (null === $module) {
$module = $this->_defaultModule;
}
$module = (string) $module;
$path = rtrim((string) $path, '/\\');
$this->_controllerDirectory[$module] = $path;
return $this;
}
/**
* Set controller directory
*
* @param array|string $directory
* @return Zend_Controller_Dispatcher_Standard
*/
public function setControllerDirectory($directory, $module = null)
{
$this->_controllerDirectory = array();
if (is_string($directory)) {
$this->addControllerDirectory($directory, $module);
} elseif (is_array($directory)) {
foreach ((array) $directory as $module => $path) {
$this->addControllerDirectory($path, $module);
}
} else {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Controller directory spec must be either a string or an array');
}
return $this;
}
/**
* Return the currently set directories for Zend_Controller_Action class
* lookup
*
* If a module is specified, returns just that directory.
*
* @param string $module Module name
* @return array|string Returns array of all directories by default, single
* module directory if module argument provided
*/
public function getControllerDirectory($module = null)
{
if (null === $module) {
return $this->_controllerDirectory;
}
$module = (string) $module;
if (array_key_exists($module, $this->_controllerDirectory)) {
return $this->_controllerDirectory[$module];
}
return null;
}
/**
* Remove a controller directory by module name
*
* @param string $module
* @return bool
*/
public function removeControllerDirectory($module)
{
$module = (string) $module;
if (array_key_exists($module, $this->_controllerDirectory)) {
unset($this->_controllerDirectory[$module]);
return true;
}
return false;
}
/**
* Format the module name.
*
* @param string $unformatted
* @return string
*/
public function formatModuleName($unformatted)
{
if (($this->_defaultModule == $unformatted) && !$this->getParam('prefixDefaultModule')) {
return $unformatted;
}
return ucfirst($this->_formatName($unformatted));
}
/**
* Format action class name
*
* @param string $moduleName Name of the current module
* @param string $className Name of the action class
* @return string Formatted class name
*/
public function formatClassName($moduleName, $className)
{
return $this->formatModuleName($moduleName) . '_' . $className;
}
/**
* Convert a class name to a filename
*
* @param string $class
* @return string
*/
public function classToFilename($class)
{
return str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
}
/**
* Returns TRUE if the Zend_Controller_Request_Abstract object can be
* dispatched to a controller.
*
* Use this method wisely. By default, the dispatcher will fall back to the
* default controller (either in the module specified or the global default)
* if a given controller does not exist. This method returning false does
* not necessarily indicate the dispatcher will not still dispatch the call.
*
* @param Zend_Controller_Request_Abstract $action
* @return boolean
*/
public function isDispatchable(Zend_Controller_Request_Abstract $request)
{
$className = $this->getControllerClass($request);
if (!$className) {
return false;
}
if (class_exists($className, false)) {
return true;
}
$fileSpec = $this->classToFilename($className);
$dispatchDir = $this->getDispatchDirectory();
$test = $dispatchDir . DIRECTORY_SEPARATOR . $fileSpec;
return Zend_Loader::isReadable($test);
}
/**
* Dispatch to a controller/action
*
* By default, if a controller is not dispatchable, dispatch() will throw
* an exception. If you wish to use the default controller instead, set the
* param 'useDefaultControllerAlways' via {@link setParam()}.
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @return void
* @throws Zend_Controller_Dispatcher_Exception
*/
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
{
$this->setResponse($response);
/**
* Get controller class
*/
if (!$this->isDispatchable($request)) {
$controller = $request->getControllerName();
if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
}
$className = $this->getDefaultControllerClass($request);
} else {
$className = $this->getControllerClass($request);
if (!$className) {
$className = $this->getDefaultControllerClass($request);
}
}
/**
* Load the controller class file
*/
$className = $this->loadClass($className);
/**
* Instantiate controller with request, response, and invocation
* arguments; throw exception if it's not an action controller
*/
$controller = new $className($request, $this->getResponse(), $this->getParams());
if (!$controller instanceof Zend_Controller_Action) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception("Controller '$className' is not an instance of Zend_Controller_Action");
}
/**
* Retrieve the action name
*/
$action = $this->getActionMethod($request);
/**
* Dispatch the method call
*/
$request->setDispatched(true);
// by default, buffer output
$disableOb = $this->getParam('disableOutputBuffering');
$obLevel = ob_get_level();
if (empty($disableOb)) {
ob_start();
}
try {
$controller->dispatch($action);
} catch (Exception $e) {
// Clean output buffer on error
$curObLevel = ob_get_level();
if ($curObLevel > $obLevel) {
do {
ob_get_clean();
$curObLevel = ob_get_level();
} while ($curObLevel > $obLevel);
}
throw $e;
}
if (empty($disableOb)) {
$content = ob_get_clean();
$response->appendBody($content);
}
// Destroy the page controller instance and reflection objects
$controller = null;
}
/**
* Load a controller class
*
* Attempts to load the controller class file from
* {@link getControllerDirectory()}. If the controller belongs to a
* module, looks for the module prefix to the controller class.
*
* @param string $className
* @return string Class name loaded
* @throws Zend_Controller_Dispatcher_Exception if class not loaded
*/
public function loadClass($className)
{
$finalClass = $className;
if (($this->_defaultModule != $this->_curModule)
|| $this->getParam('prefixDefaultModule'))
{
$finalClass = $this->formatClassName($this->_curModule, $className);
}
if (class_exists($finalClass, false)) {
return $finalClass;
}
$dispatchDir = $this->getDispatchDirectory();
$loadFile = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);
if (!include_once $loadFile) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $loadFile . "'");
}
if (!class_exists($finalClass, false)) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid controller class ("' . $finalClass . '")');
}
return $finalClass;
}
/**
* Get controller class name
*
* Try request first; if not found, try pulling from request parameter;
* if still not found, fallback to default
*
* @param Zend_Controller_Request_Abstract $request
* @return string|false Returns class name on success
*/
public function getControllerClass(Zend_Controller_Request_Abstract $request)
{
$controllerName = $request->getControllerName();
if (empty($controllerName)) {
if (!$this->getParam('useDefaultControllerAlways')) {
return false;
}
$controllerName = $this->getDefaultControllerName();
$request->setControllerName($controllerName);
}
$className = $this->formatControllerName($controllerName);
$controllerDirs = $this->getControllerDirectory();
$module = $request->getModuleName();
if ($this->isValidModule($module)) {
$this->_curModule = $module;
$this->_curDirectory = $controllerDirs[$module];
} elseif ($this->isValidModule($this->_defaultModule)) {
$request->setModuleName($this->_defaultModule);
$this->_curModule = $this->_defaultModule;
$this->_curDirectory = $controllerDirs[$this->_defaultModule];
} else {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('No default module defined for this application');
}
return $className;
}
/**
* Determine if a given module is valid
*
* @param string $module
* @return bool
*/
public function isValidModule($module)
{
if (!is_string($module)) {
return false;
}
$module = strtolower($module);
$controllerDir = $this->getControllerDirectory();
foreach (array_keys($controllerDir) as $moduleName) {
if ($module == strtolower($moduleName)) {
return true;
}
}
return false;
}
/**
* Retrieve default controller class
*
* Determines whether the default controller to use lies within the
* requested module, or if the global default should be used.
*
* By default, will only use the module default unless that controller does
* not exist; if this is the case, it falls back to the default controller
* in the default module.
*
* @param Zend_Controller_Request_Abstract $request
* @return string
*/
public function getDefaultControllerClass(Zend_Controller_Request_Abstract $request)
{
$controller = $this->getDefaultControllerName();
$default = $this->formatControllerName($controller);
$request->setControllerName($controller)
->setActionName(null);
$module = $request->getModuleName();
$controllerDirs = $this->getControllerDirectory();
$this->_curModule = $this->_defaultModule;
$this->_curDirectory = $controllerDirs[$this->_defaultModule];
if ($this->isValidModule($module)) {
$found = false;
if (class_exists($default, false)) {
$found = true;
} else {
$moduleDir = $controllerDirs[$module];
$fileSpec = $moduleDir . DIRECTORY_SEPARATOR . $this->classToFilename($default);
if (Zend_Loader::isReadable($fileSpec)) {
$found = true;
$this->_curDirectory = $moduleDir;
}
}
if ($found) {
$request->setModuleName($module);
$this->_curModule = $this->formatModuleName($module);
}
} else {
$request->setModuleName($this->_defaultModule);
}
return $default;
}
/**
* Return the value of the currently selected dispatch directory (as set by
* {@link getController()})
*
* @return string
*/
public function getDispatchDirectory()
{
return $this->_curDirectory;
}
/**
* Determine the action name
*
* First attempt to retrieve from request; then from request params
* using action key; default to default action
*
* Returns formatted action name
*
* @param Zend_Controller_Request_Abstract $request
* @return string
*/
public function getActionMethod(Zend_Controller_Request_Abstract $request)
{
$action = $request->getActionName();
if (empty($action)) {
$action = $this->getDefaultAction();
$request->setActionName($action);
}
return $this->formatActionName($action);
}
}
Controller/Dispatcher/Abstract.php 0000604 00000027107 15071256136 0013242 0 ustar 00 <?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_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Dispatcher_Interface */
require_once 'Zend/Controller/Dispatcher/Interface.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Dispatcher
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Dispatcher_Abstract implements Zend_Controller_Dispatcher_Interface
{
/**
* Default action
* @var string
*/
protected $_defaultAction = 'index';
/**
* Default controller
* @var string
*/
protected $_defaultController = 'index';
/**
* Default module
* @var string
*/
protected $_defaultModule = 'default';
/**
* Front Controller instance
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* Array of invocation parameters to use when instantiating action
* controllers
* @var array
*/
protected $_invokeParams = array();
/**
* Path delimiter character
* @var string
*/
protected $_pathDelimiter = '_';
/**
* Response object to pass to action controllers, if any
* @var Zend_Controller_Response_Abstract|null
*/
protected $_response = null;
/**
* Word delimiter characters
* @var array
*/
protected $_wordDelimiter = array('-', '.');
/**
* Constructor
*
* @return void
*/
public function __construct(array $params = array())
{
$this->setParams($params);
}
/**
* Formats a string into a controller name. This is used to take a raw
* controller name, such as one stored inside a Zend_Controller_Request_Abstract
* object, and reformat it to a proper class name that a class extending
* Zend_Controller_Action would use.
*
* @param string $unformatted
* @return string
*/
public function formatControllerName($unformatted)
{
return ucfirst($this->_formatName($unformatted)) . 'Controller';
}
/**
* Formats a string into an action name. This is used to take a raw
* action name, such as one that would be stored inside a Zend_Controller_Request_Abstract
* object, and reformat into a proper method name that would be found
* inside a class extending Zend_Controller_Action.
*
* @param string $unformatted
* @return string
*/
public function formatActionName($unformatted)
{
$formatted = $this->_formatName($unformatted, true);
return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action';
}
/**
* Verify delimiter
*
* Verify a delimiter to use in controllers or actions. May be a single
* string or an array of strings.
*
* @param string|array $spec
* @return array
* @throws Zend_Controller_Dispatcher_Exception with invalid delimiters
*/
public function _verifyDelimiter($spec)
{
if (is_string($spec)) {
return (array) $spec;
} elseif (is_array($spec)) {
$allStrings = true;
foreach ($spec as $delim) {
if (!is_string($delim)) {
$allStrings = false;
break;
}
}
if (!$allStrings) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Word delimiter array must contain only strings');
}
return $spec;
}
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid word delimiter');
}
/**
* Retrieve the word delimiter character(s) used in
* controller or action names
*
* @return array
*/
public function getWordDelimiter()
{
return $this->_wordDelimiter;
}
/**
* Set word delimiter
*
* Set the word delimiter to use in controllers and actions. May be a
* single string or an array of strings.
*
* @param string|array $spec
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setWordDelimiter($spec)
{
$spec = $this->_verifyDelimiter($spec);
$this->_wordDelimiter = $spec;
return $this;
}
/**
* Retrieve the path delimiter character(s) used in
* controller names
*
* @return array
*/
public function getPathDelimiter()
{
return $this->_pathDelimiter;
}
/**
* Set path delimiter
*
* Set the path delimiter to use in controllers. May be a single string or
* an array of strings.
*
* @param string $spec
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setPathDelimiter($spec)
{
if (!is_string($spec)) {
require_once 'Zend/Controller/Dispatcher/Exception.php';
throw new Zend_Controller_Dispatcher_Exception('Invalid path delimiter');
}
$this->_pathDelimiter = $spec;
return $this;
}
/**
* Formats a string from a URI into a PHP-friendly name.
*
* By default, replaces words separated by the word separator character(s)
* with camelCaps. If $isAction is false, it also preserves replaces words
* separated by the path separation character with an underscore, making
* the following word Title cased. All non-alphanumeric characters are
* removed.
*
* @param string $unformatted
* @param boolean $isAction Defaults to false
* @return string
*/
protected function _formatName($unformatted, $isAction = false)
{
// preserve directories
if (!$isAction) {
$segments = explode($this->getPathDelimiter(), $unformatted);
} else {
$segments = (array) $unformatted;
}
foreach ($segments as $key => $segment) {
$segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment));
$segment = preg_replace('/[^a-z0-9 ]/', '', $segment);
$segments[$key] = str_replace(' ', '', ucwords($segment));
}
return implode('_', $segments);
}
/**
* Retrieve front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_frontController) {
require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
/**
* Set front controller instance
*
* @param Zend_Controller_Front $controller
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setFrontController(Zend_Controller_Front $controller)
{
$this->_frontController = $controller;
return $this;
}
/**
* Add or modify a parameter to use when instantiating an action controller
*
* @param string $name
* @param mixed $value
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setParam($name, $value)
{
$name = (string) $name;
$this->_invokeParams[$name] = $value;
return $this;
}
/**
* Set parameters to pass to action controller constructors
*
* @param array $params
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setParams(array $params)
{
$this->_invokeParams = array_merge($this->_invokeParams, $params);
return $this;
}
/**
* Retrieve a single parameter from the controller parameter stack
*
* @param string $name
* @return mixed
*/
public function getParam($name)
{
if(isset($this->_invokeParams[$name])) {
return $this->_invokeParams[$name];
}
return null;
}
/**
* Retrieve action controller instantiation parameters
*
* @return array
*/
public function getParams()
{
return $this->_invokeParams;
}
/**
* Clear the controller parameter stack
*
* By default, clears all parameters. If a parameter name is given, clears
* only that parameter; if an array of parameter names is provided, clears
* each.
*
* @param null|string|array single key or array of keys for params to clear
* @return Zend_Controller_Dispatcher_Abstract
*/
public function clearParams($name = null)
{
if (null === $name) {
$this->_invokeParams = array();
} elseif (is_string($name) && isset($this->_invokeParams[$name])) {
unset($this->_invokeParams[$name]);
} elseif (is_array($name)) {
foreach ($name as $key) {
if (is_string($key) && isset($this->_invokeParams[$key])) {
unset($this->_invokeParams[$key]);
}
}
}
return $this;
}
/**
* Set response object to pass to action controllers
*
* @param Zend_Controller_Response_Abstract|null $response
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setResponse(Zend_Controller_Response_Abstract $response = null)
{
$this->_response = $response;
return $this;
}
/**
* Return the registered response object
*
* @return Zend_Controller_Response_Abstract|null
*/
public function getResponse()
{
return $this->_response;
}
/**
* Set the default controller (minus any formatting)
*
* @param string $controller
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setDefaultControllerName($controller)
{
$this->_defaultController = (string) $controller;
return $this;
}
/**
* Retrieve the default controller name (minus formatting)
*
* @return string
*/
public function getDefaultControllerName()
{
return $this->_defaultController;
}
/**
* Set the default action (minus any formatting)
*
* @param string $action
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setDefaultAction($action)
{
$this->_defaultAction = (string) $action;
return $this;
}
/**
* Retrieve the default action name (minus formatting)
*
* @return string
*/
public function getDefaultAction()
{
return $this->_defaultAction;
}
/**
* Set the default module
*
* @param string $module
* @return Zend_Controller_Dispatcher_Abstract
*/
public function setDefaultModule($module)
{
$this->_defaultModule = (string) $module;
return $this;
}
/**
* Retrieve the default module
*
* @return string
*/
public function getDefaultModule()
{
return $this->_defaultModule;
}
}
Controller/Request/HttpTestCase.php 0000604 00000013321 15071256136 0013405 0 ustar 00 <?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_Controller
* @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 Zend_Controller_Request_Http
*/
require_once 'Zend/Controller/Request/Http.php';
/**
* Zend_Controller_Request_HttpTestCase
*
* HTTP request object for use with Zend_Controller family.
*
* @uses Zend_Controller_Request_Http
* @package Zend_Controller
* @subpackage Request
*/
class Zend_Controller_Request_HttpTestCase extends Zend_Controller_Request_Http
{
/**
* Request headers
* @var array
*/
protected $_headers = array();
/**
* Request method
* @var string
*/
protected $_method;
/**
* Raw POST body
* @var string|null
*/
protected $_rawBody;
/**
* Valid request method types
* @var array
*/
protected $_validMethodTypes = array(
'DELETE',
'GET',
'HEAD',
'OPTIONS',
'POST',
'PUT',
);
/**
* Clear GET values
*
* @return Zend_Controller_Request_HttpTestCase
*/
public function clearQuery()
{
$_GET = array();
return $this;
}
/**
* Clear POST values
*
* @return Zend_Controller_Request_HttpTestCase
*/
public function clearPost()
{
$_POST = array();
return $this;
}
/**
* Set raw POST body
*
* @param string $content
* @return Zend_Controller_Request_HttpTestCase
*/
public function setRawBody($content)
{
$this->_rawBody = (string) $content;
return $this;
}
/**
* Get RAW POST body
*
* @return string|null
*/
public function getRawBody()
{
return $this->_rawBody;
}
/**
* Clear raw POST body
*
* @return Zend_Controller_Request_HttpTestCase
*/
public function clearRawBody()
{
$this->_rawBody = null;
return $this;
}
/**
* Set a cookie
*
* @param string $key
* @param mixed $value
* @return Zend_Controller_Request_HttpTestCase
*/
public function setCookie($key, $value)
{
$_COOKIE[(string) $key] = $value;
return $this;
}
/**
* Set multiple cookies at once
*
* @param array $cookies
* @return void
*/
public function setCookies(array $cookies)
{
foreach ($cookies as $key => $value) {
$_COOKIE[$key] = $value;
}
return $this;
}
/**
* Clear all cookies
*
* @return Zend_Controller_Request_HttpTestCase
*/
public function clearCookies()
{
$_COOKIE = array();
return $this;
}
/**
* Set request method
*
* @param string $type
* @return Zend_Controller_Request_HttpTestCase
*/
public function setMethod($type)
{
$type = strtoupper(trim((string) $type));
if (!in_array($type, $this->_validMethodTypes)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid request method specified');
}
$this->_method = $type;
return $this;
}
/**
* Get request method
*
* @return string|null
*/
public function getMethod()
{
return $this->_method;
}
/**
* Set a request header
*
* @param string $key
* @param string $value
* @return Zend_Controller_Request_HttpTestCase
*/
public function setHeader($key, $value)
{
$key = $this->_normalizeHeaderName($key);
$this->_headers[$key] = (string) $value;
return $this;
}
/**
* Set request headers
*
* @param array $headers
* @return Zend_Controller_Request_HttpTestCase
*/
public function setHeaders(array $headers)
{
foreach ($headers as $key => $value) {
$this->setHeader($key, $value);
}
return $this;
}
/**
* Get request header
*
* @param string $header
* @param mixed $default
* @return string|null
*/
public function getHeader($header, $default = null)
{
$header = $this->_normalizeHeaderName($header);
if (array_key_exists($header, $this->_headers)) {
return $this->_headers[$header];
}
return $default;
}
/**
* Get all request headers
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Clear request headers
*
* @return Zend_Controller_Request_HttpTestCase
*/
public function clearHeaders()
{
$this->_headers = array();
return $this;
}
/**
* Get REQUEST_URI
*
* @return null|string
*/
public function getRequestUri()
{
return $this->_requestUri;
}
/**
* Normalize a header name for setting and retrieval
*
* @param string $name
* @return string
*/
protected function _normalizeHeaderName($name)
{
$name = strtoupper((string) $name);
$name = str_replace('-', '_', $name);
return $name;
}
}
Controller/Request/Apache404.php 0000604 00000005643 15071256136 0012453 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Request_Exception */
require_once 'Zend/Controller/Request/Exception.php';
/** Zend_Controller_Request_Http */
require_once 'Zend/Controller/Request/Http.php';
/** Zend_Uri */
require_once 'Zend/Uri.php';
/**
* Zend_Controller_Request_Apache404
*
* HTTP request object for use with Zend_Controller family. Extends basic HTTP
* request object to allow for two edge cases when using Apache:
* - Using Apache's 404 handler instead of mod_rewrite to direct requests
* - Using the PT flag in rewrite rules
*
* In each case, the URL to check against is found in REDIRECT_URL, not
* REQUEST_URI.
*
* @uses Zend_Controller_Request_Http
* @package Zend_Controller
* @subpackage Request
*/
class Zend_Controller_Request_Apache404 extends Zend_Controller_Request_Http
{
public function setRequestUri($requestUri = null)
{
$parseUriGetVars = false;
if ($requestUri === null) {
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REDIRECT_URL'])) { // Check if using mod_rewrite
$requestUri = $_SERVER['REDIRECT_URL'];
if (isset($_SERVER['REDIRECT_QUERYSTRING'])) {
$parseUriGetVars = $_SERVER['REDIRECT_QUERYSTRING'];
}
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this;
}
} elseif (!is_string($requestUri)) {
return $this;
} else {
if (false !== ($pos = strpos($requestUri, '?'))) {
$parseUriGetVars = substr($requestUri, $pos + 1);
}
}
if ($parseUriGetVars) {
// Set GET items, if available
parse_str($parseUriGetVars, $_GET);
}
$this->_requestUri = $requestUri;
return $this;
}
}
Controller/Request/Exception.php 0000604 00000002132 15071256136 0012766 0 ustar 00 <?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_Controller
* @subpackage Request
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Request
* @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_Controller_Request_Exception extends Zend_Controller_Exception
{}
Controller/Request/Simple.php 0000604 00000003100 15071256136 0012255 0 ustar 00 <?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_Controller
* @subpackage Request
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Request_Abstract */
require_once 'Zend/Controller/Request/Abstract.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Request
* @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_Controller_Request_Simple extends Zend_Controller_Request_Abstract
{
public function __construct($action = null, $controller = null, $module = null, array $params = array())
{
if ($action) {
$this->setActionName($action);
}
if ($controller) {
$this->setControllerName($controller);
}
if ($module) {
$this->setModuleName($module);
}
if ($params) {
$this->setParams($params);
}
}
}
Controller/Request/Abstract.php 0000604 00000016426 15071256136 0012606 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Request_Abstract
{
/**
* Has the action been dispatched?
* @var boolean
*/
protected $_dispatched = false;
/**
* Module
* @var string
*/
protected $_module;
/**
* Module key for retrieving module from params
* @var string
*/
protected $_moduleKey = 'module';
/**
* Controller
* @var string
*/
protected $_controller;
/**
* Controller key for retrieving controller from params
* @var string
*/
protected $_controllerKey = 'controller';
/**
* Action
* @var string
*/
protected $_action;
/**
* Action key for retrieving action from params
* @var string
*/
protected $_actionKey = 'action';
/**
* Request parameters
* @var array
*/
protected $_params = array();
/**
* Retrieve the module name
*
* @return string
*/
public function getModuleName()
{
if (null === $this->_module) {
$this->_module = $this->getParam($this->getModuleKey());
}
return $this->_module;
}
/**
* Set the module name to use
*
* @param string $value
* @return Zend_Controller_Request_Abstract
*/
public function setModuleName($value)
{
$this->_module = $value;
return $this;
}
/**
* Retrieve the controller name
*
* @return string
*/
public function getControllerName()
{
if (null === $this->_controller) {
$this->_controller = $this->getParam($this->getControllerKey());
}
return $this->_controller;
}
/**
* Set the controller name to use
*
* @param string $value
* @return Zend_Controller_Request_Abstract
*/
public function setControllerName($value)
{
$this->_controller = $value;
return $this;
}
/**
* Retrieve the action name
*
* @return string
*/
public function getActionName()
{
if (null === $this->_action) {
$this->_action = $this->getParam($this->getActionKey());
}
return $this->_action;
}
/**
* Set the action name
*
* @param string $value
* @return Zend_Controller_Request_Abstract
*/
public function setActionName($value)
{
$this->_action = $value;
/**
* @see ZF-3465
*/
if (null === $value) {
$this->setParam($this->getActionKey(), $value);
}
return $this;
}
/**
* Retrieve the module key
*
* @return string
*/
public function getModuleKey()
{
return $this->_moduleKey;
}
/**
* Set the module key
*
* @param string $key
* @return Zend_Controller_Request_Abstract
*/
public function setModuleKey($key)
{
$this->_moduleKey = (string) $key;
return $this;
}
/**
* Retrieve the controller key
*
* @return string
*/
public function getControllerKey()
{
return $this->_controllerKey;
}
/**
* Set the controller key
*
* @param string $key
* @return Zend_Controller_Request_Abstract
*/
public function setControllerKey($key)
{
$this->_controllerKey = (string) $key;
return $this;
}
/**
* Retrieve the action key
*
* @return string
*/
public function getActionKey()
{
return $this->_actionKey;
}
/**
* Set the action key
*
* @param string $key
* @return Zend_Controller_Request_Abstract
*/
public function setActionKey($key)
{
$this->_actionKey = (string) $key;
return $this;
}
/**
* Get an action parameter
*
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed
*/
public function getParam($key, $default = null)
{
$key = (string) $key;
if (isset($this->_params[$key])) {
return $this->_params[$key];
}
return $default;
}
/**
* Retrieve only user params (i.e, any param specific to the object and not the environment)
*
* @return array
*/
public function getUserParams()
{
return $this->_params;
}
/**
* Retrieve a single user param (i.e, a param specific to the object and not the environment)
*
* @param string $key
* @param string $default Default value to use if key not found
* @return mixed
*/
public function getUserParam($key, $default = null)
{
if (isset($this->_params[$key])) {
return $this->_params[$key];
}
return $default;
}
/**
* Set an action parameter
*
* A $value of null will unset the $key if it exists
*
* @param string $key
* @param mixed $value
* @return Zend_Controller_Request_Abstract
*/
public function setParam($key, $value)
{
$key = (string) $key;
if ((null === $value) && isset($this->_params[$key])) {
unset($this->_params[$key]);
} elseif (null !== $value) {
$this->_params[$key] = $value;
}
return $this;
}
/**
* Get all action parameters
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
/**
* Set action parameters en masse; does not overwrite
*
* Null values will unset the associated key.
*
* @param array $array
* @return Zend_Controller_Request_Abstract
*/
public function setParams(array $array)
{
$this->_params = $this->_params + (array) $array;
foreach ($this->_params as $key => $value) {
if (null === $value) {
unset($this->_params[$key]);
}
}
return $this;
}
/**
* Set flag indicating whether or not request has been dispatched
*
* @param boolean $flag
* @return Zend_Controller_Request_Abstract
*/
public function setDispatched($flag = true)
{
$this->_dispatched = $flag ? true : false;
return $this;
}
/**
* Determine if the request has been dispatched
*
* @return boolean
*/
public function isDispatched()
{
return $this->_dispatched;
}
}
Controller/Request/Http.php 0000604 00000066012 15071256136 0011756 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Request_Exception */
require_once 'Zend/Controller/Request/Exception.php';
/** Zend_Controller_Request_Abstract */
require_once 'Zend/Controller/Request/Abstract.php';
/** Zend_Uri */
require_once 'Zend/Uri.php';
/**
* Zend_Controller_Request_Http
*
* HTTP request object for use with Zend_Controller family.
*
* @uses Zend_Controller_Request_Abstract
* @package Zend_Controller
* @subpackage Request
*/
class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
{
/**
* Scheme for http
*
*/
const SCHEME_HTTP = 'http';
/**
* Scheme for https
*
*/
const SCHEME_HTTPS = 'https';
/**
* Allowed parameter sources
* @var array
*/
protected $_paramSources = array('_GET', '_POST');
/**
* REQUEST_URI
* @var string;
*/
protected $_requestUri;
/**
* Base URL of request
* @var string
*/
protected $_baseUrl = null;
/**
* Base path of request
* @var string
*/
protected $_basePath = null;
/**
* PATH_INFO
* @var string
*/
protected $_pathInfo = '';
/**
* Instance parameters
* @var array
*/
protected $_params = array();
/**
* Alias keys for request parameters
* @var array
*/
protected $_aliases = array();
/**
* Constructor
*
* If a $uri is passed, the object will attempt to populate itself using
* that information.
*
* @param string|Zend_Uri $uri
* @return void
* @throws Zend_Controller_Request_Exception when invalid URI passed
*/
public function __construct($uri = null)
{
if (null !== $uri) {
if (!$uri instanceof Zend_Uri) {
$uri = Zend_Uri::factory($uri);
}
if ($uri->valid()) {
$path = $uri->getPath();
$query = $uri->getQuery();
if (!empty($query)) {
$path .= '?' . $query;
}
$this->setRequestUri($path);
} else {
require_once 'Zend/Controller/Request/Exception.php';
throw new Zend_Controller_Request_Exception('Invalid URI provided to constructor');
}
} else {
$this->setRequestUri();
}
}
/**
* Access values contained in the superglobals as public members
* Order of precedence: 1. GET, 2. POST, 3. COOKIE, 4. SERVER, 5. ENV
*
* @see http://msdn.microsoft.com/en-us/library/system.web.httprequest.item.aspx
* @param string $key
* @return mixed
*/
public function __get($key)
{
switch (true) {
case isset($this->_params[$key]):
return $this->_params[$key];
case isset($_GET[$key]):
return $_GET[$key];
case isset($_POST[$key]):
return $_POST[$key];
case isset($_COOKIE[$key]):
return $_COOKIE[$key];
case ($key == 'REQUEST_URI'):
return $this->getRequestUri();
case ($key == 'PATH_INFO'):
return $this->getPathInfo();
case isset($_SERVER[$key]):
return $_SERVER[$key];
case isset($_ENV[$key]):
return $_ENV[$key];
default:
return null;
}
}
/**
* Alias to __get
*
* @param string $key
* @return mixed
*/
public function get($key)
{
return $this->__get($key);
}
/**
* Set values
*
* In order to follow {@link __get()}, which operates on a number of
* superglobals, setting values through overloading is not allowed and will
* raise an exception. Use setParam() instead.
*
* @param string $key
* @param mixed $value
* @return void
* @throws Zend_Controller_Request_Exception
*/
public function __set($key, $value)
{
require_once 'Zend/Controller/Request/Exception.php';
throw new Zend_Controller_Request_Exception('Setting values in superglobals not allowed; please use setParam()');
}
/**
* Alias to __set()
*
* @param string $key
* @param mixed $value
* @return void
*/
public function set($key, $value)
{
return $this->__set($key, $value);
}
/**
* Check to see if a property is set
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
switch (true) {
case isset($this->_params[$key]):
return true;
case isset($_GET[$key]):
return true;
case isset($_POST[$key]):
return true;
case isset($_COOKIE[$key]):
return true;
case isset($_SERVER[$key]):
return true;
case isset($_ENV[$key]):
return true;
default:
return false;
}
}
/**
* Alias to __isset()
*
* @param string $key
* @return boolean
*/
public function has($key)
{
return $this->__isset($key);
}
/**
* Set GET values
*
* @param string|array $spec
* @param null|mixed $value
* @return Zend_Controller_Request_Http
*/
public function setQuery($spec, $value = null)
{
if ((null === $value) && !is_array($spec)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid value passed to setQuery(); must be either array of values or key/value pair');
}
if ((null === $value) && is_array($spec)) {
foreach ($spec as $key => $value) {
$this->setQuery($key, $value);
}
return $this;
}
$_GET[(string) $spec] = $value;
return $this;
}
/**
* Retrieve a member of the $_GET superglobal
*
* If no $key is passed, returns the entire $_GET array.
*
* @todo How to retrieve from nested arrays
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getQuery($key = null, $default = null)
{
if (null === $key) {
return $_GET;
}
return (isset($_GET[$key])) ? $_GET[$key] : $default;
}
/**
* Set POST values
*
* @param string|array $spec
* @param null|mixed $value
* @return Zend_Controller_Request_Http
*/
public function setPost($spec, $value = null)
{
if ((null === $value) && !is_array($spec)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid value passed to setPost(); must be either array of values or key/value pair');
}
if ((null === $value) && is_array($spec)) {
foreach ($spec as $key => $value) {
$this->setPost($key, $value);
}
return $this;
}
$_POST[(string) $spec] = $value;
return $this;
}
/**
* Retrieve a member of the $_POST superglobal
*
* If no $key is passed, returns the entire $_POST array.
*
* @todo How to retrieve from nested arrays
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getPost($key = null, $default = null)
{
if (null === $key) {
return $_POST;
}
return (isset($_POST[$key])) ? $_POST[$key] : $default;
}
/**
* Retrieve a member of the $_COOKIE superglobal
*
* If no $key is passed, returns the entire $_COOKIE array.
*
* @todo How to retrieve from nested arrays
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getCookie($key = null, $default = null)
{
if (null === $key) {
return $_COOKIE;
}
return (isset($_COOKIE[$key])) ? $_COOKIE[$key] : $default;
}
/**
* Retrieve a member of the $_SERVER superglobal
*
* If no $key is passed, returns the entire $_SERVER array.
*
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getServer($key = null, $default = null)
{
if (null === $key) {
return $_SERVER;
}
return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default;
}
/**
* Retrieve a member of the $_ENV superglobal
*
* If no $key is passed, returns the entire $_ENV array.
*
* @param string $key
* @param mixed $default Default value to use if key not found
* @return mixed Returns null if key does not exist
*/
public function getEnv($key = null, $default = null)
{
if (null === $key) {
return $_ENV;
}
return (isset($_ENV[$key])) ? $_ENV[$key] : $default;
}
/**
* Set the REQUEST_URI on which the instance operates
*
* If no request URI is passed, uses the value in $_SERVER['REQUEST_URI'],
* $_SERVER['HTTP_X_REWRITE_URL'], or $_SERVER['ORIG_PATH_INFO'] + $_SERVER['QUERY_STRING'].
*
* @param string $requestUri
* @return Zend_Controller_Request_Http
*/
public function setRequestUri($requestUri = null)
{
if ($requestUri === null) {
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri, $_SERVER['HTTP_HOST'])) {
$pathInfo = parse_url($requestUri, PHP_URL_PATH);
$queryString = parse_url($requestUri, PHP_URL_QUERY);
$requestUri = $pathInfo
. ((empty($queryString)) ? '' : '?' . $queryString);
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this;
}
} elseif (!is_string($requestUri)) {
return $this;
} else {
// Set GET items, if available
if (false !== ($pos = strpos($requestUri, '?'))) {
// Get key => value pairs and set $_GET
$query = substr($requestUri, $pos + 1);
parse_str($query, $vars);
$this->setQuery($vars);
}
}
$this->_requestUri = $requestUri;
return $this;
}
/**
* Returns the REQUEST_URI taking into account
* platform differences between Apache and IIS
*
* @return string
*/
public function getRequestUri()
{
if (empty($this->_requestUri)) {
$this->setRequestUri();
}
return $this->_requestUri;
}
/**
* Set the base URL of the request; i.e., the segment leading to the script name
*
* E.g.:
* - /admin
* - /myapp
* - /subdir/index.php
*
* Do not use the full URI when providing the base. The following are
* examples of what not to use:
* - http://example.com/admin (should be just /admin)
* - http://example.com/subdir/index.php (should be just /subdir/index.php)
*
* If no $baseUrl is provided, attempts to determine the base URL from the
* environment, using SCRIPT_FILENAME, SCRIPT_NAME, PHP_SELF, and
* ORIG_SCRIPT_NAME in its determination.
*
* @param mixed $baseUrl
* @return Zend_Controller_Request_Http
*/
public function setBaseUrl($baseUrl = null)
{
if ((null !== $baseUrl) && !is_string($baseUrl)) {
return $this;
}
if ($baseUrl === null) {
$filename = (isset($_SERVER['SCRIPT_FILENAME'])) ? basename($_SERVER['SCRIPT_FILENAME']) : '';
if (isset($_SERVER['SCRIPT_NAME']) && basename($_SERVER['SCRIPT_NAME']) === $filename) {
$baseUrl = $_SERVER['SCRIPT_NAME'];
} elseif (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) === $filename) {
$baseUrl = $_SERVER['PHP_SELF'];
} elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $filename) {
$baseUrl = $_SERVER['ORIG_SCRIPT_NAME']; // 1and1 shared hosting compatibility
} else {
// Backtrack up the script_filename to find the portion matching
// php_self
$path = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
$file = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';
$segs = explode('/', trim($file, '/'));
$segs = array_reverse($segs);
$index = 0;
$last = count($segs);
$baseUrl = '';
do {
$seg = $segs[$index];
$baseUrl = '/' . $seg . $baseUrl;
++$index;
} while (($last > $index) && (false !== ($pos = strpos($path, $baseUrl))) && (0 != $pos));
}
// Does the baseUrl have anything in common with the request_uri?
$requestUri = $this->getRequestUri();
if (0 === strpos($requestUri, $baseUrl)) {
// full $baseUrl matches
$this->_baseUrl = $baseUrl;
return $this;
}
if (0 === strpos($requestUri, dirname($baseUrl))) {
// directory portion of $baseUrl matches
$this->_baseUrl = rtrim(dirname($baseUrl), '/');
return $this;
}
if (!strpos($requestUri, basename($baseUrl))) {
// no match whatsoever; set it blank
$this->_baseUrl = '';
return $this;
}
// If using mod_rewrite or ISAPI_Rewrite strip the script filename
// out of baseUrl. $pos !== 0 makes sure it is not matching a value
// from PATH_INFO or QUERY_STRING
if ((strlen($requestUri) >= strlen($baseUrl))
&& ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0)))
{
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
}
}
$this->_baseUrl = rtrim($baseUrl, '/');
return $this;
}
/**
* Everything in REQUEST_URI before PATH_INFO
* <form action="<?=$baseUrl?>/news/submit" method="POST"/>
*
* @return string
*/
public function getBaseUrl()
{
if (null === $this->_baseUrl) {
$this->setBaseUrl();
}
return $this->_baseUrl;
}
/**
* Set the base path for the URL
*
* @param string|null $basePath
* @return Zend_Controller_Request_Http
*/
public function setBasePath($basePath = null)
{
if ($basePath === null) {
$filename = basename($_SERVER['SCRIPT_FILENAME']);
$baseUrl = $this->getBaseUrl();
if (empty($baseUrl)) {
$this->_basePath = '';
return $this;
}
if (basename($baseUrl) === $filename) {
$basePath = dirname($baseUrl);
} else {
$basePath = $baseUrl;
}
}
if (substr(PHP_OS, 0, 3) === 'WIN') {
$basePath = str_replace('\\', '/', $basePath);
}
$this->_basePath = rtrim($basePath, '/');
return $this;
}
/**
* Everything in REQUEST_URI before PATH_INFO not including the filename
* <img src="<?=$basePath?>/images/zend.png"/>
*
* @return string
*/
public function getBasePath()
{
if (null === $this->_basePath) {
$this->setBasePath();
}
return $this->_basePath;
}
/**
* Set the PATH_INFO string
*
* @param string|null $pathInfo
* @return Zend_Controller_Request_Http
*/
public function setPathInfo($pathInfo = null)
{
if ($pathInfo === null) {
$baseUrl = $this->getBaseUrl();
if (null === ($requestUri = $this->getRequestUri())) {
return $this;
}
// Remove the query string from REQUEST_URI
if ($pos = strpos($requestUri, '?')) {
$requestUri = substr($requestUri, 0, $pos);
}
if ((null !== $baseUrl)
&& (false === ($pathInfo = substr($requestUri, strlen($baseUrl)))))
{
// If substr() returns false then PATH_INFO is set to an empty string
$pathInfo = '';
} elseif (null === $baseUrl) {
$pathInfo = $requestUri;
}
}
$this->_pathInfo = (string) $pathInfo;
return $this;
}
/**
* Returns everything between the BaseUrl and QueryString.
* This value is calculated instead of reading PATH_INFO
* directly from $_SERVER due to cross-platform differences.
*
* @return string
*/
public function getPathInfo()
{
if (empty($this->_pathInfo)) {
$this->setPathInfo();
}
return $this->_pathInfo;
}
/**
* Set allowed parameter sources
*
* Can be empty array, or contain one or more of '_GET' or '_POST'.
*
* @param array $paramSoures
* @return Zend_Controller_Request_Http
*/
public function setParamSources(array $paramSources = array())
{
$this->_paramSources = $paramSources;
return $this;
}
/**
* Get list of allowed parameter sources
*
* @return array
*/
public function getParamSources()
{
return $this->_paramSources;
}
/**
* Set a userland parameter
*
* Uses $key to set a userland parameter. If $key is an alias, the actual
* key will be retrieved and used to set the parameter.
*
* @param mixed $key
* @param mixed $value
* @return Zend_Controller_Request_Http
*/
public function setParam($key, $value)
{
$key = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;
parent::setParam($key, $value);
return $this;
}
/**
* Retrieve a parameter
*
* Retrieves a parameter from the instance. Priority is in the order of
* userland parameters (see {@link setParam()}), $_GET, $_POST. If a
* parameter matching the $key is not found, null is returned.
*
* If the $key is an alias, the actual key aliased will be used.
*
* @param mixed $key
* @param mixed $default Default value to use if key not found
* @return mixed
*/
public function getParam($key, $default = null)
{
$keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key;
$paramSources = $this->getParamSources();
if (isset($this->_params[$keyName])) {
return $this->_params[$keyName];
} elseif (in_array('_GET', $paramSources) && (isset($_GET[$keyName]))) {
return $_GET[$keyName];
} elseif (in_array('_POST', $paramSources) && (isset($_POST[$keyName]))) {
return $_POST[$keyName];
}
return $default;
}
/**
* Retrieve an array of parameters
*
* Retrieves a merged array of parameters, with precedence of userland
* params (see {@link setParam()}), $_GET, $POST (i.e., values in the
* userland params will take precedence over all others).
*
* @return array
*/
public function getParams()
{
$return = $this->_params;
if (isset($_GET) && is_array($_GET)) {
$return += $_GET;
}
if (isset($_POST) && is_array($_POST)) {
$return += $_POST;
}
return $return;
}
/**
* Set parameters
*
* Set one or more parameters. Parameters are set as userland parameters,
* using the keys specified in the array.
*
* @param array $params
* @return Zend_Controller_Request_Http
*/
public function setParams(array $params)
{
foreach ($params as $key => $value) {
$this->setParam($key, $value);
}
return $this;
}
/**
* Set a key alias
*
* Set an alias used for key lookups. $name specifies the alias, $target
* specifies the actual key to use.
*
* @param string $name
* @param string $target
* @return Zend_Controller_Request_Http
*/
public function setAlias($name, $target)
{
$this->_aliases[$name] = $target;
return $this;
}
/**
* Retrieve an alias
*
* Retrieve the actual key represented by the alias $name.
*
* @param string $name
* @return string|null Returns null when no alias exists
*/
public function getAlias($name)
{
if (isset($this->_aliases[$name])) {
return $this->_aliases[$name];
}
return null;
}
/**
* Retrieve the list of all aliases
*
* @return array
*/
public function getAliases()
{
return $this->_aliases;
}
/**
* Return the method by which the request was made
*
* @return string
*/
public function getMethod()
{
return $this->getServer('REQUEST_METHOD');
}
/**
* Was the request made by POST?
*
* @return boolean
*/
public function isPost()
{
if ('POST' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Was the request made by GET?
*
* @return boolean
*/
public function isGet()
{
if ('GET' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Was the request made by PUT?
*
* @return boolean
*/
public function isPut()
{
if ('PUT' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Was the request made by DELETE?
*
* @return boolean
*/
public function isDelete()
{
if ('DELETE' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Was the request made by HEAD?
*
* @return boolean
*/
public function isHead()
{
if ('HEAD' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Was the request made by OPTIONS?
*
* @return boolean
*/
public function isOptions()
{
if ('OPTIONS' == $this->getMethod()) {
return true;
}
return false;
}
/**
* Is the request a Javascript XMLHttpRequest?
*
* Should work with Prototype/Script.aculo.us, possibly others.
*
* @return boolean
*/
public function isXmlHttpRequest()
{
return ($this->getHeader('X_REQUESTED_WITH') == 'XMLHttpRequest');
}
/**
* Is this a Flash request?
*
* @return bool
*/
public function isFlashRequest()
{
$header = strtolower($this->getHeader('USER_AGENT'));
return (strstr($header, ' flash')) ? true : false;
}
/**
* Is https secure request
*
* @return boolean
*/
public function isSecure()
{
return ($this->getScheme() === self::SCHEME_HTTPS);
}
/**
* Return the raw body of the request, if present
*
* @return string|false Raw body, or false if not present
*/
public function getRawBody()
{
$body = file_get_contents('php://input');
if (strlen(trim($body)) > 0) {
return $body;
}
return false;
}
/**
* Return the value of the given HTTP header. Pass the header name as the
* plain, HTTP-specified header name. Ex.: Ask for 'Accept' to get the
* Accept header, 'Accept-Encoding' to get the Accept-Encoding header.
*
* @param string $header HTTP header name
* @return string|false HTTP header value, or false if not found
* @throws Zend_Controller_Request_Exception
*/
public function getHeader($header)
{
if (empty($header)) {
require_once 'Zend/Controller/Request/Exception.php';
throw new Zend_Controller_Request_Exception('An HTTP header name is required');
}
// Try to get it from the $_SERVER array first
$temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
if (!empty($_SERVER[$temp])) {
return $_SERVER[$temp];
}
// This seems to be the only way to get the Authorization header on
// Apache
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
if (!empty($headers[$header])) {
return $headers[$header];
}
}
return false;
}
/**
* Get the request URI scheme
*
* @return string
*/
public function getScheme()
{
return ($this->getServer('HTTPS') == 'on') ? self::SCHEME_HTTPS : self::SCHEME_HTTP;
}
/**
* Get the HTTP host.
*
* "Host" ":" host [ ":" port ] ; Section 3.2.2
* Note the HTTP Host header is not the same as the URI host.
* It includes the port while the URI host doesn't.
*
* @return string
*/
public function getHttpHost()
{
$host = $this->getServer('HTTP_HOST');
if (!empty($host)) {
return $host;
}
$scheme = $this->getScheme();
$name = $this->getServer('SERVER_NAME');
$port = $this->getServer('SERVER_PORT');
if (($scheme == self::SCHEME_HTTP && $port == 80) || ($scheme == self::SCHEME_HTTPS && $port == 443)) {
return $name;
} else {
return $name . ':' . $port;
}
}
}
Controller/Action/Helper/Url.php 0000604 00000007436 15071256136 0012612 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: Url.php 12526 2008-11-10 20:25:20Z ralph $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Helper for creating URLs for redirects and other tasks
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_Url extends Zend_Controller_Action_Helper_Abstract
{
/**
* Create URL based on default route
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return string
*/
public function simple($action, $controller = null, $module = null, array $params = null)
{
$request = $this->getRequest();
if (null === $controller) {
$controller = $request->getControllerName();
}
if (null === $module) {
$module = $request->getModuleName();
}
$url = $controller . '/' . $action;
if ($module != $this->getFrontController()->getDispatcher()->getDefaultModule()) {
$url = $module . '/' . $url;
}
if ('' !== ($baseUrl = $this->getFrontController()->getBaseUrl())) {
$url = $baseUrl . '/' . $url;
}
if (null !== $params) {
$paramPairs = array();
foreach ($params as $key => $value) {
$paramPairs[] = urlencode($key) . '/' . urlencode($value);
}
$paramString = implode('/', $paramPairs);
$url .= '/' . $paramString;
}
$url = '/' . ltrim($url, '/');
return $url;
}
/**
* Assembles a URL based on a given route
*
* This method will typically be used for more complex operations, as it
* ties into the route objects registered with the router.
*
* @param array $urlOptions Options passed to the assemble method of the Route object.
* @param mixed $name The name of a Route to use. If null it will use the current Route
* @param boolean $reset
* @param boolean $encode
* @return string Url for the link href attribute.
*/
public function url($urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$router = $this->getFrontController()->getRouter();
return $router->assemble($urlOptions, $name, $reset, $encode);
}
/**
* Perform helper when called as $this->_helper->url() from an action controller
*
* Proxies to {@link simple()}
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return string
*/
public function direct($action, $controller = null, $module = null, array $params = null)
{
return $this->simple($action, $controller, $module, $params);
}
}
Controller/Action/Helper/ContextSwitch.php 0000604 00000120551 15071256136 0014650 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: ContextSwitch.php 12812 2008-11-24 20:46:45Z matthew $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Simplify context switching based on requested format
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_ContextSwitch extends Zend_Controller_Action_Helper_Abstract
{
/**
* Trigger type constants
*/
const TRIGGER_INIT = 'TRIGGER_INIT';
const TRIGGER_POST = 'TRIGGER_POST';
/**
* Supported contexts
* @var array
*/
protected $_contexts = array();
/**
* JSON auto-serialization flag
* @var boolean
*/
protected $_autoJsonSerialization = true;
/**
* Controller property key to utilize for context switching
* @var string
*/
protected $_contextKey = 'contexts';
/**
* Request parameter containing requested context
* @var string
*/
protected $_contextParam = 'format';
/**
* Current context
* @var string
*/
protected $_currentContext;
/**
* Default context (xml)
* @var string
*/
protected $_defaultContext = 'xml';
/**
* Whether or not to disable layouts when switching contexts
* @var boolean
*/
protected $_disableLayout = true;
/**
* Methods that require special configuration
* @var array
*/
protected $_specialConfig = array(
'setSuffix',
'setHeaders',
'setCallbacks',
);
/**
* Methods that are not configurable via setOptions and setConfig
* @var array
*/
protected $_unconfigurable = array(
'setOptions',
'setConfig',
'setHeader',
'setCallback',
'setContext',
'setActionContext',
'setActionContexts',
);
/**
* @var Zend_Controller_Action_Helper_ViewRenderer
*/
protected $_viewRenderer;
/**
* Original view suffix prior to detecting context switch
* @var string
*/
protected $_viewSuffixOrig;
/**
* Constructor
*
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$this->setConfig($options);
} elseif (is_array($options)) {
$this->setOptions($options);
}
if (empty($this->_contexts)) {
$this->addContexts(array(
'json' => array(
'suffix' => 'json',
'headers' => array('Content-Type' => 'application/json'),
'callbacks' => array(
'init' => 'initJsonContext',
'post' => 'postJsonContext'
)
),
'xml' => array(
'suffix' => 'xml',
'headers' => array('Content-Type' => 'application/xml'),
)
));
}
$this->init();
}
/**
* Initialize at start of action controller
*
* Reset the view script suffix to the original state, or store the
* original state.
*
* @return void
*/
public function init()
{
if (null === $this->_viewSuffixOrig) {
$this->_viewSuffixOrig = $this->_getViewRenderer()->getViewSuffix();
} else {
$this->_getViewRenderer()->setViewSuffix($this->_viewSuffixOrig);
}
}
/**
* Configure object from array of options
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setOptions(array $options)
{
if (isset($options['contexts'])) {
$this->setContexts($options['contexts']);
unset($options['contexts']);
}
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $this->_unconfigurable)) {
continue;
}
if (in_array($method, $this->_specialConfig)) {
$method = '_' . $method;
}
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set object state from config object
*
* @param Zend_Config $config
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Strategy pattern: return object
*
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function direct()
{
return $this;
}
/**
* Initialize context detection and switching
*
* @param mixed $format
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function initContext($format = null)
{
$this->_currentContext = null;
$controller = $this->getActionController();
$request = $this->getRequest();
$action = $request->getActionName();
// Return if no context switching enabled, or no context switching
// enabled for this action
$contexts = $this->getActionContexts($action);
if (empty($contexts)) {
return;
}
// Return if no context parameter provided
if (!$context = $request->getParam($this->getContextParam())) {
if ($format === null) {
return;
}
$context = $format;
$format = null;
}
// Check if context allowed by action controller
if (!$this->hasActionContext($action, $context)) {
return;
}
// Return if invalid context parameter provided and no format or invalid
// format provided
if (!$this->hasContext($context)) {
if (empty($format) || !$this->hasContext($format)) {
return;
}
}
// Use provided format if passed
if (!empty($format) && $this->hasContext($format)) {
$context = $format;
}
$suffix = $this->getSuffix($context);
$this->_getViewRenderer()->setViewSuffix($suffix);
$headers = $this->getHeaders($context);
if (!empty($headers)) {
$response = $this->getResponse();
foreach ($headers as $header => $content) {
$response->setHeader($header, $content);
}
}
if ($this->getAutoDisableLayout()) {
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
$layout = Zend_Layout::getMvcInstance();
if (null !== $layout) {
$layout->disableLayout();
}
}
if (null !== ($callback = $this->getCallback($context, self::TRIGGER_INIT))) {
if (is_string($callback) && method_exists($this, $callback)) {
$this->$callback();
} elseif (is_string($callback) && function_exists($callback)) {
$callback();
} elseif (is_array($callback)) {
call_user_func($callback);
} else {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid context callback registered for context "%s"', $context));
}
}
$this->_currentContext = $context;
}
/**
* JSON context extra initialization
*
* Turns off viewRenderer auto-rendering
*
* @return void
*/
public function initJsonContext()
{
if (!$this->getAutoJsonSerialization()) {
return;
}
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = $viewRenderer->view;
if ($view instanceof Zend_View_Interface) {
$viewRenderer->setNoRender(true);
}
}
/**
* Should JSON contexts auto-serialize?
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setAutoJsonSerialization($flag)
{
$this->_autoJsonSerialization = (bool) $flag;
return $this;
}
/**
* Get JSON context auto-serialization flag
*
* @return boolean
*/
public function getAutoJsonSerialization()
{
return $this->_autoJsonSerialization;
}
/**
* Set suffix from array
*
* @param array $spec
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setSuffix(array $spec)
{
foreach ($spec as $context => $suffixInfo) {
if (!is_string($context)) {
$context = null;
}
if (is_string($suffixInfo)) {
$this->setSuffix($context, $suffixInfo);
continue;
} elseif (is_array($suffixInfo)) {
if (isset($suffixInfo['suffix'])) {
$suffix = $suffixInfo['suffix'];
$prependViewRendererSuffix = true;
if ((null === $context) && isset($suffixInfo['context'])) {
$context = $suffixInfo['context'];
}
if (isset($suffixInfo['prependViewRendererSuffix'])) {
$prependViewRendererSuffix = $suffixInfo['prependViewRendererSuffix'];
}
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
continue;
}
$count = count($suffixInfo);
switch (true) {
case (($count < 2) && (null === $context)):
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid suffix information provided in config');
case ($count < 2):
$suffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix);
break;
case (($count < 3) && (null === $context)):
$context = array_shift($suffixInfo);
$suffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix);
break;
case (($count == 3) && (null === $context)):
$context = array_shift($suffixInfo);
$suffix = array_shift($suffixInfo);
$prependViewRendererSuffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
break;
case ($count >= 2):
$suffix = array_shift($suffixInfo);
$prependViewRendererSuffix = array_shift($suffixInfo);
$this->setSuffix($context, $suffix, $prependViewRendererSuffix);
break;
}
}
}
return $this;
}
/**
* Customize view script suffix to use when switching context.
*
* Passing an empty suffix value to the setters disables the view script
* suffix change.
*
* @param string $context Context type for which to set suffix
* @param string $suffix Suffix to use
* @param boolean $prependViewRendererSuffix Whether or not to prepend the new suffix to the viewrenderer suffix
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setSuffix($context, $suffix, $prependViewRendererSuffix = true)
{
if (!isset($this->_contexts[$context])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot set suffix; invalid context type "%s"', $context));
}
if (empty($suffix)) {
$suffix = '';
}
if (is_array($suffix)) {
if (isset($suffix['prependViewRendererSuffix'])) {
$prependViewRendererSuffix = $suffix['prependViewRendererSuffix'];
}
if (isset($suffix['suffix'])) {
$suffix = $suffix['suffix'];
} else {
$suffix = '';
}
}
$suffix = (string) $suffix;
if ($prependViewRendererSuffix) {
if (empty($suffix)) {
$suffix = $this->_getViewRenderer()->getViewSuffix();
} else {
$suffix .= '.' . $this->_getViewRenderer()->getViewSuffix();
}
}
$this->_contexts[$context]['suffix'] = $suffix;
return $this;
}
/**
* Retrieve suffix for given context type
*
* @param string $type Context type
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function getSuffix($type)
{
if (!isset($this->_contexts[$type])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot retrieve suffix; invalid context type "%s"', $type));
}
return $this->_contexts[$type]['suffix'];
}
/**
* Does the given context exist?
*
* @param string $context
* @param boolean $throwException
* @throws Zend_Controller_Action_Exception if context does not exist and throwException is true
* @return bool
*/
public function hasContext($context, $throwException = false)
{
if (is_string($context)) {
if (isset($this->_contexts[$context])) {
return true;
}
} elseif (is_array($context)) {
$error = false;
foreach ($context as $test) {
if (!isset($this->_contexts[$test])) {
$error = (string) $test;
break;
}
}
if (false === $error) {
return true;
}
$context = $error;
} elseif (true === $context) {
return true;
}
if ($throwException) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Context "%s" does not exist', $context));
}
return false;
}
/**
* Add header to context
*
* @param string $context
* @param string $header
* @param string $content
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addHeader($context, $header, $content)
{
$context = (string) $context;
$this->hasContext($context, true);
$header = (string) $header;
$content = (string) $content;
if (isset($this->_contexts[$context]['headers'][$header])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot add "%s" header to context "%s": already exists', $header, $context));
}
$this->_contexts[$context]['headers'][$header] = $content;
return $this;
}
/**
* Customize response header to use when switching context
*
* Passing an empty header value to the setters disables the response
* header.
*
* @param string $type Context type for which to set suffix
* @param string $header Header to set
* @param string $content Header content
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setHeader($context, $header, $content)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
$content = (string) $content;
$this->_contexts[$context]['headers'][$header] = $content;
return $this;
}
/**
* Add multiple headers at once for a given context
*
* @param string $context
* @param array $headers
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addHeaders($context, array $headers)
{
foreach ($headers as $header => $content) {
$this->addHeader($context, $header, $content);
}
return $this;
}
/**
* Set headers from context => headers pairs
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setHeaders(array $options)
{
foreach ($options as $context => $headers) {
if (!is_array($headers)) {
continue;
}
$this->setHeaders($context, $headers);
}
return $this;
}
/**
* Set multiple headers at once for a given context
*
* @param string $context
* @param array $headers
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setHeaders($context, array $headers)
{
$this->clearHeaders($context);
foreach ($headers as $header => $content) {
$this->setHeader($context, $header, $content);
}
return $this;
}
/**
* Retrieve context header
*
* Returns the value of a given header for a given context type
*
* @param string $context
* @param string $header
* @return string|null
*/
public function getHeader($context, $header)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
if (isset($this->_contexts[$context]['headers'][$header])) {
return $this->_contexts[$context]['headers'][$header];
}
return null;
}
/**
* Retrieve context headers
*
* Returns all headers for a context as key/value pairs
*
* @param string $context
* @return array
*/
public function getHeaders($context)
{
$this->hasContext($context, true);
$context = (string) $context;
return $this->_contexts[$context]['headers'];
}
/**
* Remove a single header from a context
*
* @param string $context
* @param string $header
* @return boolean
*/
public function removeHeader($context, $header)
{
$this->hasContext($context, true);
$context = (string) $context;
$header = (string) $header;
if (isset($this->_contexts[$context]['headers'][$header])) {
unset($this->_contexts[$context]['headers'][$header]);
return true;
}
return false;
}
/**
* Clear all headers for a given context
*
* @param string $context
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearHeaders($context)
{
$this->hasContext($context, true);
$context = (string) $context;
$this->_contexts[$context]['headers'] = array();
return $this;
}
/**
* Validate trigger and return in normalized form
*
* @param string $trigger
* @throws Zend_Controller_Action_Exception
* @return string
*/
protected function _validateTrigger($trigger)
{
$trigger = strtoupper($trigger);
if ('TRIGGER_' !== substr($trigger, 0, 8)) {
$trigger = 'TRIGGER_' . $trigger;
}
if (!in_array($trigger, array(self::TRIGGER_INIT, self::TRIGGER_POST))) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid trigger "%s"', $trigger));
}
return $trigger;
}
/**
* Set a callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @param string|array $callback
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setCallback($context, $trigger, $callback)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (!is_string($callback)) {
if (!is_array($callback) || (2 != count($callback))) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid callback specified');
}
}
$this->_contexts[$context]['callbacks'][$trigger] = $callback;
return $this;
}
/**
* Set callbacks from array of context => callbacks pairs
*
* @param array $options
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
protected function _setCallbacks(array $options)
{
foreach ($options as $context => $callbacks) {
if (!is_array($callbacks)) {
continue;
}
$this->setCallbacks($context, $callbacks);
}
return $this;
}
/**
* Set callbacks for a given context
*
* Callbacks should be in trigger/callback pairs.
*
* @param string $context
* @param array $callbacks
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setCallbacks($context, array $callbacks)
{
$this->hasContext($context, true);
$context = (string) $context;
if (!isset($this->_contexts[$context]['callbacks'])) {
$this->_contexts[$context]['callbacks'] = array();
}
foreach ($callbacks as $trigger => $callback) {
$this->setCallback($context, $trigger, $callback);
}
return $this;
}
/**
* Get a single callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @return string|array|null
*/
public function getCallback($context, $trigger)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (isset($this->_contexts[$context]['callbacks'][$trigger])) {
return $this->_contexts[$context]['callbacks'][$trigger];
}
return null;
}
/**
* Get all callbacks for a given context
*
* @param string $context
* @return array
*/
public function getCallbacks($context)
{
$this->hasContext($context, true);
return $this->_contexts[$context]['callbacks'];
}
/**
* Clear a callback for a given context and trigger
*
* @param string $context
* @param string $trigger
* @return boolean
*/
public function removeCallback($context, $trigger)
{
$this->hasContext($context, true);
$trigger = $this->_validateTrigger($trigger);
if (isset($this->_contexts[$context]['callbacks'][$trigger])) {
unset($this->_contexts[$context]['callbacks'][$trigger]);
return true;
}
return false;
}
/**
* Clear all callbacks for a given context
*
* @param string $context
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearCallbacks($context)
{
$this->hasContext($context, true);
$this->_contexts[$context]['callbacks'] = array();
return $this;
}
/**
* Set name of parameter to use when determining context format
*
* @param string $name
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContextParam($name)
{
$this->_contextParam = (string) $name;
return $this;
}
/**
* Return context format request parameter name
*
* @return string
*/
public function getContextParam()
{
return $this->_contextParam;
}
/**
* Indicate default context to use when no context format provided
*
* @param string $type
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setDefaultContext($type)
{
if (!isset($this->_contexts[$type])) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot set default context; invalid context type "%s"', $type));
}
$this->_defaultContext = $type;
return $this;
}
/**
* Return default context
*
* @return string
*/
public function getDefaultContext()
{
return $this->_defaultContext;
}
/**
* Set flag indicating if layout should be disabled
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setAutoDisableLayout($flag)
{
$this->_disableLayout = ($flag) ? true : false;
return $this;
}
/**
* Retrieve auto layout disable flag
*
* @return boolean
*/
public function getAutoDisableLayout()
{
return $this->_disableLayout;
}
/**
* Add new context
*
* @param string $context Context type
* @param array $spec Context specification
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addContext($context, array $spec)
{
if ($this->hasContext($context)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Cannot add context "%s"; already exists', $context));
}
$context = (string) $context;
$this->_contexts[$context] = array();
$this->setSuffix($context, (isset($spec['suffix']) ? $spec['suffix'] : ''))
->setHeaders($context, (isset($spec['headers']) ? $spec['headers'] : array()))
->setCallbacks($context, (isset($spec['callbacks']) ? $spec['callbacks'] : array()));
return $this;
}
/**
* Overwrite existing context
*
* @param string $context Context type
* @param array $spec Context specification
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContext($context, array $spec)
{
$this->removeContext($context);
return $this->addContext($context, $spec);
}
/**
* Add multiple contexts
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addContexts(array $contexts)
{
foreach ($contexts as $context => $spec) {
$this->addContext($context, $spec);
}
return $this;
}
/**
* Set multiple contexts, after first removing all
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setContexts(array $contexts)
{
$this->clearContexts();
foreach ($contexts as $context => $spec) {
$this->addContext($context, $spec);
}
return $this;
}
/**
* Retrieve context specification
*
* @param string $context
* @return array|null
*/
public function getContext($context)
{
if ($this->hasContext($context)) {
return $this->_contexts[(string) $context];
}
return null;
}
/**
* Retrieve context definitions
*
* @return array
*/
public function getContexts()
{
return $this->_contexts;
}
/**
* Remove a context
*
* @param string $context
* @return boolean
*/
public function removeContext($context)
{
if ($this->hasContext($context)) {
unset($this->_contexts[(string) $context]);
return true;
}
return false;
}
/**
* Remove all contexts
*
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearContexts()
{
$this->_contexts = array();
return $this;
}
/**
* Return current context, if any
*
* @return null|string
*/
public function getCurrentContext()
{
return $this->_currentContext;
}
/**
* Post dispatch processing
*
* Execute postDispatch callback for current context, if available
*
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function postDispatch()
{
$context = $this->getCurrentContext();
if (null !== $context) {
if (null !== ($callback = $this->getCallback($context, self::TRIGGER_POST))) {
if (is_string($callback) && method_exists($this, $callback)) {
$this->$callback();
} elseif (is_string($callback) && function_exists($callback)) {
$callback();
} elseif (is_array($callback)) {
call_user_func($callback);
} else {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid postDispatch context callback registered for context "%s"', $context));
}
}
}
}
/**
* JSON post processing
*
* JSON serialize view variables to response body
*
* @return void
*/
public function postJsonContext()
{
if (!$this->getAutoJsonSerialization()) {
return;
}
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = $viewRenderer->view;
if ($view instanceof Zend_View_Interface) {
/**
* @see Zend_Json
*/
if(method_exists($view, 'getVars')) {
require_once 'Zend/Json.php';
$vars = Zend_Json::encode($view->getVars());
$this->getResponse()->setBody($vars);
} else {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('View does not implement the getVars() method needed to encode the view into JSON');
}
}
}
/**
* Add one or more contexts to an action
*
* @param string $action
* @param string|array $context
* @return Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
*/
public function addActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
$controller->$contextKey = array();
}
if (true === $context) {
$contexts = $this->getContexts();
$controller->{$contextKey}[$action] = array_keys($contexts);
return $this;
}
$context = (array) $context;
if (!isset($controller->{$contextKey}[$action])) {
$controller->{$contextKey}[$action] = $context;
} else {
$controller->{$contextKey}[$action] = array_merge(
$controller->{$contextKey}[$action],
$context
);
}
return $this;
}
/**
* Set a context as available for a given controller action
*
* @param string $action
* @param string|array $context
* @return Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
*/
public function setActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
$controller->$contextKey = array();
}
if (true === $context) {
$contexts = $this->getContexts();
$controller->{$contextKey}[$action] = array_keys($contexts);
} else {
$controller->{$contextKey}[$action] = (array) $context;
}
return $this;
}
/**
* Add multiple action/context pairs at once
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function addActionContexts(array $contexts)
{
foreach ($contexts as $action => $context) {
$this->addActionContext($action, $context);
}
return $this;
}
/**
* Overwrite and set multiple action contexts at once
*
* @param array $contexts
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function setActionContexts(array $contexts)
{
foreach ($contexts as $action => $context) {
$this->setActionContext($action, $context);
}
return $this;
}
/**
* Does a particular controller action have the given context(s)?
*
* @param string $action
* @param string|array $context
* @throws Zend_Controller_Action_Exception
* @return boolean
*/
public function hasActionContext($action, $context)
{
$this->hasContext($context, true);
$controller = $this->getActionController();
if (null === $controller) {
return false;
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->{$contextKey})) {
return false;
}
$allContexts = $controller->{$contextKey};
if (!is_array($allContexts)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception("Invalid contexts found for controller");
}
if (!isset($allContexts[$action])) {
return false;
}
if (true === $allContexts[$action]) {
return true;
}
$contexts = $allContexts[$action];
if (!is_array($contexts)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf("Invalid contexts found for action '%s'", $action));
}
if (is_string($context) && in_array($context, $contexts)) {
return true;
} elseif (is_array($context)) {
$found = true;
foreach ($context as $test) {
if (!in_array($test, $contexts)) {
$found = false;
break;
}
}
return $found;
}
return false;
}
/**
* Get contexts for a given action or all actions in the controller
*
* @param string $action
* @return array
*/
public function getActionContexts($action = null)
{
$controller = $this->getActionController();
if (null === $controller) {
return array();
}
$action = (string) $action;
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey)) {
return array();
}
if (null !== $action) {
if (isset($controller->{$contextKey}[$action])) {
return $controller->{$contextKey}[$action];
} else {
return array();
}
}
return $controller->$contextKey;
}
/**
* Remove one or more contexts for a given controller action
*
* @param string $action
* @param string|array $context
* @return boolean
*/
public function removeActionContext($action, $context)
{
if ($this->hasActionContext($action, $context)) {
$controller = $this->getActionController();
$contextKey = $this->_contextKey;
$action = (string) $action;
$contexts = $controller->$contextKey;
$actionContexts = $contexts[$action];
$contexts = (array) $context;
foreach ($contexts as $context) {
$index = array_search($context, $actionContexts);
if (false !== $index) {
unset($controller->{$contextKey}[$action][$index]);
}
}
return true;
}
return false;
}
/**
* Clear all contexts for a given controller action or all actions
*
* @param string $action
* @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
*/
public function clearActionContexts($action = null)
{
$controller = $this->getActionController();
$contextKey = $this->_contextKey;
if (!isset($controller->$contextKey) || empty($controller->$contextKey)) {
return $this;
}
if (null === $action) {
$controller->$contextKey = array();
return $this;
}
$action = (string) $action;
if (isset($controller->{$contextKey}[$action])) {
unset($controller->{$contextKey}[$action]);
}
return $this;
}
/**
* Retrieve ViewRenderer
*
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
protected function _getViewRenderer()
{
if (null === $this->_viewRenderer) {
$this->_viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
}
return $this->_viewRenderer;
}
}
Controller/Action/Helper/AutoComplete/Abstract.php 0000604 00000010270 15071256136 0016202 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: Abstract.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Create and send autocompletion lists
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Action_Helper_AutoComplete_Abstract extends Zend_Controller_Action_Helper_Abstract
{
/**
* Suppress exit when sendJson() called
*
* @var boolean
*/
public $suppressExit = false;
/**
* Validate autocompletion data
*
* @param mixed $data
* @return boolean
*/
abstract public function validateData($data);
/**
* Prepare autocompletion data
*
* @param mixed $data
* @param boolean $keepLayouts
* @return mixed
*/
abstract public function prepareAutoCompletion($data, $keepLayouts = false);
/**
* Disable layouts and view renderer
*
* @return Zend_Controller_Action_Helper_AutoComplete_Abstract Provides a fluent interface
*/
public function disableLayouts()
{
/**
* @see Zend_Layout
*/
require_once 'Zend/Layout.php';
if (null !== ($layout = Zend_Layout::getMvcInstance())) {
$layout->disableLayout();
}
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
return $this;
}
/**
* Encode data to JSON
*
* @param mixed $data
* @param bool $keepLayouts
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function encodeJson($data, $keepLayouts = false)
{
if ($this->validateData($data)) {
return Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts);
}
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
}
/**
* Send autocompletion data
*
* Calls prepareAutoCompletion, populates response body with this
* information, and sends response.
*
* @param mixed $data
* @param bool $keepLayouts
* @return string|void
*/
public function sendAutoCompletion($data, $keepLayouts = false)
{
$data = $this->prepareAutoCompletion($data, $keepLayouts);
$response = $this->getResponse();
$response->setBody($data);
if (!$this->suppressExit) {
$response->sendResponse();
exit;
}
return $data;
}
/**
* Strategy pattern: allow calling helper as broker method
*
* Prepares autocompletion data and, if $sendNow is true, immediately sends
* response.
*
* @param mixed $data
* @param bool $sendNow
* @param bool $keepLayouts
* @return string|void
*/
public function direct($data, $sendNow = true, $keepLayouts = false)
{
if ($sendNow) {
return $this->sendAutoCompletion($data, $keepLayouts);
}
return $this->prepareAutoCompletion($data, $keepLayouts);
}
}
Controller/Action/Helper/Redirector.php 0000604 00000035176 15071256136 0014154 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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 Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_Redirector extends Zend_Controller_Action_Helper_Abstract
{
/**
* HTTP status code for redirects
* @var int
*/
protected $_code = 302;
/**
* Whether or not calls to _redirect() should exit script execution
* @var boolean
*/
protected $_exit = true;
/**
* Whether or not _redirect() should attempt to prepend the base URL to the
* passed URL (if it's a relative URL)
* @var boolean
*/
protected $_prependBase = true;
/**
* Url to which to redirect
* @var string
*/
protected $_redirectUrl = null;
/**
* Whether or not to use an absolute URI when redirecting
* @var boolean
*/
protected $_useAbsoluteUri = false;
/**
* Retrieve HTTP status code to emit on {@link _redirect()} call
*
* @return int
*/
public function getCode()
{
return $this->_code;
}
/**
* Validate HTTP status redirect code
*
* @param int $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (int)$code;
if ((300 > $code) || (307 < $code) || (304 == $code) || (306 == $code)) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
/**
* Retrieve HTTP status code for {@link _redirect()} behaviour
*
* @param int $code
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setCode($code)
{
$this->_checkCode($code);
$this->_code = $code;
return $this;
}
/**
* Retrieve flag for whether or not {@link _redirect()} will exit when finished.
*
* @return boolean
*/
public function getExit()
{
return $this->_exit;
}
/**
* Retrieve exit flag for {@link _redirect()} behaviour
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setExit($flag)
{
$this->_exit = ($flag) ? true : false;
return $this;
}
/**
* Retrieve flag for whether or not {@link _redirect()} will prepend the
* base URL on relative URLs
*
* @return boolean
*/
public function getPrependBase()
{
return $this->_prependBase;
}
/**
* Retrieve 'prepend base' flag for {@link _redirect()} behaviour
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setPrependBase($flag)
{
$this->_prependBase = ($flag) ? true : false;
return $this;
}
/**
* Return use absolute URI flag
*
* @return boolean
*/
public function getUseAbsoluteUri()
{
return $this->_useAbsoluteUri;
}
/**
* Set use absolute URI flag
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setUseAbsoluteUri($flag = true)
{
$this->_useAbsoluteUri = ($flag) ? true : false;
return $this;
}
/**
* Set redirect in response object
*
* @return void
*/
protected function _redirect($url)
{
if ($this->getUseAbsoluteUri() && !preg_match('#^(https?|ftp)://#', $url)) {
$host = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
$proto = (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=="off") ? 'https' : 'http';
$port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
$uri = $proto . '://' . $host;
if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
$uri .= ':' . $port;
}
$url = $uri . '/' . ltrim($url, '/');
}
$this->_redirectUrl = $url;
$this->getResponse()->setRedirect($url, $this->getCode());
}
/**
* Retrieve currently set URL for redirect
*
* @return string
*/
public function getRedirectUrl()
{
return $this->_redirectUrl;
}
/**
* Determine if the baseUrl should be prepended, and prepend if necessary
*
* @param string $url
* @return string
*/
protected function _prependBase($url)
{
if ($this->getPrependBase()) {
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Http) {
$base = rtrim($request->getBaseUrl(), '/');
if (!empty($base) && ('/' != $base)) {
$url = $base . '/' . ltrim($url, '/');
} else {
$url = '/' . ltrim($url, '/');
}
}
}
return $url;
}
/**
* Set a redirect URL of the form /module/controller/action/params
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function setGotoSimple($action, $controller = null, $module = null, array $params = array())
{
$dispatcher = $this->getFrontController()->getDispatcher();
$request = $this->getRequest();
$curModule = $request->getModuleName();
$useDefaultController = false;
if (null === $controller && null !== $module) {
$useDefaultController = true;
}
if (null === $module) {
$module = $curModule;
}
if ($module == $dispatcher->getDefaultModule()) {
$module = '';
}
if (null === $controller && !$useDefaultController) {
$controller = $request->getControllerName();
if (empty($controller)) {
$controller = $dispatcher->getDefaultControllerName();
}
}
$params['module'] = $module;
$params['controller'] = $controller;
$params['action'] = $action;
$router = $this->getFrontController()->getRouter();
$url = $router->assemble($params, 'default', true);
$this->_redirect($url);
}
/**
* Build a URL based on a route
*
* @param array $urlOptions
* @param string $name Route name
* @param boolean $reset
* @param boolean $encode
* @return void
*/
public function setGotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$router = $this->getFrontController()->getRouter();
$url = $router->assemble($urlOptions, $name, $reset, $encode);
$this->_redirect($url);
}
/**
* Set a redirect URL string
*
* By default, emits a 302 HTTP status header, prepends base URL as defined
* in request object if url is relative, and halts script execution by
* calling exit().
*
* $options is an optional associative array that can be used to control
* redirect behaviour. The available option keys are:
* - exit: boolean flag indicating whether or not to halt script execution when done
* - prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
* - code: integer HTTP status code to use with redirect. Should be between 300 and 307.
*
* _redirect() sets the Location header in the response object. If you set
* the exit flag to false, you can override this header later in code
* execution.
*
* If the exit flag is true (true by default), _redirect() will write and
* close the current session, if any.
*
* @param string $url
* @param array $options
* @return void
*/
public function setGotoUrl($url, array $options = array())
{
// prevent header injections
$url = str_replace(array("\n", "\r"), '', $url);
$exit = $this->getExit();
$prependBase = $this->getPrependBase();
$code = $this->getCode();
if (null !== $options) {
if (isset($options['exit'])) {
$this->setExit(($options['exit']) ? true : false);
}
if (isset($options['prependBase'])) {
$this->setPrependBase(($options['prependBase']) ? true : false);
}
if (isset($options['code'])) {
$this->setCode($options['code']);
}
}
// If relative URL, decide if we should prepend base URL
if (!preg_match('|^[a-z]+://|', $url)) {
$url = $this->_prependBase($url);
}
$this->_redirect($url);
}
/**
* Perform a redirect to an action/controller/module with params
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function gotoSimple($action, $controller = null, $module = null, array $params = array())
{
$this->setGotoSimple($action, $controller, $module, $params);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Perform a redirect to an action/controller/module with params, forcing an immdiate exit
*
* @param mixed $action
* @param mixed $controller
* @param mixed $module
* @param array $params
* @return void
*/
public function gotoSimpleAndExit($action, $controller = null, $module = null, array $params = array())
{
$this->setGotoSimple($action, $controller, $module, $params);
$this->redirectAndExit();
}
/**
* Redirect to a route-based URL
*
* Uses route's assemble method tobuild the URL; route is specified by $name;
* default route is used if none provided.
*
* @param array $urlOptions Array of key/value pairs used to assemble URL
* @param string $name
* @param boolean $reset
* @param boolean $encode
* @return void
*/
public function gotoRoute(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
{
$this->setGotoRoute($urlOptions, $name, $reset, $encode);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Redirect to a route-based URL, and immediately exit
*
* Uses route's assemble method tobuild the URL; route is specified by $name;
* default route is used if none provided.
*
* @param array $urlOptions Array of key/value pairs used to assemble URL
* @param string $name
* @param boolean $reset
* @return void
*/
public function gotoRouteAndExit(array $urlOptions = array(), $name = null, $reset = false)
{
$this->setGotoRoute($urlOptions, $name, $reset);
$this->redirectAndExit();
}
/**
* Perform a redirect to a url
*
* @param string $url
* @param array $options
* @return void
*/
public function gotoUrl($url, array $options = array())
{
$this->setGotoUrl($url, $options);
if ($this->getExit()) {
$this->redirectAndExit();
}
}
/**
* Set a URL string for a redirect, perform redirect, and immediately exit
*
* @param string $url
* @param array $options
* @return void
*/
public function gotoUrlAndExit($url, array $options = array())
{
$this->gotoUrl($url, $options);
$this->redirectAndExit();
}
/**
* exit(): Perform exit for redirector
*
* @return void
*/
public function redirectAndExit()
{
// Close session, if started
if (class_exists('Zend_Session', false) && Zend_Session::isStarted()) {
Zend_Session::writeClose();
} elseif (isset($_SESSION)) {
session_write_close();
}
$this->getResponse()->sendHeaders();
exit();
}
/**
* direct(): Perform helper when called as
* $this->_helper->redirector($action, $controller, $module, $params)
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
public function direct($action, $controller = null, $module = null, array $params = array())
{
$this->gotoSimple($action, $controller, $module, $params);
}
/**
* Overloading
*
* Overloading for old 'goto', 'setGoto', and 'gotoAndExit' methods
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Controller_Action_Exception for invalid methods
*/
public function __call($method, $args)
{
$method = strtolower($method);
if ('goto' == $method) {
return call_user_func_array(array($this, 'gotoSimple'), $args);
}
if ('setgoto' == $method) {
return call_user_func_array(array($this, 'setGotoSimple'), $args);
}
if ('gotoandexit' == $method) {
return call_user_func_array(array($this, 'gotoSimpleAndExit'), $args);
}
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception(sprintf('Invalid method "%s" called on redirector', $method));
}
}
Controller/Action/Helper/Abstract.php 0000604 00000007436 15071256136 0013613 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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 Zend_Controller_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
/**
* @see Zend_Controller_Action
*/
require_once 'Zend/Controller/Action.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Action_Helper_Abstract
{
/**
* $_actionController
*
* @var Zend_Controller_Action $_actionController
*/
protected $_actionController = null;
/**
* @var mixed $_frontController
*/
protected $_frontController = null;
/**
* setActionController()
*
* @param Zend_Controller_Action $actionController
* @return Zend_Controller_ActionHelper_Abstract Provides a fluent interface
*/
public function setActionController(Zend_Controller_Action $actionController = null)
{
$this->_actionController = $actionController;
return $this;
}
/**
* Retrieve current action controller
*
* @return Zend_Controller_Action
*/
public function getActionController()
{
return $this->_actionController;
}
/**
* Retrieve front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_frontController) {
$this->_frontController = Zend_Controller_Front::getInstance();
}
return $this->_frontController;
}
/**
* Hook into action controller initialization
*
* @return void
*/
public function init()
{
}
/**
* Hook into action controller preDispatch() workflow
*
* @return void
*/
public function preDispatch()
{
}
/**
* Hook into action controller postDispatch() workflow
*
* @return void
*/
public function postDispatch()
{
}
/**
* getRequest() -
*
* @return Zend_Controller_Request_Abstract $request
*/
public function getRequest()
{
$controller = $this->getActionController();
if (null === $controller) {
$controller = $this->getFrontController();
}
return $controller->getRequest();
}
/**
* getResponse() -
*
* @return Zend_Controller_Response_Abstract $response
*/
public function getResponse()
{
$controller = $this->getActionController();
if (null === $controller) {
$controller = $this->getFrontController();
}
return $controller->getResponse();
}
/**
* getName()
*
* @return string
*/
public function getName()
{
$full_class_name = get_class($this);
if (strpos($full_class_name, '_') !== false) {
$helper_name = strrchr($full_class_name, '_');
return ltrim($helper_name, '_');
} else {
return $full_class_name;
}
}
}
Controller/Action/Helper/ActionStack.php 0000604 00000011071 15071256136 0014241 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: ActionStack.php 11493 2008-09-23 14:25:11Z doctorrock83 $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Add to action stack
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_ActionStack extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Controller_Plugin_ActionStack
*/
protected $_actionStack;
/**
* Constructor
*
* Register action stack plugin
*
* @return void
*/
public function __construct()
{
$front = Zend_Controller_Front::getInstance();
if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
/**
* @see Zend_Controller_Plugin_ActionStack
*/
require_once 'Zend/Controller/Plugin/ActionStack.php';
$this->_actionStack = new Zend_Controller_Plugin_ActionStack();
$front->registerPlugin($this->_actionStack, 97);
} else {
$this->_actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
}
}
/**
* Push onto the stack
*
* @param Zend_Controller_Request_Abstract $next
* @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface
*/
public function pushStack(Zend_Controller_Request_Abstract $next)
{
$this->_actionStack->pushStack($next);
return $this;
}
/**
* Push a new action onto the stack
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @throws Zend_Controller_Action_Exception
* @return Zend_Controller_Action_Helper_ActionStack
*/
public function actionToStack($action, $controller = null, $module = null, array $params = array())
{
if ($action instanceof Zend_Controller_Request_Abstract) {
return $this->pushStack($action);
} elseif (!is_string($action)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ActionStack requires either a request object or minimally a string action');
}
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Abstract === false){
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Request object not set yet');
}
$controller = (null === $controller) ? $request->getControllerName() : $controller;
$module = (null === $module) ? $request->getModuleName() : $module;
/**
* @see Zend_Controller_Request_Simple
*/
require_once 'Zend/Controller/Request/Simple.php';
$newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params);
return $this->pushStack($newRequest);
}
/**
* Perform helper when called as $this->_helper->actionStack() from an action controller
*
* Proxies to {@link simple()}
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return boolean
*/
public function direct($action, $controller = null, $module = null, array $params = array())
{
return $this->actionToStack($action, $controller, $module, $params);
}
}
Controller/Action/Helper/AjaxContext.php 0000604 00000004257 15071256136 0014276 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: AjaxContext.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Controller_Action_Helper_ContextSwitch
*/
require_once 'Zend/Controller/Action/Helper/ContextSwitch.php';
/**
* Simplify AJAX context switching based on requested format
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_AjaxContext extends Zend_Controller_Action_Helper_ContextSwitch
{
/**
* Controller property to utilize for context switching
* @var string
*/
protected $_contextKey = 'ajaxable';
/**
* Constructor
*
* Add HTML context
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->addContext('html', array('suffix' => 'ajax'));
}
/**
* Initialize AJAX context switching
*
* Checks for XHR requests; if detected, attempts to perform context switch.
*
* @param string $format
* @return void
*/
public function initContext($format = null)
{
$this->_currentContext = null;
if (!$this->getRequest()->isXmlHttpRequest()) {
return;
}
return parent::initContext($format);
}
}
Controller/Action/Helper/FlashMessenger.php 0000604 00000015330 15071256136 0014746 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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 Zend_Session
*/
require_once 'Zend/Session.php';
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Flash Messenger - implement session-based messages
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: $
*/
class Zend_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Action_Helper_Abstract implements IteratorAggregate, Countable
{
/**
* $_messages - Messages from previous request
*
* @var array
*/
static protected $_messages = array();
/**
* $_session - Zend_Session storage object
*
* @var Zend_Session
*/
static protected $_session = null;
/**
* $_messageAdded - Wether a message has been previously added
*
* @var boolean
*/
static protected $_messageAdded = false;
/**
* $_namespace - Instance namespace, default is 'default'
*
* @var string
*/
protected $_namespace = 'default';
/**
* __construct() - Instance constructor, needed to get iterators, etc
*
* @param string $namespace
* @return void
*/
public function __construct()
{
if (!self::$_session instanceof Zend_Session_Namespace) {
self::$_session = new Zend_Session_Namespace($this->getName());
foreach (self::$_session as $namespace => $messages) {
self::$_messages[$namespace] = $messages;
unset(self::$_session->{$namespace});
}
}
}
/**
* postDispatch() - runs after action is dispatched, in this
* case, it is resetting the namespace in case we have forwarded to a different
* action, Flashmessage will be 'clean' (default namespace)
*
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function postDispatch()
{
$this->resetNamespace();
return $this;
}
/**
* setNamespace() - change the namespace messages are added to, useful for
* per action controller messaging between requests
*
* @param string $namespace
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function setNamespace($namespace = 'default')
{
$this->_namespace = $namespace;
return $this;
}
/**
* resetNamespace() - reset the namespace to the default
*
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function resetNamespace()
{
$this->setNamespace();
return $this;
}
/**
* addMessage() - Add a message to flash message
*
* @param string $message
* @return Zend_Controller_Action_Helper_FlashMessenger Provides a fluent interface
*/
public function addMessage($message)
{
if (self::$_messageAdded === false) {
self::$_session->setExpirationHops(1, null, true);
}
if (!is_array(self::$_session->{$this->_namespace})) {
self::$_session->{$this->_namespace} = array();
}
self::$_session->{$this->_namespace}[] = $message;
return $this;
}
/**
* hasMessages() - Wether a specific namespace has messages
*
* @return boolean
*/
public function hasMessages()
{
return isset(self::$_messages[$this->_namespace]);
}
/**
* getMessages() - Get messages from a specific namespace
*
* @return array
*/
public function getMessages()
{
if ($this->hasMessages()) {
return self::$_messages[$this->_namespace];
}
return array();
}
/**
* Clear all messages from the previous request & current namespace
*
* @return boolean True if messages were cleared, false if none existed
*/
public function clearMessages()
{
if ($this->hasMessages()) {
unset(self::$_messages[$this->_namespace]);
return true;
}
return false;
}
/**
* hasCurrentMessages() - check to see if messages have been added to current
* namespace within this request
*
* @return boolean
*/
public function hasCurrentMessages()
{
return isset(self::$_session->{$this->_namespace});
}
/**
* getCurrentMessages() - get messages that have been added to the current
* namespace within this request
*
* @return array
*/
public function getCurrentMessages()
{
if ($this->hasCurrentMessages()) {
return self::$_session->{$this->_namespace};
}
return array();
}
/**
* clear messages from the current request & current namespace
*
* @return boolean
*/
public function clearCurrentMessages()
{
if ($this->hasCurrentMessages()) {
unset(self::$_session->{$this->_namespace});
return true;
}
return false;
}
/**
* getIterator() - complete the IteratorAggregate interface, for iterating
*
* @return ArrayObject
*/
public function getIterator()
{
if ($this->hasMessages()) {
return new ArrayObject($this->getMessages());
}
return new ArrayObject();
}
/**
* count() - Complete the countable interface
*
* @return int
*/
public function count()
{
if ($this->hasMessages()) {
return count($this->getMessages());
}
return 0;
}
/**
* Strategy pattern: proxy to addMessage()
*
* @param string $message
* @return void
*/
public function direct($message)
{
return $this->addMessage($message);
}
}
Controller/Action/Helper/ViewRenderer.php 0000604 00000070145 15071256136 0014446 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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 Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* @see Zend_View
*/
require_once 'Zend/View.php';
/**
* View script integration
*
* Zend_Controller_Action_Helper_ViewRenderer provides transparent view
* integration for action controllers. It allows you to create a view object
* once, and populate it throughout all actions. Several global options may be
* set:
*
* - noController: if set true, render() will not look for view scripts in
* subdirectories named after the controller
* - viewSuffix: what view script filename suffix to use
*
* The helper autoinitializes the action controller view preDispatch(). It
* determines the path to the class file, and then determines the view base
* directory from there. It also uses the module name as a class prefix for
* helpers and views such that if your module name is 'Search', it will set the
* helper class prefix to 'Search_View_Helper' and the filter class prefix to ;
* 'Search_View_Filter'.
*
* Usage:
* <code>
* // In your bootstrap:
* Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
*
* // In your action controller methods:
* $viewHelper = $this->_helper->getHelper('view');
*
* // Don't use controller subdirectories
* $viewHelper->setNoController(true);
*
* // Specify a different script to render:
* $this->_helper->view('form');
*
* </code>
*
* @uses Zend_Controller_Action_Helper_Abstract
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_View_Interface
*/
public $view;
/**
* Word delimiters
* @var array
*/
protected $_delimiters;
/**
* Front controller instance
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* @var Zend_Filter_Inflector
*/
protected $_inflector;
/**
* Inflector target
* @var string
*/
protected $_inflectorTarget = '';
/**
* Current module directory
* @var string
*/
protected $_moduleDir = '';
/**
* Whether or not to autorender using controller name as subdirectory;
* global setting (not reset at next invocation)
* @var boolean
*/
protected $_neverController = false;
/**
* Whether or not to autorender postDispatch; global setting (not reset at
* next invocation)
* @var boolean
*/
protected $_neverRender = false;
/**
* Whether or not to use a controller name as a subdirectory when rendering
* @var boolean
*/
protected $_noController = false;
/**
* Whether or not to autorender postDispatch; per controller/action setting (reset
* at next invocation)
* @var boolean
*/
protected $_noRender = false;
/**
* Characters representing path delimiters in the controller
* @var string|array
*/
protected $_pathDelimiters;
/**
* Which named segment of the response to utilize
* @var string
*/
protected $_responseSegment = null;
/**
* Which action view script to render
* @var string
*/
protected $_scriptAction = null;
/**
* View object basePath
* @var string
*/
protected $_viewBasePathSpec = ':moduleDir/views';
/**
* View script path specification string
* @var string
*/
protected $_viewScriptPathSpec = ':controller/:action.:suffix';
/**
* View script path specification string, minus controller segment
* @var string
*/
protected $_viewScriptPathNoControllerSpec = ':action.:suffix';
/**
* View script suffix
* @var string
*/
protected $_viewSuffix = 'phtml';
/**
* Constructor
*
* Optionally set view object and options.
*
* @param Zend_View_Interface $view
* @param array $options
* @return void
*/
public function __construct(Zend_View_Interface $view = null, array $options = array())
{
if (null !== $view) {
$this->setView($view);
}
if (!empty($options)) {
$this->_setOptions($options);
}
}
/**
* Clone - also make sure the view is cloned.
*
* @return void
*/
public function __clone()
{
if (isset($this->view) && $this->view instanceof Zend_View_Interface) {
$this->view = clone $this->view;
}
}
/**
* Set the view object
*
* @param Zend_View_Interface $view
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}
/**
* Get current module name
*
* @return string
*/
public function getModule()
{
$request = $this->getRequest();
$module = $request->getModuleName();
if (null === $module) {
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
}
return $module;
}
/**
* Get module directory
*
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function getModuleDirectory()
{
$module = $this->getModule();
$moduleDir = $this->getFrontController()->getControllerDirectory($module);
if ((null === $moduleDir) || is_array($moduleDir)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ViewRenderer cannot locate module directory');
}
$this->_moduleDir = dirname($moduleDir);
return $this->_moduleDir;
}
/**
* Get inflector
*
* @return Zend_Filter_Inflector
*/
public function getInflector()
{
if (null === $this->_inflector) {
/**
* @see Zend_Filter_Inflector
*/
require_once 'Zend/Filter/Inflector.php';
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/PregReplace.php';
/**
* @see Zend_Filter_Word_UnderscoreToSeparator
*/
require_once 'Zend/Filter/Word/UnderscoreToSeparator.php';
$this->_inflector = new Zend_Filter_Inflector();
$this->_inflector->setStaticRuleReference('moduleDir', $this->_moduleDir) // moduleDir must be specified before the less specific 'module'
->addRules(array(
':module' => array('Word_CamelCaseToDash', 'StringToLower'),
':controller' => array('Word_CamelCaseToDash', new Zend_Filter_Word_UnderscoreToSeparator('/'), 'StringToLower', new Zend_Filter_PregReplace('/\./', '-')),
':action' => array('Word_CamelCaseToDash', new Zend_Filter_PregReplace('#[^a-z0-9' . preg_quote('/', '#') . ']+#i', '-'), 'StringToLower'),
))
->setStaticRuleReference('suffix', $this->_viewSuffix)
->setTargetReference($this->_inflectorTarget);
}
// Ensure that module directory is current
$this->getModuleDirectory();
return $this->_inflector;
}
/**
* Set inflector
*
* @param Zend_Filter_Inflector $inflector
* @param boolean $reference Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setInflector(Zend_Filter_Inflector $inflector, $reference = false)
{
$this->_inflector = $inflector;
if ($reference) {
$this->_inflector->setStaticRuleReference('suffix', $this->_viewSuffix)
->setStaticRuleReference('moduleDir', $this->_moduleDir)
->setTargetReference($this->_inflectorTarget);
}
return $this;
}
/**
* Set inflector target
*
* @param string $target
* @return void
*/
protected function _setInflectorTarget($target)
{
$this->_inflectorTarget = (string) $target;
}
/**
* Set internal module directory representation
*
* @param string $dir
* @return void
*/
protected function _setModuleDir($dir)
{
$this->_moduleDir = (string) $dir;
}
/**
* Get internal module directory representation
*
* @return string
*/
protected function _getModuleDir()
{
return $this->_moduleDir;
}
/**
* Generate a class prefix for helper and filter classes
*
* @return string
*/
protected function _generateDefaultPrefix()
{
$default = 'Zend_View';
if (null === $this->_actionController) {
return $default;
}
$class = get_class($this->_actionController);
if (!strstr($class, '_')) {
return $default;
}
$module = $this->getModule();
if ('default' == $module) {
return $default;
}
$prefix = substr($class, 0, strpos($class, '_')) . '_View';
return $prefix;
}
/**
* Retrieve base path based on location of current action controller
*
* @return string
*/
protected function _getBasePath()
{
if (null === $this->_actionController) {
return './views';
}
$inflector = $this->getInflector();
$this->_setInflectorTarget($this->getViewBasePathSpec());
$dispatcher = $this->_frontController->getDispatcher();
$request = $this->getRequest();
$parts = array(
'module' => (($moduleName = $request->getModuleName()) != '') ? $dispatcher->formatModuleName($moduleName) : $moduleName,
'controller' => $request->getControllerName(),
'action' => $dispatcher->formatActionName($request->getActionName())
);
$path = $inflector->filter($parts);
return $path;
}
/**
* Set options
*
* @param array $options
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
protected function _setOptions(array $options)
{
foreach ($options as $key => $value)
{
switch ($key) {
case 'neverRender':
case 'neverController':
case 'noController':
case 'noRender':
$property = '_' . $key;
$this->{$property} = ($value) ? true : false;
break;
case 'responseSegment':
case 'scriptAction':
case 'viewBasePathSpec':
case 'viewScriptPathSpec':
case 'viewScriptPathNoControllerSpec':
case 'viewSuffix':
$property = '_' . $key;
$this->{$property} = (string) $value;
break;
default:
break;
}
}
return $this;
}
/**
* Initialize the view object
*
* $options may contain the following keys:
* - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls)
* - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller
* - noRender - flag indicating whether or not to autorender postDispatch()
* - responseSegment - which named response segment to render a view script to
* - scriptAction - what action script to render
* - viewBasePathSpec - specification to use for determining view base path
* - viewScriptPathSpec - specification to use for determining view script paths
* - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set
* - viewSuffix - what view script filename suffix to use
*
* @param string $path
* @param string $prefix
* @param array $options
* @throws Zend_Controller_Action_Exception
* @return void
*/
public function initView($path = null, $prefix = null, array $options = array())
{
if (null === $this->view) {
$this->setView(new Zend_View());
}
// Reset some flags every time
$options['noController'] = (isset($options['noController'])) ? $options['noController'] : false;
$options['noRender'] = (isset($options['noRender'])) ? $options['noRender'] : false;
$this->_scriptAction = null;
$this->_responseSegment = null;
// Set options first; may be used to determine other initializations
$this->_setOptions($options);
// Get base view path
if (empty($path)) {
$path = $this->_getBasePath();
if (empty($path)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('ViewRenderer initialization failed: retrieved view base path is empty');
}
}
if (null === $prefix) {
$prefix = $this->_generateDefaultPrefix();
}
// Determine if this path has already been registered
$currentPaths = $this->view->getScriptPaths();
$path = str_replace(array('/', '\\'), '/', $path);
$pathExists = false;
foreach ($currentPaths as $tmpPath) {
$tmpPath = str_replace(array('/', '\\'), '/', $tmpPath);
if (strstr($tmpPath, $path)) {
$pathExists = true;
break;
}
}
if (!$pathExists) {
$this->view->addBasePath($path, $prefix);
}
// Register view with action controller (unless already registered)
if ((null !== $this->_actionController) && (null === $this->_actionController->view)) {
$this->_actionController->view = $this->view;
$this->_actionController->viewSuffix = $this->_viewSuffix;
}
}
/**
* init - initialize view
*
* @return void
*/
public function init()
{
if ($this->getFrontController()->getParam('noViewRenderer')) {
return;
}
$this->initView();
}
/**
* Set view basePath specification
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewBasePathSpec($path)
{
$this->_viewBasePathSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view basePath specification string
*
* @return string
*/
public function getViewBasePathSpec()
{
return $this->_viewBasePathSpec;
}
/**
* Set view script path specification
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewScriptPathSpec($path)
{
$this->_viewScriptPathSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view script path specification string
*
* @return string
*/
public function getViewScriptPathSpec()
{
return $this->_viewScriptPathSpec;
}
/**
* Set view script path specification (no controller variant)
*
* Specification can contain one or more of the following:
* - :moduleDir - current module directory
* - :controller - name of current controller in the request
* - :action - name of current action in the request
* - :module - name of current module in the request
*
* :controller will likely be ignored in this variant.
*
* @param string $path
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewScriptPathNoControllerSpec($path)
{
$this->_viewScriptPathNoControllerSpec = (string) $path;
return $this;
}
/**
* Retrieve the current view script path specification string (no controller variant)
*
* @return string
*/
public function getViewScriptPathNoControllerSpec()
{
return $this->_viewScriptPathNoControllerSpec;
}
/**
* Get a view script based on an action and/or other variables
*
* Uses values found in current request if no values passed in $vars.
*
* If {@link $_noController} is set, uses {@link $_viewScriptPathNoControllerSpec};
* otherwise, uses {@link $_viewScriptPathSpec}.
*
* @param string $action
* @param array $vars
* @return string
*/
public function getViewScript($action = null, array $vars = array())
{
$request = $this->getRequest();
if ((null === $action) && (!isset($vars['action']))) {
$action = $this->getScriptAction();
if (null === $action) {
$action = $request->getActionName();
}
$vars['action'] = $action;
} elseif (null !== $action) {
$vars['action'] = $action;
}
$inflector = $this->getInflector();
if ($this->getNoController() || $this->getNeverController()) {
$this->_setInflectorTarget($this->getViewScriptPathNoControllerSpec());
} else {
$this->_setInflectorTarget($this->getViewScriptPathSpec());
}
return $this->_translateSpec($vars);
}
/**
* Set the neverRender flag (i.e., globally dis/enable autorendering)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNeverRender($flag = true)
{
$this->_neverRender = ($flag) ? true : false;
return $this;
}
/**
* Retrieve neverRender flag value
*
* @return boolean
*/
public function getNeverRender()
{
return $this->_neverRender;
}
/**
* Set the noRender flag (i.e., whether or not to autorender)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNoRender($flag = true)
{
$this->_noRender = ($flag) ? true : false;
return $this;
}
/**
* Retrieve noRender flag value
*
* @return boolean
*/
public function getNoRender()
{
return $this->_noRender;
}
/**
* Set the view script to use
*
* @param string $name
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setScriptAction($name)
{
$this->_scriptAction = (string) $name;
return $this;
}
/**
* Retrieve view script name
*
* @return string
*/
public function getScriptAction()
{
return $this->_scriptAction;
}
/**
* Set the response segment name
*
* @param string $name
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setResponseSegment($name)
{
if (null === $name) {
$this->_responseSegment = null;
} else {
$this->_responseSegment = (string) $name;
}
return $this;
}
/**
* Retrieve named response segment name
*
* @return string
*/
public function getResponseSegment()
{
return $this->_responseSegment;
}
/**
* Set the noController flag (i.e., whether or not to render into controller subdirectories)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNoController($flag = true)
{
$this->_noController = ($flag) ? true : false;
return $this;
}
/**
* Retrieve noController flag value
*
* @return boolean
*/
public function getNoController()
{
return $this->_noController;
}
/**
* Set the neverController flag (i.e., whether or not to render into controller subdirectories)
*
* @param boolean $flag
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setNeverController($flag = true)
{
$this->_neverController = ($flag) ? true : false;
return $this;
}
/**
* Retrieve neverController flag value
*
* @return boolean
*/
public function getNeverController()
{
return $this->_neverController;
}
/**
* Set view script suffix
*
* @param string $suffix
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setViewSuffix($suffix)
{
$this->_viewSuffix = (string) $suffix;
return $this;
}
/**
* Get view script suffix
*
* @return string
*/
public function getViewSuffix()
{
return $this->_viewSuffix;
}
/**
* Set options for rendering a view script
*
* @param string $action View script to render
* @param string $name Response named segment to render to
* @param boolean $noController Whether or not to render within a subdirectory named after the controller
* @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
*/
public function setRender($action = null, $name = null, $noController = null)
{
if (null !== $action) {
$this->setScriptAction($action);
}
if (null !== $name) {
$this->setResponseSegment($name);
}
if (null !== $noController) {
$this->setNoController($noController);
}
return $this;
}
/**
* Inflect based on provided vars
*
* Allowed variables are:
* - :moduleDir - current module directory
* - :module - current module name
* - :controller - current controller name
* - :action - current action name
* - :suffix - view script file suffix
*
* @param array $vars
* @return string
*/
protected function _translateSpec(array $vars = array())
{
$inflector = $this->getInflector();
$request = $this->getRequest();
$dispatcher = $this->_frontController->getDispatcher();
$module = $dispatcher->formatModuleName($request->getModuleName());
$controller = $request->getControllerName();
$action = $dispatcher->formatActionName($request->getActionName());
$params = compact('module', 'controller', 'action');
foreach ($vars as $key => $value) {
switch ($key) {
case 'module':
case 'controller':
case 'action':
case 'moduleDir':
case 'suffix':
$params[$key] = (string) $value;
break;
default:
break;
}
}
if (isset($params['suffix'])) {
$origSuffix = $this->getViewSuffix();
$this->setViewSuffix($params['suffix']);
}
if (isset($params['moduleDir'])) {
$origModuleDir = $this->_getModuleDir();
$this->_setModuleDir($params['moduleDir']);
}
$filtered = $inflector->filter($params);
if (isset($params['suffix'])) {
$this->setViewSuffix($origSuffix);
}
if (isset($params['moduleDir'])) {
$this->_setModuleDir($origModuleDir);
}
return $filtered;
}
/**
* Render a view script (optionally to a named response segment)
*
* Sets the noRender flag to true when called.
*
* @param string $script
* @param string $name
* @return void
*/
public function renderScript($script, $name = null)
{
if (null === $name) {
$name = $this->getResponseSegment();
}
$this->getResponse()->appendBody(
$this->view->render($script),
$name
);
$this->setNoRender();
}
/**
* Render a view based on path specifications
*
* Renders a view based on the view script path specifications.
*
* @param string $action
* @param string $name
* @param boolean $noController
* @return void
*/
public function render($action = null, $name = null, $noController = null)
{
$this->setRender($action, $name, $noController);
$path = $this->getViewScript();
$this->renderScript($path, $name);
}
/**
* Render a script based on specification variables
*
* Pass an action, and one or more specification variables (view script suffix)
* to determine the view script path, and render that script.
*
* @param string $action
* @param array $vars
* @param string $name
* @return void
*/
public function renderBySpec($action = null, array $vars = array(), $name = null)
{
if (null !== $name) {
$this->setResponseSegment($name);
}
$path = $this->getViewScript($action, $vars);
$this->renderScript($path);
}
/**
* postDispatch - auto render a view
*
* Only autorenders if:
* - _noRender is false
* - action controller is present
* - request has not been re-dispatched (i.e., _forward() has not been called)
* - response is not a redirect
*
* @return void
*/
public function postDispatch()
{
if ($this->_shouldRender()) {
$this->render();
}
}
/**
* Should the ViewRenderer render a view script?
*
* @return boolean
*/
protected function _shouldRender()
{
return (!$this->getFrontController()->getParam('noViewRenderer')
&& !$this->_neverRender
&& !$this->_noRender
&& (null !== $this->_actionController)
&& $this->getRequest()->isDispatched()
&& !$this->getResponse()->isRedirect()
);
}
/**
* Use this helper as a method; proxies to setRender()
*
* @param string $action
* @param string $name
* @param boolean $noController
* @return void
*/
public function direct($action = null, $name = null, $noController = null)
{
$this->setRender($action, $name, $noController);
}
}
Controller/Action/Helper/Json.php 0000604 00000006664 15071256136 0012763 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: Json.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Controller_Action_Helper_Abstract
*/
require_once 'Zend/Controller/Action/Helper/Abstract.php';
/**
* Simplify AJAX context switching based on requested format
*
* @uses Zend_Controller_Action_Helper_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_Json extends Zend_Controller_Action_Helper_Abstract
{
/**
* Suppress exit when sendJson() called
* @var boolean
*/
public $suppressExit = false;
/**
* Create JSON response
*
* Encodes and returns data to JSON. Content-Type header set to
* 'application/json', and disables layouts and viewRenderer (if being
* used).
*
* @param mixed $data
* @param boolean $keepLayouts
* @throws Zend_Controller_Action_Helper_Json
* @return string
*/
public function encodeJson($data, $keepLayouts = false)
{
/**
* @see Zend_View_Helper_Json
*/
require_once 'Zend/View/Helper/Json.php';
$jsonHelper = new Zend_View_Helper_Json();
$data = $jsonHelper->json($data, $keepLayouts);
if (!$keepLayouts) {
/**
* @see Zend_Controller_Action_HelperBroker
*/
require_once 'Zend/Controller/Action/HelperBroker.php';
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
}
return $data;
}
/**
* Encode JSON response and immediately send
*
* @param mixed $data
* @param boolean $keepLayouts
* @return string|void
*/
public function sendJson($data, $keepLayouts = false)
{
$data = $this->encodeJson($data, $keepLayouts);
$response = $this->getResponse();
$response->setBody($data);
if (!$this->suppressExit) {
$response->sendResponse();
exit;
}
return $data;
}
/**
* Strategy pattern: call helper as helper broker method
*
* Allows encoding JSON. If $sendNow is true, immediately sends JSON
* response.
*
* @param mixed $data
* @param boolean $sendNow
* @param boolean $keepLayouts
* @return string|void
*/
public function direct($data, $sendNow = true, $keepLayouts = false)
{
if ($sendNow) {
return $this->sendJson($data, $keepLayouts);
}
return $this->encodeJson($data, $keepLayouts);
}
}
Controller/Action/Helper/AutoCompleteDojo.php 0000604 00000005405 15071256136 0015257 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: AutoCompleteDojo.php 12301 2008-11-05 16:04:12Z matthew $
*/
/**
* @see Zend_Controller_Action_Helper_AutoComplete_Abstract
*/
require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
/**
* Create and send Dojo-compatible autocompletion lists
*
* @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract
{
/**
* Validate data for autocompletion
*
* Stub; unused
*
* @param mixed $data
* @return boolean
*/
public function validateData($data)
{
return true;
}
/**
* Prepare data for autocompletion
*
* @param mixed $data
* @param boolean $keepLayouts
* @return string
*/
public function prepareAutoCompletion($data, $keepLayouts = false)
{
if (!$data instanceof Zend_Dojo_Data) {
require_once 'Zend/Dojo/Data.php';
$items = array();
foreach ($data as $key => $value) {
$items[] = array('label' => $value, 'name' => $value);
}
$data = new Zend_Dojo_Data('name', $items);
}
if (!$keepLayouts) {
require_once 'Zend/Controller/Action/HelperBroker.php';
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
require_once 'Zend/Layout.php';
$layout = Zend_Layout::getMvcInstance();
if ($layout instanceof Zend_Layout) {
$layout->disableLayout();
}
}
$response = Zend_Controller_Front::getInstance()->getResponse();
$response->setHeader('Content-Type', 'application/json');
return $data->toJson();
}
}
Controller/Action/Helper/AutoCompleteScriptaculous.php 0000604 00000004766 15071256136 0017235 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action_Helper
* @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: AutoCompleteScriptaculous.php 9098 2008-03-30 19:29:10Z thomas $
*/
/**
* @see Zend_Controller_Action_Helper_AutoComplete_Abstract
*/
require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
/**
* Create and send Scriptaculous-compatible autocompletion lists
*
* @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action_Helper
* @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_Controller_Action_Helper_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
{
/**
* Validate data for autocompletion
*
* @param mixed $data
* @return bool
*/
public function validateData($data)
{
if (!is_array($data) && !is_scalar($data)) {
return false;
}
return true;
}
/**
* Prepare data for autocompletion
*
* @param mixed $data
* @param boolean $keepLayouts
* @throws Zend_Controller_Action_Exception
* @return string
*/
public function prepareAutoCompletion($data, $keepLayouts = false)
{
if (!$this->validateData($data)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
}
$data = (array) $data;
$data = '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
if (!$keepLayouts) {
$this->disableLayouts();
}
return $data;
}
}
Controller/Action/Exception.php 0000604 00000002177 15071256136 0012564 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action
* @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 Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action
* @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_Controller_Action_Exception extends Zend_Controller_Exception
{}
Controller/Action/HelperBroker/PriorityStack.php 0000604 00000020750 15071256136 0016016 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action
* @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_Controller_Action_HelperBroker_PriorityStack implements IteratorAggregate, ArrayAccess, Countable
{
/** @protected */
protected $_helpersByPriority = array();
protected $_helpersByNameRef = array();
protected $_nextDefaultPriority = 1;
/**
* Magic property overloading for returning helper by name
*
* @param string $helperName The helper name
* @return Zend_Controller_Action_Helper_Abstract
*/
public function __get($helperName)
{
if (!array_key_exists($helperName, $this->_helpersByNameRef)) {
return false;
}
return $this->_helpersByNameRef[$helperName];
}
/**
* Magic property overloading for returning if helper is set by name
*
* @param string $helperName The helper name
* @return Zend_Controller_Action_Helper_Abstract
*/
public function __isset($helperName)
{
return array_key_exists($helperName, $this->_helpersByNameRef);
}
/**
* Magic property overloading for unsetting if helper is exists by name
*
* @param string $helperName The helper name
* @return Zend_Controller_Action_Helper_Abstract
*/
public function __unset($helperName)
{
return $this->offsetUnset($helperName);
}
/**
* push helper onto the stack
*
* @param Zend_Controller_Action_Helper_Abstract $helper
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public function push(Zend_Controller_Action_Helper_Abstract $helper)
{
$this->offsetSet($this->getNextFreeHigherPriority(), $helper);
return $this;
}
/**
* Return something iterable
*
* @return array
*/
public function getIterator()
{
return new ArrayObject($this->_helpersByPriority);
}
/**
* offsetExists()
*
* @param int|string $priorityOrHelperName
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public function offsetExists($priorityOrHelperName)
{
if (is_string($priorityOrHelperName)) {
return array_key_exists($priorityOrHelperName, $this->_helpersByNameRef);
} else {
return array_key_exists($priorityOrHelperName, $this->_helpersByPriority);
}
}
/**
* offsetGet()
*
* @param int|string $priorityOrHelperName
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public function offsetGet($priorityOrHelperName)
{
if (!$this->offsetExists($priorityOrHelperName)) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('A helper with priority ' . $priority . ' does not exist.');
}
if (is_string($priorityOrHelperName)) {
return $this->_helpersByNameRef[$priorityOrHelperName];
} else {
return $this->_helpersByPriority[$priorityOrHelperName];
}
}
/**
* offsetSet()
*
* @param int $priority
* @param Zend_Controller_Action_Helper_Abstract $helper
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public function offsetSet($priority, $helper)
{
$priority = (int) $priority;
if (!$helper instanceof Zend_Controller_Action_Helper_Abstract) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('$helper must extend Zend_Controller_Action_Helper_Abstract.');
}
if (array_key_exists($helper->getName(), $this->_helpersByNameRef)) {
// remove any object with the same name to retain BC compailitbility
// @todo At ZF 2.0 time throw an exception here.
$this->offsetUnset($helper->getName());
}
if (array_key_exists($priority, $this->_helpersByPriority)) {
$priority = $this->getNextFreeHigherPriority($priority); // ensures LIFO
trigger_error("A helper with the same priority already exists, reassigning to $priority", E_USER_WARNING);
}
$this->_helpersByPriority[$priority] = $helper;
$this->_helpersByNameRef[$helper->getName()] = $helper;
if ($priority == ($nextFreeDefault = $this->getNextFreeHigherPriority($this->_nextDefaultPriority))) {
$this->_nextDefaultPriority = $nextFreeDefault;
}
krsort($this->_helpersByPriority); // always make sure priority and LIFO are both enforced
return $this;
}
/**
* offsetUnset()
*
* @param int|string $priorityOrHelperName Priority integer or the helper name
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public function offsetUnset($priorityOrHelperName)
{
if (!$this->offsetExists($priorityOrHelperName)) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('A helper with priority or name ' . $priorityOrHelperName . ' does not exist.');
}
if (is_string($priorityOrHelperName)) {
$helperName = $priorityOrHelperName;
$helper = $this->_helpersByNameRef[$helperName];
$priority = array_search($helper, $this->_helpersByPriority, true);
} else {
$priority = $priorityOrHelperName;
$helperName = $this->_helpersByPriority[$priorityOrHelperName]->getName();
}
unset($this->_helpersByNameRef[$helperName]);
unset($this->_helpersByPriority[$priority]);
return $this;
}
/**
* return the count of helpers
*
* @return int
*/
public function count()
{
return count($this->_helpersByPriority);
}
/**
* Find the next free higher priority. If an index is given, it will
* find the next free highest priority after it.
*
* @param int $indexPriority OPTIONAL
* @return int
*/
public function getNextFreeHigherPriority($indexPriority = null)
{
if ($indexPriority == null) {
$indexPriority = $this->_nextDefaultPriority;
}
$priorities = array_keys($this->_helpersByPriority);
while (in_array($indexPriority, $priorities)) {
$indexPriority++;
}
return $indexPriority;
}
/**
* Find the next free lower priority. If an index is given, it will
* find the next free lower priority before it.
*
* @param int $indexPriority
* @return int
*/
public function getNextFreeLowerPriority($indexPriority = null)
{
if ($indexPriority == null) {
$indexPriority = $this->_nextDefaultPriority;
}
$priorities = array_keys($this->_helpersByPriority);
while (in_array($indexPriority, $priorities)) {
$indexPriority--;
}
return $indexPriority;
}
/**
* return the highest priority
*
* @return int
*/
public function getHighestPriority()
{
return max(array_keys($this->_helpersByPriority));
}
/**
* return the lowest priority
*
* @return int
*/
public function getLowestPriority()
{
return min(array_keys($this->_helpersByPriority));
}
/**
* return the helpers referenced by name
*
* @return array
*/
public function getHelpersByName()
{
return $this->_helpersByNameRef;
}
}
Controller/Action/HelperBroker.php 0000604 00000024504 15071256136 0013210 0 ustar 00 <?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_Controller
* @subpackage Zend_Controller_Action
* @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 Zend_Controller_Action_HelperBroker_PriorityStack
*/
require_once 'Zend/Controller/Action/HelperBroker/PriorityStack.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Zend_Controller_Action
* @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_Controller_Action_HelperBroker
{
/**
* $_actionController - ActionController reference
*
* @var Zend_Controller_Action
*/
protected $_actionController;
/**
* @var Zend_Loader_PluginLoader_Interface
*/
protected static $_pluginLoader;
/**
* $_helpers - Helper array
*
* @var Zend_Controller_Action_HelperBroker_PriorityStack
*/
protected static $_stack = null;
/**
* Set PluginLoader for use with broker
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @return void
*/
public static function setPluginLoader($loader)
{
if ((null !== $loader) && (!$loader instanceof Zend_Loader_PluginLoader_Interface)) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid plugin loader provided to HelperBroker');
}
self::$_pluginLoader = $loader;
}
/**
* Retrieve PluginLoader
*
* @return Zend_Loader_PluginLoader
*/
public static function getPluginLoader()
{
if (null === self::$_pluginLoader) {
require_once 'Zend/Loader/PluginLoader.php';
self::$_pluginLoader = new Zend_Loader_PluginLoader(array(
'Zend_Controller_Action_Helper' => 'Zend/Controller/Action/Helper/',
));
}
return self::$_pluginLoader;
}
/**
* addPrefix() - Add repository of helpers by prefix
*
* @param string $prefix
*/
static public function addPrefix($prefix)
{
$prefix = rtrim($prefix, '_');
$path = str_replace('_', DIRECTORY_SEPARATOR, $prefix);
self::getPluginLoader()->addPrefixPath($prefix, $path);
}
/**
* addPath() - Add path to repositories where Action_Helpers could be found.
*
* @param string $path
* @param string $prefix Optional; defaults to 'Zend_Controller_Action_Helper'
* @return void
*/
static public function addPath($path, $prefix = 'Zend_Controller_Action_Helper')
{
self::getPluginLoader()->addPrefixPath($prefix, $path);
}
/**
* addHelper() - Add helper objects
*
* @param Zend_Controller_Action_Helper_Abstract $helper
* @return void
*/
static public function addHelper(Zend_Controller_Action_Helper_Abstract $helper)
{
self::getStack()->push($helper);
return;
}
/**
* resetHelpers()
*
* @return void
*/
static public function resetHelpers()
{
self::$_stack = null;
return;
}
/**
* Retrieve or initialize a helper statically
*
* Retrieves a helper object statically, loading on-demand if the helper
* does not already exist in the stack. Always returns a helper, unless
* the helper class cannot be found.
*
* @param string $name
* @return Zend_Controller_Action_Helper_Abstract
*/
public static function getStaticHelper($name)
{
$name = self::_normalizeHelperName($name);
$stack = self::getStack();
if (!isset($stack->{$name})) {
self::_loadHelper($name);
}
return $stack->{$name};
}
/**
* getExistingHelper() - get helper by name
*
* Static method to retrieve helper object. Only retrieves helpers already
* initialized with the broker (either via addHelper() or on-demand loading
* via getHelper()).
*
* Throws an exception if the referenced helper does not exist in the
* stack; use {@link hasHelper()} to check if the helper is registered
* prior to retrieving it.
*
* @param string $name
* @return Zend_Controller_Action_Helper_Abstract
* @throws Zend_Controller_Action_Exception
*/
public static function getExistingHelper($name)
{
$name = self::_normalizeHelperName($name);
$stack = self::getStack();
if (!isset($stack->{$name})) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Action helper "' . $name . '" has not been registered with the helper broker');
}
return $stack->{$name};
}
/**
* Return all registered helpers as helper => object pairs
*
* @return array
*/
public static function getExistingHelpers()
{
return self::getStack()->getHelpersByName();
}
/**
* Is a particular helper loaded in the broker?
*
* @param string $name
* @return boolean
*/
public static function hasHelper($name)
{
$name = self::_normalizeHelperName($name);
return isset(self::getStack()->{$name});
}
/**
* Remove a particular helper from the broker
*
* @param string $name
* @return boolean
*/
public static function removeHelper($name)
{
$name = self::_normalizeHelperName($name);
$stack = self::getStack();
if (isset($stack->{$name})) {
unset($stack->{$name});
}
return false;
}
/**
* Lazy load the priority stack and return it
*
* @return Zend_Controller_Action_HelperBroker_PriorityStack
*/
public static function getStack()
{
if (self::$_stack == null) {
self::$_stack = new Zend_Controller_Action_HelperBroker_PriorityStack();
}
return self::$_stack;
}
/**
* Constructor
*
* @param Zend_Controller_Action $actionController
* @return void
*/
public function __construct(Zend_Controller_Action $actionController)
{
$this->_actionController = $actionController;
foreach (self::getStack() as $helper) {
$helper->setActionController($actionController);
$helper->init();
}
}
/**
* notifyPreDispatch() - called by action controller dispatch method
*
* @return void
*/
public function notifyPreDispatch()
{
foreach (self::getStack() as $helper) {
$helper->preDispatch();
}
}
/**
* notifyPostDispatch() - called by action controller dispatch method
*
* @return void
*/
public function notifyPostDispatch()
{
foreach (self::getStack() as $helper) {
$helper->postDispatch();
}
}
/**
* getHelper() - get helper by name
*
* @param string $name
* @return Zend_Controller_Action_Helper_Abstract
*/
public function getHelper($name)
{
$name = self::_normalizeHelperName($name);
$stack = self::getStack();
if (!isset($stack->{$name})) {
self::_loadHelper($name);
}
$helper = $stack->{$name};
$initialize = false;
if (null === ($actionController = $helper->getActionController())) {
$initialize = true;
} elseif ($actionController !== $this->_actionController) {
$initialize = true;
}
if ($initialize) {
$helper->setActionController($this->_actionController)
->init();
}
return $helper;
}
/**
* Method overloading
*
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Controller_Action_Exception if helper does not have a direct() method
*/
public function __call($method, $args)
{
$helper = $this->getHelper($method);
if (!method_exists($helper, 'direct')) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Helper "' . $method . '" does not support overloading via direct()');
}
return call_user_func_array(array($helper, 'direct'), $args);
}
/**
* Retrieve helper by name as object property
*
* @param string $name
* @return Zend_Controller_Action_Helper_Abstract
*/
public function __get($name)
{
return $this->getHelper($name);
}
/**
* Normalize helper name for lookups
*
* @param string $name
* @return string
*/
protected static function _normalizeHelperName($name)
{
if (strpos($name, '_') !== false) {
$name = str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
}
return ucfirst($name);
}
/**
* Load a helper
*
* @param string $name
* @return void
*/
protected static function _loadHelper($name)
{
try {
$class = self::getPluginLoader()->load($name);
} catch (Zend_Loader_PluginLoader_Exception $e) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Action Helper by name ' . $name . ' not found');
}
$helper = new $class();
if (!$helper instanceof Zend_Controller_Action_Helper_Abstract) {
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('Helper name ' . $name . ' -> class ' . $class . ' is not of type Zend_Controller_Action_Helper_Abstract');
}
self::getStack()->push($helper);
}
}
Controller/Plugin/ActionStack.php 0000604 00000014235 15071256136 0013050 0 ustar 00 <?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_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';
/** Zend_Registry */
require_once 'Zend/Registry.php';
/**
* Manage a stack of actions
*
* @uses Zend_Controller_Plugin_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Plugins
* @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: ActionStack.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Controller_Plugin_ActionStack extends Zend_Controller_Plugin_Abstract
{
/** @var Zend_Registry */
protected $_registry;
/**
* Registry key under which actions are stored
* @var string
*/
protected $_registryKey = 'Zend_Controller_Plugin_ActionStack';
/**
* Valid keys for stack items
* @var array
*/
protected $_validKeys = array(
'module',
'controller',
'action',
'params'
);
/**
* Constructor
*
* @param Zend_Registry $registry
* @param string $key
* @return void
*/
public function __construct(Zend_Registry $registry = null, $key = null)
{
if (null === $registry) {
$registry = Zend_Registry::getInstance();
}
$this->setRegistry($registry);
if (null !== $key) {
$this->setRegistryKey($key);
} else {
$key = $this->getRegistryKey();
}
$registry[$key] = array();
}
/**
* Set registry object
*
* @param Zend_Registry $registry
* @return Zend_Controller_Plugin_ActionStack
*/
public function setRegistry(Zend_Registry $registry)
{
$this->_registry = $registry;
return $this;
}
/**
* Retrieve registry object
*
* @return Zend_Registry
*/
public function getRegistry()
{
return $this->_registry;
}
/**
* Retrieve registry key
*
* @return string
*/
public function getRegistryKey()
{
return $this->_registryKey;
}
/**
* Set registry key
*
* @param string $key
* @return Zend_Controller_Plugin_ActionStack
*/
public function setRegistryKey($key)
{
$this->_registryKey = (string) $key;
return $this;
}
/**
* Retrieve action stack
*
* @return array
*/
public function getStack()
{
$registry = $this->getRegistry();
$stack = $registry[$this->getRegistryKey()];
return $stack;
}
/**
* Save stack to registry
*
* @param array $stack
* @return Zend_Controller_Plugin_ActionStack
*/
protected function _saveStack(array $stack)
{
$registry = $this->getRegistry();
$registry[$this->getRegistryKey()] = $stack;
return $this;
}
/**
* Push an item onto the stack
*
* @param Zend_Controller_Request_Abstract $next
* @return Zend_Controller_Plugin_ActionStack
*/
public function pushStack(Zend_Controller_Request_Abstract $next)
{
$stack = $this->getStack();
array_push($stack, $next);
return $this->_saveStack($stack);
}
/**
* Pop an item off the action stack
*
* @return false|Zend_Controller_Request_Abstract
*/
public function popStack()
{
$stack = $this->getStack();
if (0 == count($stack)) {
return false;
}
$next = array_pop($stack);
$this->_saveStack($stack);
if (!$next instanceof Zend_Controller_Request_Abstract) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('ArrayStack should only contain request objects');
}
$action = $next->getActionName();
if (empty($action)) {
return $this->popStack($stack);
}
$request = $this->getRequest();
$controller = $next->getControllerName();
if (empty($controller)) {
$next->setControllerName($request->getControllerName());
}
$module = $next->getModuleName();
if (empty($module)) {
$next->setModuleName($request->getModuleName());
}
return $next;
}
/**
* postDispatch() plugin hook -- check for actions in stack, and dispatch if any found
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
// Don't move on to next request if this is already an attempt to
// forward
if (!$request->isDispatched()) {
return;
}
$this->setRequest($request);
$stack = $this->getStack();
if (empty($stack)) {
return;
}
$next = $this->popStack();
if (!$next) {
return;
}
$this->forward($next);
}
/**
* Forward request with next action
*
* @param array $next
* @return void
*/
public function forward(Zend_Controller_Request_Abstract $next)
{
$this->getRequest()->setModuleName($next->getModuleName())
->setControllerName($next->getControllerName())
->setActionName($next->getActionName())
->setParams($next->getParams())
->setDispatched(false);
}
}
Controller/Plugin/Broker.php 0000604 00000024144 15071256136 0012071 0 ustar 00 <?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_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';
/**
* @category Zend
* @package Zend_Controller
* @subpackage Plugins
* @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_Controller_Plugin_Broker extends Zend_Controller_Plugin_Abstract
{
/**
* Array of instance of objects extending Zend_Controller_Plugin_Abstract
*
* @var array
*/
protected $_plugins = array();
/**
* Register a plugin.
*
* @param Zend_Controller_Plugin_Abstract $plugin
* @param int $stackIndex
* @return Zend_Controller_Plugin_Broker
*/
public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null)
{
if (false !== array_search($plugin, $this->_plugins, true)) {
throw new Zend_Controller_Exception('Plugin already registered');
}
$stackIndex = (int) $stackIndex;
if ($stackIndex) {
if (isset($this->_plugins[$stackIndex])) {
throw new Zend_Controller_Exception('Plugin with stackIndex "' . $stackIndex . '" already registered');
}
$this->_plugins[$stackIndex] = $plugin;
} else {
$stackIndex = count($this->_plugins);
while (isset($this->_plugins[$stackIndex])) {
++$stackIndex;
}
$this->_plugins[$stackIndex] = $plugin;
}
$request = $this->getRequest();
if ($request) {
$this->_plugins[$stackIndex]->setRequest($request);
}
$response = $this->getResponse();
if ($response) {
$this->_plugins[$stackIndex]->setResponse($response);
}
ksort($this->_plugins);
return $this;
}
/**
* Unregister a plugin.
*
* @param string|Zend_Controller_Plugin_Abstract $plugin Plugin object or class name
* @return Zend_Controller_Plugin_Broker
*/
public function unregisterPlugin($plugin)
{
if ($plugin instanceof Zend_Controller_Plugin_Abstract) {
// Given a plugin object, find it in the array
$key = array_search($plugin, $this->_plugins, true);
if (false === $key) {
throw new Zend_Controller_Exception('Plugin never registered.');
}
unset($this->_plugins[$key]);
} elseif (is_string($plugin)) {
// Given a plugin class, find all plugins of that class and unset them
foreach ($this->_plugins as $key => $_plugin) {
$type = get_class($_plugin);
if ($plugin == $type) {
unset($this->_plugins[$key]);
}
}
}
return $this;
}
/**
* Is a plugin of a particular class registered?
*
* @param string $class
* @return bool
*/
public function hasPlugin($class)
{
foreach ($this->_plugins as $plugin) {
$type = get_class($plugin);
if ($class == $type) {
return true;
}
}
return false;
}
/**
* Retrieve a plugin or plugins by class
*
* @param string $class Class name of plugin(s) desired
* @return false|Zend_Controller_Plugin_Abstract|array Returns false if none found, plugin if only one found, and array of plugins if multiple plugins of same class found
*/
public function getPlugin($class)
{
$found = array();
foreach ($this->_plugins as $plugin) {
$type = get_class($plugin);
if ($class == $type) {
$found[] = $plugin;
}
}
switch (count($found)) {
case 0:
return false;
case 1:
return $found[0];
default:
return $found;
}
}
/**
* Retrieve all plugins
*
* @return array
*/
public function getPlugins()
{
return $this->_plugins;
}
/**
* Set request object, and register with each plugin
*
* @param Zend_Controller_Request_Abstract $request
* @return Zend_Controller_Plugin_Broker
*/
public function setRequest(Zend_Controller_Request_Abstract $request)
{
$this->_request = $request;
foreach ($this->_plugins as $plugin) {
$plugin->setRequest($request);
}
return $this;
}
/**
* Get request object
*
* @return Zend_Controller_Request_Abstract $request
*/
public function getRequest()
{
return $this->_request;
}
/**
* Set response object
*
* @param Zend_Controller_Response_Abstract $response
* @return Zend_Controller_Plugin_Broker
*/
public function setResponse(Zend_Controller_Response_Abstract $response)
{
$this->_response = $response;
foreach ($this->_plugins as $plugin) {
$plugin->setResponse($response);
}
return $this;
}
/**
* Get response object
*
* @return Zend_Controller_Response_Abstract $response
*/
public function getResponse()
{
return $this->_response;
}
/**
* Called before Zend_Controller_Front begins evaluating the
* request against its routes.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->routeStartup($request);
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
/**
* Called before Zend_Controller_Front exits its iterations over
* the route set.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->routeShutdown($request);
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
/**
* Called before Zend_Controller_Front enters its dispatch loop.
*
* During the dispatch loop, Zend_Controller_Front keeps a
* Zend_Controller_Request_Abstract object, and uses
* Zend_Controller_Dispatcher to dispatch the
* Zend_Controller_Request_Abstract object to controllers/actions.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->dispatchLoopStartup($request);
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
/**
* Called before an action is dispatched by Zend_Controller_Dispatcher.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->preDispatch($request);
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
/**
* Called after an action is dispatched by Zend_Controller_Dispatcher.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->postDispatch($request);
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
/**
* Called before Zend_Controller_Front exits its dispatch loop.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopShutdown()
{
foreach ($this->_plugins as $plugin) {
try {
$plugin->dispatchLoopShutdown();
} catch (Exception $e) {
if (Zend_Controller_Front::getInstance()->throwExceptions()) {
throw $e;
} else {
$this->getResponse()->setException($e);
}
}
}
}
}
Controller/Plugin/Abstract.php 0000604 00000010204 15071256136 0012400 0 ustar 00 <?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_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Plugin_Abstract
{
/**
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* @var Zend_Controller_Response_Abstract
*/
protected $_response;
/**
* Set request object
*
* @param Zend_Controller_Request_Abstract $request
* @return Zend_Controller_Plugin_Abstract
*/
public function setRequest(Zend_Controller_Request_Abstract $request)
{
$this->_request = $request;
return $this;
}
/**
* Get request object
*
* @return Zend_Controller_Request_Abstract $request
*/
public function getRequest()
{
return $this->_request;
}
/**
* Set response object
*
* @param Zend_Controller_Response_Abstract $response
* @return Zend_Controller_Plugin_Abstract
*/
public function setResponse(Zend_Controller_Response_Abstract $response)
{
$this->_response = $response;
return $this;
}
/**
* Get response object
*
* @return Zend_Controller_Response_Abstract $response
*/
public function getResponse()
{
return $this->_response;
}
/**
* Called before Zend_Controller_Front begins evaluating the
* request against its routes.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function routeStartup(Zend_Controller_Request_Abstract $request)
{}
/**
* Called after Zend_Controller_Router exits.
*
* Called after Zend_Controller_Front exits from the router.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{}
/**
* Called before Zend_Controller_Front enters its dispatch loop.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{}
/**
* Called before an action is dispatched by Zend_Controller_Dispatcher.
*
* This callback allows for proxy or filter behavior. By altering the
* request and resetting its dispatched flag (via
* {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
* the current action may be skipped.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{}
/**
* Called after an action is dispatched by Zend_Controller_Dispatcher.
*
* This callback allows for proxy or filter behavior. By altering the
* request and resetting its dispatched flag (via
* {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
* a new action may be specified for dispatching.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{}
/**
* Called before Zend_Controller_Front exits its dispatch loop.
*
* @return void
*/
public function dispatchLoopShutdown()
{}
}
Controller/Plugin/ErrorHandler.php 0000604 00000017227 15071256136 0013240 0 ustar 00 <?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_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';
/**
* Handle exceptions that bubble up based on missing controllers, actions, or
* application errors, and forward to an error handler.
*
* @uses Zend_Controller_Plugin_Abstract
* @category Zend
* @package Zend_Controller
* @subpackage Plugins
* @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: ErrorHandler.php 8064 2008-02-16 10:58:39Z thomas $
*/
class Zend_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_Abstract
{
/**
* Const - No controller exception; controller does not exist
*/
const EXCEPTION_NO_CONTROLLER = 'EXCEPTION_NO_CONTROLLER';
/**
* Const - No action exception; controller exists, but action does not
*/
const EXCEPTION_NO_ACTION = 'EXCEPTION_NO_ACTION';
/**
* Const - Other Exception; exceptions thrown by application controllers
*/
const EXCEPTION_OTHER = 'EXCEPTION_OTHER';
/**
* Module to use for errors; defaults to default module in dispatcher
* @var string
*/
protected $_errorModule;
/**
* Controller to use for errors; defaults to 'error'
* @var string
*/
protected $_errorController = 'error';
/**
* Action to use for errors; defaults to 'error'
* @var string
*/
protected $_errorAction = 'error';
/**
* Flag; are we already inside the error handler loop?
* @var bool
*/
protected $_isInsideErrorHandlerLoop = false;
/**
* Exception count logged at first invocation of plugin
* @var int
*/
protected $_exceptionCountAtFirstEncounter = 0;
/**
* Constructor
*
* Options may include:
* - module
* - controller
* - action
*
* @param Array $options
* @return void
*/
public function __construct(Array $options = array())
{
$this->setErrorHandler($options);
}
/**
* setErrorHandler() - setup the error handling options
*
* @param array $options
* @return Zend_Controller_Plugin_ErrorHandler
*/
public function setErrorHandler(Array $options = array())
{
if (isset($options['module'])) {
$this->setErrorHandlerModule($options['module']);
}
if (isset($options['controller'])) {
$this->setErrorHandlerController($options['controller']);
}
if (isset($options['action'])) {
$this->setErrorHandlerAction($options['action']);
}
return $this;
}
/**
* Set the module name for the error handler
*
* @param string $module
* @return Zend_Controller_Plugin_ErrorHandler
*/
public function setErrorHandlerModule($module)
{
$this->_errorModule = (string) $module;
return $this;
}
/**
* Retrieve the current error handler module
*
* @return string
*/
public function getErrorHandlerModule()
{
if (null === $this->_errorModule) {
$this->_errorModule = Zend_Controller_Front::getInstance()->getDispatcher()->getDefaultModule();
}
return $this->_errorModule;
}
/**
* Set the controller name for the error handler
*
* @param string $controller
* @return Zend_Controller_Plugin_ErrorHandler
*/
public function setErrorHandlerController($controller)
{
$this->_errorController = (string) $controller;
return $this;
}
/**
* Retrieve the current error handler controller
*
* @return string
*/
public function getErrorHandlerController()
{
return $this->_errorController;
}
/**
* Set the action name for the error handler
*
* @param string $action
* @return Zend_Controller_Plugin_ErrorHandler
*/
public function setErrorHandlerAction($action)
{
$this->_errorAction = (string) $action;
return $this;
}
/**
* Retrieve the current error handler action
*
* @return string
*/
public function getErrorHandlerAction()
{
return $this->_errorAction;
}
/**
* postDispatch() plugin hook -- check for exceptions and dispatch error
* handler if necessary
*
* If the 'noErrorHandler' front controller flag has been set,
* returns early.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$frontController = Zend_Controller_Front::getInstance();
if ($frontController->getParam('noErrorHandler')) {
return;
}
$response = $this->getResponse();
if ($this->_isInsideErrorHandlerLoop) {
$exceptions = $response->getException();
if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
// Exception thrown by error handler; tell the front controller to throw it
$frontController->throwExceptions(true);
throw array_pop($exceptions);
}
}
// check for an exception AND allow the error handler controller the option to forward
if (($response->isException()) && (!$this->_isInsideErrorHandlerLoop)) {
$this->_isInsideErrorHandlerLoop = true;
// Get exception information
$error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$exceptions = $response->getException();
$exception = $exceptions[0];
$exceptionType = get_class($exception);
$error->exception = $exception;
switch ($exceptionType) {
case 'Zend_Controller_Dispatcher_Exception':
$error->type = self::EXCEPTION_NO_CONTROLLER;
break;
case 'Zend_Controller_Action_Exception':
if (404 == $exception->getCode()) {
$error->type = self::EXCEPTION_NO_ACTION;
} else {
$error->type = self::EXCEPTION_OTHER;
}
break;
default:
$error->type = self::EXCEPTION_OTHER;
break;
}
// Keep a copy of the original request
$error->request = clone $request;
// get a count of the number of exceptions encountered
$this->_exceptionCountAtFirstEncounter = count($exceptions);
// Forward to the error handler
$request->setParam('error_handler', $error)
->setModuleName($this->getErrorHandlerModule())
->setControllerName($this->getErrorHandlerController())
->setActionName($this->getErrorHandlerAction())
->setDispatched(false);
}
}
}
Controller/Action.php 0000604 00000051771 15071256136 0010632 0 ustar 00 <?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_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Action_HelperBroker */
require_once 'Zend/Controller/Action/HelperBroker.php';
/** Zend_Controller_Front */
require_once 'Zend/Controller/Front.php';
/**
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Controller_Action
{
/**
* @var array of existing class methods
*/
protected $_classMethods;
/**
* Word delimiters (used for normalizing view script paths)
* @var array
*/
protected $_delimiters;
/**
* Array of arguments provided to the constructor, minus the
* {@link $_request Request object}.
* @var array
*/
protected $_invokeArgs = array();
/**
* Front controller instance
* @var Zend_Controller_Front
*/
protected $_frontController;
/**
* Zend_Controller_Request_Abstract object wrapping the request environment
* @var Zend_Controller_Request_Abstract
*/
protected $_request = null;
/**
* Zend_Controller_Response_Abstract object wrapping the response
* @var Zend_Controller_Response_Abstract
*/
protected $_response = null;
/**
* View script suffix; defaults to 'phtml'
* @see {render()}
* @var string
*/
public $viewSuffix = 'phtml';
/**
* View object
* @var Zend_View_Interface
*/
public $view;
/**
* Helper Broker to assist in routing help requests to the proper object
*
* @var Zend_Controller_Action_HelperBroker
*/
protected $_helper = null;
/**
* Class constructor
*
* The request and response objects should be registered with the
* controller, as should be any additional optional arguments; these will be
* available via {@link getRequest()}, {@link getResponse()}, and
* {@link getInvokeArgs()}, respectively.
*
* When overriding the constructor, please consider this usage as a best
* practice and ensure that each is registered appropriately; the easiest
* way to do so is to simply call parent::__construct($request, $response,
* $invokeArgs).
*
* After the request, response, and invokeArgs are set, the
* {@link $_helper helper broker} is initialized.
*
* Finally, {@link init()} is called as the final action of
* instantiation, and may be safely overridden to perform initialization
* tasks; as a general rule, override {@link init()} instead of the
* constructor to customize an action controller's instantiation.
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @param array $invokeArgs Any additional invocation arguments
* @return void
*/
public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
{
$this->setRequest($request)
->setResponse($response)
->_setInvokeArgs($invokeArgs);
$this->_helper = new Zend_Controller_Action_HelperBroker($this);
$this->init();
}
/**
* Initialize object
*
* Called from {@link __construct()} as final step of object instantiation.
*
* @return void
*/
public function init()
{
}
/**
* Initialize View object
*
* Initializes {@link $view} if not otherwise a Zend_View_Interface.
*
* If {@link $view} is not otherwise set, instantiates a new Zend_View
* object, using the 'views' subdirectory at the same level as the
* controller directory for the current module as the base directory.
* It uses this to set the following:
* - script path = views/scripts/
* - helper path = views/helpers/
* - filter path = views/filters/
*
* @return Zend_View_Interface
* @throws Zend_Controller_Exception if base view directory does not exist
*/
public function initView()
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->view;
}
require_once 'Zend/View/Interface.php';
if (isset($this->view) && ($this->view instanceof Zend_View_Interface)) {
return $this->view;
}
$request = $this->getRequest();
$module = $request->getModuleName();
$dirs = $this->getFrontController()->getControllerDirectory();
if (empty($module) || !isset($dirs[$module])) {
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
}
$baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views';
if (!file_exists($baseDir) || !is_dir($baseDir)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Missing base view directory ("' . $baseDir . '")');
}
require_once 'Zend/View.php';
$this->view = new Zend_View(array('basePath' => $baseDir));
return $this->view;
}
/**
* Render a view
*
* Renders a view. By default, views are found in the view script path as
* <controller>/<action>.phtml. You may change the script suffix by
* resetting {@link $viewSuffix}. You may omit the controller directory
* prefix by specifying boolean true for $noController.
*
* By default, the rendered contents are appended to the response. You may
* specify the named body content segment to set by specifying a $name.
*
* @see Zend_Controller_Response_Abstract::appendBody()
* @param string|null $action Defaults to action registered in request object
* @param string|null $name Response object named path segment to use; defaults to null
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @return void
*/
public function render($action = null, $name = null, $noController = false)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->render($action, $name, $noController);
}
$view = $this->initView();
$script = $this->getViewScript($action, $noController);
$this->getResponse()->appendBody(
$view->render($script),
$name
);
}
/**
* Render a given view script
*
* Similar to {@link render()}, this method renders a view script. Unlike render(),
* however, it does not autodetermine the view script via {@link getViewScript()},
* but instead renders the script passed to it. Use this if you know the
* exact view script name and path you wish to use, or if using paths that do not
* conform to the spec defined with getViewScript().
*
* By default, the rendered contents are appended to the response. You may
* specify the named body content segment to set by specifying a $name.
*
* @param string $script
* @param string $name
* @return void
*/
public function renderScript($script, $name = null)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->renderScript($script, $name);
}
$view = $this->initView();
$this->getResponse()->appendBody(
$view->render($script),
$name
);
}
/**
* Construct view script path
*
* Used by render() to determine the path to the view script.
*
* @param string $action Defaults to action registered in request object
* @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script
* @return string
* @throws Zend_Controller_Exception with bad $action
*/
public function getViewScript($action = null, $noController = null)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
$viewRenderer = $this->_helper->getHelper('viewRenderer');
if (null !== $noController) {
$viewRenderer->setNoController($noController);
}
return $viewRenderer->getViewScript($action);
}
$request = $this->getRequest();
if (null === $action) {
$action = $request->getActionName();
} elseif (!is_string($action)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid action specifier for view render');
}
if (null === $this->_delimiters) {
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
$wordDelimiters = $dispatcher->getWordDelimiter();
$pathDelimiters = $dispatcher->getPathDelimiter();
$this->_delimiters = array_unique(array_merge($wordDelimiters, (array) $pathDelimiters));
}
$action = str_replace($this->_delimiters, '-', $action);
$script = $action . '.' . $this->viewSuffix;
if (!$noController) {
$controller = $request->getControllerName();
$controller = str_replace($this->_delimiters, '-', $controller);
$script = $controller . DIRECTORY_SEPARATOR . $script;
}
return $script;
}
/**
* Return the Request object
*
* @return Zend_Controller_Request_Abstract
*/
public function getRequest()
{
return $this->_request;
}
/**
* Set the Request object
*
* @param Zend_Controller_Request_Abstract $request
* @return Zend_Controller_Action
*/
public function setRequest(Zend_Controller_Request_Abstract $request)
{
$this->_request = $request;
return $this;
}
/**
* Return the Response object
*
* @return Zend_Controller_Response_Abstract
*/
public function getResponse()
{
return $this->_response;
}
/**
* Set the Response object
*
* @param Zend_Controller_Response_Abstract $response
* @return Zend_Controller_Action
*/
public function setResponse(Zend_Controller_Response_Abstract $response)
{
$this->_response = $response;
return $this;
}
/**
* Set invocation arguments
*
* @param array $args
* @return Zend_Controller_Action
*/
protected function _setInvokeArgs(array $args = array())
{
$this->_invokeArgs = $args;
return $this;
}
/**
* Return the array of constructor arguments (minus the Request object)
*
* @return array
*/
public function getInvokeArgs()
{
return $this->_invokeArgs;
}
/**
* Return a single invocation argument
*
* @param string $key
* @return mixed
*/
public function getInvokeArg($key)
{
if (isset($this->_invokeArgs[$key])) {
return $this->_invokeArgs[$key];
}
return null;
}
/**
* Get a helper by name
*
* @param string $helperName
* @return Zend_Controller_Action_Helper_Abstract
*/
public function getHelper($helperName)
{
return $this->_helper->{$helperName};
}
/**
* Get a clone of a helper by name
*
* @param string $helperName
* @return Zend_Controller_Action_Helper_Abstract
*/
public function getHelperCopy($helperName)
{
return clone $this->_helper->{$helperName};
}
/**
* Set the front controller instance
*
* @param Zend_Controller_Front $front
* @return Zend_Controller_Action
*/
public function setFrontController(Zend_Controller_Front $front)
{
$this->_frontController = $front;
return $this;
}
/**
* Retrieve Front Controller
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
// Used cache version if found
if (null !== $this->_frontController) {
return $this->_frontController;
}
// Grab singleton instance, if class has been loaded
if (class_exists('Zend_Controller_Front')) {
$this->_frontController = Zend_Controller_Front::getInstance();
return $this->_frontController;
}
// Throw exception in all other cases
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Front controller class has not been loaded');
}
/**
* Pre-dispatch routines
*
* Called before action method. If using class with
* {@link Zend_Controller_Front}, it may modify the
* {@link $_request Request object} and reset its dispatched flag in order
* to skip processing the current action.
*
* @return void
*/
public function preDispatch()
{
}
/**
* Post-dispatch routines
*
* Called after action method execution. If using class with
* {@link Zend_Controller_Front}, it may modify the
* {@link $_request Request object} and reset its dispatched flag in order
* to process an additional action.
*
* Common usages for postDispatch() include rendering content in a sitewide
* template, link url correction, setting headers, etc.
*
* @return void
*/
public function postDispatch()
{
}
/**
* Proxy for undefined methods. Default behavior is to throw an
* exception on undefined methods, however this function can be
* overridden to implement magic (dynamic) actions, or provide run-time
* dispatching.
*
* @param string $methodName
* @param array $args
* @return void
* @throws Zend_Controller_Action_Exception
*/
public function __call($methodName, $args)
{
require_once 'Zend/Controller/Action/Exception.php';
if ('Action' == substr($methodName, -6)) {
$action = substr($methodName, 0, strlen($methodName) - 6);
throw new Zend_Controller_Action_Exception(sprintf('Action "%s" does not exist and was not trapped in __call()', $action), 404);
}
throw new Zend_Controller_Action_Exception(sprintf('Method "%s" does not exist and was not trapped in __call()', $methodName), 500);
}
/**
* Dispatch the requested action
*
* @param string $action Method name of action
* @return void
*/
public function dispatch($action)
{
// Notify helpers of action preDispatch state
$this->_helper->notifyPreDispatch();
$this->preDispatch();
if ($this->getRequest()->isDispatched()) {
if (null === $this->_classMethods) {
$this->_classMethods = get_class_methods($this);
}
// preDispatch() didn't change the action, so we can continue
if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
if ($this->getInvokeArg('useCaseSensitiveActions')) {
trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
}
$this->$action();
} else {
$this->__call($action, array());
}
$this->postDispatch();
}
// whats actually important here is that this action controller is
// shutting down, regardless of dispatching; notify the helpers of this
// state
$this->_helper->notifyPostDispatch();
}
/**
* Call the action specified in the request object, and return a response
*
* Not used in the Action Controller implementation, but left for usage in
* Page Controller implementations. Dispatches a method based on the
* request.
*
* Returns a Zend_Controller_Response_Abstract object, instantiating one
* prior to execution if none exists in the controller.
*
* {@link preDispatch()} is called prior to the action,
* {@link postDispatch()} is called following it.
*
* @param null|Zend_Controller_Request_Abstract $request Optional request
* object to use
* @param null|Zend_Controller_Response_Abstract $response Optional response
* object to use
* @return Zend_Controller_Response_Abstract
*/
public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
{
if (null !== $request) {
$this->setRequest($request);
} else {
$request = $this->getRequest();
}
if (null !== $response) {
$this->setResponse($response);
}
$action = $request->getActionName();
if (empty($action)) {
$action = 'index';
}
$action = $action . 'Action';
$request->setDispatched(true);
$this->dispatch($action);
return $this->getResponse();
}
/**
* Gets a parameter from the {@link $_request Request object}. If the
* parameter does not exist, NULL will be returned.
*
* If the parameter does not exist and $default is set, then
* $default will be returned instead of NULL.
*
* @param string $paramName
* @param mixed $default
* @return mixed
*/
protected function _getParam($paramName, $default = null)
{
$value = $this->getRequest()->getParam($paramName);
if ((null == $value) && (null !== $default)) {
$value = $default;
}
return $value;
}
/**
* Set a parameter in the {@link $_request Request object}.
*
* @param string $paramName
* @param mixed $value
* @return Zend_Controller_Action
*/
protected function _setParam($paramName, $value)
{
$this->getRequest()->setParam($paramName, $value);
return $this;
}
/**
* Determine whether a given parameter exists in the
* {@link $_request Request object}.
*
* @param string $paramName
* @return boolean
*/
protected function _hasParam($paramName)
{
return null !== $this->getRequest()->getParam($paramName);
}
/**
* Return all parameters in the {@link $_request Request object}
* as an associative array.
*
* @return array
*/
protected function _getAllParams()
{
return $this->getRequest()->getParams();
}
/**
* Forward to another controller/action.
*
* It is important to supply the unformatted names, i.e. "article"
* rather than "ArticleController". The dispatcher will do the
* appropriate formatting when the request is received.
*
* If only an action name is provided, forwards to that action in this
* controller.
*
* If an action and controller are specified, forwards to that action and
* controller in this module.
*
* Specifying an action, controller, and module is the most specific way to
* forward.
*
* A fourth argument, $params, will be used to set the request parameters.
* If either the controller or module are unnecessary for forwarding,
* simply pass null values for them before specifying the parameters.
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params
* @return void
*/
final protected function _forward($action, $controller = null, $module = null, array $params = null)
{
$request = $this->getRequest();
if (null !== $params) {
$request->setParams($params);
}
if (null !== $controller) {
$request->setControllerName($controller);
// Module should only be reset if controller has been specified
if (null !== $module) {
$request->setModuleName($module);
}
}
$request->setActionName($action)
->setDispatched(false);
}
/**
* Redirect to another URL
*
* Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
*
* @param string $url
* @param array $options Options to be used when redirecting
* @return void
*/
protected function _redirect($url, array $options = array())
{
$this->_helper->redirector->gotoUrl($url, $options);
}
}
Controller/LayoutPlugin.php 0000604 00000003243 15071256136 0012040 0 ustar 00 <?php
class Zend_Controller_LayoutPlugin extends Zend_Controller_Plugin_Abstract {
/**
* Array of layout paths associating modules with layouts
*/
protected $_moduleLayouts;
/**
* Registers a module layout.
* This layout will be rendered when the specified module is called.
* If there is no layout registered for the current module, the default layout as specified
* in Zend_Layout will be rendered
*
* @param String $module The name of the module
* @param String $layoutPath The path to the layout
* @param String $layout The name of the layout to render
*/
public function registerModuleLayout($module, $layoutPath, $layout=null){
$this->_moduleLayouts[$module] = array(
'layoutPath' => $layoutPath,
'layout' => $layout
);
}
public function preDispatch(Zend_Controller_Request_Abstract $request){
if(isset($this->_moduleLayouts[$request->getModuleName()])){
$config = $this->_moduleLayouts[$request->getModuleName()];
$layout = Zend_Layout::getMvcInstance();
if($layout->getMvcEnabled()){
$layout->setLayoutPath($config['layoutPath']);
if($config['layout'] !== null){
$layout->setLayout($config['layout']);
}
}
}
}
}
?>