Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / File / Transfer / Transfer.php
blobd480d49c8c773c3d144ad54e8618d12197ab19f9
1 <?php
2 /**
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
8 */
10 namespace Zend\File\Transfer;
12 /**
13 * Base class for all protocols supporting file transfers
16 class Transfer
18 /**
19 * Array holding all directions
21 * @var array
23 protected $adapter = array();
25 /**
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);
38 /**
39 * Sets a new adapter
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
44 * @return Transfer
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'
65 return $this;
68 /**
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];
86 /**
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
92 * @return mixed
94 public function __call($method, array $options)
96 if (array_key_exists('direction', $options)) {
97 $direction = (int) $options['direction'];
98 } else {
99 $direction = 0;
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!");