functions.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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, $password)
  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 file_get_contents($path)
  188. {
  189. return sprintf('%s content', $path);
  190. }
  191. function time()
  192. {
  193. return \strtotime('2012-10-10 23:10:10');
  194. }
  195. function file_put_contents($path, $content)
  196. {
  197. return strlen($content);
  198. }
  199. function rename($from, $to)
  200. {
  201. return $from.' to '.$to;
  202. }
  203. function file_exists($path)
  204. {
  205. return in_array($path, array('/home/l3l0/filename', '/home/somedir/filename', 'ssh+ssl://localhost/home/l3l0/filename')) ? true : false;
  206. }
  207. function iterator_to_array($iterator)
  208. {
  209. global $iteratorToArray;
  210. return $iteratorToArray;
  211. }
  212. function extension_loaded($name)
  213. {
  214. global $extensionLoaded;
  215. if (is_null($extensionLoaded)) {
  216. return true;
  217. }
  218. return $extensionLoaded;
  219. }
  220. function opendir($url)
  221. {
  222. return true;
  223. }
  224. function filemtime($key)
  225. {
  226. return 12345;
  227. }
  228. function unlink($key)
  229. {
  230. return in_array($key, array('/home/l3l0/filename', '/home/somedir/filename')) ? true : false;
  231. }
  232. function is_dir($key)
  233. {
  234. return (in_array($key, array('/home/l3l0', '/home/l3l0/dir', '/home/somedir', '/home/somedir/dir', '/home/l3l1'))) ? true : false;
  235. }
  236. function realpath($link)
  237. {
  238. return ('symbolicLink' === $link) ? '/home/somedir' : $link;
  239. }
  240. function is_link($link)
  241. {
  242. return ('symbolicLink' === $link) ? true : false;
  243. }
  244. function mkdir($directory, $mode, $recursive)
  245. {
  246. return (in_array($directory, array('/home/other', '/home/somedir/aaa'))) ? true : false;
  247. }
  248. function apc_fetch($path)
  249. {
  250. return sprintf('%s content', $path);
  251. }
  252. function apc_store($path, $content, $ttl)
  253. {
  254. if ('prefix-apc-test/invalid' === $path) {
  255. return false;
  256. }
  257. return sprintf('%s content', $path);
  258. }
  259. function apc_delete($path)
  260. {
  261. if ('prefix-apc-test/invalid' === $path) {
  262. return false;
  263. }
  264. return true;
  265. }
  266. function apc_exists($path)
  267. {
  268. if ('prefix-apc-test/invalid' === $path) {
  269. return false;
  270. }
  271. return true;
  272. }