1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage dispatcher
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8 // Protect from unauthorized access
9 defined('FOF_INCLUDED') or die;
10
11 /**
12 * Abstract base class for download adapters
13 */
14 abstract class FOFDownloadAdapterAbstract implements FOFDownloadInterface
15 {
16 public $priority = 100;
17
18 public $name = '';
19
20 public $isSupported = false;
21
22 public $supportsChunkDownload = false;
23
24 public $supportsFileSize = false;
25
26 /**
27 * Does this download adapter support downloading files in chunks?
28 *
29 * @return boolean True if chunk download is supported
30 */
31 public function supportsChunkDownload()
32 {
33 return $this->supportsChunkDownload;
34 }
35
36 /**
37 * Does this download adapter support reading the size of a remote file?
38 *
39 * @return boolean True if remote file size determination is supported
40 */
41 public function supportsFileSize()
42 {
43 return $this->supportsFileSize;
44 }
45
46 /**
47 * Is this download class supported in the current server environment?
48 *
49 * @return boolean True if this server environment supports this download class
50 */
51 public function isSupported()
52 {
53 return $this->isSupported;
54 }
55
56 /**
57 * Get the priority of this adapter. If multiple download adapters are
58 * supported on a site, the one with the highest priority will be
59 * used.
60 *
61 * @return boolean
62 */
63 public function getPriority()
64 {
65 return $this->priority;
66 }
67
68 /**
69 * Returns the name of this download adapter in use
70 *
71 * @return string
72 */
73 public function getName()
74 {
75 return $this->name;
76 }
77
78 /**
79 * Download a part (or the whole) of a remote URL and return the downloaded
80 * data. You are supposed to check the size of the returned data. If it's
81 * smaller than what you expected you've reached end of file. If it's empty
82 * you have tried reading past EOF. If it's larger than what you expected
83 * the server doesn't support chunk downloads.
84 *
85 * If this class' supportsChunkDownload returns false you should assume
86 * that the $from and $to parameters will be ignored.
87 *
88 * @param string $url The remote file's URL
89 * @param integer $from Byte range to start downloading from. Use null for start of file.
90 * @param integer $to Byte range to stop downloading. Use null to download the entire file ($from is ignored)
91 * @param array $params Additional params that will be added before performing the download
92 *
93 * @return string The raw file data retrieved from the remote URL.
94 *
95 * @throws Exception A generic exception is thrown on error
96 */
97 public function downloadAndReturn($url, $from = null, $to = null, array $params = array())
98 {
99 return '';
100 }
101
102 /**
103 * Get the size of a remote file in bytes
104 *
105 * @param string $url The remote file's URL
106 *
107 * @return integer The file size, or -1 if the remote server doesn't support this feature
108 */
109 public function getFileSize($url)
110 {
111 return -1;
112 }
113 }