X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffile_directories%2Finput%2Ftext%2Fclass_FrameworkTextFileInputPointer.php;h=bb3b97fffe687fca9ac91d2b8220d848e7230c02;hp=6dc36c314ccbba3c9eb9f82f2dba157a1346f960;hb=1a91dabdfed365947d1ce11675aacae9d424edff;hpb=e65d661719c78867ff57607457c8abfaae2e2ee3 diff --git a/inc/classes/main/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/inc/classes/main/file_directories/input/text/class_FrameworkTextFileInputPointer.php index 6dc36c31..bb3b97ff 100644 --- a/inc/classes/main/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/inc/classes/main/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -75,12 +75,34 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { /** * Read data a file pointer * - * @return mixed The result of fread() + * @return $data Read data from file + */ + public function readFromFile () { + // Read 1024 Byte data from the file pointer and return it + return $this->read(1024); + } + + /** + * Reads a line, maximum 4096 Bytes from current file pointer + * + * @return $data Read data from file + */ + public function readLine () { + // Read whole line from the file pointer and return it + return $this->read(); + } + + /** + * Reads given amount of bytes from file. + * + * @param $bytes Amount of bytes to read or whole line (only text files) + * @return $data Data read from file * @throws NullPointerException If the file pointer instance * is not set by setPointer() * @throws InvalidResourceException If there is being set */ - public function readFromFile () { + public function read ($bytes = NULL) { + // Some sanity checks if (is_null($this->getPointer())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); @@ -89,22 +111,14 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } - // Read data from the file pointer and return it - return $this->read(1024); - } - - /** - * Reads given amount of bytes from file. - * - * @param $bytes Amount of bytes to read - * @return $data Data read from file - */ - public function read ($bytes) { - // Try to read given characters - $data = fgets($this->getPointer(), $bytes); - - // Was this successfull? - assert(is_string($data)); + // Is $bytes set? + if (is_int($bytes)) { + // Try to read given characters + $data = fgets($this->getPointer(), $bytes); + } else { + // Try to read whole line + $data = fgets($this->getPointer()); + } // Then return it return $data;