[ 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/ -> Validator.php (source)

   1  <?php
   2  /*
   3   *  $Id: Validator.php 64 2005-05-13 02:43:56Z root $
   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  include_once 'propel/engine/EngineException.php';
  24  include_once 'propel/engine/database/model/PropelTypes.php';
  25  include_once 'propel/engine/database/model/Rule.php';
  26  
  27  /**
  28   * Validator.
  29   *
  30   * @author Michael Aichler <aichler@mediacluster.de> (Propel)
  31   * @version $Revision: 64 $
  32   * @package propel.engine.database.model
  33   */
  34  class Validator extends XMLElement {
  35  
  36      const TRANSLATE_NONE = "none";
  37      const TRANSLATE_GETTEXT = "gettext";
  38  
  39      private $columnName;
  40      private $column;
  41      private $ruleList;
  42      private $translate;
  43      private $table;
  44      
  45      /**
  46       * Creates a new column and set the name
  47       *
  48       * @param name validator name
  49       */
  50      public function __construct()
  51      {
  52          $this->ruleList = array();
  53      }
  54  
  55      /**
  56       * Sets up the Validator object based on the attributes that were passed to loadFromXML().
  57       * @see parent::loadFromXML()
  58       */
  59      protected function setupObject()
  60      {
  61          $this->columnName = $this->getAttribute("column");
  62          $this->translate = $this->getAttribute("translate", $this->getTable()->getDatabase()->getDefaultTranslateMethod());;
  63      }
  64      
  65      /**
  66       * Add a Rule to this validator.
  67       * Supports two signatures:
  68       * - addRule(Rule $rule)
  69       * - addRule(array $attribs)
  70       * @param mixed $data Rule object or XML attribs (array) from <rule/> element.
  71       * @return Rule The added Rule.
  72       */
  73      public function addRule($data)
  74      {
  75          if ($data instanceof Rule) {
  76              $rule = $data; // alias
  77              $rule->setValidator($this);
  78              $this->ruleList[] = $rule;
  79              return $rule;
  80          }
  81          else {
  82              $rule = new Rule();
  83              $rule->setValidator($this);
  84              $rule->loadFromXML($data);
  85              return $this->addRule($rule); // call self w/ different param
  86          }
  87      }
  88      
  89      /**
  90       * Gets an array of all added rules for this validator.
  91       * @return array Rule[]
  92       */
  93      public function getRules()
  94      {
  95          return $this->ruleList;
  96      }
  97      
  98      /**
  99       * Gets the name of the column that this Validator applies to.
 100       * @return string
 101       */
 102      public function getColumnName()
 103      {
 104          return $this->columnName;
 105      }
 106      
 107      /**
 108       * Sets the Column object that this validator applies to.
 109       * @param Column $column
 110       * @see Table::addValidator()
 111       */
 112      public function setColumn(Column $column)
 113      {
 114          $this->column = $column;
 115      }
 116      
 117      /**
 118       * Gets the Column object that this validator applies to.
 119       * @return Column
 120       */
 121      public function getColumn()
 122      {
 123          return $this->column;
 124      }
 125      
 126      /**
 127       * Set the owning Table.
 128       * @param Table $table
 129       */
 130  	public function setTable(Table $table)
 131      {
 132          $this->table = $table;
 133      }
 134      
 135      /**
 136       * Get the owning Table.
 137       * @return Table
 138       */
 139  	public function getTable()
 140      {
 141          return $this->table;
 142      }
 143  
 144      /**
 145       * Set the translation mode to use for the message.
 146       * Currently only "gettext" and "none" are supported.  The default is "none".
 147       * @param string $method Translation method ("gettext", "none").
 148       */
 149      public function setTranslate($method)
 150      {
 151          $this->translate = $method;
 152      }
 153      
 154      /**
 155       * Get the translation mode to use for the message.
 156       * Currently only "gettext" and "none" are supported.  The default is "none".
 157       * @return string Translation method ("gettext", "none").
 158       */
 159      public function getTranslate()
 160      {
 161          return $this->translate;
 162      }
 163      
 164      /**
 165       * Gets XML (string) representation of this Validator.
 166       * @return string
 167       */
 168      public function toString()
 169      {
 170          $result = "<validator column=\"" . $this->columnName . "\"";
 171          if ($this->translate !== null) {
 172              $result .= " translate=\"".$this->translate."\"";
 173          }
 174          $result .= ">\n";
 175          
 176          if ($this->ruleList !== null) {
 177              for($i=0,$_i=count($this->ruleList); $i < $_i; $i++) {
 178                  $result .= $this->ruleList[$i]->toString();
 179              }
 180          }
 181          
 182          $result .= "</validator>\n";
 183          
 184          return $result;
 185      }
 186  }


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