-
Notifications
You must be signed in to change notification settings - Fork 0
/
PString.php
62 lines (55 loc) · 1.19 KB
/
PString.php
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
<?php
namespace Pv;
class PString extends Variable
{
public function __construct($value,$type=null)
{
if (!is_string($value)) {
throw new ValidationException('Variable type mismatch, expected string');
}
parent::__construct($value,$type);
}
/**
* Convert to a DateTime object
* @return \DateTime
*/
public function toDate()
{
return date('r', $this->value);
}
/**
* Return the string as a single value array
* @return array
*/
public function toArray()
{
return array($this->value);
}
/**
* Convert to a boolean - if the value is "true" or "false"
* convert directly, otherwise set to true
* @return bool
*/
public function toBoolean()
{
$return = true;
if ($this->value == 'true') {
$return = true;
}
if ($this->value == 'false') {
$return = false;
}
return $return;
}
/**
* Return an object
* @return \Pv\PObject
*/
public function toObject()
{
$obj = new \stdClass();
$obj->value = $this->value;
return $obj;
}
}
?>