3 namespace CoreFramework\Stacker;
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class FiFoStacker extends BaseStacker implements Stackable {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
39 * Creates an instance of the class Stacker and prepares it for usage
41 * @return $stackInstance An instance of FiFoStacker
43 public static final function createFiFoStacker () {
45 $stackInstance = new FiFoStacker();
47 // Init generic stacker
48 $stackInstance->initStack('generic');
50 // Return the prepared instance
51 return $stackInstance;
55 * Pushs a value on a named stacker
57 * @param $stackerName Name of the stack
58 * @param $value Value to push on it
60 * @throws StackerFullException If the stack is full
62 public function pushNamed ($stackerName, $value) {
63 // Call the protected method
64 parent::addValue($stackerName, $value);
68 * 'Pops' a value from a named stacker and returns it's value
70 * @param $stackerName Name of the stack
71 * @return $value Value of the current stack entry
72 * @throws NoStackerException If the named stacker was not found
73 * @throws EmptyStackerException If the named stacker is empty
75 public function popNamed ($stackerName) {
77 $value = $this->getNamed($stackerName);
79 // Call the protected method
80 parent::popFirst($stackerName);
87 * Get value from named stacker
89 * @param $stackerName Name of the stack
90 * @return $value Value of last added value
91 * @throws NoStackerException If the named stacker was not found
92 * @throws EmptyStackerException If the named stacker is empty
94 public function getNamed ($stackerName) {
95 // Call the protected method
96 return parent::getFirstValue($stackerName);