RegulatedForm.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: RegulatedForm.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     abstract class RegulatedForm extends PlainForm
00019     {
00020         protected $rules        = array(); // forever
00021         protected $violated     = array(); // rules
00022 
00027         public function addRule($name, LogicalObject $rule)
00028         {
00029             Assert::isString($name);
00030             
00031             $this->rules[$name] = $rule;
00032             
00033             return $this;
00034         }
00035         
00040         public function dropRuleByName($name)
00041         {
00042             if (isset($this->rules[$name])) {
00043                 unset($this->rules[$name]);
00044                 return $this;
00045             }
00046             
00047             throw new MissingElementException(
00048                 "no such rule with '{$name}' name"
00049             );
00050         }
00051         
00055         public function checkRules()
00056         {
00057             foreach ($this->rules as $name => &$logicalObject) {
00058                 if (!$logicalObject->toBoolean($this))
00059                     $this->violated[$name] = Form::WRONG;
00060             }
00061 
00062             return $this;
00063         }
00064     }
00065 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4