7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_File_Transfer
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
25 require_once 'Zend/Loader.php';
28 * Base class for all protocols supporting file transfers
31 * @package Zend_File_Transfer
32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_File_Transfer
38 * Array holding all directions
42 protected $_adapter = array();
45 * Creates a file processing handler
47 * @param string $adapter Adapter to use
48 * @param boolean $direction OPTIONAL False means Download, true means upload
49 * @param array $options OPTIONAL Options to set for this adapter
50 * @throws Zend_File_Transfer_Exception
52 public function __construct($adapter = 'Http', $direction = false, $options = array())
54 $this->setAdapter($adapter, $direction, $options);
60 * @param string $adapter Adapter to use
61 * @param boolean $direction OPTIONAL False means Download, true means upload
62 * @param array $options OPTIONAL Options to set for this adapter
63 * @throws Zend_File_Transfer_Exception
65 public function setAdapter($adapter, $direction = false, $options = array())
67 if (Zend_Loader
::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter). '.php')) {
68 $adapter = 'Zend_File_Transfer_Adapter_' . ucfirst($adapter);
71 if (!class_exists($adapter)) {
72 Zend_Loader
::loadClass($adapter);
75 $direction = (integer) $direction;
76 $this->_adapter
[$direction] = new $adapter($options);
77 if (!$this->_adapter
[$direction] instanceof Zend_File_Transfer_Adapter
) {
78 require_once 'Zend/File/Transfer/Exception.php';
79 throw new Zend_File_Transfer_Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter");
86 * Returns all set adapters
88 * @param boolean $direction On null, all directions are returned
89 * On false, download direction is returned
90 * On true, upload direction is returned
91 * @return array|Zend_File_Transfer_Adapter
93 public function getAdapter($direction = null)
95 if ($direction === null) {
96 return $this->_adapter
;
99 $direction = (integer) $direction;
100 return $this->_adapter
[$direction];
104 * Calls all methods from the adapter
106 * @param string $method Method to call
107 * @param array $options Options for this method
110 public function __call($method, array $options)
112 if (array_key_exists('direction', $options)) {
113 $direction = (integer) $options['direction'];
118 if (method_exists($this->_adapter
[$direction], $method)) {
119 return call_user_func_array(array($this->_adapter
[$direction], $method), $options);
122 require_once 'Zend/File/Transfer/Exception.php';
123 throw new Zend_File_Transfer_Exception("Unknown method '" . $method . "' called!");