# RegulatedForm.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2005-2008 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
    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
    00052         public function ruleExists($name)
    00053         {
    00054             return isset($this->rules[$name]);
    00055         }
    00056
    00060         public function checkRules()
    00061         {
    00062             foreach ($this->rules as $name => $logicalObject) {
    00063                 if (!$logicalObject->toBoolean($this))
    00064                     $this->violated[$name] = Form::WRONG;
    00065             }
    00066
    00067             return $this;
    00068         }
    00069     }
    00070 ?>