1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-22 13:41:52 +02:00

Merge pull request from Deltik/fix-3538

Better names for eShims classes
This commit is contained in:
Cameron 2018-11-03 11:27:29 -07:00 committed by GitHub
commit 46c07cd416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 69 deletions

@ -11,7 +11,7 @@
namespace e107\Shims;
class All
class AllShims
{
use InternalShims;
use InternalShimsTrait;
}

@ -1,17 +0,0 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Shims for PHP internal functions
*/
namespace e107\Shims;
class Internal
{
use InternalShims;
}

@ -11,53 +11,7 @@
namespace e107\Shims;
trait InternalShims
class InternalShims
{
/**
* Outputs a file
*
* Resilient replacement for PHP internal readfile()
*
* @see https://github.com/e107inc/e107/issues/3528 Why this method was implemented
* @param string $filename The filename being read.
* @param bool $use_include_path You can use the optional second parameter and set it to TRUE,
* if you want to search for the file in the include_path, too.
* @param resource $context A context stream resource.
* @return int|bool Returns the number of bytes read from the file.
* If an error occurs, FALSE is returned.
*/
public static function readfile($filename, $use_include_path = FALSE, $context = NULL)
{
$output = @readfile($filename, $use_include_path, $context);
if ($output === NULL)
{
return self::readfile_alt($filename, $use_include_path, $context);
}
return $output;
}
/**
* Outputs a file
*
* Alternative implementation using file streams
*
* @param $filename
* @param bool $use_include_path
* @param resource $context
* @return bool|int
*/
public static function readfile_alt($filename, $use_include_path = FALSE, $context = NULL)
{
// fopen() silently returns false if there is no context
if (!is_resource($context)) $context = stream_context_create();
$handle = @fopen($filename, 'rb', $use_include_path, $context);
if ($handle === FALSE) return FALSE;
while (!feof($handle))
{
echo(fread($handle, 8192));
}
fclose($handle);
return filesize($filename);
}
}
use InternalShimsTrait;
}

@ -0,0 +1,63 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Shims for PHP internal functions
*/
namespace e107\Shims;
trait InternalShimsTrait
{
/**
* Outputs a file
*
* Resilient replacement for PHP internal readfile()
*
* @see https://github.com/e107inc/e107/issues/3528 Why this method was implemented
* @param string $filename The filename being read.
* @param bool $use_include_path You can use the optional second parameter and set it to TRUE,
* if you want to search for the file in the include_path, too.
* @param resource $context A context stream resource.
* @return int|bool Returns the number of bytes read from the file.
* If an error occurs, FALSE is returned.
*/
public static function readfile($filename, $use_include_path = FALSE, $context = NULL)
{
$output = @readfile($filename, $use_include_path, $context);
if ($output === NULL)
{
return self::readfile_alt($filename, $use_include_path, $context);
}
return $output;
}
/**
* Outputs a file
*
* Alternative implementation using file streams
*
* @param $filename
* @param bool $use_include_path
* @param resource $context
* @return bool|int
*/
public static function readfile_alt($filename, $use_include_path = FALSE, $context = NULL)
{
// fopen() silently returns false if there is no context
if (!is_resource($context)) $context = stream_context_create();
$handle = @fopen($filename, 'rb', $use_include_path, $context);
if ($handle === FALSE) return FALSE;
while (!feof($handle))
{
echo(fread($handle, 8192));
}
fclose($handle);
return filesize($filename);
}
}

@ -12,7 +12,7 @@
// e107 v2-style classes
namespace
{
class eShims extends \e107\Shims\All
class eShims extends \e107\Shims\AllShims
{
}
}