PluginProbe
Contact Forms by Cimatti / 1.9.2
Contact Forms by Cimatti v1.9.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / PFBC / Base.php

Base.php in Contact Forms by Cimatti 1.9.2, at PFBC/Base.php

67 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 abstract class Base {
3 public function configure(array $properties = null) {
4 if(!empty($properties)) {
5 $class = get_class($this);
6
7 /*The property_reference lookup array is created so that properties can be set
8 case-insensitively.*/
9 $available = array_keys(get_object_vars($this));
10 $property_reference = array();
11 foreach($available as $property)
12 $property_reference[strtolower($property)] = $property;
13
14 /*The method reference lookup array is created so that "set" methods can be called
15 case-insensitively.*/
16 $available = get_class_methods($class);
17 $method_reference = array();
18 foreach($available as $method)
19 $method_reference[strtolower($method)] = $method;
20
21 foreach($properties as $property => $value) {
22 $property = strtolower($property);
23 /*The attributes property cannot be set directly.*/
24 if($property != "attributes") {
25 /*If the appropriate class has a "set" method for the property provided, then
26 it is called instead or setting the property directly.*/
27 if(isset($method_reference["set" . $property]))
28 $this->{$method_reference["set" . $property]}($value);
29 elseif(isset($property_reference[$property]))
30 $this->{$property_reference[$property]} = $value;
31 /*Entries that don't match an available class property are stored in the attributes
32 property if applicable. Typically, these entries will be element attributes such as
33 class, value, onkeyup, etc.*/
34 elseif(isset($property_reference["attributes"]))
35 $this->attributes[$property] = $value;
36 }
37 }
38 }
39 return $this;
40 }
41
42 /*This method can be used to view a class' state.*/
43 public function debug() {
44 echo "<pre>", print_r($this, true), "</pre>";
45 }
46
47 /*This method prevents double/single quotes in html attributes from breaking the markup.*/
48 protected function filter($str) {
49 return htmlspecialchars($str);
50 }
51
52 /*This method is used by the Form class and all Element classes to return a string of html
53 attributes. There is an ignore parameter that allows special attributes from being included.*/
54 public function getAttributes($ignore = "") {
55 $str = "";
56 if(!empty($this->attributes)) {
57 if(!is_array($ignore))
58 $ignore = array($ignore);
59 $attributes = array_diff(array_keys($this->attributes), $ignore);
60 foreach($attributes as $attribute)
61 $str .= ' ' . $attribute . '="' . $this->filter($this->attributes[$attribute]) . '"';
62 }
63 return $str;
64 }
65 }
66 ?>
67