PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phing/phing/classes/phing/util/ExtendedFileStream.php

https://gitlab.com/Isaki/le331.fr
PHP | 194 lines | 149 code | 7 blank | 38 comment | 4 complexity | eb0e855705fad0578ff0f7612bc3fbfb MD5 | raw file
  1. <?php
  2. include_once 'phing/system/io/PhingFile.php';
  3. /**
  4. * $Id: 9f3deadd6a2b93620d27fe8959f9f688b4c58171 $
  5. *
  6. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. *
  18. * This software consists of voluntary contributions made by many individuals
  19. * and is licensed under the LGPL. For more information please see
  20. * <http://phing.info>.
  21. */
  22. /**
  23. * Extended file stream wrapper class which auto-creates directories
  24. *
  25. * @author Michiel Rook <mrook@php.net>
  26. * @version $Id: 9f3deadd6a2b93620d27fe8959f9f688b4c58171 $
  27. * @package phing.util
  28. */
  29. class ExtendedFileStream
  30. {
  31. private $fp = null;
  32. public static function registerStream()
  33. {
  34. if (!in_array("efile", stream_get_wrappers())) {
  35. stream_wrapper_register("efile", "ExtendedFileStream");
  36. }
  37. }
  38. public static function unregisterStream()
  39. {
  40. stream_wrapper_unregister("efile");
  41. }
  42. /**
  43. * @param $path
  44. */
  45. private function createDirectories($path)
  46. {
  47. $f = new PhingFile($path);
  48. if (!$f->exists()) {
  49. $f->mkdirs();
  50. }
  51. }
  52. /**
  53. * @param $path
  54. * @param $mode
  55. * @param $options
  56. * @param $opened_path
  57. * @return bool
  58. * @throws IOException
  59. */
  60. public function stream_open($path, $mode, $options, &$opened_path)
  61. {
  62. // if we're on Windows, urldecode() the path again
  63. if (FileSystem::getFileSystem()->getSeparator() == '\\') {
  64. $path = urldecode($path);
  65. }
  66. $filepath = substr($path, 8);
  67. $this->createDirectories(dirname($filepath));
  68. $this->fp = fopen($filepath, $mode);
  69. if (! $this->fp) {
  70. throw new BuildException("Unable to open stream for path {$path}");
  71. }
  72. return true;
  73. }
  74. public function stream_close()
  75. {
  76. fclose($this->fp);
  77. $this->fp = null;
  78. }
  79. /**
  80. * @param $count
  81. * @return string
  82. */
  83. public function stream_read($count)
  84. {
  85. return fread($this->fp, $count);
  86. }
  87. /**
  88. * @param $data
  89. * @return int
  90. */
  91. public function stream_write($data)
  92. {
  93. return fwrite($this->fp, $data);
  94. }
  95. /**
  96. * @return bool
  97. */
  98. public function stream_eof()
  99. {
  100. return feof($this->fp);
  101. }
  102. /**
  103. * @return int
  104. */
  105. public function stream_tell()
  106. {
  107. return ftell($this->fp);
  108. }
  109. /**
  110. * @param $offset
  111. * @param $whence
  112. * @return int
  113. */
  114. public function stream_seek($offset, $whence)
  115. {
  116. return fseek($this->fp, $offset, $whence);
  117. }
  118. /**
  119. * @return bool
  120. */
  121. public function stream_flush()
  122. {
  123. return fflush($this->fp);
  124. }
  125. /**
  126. * @return array
  127. */
  128. public function stream_stat()
  129. {
  130. return fstat($this->fp);
  131. }
  132. /**
  133. * @param $path
  134. * @return bool
  135. */
  136. public function unlink($path)
  137. {
  138. return false;
  139. }
  140. /**
  141. * @param $path_from
  142. * @param $path_to
  143. * @return bool
  144. */
  145. public function rename($path_from, $path_to)
  146. {
  147. return false;
  148. }
  149. /**
  150. * @param $path
  151. * @param $mode
  152. * @param $options
  153. * @return bool
  154. */
  155. public function mkdir($path, $mode, $options)
  156. {
  157. return false;
  158. }
  159. /**
  160. * @param $path
  161. * @param $options
  162. * @return bool
  163. */
  164. public function rmdir($path, $options)
  165. {
  166. return false;
  167. }
  168. }
  169. ;