]> git.mxchange.org Git - core.git/blob - framework/main/classes/file_directories/text/class_BaseTextFile.php
Continued:
[core.git] / framework / main / classes / file_directories / text / class_BaseTextFile.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Filesystem\File;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
9
10 // Import SPL stuff
11 use \SplFileInfo;
12
13 /**
14  * A general text file class
15  *
16  * @author              Roland Haeder <webmaster@ship-simu.org>
17  * @version             0.0.0
18  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
19  * @license             GNU GPL 3.0 or any newer version
20  * @link                http://www.ship-simu.org
21  *
22  * This program is free software: you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation, either version 3 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
34  */
35 abstract class BaseTextFile extends BaseAbstractFile {
36         /**
37          * Protected constructor
38          *
39          * @param       $className      Name of the class
40          * @return      void
41          */
42         protected function __construct (string $className) {
43                 // Call parent constructor
44                 parent::__construct($className);
45         }
46
47         /**
48          * Determines seek position
49          *
50          * @return      $seekPosition   Current seek position
51          */
52         public function determineSeekPosition () {
53                 // Not possible in text files
54                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
55         }
56
57         /**
58          * Seek to given offset (default) or other possibilities as fseek() gives.
59          *
60          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
61          * @param       $whence         Added to offset (default: only use offset to seek to)
62          * @return      $status         Status of file seek: 0 = success, -1 = failed
63          */
64         public function seek (int $offset, int $whence = SEEK_SET) {
65                 // Not possible in text files
66                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: offset=' . $offset . ',whence=' . $whence);
67                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
68         }
69
70         /**
71          * Reads from a local or remote file
72          *
73          * @param       $infoInstance   An instance of a SplFileInfo class
74          * @return      $array  An array containing all read lines
75          * @throws      InvalidArrayCountException      If an array has not the expected size
76          * @throws      InvalidMD5ChecksumException     If two MD5 hashes did not match
77          */
78         public function loadFileContents (SplFileInfo $infoInstance) {
79                 /*
80                  * This class (or its implementations) are special file readers/writers.
81                  * There is no need to read/write the whole file.
82                  */
83                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: infoInstance=' . $infoInstance);
84                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
85         }
86
87 }