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