public function saveToFile($fileName, $includeHeaders = true)
 {
     $target = uFs::fopen($fileName, 'w+', true);
     if ($this->headers !== null && $includeHeaders) {
         fputcsv($target, $this->headers);
     }
     $currentPosition = ftell($this->fp);
     rewind($this->fp);
     stream_copy_to_stream($this->fp, $target);
     fseek($this->fp, $currentPosition);
     fclose($target);
 }
 /**
  * Check if the target path exists and if it is writable. Depending on the
  * $createIfNotExists parameter it will be created if it does not exist.
  *
  * @param <type> $fullPath
  * @param <type> $createIfNotExists
  * @return <type>
  */
 protected static function checkTargetPath($fullPath, $createIfNotExists = false)
 {
     $path = self::getBasePath($fullPath);
     if ($createIfNotExists) {
         uFs::mkdir($path, 0777, true);
     } else {
         uFs::file_exists($path, true);
         uFs::is_writable($path, true);
     }
     return true;
 }
 /**
  * Adhoc logger that simply writes the message to a file.
  *
  * @param string $msg  The string to be logged
  * @param string $file The file name for the log file
  */
 public static function log($msg, $file = 'debug.log')
 {
     $f = uFs::fopen($file, 'a');
     fwrite($f, $msg . PHP_EOL);
     fclose($f);
 }
 /**
  * Install a cron job that runs at a custom time (other than the .hourly/
  * .daily/.weekly/.monthly. A file in the same format as /etc/crontab is
  * created in /etc/cron.d with permissions 644.
  * 
  * $fileName should not have any extension and is the name of the file that
  *           wil be created in $cronPath.
  *
  * $time is a string that represents the customary cron time format:
  *   minute   hour   day   month   dayofweek
  *
  *   minute    - any integer from 0 to 59
  *   hour      - any integer from 0 to 23
  *   day       - any integer from 1 to 31 (must be a valid day if a month is
  *               specified)
  *   month     - any integer from 1 to 12 (or the short name of the month such
  *               as jan or feb)
  *   dayofweek - any integer from 0 to 7, where 0 or 7 represents Sunday (or
  *               the short name of the week such as sun or mon)
  *
  *   Example: run the command at 7 am every day
  *            0 7 * * *
  *
  * $sfTaskCall is the symfony command line that the script should execute.
  *
  * @param <type> $cronPath   Path to the cron directory (must be /etc/cron.d)
  * @param <type> $fileName   Name of the file to be created in $cronPath
  * @param <type> $time       Cron time format (see above)
  * @param <type> $sfTaskCall The command to call
  */
 public static function custom($fileName, $time, $sfTaskCall, $cronPath = '/etc/cron.d')
 {
     $DS = DIRECTORY_SEPARATOR;
     $fullPath = $cronPath . $DS . $fileName;
     $command = $time . ' root php ' . sfConfig::get('sf_root_dir') . $DS . $sfTaskCall . PHP_EOL;
     uFs::file_put_contents($fullPath, $command);
     uFs::chmod($fullPath, 0644, true);
 }
 public static function symlink($target, $linkName, $throwException = true)
 {
     if (function_exists('symlink')) {
         if (is_link($linkName)) {
             if (readlink($linkName) != $target) {
                 uFs::unlink($linkName, false);
             }
         }
         if (!self::relativeSymlink($target, $linkName)) {
             if ($throwException) {
                 throw new Exception('symlink(' . $target . ',' . $linkName . ') failed.');
             } else {
                 return false;
             }
         }
     } else {
         if ($throwException) {
             throw new Exception('Function \'symlink\' does not exist.');
         } else {
             return false;
         }
     }
 }
 public function __destruct()
 {
     uFs::unlink($this->fullPath);
 }