TYPO3 API  SVNRelease
Arguments.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  * Arguments list. Wraps an array, but only allows read-only methods on it.
00025  * Is available inside every view helper as $this->arguments - and you use it as if it was an array.
00026  * However, you can only read, and not write to it.
00027  *
00028  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00029  * @api
00030  */
00031 class Tx_Fluid_Core_ViewHelper_Arguments implements ArrayAccess {
00032 
00033     /**
00034      * Array storing the arguments themselves
00035      */
00036     protected $arguments = array();
00037 
00038     /**
00039      * Constructor.
00040      *
00041      * @param array $arguments Array of arguments
00042      * @author Sebastian Kurfürst <sebastian@typo3.org>
00043      * @api
00044      */
00045     public function __construct(array $arguments) {
00046         $this->arguments = $arguments;
00047     }
00048 
00049     /**
00050      * Checks if a given key exists in the array
00051      *
00052      * @param string $key Key to check
00053      * @return boolean true if exists
00054      * @author Sebastian Kurfürst <sebastian@typo3.org>
00055      */
00056     public function offsetExists($key) {
00057         return array_key_exists($key, $this->arguments);
00058     }
00059 
00060     /**
00061      * Returns the value to the given key.
00062      *
00063      * @param string $key Key to get.
00064      * @return object associated value
00065      * @author Sebastian Kurfürst <sebastian@typo3.org>
00066      */
00067     public function offsetGet($key) {
00068         if (!array_key_exists($key, $this->arguments)) {
00069             return NULL;
00070         }
00071 
00072         return $this->arguments[$key];
00073     }
00074 
00075     /**
00076      * Throw exception if you try to set a value.
00077      *
00078      * @param string $key
00079      * @param object $value
00080      * @author Sebastian Kurfürst <sebastian@typo3.org>
00081      */
00082     public function offsetSet($key, $value) {
00083         throw new Tx_Fluid_Core_Exception('Tried to set argument "' . $key . '", but setting arguments is forbidden.', 1236080693);
00084     }
00085 
00086     /**
00087      * Throw exception if you try to unset a value.
00088      *
00089      * @param string $key
00090      * @author Sebastian Kurfürst <sebastian@typo3.org>
00091      */
00092     public function offsetUnset($key) {
00093         throw new Tx_Fluid_Core_Exception('Tried to unset argument "' . $key . '", but setting arguments is forbidden.', 1236080702);
00094     }
00095 
00096     /**
00097      * Checks if an argument with the specified name exists
00098      *
00099      * @param string $argumentName Name of the argument to check for
00100      * @return boolean TRUE if such an argument exists, otherwise FALSE
00101      * @see offsetExists()
00102      * @author Bastian Waidelich <bastian@typo3.org>
00103      */
00104     public function hasArgument($argumentName) {
00105         return $this->offsetExists($argumentName) && $this->arguments[$argumentName] !== NULL;
00106     }
00107 }
00108 ?>