예제 #1
0
 /**
  * Creates temporary files or directories. This function will remove
  * the created files when the scripts finish its execution.
  *
  * Usage:
  *   1) $tempfile = System::mktemp("prefix");
  *   2) $tempdir  = System::mktemp("-d prefix");
  *   3) $tempfile = System::mktemp();
  *   4) $tempfile = System::mktemp("-t /var/tmp prefix");
  *
  * prefix -> The string that will be prepended to the temp name
  *           (defaults to "tmp").
  * -d     -> A temporary dir will be created instead of a file.
  * -t     -> The target dir where the temporary (file|dir) will be created. If
  *           this param is missing by default the env vars TMP on Windows or
  *           TMPDIR in Unix will be used. If these vars are also missing
  *           c:\windows\temp or /tmp will be used.
  *
  * @param   string  $args  The arguments
  * @return  mixed   the full path of the created (file|dir) or false
  * @see System::tmpdir()
  * @access  public
  */
 function mktemp($args = null)
 {
     static $first_time = true;
     $opts = System::_parseArgs($args, 't:d');
     if (PEAR::isError($opts)) {
         return System::raiseError($opts);
     }
     foreach ($opts[0] as $opt) {
         if ($opt[0] == 'd') {
             $tmp_is_dir = true;
         } elseif ($opt[0] == 't') {
             $tmpdir = $opt[1];
         }
     }
     $prefix = isset($opts[1][0]) ? $opts[1][0] : 'tmp';
     if (!isset($tmpdir)) {
         $tmpdir = System::tmpdir();
     }
     if (!System::mkDir("-p {$tmpdir}")) {
         return false;
     }
     $tmp = tempnam($tmpdir, $prefix);
     if (isset($tmp_is_dir)) {
         unlink($tmp);
         // be careful possible race condition here
         if (!call_user_func('mkdir', $tmp, 0700)) {
             return System::raiseError("Unable to create temporary directory {$tmpdir}");
         }
     }
     $GLOBALS['_System_temp_files'][] = $tmp;
     if ($first_time) {
         PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
         $first_time = false;
     }
     return $tmp;
 }
예제 #2
0
    {
        require_once 'File/Util.php';
        return File_Util::tmpFile($dirname);
    }
    /**
     * @deprecated      Use File_Util::isAbsolute() instead.
     */
    function isAbsolute($path)
    {
        require_once 'File/Util.php';
        return File_Util::isAbsolute($path);
    }
    /**
     * @deprecated      Use File_Util::relativePath() instead.
     */
    function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
    {
        require_once 'File/Util.php';
        return File_Util::relativePath($path, $root, $separator);
    }
    /**
     * @deprecated      Use File_Util::realpath() instead.
     */
    function realpath($path, $separator = DIRECTORY_SEPARATOR)
    {
        require_once 'File/Util.php';
        return File_Util::realpath($path, $separator);
    }
}
PEAR::registerShutdownFunc(array('File', '_File'));
예제 #3
0
파일: MDB2.php 프로젝트: gauthierm/MDB2
 /**
  * Use this function to register a shutdown method for static
  * classes.
  *
  * @param  mixed $func  The function name (or array of class/method) to call
  * @param  mixed $args  The arguments to pass to the function
  * @return void
  *
  * @uses PEAR::registerShutdownFunc()
  */
 public function registerShutdownFunc($func, $args = array())
 {
     return $this->pear->registerShutdownFunc($func, $args);
 }
예제 #4
0
 /**
  * インスタンス取得
  *
  * <pre>
  * 指定の画像エンジンで画像処理オブジェクトを返します
  * </pre>
  *
  * @return BEAR_Img_Adapter_GD | BEAR_Img_Adapter_Magick | BEAR_Img_Adapter_Cairo
  * @throws BEAR_Img_Exception
  */
 public function factory()
 {
     if (self::$_instance) {
         return self::$_instance;
     }
     PEAR::registerShutdownFunc(array('BEAR_Img', 'onShutdown'));
     $adapter = $this->_config['adapter'];
     switch ($this->_config['adapter']) {
         case self::ADAPTER_GD:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_GD');
             break;
         case self::ADAPTER_MAGICK:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_Magick');
             break;
         case self::ADAPTER_CAIRO:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_Cairo');
             break;
         default:
             if (is_string($adapter)) {
                 self::$_instance = BEAR::dependency('App_Img_Adapter_' . $this->_config['adapter']);
                 break;
             }
             $options = array('config' => $this->_config);
             throw $this->_exception('Invalid Image Adapter', $options);
     }
     return self::$_instance;
 }
예제 #5
0
 /**
  * Creates temporary files or directories. This function will remove
  * the created files when the scripts finish its execution.
  *
  * Usage:
  *   1) $tempfile = System::mktemp("prefix");
  *   2) $tempdir  = System::mktemp("-d prefix");
  *   3) $tempfile = System::mktemp();
  *   4) $tempfile = System::mktemp("-t /var/tmp prefix");
  *
  * prefix -> The string that will be prepended to the temp name
  *           (defaults to "tmp").
  * -d     -> A temporary dir will be created instead of a file.
  * -t     -> The target dir where the temporary (file|dir) will be created. If
  *           this param is missing by default the env vars TMP on Windows or
  *           TMPDIR in Unix will be used. If these vars are also missing
  *           c:\windows\temp or /tmp will be used.
  *
  * @param   string  $args  The arguments
  * @return  mixed   the full path of the created (file|dir) or false
  * @see System::tmpdir()
  * @static 
  * @access  public
  */
 function mktemp($args = null)
 {
     static $first_time = true;
     $opts = System::_parseArgs($args, 't:d');
     if (PEAR::isError($opts)) {
         return System::raiseError($opts);
     }
     foreach ($opts[0] as $opt) {
         if ($opt[0] == 'd') {
             $tmp_is_dir = true;
         } elseif ($opt[0] == 't') {
             $tmpdir = $opt[1];
         }
     }
     $prefix = isset($opts[1][0]) ? $opts[1][0] : 'tmp';
     if (!isset($tmpdir)) {
         $tmpdir = System::tmpdir();
     }
     /*
      * Magento fix for set tmp dir in config.ini
      */
     if (class_exists('Maged_Controller', false)) {
         $magedConfig = Maged_Controller::model('Config', true)->load();
         if ($magedConfig->get('use_custom_permissions_mode') == '1' && ($mode = $magedConfig->get('mkdir_mode'))) {
             $result = System::mkDir(array('-m' . $mode, $tmpdir));
         } else {
             $result = System::mkDir(array('-p', $tmpdir));
         }
         if (!$result) {
             return false;
         }
     }
     // Old realisation
     //if (!System::mkDir(array('-p', $tmpdir))) {
     //    return false;
     //}
     /*
      * End fix
      */
     $tmp = tempnam($tmpdir, $prefix);
     if (isset($tmp_is_dir)) {
         unlink($tmp);
         // be careful possible race condition here
         if (!mkdir($tmp, 0700)) {
             return System::raiseError("Unable to create temporary directory {$tmpdir}");
         }
     }
     $GLOBALS['_System_temp_files'][] = $tmp;
     if ($first_time) {
         PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
         $first_time = false;
     }
     return $tmp;
 }