Skip to content
Browse files

Update documentation, removing references to previous validators

  • Loading branch information...
1 parent f8eb808 commit 3071b95cc586c8378e7723e5272f4f42f7a0c498 @cristianoc72 cristianoc72 committed
View
3 documentation/cookbook/runtime-introspection.markdown
@@ -7,7 +7,7 @@ title: Model Introspection At Runtime
In addition to the object and peer classes used to do C.R.U.D. operations, Propel generates an object mapping for your tables to allow runtime introspection.
-The intospection objects are instances of the map classes. Propel maps databases, tables, columns, validators, and relations into objects that you can easily use.
+The intospection objects are instances of the map classes. Propel maps databases, tables, columns and relations into objects that you can easily use.
## Retrieving a TableMap ##
@@ -82,7 +82,6 @@ $bookTitleColumn->isNumeric(); // false
$bookTitleColumn->isText(); // true
$bookTitleColumn->isPrimaryKey(); // false
$bookTitleColumn->isForeignKey(); // false
-$bookTitleColumn->hasValidators(); // false
$bookTitleColumn->isPrimaryString(); // true
{% endhighlight %}
View
2 documentation/cookbook/writing-behavior.markdown
@@ -93,7 +93,7 @@ class AggregateColumnBehavior extends Behavior
This method shows that a behavior class has access to the `<parameters>` defined for it in the `schema.xml` through the `getParameter()` command. Behaviors can also always access the `Table` object attached to them, by calling `getTable()`. A `Table` can check if a column exists and add a new one easily. The `Table` class is one of the numerous generator classes that serve to describe the object model at buildtime, together with `Column`, `ForeignKey`, `Index`, and a lot more classes. You can find all the buildtime model classes under the `generator/lib/model` directory.
-_Tip_: Don't mix up the _runtime_ database model (`DatabaseMap`, `TableMap`, `ColumnMap`, `ValidatorMap`, `RelationMap`) with the _buildtime_ database model (`Database`, `Table`, `Column`, `Validator`, etc.). The buildtime model is very detailed, in order to ease the work of the builders that write the ActiveRecord and Query classes. On the other hand, the runtime model is optimized for speed, and carries minimal information to allow correct hydration and binding at runtime. Behaviors use the buildtime object model, because they are run at buildtime, so they have access to the most powerful model.
+_Tip_: Don't mix up the _runtime_ database model (`DatabaseMap`, `TableMap`, `ColumnMap`, `RelationMap`) with the _buildtime_ database model (`Database`, `Table`, `Column`, etc.). The buildtime model is very detailed, in order to ease the work of the builders that write the ActiveRecord and Query classes. On the other hand, the runtime model is optimized for speed, and carries minimal information to allow correct hydration and binding at runtime. Behaviors use the buildtime object model, because they are run at buildtime, so they have access to the most powerful model.
Now rebuild the model and the SQL, and sure enough, the new column is there. `BasePollQuestion` offers a `getTotalNbVotes()` and a `setTotalNbVotes()` method, and the table creation SQL now includes the additional `total_nb_votes` column:
View
240 documentation/documentation/05-validators.markdown
@@ -1,240 +0,0 @@
----
-layout: documentation
-title: Validators
----
-
-# Validators #
-
-Validators help you to validate an input before persisting it to the database. In Propel, validators are rules describing what type of data a column accepts. Validators are referenced in the `schema.xml` file, using `<validator>` tags.
-
-Validators are applied at the PHP level, they are not created as constraints on the database itself. That means that if you also use another language to work with the database, the validator rules will not be enforced.
-You can also apply multiple rule entries per validator entry in the schema.xml file.
-
-## Overview ##
-
-In the following example, the `username` column is defined to have a minimum length of 4 characters:
-
-{% highlight xml %}
-<table name="user">
- <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/>
- <column name="username" type="VARCHAR" size="34" required="true" />
- <validator column="username">
- <rule name="minLength" value="4" message="Username must be at least ${value} characters !" />
- </validator>
-</table>
-{% endhighlight %}
-
-Every column rule is represented by a `<rule>` tag. A `<validator>` is a set of `<rule>` tags bound to a column.
-
-At runtime, you can validate an instance of the model by calling the `validate()` method:
-
-{% highlight php %}
-<?php
-$user = new User();
-$user->setUsername("foo"); // only 3 in length, which is too short...
-if ($objUser->validate()) {
- // no validation errors, so the data can be persisted
- $user->save();
-} else {
- // Something went wrong.
- // Use the validationFailures to check what
- foreach ($objUser->getValidationFailures() as $failure) {
- echo $failure->getMessage() . "\n";
- }
-}
-{% endhighlight %}
-
-`validate()` returns a boolean. If the validation failed, you can access the array `ValidationFailed` objects by way of the `getValidationFailures()` method. Each `ValidationFailed` instance gives access to the column, the messagen and the validator that caused the failure.
-
-## Core Validators ##
-
-Propel bundles a set of validatorts that should help you deal with the most common cases.
-
-### MatchValidator ###
-
-The `MatchValidator` is used to run a regular expression of choice against the column. Note that this is a `preg`, not `ereg` (check [the preg_match documentation](http://www.php.net/preg_match) for more information about regexps).
-
-{% highlight xml %}
-<validator column="username">
- <!-- allow strings that match the email adress pattern -->
- <rule
- name="match"
- value="/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/"
- message="Please enter a valid email address." />
-</validator>
-{% endhighlight %}
-
-### NotMatchValidator ###
-
-Opposite of `MatchValidator`, this validator returns false if the regex returns true
-
-{% highlight xml %}
-<column name="ISBN" type="VARCHAR" size="20" required="true" />
-<validator column="ISBN">
- <!-- disallow everything that's not a digit or minus -->
- <rule
- name="notMatch"
- value="/[^\d-]+/"
- message="Please enter a valid ISBN" />
-</validator>
-{% endhighlight %}
-
-### MaxLengthValidator ###
-
-When you want to limit the size of the string to be inserted in a column, use the `MaxLengthValidator`. Internally, it uses `strlen()` to get the length of the string. For instance, some database completely ignore the lentgh of `LONGVARCHAR` columns; you can enforce it using a validator:
-
-{% highlight xml %}
-<column name="comment" type="LONGVARCHAR" required="true" />
-<validator column="comment">
- <rule
- name="maxLength"
- value="1024"
- message="Comments can be no larger than ${value} in size" />
-</validator>
-{% endhighlight %}
-
->**Tip**<br />If you have specified the `size` attribute in the `<column>` tag, you don't have to specify the `value` attribute in the validator rule again, as this is done automatically.
-
-### MinLengthValidator ###
-
-{% highlight xml %}
-<column name="username" type="VARCHAR" size="34" required="true" />
-<validator column="username">
- <rule
- name="minLength"
- value="4"
- message="Username must be at least ${value} characters !" />
-</validator>
-{% endhighlight %}
-
-### MaxValueValidator ###
-
-To limit the value of an integer column, use the `MaxValueValidator`. Note that this validator uses a non-strict comparison ('less than or equal'):
-
-{% highlight xml %}
-<column name="security_level" type="INTEGER" required="true" />
-<validator column="security_level">
- <rule
- name="maxValue"
- value="1000"
- message="Maximum security level is ${value} !" />
-</validator>
-{% endhighlight %}
-
-### MinValueValidator ###
-
-{% highlight xml %}
-<column name="cost" type="INTEGER" required="true" />
-<validator column="cost">
- <rule
- name="minValue"
- value="0"
- message="Products can cost us negative $ can they?" />
-</validator>
-{% endhighlight %}
-
->**Tip**<br />You can run multiple validators against a single column.
-
-{% highlight xml %}
-<column name="security_level" type="INTEGER" required="true" default="10" />
-<validator column="security_level" translate="none">
- <rule
- name="minValue"
- value="0"
- message="Invalid security level, range: 0-10" />
- <rule
- name="maxValue"
- value="10"
- message="Invalid security level, range: 0-10" />
-</validator>
-{% endhighlight %}
-
-### RequiredValidator ###
-
-This validator checks the same rule as a `required=true` on the column at the database level. This, however, will give you a clean error to work with.
-
-{% highlight xml %}
-<column name="username" type="VARCHAR" size="25" required="true" />
-<validator column="username">
- <rule
- name="required"
- message="Username is required." />
-</validator>
-{% endhighlight %}
-
-### UniqueValidator ###
-
-To check whether the value already exists in the table, use the `UniqueValidator`:
-
-{% highlight xml %}
-<column name="username" type="VARCHAR" size="25" required="true" />
-<validator column="username">
- <rule
- name="unique"
- message="Username already exists !" />
-</validator>
-{% endhighlight %}
-
-### ValidValuesValidator ###
-
-This rule restricts the valid values to a list delimited by a pipe ('|').
-
-{% highlight xml %}
-<column name="address_type" type="VARCHAR" required="true" default="delivery" />
-<validator column="address_type">
- <rule
- name="validValues"
- value="account|delivery"
- message="Please select a valid address type." />
-</validator>
-{% endhighlight %}
-
-### TypeValidator ###
-
-Restrict values to a certain PHP type using the `TypeValidator`:
-
-{% highlight xml %}
-<column name="username" type="VARCHAR" size="25" required="true" />
-<validator column="username">
- <rule
- name="type"
- value="string"
- message="Username must be a string" />
-</validator>
-{% endhighlight %}
-
-## Adding A Custom Validator ##
-
-You can easily add a custom validator. A validator is a class extending `BasicValidator` providing a public `isValid()` method. For instance:
-
-{% highlight php %}
-<?php
-require_once 'propel/validator/BasicValidator.php';
-
-/**
- * A simple validator for email fields.
- *
- * @package propel.validator
- */
-class EmailValidator implements BasicValidator
-{
- public function isValid(ValidatorMap $map, $str)
- {
- return preg_match('/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i', $str) !== 0;
- }
-}
-{% endhighlight %}
-
-The `ValidatorMap` instance passed as parameter gives you access to the rules attribute as defined in the `<rule>` tag. So `$map->getValue()` returns the `value` attribute.
-
->**Tip**<br />Make sure that `isValid()` returns a boolean, so really true or false. Propel is very strict about this. Returning a mixed value just won't do.
-
-To enable the new validator on a column, add a corresponding `<rule>` in your schema and use 'class' as the rule `name`.
-
-{% highlight xml %}
-<validator column="<column_name>">
- <rule name="class" class="my.dir.EmailValidator" message="Invalid e-mail address!" />
-</validator>
-{% endhighlight %}
-
-The `class` attribute of the `<rule>` tag should contain a path to the validator class accessible from the include_path, where the directory separator is replaced by a dot.
View
2 documentation/documentation/09-inheritance.markdown
@@ -369,7 +369,7 @@ Since the columns of the main table are copied to the child tables, this schema
</table>
{% endhighlight %}
->**Tip**<br />The `concrete_inheritance` behavior copies columns, foreign keys, indices and validators.
+>**Tip**<br />The `concrete_inheritance` behavior copies columns, foreign keys and indices. If you've configured the `validate` behavior, it copies also validators.
### Using Inherited Model Classes ###
View
1 documentation/documentation/index.markdown
@@ -18,7 +18,6 @@ title: Documentation
* [Basic CRUD](03-basic-crud.html) The basics of Propel C.R.U.D. (Create, Retrieve, Update, Delete) operations
* [Relationships](04-relationships.html) Searching and manipulating data from related tables.
-* [Validators](05-validators.html) The validation framework checks data before insertion based on column type.
* [Transactions](06-transactions.html) Where and when to use transactions.
* [Behaviors](07-behaviors.html) The behavior system allows to package and reuse common model features.
* [Logging And Debugging](08-logging.html) Propel can log a lot of information, including the SQL queries it executes.
View
8 documentation/reference/active-record.markdown
@@ -250,7 +250,7 @@ echo $book->getAuthor()->getLastName(); // Tolstoi
<reference local="author_id" foreign="id" />
</foreign-key>
</table>
-<!-- Generated methods will then be Book::setWriter(), and Book::getWriter()
+<!-- Generated methods will then be Book::setWriter(), and Book::getWriter() -->
{% endhighlight %}
### Many-to-one Relationships ###
@@ -280,7 +280,7 @@ $author->clearBooks(); // removes the relationship
</foreign-key>
</table>
<!-- Generated methods will then be Author::addPublication(), Author::getPublications(),
- Author::countPublications(), and Author::clearPublications()
+ Author::countPublications(), and Author::clearPublications() -->
{% endhighlight %}
### Many-to-many relationships ###
@@ -522,7 +522,7 @@ propel.addGenericMutators = false
## Validation ##
-Active Record classes for tables using validation rules (defined in the schema using the `<validator>` and `<rule>` tags) have two additional methods: `validate()`, and `getValidationFailures()`.
+Active Record classes for tables using validate behavior have three additional methods: `validate()`, `getValidationFailures()` and `loadValidatorMetadata()`.
{% highlight php %}
<?php
@@ -540,7 +540,7 @@ if ($book->validate()) {
}
{% endhighlight %}
-See the [Validators documentation](../documentation/05-validators) for more details.
+See the [Validate behavior documentation](../behaviors/validate.html) for more details.
## Import and Export Capabilities ##

0 comments on commit 3071b95

Please sign in to comment.
Something went wrong with that request. Please try again.