Some updates:
[core.git] / framework / main / classes / stacker / file / fifo / class_FiFoFileStack.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Stacker\Filesystem;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
7 use Org\Mxchange\CoreFramework\Filesystem\Stack\StackableFile;
8 use Org\Mxchange\CoreFramework\Registry\Registerable;
9 use Org\Mxchange\CoreFramework\Stacker\Filesystem\BaseFileStacker;
10
11 // Import SPL stuff
12 use \SplFileInfo;
13
14 /**
15  * A FiFo file-based stack
16  *
17  * @author              Roland Haeder <webmaster@ship-simu.org>
18  * @version             0.0.0
19 <<<<<<< HEAD:framework/main/classes/stacker/file/fifo/class_FiFoFileStack.php
20  * @copyright   Copyright (c) 2017 Core Developer Team
21 =======
22  * @copyright   Copyright (c) 2016 Core Developer Team
23 >>>>>>> Some updates::inc/main/classes/stacker/file/fifo/class_FiFoFileStack.php
24  * @license             GNU GPL 3.0 or any newer version
25  * @link                http://www.ship-simu.org
26  *
27  * This program is free software: you can redistribute it and/or modify
28  * it under the terms of the GNU General Public License as published by
29  * the Free Software Foundation, either version 3 of the License, or
30  * (at your option) any later version.
31  *
32  * This program is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35  * GNU General Public License for more details.
36  *
37  * You should have received a copy of the GNU General Public License
38  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
39  */
40 class FiFoFileStack extends BaseFileStack implements StackableFile, CalculatableBlock, Registerable {
41         /**
42          * Protected constructor
43          *
44          * @return      void
45          */
46         protected function __construct () {
47                 // Call parent constructor
48                 parent::__construct(__CLASS__);
49         }
50
51         /**
52          * Creates an instance of this class
53          *
54          * @param       $fileInfoInstance       An instance of a SplFileInfo class
55          * @param       $type                   Type of this stack (e.g. url_source for URL sources)
56          * @return      $stackInstance  An instance of a StackableFile class
57          */
58         public final static function createFiFoFileStack (SplFileInfo $fileInfoInstance, $type) {
59                 // Get new instance
60                 $stackInstance = new FiFoFileStack();
61
62                 // Init this stack
63                 $stackInstance->initFileStack($fileInfoInstance, $type);
64
65                 // Return the prepared instance
66                 return $stackInstance;
67         }
68
69         /**
70          * Pushs a value on a named stacker
71          *
72          * @param       $stackerName    Name of the stack
73          * @param       $value                  Value to push on it
74          * @return      void
75          * @throws      StackerFullException    If the stack is full
76          */
77         public function pushNamed ($stackerName, $value) {
78                 // Call the protected method
79                 parent::addValue($stackerName, $value);
80         }
81
82         /**
83          * 'Pops' a value from a named stacker and returns it's value
84          *
85          * @param       $stackerName    Name of the stack
86          * @return      $value                  Value of the current stack entry
87          * @throws      NoStackerException      If the named stacker was not found
88          * @throws      EmptyStackerException   If the named stacker is empty
89          */
90         public function popNamed ($stackerName) {
91                 // Get the value
92                 $value = $this->getNamed($stackerName);
93
94                 // Call the protected method
95                 parent::popFirst($stackerName);
96
97                 // Return the value
98                 return $value;
99         }
100
101         /**
102          * Get value from named stacker
103          *
104          * @param       $stackerName    Name of the stack
105          * @return      $value                  Value of last added value
106          * @throws      NoStackerException      If the named stacker was not found
107          * @throws      EmptyStackerException   If the named stacker is empty
108          */
109         public function getNamed ($stackerName) {
110                 // Call the protected method
111                 return parent::getFirstValue($stackerName);
112         }
113
114         /**
115          * Seeks to given position
116          *
117          * @param       $seekPosition   Seek position in file
118          * @return      $status                 Status of this operation
119          */
120         public function seek ($seekPosition) {
121                 $this->partialStub('seekPosition=' . $seekPosition);
122         }
123
124         /**
125          * Size of file stack
126          *
127          * @return      $size   Size (in bytes) of file
128          */
129         public function size () {
130                 // Call the iterator instance
131                 return $this->getIteratorInstance()->size();
132         }
133
134 }