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 / system / io / FileOutputStream.php < prev    next >
Encoding:
PHP Script  |  2007-08-28  |  2.4 KB  |  72 lines

  1. <?php
  2. /*
  3.  *  $Id: FileWriter.php 123 2006-09-14 20:19:08Z mrook $  
  4.  * 
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information please see
  19.  * <http://phing.info>.
  20.  */
  21.  
  22. require_once 'phing/system/io/OutputStream.php';
  23. require_once 'phing/system/io/PhingFile.php';
  24.  
  25. /**
  26.  * Output stream subclass for file streams.
  27.  * 
  28.  * @package   phing.system.io
  29.  */
  30. class FileOutputStream extends OutputStream {
  31.     
  32.     /**
  33.      * @var PhingFile The associated file.
  34.      */
  35.     protected $file;
  36.     
  37.     /**
  38.      * Construct a new FileOutputStream.
  39.      * @param mixed $file
  40.      * @param boolean $append Whether to append bytes to end of file rather than beginning.
  41.      * @throws Exception - if invalid argument specified.
  42.      * @throws IOException - if unable to open file.
  43.      */
  44.     public function __construct($file, $append = false) {
  45.         if ($file instanceof PhingFile) {
  46.             $this->file = $file;
  47.         } elseif (is_string($file)) {
  48.             $this->file = new PhingFile($file);
  49.         } else {
  50.             throw new Exception("Invalid argument type for \$file.");
  51.         }
  52.         if ($append) {
  53.             $stream = @fopen($this->file->getAbsolutePath(), "ab");
  54.         } else {
  55.             $stream = @fopen($this->file->getAbsolutePath(), "wb");
  56.         }
  57.         if ($stream === false) {
  58.             throw new IOException("Unable to open " . $this->file->__toString() . " for writing: " . $php_errormsg);
  59.         }
  60.         parent::__construct($stream);
  61.     }
  62.     
  63.     /**
  64.      * Returns a string representation of the attached file.
  65.      * @return string
  66.      */
  67.     public function __toString() {
  68.         return $this->file->getPath();
  69.     }
  70. }
  71.  
  72.