-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.php
More file actions
49 lines (42 loc) · 962 Bytes
/
object.php
File metadata and controls
49 lines (42 loc) · 962 Bytes
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
<?php
namespace BestProject\Wordpress;
defined('ABSPATH') or die;
/**
* Just a basic structure for basic class methods.
*/
trait Object
{
/**
* Get a given property.
*
* @param String $property Name of a property to get.
* @param Mixed $default_value Default value to return in case property was emtpy or not found.
* @return Mixed
*/
public function get($property, $default_value = null)
{
if (isset($this->$property)) {
return $this->$property;
} else {
return $default_value;
}
}
/**
* Sets a given property.
*
* @param Strong $property A property to set.
* @param Mixed $value Value to set.
*
* @throws ErrorException
*/
public function set($property, $value = true)
{
$className = get_called_class();
if (property_exists($this, $property)) {
$this->$property = $value;
} else {
throw new Exception('Property <b>'.$property.'</b> does not exists in <b>'.$className.'</b>',
500);
}
}
}