Continued:
[core.git] / framework / main / classes / stacker / filo / class_FiLoStacker.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Stacker\File;
4
5 // Import framework stuff
6 use CoreFramework\Stacker\BaseStacker;
7 use CoreFramework\Stacker\Stackable;
8
9 /**
10  * A FiLo Stacker class
11  *
12  * @author              Roland Haeder <webmaster@shipsimu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15  * @license             GNU GPL 3.0 or any newer version
16  * @link                http://www.shipsimu.org
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <http://www.gnu.org/licenses/>.
30  */
31 class FiLoStacker extends BaseStacker implements Stackable {
32         /**
33          * Protected constructor
34          *
35          * @return      void
36          */
37         protected function __construct () {
38                 // Call parent constructor
39                 parent::__construct(__CLASS__);
40         }
41
42         /**
43          * Creates an instance of the class Stacker and prepares it for usage
44          *
45          * @return      $stackInstance  An instance of FiLoStacker
46          */
47         public static final function createFiLoStacker () {
48                 // Get a new instance
49                 $stackInstance = new FiLoStacker();
50
51                 // Init the generic stacker
52                 $stackInstance->initStack('generic');
53
54                 // Return the prepared instance
55                 return $stackInstance;
56         }
57
58         /**
59          * Pushs a value on a named stacker
60          *
61          * @param       $stackerName    Name of the stack
62          * @param       $value                  Value to push on it
63          * @return      void
64          * @throws      StackerFullException    If the stack is full
65          */
66         public function pushNamed ($stackerName, $value) {
67                 // Call the protected method
68                 parent::addValue($stackerName, $value);
69         }
70
71         /**
72          * 'Pops' a value from a named stacker and returns it's value
73          *
74          * @param       $stackerName    Name of the stack
75          * @return      $value                  Value of the current stack entry
76          * @throws      NoStackerException      If the named stacker was not found
77          * @throws      EmptyStackerException   If the named stacker is empty
78          */
79         public function popNamed ($stackerName) {
80                 // Get the value
81                 $value = $this->getNamed($stackerName);
82
83                 // Call the protected method
84                 parent::popLast($stackerName);
85
86                 // Return the value
87                 return $value;
88         }
89
90         /**
91          * Get value from named stacker
92          *
93          * @param       $stackerName    Name of the stack
94          * @return      $value                  Value of last added value
95          * @throws      NoStackerException      If the named stacker was not found
96          * @throws      EmptyStackerException   If the named stacker is empty
97          */
98         public function getNamed ($stackerName) {
99                 // Call the protected method
100                 return parent::getLastValue($stackerName);
101         }
102
103 }