3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\File\Transfer
;
13 * Base class for all protocols supporting file transfers
19 * Array holding all directions
23 protected $adapter = array();
26 * Creates a file processing handler
28 * @param string $adapter Adapter to use
29 * @param bool $direction OPTIONAL False means Download, true means upload
30 * @param array $options OPTIONAL Options to set for this adapter
31 * @throws Exception\InvalidArgumentException
33 public function __construct($adapter = 'Http', $direction = false, $options = array())
35 $this->setAdapter($adapter, $direction, $options);
41 * @param string $adapter Adapter to use
42 * @param bool $direction OPTIONAL False means Download, true means upload
43 * @param array $options OPTIONAL Options to set for this adapter
45 * @throws Exception\InvalidArgumentException
47 public function setAdapter($adapter, $direction = false, $options = array())
49 if (!is_string($adapter)) {
50 throw new Exception\
InvalidArgumentException('Adapter must be a string');
53 if ($adapter[0] != '\\') {
54 $adapter = '\Zend\File\Transfer\Adapter\\' . ucfirst($adapter);
57 $direction = (int) $direction;
58 $this->adapter
[$direction] = new $adapter($options);
59 if (!$this->adapter
[$direction] instanceof Adapter\AbstractAdapter
) {
60 throw new Exception\
InvalidArgumentException(
61 'Adapter ' . $adapter . ' does not extend Zend\File\Transfer\Adapter\AbstractAdapter'
69 * Returns all set adapters
71 * @param bool $direction On null, all directions are returned
72 * On false, download direction is returned
73 * On true, upload direction is returned
74 * @return array|Adapter\AbstractAdapter
76 public function getAdapter($direction = null)
78 if ($direction === null) {
79 return $this->adapter
;
82 $direction = (int) $direction;
83 return $this->adapter
[$direction];
87 * Calls all methods from the adapter
89 * @param string $method Method to call
90 * @param array $options Options for this method
91 * @throws Exception\BadMethodCallException if unknown method
94 public function __call($method, array $options)
96 if (array_key_exists('direction', $options)) {
97 $direction = (int) $options['direction'];
102 if (method_exists($this->adapter
[$direction], $method)) {
103 return call_user_func_array(array($this->adapter
[$direction], $method), $options);
106 throw new Exception\
BadMethodCallException("Unknown method '" . $method . "' called!");