Bouncy Melons 0.1
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 
21  public function __construct($name, $title=null, $options = array(), $sqlType = null) {
22  $this->name = $name;
23  $this->title = $title;
24  $this->options = $options;
25  $this->sqlType = $sqlType;
26  }
27 
31  public function getName() {
32  return $this->name;
33  }
34 
38  public function getTitle() {
39  if(empty($this->title)) {
40  return $this->getName();
41  }
42  return $this->title;
43  }
44 
45 
50  public function getOption($key) {
51  return @$this->options[$key];
52  }
53 
54 
58  public function getSqlType() {
59  if(empty($this->sqlType)) {
60  return static::DEFAULT_SQL_TYPE;
61  }
62  return strtolower($this->sqlType);
63  }
64 
72  public function beforeGet($value, ISingle $single) {
73  if(!empty($this->getOption('default'))
74  && empty($value)
75  && $value !== false
76  && $value !== 0
77  && $value !== '0'
78  ) {
79  $value = $this->getOption('default');
80  }
81  return $value;
82  }
83 
91  public function beforeRead($value, ISingle $single) {
92 
93  }
94 
101  public function beforeSet($value, ISingle $single) {
102  return $value;
103  }
104 
111  public function setOption($key, $value) {
112  $this->options[$key] = $value;
113  }
114 
115 }
beforeSet($value, ISingle $single)
Definition: Field.php:101
getSqlType()
Definition: Field.php:58
beforeRead($value, ISingle $single)
Definition: Field.php:91
$sqlType
Definition: Field.php:12
__construct($name, $title=null, $options=array(), $sqlType=null)
Definition: Field.php:21
getOption($key)
Definition: Field.php:50
setOption($key, $value)
Definition: Field.php:111
beforeGet($value, ISingle $single)
Definition: Field.php:72
getName()
Definition: Field.php:31
getTitle()
Definition: Field.php:38
$title
Definition: Field.php:11