Bouncy Melons 0.2
declarative style orm
Field.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm;
4 
7 
8 class Field implements IField{
9 
10  protected $name;
11  protected $title;
12  protected $sqlType;
13  protected $options = [];
14 
25  public function __construct($name, $title=null, $options = array(), $sqlType = null) {
26  $this->name = $name;
27  $this->title = $title;
28  $this->options = $options;
29  $this->sqlType = $sqlType;
30  }
31 
35  public function getName() {
36  return $this->name;
37  }
38 
42  public function getTitle() {
43  if(empty($this->title)) {
44  return $this->getName();
45  }
46  return $this->title;
47  }
48 
53  public function getType() {
54  $exploded = explode("\\",get_class($this));
55  return strtolower(str_replace("Field","",end($exploded)));
56  }
57 
62  public function getOption($key) {
63  return @$this->options[$key];
64  }
65 
66  public function isRequired() {
67 // var_dump('in isRequired', $this->getOption('required'));//exit;
68  return $this->getOption('required') == true;
69  }
70 
74  public function getSqlType() {
75  if(empty($this->sqlType)) {
76  return static::DEFAULT_SQL_TYPE;
77  }
78  return strtolower($this->sqlType);
79  }
80 
88  public function beforeGet($value) {
89  if(!empty($this->getOption('default'))
90  && empty($value)
91  && $value !== false
92  && $value !== 0
93  && $value !== '0'
94  ) {
95  $value = $this->getOption('default');
96  }
97  return $value;
98  }
99 
106  public function beforeRead($value) {
107 
108  }
109 
115  public function beforeSet($value) {
116  return $value;
117  }
118 
125  public function setOption($key, $value) {
126  $this->options[$key] = $value;
127  }
128 
129 }
getSqlType()
Definition: Field.php:74
beforeGet($value)
Definition: Field.php:88
$sqlType
Definition: Field.php:12
__construct($name, $title=null, $options=array(), $sqlType=null)
Definition: Field.php:25
getOption($key)
Definition: Field.php:62
setOption($key, $value)
Definition: Field.php:125
getType()
Definition: Field.php:53
isRequired()
Definition: Field.php:66
beforeSet($value)
Definition: Field.php:115
getName()
Definition: Field.php:35
getTitle()
Definition: Field.php:42
beforeRead($value)
Definition: Field.php:106
$title
Definition: Field.php:11