File indexing completed on 2024-12-22 05:36:41
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_File_Transfer 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Loader 0024 */ 0025 // require_once 'Zend/Loader.php'; 0026 0027 /** 0028 * Base class for all protocols supporting file transfers 0029 * 0030 * @category Zend 0031 * @package Zend_File_Transfer 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_File_Transfer 0036 { 0037 /** 0038 * Array holding all directions 0039 * 0040 * @var array 0041 */ 0042 protected $_adapter = array(); 0043 0044 /** 0045 * Creates a file processing handler 0046 * 0047 * @param string $adapter Adapter to use 0048 * @param boolean $direction OPTIONAL False means Download, true means upload 0049 * @param array $options OPTIONAL Options to set for this adapter 0050 * @throws Zend_File_Transfer_Exception 0051 */ 0052 public function __construct($adapter = 'Http', $direction = false, $options = array()) 0053 { 0054 $this->setAdapter($adapter, $direction, $options); 0055 } 0056 0057 /** 0058 * Sets a new adapter 0059 * 0060 * @param string $adapter Adapter to use 0061 * @param boolean $direction OPTIONAL False means Download, true means upload 0062 * @param array $options OPTIONAL Options to set for this adapter 0063 * @throws Zend_File_Transfer_Exception 0064 */ 0065 public function setAdapter($adapter, $direction = false, $options = array()) 0066 { 0067 if (Zend_Loader::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter). '.php')) { 0068 $adapter = 'Zend_File_Transfer_Adapter_' . ucfirst($adapter); 0069 } 0070 0071 if (!class_exists($adapter)) { 0072 Zend_Loader::loadClass($adapter); 0073 } 0074 0075 $direction = (integer) $direction; 0076 $this->_adapter[$direction] = new $adapter($options); 0077 if (!$this->_adapter[$direction] instanceof Zend_File_Transfer_Adapter_Abstract) { 0078 // require_once 'Zend/File/Transfer/Exception.php'; 0079 throw new Zend_File_Transfer_Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter_Abstract"); 0080 } 0081 0082 return $this; 0083 } 0084 0085 /** 0086 * Returns all set adapters 0087 * 0088 * @param boolean $direction On null, all directions are returned 0089 * On false, download direction is returned 0090 * On true, upload direction is returned 0091 * @return array|Zend_File_Transfer_Adapter 0092 */ 0093 public function getAdapter($direction = null) 0094 { 0095 if ($direction === null) { 0096 return $this->_adapter; 0097 } 0098 0099 $direction = (integer) $direction; 0100 return $this->_adapter[$direction]; 0101 } 0102 0103 /** 0104 * Calls all methods from the adapter 0105 * 0106 * @param string $method Method to call 0107 * @param array $options Options for this method 0108 * @return mixed 0109 */ 0110 public function __call($method, array $options) 0111 { 0112 if (array_key_exists('direction', $options)) { 0113 $direction = (integer) $options['direction']; 0114 } else { 0115 $direction = 0; 0116 } 0117 0118 if (method_exists($this->_adapter[$direction], $method)) { 0119 return call_user_func_array(array($this->_adapter[$direction], $method), $options); 0120 } 0121 0122 // require_once 'Zend/File/Transfer/Exception.php'; 0123 throw new Zend_File_Transfer_Exception("Unknown method '" . $method . "' called!"); 0124 } 0125 }