home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / util / ExtendedFileStream.php < prev    next >
Encoding:
PHP Script  |  2006-09-14  |  2.8 KB  |  133 lines

  1. <?php
  2.  
  3.     include_once 'phing/system/io/PhingFile.php';
  4.  
  5.     /**
  6.      * $Id: ExtendedFileStream.php 123 2006-09-14 20:19:08Z mrook $
  7.      *
  8.      * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  9.      * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  10.      * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  11.      * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  12.      * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  13.      * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  14.      * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  15.      * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  16.      * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17.      * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  18.      * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19.      *
  20.      * This software consists of voluntary contributions made by many individuals
  21.      * and is licensed under the LGPL. For more information please see
  22.      * <http://phing.info>.
  23.      */
  24.  
  25.     /**
  26.      * Extended file stream wrapper class which auto-creates directories
  27.      *
  28.      * @author Michiel Rook <michiel.rook@gmail.com>
  29.      * @version $Id: ExtendedFileStream.php 123 2006-09-14 20:19:08Z mrook $
  30.      * @package phing.util
  31.      */
  32.     class ExtendedFileStream
  33.     {
  34.         private $fp = NULL;
  35.         
  36.         static function registerStream()
  37.         {
  38.             if (!in_array("efile", stream_get_wrappers()))
  39.             {
  40.                 stream_wrapper_register("efile", "ExtendedFileStream");
  41.             }
  42.         }
  43.         
  44.         private function createDirectories($path)
  45.         {
  46.             $f = new PhingFile($path);
  47.             if (!$f->exists()) {
  48.                 $f->mkdirs();
  49.             }
  50.         }
  51.         
  52.         function stream_open($path, $mode, $options, &$opened_path)
  53.         {
  54.             /** Small fix for Windows */
  55.             if ($path[8] == DIRECTORY_SEPARATOR)
  56.             {
  57.                 $filepath = substr($path, 7);
  58.             }
  59.             else
  60.             {
  61.                 $filepath = substr($path, 8);
  62.             }
  63.             
  64.             $this->createDirectories(dirname($filepath));
  65.             
  66.             $this->fp = fopen($filepath, $mode);
  67.             
  68.             return true;
  69.         }
  70.         
  71.         function stream_close()
  72.         {
  73.             fclose($this->fp);
  74.             $this->fp = NULL;
  75.         }
  76.         
  77.         function stream_read($count)
  78.         {
  79.             return fread($this->fp, $count);
  80.         }
  81.         
  82.         function stream_write($data)
  83.         {
  84.             return fwrite($this->fp, $data);
  85.         }
  86.         
  87.         function stream_eof()
  88.         {
  89.             return feof($this->fp);
  90.         }
  91.         
  92.         function stream_tell()
  93.         {
  94.             return ftell($this->fp);
  95.         }
  96.         
  97.         function stream_seek($offset, $whence)
  98.         {
  99.             return fseek($this->fp, $offset, $whence);
  100.         }
  101.         
  102.         function stream_flush()
  103.         {
  104.             return fflush($this->fp);
  105.         }
  106.         
  107.         function stream_stat()
  108.         {
  109.             return fstat($this->fp);
  110.         }
  111.         
  112.         function unlink($path)
  113.         {
  114.             return FALSE;
  115.         }
  116.         
  117.         function rename($path_from, $path_to)
  118.         {
  119.             return FALSE;
  120.         }
  121.         
  122.         function mkdir($path, $mode, $options)
  123.         {
  124.             return FALSE;
  125.         }
  126.         
  127.         function rmdir($path, $options)
  128.         {
  129.             return FALSE;
  130.         }        
  131.     };
  132.  
  133. ?>