Source for file ErrorStack.php

Documentation is available at ErrorStack.php

  1. <?php
  2. /*
  3.  *  $Id: ErrorStack.php 1080 2007-02-10 18:17:08Z romanb $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. /**
  22.  * Doctrine_Validator_ErrorStack
  23.  *
  24.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  25.  * @author      Roman Borschel <roman@code-factory.org>
  26.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  27.  * @package     Doctrine
  28.  * @category    Object Relational Mapping
  29.  * @link        www.phpdoctrine.com
  30.  * @since       1.0
  31.  * @version     $Revision: 1080 $
  32.  */
  33. class Doctrine_Validator_ErrorStack extends Doctrine_Access implements CountableIteratorAggregate
  34. {
  35.  
  36.     /**
  37.      * The errors of the error stack.
  38.      *
  39.      * @var array 
  40.      */
  41.     protected $errors = array();
  42.  
  43.     /**
  44.      * Constructor
  45.      *
  46.      */
  47.     public function __construct()
  48.     {}
  49.  
  50.     /**
  51.      * Adds an error to the stack.
  52.      *
  53.      * @param string $invalidFieldName 
  54.      * @param string $errorType 
  55.      */
  56.     public function add($invalidFieldName$errorCode 'general')
  57.     {
  58.         $this->errors[$invalidFieldName][$errorCode;
  59.     }
  60.  
  61.     /**
  62.      * Removes all existing errors for the specified field from the stack.
  63.      *
  64.      * @param string $fieldName 
  65.      */
  66.     public function remove($fieldName)
  67.     {
  68.         if (isset($this->errors[$fieldName])) {
  69.             unset($this->errors[$fieldName]);
  70.         }
  71.     }
  72.  
  73.     /**
  74.      * Enter description here...
  75.      *
  76.      * @param unknown_type $name 
  77.      * @return unknown 
  78.      */
  79.     public function get($fieldName)
  80.     {
  81.         return isset($this->errors[$fieldName]$this->errors[$fieldNamenull;
  82.     }
  83.  
  84.     /**
  85.      * Enter description here...
  86.      *
  87.      * @param unknown_type $name 
  88.      */
  89.     public function set($fieldName$errorCode)
  90.     {
  91.         $this->add($fieldName$errorCode);
  92.     }
  93.  
  94.     /**
  95.      * Enter description here...
  96.      *
  97.      * @return unknown 
  98.      */
  99.     public function contains($fieldName)
  100.     {
  101.         return array_key_exists($fieldName$this->errors);
  102.     }
  103.  
  104.     /**
  105.      * Removes all errors from the stack.
  106.      */
  107.     public function clear()
  108.     {
  109.         $this->errors = array();
  110.     }
  111.  
  112.     /** IteratorAggregate implementation */
  113.  
  114.     /**
  115.      * Enter description here...
  116.      *
  117.      * @return unknown 
  118.      */
  119.     public function getIterator()
  120.     {
  121.         return new ArrayIterator($this->errors);
  122.     }
  123.  
  124.     /** Countable implementation */
  125.  
  126.     /**
  127.      * Enter description here...
  128.      *
  129.      * @return unknown 
  130.      */
  131.     public function count()
  132.     {
  133.         return count($this->errors);
  134.     }
  135. }