?
home/cideo/library/Zend/Measure/Abstract.php 0000666 00000026016 15125176217 0015020 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/Filter/Word/Separator/Abstract.php 0000666 00000004110 15125227614 0017504 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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: CamelCaseToUnderscore.php 6779 2007-11-08 15:10:41Z matthew $
*/
/**
* @see Zend_Filter_PregReplace
*/
require_once 'Zend/Filter/PregReplace.php';
/**
* @category Zend
* @package Zend_Filter
* @uses Zend_Filter_PregReplace
* @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_Filter_Word_Separator_Abstract extends Zend_Filter_PregReplace
{
protected $_separator = null;
/**
* Constructor
*
* @param string $separator Space by default
* @return void
*/
public function __construct($separator = ' ')
{
$this->setSeparator($separator);
}
/**
* Sets a new seperator
*
* @param string $separator Seperator
* @return $this
*/
public function setSeparator($separator)
{
if ($separator == null) {
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception('"' . $separator . '" is not a valid separator.');
}
$this->_separator = $separator;
return $this;
}
/**
* Returns the actual set seperator
*
* @return string
*/
public function getSeparator()
{
return $this->_separator;
}
} home/cideo/library/Zend/Mail/Storage/Abstract.php 0000666 00000022732 15125271345 0015704 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/Mail/Protocol/Abstract.php 0000666 00000024103 15125271760 0016074 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/View/Helper/Abstract.php 0000666 00000003305 15125273203 0015535 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_View
* @subpackage 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 10664 2008-08-05 10:56:06Z matthew $
*/
/**
* @see Zend_View_Helper_Interface
*/
require_once 'Zend/View/Helper/Interface.php';
/**
* @category Zend
* @package Zend_View
* @subpackage 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_View_Helper_Abstract implements Zend_View_Helper_Interface
{
/**
* View object
*
* @var Zend_View_Interface
*/
public $view = null;
/**
* Set the View object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_Abstract
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}
/**
* Strategy pattern: currently unutilized
*
* @return void
*/
public function direct()
{
}
}
home/cideo/library/Zend/View/Helper/Placeholder/Container/Abstract.php 0000666 00000023175 15125275462 0021721 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable 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_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Abstract.php 9099 2008-03-30 19:35:47Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Abstract class representing container for placeholder values
*
* @package Zend_View
* @subpackage Helpers
* @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_View_Helper_Placeholder_Container_Abstract extends ArrayObject
{
/**
* Whether or not to override all contents of placeholder
* @const string
*/
const SET = 'SET';
/**
* Whether or not to append contents to placeholder
* @const string
*/
const APPEND = 'APPEND';
/**
* Whether or not to prepend contents to placeholder
* @const string
*/
const PREPEND = 'PREPEND';
/**
* What text to prefix the placeholder with when rendering
* @var string
*/
protected $_prefix = '';
/**
* What text to append the placeholder with when rendering
* @var string
*/
protected $_postfix = '';
/**
* What string to use between individual items in the placeholder when rendering
* @var string
*/
protected $_separator = '';
/**
* What string to use as the indentation of output, this will typically be spaces. Eg: ' '
* @var string
*/
protected $_indent = '';
/**
* Whether or not we're already capturing for this given container
* @var bool
*/
protected $_captureLock = false;
/**
* What type of capture (overwrite (set), append, prepend) to use
* @var string
*/
protected $_captureType;
/**
* Key to which to capture content
* @var string
*/
protected $_captureKey;
/**
* Constructor - This is needed so that we can attach a class member as the ArrayObject container
*
* @return void
*/
public function __construct()
{
parent::__construct(array(), parent::ARRAY_AS_PROPS);
}
/**
* Set a single value
*
* @param mixed $value
* @return void
*/
public function set($value)
{
$this->exchangeArray(array($value));
}
/**
* Prepend a value to the top of the container
*
* @param mixed $value
* @return void
*/
public function prepend($value)
{
$values = $this->getArrayCopy();
array_unshift($values, $value);
$this->exchangeArray($values);
}
/**
* Retrieve container value
*
* If single element registered, returns that element; otherwise,
* serializes to array.
*
* @return mixed
*/
public function getValue()
{
if (1 == count($this)) {
$keys = $this->getKeys();
$key = array_shift($keys);
return $this[$key];
}
return $this->getArrayCopy();
}
/**
* Set prefix for __toString() serialization
*
* @param string $prefix
* @return Zend_View_Helper_Placeholder_Container
*/
public function setPrefix($prefix)
{
$this->_prefix = (string) $prefix;
return $this;
}
/**
* Retrieve prefix
*
* @return string
*/
public function getPrefix()
{
return $this->_prefix;
}
/**
* Set postfix for __toString() serialization
*
* @param string $postfix
* @return Zend_View_Helper_Placeholder_Container
*/
public function setPostfix($postfix)
{
$this->_postfix = (string) $postfix;
return $this;
}
/**
* Retrieve postfix
*
* @return string
*/
public function getPostfix()
{
return $this->_postfix;
}
/**
* Set separator for __toString() serialization
*
* Used to implode elements in container
*
* @param string $separator
* @return Zend_View_Helper_Placeholder_Container
*/
public function setSeparator($separator)
{
$this->_separator = (string) $separator;
return $this;
}
/**
* Retrieve separator
*
* @return string
*/
public function getSeparator()
{
return $this->_separator;
}
/**
* Set the indentation string for __toString() serialization,
* optionally, if a number is passed, it will be the number of spaces
*
* @param string|int $indent
* @return Zend_View_Helper_Placeholder_Container_Abstract
*/
public function setIndent($indent)
{
$this->_indent = $this->getWhitespace($indent);
return $this;
}
/**
* Retrieve indentation
*
* @return string
*/
public function getIndent()
{
return $this->_indent;
}
/**
* Retrieve whitespace representation of $indent
*
* @param int|string $indent
* @return string
*/
public function getWhitespace($indent)
{
if (is_int($indent)) {
$indent = str_repeat(' ', $indent);
}
return (string) $indent;
}
/**
* Start capturing content to push into placeholder
*
* @param int $type How to capture content into placeholder; append, prepend, or set
* @return void
* @throws Zend_View_Helper_Placeholder_Exception if nested captures detected
*/
public function captureStart($type = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $key = null)
{
if ($this->_captureLock) {
require_once 'Zend/View/Helper/Placeholder/Container/Exception.php';
throw new Zend_View_Helper_Placeholder_Container_Exception('Cannot nest placeholder captures for the same placeholder');
}
$this->_captureLock = true;
$this->_captureType = $type;
if ((null !== $key) && is_scalar($key)) {
$this->_captureKey = (string) $key;
}
ob_start();
}
/**
* End content capture
*
* @return void
*/
public function captureEnd()
{
$data = ob_get_clean();
$key = null;
$this->_captureLock = false;
if (null !== $this->_captureKey) {
$key = $this->_captureKey;
}
switch ($this->_captureType) {
case self::SET:
if (null !== $key) {
$this[$key] = $data;
} else {
$this->exchangeArray(array($data));
}
break;
case self::PREPEND:
if (null !== $key) {
$array = array($key => $data);
$values = $this->getArrayCopy();
$final = $array + $values;
$this->exchangeArray($final);
} else {
$this->prepend($data);
}
break;
case self::APPEND:
default:
if (null !== $key) {
if (empty($this[$key])) {
$this[$key] = $data;
} else {
$this[$key] .= $data;
}
} else {
$this[$this->nextIndex()] = $data;
}
break;
}
}
/**
* Get keys
*
* @return array
*/
public function getKeys()
{
$array = $this->getArrayCopy();
return array_keys($array);
}
/**
* Next Index
*
* as defined by the PHP manual
* @return int
*/
public function nextIndex()
{
$keys = $this->getKeys();
if (0 == count($keys)) {
return 0;
}
return $nextIndex = max($keys) + 1;
}
/**
* Render the placeholder
*
* @return string
*/
public function toString($indent = null)
{
$indent = ($indent !== null)
? $this->getWhitespace($indent)
: $this->getIndent();
$items = $this->getArrayCopy();
$return = $indent
. $this->getPrefix()
. implode($this->getSeparator(), $items)
. $this->getPostfix();
$return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return);
return $return;
}
/**
* Serialize object to string
*
* @return string
*/
public function __toString()
{
return $this->toString();
}
}
home/cideo/library/Zend/Soap/Wsdl/Strategy/Abstract.php 0000666 00000003251 15125277650 0017033 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @copyright Copyright (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 Zend_Soap_Wsdl_Strategy.
*
* @category Zend
* @package Zend_Soap
* @subpackage Wsdl
* @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_Soap_Wsdl_Strategy_Abstract implements Zend_Soap_Wsdl_Strategy_Interface
{
/**
* Context object
*
* @var Zend_Soap_Wsdl
*/
protected $_context;
/**
* Set the Zend_Soap_Wsdl Context object this strategy resides in.
*
* @param Zend_Soap_Wsdl $context
* @return void
*/
public function setContext(Zend_Soap_Wsdl $context)
{
$this->_context = $context;
}
/**
* Return the current Zend_Soap_Wsdl context object
*
* @return Zend_Soap_Wsdl
*/
public function getContext()
{
return $this->_context;
}
}
home/cideo/library/Zend/Controller/Dispatcher/Abstract.php 0000666 00000027776 15125335151 0017640 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/Controller/Response/Abstract.php 0000666 00000047757 15125335154 0017354 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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();
}
}
home/cideo/library/Zend/Log/Writer/Abstract.php 0000666 00000005477 15125343744 0015425 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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
* @subpackage Writer
* @copyright Copyright (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 13691 2009-01-19 05:33:06Z cadorn $
*/
/** Zend_Log_Filter_Priority */
require_once 'Zend/Log/Filter/Priority.php';
/** Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Writer
* @copyright Copyright (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 13691 2009-01-19 05:33:06Z cadorn $
*/
abstract class Zend_Log_Writer_Abstract
{
/**
* @var array of Zend_Log_Filter_Interface
*/
protected $_filters = array();
/**
* Formats the log message before writing.
* @var Zend_Log_Formatter_Interface
*/
protected $_formatter;
/**
* Add a filter specific to this writer.
*
* @param Zend_Log_Filter_Interface $filter
* @return void
*/
public function addFilter($filter)
{
if (is_integer($filter)) {
$filter = new Zend_Log_Filter_Priority($filter);
}
$this->_filters[] = $filter;
}
/**
* Log a message to this writer.
*
* @param array $event log data event
* @return void
*/
public function write($event)
{
foreach ($this->_filters as $filter) {
if (! $filter->accept($event)) {
return;
}
}
// exception occurs on error
$this->_write($event);
}
/**
* Set a new formatter for this writer
*
* @param Zend_Log_Formatter_Interface $formatter
* @return void
*/
public function setFormatter($formatter)
{
$this->_formatter = $formatter;
}
/**
* Perform shutdown activites such as closing open resources
*
* @return void
*/
public function shutdown()
{}
/**
* Write a message to the log.
*
* @param array $event log data event
* @return void
*/
abstract protected function _write($event);
} home/cideo/library/Zend/Db/Table/Abstract.php 0000666 00000130375 15125344634 0014777 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Table
* @copyright Copyright (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 6320 2007-09-12 00:27:22Z bkarwin $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Select.php';
/**
* @see Zend_Db
*/
require_once 'Zend/Db.php';
/**
* Class for SQL table interface.
*
* @category Zend
* @package Zend_Db
* @subpackage Table
* @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_Db_Table_Abstract
{
const ADAPTER = 'db';
const SCHEMA = 'schema';
const NAME = 'name';
const PRIMARY = 'primary';
const COLS = 'cols';
const METADATA = 'metadata';
const METADATA_CACHE = 'metadataCache';
const METADATA_CACHE_IN_CLASS = 'metadataCacheInClass';
const ROW_CLASS = 'rowClass';
const ROWSET_CLASS = 'rowsetClass';
const REFERENCE_MAP = 'referenceMap';
const DEPENDENT_TABLES = 'dependentTables';
const SEQUENCE = 'sequence';
const COLUMNS = 'columns';
const REF_TABLE_CLASS = 'refTableClass';
const REF_COLUMNS = 'refColumns';
const ON_DELETE = 'onDelete';
const ON_UPDATE = 'onUpdate';
const CASCADE = 'cascade';
const RESTRICT = 'restrict';
const SET_NULL = 'setNull';
const DEFAULT_NONE = 'defaultNone';
const DEFAULT_CLASS = 'defaultClass';
const DEFAULT_DB = 'defaultDb';
/**
* Default Zend_Db_Adapter_Abstract object.
*
* @var Zend_Db_Adapter_Abstract
*/
protected static $_defaultDb;
/**
* Default cache for information provided by the adapter's describeTable() method.
*
* @var Zend_Cache_Core
*/
protected static $_defaultMetadataCache = null;
/**
* Zend_Db_Adapter_Abstract object.
*
* @var Zend_Db_Adapter_Abstract
*/
protected $_db;
/**
* The schema name (default null means current schema)
*
* @var array
*/
protected $_schema = null;
/**
* The table name.
*
* @var array
*/
protected $_name = null;
/**
* The table column names derived from Zend_Db_Adapter_Abstract::describeTable().
*
* @var array
*/
protected $_cols;
/**
* The primary key column or columns.
* A compound key should be declared as an array.
* You may declare a single-column primary key
* as a string.
*
* @var mixed
*/
protected $_primary = null;
/**
* If your primary key is a compound key, and one of the columns uses
* an auto-increment or sequence-generated value, set _identity
* to the ordinal index in the $_primary array for that column.
* Note this index is the position of the column in the primary key,
* not the position of the column in the table. The primary key
* array is 1-based.
*
* @var integer
*/
protected $_identity = 1;
/**
* Define the logic for new values in the primary key.
* May be a string, boolean true, or boolean false.
*
* @var mixed
*/
protected $_sequence = true;
/**
* Information provided by the adapter's describeTable() method.
*
* @var array
*/
protected $_metadata = array();
/**
* Cache for information provided by the adapter's describeTable() method.
*
* @var Zend_Cache_Core
*/
protected $_metadataCache = null;
/**
* Flag: whether or not to cache metadata in the class
* @var bool
*/
protected $_metadataCacheInClass = true;
/**
* Classname for row
*
* @var string
*/
protected $_rowClass = 'Zend_Db_Table_Row';
/**
* Classname for rowset
*
* @var string
*/
protected $_rowsetClass = 'Zend_Db_Table_Rowset';
/**
* Associative array map of declarative referential integrity rules.
* This array has one entry per foreign key in the current table.
* Each key is a mnemonic name for one reference rule.
*
* Each value is also an associative array, with the following keys:
* - columns = array of names of column(s) in the child table.
* - refTableClass = class name of the parent table.
* - refColumns = array of names of column(s) in the parent table,
* in the same order as those in the 'columns' entry.
* - onDelete = "cascade" means that a delete in the parent table also
* causes a delete of referencing rows in the child table.
* - onUpdate = "cascade" means that an update of primary key values in
* the parent table also causes an update of referencing
* rows in the child table.
*
* @var array
*/
protected $_referenceMap = array();
/**
* Simple array of class names of tables that are "children" of the current
* table, in other words tables that contain a foreign key to this one.
* Array elements are not table names; they are class names of classes that
* extend Zend_Db_Table_Abstract.
*
* @var array
*/
protected $_dependentTables = array();
protected $_defaultSource = self::DEFAULT_NONE;
protected $_defaultValues = array();
/**
* Constructor.
*
* Supported params for $config are:
* - db = user-supplied instance of database connector,
* or key name of registry instance.
* - name = table name.
* - primary = string or array of primary key(s).
* - rowClass = row class name.
* - rowsetClass = rowset class name.
* - referenceMap = array structure to declare relationship
* to parent tables.
* - dependentTables = array of child tables.
* - metadataCache = cache for information from adapter describeTable().
*
* @param mixed $config Array of user-specified config options, or just the Db Adapter.
* @return void
*/
public function __construct($config = array())
{
/**
* Allow a scalar argument to be the Adapter object or Registry key.
*/
if (!is_array($config)) {
$config = array(self::ADAPTER => $config);
}
foreach ($config as $key => $value) {
switch ($key) {
case self::ADAPTER:
$this->_setAdapter($value);
break;
case self::SCHEMA:
$this->_schema = (string) $value;
break;
case self::NAME:
$this->_name = (string) $value;
break;
case self::PRIMARY:
$this->_primary = (array) $value;
break;
case self::ROW_CLASS:
$this->setRowClass($value);
break;
case self::ROWSET_CLASS:
$this->setRowsetClass($value);
break;
case self::REFERENCE_MAP:
$this->setReferences($value);
break;
case self::DEPENDENT_TABLES:
$this->setDependentTables($value);
break;
case self::METADATA_CACHE:
$this->_setMetadataCache($value);
break;
case self::METADATA_CACHE_IN_CLASS:
$this->setMetadataCacheInClass($value);
break;
case self::SEQUENCE:
$this->_setSequence($value);
break;
default:
// ignore unrecognized configuration directive
break;
}
}
$this->_setup();
$this->init();
}
/**
* @param string $classname
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
public function setRowClass($classname)
{
$this->_rowClass = (string) $classname;
return $this;
}
/**
* @return string
*/
public function getRowClass()
{
return $this->_rowClass;
}
/**
* @param string $classname
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
public function setRowsetClass($classname)
{
$this->_rowsetClass = (string) $classname;
return $this;
}
/**
* @return string
*/
public function getRowsetClass()
{
return $this->_rowsetClass;
}
/**
* @param array $referenceMap
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
public function setReferences(array $referenceMap)
{
$this->_referenceMap = $referenceMap;
return $this;
}
/**
* @param string $tableClassname
* @param string $ruleKey OPTIONAL
* @return array
* @throws Zend_Db_Table_Exception
*/
public function getReference($tableClassname, $ruleKey = null)
{
$thisClass = get_class($this);
$refMap = $this->_getReferenceMapNormalized();
if ($ruleKey !== null) {
if (!isset($refMap[$ruleKey])) {
require_once "Zend/Db/Table/Exception.php";
throw new Zend_Db_Table_Exception("No reference rule \"$ruleKey\" from table $thisClass to table $tableClassname");
}
if ($refMap[$ruleKey][self::REF_TABLE_CLASS] != $tableClassname) {
require_once "Zend/Db/Table/Exception.php";
throw new Zend_Db_Table_Exception("Reference rule \"$ruleKey\" does not reference table $tableClassname");
}
return $refMap[$ruleKey];
}
foreach ($refMap as $reference) {
if ($reference[self::REF_TABLE_CLASS] == $tableClassname) {
return $reference;
}
}
require_once "Zend/Db/Table/Exception.php";
throw new Zend_Db_Table_Exception("No reference from table $thisClass to table $tableClassname");
}
/**
* @param array $dependentTables
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
public function setDependentTables(array $dependentTables)
{
$this->_dependentTables = $dependentTables;
return $this;
}
/**
* @return array
*/
public function getDependentTables()
{
return $this->_dependentTables;
}
/**
* set the defaultSource property - this tells the table class where to find default values
*
* @param string $defaultSource
* @return Zend_Db_Table_Abstract
*/
public function setDefaultSource($defaultSource = self::DEFAULT_NONE)
{
if (!in_array($defaultSource, array(self::DEFAULT_CLASS, self::DEFAULT_DB, self::DEFAULT_NONE))) {
$defaultSource = self::DEFAULT_NONE;
}
$this->_defaultSource = $defaultSource;
return $this;
}
/**
* returns the default source flag that determines where defaultSources come from
*
* @return unknown
*/
public function getDefaultSource()
{
return $this->_defaultSource;
}
/**
* set the default values for the table class
*
* @param array $defaultValues
* @return Zend_Db_Table_Abstract
*/
public function setDefaultValues(Array $defaultValues)
{
foreach ($defaultValues as $defaultName => $defaultValue) {
if (array_key_exists($defaultName, $this->_metadata)) {
$this->_defaultValues[$defaultName] = $defaultValue;
}
}
return $this;
}
public function getDefaultValues()
{
return $this->_defaultValues;
}
/**
* Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.
*
* @param mixed $db Either an Adapter object, or a string naming a Registry key
* @return void
*/
public static function setDefaultAdapter($db = null)
{
self::$_defaultDb = self::_setupAdapter($db);
}
/**
* Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.
*
* @return Zend_Db_Adapter_Abstract or null
*/
public static function getDefaultAdapter()
{
return self::$_defaultDb;
}
/**
* @param mixed $db Either an Adapter object, or a string naming a Registry key
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
protected function _setAdapter($db)
{
$this->_db = self::_setupAdapter($db);
return $this;
}
/**
* Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.
*
* @return Zend_Db_Adapter_Abstract
*/
public function getAdapter()
{
return $this->_db;
}
/**
* @param mixed $db Either an Adapter object, or a string naming a Registry key
* @return Zend_Db_Adapter_Abstract
* @throws Zend_Db_Table_Exception
*/
protected static function _setupAdapter($db)
{
if ($db === null) {
return null;
}
if (is_string($db)) {
require_once 'Zend/Registry.php';
$db = Zend_Registry::get($db);
}
if (!$db instanceof Zend_Db_Adapter_Abstract) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('Argument must be of type Zend_Db_Adapter_Abstract, or a Registry key where a Zend_Db_Adapter_Abstract object is stored');
}
return $db;
}
/**
* Sets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
*
* If $defaultMetadataCache is null, then no metadata cache is used by default.
*
* @param mixed $metadataCache Either a Cache object, or a string naming a Registry key
* @return void
*/
public static function setDefaultMetadataCache($metadataCache = null)
{
self::$_defaultMetadataCache = self::_setupMetadataCache($metadataCache);
}
/**
* Gets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
*
* @return Zend_Cache_Core or null
*/
public static function getDefaultMetadataCache()
{
return self::$_defaultMetadataCache;
}
/**
* Sets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
*
* If $metadataCache is null, then no metadata cache is used. Since there is no opportunity to reload metadata
* after instantiation, this method need not be public, particularly because that it would have no effect
* results in unnecessary API complexity. To configure the metadata cache, use the metadataCache configuration
* option for the class constructor upon instantiation.
*
* @param mixed $metadataCache Either a Cache object, or a string naming a Registry key
* @return Zend_Db_Table_Abstract Provides a fluent interface
*/
protected function _setMetadataCache($metadataCache)
{
$this->_metadataCache = self::_setupMetadataCache($metadataCache);
return $this;
}
/**
* Gets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
*
* @return Zend_Cache_Core or null
*/
public function getMetadataCache()
{
return $this->_metadataCache;
}
/**
* Indicate whether metadata should be cached in the class for the duration
* of the instance
*
* @param bool $flag
* @return Zend_Db_Table_Abstract
*/
public function setMetadataCacheInClass($flag)
{
$this->_metadataCacheInClass = (bool) $flag;
return $this;
}
/**
* Retrieve flag indicating if metadata should be cached for duration of
* instance
*
* @return bool
*/
public function metadataCacheInClass()
{
return $this->_metadataCacheInClass;
}
/**
* @param mixed $metadataCache Either a Cache object, or a string naming a Registry key
* @return Zend_Cache_Core
* @throws Zend_Db_Table_Exception
*/
protected static function _setupMetadataCache($metadataCache)
{
if ($metadataCache === null) {
return null;
}
if (is_string($metadataCache)) {
require_once 'Zend/Registry.php';
$metadataCache = Zend_Registry::get($metadataCache);
}
if (!$metadataCache instanceof Zend_Cache_Core) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored');
}
return $metadataCache;
}
/**
* Sets the sequence member, which defines the behavior for generating
* primary key values in new rows.
* - If this is a string, then the string names the sequence object.
* - If this is boolean true, then the key uses an auto-incrementing
* or identity mechanism.
* - If this is boolean false, then the key is user-defined.
* Use this for natural keys, for example.
*
* @param mixed $sequence
* @return Zend_Db_Table_Adapter_Abstract Provides a fluent interface
*/
protected function _setSequence($sequence)
{
$this->_sequence = $sequence;
return $this;
}
/**
* Turnkey for initialization of a table object.
* Calls other protected methods for individual tasks, to make it easier
* for a subclass to override part of the setup logic.
*
* @return void
*/
protected function _setup()
{
$this->_setupDatabaseAdapter();
$this->_setupTableName();
}
/**
* Initialize database adapter.
*
* @return void
*/
protected function _setupDatabaseAdapter()
{
if (! $this->_db) {
$this->_db = self::getDefaultAdapter();
if (!$this->_db instanceof Zend_Db_Adapter_Abstract) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('No adapter found for ' . get_class($this));
}
}
}
/**
* Initialize table and schema names.
*
* If the table name is not set in the class definition,
* use the class name itself as the table name.
*
* A schema name provided with the table name (e.g., "schema.table") overrides
* any existing value for $this->_schema.
*
* @return void
*/
protected function _setupTableName()
{
if (! $this->_name) {
$this->_name = get_class($this);
} else if (strpos($this->_name, '.')) {
list($this->_schema, $this->_name) = explode('.', $this->_name);
}
}
/**
* Initializes metadata.
*
* If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
* information. Returns true if and only if the metadata are loaded from cache.
*
* @return boolean
* @throws Zend_Db_Table_Exception
*/
protected function _setupMetadata()
{
if ($this->metadataCacheInClass() && (count($this->_metadata) > 0)) {
return true;
}
// Assume that metadata will be loaded from cache
$isMetadataFromCache = true;
// If $this has no metadata cache but the class has a default metadata cache
if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) {
// Make $this use the default metadata cache of the class
$this->_setMetadataCache(self::$_defaultMetadataCache);
}
// If $this has a metadata cache
if (null !== $this->_metadataCache) {
// Define the cache identifier where the metadata are saved
$cacheId = md5("$this->_schema.$this->_name");
}
// If $this has no metadata cache or metadata cache misses
if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->load($cacheId))) {
// Metadata are not loaded from cache
$isMetadataFromCache = false;
// Fetch metadata from the adapter's describeTable() method
$metadata = $this->_db->describeTable($this->_name, $this->_schema);
// If $this has a metadata cache, then cache the metadata
if (null !== $this->_metadataCache && !$this->_metadataCache->save($metadata, $cacheId)) {
/**
* @see Zend_Db_Table_Exception
*/
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('Failed saving metadata to metadataCache');
}
}
// Assign the metadata to $this
$this->_metadata = $metadata;
// Return whether the metadata were loaded from cache
return $isMetadataFromCache;
}
/**
* Retrieve table columns
*
* @return array
*/
protected function _getCols()
{
if (null === $this->_cols) {
$this->_setupMetadata();
$this->_cols = array_keys($this->_metadata);
}
return $this->_cols;
}
/**
* Initialize primary key from metadata.
* If $_primary is not defined, discover primary keys
* from the information returned by describeTable().
*
* @return void
* @throws Zend_Db_Table_Exception
*/
protected function _setupPrimaryKey()
{
if (!$this->_primary) {
$this->_setupMetadata();
$this->_primary = array();
foreach ($this->_metadata as $col) {
if ($col['PRIMARY']) {
$this->_primary[ $col['PRIMARY_POSITION'] ] = $col['COLUMN_NAME'];
if ($col['IDENTITY']) {
$this->_identity = $col['PRIMARY_POSITION'];
}
}
}
// if no primary key was specified and none was found in the metadata
// then throw an exception.
if (empty($this->_primary)) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('A table must have a primary key, but none was found');
}
} else if (!is_array($this->_primary)) {
$this->_primary = array(1 => $this->_primary);
} else if (isset($this->_primary[0])) {
array_unshift($this->_primary, null);
unset($this->_primary[0]);
}
$cols = $this->_getCols();
if (! array_intersect((array) $this->_primary, $cols) == (array) $this->_primary) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception("Primary key column(s) ("
. implode(',', (array) $this->_primary)
. ") are not columns in this table ("
. implode(',', $cols)
. ")");
}
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int) $this->_identity];
/**
* Special case for PostgreSQL: a SERIAL key implicitly uses a sequence
* object whose name is "<table>_<column>_seq".
*/
if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
$this->_sequence = "{$this->_name}_{$pkIdentity}_seq";
if ($this->_schema) {
$this->_sequence = $this->_schema . '.' . $this->_sequence;
}
}
}
/**
* Returns a normalized version of the reference map
*
* @return array
*/
protected function _getReferenceMapNormalized()
{
$referenceMapNormalized = array();
foreach ($this->_referenceMap as $rule => $map) {
$referenceMapNormalized[$rule] = array();
foreach ($map as $key => $value) {
switch ($key) {
// normalize COLUMNS and REF_COLUMNS to arrays
case self::COLUMNS:
case self::REF_COLUMNS:
if (!is_array($value)) {
$referenceMapNormalized[$rule][$key] = array($value);
} else {
$referenceMapNormalized[$rule][$key] = $value;
}
break;
// other values are copied as-is
default:
$referenceMapNormalized[$rule][$key] = $value;
break;
}
}
}
return $referenceMapNormalized;
}
/**
* Initialize object
*
* Called from {@link __construct()} as final step of object instantiation.
*
* @return void
*/
public function init()
{
}
/**
* Returns table information.
*
* You can elect to return only a part of this information by supplying its key name,
* otherwise all information is returned as an array.
*
* @param $key The specific info part to return OPTIONAL
* @return mixed
*/
public function info($key = null)
{
$this->_setupPrimaryKey();
$info = array(
self::SCHEMA => $this->_schema,
self::NAME => $this->_name,
self::COLS => $this->_getCols(),
self::PRIMARY => (array) $this->_primary,
self::METADATA => $this->_metadata,
self::ROW_CLASS => $this->_rowClass,
self::ROWSET_CLASS => $this->_rowsetClass,
self::REFERENCE_MAP => $this->_referenceMap,
self::DEPENDENT_TABLES => $this->_dependentTables,
self::SEQUENCE => $this->_sequence
);
if ($key === null) {
return $info;
}
if (!array_key_exists($key, $info)) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('There is no table information for the key "' . $key . '"');
}
return $info[$key];
}
/**
* Returns an instance of a Zend_Db_Table_Select object.
*
* @return Zend_Db_Table_Select
*/
public function select()
{
require_once 'Zend/Db/Table/Select.php';
return new Zend_Db_Table_Select($this);
}
/**
* Inserts a new row.
*
* @param array $data Column-value pairs.
* @return mixed The primary key of the row inserted.
*/
public function insert(array $data)
{
$this->_setupPrimaryKey();
/**
* Zend_Db_Table assumes that if you have a compound primary key
* and one of the columns in the key uses a sequence,
* it's the _first_ column in the compound key.
*/
$primary = (array) $this->_primary;
$pkIdentity = $primary[(int)$this->_identity];
/**
* If this table uses a database sequence object and the data does not
* specify a value, then get the next ID from the sequence and add it
* to the row. We assume that only the first column in a compound
* primary key takes a value from a sequence.
*/
if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
}
/**
* If the primary key can be generated automatically, and no value was
* specified in the user-supplied data, then omit it from the tuple.
*/
if (array_key_exists($pkIdentity, $data) && $data[$pkIdentity] === null) {
unset($data[$pkIdentity]);
}
/**
* INSERT the new row.
*/
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
$this->_db->insert($tableSpec, $data);
/**
* Fetch the most recent ID generated by an auto-increment
* or IDENTITY column, unless the user has specified a value,
* overriding the auto-increment mechanism.
*/
if ($this->_sequence === true && !isset($data[$pkIdentity])) {
$data[$pkIdentity] = $this->_db->lastInsertId();
}
/**
* Return the primary key value if the PK is a single column,
* else return an associative array of the PK column/value pairs.
*/
$pkData = array_intersect_key($data, array_flip($primary));
if (count($primary) == 1) {
reset($pkData);
return current($pkData);
}
return $pkData;
}
/**
* Updates existing rows.
*
* @param array $data Column-value pairs.
* @param array|string $where An SQL WHERE clause, or an array of SQL WHERE clauses.
* @return int The number of rows updated.
*/
public function update(array $data, $where)
{
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
return $this->_db->update($tableSpec, $data, $where);
}
/**
* Called by a row object for the parent table's class during save() method.
*
* @param string $parentTableClassname
* @param array $oldPrimaryKey
* @param array $newPrimaryKey
* @return int
*/
public function _cascadeUpdate($parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey)
{
$this->_setupMetadata();
$rowsAffected = 0;
foreach ($this->_getReferenceMapNormalized() as $map) {
if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_UPDATE])) {
switch ($map[self::ON_UPDATE]) {
case self::CASCADE:
$newRefs = array();
$where = array();
for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
$col = $this->_db->foldCase($map[self::COLUMNS][$i]);
$refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
if (array_key_exists($refCol, $newPrimaryKey)) {
$newRefs[$col] = $newPrimaryKey[$refCol];
}
$type = $this->_metadata[$col]['DATA_TYPE'];
$where[] = $this->_db->quoteInto(
$this->_db->quoteIdentifier($col, true) . ' = ?',
$oldPrimaryKey[$refCol], $type);
}
$rowsAffected += $this->update($newRefs, $where);
break;
default:
// no action
break;
}
}
}
return $rowsAffected;
}
/**
* Deletes existing rows.
*
* @param array|string $where SQL WHERE clause(s).
* @return int The number of rows deleted.
*/
public function delete($where)
{
$tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
return $this->_db->delete($tableSpec, $where);
}
/**
* Called by parent table's class during delete() method.
*
* @param string $parentTableClassname
* @param array $primaryKey
* @return int Number of affected rows
*/
public function _cascadeDelete($parentTableClassname, array $primaryKey)
{
$this->_setupMetadata();
$rowsAffected = 0;
foreach ($this->_getReferenceMapNormalized() as $map) {
if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
switch ($map[self::ON_DELETE]) {
case self::CASCADE:
$where = array();
for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
$col = $this->_db->foldCase($map[self::COLUMNS][$i]);
$refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
$type = $this->_metadata[$col]['DATA_TYPE'];
$where[] = $this->_db->quoteInto(
$this->_db->quoteIdentifier($col, true) . ' = ?',
$primaryKey[$refCol], $type);
}
$rowsAffected += $this->delete($where);
break;
default:
// no action
break;
}
}
}
return $rowsAffected;
}
/**
* Fetches rows by primary key. The argument specifies one or more primary
* key value(s). To find multiple rows by primary key, the argument must
* be an array.
*
* This method accepts a variable number of arguments. If the table has a
* multi-column primary key, the number of arguments must be the same as
* the number of columns in the primary key. To find multiple rows in a
* table with a multi-column primary key, each argument must be an array
* with the same number of elements.
*
* The find() method always returns a Rowset object, even if only one row
* was found.
*
* @param mixed $key The value(s) of the primary keys.
* @return Zend_Db_Table_Rowset_Abstract Row(s) matching the criteria.
* @throws Zend_Db_Table_Exception
*/
public function find()
{
$this->_setupPrimaryKey();
$args = func_get_args();
$keyNames = array_values((array) $this->_primary);
if (count($args) < count($keyNames)) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception("Too few columns for the primary key");
}
if (count($args) > count($keyNames)) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception("Too many columns for the primary key");
}
$whereList = array();
$numberTerms = 0;
foreach ($args as $keyPosition => $keyValues) {
// Coerce the values to an array.
// Don't simply typecast to array, because the values
// might be Zend_Db_Expr objects.
if (!is_array($keyValues)) {
$keyValues = array($keyValues);
}
if ($numberTerms == 0) {
$numberTerms = count($keyValues);
} else if (count($keyValues) != $numberTerms) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception("Missing value(s) for the primary key");
}
for ($i = 0; $i < count($keyValues); ++$i) {
if (!isset($whereList[$i])) {
$whereList[$i] = array();
}
$whereList[$i][$keyPosition] = $keyValues[$i];
}
}
$whereClause = null;
if (count($whereList)) {
$whereOrTerms = array();
foreach ($whereList as $keyValueSets) {
$whereAndTerms = array();
foreach ($keyValueSets as $keyPosition => $keyValue) {
$type = $this->_metadata[$keyNames[$keyPosition]]['DATA_TYPE'];
$tableName = $this->_db->quoteTableAs($this->_name, null, true);
$columnName = $this->_db->quoteIdentifier($keyNames[$keyPosition], true);
$whereAndTerms[] = $this->_db->quoteInto(
$tableName . '.' . $columnName . ' = ?',
$keyValue, $type);
}
$whereOrTerms[] = '(' . implode(' AND ', $whereAndTerms) . ')';
}
$whereClause = '(' . implode(' OR ', $whereOrTerms) . ')';
}
return $this->fetchAll($whereClause);
}
/**
* Fetches all rows.
*
* Honors the Zend_Db_Adapter fetch mode.
*
* @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @param int $count OPTIONAL An SQL LIMIT count.
* @param int $offset OPTIONAL An SQL LIMIT offset.
* @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
*/
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
{
if (!($where instanceof Zend_Db_Table_Select)) {
$select = $this->select();
if ($where !== null) {
$this->_where($select, $where);
}
if ($order !== null) {
$this->_order($select, $order);
}
if ($count !== null || $offset !== null) {
$select->limit($count, $offset);
}
} else {
$select = $where;
}
$rows = $this->_fetch($select);
$data = array(
'table' => $this,
'data' => $rows,
'readOnly' => $select->isReadOnly(),
'rowClass' => $this->_rowClass,
'stored' => true
);
@Zend_Loader::loadClass($this->_rowsetClass);
return new $this->_rowsetClass($data);
}
/**
* Fetches one row in an object of type Zend_Db_Table_Row_Abstract,
* or returns Boolean false if no row matches the specified criteria.
*
* @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @return Zend_Db_Table_Row_Abstract The row results per the
* Zend_Db_Adapter fetch mode, or null if no row found.
*/
public function fetchRow($where = null, $order = null)
{
if (!($where instanceof Zend_Db_Table_Select)) {
$select = $this->select();
if ($where !== null) {
$this->_where($select, $where);
}
if ($order !== null) {
$this->_order($select, $order);
}
$select->limit(1);
} else {
$select = $where->limit(1);
}
$rows = $this->_fetch($select);
if (count($rows) == 0) {
return null;
}
$data = array(
'table' => $this,
'data' => $rows[0],
'readOnly' => $select->isReadOnly(),
'stored' => true
);
@Zend_Loader::loadClass($this->_rowClass);
return new $this->_rowClass($data);
}
/**
* Fetches a new blank row (not from the database).
*
* @return Zend_Db_Table_Row_Abstract
* @deprecated since 0.9.3 - use createRow() instead.
*/
public function fetchNew()
{
return $this->createRow();
}
/**
* Fetches a new blank row (not from the database).
*
* @param array $data OPTIONAL data to populate in the new row.
* @param string $defaultSource OPTIONAL flag to force default values into new row
* @return Zend_Db_Table_Row_Abstract
*/
public function createRow(array $data = array(), $defaultSource = null)
{
$cols = $this->_getCols();
$defaults = array_combine($cols, array_fill(0, count($cols), null));
// nothing provided at call-time, take the class value
if ($defaultSource == null) {
$defaultSource = $this->_defaultSource;
}
if (!in_array($defaultSource, array(self::DEFAULT_CLASS, self::DEFAULT_DB, self::DEFAULT_NONE))) {
$defaultSource = self::DEFAULT_NONE;
}
if ($defaultSource == self::DEFAULT_DB) {
foreach ($this->_metadata as $metadataName => $metadata) {
if (($metadata['DEFAULT'] != null) &&
($metadata['NULLABLE'] !== true || ($metadata['NULLABLE'] === true && isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === true)) &&
(!(isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === false))) {
$defaults[$metadataName] = $metadata['DEFAULT'];
}
}
} elseif ($defaultSource == self::DEFAULT_CLASS && $this->_defaultValues) {
foreach ($this->_defaultValues as $defaultName => $defaultValue) {
if (array_key_exists($defaultName, $defaults)) {
$defaults[$defaultName] = $defaultValue;
}
}
}
$config = array(
'table' => $this,
'data' => $defaults,
'readOnly' => false,
'stored' => false
);
@Zend_Loader::loadClass($this->_rowClass);
$row = new $this->_rowClass($config);
$row->setFromArray($data);
return $row;
}
/**
* Generate WHERE clause from user-supplied string or array
*
* @param string|array $where OPTIONAL An SQL WHERE clause.
* @return Zend_Db_Table_Select
*/
protected function _where(Zend_Db_Table_Select $select, $where)
{
$where = (array) $where;
foreach ($where as $key => $val) {
// is $key an int?
if (is_int($key)) {
// $val is the full condition
$select->where($val);
} else {
// $key is the condition with placeholder,
// and $val is quoted into the condition
$select->where($key, $val);
}
}
return $select;
}
/**
* Generate ORDER clause from user-supplied string or array
*
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @return Zend_Db_Table_Select
*/
protected function _order(Zend_Db_Table_Select $select, $order)
{
if (!is_array($order)) {
$order = array($order);
}
foreach ($order as $val) {
$select->order($val);
}
return $select;
}
/**
* Support method for fetching rows.
*
* @param Zend_Db_Table_Select $select query options.
* @return array An array containing the row results in FETCH_ASSOC mode.
*/
protected function _fetch(Zend_Db_Table_Select $select)
{
$stmt = $this->_db->query($select);
$data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
return $data;
}
}
home/cideo/library/Zend/Db/Adapter/Pdo/Abstract.php 0000666 00000024436 15125345374 0016054 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage 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: Abstract.php 13711 2009-01-20 17:37:35Z mikaelkael $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once 'Zend/Db/Adapter/Abstract.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Db_Statement_Pdo
*/
require_once 'Zend/Db/Statement/Pdo.php';
/**
* Class for connecting to SQL databases and performing common operations using PDO.
*
* @category Zend
* @package Zend_Db
* @subpackage 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_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
{
/**
* Default class name for a DB statement.
*
* @var string
*/
protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo';
/**
* Creates a PDO DSN for the adapter from $this->_config settings.
*
* @return string
*/
protected function _dsn()
{
// baseline of DSN parts
$dsn = $this->_config;
// don't pass the username, password, and driver_options in the DSN
unset($dsn['username']);
unset($dsn['password']);
unset($dsn['options']);
unset($dsn['driver_options']);
// use all remaining parts in the DSN
foreach ($dsn as $key => $val) {
$dsn[$key] = "$key=$val";
}
return $this->_pdoType . ':' . implode(';', $dsn);
}
/**
* Creates a PDO object and connects to the database.
*
* @return void
* @throws Zend_Db_Adapter_Exception
*/
protected function _connect()
{
// if we already have a PDO object, no need to re-connect.
if ($this->_connection) {
return;
}
// get the dsn first, because some adapters alter the $_pdoType
$dsn = $this->_dsn();
// check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
// check the PDO driver is available
if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
}
// create PDO connection
$q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);
try {
$this->_connection = new PDO(
$dsn,
$this->_config['username'],
$this->_config['password'],
$this->_config['driver_options']
);
$this->_profiler->queryEnd($q);
// set the PDO connection to perform case-folding on array keys, or not
$this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
// always use exceptions.
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($e->getMessage());
}
}
/**
* Test if a connection is active
*
* @return boolean
*/
public function isConnected()
{
return ((bool) ($this->_connection instanceof PDO));
}
/**
* Force the connection to close.
*
* @return void
*/
public function closeConnection()
{
$this->_connection = null;
}
/**
* Prepares an SQL statement.
*
* @param string $sql The SQL statement with placeholders.
* @param array $bind An array of data to bind to the placeholders.
* @return PDOStatement
*/
public function prepare($sql)
{
$this->_connect();
$stmtClass = $this->_defaultStmtClass;
Zend_Loader::loadClass($stmtClass);
$stmt = new $stmtClass($this, $sql);
$stmt->setFetchMode($this->_fetchMode);
return $stmt;
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* On RDBMS brands that don't support sequences, $tableName and $primaryKey
* are ignored.
*
* @param string $tableName OPTIONAL Name of table.
* @param string $primaryKey OPTIONAL Name of primary key column.
* @return string
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$this->_connect();
return $this->_connection->lastInsertId();
}
/**
* Special handling for PDO query().
* All bind parameter names must begin with ':'
*
* @param string|Zend_Db_Select $sql The SQL statement with placeholders.
* @param array $bind An array of data to bind to the placeholders.
* @return Zend_Db_Statement_Pdo
* @throws Zend_Db_Adapter_Exception To re-throw PDOException.
*/
public function query($sql, $bind = array())
{
if (is_array($bind)) {
foreach ($bind as $name => $value) {
if (!is_int($name) && !preg_match('/^:/', $name)) {
$newName = ":$name";
unset($bind[$name]);
$bind[$newName] = $value;
}
}
}
try {
return parent::query($sql, $bind);
} catch (PDOException $e) {
/**
* @see Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage());
}
}
/**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$this->_connect();
return $this->_connection->quote($value);
}
/**
* Begin a transaction.
*/
protected function _beginTransaction()
{
$this->_connect();
$this->_connection->beginTransaction();
}
/**
* Commit a transaction.
*/
protected function _commit()
{
$this->_connect();
$this->_connection->commit();
}
/**
* Roll-back a transaction.
*/
protected function _rollBack() {
$this->_connect();
$this->_connection->rollBack();
}
/**
* Set the PDO fetch mode.
*
* @todo Support FETCH_CLASS and FETCH_INTO.
*
* @param int $mode A PDO fetch mode.
* @return void
* @throws Zend_Db_Adapter_Exception
*/
public function setFetchMode($mode)
{
//check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
switch ($mode) {
case PDO::FETCH_LAZY:
case PDO::FETCH_ASSOC:
case PDO::FETCH_NUM:
case PDO::FETCH_BOTH:
case PDO::FETCH_NAMED:
case PDO::FETCH_OBJ:
$this->_fetchMode = $mode;
break;
default:
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Invalid fetch mode '$mode' specified");
break;
}
}
/**
* Check if the adapter supports real SQL parameters.
*
* @param string $type 'positional' or 'named'
* @return bool
*/
public function supportsParameters($type)
{
switch ($type) {
case 'positional':
case 'named':
default:
return true;
}
}
/**
* Retrieve server version in PHP style
*
* @return string
*/
public function getServerVersion()
{
$this->_connect();
try {
$version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
} catch (PDOException $e) {
// In case of the driver doesn't support getting attributes
return null;
}
$matches = null;
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
return $matches[1];
} else {
return null;
}
}
}
home/cideo/library/Zend/Db/Table/Row/Abstract.php 0000666 00000111661 15125345535 0015544 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Table
* @copyright Copyright (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 6332 2007-09-13 00:35:08Z bkarwin $
*/
/**
* @see Zend_Db
*/
require_once 'Zend/Db.php';
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Table
* @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_Db_Table_Row_Abstract implements ArrayAccess
{
/**
* The data for each column in the row (column_name => value).
* The keys must match the physical names of columns in the
* table for which this row is defined.
*
* @var array
*/
protected $_data = array();
/**
* This is set to a copy of $_data when the data is fetched from
* a database, specified as a new tuple in the constructor, or
* when dirty data is posted to the database with save().
*
* @var array
*/
protected $_cleanData = array();
/**
* Tracks columns where data has been updated. Allows more specific insert and
* update operations.
*
* @var array
*/
protected $_modifiedFields = array();
/**
* Zend_Db_Table_Abstract parent class or instance.
*
* @var Zend_Db_Table_Abstract
*/
protected $_table = null;
/**
* Connected is true if we have a reference to a live
* Zend_Db_Table_Abstract object.
* This is false after the Rowset has been deserialized.
*
* @var boolean
*/
protected $_connected = true;
/**
* A row is marked read only if it contains columns that are not physically represented within
* the database schema (e.g. evaluated columns/Zend_Db_Expr columns). This can also be passed
* as a run-time config options as a means of protecting row data.
*
* @var boolean
*/
protected $_readOnly = false;
/**
* Name of the class of the Zend_Db_Table_Abstract object.
*
* @var string
*/
protected $_tableClass = null;
/**
* Primary row key(s).
*
* @var array
*/
protected $_primary;
/**
* Constructor.
*
* Supported params for $config are:-
* - table = class name or object of type Zend_Db_Table_Abstract
* - data = values of columns in this row.
*
* @param array $config OPTIONAL Array of user-specified config options.
* @return void
* @throws Zend_Db_Table_Row_Exception
*/
public function __construct(array $config = array())
{
if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
$this->_table = $config['table'];
$this->_tableClass = get_class($this->_table);
}
if (isset($config['data'])) {
if (!is_array($config['data'])) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Data must be an array');
}
$this->_data = $config['data'];
}
if (isset($config['stored']) && $config['stored'] === true) {
$this->_cleanData = $this->_data;
}
if (isset($config['readOnly']) && $config['readOnly'] === true) {
$this->setReadOnly(true);
}
// Retrieve primary keys from table schema
if (($table = $this->_getTable())) {
$info = $table->info();
$this->_primary = (array) $info['primary'];
}
$this->init();
}
/**
* Transform a column name from the user-specified form
* to the physical form used in the database.
* You can override this method in a custom Row class
* to implement column name mappings, for example inflection.
*
* @param string $columnName Column name given.
* @return string The column name after transformation applied (none by default).
* @throws Zend_Db_Table_Row_Exception if the $columnName is not a string.
*/
protected function _transformColumn($columnName)
{
if (!is_string($columnName)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Specified column is not a string');
}
// Perform no transformation by default
return $columnName;
}
/**
* Retrieve row field value
*
* @param string $columnName The user-specified column name.
* @return string The corresponding column value.
* @throws Zend_Db_Table_Row_Exception if the $columnName is not a column in the row.
*/
public function __get($columnName)
{
$columnName = $this->_transformColumn($columnName);
if (!array_key_exists($columnName, $this->_data)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
}
return $this->_data[$columnName];
}
/**
* Set row field value
*
* @param string $columnName The column key.
* @param mixed $value The value for the property.
* @return void
* @throws Zend_Db_Table_Row_Exception
*/
public function __set($columnName, $value)
{
$columnName = $this->_transformColumn($columnName);
if (!array_key_exists($columnName, $this->_data)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
}
$this->_data[$columnName] = $value;
$this->_modifiedFields[$columnName] = true;
}
/**
* Test existence of row field
*
* @param string $columnName The column key.
* @return boolean
*/
public function __isset($columnName)
{
$columnName = $this->_transformColumn($columnName);
return array_key_exists($columnName, $this->_data);
}
/**
* Store table, primary key and data in serialized object
*
* @return array
*/
public function __sleep()
{
return array('_tableClass', '_primary', '_data', '_cleanData', '_readOnly' ,'_modifiedFields');
}
/**
* Setup to do on wakeup.
* A de-serialized Row should not be assumed to have access to a live
* database connection, so set _connected = false.
*
* @return void
*/
public function __wakeup()
{
$this->_connected = false;
}
/**
* Proxy to __isset
* Required by the ArrayAccess implementation
*
* @param string $offset
* @return boolean
*/
public function offsetExists($offset)
{
return $this->__isset($offset);
}
/**
* Proxy to __get
* Required by the ArrayAccess implementation
*
* @param string $offset
* @return string
*/
public function offsetGet($offset)
{
return $this->__get($offset);
}
/**
* Proxy to __set
* Required by the ArrayAccess implementation
*
* @param string $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
$this->__set($offset, $value);
}
/**
* Does nothing
* Required by the ArrayAccess implementation
*
* @param string $offset
*/
public function offsetUnset($offset)
{
}
/**
* Initialize object
*
* Called from {@link __construct()} as final step of object instantiation.
*
* @return void
*/
public function init()
{
}
/**
* Returns the table object, or null if this is disconnected row
*
* @return Zend_Db_Table_Abstract|null
*/
public function getTable()
{
return $this->_table;
}
/**
* Set the table object, to re-establish a live connection
* to the database for a Row that has been de-serialized.
*
* @param Zend_Db_Table_Abstract $table
* @return boolean
* @throws Zend_Db_Table_Row_Exception
*/
public function setTable(Zend_Db_Table_Abstract $table = null)
{
if ($table == null) {
$this->_table = null;
$this->_connected = false;
return false;
}
$tableClass = get_class($table);
if (! $table instanceof $this->_tableClass) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass");
}
$this->_table = $table;
$this->_tableClass = $tableClass;
$info = $this->_table->info();
if ($info['cols'] != array_keys($this->_data)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
}
if (! array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table '$tableClass' does not have the same primary key as the Row");
}
$this->_connected = true;
return true;
}
/**
* Query the class name of the Table object for which this
* Row was created.
*
* @return string
*/
public function getTableClass()
{
return $this->_tableClass;
}
/**
* Test the connected status of the row.
*
* @return boolean
*/
public function isConnected()
{
return $this->_connected;
}
/**
* Test the read-only status of the row.
*
* @return boolean
*/
public function isReadOnly()
{
return $this->_readOnly;
}
/**
* Set the read-only status of the row.
*
* @param boolean $flag
* @return boolean
*/
public function setReadOnly($flag)
{
$this->_readOnly = (bool) $flag;
}
/**
* Returns an instance of the parent table's Zend_Db_Table_Select object.
*
* @return Zend_Db_Table_Select
*/
public function select()
{
return $this->getTable()->select();
}
/**
* Saves the properties to the database.
*
* This performs an intelligent insert/update, and reloads the
* properties with fresh data from the table on success.
*
* @return mixed The primary key value(s), as an associative array if the
* key is compound, or a scalar if the key is single-column.
*/
public function save()
{
/**
* If the _cleanData array is empty,
* this is an INSERT of a new row.
* Otherwise it is an UPDATE.
*/
if (empty($this->_cleanData)) {
return $this->_doInsert();
} else {
return $this->_doUpdate();
}
}
/**
* @return mixed The primary key value(s), as an associative array if the
* key is compound, or a scalar if the key is single-column.
*/
protected function _doInsert()
{
/**
* A read-only row cannot be saved.
*/
if ($this->_readOnly === true) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
}
/**
* Run pre-INSERT logic
*/
$this->_insert();
/**
* Execute the INSERT (this may throw an exception)
*/
$data = array_intersect_key($this->_data, $this->_modifiedFields);
$primaryKey = $this->_getTable()->insert($data);
/**
* Normalize the result to an array indexed by primary key column(s).
* The table insert() method may return a scalar.
*/
if (is_array($primaryKey)) {
$newPrimaryKey = $primaryKey;
} else {
$newPrimaryKey = array(current((array) $this->_primary) => $primaryKey);
}
/**
* Save the new primary key value in _data. The primary key may have
* been generated by a sequence or auto-increment mechanism, and this
* merge should be done before the _postInsert() method is run, so the
* new values are available for logging, etc.
*/
$this->_data = array_merge($this->_data, $newPrimaryKey);
/**
* Run post-INSERT logic
*/
$this->_postInsert();
/**
* Update the _cleanData to reflect that the data has been inserted.
*/
$this->_refresh();
return $primaryKey;
}
/**
* @return mixed The primary key value(s), as an associative array if the
* key is compound, or a scalar if the key is single-column.
*/
protected function _doUpdate()
{
/**
* A read-only row cannot be saved.
*/
if ($this->_readOnly === true) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
}
/**
* Get expressions for a WHERE clause
* based on the primary key value(s).
*/
$where = $this->_getWhereQuery(false);
/**
* Run pre-UPDATE logic
*/
$this->_update();
/**
* Compare the data to the modified fields array to discover
* which columns have been changed.
*/
$diffData = array_intersect_key($this->_data, $this->_modifiedFields);
/**
* Were any of the changed columns part of the primary key?
*/
$pkDiffData = array_intersect_key($diffData, array_flip((array)$this->_primary));
/**
* Execute cascading updates against dependent tables.
* Do this only if primary key value(s) were changed.
*/
if (count($pkDiffData) > 0) {
$depTables = $this->_getTable()->getDependentTables();
if (!empty($depTables)) {
$db = $this->_getTable()->getAdapter();
$pkNew = $this->_getPrimaryKey(true);
$pkOld = $this->_getPrimaryKey(false);
foreach ($depTables as $tableClass) {
try {
@Zend_Loader::loadClass($tableClass);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$t = new $tableClass(array('db' => $db));
$t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
}
}
}
/**
* Execute the UPDATE (this may throw an exception)
* Do this only if data values were changed.
* Use the $diffData variable, so the UPDATE statement
* includes SET terms only for data values that changed.
*/
if (count($diffData) > 0) {
$this->_getTable()->update($diffData, $where);
}
/**
* Run post-UPDATE logic. Do this before the _refresh()
* so the _postUpdate() function can tell the difference
* between changed data and clean (pre-changed) data.
*/
$this->_postUpdate();
/**
* Refresh the data just in case triggers in the RDBMS changed
* any columns. Also this resets the _cleanData.
*/
$this->_refresh();
/**
* Return the primary key value(s) as an array
* if the key is compound or a scalar if the key
* is a scalar.
*/
$primaryKey = $this->_getPrimaryKey(true);
if (count($primaryKey) == 1) {
return current($primaryKey);
}
return $primaryKey;
}
/**
* Deletes existing rows.
*
* @return int The number of rows deleted.
*/
public function delete()
{
/**
* A read-only row cannot be deleted.
*/
if ($this->_readOnly === true) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
}
$where = $this->_getWhereQuery();
/**
* Execute pre-DELETE logic
*/
$this->_delete();
/**
* Execute cascading deletes against dependent tables
*/
$depTables = $this->_getTable()->getDependentTables();
if (!empty($depTables)) {
$db = $this->_getTable()->getAdapter();
$pk = $this->_getPrimaryKey();
foreach ($depTables as $tableClass) {
try {
@Zend_Loader::loadClass($tableClass);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$t = new $tableClass(array('db' => $db));
$t->_cascadeDelete($this->getTableClass(), $pk);
}
}
/**
* Execute the DELETE (this may throw an exception)
*/
$result = $this->_getTable()->delete($where);
/**
* Execute post-DELETE logic
*/
$this->_postDelete();
/**
* Reset all fields to null to indicate that the row is not there
*/
$this->_data = array_combine(
array_keys($this->_data),
array_fill(0, count($this->_data), null)
);
return $result;
}
/**
* Returns the column/value data as an array.
*
* @return array
*/
public function toArray()
{
return (array)$this->_data;
}
/**
* Sets all data in the row from an array.
*
* @param array $data
* @return Zend_Db_Table_Row_Abstract Provides a fluent interface
*/
public function setFromArray(array $data)
{
$data = array_intersect_key($data, $this->_data);
foreach ($data as $columnName => $value) {
$this->__set($columnName, $value);
}
return $this;
}
/**
* Refreshes properties from the database.
*
* @return void
*/
public function refresh()
{
return $this->_refresh();
}
/**
* Retrieves an instance of the parent table.
*
* @return Zend_Db_Table_Abstract
*/
protected function _getTable()
{
if (!$this->_connected) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Cannot save a Row unless it is connected');
}
return $this->_table;
}
/**
* Retrieves an associative array of primary keys.
*
* @param bool $useDirty
* @return array
*/
protected function _getPrimaryKey($useDirty = true)
{
if (!is_array($this->_primary)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The primary key must be set as an array");
}
$primary = array_flip($this->_primary);
if ($useDirty) {
$array = array_intersect_key($this->_data, $primary);
} else {
$array = array_intersect_key($this->_cleanData, $primary);
}
if (count($primary) != count($array)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table '$this->_tableClass' does not have the same primary key as the Row");
}
return $array;
}
/**
* Constructs where statement for retrieving row(s).
*
* @param bool $useDirty
* @return array
*/
protected function _getWhereQuery($useDirty = true)
{
$where = array();
$db = $this->_getTable()->getAdapter();
$primaryKey = $this->_getPrimaryKey($useDirty);
$info = $this->_getTable()->info();
$metadata = $info[Zend_Db_Table_Abstract::METADATA];
// retrieve recently updated row using primary keys
$where = array();
foreach ($primaryKey as $column => $value) {
$tableName = $db->quoteIdentifier($info[Zend_Db_Table_Abstract::NAME], true);
$type = $metadata[$column]['DATA_TYPE'];
$columnName = $db->quoteIdentifier($column, true);
$where[] = $db->quoteInto("{$tableName}.{$columnName} = ?", $value, $type);
}
return $where;
}
/**
* Refreshes properties from the database.
*
* @return void
*/
protected function _refresh()
{
$where = $this->_getWhereQuery();
$row = $this->_getTable()->fetchRow($where);
if (null === $row) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
}
$this->_data = $row->toArray();
$this->_cleanData = $this->_data;
$this->_modifiedFields = array();
}
/**
* Allows pre-insert logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _insert()
{
}
/**
* Allows post-insert logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _postInsert()
{
}
/**
* Allows pre-update logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _update()
{
}
/**
* Allows post-update logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _postUpdate()
{
}
/**
* Allows pre-delete logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _delete()
{
}
/**
* Allows post-delete logic to be applied to row.
* Subclasses may override this method.
*
* @return void
*/
protected function _postDelete()
{
}
/**
* Prepares a table reference for lookup.
*
* Ensures all reference keys are set and properly formatted.
*
* @param Zend_Db_Table_Abstract $dependentTable
* @param Zend_Db_Table_Abstract $parentTable
* @param string $ruleKey
* @return array
*/
protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
{
$map = $dependentTable->getReference(get_class($parentTable), $ruleKey);
if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
$parentInfo = $parentTable->info();
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
}
$map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];
return $map;
}
/**
* Query a dependent table to retrieve rows matching the current row.
*
* @param string|Zend_Db_Table_Abstract $dependentTable
* @param string OPTIONAL $ruleKey
* @param Zend_Db_Table_Select OPTIONAL $select
* @return Zend_Db_Table_Rowset_Abstract Query result from $dependentTable
* @throws Zend_Db_Table_Row_Exception If $dependentTable is not a table or is not loadable.
*/
public function findDependentRowset($dependentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($dependentTable)) {
try {
@Zend_Loader::loadClass($dependentTable);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$dependentTable = new $dependentTable(array('db' => $db));
}
if (! $dependentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($dependentTable);
if ($type == 'object') {
$type = get_class($dependentTable);
}
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
}
if ($select === null) {
$select = $dependentTable->select();
} else {
$select->setTable($dependentTable);
}
$map = $this->_prepareReference($dependentTable, $this->_getTable(), $ruleKey);
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$parentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$value = $this->_data[$parentColumnName];
// Use adapter from dependent table to ensure correct query construction
$dependentDb = $dependentTable->getAdapter();
$dependentColumnName = $dependentDb->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$dependentColumn = $dependentDb->quoteIdentifier($dependentColumnName, true);
$dependentInfo = $dependentTable->info();
$type = $dependentInfo[Zend_Db_Table_Abstract::METADATA][$dependentColumnName]['DATA_TYPE'];
$select->where("$dependentColumn = ?", $value, $type);
}
return $dependentTable->fetchAll($select);
}
/**
* Query a parent table to retrieve the single row matching the current row.
*
* @param string|Zend_Db_Table_Abstract $parentTable
* @param string OPTIONAL $ruleKey
* @return Zend_Db_Table_Row_Abstract Query result from $parentTable
* @throws Zend_Db_Table_Row_Exception If $parentTable is not a table or is not loadable.
*/
public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($parentTable)) {
try {
@Zend_Loader::loadClass($parentTable);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$parentTable = new $parentTable(array('db' => $db));
}
if (! $parentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($parentTable);
if ($type == 'object') {
$type = get_class($parentTable);
}
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
}
if ($select === null) {
$select = $parentTable->select();
} else {
$select->setTable($parentTable);
}
$map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$value = $this->_data[$dependentColumnName];
// Use adapter from parent table to ensure correct query construction
$parentDb = $parentTable->getAdapter();
$parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$parentColumn = $parentDb->quoteIdentifier($parentColumnName, true);
$parentInfo = $parentTable->info();
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
$select->where("$parentColumn = ?", $value, $type);
}
return $parentTable->fetchRow($select);
}
/**
* @param string|Zend_Db_Table_Abstract $matchTable
* @param string|Zend_Db_Table_Abstract $intersectionTable
* @param string OPTIONAL $primaryRefRule
* @param string OPTIONAL $matchRefRule
* @return Zend_Db_Table_Rowset_Abstract Query result from $matchTable
* @throws Zend_Db_Table_Row_Exception If $matchTable or $intersectionTable is not a table class or is not loadable.
*/
public function findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null,
$matchRefRule = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($intersectionTable)) {
try {
@Zend_Loader::loadClass($intersectionTable);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$intersectionTable = new $intersectionTable(array('db' => $db));
}
if (! $intersectionTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($intersectionTable);
if ($type == 'object') {
$type = get_class($intersectionTable);
}
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Intersection table must be a Zend_Db_Table_Abstract, but it is $type");
}
if (is_string($matchTable)) {
try {
@Zend_Loader::loadClass($matchTable);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$matchTable = new $matchTable(array('db' => $db));
}
if (! $matchTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($matchTable);
if ($type == 'object') {
$type = get_class($matchTable);
}
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Match table must be a Zend_Db_Table_Abstract, but it is $type");
}
if ($select === null) {
$select = $matchTable->select();
} else {
$select->setTable($matchTable);
}
// Use adapter from intersection table to ensure correct query construction
$interInfo = $intersectionTable->info();
$interDb = $intersectionTable->getAdapter();
$interName = $interInfo['name'];
$interSchema = isset($interInfo['schema']) ? $interInfo['schema'] : null;
$matchInfo = $matchTable->info();
$matchName = $matchInfo['name'];
$matchSchema = isset($matchInfo['schema']) ? $matchInfo['schema'] : null;
$matchMap = $this->_prepareReference($intersectionTable, $matchTable, $matchRefRule);
for ($i = 0; $i < count($matchMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$interCol = $interDb->quoteIdentifier('i' . '.' . $matchMap[Zend_Db_Table_Abstract::COLUMNS][$i], true);
$matchCol = $interDb->quoteIdentifier('m' . '.' . $matchMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i], true);
$joinCond[] = "$interCol = $matchCol";
}
$joinCond = implode(' AND ', $joinCond);
$select->from(array('i' => $interName), Zend_Db_Select::SQL_WILDCARD, $interSchema)
->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
->setIntegrityCheck(false);
$callerMap = $this->_prepareReference($intersectionTable, $this->_getTable(), $callerRefRule);
for ($i = 0; $i < count($callerMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$callerColumnName = $db->foldCase($callerMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$value = $this->_data[$callerColumnName];
$interColumnName = $interDb->foldCase($callerMap[Zend_Db_Table_Abstract::COLUMNS][$i]);
$interCol = $interDb->quoteIdentifier("i.$interColumnName", true);
$interInfo = $intersectionTable->info();
$type = $interInfo[Zend_Db_Table_Abstract::METADATA][$interColumnName]['DATA_TYPE'];
$select->where($interDb->quoteInto("$interCol = ?", $value, $type));
}
$stmt = $select->query();
$config = array(
'table' => $matchTable,
'data' => $stmt->fetchAll(Zend_Db::FETCH_ASSOC),
'rowClass' => $matchTable->getRowClass(),
'readOnly' => false,
'stored' => true
);
$rowsetClass = $matchTable->getRowsetClass();
try {
@Zend_Loader::loadClass($rowsetClass);
} catch (Zend_Exception $e) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception($e->getMessage());
}
$rowset = new $rowsetClass($config);
return $rowset;
}
/**
* Turn magic function calls into non-magic function calls
* to the above methods.
*
* @param string $method
* @param array $args OPTIONAL Zend_Db_Table_Select query modifier
* @return Zend_Db_Table_Row_Abstract|Zend_Db_Table_Rowset_Abstract
* @throws Zend_Db_Table_Row_Exception If an invalid method is called.
*/
public function __call($method, array $args)
{
$matches = array();
if (count($args) && $args[0] instanceof Zend_Db_Table_Select) {
$select = $args[0];
} else {
$select = null;
}
/**
* Recognize methods for Has-Many cases:
* findParent<Class>()
* findParent<Class>By<Rule>()
* Use the non-greedy pattern repeat modifier e.g. \w+?
*/
if (preg_match('/^findParent(\w+?)(?:By(\w+))?$/', $method, $matches)) {
$class = $matches[1];
$ruleKey1 = isset($matches[2]) ? $matches[2] : null;
return $this->findParentRow($class, $ruleKey1, $select);
}
/**
* Recognize methods for Many-to-Many cases:
* find<Class1>Via<Class2>()
* find<Class1>Via<Class2>By<Rule>()
* find<Class1>Via<Class2>By<Rule1>And<Rule2>()
* Use the non-greedy pattern repeat modifier e.g. \w+?
*/
if (preg_match('/^find(\w+?)Via(\w+?)(?:By(\w+?)(?:And(\w+))?)?$/', $method, $matches)) {
$class = $matches[1];
$viaClass = $matches[2];
$ruleKey1 = isset($matches[3]) ? $matches[3] : null;
$ruleKey2 = isset($matches[4]) ? $matches[4] : null;
return $this->findManyToManyRowset($class, $viaClass, $ruleKey1, $ruleKey2, $select);
}
/**
* Recognize methods for Belongs-To cases:
* find<Class>()
* find<Class>By<Rule>()
* Use the non-greedy pattern repeat modifier e.g. \w+?
*/
if (preg_match('/^find(\w+?)(?:By(\w+))?$/', $method, $matches)) {
$class = $matches[1];
$ruleKey1 = isset($matches[2]) ? $matches[2] : null;
return $this->findDependentRowset($class, $ruleKey1, $select);
}
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Unrecognized method '$method()'");
}
}
home/cideo/library/Zend/InfoCard/Xml/EncryptedData/Abstract.php 0000666 00000006057 15125462756 0020404 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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();
}
home/cideo/library/Zend/Feed/Abstract.php 0000666 00000016614 15125470073 0014262 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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();
}
home/cideo/library/Zend/File/Transfer/Adapter/Abstract.php 0000666 00000122050 15125472653 0017440 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/Controller/Router/Route/Abstract.php 0000666 00000003240 15125620215 0020102 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable 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;
}
}
home/cideo/library/Zend/InfoCard/Cipher/Symmetric/Adapter/Abstract.php 0000666 00000002451 15125667103 0021646 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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
{
}
home/cideo/library/Zend/InfoCard/Cipher/Pki/Adapter/Abstract.php 0000666 00000005064 15125667535 0020431 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through 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;
}
}
home/cideo/library/Zend/Server/Reflection/Function/Abstract.php 0000666 00000036647 15125716726 0020564 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Server_Reflection_Exception
*/
require_once 'Zend/Server/Reflection/Exception.php';
/**
* Zend_Server_Reflection_Node
*/
require_once 'Zend/Server/Reflection/Node.php';
/**
* Zend_Server_Reflection_Parameter
*/
require_once 'Zend/Server/Reflection/Parameter.php';
/**
* Zend_Server_Reflection_Prototype
*/
require_once 'Zend/Server/Reflection/Prototype.php';
/**
* Function/Method Reflection
*
* Decorates a ReflectionFunction. Allows setting and retrieving an alternate
* 'service' name (i.e., the name to be used when calling via a service),
* setting and retrieving the description (originally set using the docblock
* contents), retrieving the callback and callback type, retrieving additional
* method invocation arguments, and retrieving the
* method {@link Zend_Server_Reflection_Prototype prototypes}.
*
* @category Zend
* @package Zend_Server
* @subpackage Reflection
* @copyright Copyright (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 12619 2008-11-13 15:24:29Z alexander $
*/
abstract class Zend_Server_Reflection_Function_Abstract
{
/**
* @var ReflectionFunction
*/
protected $_reflection;
/**
* Additional arguments to pass to method on invocation
* @var array
*/
protected $_argv = array();
/**
* Used to store extra configuration for the method (typically done by the
* server class, e.g., to indicate whether or not to instantiate a class).
* Associative array; access is as properties via {@link __get()} and
* {@link __set()}
* @var array
*/
protected $_config = array();
/**
* Declaring class (needed for when serialization occurs)
* @var string
*/
protected $_class;
/**
* Function/method description
* @var string
*/
protected $_description = '';
/**
* Namespace with which to prefix function/method name
* @var string
*/
protected $_namespace;
/**
* Prototypes
* @var array
*/
protected $_prototypes = array();
private $_return;
private $_returnDesc;
private $_paramDesc;
private $_sigParams;
private $_sigParamsDepth;
/**
* Constructor
*
* @param ReflectionFunction $r
*/
public function __construct(Reflector $r, $namespace = null, $argv = array())
{
// In PHP 5.1.x, ReflectionMethod extends ReflectionFunction. In 5.2.x,
// both extend ReflectionFunctionAbstract. So, we can't do normal type
// hinting in the prototype, but instead need to do some explicit
// testing here.
if ((!$r instanceof ReflectionFunction)
&& (!$r instanceof ReflectionMethod)) {
throw new Zend_Server_Reflection_Exception('Invalid reflection class');
}
$this->_reflection = $r;
// Determine namespace
if (null !== $namespace){
$this->setNamespace($namespace);
}
// Determine arguments
if (is_array($argv)) {
$this->_argv = $argv;
}
// If method call, need to store some info on the class
if ($r instanceof ReflectionMethod) {
$this->_class = $r->getDeclaringClass()->getName();
}
// Perform some introspection
$this->_reflect();
}
/**
* Create signature node tree
*
* Recursive method to build the signature node tree. Increments through
* each array in {@link $_sigParams}, adding every value of the next level
* to the current value (unless the current value is null).
*
* @param Zend_Server_Reflection_Node $parent
* @param int $level
* @return void
*/
protected function _addTree(Zend_Server_Reflection_Node $parent, $level = 0)
{
if ($level >= $this->_sigParamsDepth) {
return;
}
foreach ($this->_sigParams[$level] as $value) {
$node = new Zend_Server_Reflection_Node($value, $parent);
if ((null !== $value) && ($this->_sigParamsDepth > $level + 1)) {
$this->_addTree($node, $level + 1);
}
}
}
/**
* Build the signature tree
*
* Builds a signature tree starting at the return values and descending
* through each method argument. Returns an array of
* {@link Zend_Server_Reflection_Node}s.
*
* @return array
*/
protected function _buildTree()
{
$returnTree = array();
foreach ((array) $this->_return as $value) {
$node = new Zend_Server_Reflection_Node($value);
$this->_addTree($node);
$returnTree[] = $node;
}
return $returnTree;
}
/**
* Build method signatures
*
* Builds method signatures using the array of return types and the array of
* parameters types
*
* @param array $return Array of return types
* @param string $returnDesc Return value description
* @param array $params Array of arguments (each an array of types)
* @param array $paramDesc Array of parameter descriptions
* @return array
*/
protected function _buildSignatures($return, $returnDesc, $paramTypes, $paramDesc)
{
$this->_return = $return;
$this->_returnDesc = $returnDesc;
$this->_paramDesc = $paramDesc;
$this->_sigParams = $paramTypes;
$this->_sigParamsDepth = count($paramTypes);
$signatureTrees = $this->_buildTree();
$signatures = array();
$endPoints = array();
foreach ($signatureTrees as $root) {
$tmp = $root->getEndPoints();
if (empty($tmp)) {
$endPoints = array_merge($endPoints, array($root));
} else {
$endPoints = array_merge($endPoints, $tmp);
}
}
foreach ($endPoints as $node) {
if (!$node instanceof Zend_Server_Reflection_Node) {
continue;
}
$signature = array();
do {
array_unshift($signature, $node->getValue());
$node = $node->getParent();
} while ($node instanceof Zend_Server_Reflection_Node);
$signatures[] = $signature;
}
// Build prototypes
$params = $this->_reflection->getParameters();
foreach ($signatures as $signature) {
$return = new Zend_Server_Reflection_ReturnValue(array_shift($signature), $this->_returnDesc);
$tmp = array();
foreach ($signature as $key => $type) {
$param = new Zend_Server_Reflection_Parameter($params[$key], $type, $this->_paramDesc[$key]);
$param->setPosition($key);
$tmp[] = $param;
}
$this->_prototypes[] = new Zend_Server_Reflection_Prototype($return, $tmp);
}
}
/**
* Use code reflection to create method signatures
*
* Determines the method help/description text from the function DocBlock
* comment. Determines method signatures using a combination of
* ReflectionFunction and parsing of DocBlock @param and @return values.
*
* @param ReflectionFunction $function
* @return array
*/
protected function _reflect()
{
$function = $this->_reflection;
$helpText = '';
$signatures = array();
$returnDesc = '';
$paramCount = $function->getNumberOfParameters();
$paramCountRequired = $function->getNumberOfRequiredParameters();
$parameters = $function->getParameters();
$docBlock = $function->getDocComment();
if (!empty($docBlock)) {
// Get help text
if (preg_match(':/\*\*\s*\r?\n\s*\*\s(.*?)\r?\n\s*\*(\s@|/):s', $docBlock, $matches))
{
$helpText = $matches[1];
$helpText = preg_replace('/(^\s*\*\s)/m', '', $helpText);
$helpText = preg_replace('/\r?\n\s*\*\s*(\r?\n)*/s', "\n", $helpText);
$helpText = trim($helpText);
}
// Get return type(s) and description
$return = 'void';
if (preg_match('/@return\s+(\S+)/', $docBlock, $matches)) {
$return = explode('|', $matches[1]);
if (preg_match('/@return\s+\S+\s+(.*?)(@|\*\/)/s', $docBlock, $matches))
{
$value = $matches[1];
$value = preg_replace('/\s?\*\s/m', '', $value);
$value = preg_replace('/\s{2,}/', ' ', $value);
$returnDesc = trim($value);
}
}
// Get param types and description
if (preg_match_all('/@param\s+([^\s]+)/m', $docBlock, $matches)) {
$paramTypesTmp = $matches[1];
if (preg_match_all('/@param\s+\S+\s+(\$^\S+)\s+(.*?)(@|\*\/)/s', $docBlock, $matches))
{
$paramDesc = $matches[2];
foreach ($paramDesc as $key => $value) {
$value = preg_replace('/\s?\*\s/m', '', $value);
$value = preg_replace('/\s{2,}/', ' ', $value);
$paramDesc[$key] = trim($value);
}
}
}
} else {
$helpText = $function->getName();
$return = 'void';
}
// Set method description
$this->setDescription($helpText);
// Get all param types as arrays
if (!isset($paramTypesTmp) && (0 < $paramCount)) {
$paramTypesTmp = array_fill(0, $paramCount, 'mixed');
} elseif (!isset($paramTypesTmp)) {
$paramTypesTmp = array();
} elseif (count($paramTypesTmp) < $paramCount) {
$start = $paramCount - count($paramTypesTmp);
for ($i = $start; $i < $paramCount; ++$i) {
$paramTypesTmp[$i] = 'mixed';
}
}
// Get all param descriptions as arrays
if (!isset($paramDesc) && (0 < $paramCount)) {
$paramDesc = array_fill(0, $paramCount, '');
} elseif (!isset($paramDesc)) {
$paramDesc = array();
} elseif (count($paramDesc) < $paramCount) {
$start = $paramCount - count($paramDesc);
for ($i = $start; $i < $paramCount; ++$i) {
$paramDesc[$i] = '';
}
}
if (count($paramTypesTmp) != $paramCount) {
throw new Zend_Server_Reflection_Exception(
'Variable number of arguments is not supported for services (except optional parameters). '
. 'Number of function arguments must currespond to actual number of arguments described in a docblock.');
}
$paramTypes = array();
foreach ($paramTypesTmp as $i => $param) {
$tmp = explode('|', $param);
if ($parameters[$i]->isOptional()) {
array_unshift($tmp, null);
}
$paramTypes[] = $tmp;
}
$this->_buildSignatures($return, $returnDesc, $paramTypes, $paramDesc);
}
/**
* Proxy reflection calls
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if (method_exists($this->_reflection, $method)) {
return call_user_func_array(array($this->_reflection, $method), $args);
}
throw new Zend_Server_Reflection_Exception('Invalid reflection method ("' .$method. '")');
}
/**
* Retrieve configuration parameters
*
* Values are retrieved by key from {@link $_config}. Returns null if no
* value found.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (isset($this->_config[$key])) {
return $this->_config[$key];
}
return null;
}
/**
* Set configuration parameters
*
* Values are stored by $key in {@link $_config}.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set($key, $value)
{
$this->_config[$key] = $value;
}
/**
* Set method's namespace
*
* @param string $namespace
* @return void
*/
public function setNamespace($namespace)
{
if (empty($namespace)) {
$this->_namespace = '';
return;
}
if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
throw new Zend_Server_Reflection_Exception('Invalid namespace');
}
$this->_namespace = $namespace;
}
/**
* Return method's namespace
*
* @return string
*/
public function getNamespace()
{
return $this->_namespace;
}
/**
* Set the description
*
* @param string $string
* @return void
*/
public function setDescription($string)
{
if (!is_string($string)) {
throw new Zend_Server_Reflection_Exception('Invalid description');
}
$this->_description = $string;
}
/**
* Retrieve the description
*
* @return void
*/
public function getDescription()
{
return $this->_description;
}
/**
* Retrieve all prototypes as array of
* {@link Zend_Server_Reflection_Prototype Zend_Server_Reflection_Prototypes}
*
* @return array
*/
public function getPrototypes()
{
return $this->_prototypes;
}
/**
* Retrieve additional invocation arguments
*
* @return array
*/
public function getInvokeArguments()
{
return $this->_argv;
}
/**
* Wakeup from serialization
*
* Reflection needs explicit instantiation to work correctly. Re-instantiate
* reflection object on wakeup.
*
* @return void
*/
public function __wakeup()
{
if ($this->_reflection instanceof ReflectionMethod) {
$class = new ReflectionClass($this->_class);
$this->_reflection = new ReflectionMethod($class->newInstance(), $this->getName());
} else {
$this->_reflection = new ReflectionFunction($this->getName());
}
}
}