mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
Add a $files->fileGetContents() method to accompany existing filePutContents() method
This commit is contained in:
@@ -94,7 +94,7 @@ abstract class FileValidatorModule extends WireData implements Module {
|
|||||||
protected $_pagefile = null;
|
protected $_pagefile = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the given file valid? (this is the method mdoules should implement)
|
* Is the given file valid? (this is the method modules should implement)
|
||||||
*
|
*
|
||||||
* This method should return:
|
* This method should return:
|
||||||
* - boolean TRUE if file is valid
|
* - boolean TRUE if file is valid
|
||||||
@@ -118,7 +118,7 @@ abstract class FileValidatorModule extends WireData implements Module {
|
|||||||
* FileValidator modules should not implement this method, as it only serves as a front-end to isValid()
|
* FileValidator modules should not implement this method, as it only serves as a front-end to isValid()
|
||||||
* for logging purposes.
|
* for logging purposes.
|
||||||
*
|
*
|
||||||
* @param $filename
|
* @param string $filename
|
||||||
* @return bool|int Returns TRUE if valid, FALSE if not, or integer 1 if valid as a result of sanitization.
|
* @return bool|int Returns TRUE if valid, FALSE if not, or integer 1 if valid as a result of sanitization.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@@ -24,6 +24,7 @@ require_once(__DIR__ . '/boot.php');
|
|||||||
* ======================
|
* ======================
|
||||||
* @property AdminTheme|AdminThemeFramework|null $adminTheme
|
* @property AdminTheme|AdminThemeFramework|null $adminTheme
|
||||||
* @property WireCache $cache
|
* @property WireCache $cache
|
||||||
|
* @property WireClassLoader $classLoader
|
||||||
* @property Config $config
|
* @property Config $config
|
||||||
* @property WireDatabasePDO $database
|
* @property WireDatabasePDO $database
|
||||||
* @property WireDateTime $datetime
|
* @property WireDateTime $datetime
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* #pw-summary Helpers for working with files and directories.
|
* #pw-summary Helpers for working with files and directories.
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method bool include($filename, array $vars = array(), array $options = array())
|
* @method bool include($filename, array $vars = array(), array $options = array())
|
||||||
@@ -825,6 +825,7 @@ class WireFileTools extends Wire {
|
|||||||
* - `LOCK_EX` (constant): Acquire exclusive lock to file while writing.
|
* - `LOCK_EX` (constant): Acquire exclusive lock to file while writing.
|
||||||
* @return int|bool Number of bytes written or boolean false on fail
|
* @return int|bool Number of bytes written or boolean false on fail
|
||||||
* @throws WireException if given invalid $filename (since 3.0.118)
|
* @throws WireException if given invalid $filename (since 3.0.118)
|
||||||
|
* @see WireFileTools::fileGetContents()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function filePutContents($filename, $contents, $flags = 0) {
|
public function filePutContents($filename, $contents, $flags = 0) {
|
||||||
@@ -834,6 +835,33 @@ class WireFileTools extends Wire {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get contents of file
|
||||||
|
*
|
||||||
|
* This is the same as PHP’s `file_get_contents()` except that the arguments are simpler and
|
||||||
|
* it may be preferable to use this in ProcessWire for future cases where the file system may be
|
||||||
|
* abstracted from the installation.
|
||||||
|
*
|
||||||
|
* @param string $filename Full path and filename to read
|
||||||
|
* @param int $offset The offset where the reading starts on the original stream. Negative offsets count from the end of the stream.
|
||||||
|
* @param int $maxlen Maximum length of data read. The default is to read until end of file is reached.
|
||||||
|
* @return bool|string Returns the read data (string) or boolean false on failure.
|
||||||
|
* @since 3.0.167
|
||||||
|
* @see WireFileTools::filePutContents()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function fileGetContents($filename, $offset = 0, $maxlen = 0) {
|
||||||
|
if($offset && $maxlen) {
|
||||||
|
return file_get_contents($filename, false, null, $offset, $maxlen);
|
||||||
|
} else if($offset) {
|
||||||
|
return file_get_contents($filename, false, null, $offset);
|
||||||
|
} else if($maxlen) {
|
||||||
|
return file_get_contents($filename, false, null, 0, $maxlen);
|
||||||
|
} else {
|
||||||
|
return file_get_contents($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a filename, render it as a ProcessWire template file
|
* Given a filename, render it as a ProcessWire template file
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user