*/ class FileExists { private static $lastWarning; /** * A warning handler that registers that a warning has occured and suppresses it. * * The function is a callback used with "set_error_handler". * It is declared public because it needs to be accessible from the point where the warning is triggered. * * @param integer $errno * @param string $errstr * @param string $errfile * @param integer $errline * * @return void */ public static function warningHandler($errno, $errstr, $errfile, $errline) { self::$lastWarning = [$errstr, $errno]; // Suppress the warning by returning void return; } /** * A well behaved replacement for file_exist that throws upon failure rather than emitting a warning. * * @throws \Exception Throws an exception in case file_exists emits a warning * @return boolean True if file exists. False if it doesn't. */ public static function fileExists($path) { // There is a challenges here: // We want to suppress warnings, but at the same time we want to know that it happened. // We achieve this by registering an error handler set_error_handler( array('FileUtil\FileExists', "warningHandler"), E_WARNING | E_USER_WARNING | E_NOTICE | E_USER_NOTICE ); self::$lastWarning = null; $found = @file_exists($path); // restore previous error handler immediately restore_error_handler(); // If file_exists returns true, we can rely on there being a file there if ($found) { return true; } // file_exists returned false. // this result is only trustworthy if no warning was emitted. if (is_null(self::$lastWarning)) { return false; } list($errstr, $errno) = self::$lastWarning; throw new \Exception($errstr, $errno); } /** * A fileExist doing the best it can. * * @throws \Exception If it cannot be determined if the file exists * @return boolean|null True if file exists. False if it doesn't. */ public static function fileExistsTryHarder($path) { try { $result = self::fileExists($path); } catch (\Exception $e) { try { $result = FileExistsUsingExec::fileExists($path); } catch (\Exception $e) { throw new \Exception('Cannot determine if file exists or not'); } catch (\Throwable $e) { throw new \Exception('Cannot determine if file exists or not'); } } return $result; } } __halt_compiler();----SIGNATURE:----x8SBUq8D6cOZB0tnsj+4y2mBkowTHCNLGbrDa3GuaEhysBJmpJQ6L1GBcEoyANSE3+dHeFNSkeM+daSe/wCH9Ew5isVdfiX6Xp4BUG5Kg4N7zacF+EDVjudgz5/bzxAyVSPPPoyWoZKO92u3Nfqn9EiezC7OnZWPMOJZsDvIDnJKBp6emdjf4gyH552+ZoSqRvtDW84JUZ+NGWsDhQQUSdiz4mRqCOasNc1rorYIq/Kfj5r563IoM2BjfPGmY37DSr2w6MK86tArC/dImOLXO2ysQrcz7FeFjFy9CzDieUq2unj8AnuV2ABh1GnXLAEPpCV4twKY07m4pLEq22PXe0cIg9p/e8FO767BVDW9+eQ56ZE3om1t5aEdtAPjodlDuUkDKdpQLmeSc0MXAZXJ5nR1/JkgRFl39HoaaESzP7kn3uyTktjeVUnrIDkGdmrt02ehHK7izAXaAXJ69sm+TvtdhNHJMkqvUGbbzrzNyZexgkGCUWU7Xbp7z7FpmH4jQwc5yJ71SbkSL/TBmuJuj0JFgvv9T1DJo+PeKSTLnabvxEAD/V9AXXw6fVf5pSWO3mDd+ALJZWTr0TErxX3Bo+10OZSy/fHOB7lFNypICt+MEv/xH6RLolsZzaIW2/X38HV7Od3Jm7dJ3pdI/yWHLIzHxCvwF9eHxU14PUsMPbY=----ATTACHMENT:----MzEyMTE1NDEzODU1NTUxMyA0NDI4MzU4Mjg5MjA4ODk2IDQ1MjIxNTQ3MzI4MDI0MjI=