functions.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. namespace Gaufrette\Adapter;
  3. global $createdDirectory;
  4. function ftp_delete($connection, $path)
  5. {
  6. if ($path === '/home/l3l0/invalid') {
  7. return false;
  8. }
  9. return true;
  10. }
  11. function ftp_mdtm($connection, $path)
  12. {
  13. if ($path === '/home/l3l0/invalid') {
  14. return -1;
  15. }
  16. return \strtotime('2010-10-10 23:10:10');
  17. }
  18. function ftp_rename($connection, $from, $to)
  19. {
  20. return ! ('/home/l3l0/invalid' === $from or '/home/l3l0/invalid' === $to);
  21. }
  22. function ftp_fput($connection, $path, $fileResource, $mode)
  23. {
  24. if ('/home/l3l0/filename' === $path) {
  25. return true;
  26. }
  27. return false;
  28. }
  29. function ftp_fget($connection, &$fileResource, $path, $mode)
  30. {
  31. if ('/home/l3l0/filename' === $path) {
  32. $bytes = \fwrite($fileResource, 'some content');
  33. return true;
  34. }
  35. return false;
  36. }
  37. function ftp_chdir($connection, $dirname)
  38. {
  39. if (in_array($dirname, array('/home/l3l0', '/home/l3l0/aaa', '/home/l3l0/relative', '/home/l3l0/relative/some', '/home/l3l1', '/home/l3l2', '/home/l3l2/a b c d -> žežulička', '/home/l3l3', 'C:\Ftp'))) {
  40. return true;
  41. }
  42. global $createdDirectory;
  43. if ($createdDirectory && $createdDirectory === $dirname) {
  44. return true;
  45. }
  46. trigger_error(sprintf('%s: No such file or directory', $dirname), E_USER_WARNING);
  47. return false;
  48. }
  49. function ftp_mkdir($connection, $dirname)
  50. {
  51. if (in_array($dirname, array('/home/l3l0/new'))) {
  52. global $createdDirectory;
  53. $createdDirectory = $dirname;
  54. return true;
  55. }
  56. return false;
  57. }
  58. function ftp_connect($host, $port = 21, $timeout = 90)
  59. {
  60. if ('localhost' !== $host) {
  61. return false;
  62. }
  63. return fopen('php://temp', 'r');
  64. }
  65. function ftp_close($connection)
  66. {
  67. return fclose($connection);
  68. }
  69. function ftp_rawlist($connection, $directory, $recursive = false)
  70. {
  71. $arguments = explode(' ', $directory, 2);
  72. if ('/home/l3l0' === end($arguments))
  73. {
  74. return array(
  75. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  76. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  77. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa",
  78. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  79. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe",
  80. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess",
  81. "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www -> aaa",
  82. "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb",
  83. );
  84. }
  85. if ('/home/l3l0/aaa' === end($arguments))
  86. {
  87. return array(
  88. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  89. );
  90. }
  91. if ('/home/l3l0/relative' === end($arguments))
  92. {
  93. return array(
  94. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  95. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some",
  96. );
  97. }
  98. if ('/home/l3l0/relative/some' === end($arguments))
  99. {
  100. return array(
  101. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename",
  102. );
  103. }
  104. if ('/home/l3l1' === end($arguments) && 0 === strpos(reset($arguments), '-al'))
  105. {
  106. return array(
  107. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  108. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  109. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  110. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess",
  111. );
  112. }
  113. if ('/home/l3l1' === end($arguments) && false === strpos(reset($arguments), '-al'))
  114. {
  115. return array(
  116. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  117. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  118. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  119. );
  120. }
  121. if ('/home/l3l2' === end($arguments))
  122. {
  123. return array(
  124. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  125. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  126. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 a b c d -> žežulička",
  127. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 Žľuťoučký kůň.pdf",
  128. );
  129. }
  130. if ('/home/l3l2/a b c d -> žežulička' === end($arguments))
  131. {
  132. return array(
  133. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  134. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  135. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 do re mi.pdf",
  136. );
  137. }
  138. if ('/home/l3l3' === end($arguments) && '-alR' === reset($arguments))
  139. {
  140. return array(
  141. "/home/l3l3:",
  142. "total: 12",
  143. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  144. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  145. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 aaa",
  146. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  147. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename.exe",
  148. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .htaccess",
  149. "drwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 www",
  150. "lrwxrwxrwx 1 vincent vincent 11 Jul 12 12:16 vendor -> bbb",
  151. "",
  152. "/home/l3l3/aaa:",
  153. "total: 8",
  154. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  155. "",
  156. "/home/l3l3/www:",
  157. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  158. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  159. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 filename",
  160. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 some",
  161. "",
  162. "/home/l3l3/www/some:",
  163. "total 5",
  164. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 .",
  165. "drwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 ..",
  166. "-rwxr-x--- 15 vincent vincent 4096 Nov 3 21:31 otherfilename",
  167. );
  168. }
  169. // https://github.com/KnpLabs/Gaufrette/issues/147
  170. if ('C:\Ftp' === end($arguments))
  171. {
  172. return array(
  173. "05-26-12 08:03PM <DIR> archive",
  174. "12-04-12 06:57PM 16142 file1.zip",
  175. "12-05-12 04:01PM 16142 file2.zip",
  176. );
  177. }
  178. return array();
  179. }
  180. function ftp_login($connection, $username, $password)
  181. {
  182. if ('invalid' === $username) {
  183. return false;
  184. }
  185. return true;
  186. }
  187. function time()
  188. {
  189. return \strtotime('2012-10-10 23:10:10');
  190. }
  191. function file_exists($path)
  192. {
  193. //fake it for ssh+ssl: protocol for SFTP testing, otherwise delegate to global
  194. if (strpos($path, 'ssh+ssl:') === 0) {
  195. return in_array($path, array('/home/l3l0/filename', '/home/somedir/filename', 'ssh+ssl://localhost/home/l3l0/filename')) ? true : false;
  196. }
  197. return \file_exists($path);
  198. }
  199. function extension_loaded($name)
  200. {
  201. global $extensionLoaded;
  202. if (is_null($extensionLoaded)) {
  203. return true;
  204. }
  205. return $extensionLoaded;
  206. }
  207. function opendir($url)
  208. {
  209. return true;
  210. }
  211. function apc_fetch($path)
  212. {
  213. return sprintf('%s content', $path);
  214. }
  215. function apc_store($path, $content, $ttl)
  216. {
  217. if ('prefix-apc-test/invalid' === $path) {
  218. return false;
  219. }
  220. return sprintf('%s content', $path);
  221. }
  222. function apc_delete($path)
  223. {
  224. if ('prefix-apc-test/invalid' === $path) {
  225. return false;
  226. }
  227. return true;
  228. }
  229. function apc_exists($path)
  230. {
  231. if ('prefix-apc-test/invalid' === $path) {
  232. return false;
  233. }
  234. return true;
  235. }