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