public function testExists() { $this->assertFileNotExists(TESTFILE); $this->assertFalse(File::exists(TESTFILE)); file_put_contents(TESTFILE, 'Hello World'); $this->assertFileExists(TESTFILE); $this->assertTrue(File::exists(TESTFILE)); $this->assertFalse(File::exists(__DIR__)); // this is a path! }
/** * Add one file in the pack * * @param string $file * @return boolean - FALSE if the file is not found */ public function appendFile($file) { // Check the file is within default input path if ($mtime = File::modified($this->_input_path . $file)) { $file = $this->_input_path . $file; } elseif (!($mtime = File::exists($file))) { trigger_error("file {$file} does not exists"); return false; } // add a file to the pack $this->_files[] = $file; // last modified time of the pack will be the latest time $this->_lastmtime = max($mtime, $this->_lastmtime); return true; }
/** * Add some files in the pack (as a separate pack) * * @param array $files * @return boolean - FALSE if any file is missing */ public function append_files($files = array()) { $pack = array(); foreach ($files as $file) { // Check the file is within default input path if ($mtime = File::modified($this->_input_path . $file)) { $pack[] = $this->_input_path . $file; } elseif (!($mtime = File::exists($file))) { trigger_error("file {$file} does not exists"); return false; } else { $pack[] = $file; } $this->_lastmtime = max($mtime, $this->_lastmtime); } $this->_files[] = $pack; return true; }
/** * Loads translation file * * @param string $file file should be without extension and within the path * @return boolean */ public static function load($file) { // performance boost static $last_path = false; static $last_ext = false; if ($last_path and $f = strtr($last_path, array('{file}' => $file)) and File::exists($f)) { if ($last_ext == 'mo') { return static::loadMo($f); } if ($last_ext == 'po') { return static::loadPo($f); } return static::loadPhp($f); } // search the language file foreach (static::$searchpaths as $search) { $path = strtr($search, array('{path}' => static::$path, '{lang}' => static::$lang, '{file}' => $file)); foreach (static::$extentions as $ext) { $f = strtr($path, array('{ext}' => $ext)); if (File::exists($f)) { $last_path = strtr($search, array('{path}' => static::$path, '{lang}' => static::$lang, '{ext}' => $ext)); $last_ext = $ext; if ($ext == 'mo') { return static::loadMo($f); } if ($ext == 'po') { return static::loadPo($f); } return static::loadPhp($f); } } } return false; }