Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change file exists to is file. #1547

Merged
merged 3 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function requireFile(string $file)
{
$file = $this->sanitizeFilename($file);

if (file_exists($file))
if (is_file($file))
{
require_once $file;

Expand Down
4 changes: 2 additions & 2 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function search(string $path, string $ext = 'php'): array
{
$folder = rtrim($folder, '/') . '/';

if (file_exists($folder . $path))
if (is_file($folder . $path) === true)
{
$foundPaths[] = $folder . $path;
}
Expand Down Expand Up @@ -369,7 +369,7 @@ protected function legacyLocate(string $file, string $folder = null): string
*/
protected function requireFile(string $path): bool
{
return file_exists($path);
return is_file($path);
}

//--------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function delete(string $key)
{
$key = $this->prefix . $key;

return file_exists($this->path . $key) ? unlink($this->path . $key) : false;
return is_file($this->path . $key) ? unlink($this->path . $key) : false;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -246,7 +246,7 @@ public function getMetaData(string $key)
{
$key = $this->prefix . $key;

if (! file_exists($this->path . $key))
if (! is_file($this->path . $key))
{
return false;
}
Expand Down Expand Up @@ -473,7 +473,7 @@ protected function getDirFileInfo($source_dir, $top_level_only = true, $_recursi
*/
protected function getFileInfo(string $file, array $returned_values = ['name', 'server_path', 'size', 'date'])
{
if (! file_exists($file))
if (! is_file($file))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ protected function detectEnvironment()
*/
protected function bootstrapEnvironment()
{
if (file_exists(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'))
if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'))
{
require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php';
}
Expand Down
4 changes: 2 additions & 2 deletions system/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected static function removeDir($dir)
*/
public static function moveEscaper()
{
if (class_exists('\\Zend\\Escaper\\Escaper') && file_exists(static::getClassFilePath('\\Zend\\Escaper\\Escaper')))
if (class_exists('\\Zend\\Escaper\\Escaper') && is_file(static::getClassFilePath('\\Zend\\Escaper\\Escaper')))
{
$base = static::$basePath . 'ZendEscaper';

Expand Down Expand Up @@ -181,7 +181,7 @@ public static function moveKint()
{
$filename = 'vendor/kint-php/kint/build/kint-aante-light.php';

if (file_exists($filename))
if (is_file($filename))
{
$base = static::$basePath . 'Kint';

Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLite3/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function createDatabase($db_name): bool
public function dropDatabase($db_name): bool
{
// In SQLite, a database is dropped when we delete a file
if (! file_exists($db_name))
if (! is_file($db_name))
{
if ($this->db->DBDebug)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public static function eventHandler()
$filename = WRITEPATH . 'debugbar/' . $file;

// Show the toolbar
if (file_exists($filename))
if (is_file($filename))
{
$contents = static::format(file_get_contents($filename), $format);
exit($contents);
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public function attach($file, $disposition = '', $newname = null, $mime = '')
{
if ($mime === '')
{
if (strpos($file, '://') === false && ! file_exists($file))
if (strpos($file, '://') === false && ! is_file($file))
{
$this->setErrorMessage(lang('Email.attachmentMissing', [$file]));

Expand Down
2 changes: 1 addition & 1 deletion system/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function initialize()

foreach (static::$files as $file)
{
if (! file_exists($file))
if (! is_file($file))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function move(string $targetPath, string $name = null, bool $overwrite =
*/
public function getDestination(string $destination, string $delimiter = '_', int $i = 0): string
{
while (file_exists($destination))
while (is_file($destination))
{
$info = pathinfo($destination);
if (strpos($info['filename'], $delimiter) !== false)
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ protected function setCURLOptions(array $curl_options = [], array $config = [])
$cert = $cert[0];
}

if (! file_exists($cert))
if (! is_file($cert))
{
throw HTTPException::forSSLCertNotFound($cert);
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function setPath($path)
{
mkdir($path, 0777, true);
//create the index.html file
if (! file_exists($path . 'index.html'))
if (! is_file($path . 'index.html'))
{
$file = fopen($path . 'index.html', 'x+');
fclose($file);
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function get_dir_file_info(string $source_dir, bool $top_level_only = true, bool
*/
function get_file_info(string $file, $returned_values = ['name', 'server_path', 'size', 'date'])
{
if (! file_exists($file))
if (! is_file($file))
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Log/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function handle($level, $message): bool

$msg = '';

if (! file_exists($filepath))
if (! is_file($filepath))
{
$newfile = true;

Expand Down
6 changes: 3 additions & 3 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function autoRoute(string $uri)

// Load the file so that it's available for CodeIgniter.
$file = APPPATH . 'Controllers/' . $this->directory . $this->controller . '.php';
if (file_exists($file))
if (is_file($file))
{
include_once $file;
}
Expand Down Expand Up @@ -564,7 +564,7 @@ protected function validateRequest(array $segments)
$test = $this->directory . ucfirst($this->translateURIDashes === true ? str_replace('-', '_', $segments[0]) : $segments[0]
);

if (! file_exists(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0]))
if (! is_file(APPPATH . 'Controllers/' . $test . '.php') && $directory_override === false && is_dir(APPPATH . 'Controllers/' . $this->directory . ucfirst($segments[0]))
)
{
$this->setDirectory(array_shift($segments), true);
Expand Down Expand Up @@ -663,7 +663,7 @@ protected function setDefaultController()
$this->method = 'index';
}

if (! file_exists(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php'))
if (! is_file(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php'))
{
return;
}
Expand Down
6 changes: 3 additions & 3 deletions system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function read($sessionID)
// which re-reads session data
if ($this->fileHandle === null)
{
$this->fileNew = ! file_exists($this->filePath . $sessionID);
$this->fileNew = ! is_file($this->filePath . $sessionID);

if (($this->fileHandle = fopen($this->filePath . $sessionID, 'c+b')) === false)
{
Expand Down Expand Up @@ -302,13 +302,13 @@ public function destroy($session_id): bool
{
if ($this->close())
{
return file_exists($this->filePath . $session_id) ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true;
return is_file($this->filePath . $session_id) ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true;
}
elseif ($this->filePath !== null)
{
clearstatcache();

return file_exists($this->filePath . $session_id) ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true;
return is_file($this->filePath . $session_id) ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function render(string $view, array $options = null, $saveData = null): s
$view = $view . '.php';
$file = $this->viewPath . $view;

if (! file_exists($file))
if (! is_file($file))
{
$file = $this->loader->locateFile($view, 'Views');
}
Expand Down
2 changes: 1 addition & 1 deletion system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function render(string $view, array $options = null, $saveData = null): s

$this->renderVars['file'] = $this->viewPath . $this->renderVars['view'];

if (! file_exists($this->renderVars['file']))
if (! is_file($this->renderVars['file']))
{
$this->renderVars['file'] = $this->loader->locateFile($this->renderVars['view'], 'Views', empty($fileExt) ? 'php' : $fileExt);
}
Expand Down
2 changes: 1 addition & 1 deletion system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class_alias('Config\Services', 'CodeIgniter\Services');
$loader->register(); // Register the loader with the SPL autoloader stack.

// Now load Composer's if it's available
if (file_exists(COMPOSER_PATH))
if (is_file(COMPOSER_PATH))
{
require_once COMPOSER_PATH;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/system/Cache/Handlers/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ public function __construct()

public function getFileInfoTest()
{
return $this->getFileInfo($this->config->storePath, [
$tmp_handle = tmpfile();
stream_get_meta_data($tmp_handle)['uri'];

return $this->getFileInfo(stream_get_meta_data($tmp_handle)['uri'], [
'name',
'server_path',
'size',
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/concepts/autoloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Classmap
========

The classmap is used extensively by CodeIgniter to eke the last ounces of performance out of the system
by not hitting the file-system with extra ``file_exists()`` calls. You can use the classmap to link to
by not hitting the file-system with extra ``is_file()`` calls. You can use the classmap to link to
third-party libraries that are not namespaced::

$classmap = [
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ page actually exists:

public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'/Views/pages/'.$page.'.php'))
if ( ! is_file(APPPATH.'/Views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
Expand All @@ -116,7 +116,7 @@ footer, and displayed to the user. If the page doesn't exist, a "404
Page not found" error is shown.

The first line in this method checks whether the page actually exists.
PHP's native ``file_exists()`` function is used to check whether the file
PHP's native ``is_file()`` function is used to check whether the file
is where it's expected to be. The ``PageNotFoundException`` is a CodeIgniter
exception that causes the default error page to show.

Expand Down