[DOCS] fixed code comment in one programlisting
[zend/radio.git] / library / Zend / File / Transfer.php
bloba82600cf7e6e549f335c97182ba0aef279357bee
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
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$
22 /**
23 * @see Zend_Loader
25 require_once 'Zend/Loader.php';
27 /**
28 * Base class for all protocols supporting file transfers
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
35 class Zend_File_Transfer
37 /**
38 * Array holding all directions
40 * @var array
42 protected $_adapter = array();
44 /**
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);
57 /**
58 * Sets a new adapter
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");
82 return $this;
85 /**
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
108 * @return mixed
110 public function __call($method, array $options)
112 if (array_key_exists('direction', $options)) {
113 $direction = (integer) $options['direction'];
114 } else {
115 $direction = 0;
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!");