|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
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. |
|
14 * |
|
15 * @category Zend |
|
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 |
|
19 * @version $Id: Transfer.php 21201 2010-02-24 22:13:20Z thomas $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Loader |
|
24 */ |
|
25 require_once 'Zend/Loader.php'; |
|
26 |
|
27 /** |
|
28 * Base class for all protocols supporting file transfers |
|
29 * |
|
30 * @category Zend |
|
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 |
|
34 */ |
|
35 class Zend_File_Transfer |
|
36 { |
|
37 /** |
|
38 * Array holding all directions |
|
39 * |
|
40 * @var array |
|
41 */ |
|
42 protected $_adapter = array(); |
|
43 |
|
44 /** |
|
45 * Creates a file processing handler |
|
46 * |
|
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 |
|
51 */ |
|
52 public function __construct($adapter = 'Http', $direction = false, $options = array()) |
|
53 { |
|
54 $this->setAdapter($adapter, $direction, $options); |
|
55 } |
|
56 |
|
57 /** |
|
58 * Sets a new adapter |
|
59 * |
|
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 |
|
64 */ |
|
65 public function setAdapter($adapter, $direction = false, $options = array()) |
|
66 { |
|
67 if (Zend_Loader::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter). '.php')) { |
|
68 $adapter = 'Zend_File_Transfer_Adapter_' . ucfirst($adapter); |
|
69 } |
|
70 |
|
71 if (!class_exists($adapter)) { |
|
72 Zend_Loader::loadClass($adapter); |
|
73 } |
|
74 |
|
75 $direction = (integer) $direction; |
|
76 $this->_adapter[$direction] = new $adapter($options); |
|
77 if (!$this->_adapter[$direction] instanceof Zend_File_Transfer_Adapter_Abstract) { |
|
78 require_once 'Zend/File/Transfer/Exception.php'; |
|
79 throw new Zend_File_Transfer_Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter_Abstract"); |
|
80 } |
|
81 |
|
82 return $this; |
|
83 } |
|
84 |
|
85 /** |
|
86 * Returns all set adapters |
|
87 * |
|
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 |
|
92 */ |
|
93 public function getAdapter($direction = null) |
|
94 { |
|
95 if ($direction === null) { |
|
96 return $this->_adapter; |
|
97 } |
|
98 |
|
99 $direction = (integer) $direction; |
|
100 return $this->_adapter[$direction]; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Calls all methods from the adapter |
|
105 * |
|
106 * @param string $method Method to call |
|
107 * @param array $options Options for this method |
|
108 * @return mixed |
|
109 */ |
|
110 public function __call($method, array $options) |
|
111 { |
|
112 if (array_key_exists('direction', $options)) { |
|
113 $direction = (integer) $options['direction']; |
|
114 } else { |
|
115 $direction = 0; |
|
116 } |
|
117 |
|
118 if (method_exists($this->_adapter[$direction], $method)) { |
|
119 return call_user_func_array(array($this->_adapter[$direction], $method), $options); |
|
120 } |
|
121 |
|
122 require_once 'Zend/File/Transfer/Exception.php'; |
|
123 throw new Zend_File_Transfer_Exception("Unknown method '" . $method . "' called!"); |
|
124 } |
|
125 } |