[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/database/model/ -> Rule.php (source)

   1  <?php
   2  /*
   3   *  $Id: Rule.php 92 2005-05-21 21:11:28Z rhalff $
   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 please see
  19   * <http://propel.phpdb.org>.
  20   */
  21  
  22  require_once 'propel/engine/database/model/XMLElement.php';
  23  
  24  /**
  25   * Data about a validation rule used in an application.
  26   *
  27   * @author Michael Aichler <aichler@mediacluster.de> (Propel)
  28   * @author John McNally <jmcnally@collab.net> (Intake)
  29   * @version $Revision: 92 $
  30   * @package propel.engine.database.model
  31   */
  32  class Rule extends XMLElement {
  33      
  34      private $name;
  35      private $value;
  36      private $message;
  37      private $validator;
  38      private $classname;    
  39      
  40      /**
  41       * Sets up the Rule object based on the attributes that were passed to loadFromXML().
  42       * @see parent::loadFromXML()
  43       */
  44      protected function setupObject()
  45      {
  46          $this->name = $this->getAttribute("name");
  47          $this->value = $this->getAttribute("value");
  48          $this->classname = $this->getAttribute("class");
  49          
  50          /*
  51          * Set some default values if they are not specified.
  52          * This is escpecially useful for maxLength; the size
  53          * is already known by the column and this way it is
  54          * not necessary to manage the same size two times.
  55          * 
  56          * Currently there is only one such supported default:
  57          *   - maxLength value = column max length
  58          *   (this default cannot be easily set at runtime w/o changing
  59          *   design of class system in undesired ways)
  60          */
  61          if ($this->value === null) {
  62              switch($this->name) {
  63                  case 'maxLength':
  64                      $this->value = $this->validator->getColumn()->getSize();
  65                      break;      
  66              }        
  67          }                
  68          
  69          $this->message = $this->getAttribute("message");
  70      }        
  71      
  72      /**
  73       * Sets the owning validator for this rule.
  74       * @param Validator $validator
  75       * @see Validator::addRule()
  76       */
  77      public function setValidator(Validator $validator)
  78      {
  79          $this->validator = $validator;
  80      }
  81      
  82      /**
  83       * Gets the owning validator for this rule.
  84       * @return Validator
  85       */
  86      public function getValidator()
  87      {
  88          return $this->validator;
  89      }
  90      
  91      /**
  92       * Sets the dot-path name of class to use for rule.
  93       * If no class is specified in XML, then a classname will
  94       * be built based on the 'name' attrib.
  95       * @param string $classname dot-path classname (e.g. myapp.propel.MyValidator)
  96       */
  97      public function setClass($classname)
  98      {
  99          $this->classname = $classname;   
 100      }
 101      
 102      /**
 103       * Gets the dot-path name of class to use for rule.
 104       * If no class was specified, this method will build a default classname
 105       * based on the 'name' attribute.  E.g. 'maxLength' -> 'propel.validator.MaxLengthValidator'
 106       * @return string dot-path classname (e.g. myapp.propel.MyValidator)
 107       */
 108      public function getClass()
 109      {
 110          if ($this->classname === null && $this->name !== null) {
 111              return "propel.validator." . ucfirst($this->name) . "Validator";
 112          }
 113          return $this->classname;
 114      }
 115      
 116      /**
 117       * Sets the name of the validator for this rule.
 118       * This name is used to build the classname if none was specified.
 119       * @param string $name Validator name for this rule (e.g. "maxLength", "required").
 120       * @see getClass()
 121       */
 122      public function setName($name)
 123      {
 124          $this->name = $name;
 125      }
 126      
 127      /**
 128       * Gets the name of the validator for this rule.
 129       * @return string Validator name for this rule (e.g. "maxLength", "required").
 130       */
 131      public function getName()
 132      {
 133          return $this->name;
 134      }
 135      
 136      /**
 137       * Sets the value parameter for this validator rule.
 138       * Note: not all validators need a value parameter (e.g. 'required' validator
 139       * does not).
 140       * @param string $value
 141       */
 142      public function setValue($value)
 143      {
 144          $this->value = $value;
 145      }
 146      
 147      /**
 148       * Gets the value parameter for this validator rule.
 149       * @return string
 150       */
 151      public function getValue()
 152      {
 153          return $this->value;
 154      }
 155      
 156      /**
 157       * Sets the message that will be displayed to the user if validation fails.
 158       * This message may be a Gettext msgid (if translation="gettext") or some other
 159       * id for an alternative not-yet-supported translation system.  It may also
 160       * be a simple, single-language string.
 161       * @param string $message
 162       * @see setTranslation()
 163       */
 164      public function setMessage($message)
 165      {
 166          $this->message = $message;
 167      }
 168      
 169      /**
 170       * Gets the message that will be displayed to the user if validation fails.
 171       * This message may be a Gettext msgid (if translation="gettext") or some other
 172       * id for an alternative not-yet-supported translation system.  It may also
 173       * be a simple, single-language string.
 174       * @return string
 175       * @see setTranslation()
 176       */
 177      public function getMessage()
 178      {
 179        $message = str_replace('$value}', $this->getValue(), $this->message);
 180        return $message;
 181      }
 182          
 183      /**
 184       * Create XML (string) representation of this object.
 185       * @return string
 186       */
 187      public function toString()
 188      {
 189        $result = "<rule name=\"" . $this->getName() . "\" ";
 190  
 191        if ($this->getValue() !== null) {
 192          $result .= "value=\"" . $this->getValue(). "\" ";
 193        }
 194        if ($this->getClass() !== null) {
 195            $result .= "class=\"".$this->getClass()."\" ";
 196        }
 197        $result .= "message=\"" . $this->getMessage() . "\" ";
 198        $result .= "/>\n";
 199  
 200        return $result;
 201      }
 202  
 203  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7