Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
equals.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Form Rule class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Form
17  * @since 11.1
18  */
20 {
21  /**
22  * Method to test if two values are equal. To use this rule, the form
23  * XML needs a validate attribute of equals and a field attribute
24  * that is equal to the field to test against.
25  *
26  * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
27  * @param mixed $value The form field value to validate.
28  * @param string $group The field name group control value. This acts as as an array container for the field.
29  * For example if the field has name="foo" and the group value is set to "bar" then the
30  * full field name would end up being "bar[foo]".
31  * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
32  * @param JForm $form The form object for which the field is being tested.
33  *
34  * @return boolean True if the value is valid, false otherwise.
35  *
36  * @since 11.1
37  * @throws InvalidArgumentException
38  * @throws UnexpectedValueException
39  */
40  public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
41  {
42  $field = (string) $element['field'];
43 
44  // Check that a validation field is set.
45  if (!$field)
46  {
47  throw new UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
48  }
49 
50  if (is_null($form))
51  {
52  throw new InvalidArgumentException(sprintf('The value for $form must not be null in %s', get_class($this)));
53  }
54 
55  if (is_null($input))
56  {
57  throw new InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
58  }
59 
60  // Test the two values against each other.
61  if ($value == $input->get($field))
62  {
63  return true;
64  }
65 
66  return false;
67  }
68 }