public
Description: moved the official repo to http://github.com/amptools-net/midori-php/tree/trunk
Homepage: http://www.amptools.net
Clone URL: git://github.com/michaelherndon/midori-php.git
midori-php / src / Midori / Nullable.php
100755 95 lines (86 sloc) 1.697 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
 
/**
* the abstract class which represents a nullable box type.
*
* <pre class="brush: php">
* $obj = new Midori_Int32(null);
* echo $obj; // output will be 0;
* if(!$obj->hasValue)
* echo "I am null!";
* </pre>
*
* @author Michael
* @package Midori
* @see get_class()
* @see function_exists()
* @property boolean $hasValue Gets whether or not the value is not null.
* @property-read string $nullReplacementValue; Get the defaulted value for __toString when the value is null.
*/
abstract class Midori_Nullable extends Midori_Object
{
 
/**
* gets the default value that will replace the value
* when __toString() is called.
*
* @ignore
* @return string
*/
protected function getNullReplacementValue()
{
return "";
}
 
/**
* gets the value
*
* @ignore
* @return mixed
*/
protected function getValue()
{
return $this->get("value");
}
 
/**
* sets the value
*
* @ignore
* @param mixed $value
* @return void
*/
protected function setValue($value)
{
$this->set("value", $value);
}
 
/**
* gets if the object has a value.
*
* @ignore
* @return boolean
*/
protected function getHasValue()
{
return ($this->value != null);
}
 
/**
*
*
*
*/
public function __toString()
{
if($this->hasValue)
return "$this->value";
return $this->nullReplacementValue;
}
 
protected function val($value)
{
if($value instanceof Midori_Nullable)
return $value->value;
return $value;
}
 
}
 
function val($value)
{
if($value instanceof Midori_Nullable)
return $value->value;
return $value;
}