/
core.php
124 lines (105 loc) · 2.24 KB
/
core.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php defined('SYSPATH') or die('No direct script access.');
/*
* Yada: To know in a relational sense.
* @package Yada
* @author Jeremy Fowler <jeremy.f76@gmail.com>
* @copyright Copyright (c) 2010, Jeremy Fowler
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
*/
abstract class Yada_Field_Core
{
/**
*
* @var ArrayObject
*/
protected $_props;
/**
*
* @param <type> $options
*/
public function __construct($options = array())
{
$defaults = array(
'unique' => FALSE,
'description' => '',
'default' => NULL,
'null' => FALSE,
'filters' => array(),
'rules' => array(),
'callbacks' => array(),
);
if (is_array($options))
{
$defaults = Arr::merge($defaults, $options);
}
// Check as to whether we need to add
// some callbacks for shortcut properties
if ($defaults['unique'] === TRUE)
{
$defaults['callbacks'][] = array($this, '_is_unique');
}
$this->_props = new ArrayObject($defaults, ArrayObject::ARRAY_AS_PROPS);
}
/**
*
* @param <type> $name
* @return <type>
*/
public function __get($name)
{
return ($this->_props->offsetExists($name)) ? $this->_props[$name] : NULL;
}
/**
*
* @param <type> $name
* @param <type> $value
*/
public function __set($name, $value)
{
$this->_props[$name] = $value;
}
public function __isset($name)
{
$this->_props->offsetExists($name);
}
public function __unset($name)
{
$this->_props->offsetUnset($name);
}
/**
*
* @param Yada_Meta $meta
* @param Yada_Model $model
* @param <type> $name
* @param <type> $alias
*/
public function initialize(Yada_Meta $meta, Yada_Model $model, $name, $alias)
{
$this->meta = $meta;
// This will come in handy for setting complex relationships
$this->model = $model;
// This is for naming form fields
$this->name = $name;
// This is the alias of the table
$this->alias = $alias;
// Check for a name, because we can easily provide a default
if ( ! $this->label)
{
$this->label = inflector::humanize($name);
}
}
/**
* Returns a particular value processed according
* to the class's standards.
*
* @param mixed
* @return mixed
**/
public function get($value)
{
return $value;
}
public function save()
{
}
}