my-simon 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore.orig +55 -0
- data/DOC/Launch Check List.docx +0 -0
- data/DOC/Launch Check List.pdf +0 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +20 -0
- data/README.md +21 -0
- data/README.rdoc +19 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/build/rakefile.rb +12 -0
- data/config.rb +24 -0
- data/lib/simon.rb +0 -5
- data/my-simon.gemspec +141 -0
- data/scaffolding/simon/controller.tpl +9 -0
- data/scaffolding/simon/model.tpl +10 -0
- data/scaffolding/simon/view.tpl +5 -0
- data/scaffolding/standards/html_template.html +44 -0
- data/scaffolding/standards/html_template.php +44 -0
- data/scaffolding/standards/jquery_plugin_template.js +45 -0
- data/scaffolding/standards/js_template.js +43 -0
- data/simon +282 -0
- data/test/helper.rb +18 -0
- data/test/test_simon.rb +7 -0
- data/www/.htaccess +488 -0
- data/www/404.html +32 -0
- data/www/crossdomain.xml +25 -0
- data/www/favicon.ico +0 -0
- data/www/index.php +17 -0
- data/www/lib/js/homePage.js +43 -0
- data/www/lib/js/jquery/JQbook.js +809 -0
- data/www/lib/js/jquery/jquery-1.8.0.min.js +27 -0
- data/www/lib/js/jquery/jquery.alphanumeric.js +82 -0
- data/www/lib/js/jquery/jquery.cookie.js +96 -0
- data/www/lib/js/jquery/jquery.easing.1.3.js +207 -0
- data/www/lib/js/main.js +117 -0
- data/www/lib/js/master.js +6 -0
- data/www/lib/js/plugins/handlebars-1.0.rc.1.js +1920 -0
- data/www/lib/js/plugins/modernizr-1.7.min.js +2 -0
- data/www/lib/js/plugins/swfobject.js +777 -0
- data/www/lib/js/plugins_mod/README.txt +3 -0
- data/www/lib/php/app.php +53 -0
- data/www/lib/php/controller/index.php +10 -0
- data/www/lib/php/controller/regex.php +23 -0
- data/www/lib/php/model/Book.php +8 -0
- data/www/lib/php/model/Model.php +8 -0
- data/www/lib/php/plugins/php-activerecord/ActiveRecord.php +44 -0
- data/www/lib/php/plugins/php-activerecord/lib/CallBack.php +226 -0
- data/www/lib/php/plugins/php-activerecord/lib/Column.php +155 -0
- data/www/lib/php/plugins/php-activerecord/lib/Config.php +288 -0
- data/www/lib/php/plugins/php-activerecord/lib/Connection.php +456 -0
- data/www/lib/php/plugins/php-activerecord/lib/ConnectionManager.php +38 -0
- data/www/lib/php/plugins/php-activerecord/lib/DateTime.php +45 -0
- data/www/lib/php/plugins/php-activerecord/lib/Exceptions.php +137 -0
- data/www/lib/php/plugins/php-activerecord/lib/Expressions.php +183 -0
- data/www/lib/php/plugins/php-activerecord/lib/Inflector.php +115 -0
- data/www/lib/php/plugins/php-activerecord/lib/Model.php +1673 -0
- data/www/lib/php/plugins/php-activerecord/lib/Reflections.php +86 -0
- data/www/lib/php/plugins/php-activerecord/lib/Relationship.php +637 -0
- data/www/lib/php/plugins/php-activerecord/lib/SQLBuilder.php +396 -0
- data/www/lib/php/plugins/php-activerecord/lib/Serialization.php +302 -0
- data/www/lib/php/plugins/php-activerecord/lib/Singleton.php +57 -0
- data/www/lib/php/plugins/php-activerecord/lib/Table.php +547 -0
- data/www/lib/php/plugins/php-activerecord/lib/Utils.php +351 -0
- data/www/lib/php/plugins/php-activerecord/lib/Validations.php +833 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/MysqlAdapter.php +73 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/OciAdapter.php +121 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/PgsqlAdapter.php +104 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/SqliteAdapter.php +81 -0
- data/www/lib/php/system/Config.php +174 -0
- data/www/lib/php/system/config.routes.php +29 -0
- data/www/lib/php/system/router.php +220 -0
- data/www/lib/php/template/footer.php +59 -0
- data/www/lib/php/template/header.php +74 -0
- data/www/lib/php/view/index.php +5 -0
- data/www/media/images/facebook_share.jpg +0 -0
- data/www/robots.txt +5 -0
- data/www/sandbox/readme.txt +3 -0
- data/www/sass/javascript.scss +1 -0
- data/www/sass/layout.scss +128 -0
- data/www/sass/master.scss +4 -0
- data/www/sass/reset.scss +47 -0
- data/www/sass/typography.scss +24 -0
- data/www/styles/javascript.css +1 -0
- data/www/styles/layout.css +186 -0
- data/www/styles/master.css +4 -0
- data/www/styles/reset.css +60 -0
- data/www/styles/typography.css +24 -0
- metadata +179 -7
data/www/lib/php/app.php
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Initalize the application
|
5
|
+
*/
|
6
|
+
class App{
|
7
|
+
|
8
|
+
function __construct(){
|
9
|
+
|
10
|
+
$this->_setup_uri();
|
11
|
+
|
12
|
+
$this->_find_controller();
|
13
|
+
|
14
|
+
}
|
15
|
+
|
16
|
+
private function _setup_uri(){
|
17
|
+
|
18
|
+
$ru = &$_SERVER['REQUEST_URI'];
|
19
|
+
$qmp = strpos($ru, '?');
|
20
|
+
list($path, $params) = $qmp === FALSE
|
21
|
+
? array($ru, NULL)
|
22
|
+
: array(substr($ru, 0, $qmp), substr($ru, $qmp + 1));
|
23
|
+
$parts = explode('/', $path);
|
24
|
+
$i = 0;
|
25
|
+
foreach ($parts as $part)
|
26
|
+
{
|
27
|
+
if (strlen($part) && $part !== '..' && $part !== '.')
|
28
|
+
{
|
29
|
+
define('URI_PART_'.$i++, $part);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
define('URI_PARAM', isset($params) ? '' : $params);
|
33
|
+
define('URI_PARTS', $i);
|
34
|
+
define('URI_PATH', $path);
|
35
|
+
define('URI_REQUEST', $_SERVER['REQUEST_URI']);
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
private function _find_controller(){
|
40
|
+
session_start();
|
41
|
+
require_once DIR_SYS.'/Config.php';
|
42
|
+
include DIR_SYS.'/router.php';
|
43
|
+
include DIR_SYS.'/config.routes.php';
|
44
|
+
if ($ctrl = Router::controller()) {
|
45
|
+
$settings = Config::getInstance();
|
46
|
+
include $ctrl;
|
47
|
+
}else{
|
48
|
+
include DIR_WEB."/404.html";
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
?>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
switch (URI_PART_1)
|
4
|
+
{
|
5
|
+
case 'test1':
|
6
|
+
$title = 'Test 1';
|
7
|
+
$content = "This is the regex controller. You're looking at the test 1 page.";
|
8
|
+
break;
|
9
|
+
case 'test2':
|
10
|
+
$title = 'Test 2';
|
11
|
+
$content = "This is the regex controller. You're looking at the test 2 page.";
|
12
|
+
break;
|
13
|
+
case 'test3':
|
14
|
+
$title = 'Test 3';
|
15
|
+
$content = "This is the regex controller. You're looking at the test 3 page.";
|
16
|
+
break;
|
17
|
+
}
|
18
|
+
|
19
|
+
$head['title'] = 'Regex — '.$title;
|
20
|
+
|
21
|
+
include DIR_VIEW.'/index.php';
|
22
|
+
|
23
|
+
?>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
// ======================================================================================
|
4
|
+
// = Model template for active record http://www.phpactiverecord.org/projects/main/wiki =
|
5
|
+
// ======================================================================================
|
6
|
+
class Book extends ActiveRecord\Model { }
|
7
|
+
|
8
|
+
?>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
// ======================================================================================
|
4
|
+
// = Model template for active record http://www.phpactiverecord.org/projects/main/wiki =
|
5
|
+
// ======================================================================================
|
6
|
+
class Model extends ActiveRecord\Model { }
|
7
|
+
|
8
|
+
?>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<?php
|
2
|
+
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
|
3
|
+
die('PHP ActiveRecord requires PHP 5.3 or higher');
|
4
|
+
|
5
|
+
define('PHP_ACTIVERECORD_VERSION_ID','1.0');
|
6
|
+
|
7
|
+
require 'lib/Singleton.php';
|
8
|
+
require 'lib/Config.php';
|
9
|
+
require 'lib/Utils.php';
|
10
|
+
require 'lib/DateTime.php';
|
11
|
+
require 'lib/Model.php';
|
12
|
+
require 'lib/Table.php';
|
13
|
+
require 'lib/ConnectionManager.php';
|
14
|
+
require 'lib/Connection.php';
|
15
|
+
require 'lib/SQLBuilder.php';
|
16
|
+
require 'lib/Reflections.php';
|
17
|
+
require 'lib/Inflector.php';
|
18
|
+
require 'lib/CallBack.php';
|
19
|
+
require 'lib/Exceptions.php';
|
20
|
+
|
21
|
+
spl_autoload_register('activerecord_autoload');
|
22
|
+
|
23
|
+
function activerecord_autoload($class_name)
|
24
|
+
{
|
25
|
+
$path = ActiveRecord\Config::instance()->get_model_directory();
|
26
|
+
$root = realpath(isset($path) ? $path : '.');
|
27
|
+
|
28
|
+
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
|
29
|
+
{
|
30
|
+
$class_name = array_pop($namespaces);
|
31
|
+
$directories = array();
|
32
|
+
|
33
|
+
foreach ($namespaces as $directory)
|
34
|
+
$directories[] = $directory;
|
35
|
+
|
36
|
+
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
|
37
|
+
}
|
38
|
+
|
39
|
+
$file = "$root/$class_name.php";
|
40
|
+
|
41
|
+
if (file_exists($file))
|
42
|
+
require $file;
|
43
|
+
}
|
44
|
+
?>
|
@@ -0,0 +1,226 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
use Closure;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Callbacks allow the programmer to hook into the life cycle of a {@link Model}.
|
10
|
+
*
|
11
|
+
* You can control the state of your object by declaring certain methods to be
|
12
|
+
* called before or after methods are invoked on your object inside of ActiveRecord.
|
13
|
+
*
|
14
|
+
* Valid callbacks are:
|
15
|
+
* <ul>
|
16
|
+
* <li><b>after_construct:</b> called after a model has been constructed</li>
|
17
|
+
* <li><b>before_save:</b> called before a model is saved</li>
|
18
|
+
* <li><b>after_save:</b> called after a model is saved</li>
|
19
|
+
* <li><b>before_create:</b> called before a NEW model is to be inserted into the database</li>
|
20
|
+
* <li><b>after_create:</b> called after a NEW model has been inserted into the database</li>
|
21
|
+
* <li><b>before_update:</b> called before an existing model has been saved</li>
|
22
|
+
* <li><b>after_update:</b> called after an existing model has been saved</li>
|
23
|
+
* <li><b>before_validation:</b> called before running validators</li>
|
24
|
+
* <li><b>after_validation:</b> called after running validators</li>
|
25
|
+
* <li><b>before_validation_on_create:</b> called before validation on a NEW model being inserted</li>
|
26
|
+
* <li><b>after_validation_on_create:</b> called after validation on a NEW model being inserted</li>
|
27
|
+
* <li><b>before_validation_on_update:</b> see above except for an existing model being saved</li>
|
28
|
+
* <li><b>after_validation_on_update:</b> ...</li>
|
29
|
+
* <li><b>before_destroy:</b> called after a model has been deleted</li>
|
30
|
+
* <li><b>after_destroy:</b> called after a model has been deleted</li>
|
31
|
+
* </ul>
|
32
|
+
*
|
33
|
+
* This class isn't meant to be used directly. Callbacks are defined on your model like the example below:
|
34
|
+
*
|
35
|
+
* <code>
|
36
|
+
* class Person extends ActiveRecord\Model {
|
37
|
+
* static $before_save = array('make_name_uppercase');
|
38
|
+
* static $after_save = array('do_happy_dance');
|
39
|
+
*
|
40
|
+
* public function make_name_uppercase() {
|
41
|
+
* $this->name = strtoupper($this->name);
|
42
|
+
* }
|
43
|
+
*
|
44
|
+
* public function do_happy_dance() {
|
45
|
+
* happy_dance();
|
46
|
+
* }
|
47
|
+
* }
|
48
|
+
* </code>
|
49
|
+
*
|
50
|
+
* Available options for callbacks:
|
51
|
+
*
|
52
|
+
* <ul>
|
53
|
+
* <li><b>prepend:</b> puts the callback at the top of the callback chain instead of the bottom</li>
|
54
|
+
* </ul>
|
55
|
+
*
|
56
|
+
* @package ActiveRecord
|
57
|
+
* @link http://www.phpactiverecord.org/guides/callbacks
|
58
|
+
*/
|
59
|
+
class CallBack
|
60
|
+
{
|
61
|
+
/**
|
62
|
+
* List of available callbacks.
|
63
|
+
*
|
64
|
+
* @var array
|
65
|
+
*/
|
66
|
+
static protected $VALID_CALLBACKS = array(
|
67
|
+
'after_construct',
|
68
|
+
'before_save',
|
69
|
+
'after_save',
|
70
|
+
'before_create',
|
71
|
+
'after_create',
|
72
|
+
'before_update',
|
73
|
+
'after_update',
|
74
|
+
'before_validation',
|
75
|
+
'after_validation',
|
76
|
+
'before_validation_on_create',
|
77
|
+
'after_validation_on_create',
|
78
|
+
'before_validation_on_update',
|
79
|
+
'after_validation_on_update',
|
80
|
+
'before_destroy',
|
81
|
+
'after_destroy'
|
82
|
+
);
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Container for reflection class of given model
|
86
|
+
*
|
87
|
+
* @var object
|
88
|
+
*/
|
89
|
+
private $klass;
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Holds data for registered callbacks.
|
93
|
+
*
|
94
|
+
* @var array
|
95
|
+
*/
|
96
|
+
private $registry = array();
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Creates a CallBack.
|
100
|
+
*
|
101
|
+
* @param string $model_class_name The name of a {@link Model} class
|
102
|
+
* @return CallBack
|
103
|
+
*/
|
104
|
+
public function __construct($model_class_name)
|
105
|
+
{
|
106
|
+
$this->klass = Reflections::instance()->get($model_class_name);
|
107
|
+
|
108
|
+
foreach (static::$VALID_CALLBACKS as $name)
|
109
|
+
{
|
110
|
+
// look for explicitly defined static callback
|
111
|
+
if (($definition = $this->klass->getStaticPropertyValue($name,null)))
|
112
|
+
{
|
113
|
+
if (!is_array($definition))
|
114
|
+
$definition = array($definition);
|
115
|
+
|
116
|
+
foreach ($definition as $method_name)
|
117
|
+
$this->register($name,$method_name);
|
118
|
+
}
|
119
|
+
|
120
|
+
// implicit callbacks that don't need to have a static definition
|
121
|
+
// simply define a method named the same as something in $VALID_CALLBACKS
|
122
|
+
// and the callback is auto-registered
|
123
|
+
elseif ($this->klass->hasMethod($name))
|
124
|
+
$this->register($name,$name);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Returns all the callbacks registered for a callback type.
|
130
|
+
*
|
131
|
+
* @param $name string Name of a callback (see {@link VALID_CALLBACKS $VALID_CALLBACKS})
|
132
|
+
* @return array array of callbacks or null if invalid callback name.
|
133
|
+
*/
|
134
|
+
public function get_callbacks($name)
|
135
|
+
{
|
136
|
+
return isset($this->registry[$name]) ? $this->registry[$name] : null;
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Invokes a callback.
|
141
|
+
*
|
142
|
+
* @internal This is the only piece of the CallBack class that carries its own logic for the
|
143
|
+
* model object. For (after|before)_(create|update) callbacks, it will merge with
|
144
|
+
* a generic 'save' callback which is called first for the lease amount of precision.
|
145
|
+
*
|
146
|
+
* @param string $model Model to invoke the callback on.
|
147
|
+
* @param string $name Name of the callback to invoke
|
148
|
+
* @param boolean $must_exist Set to true to raise an exception if the callback does not exist.
|
149
|
+
* @return mixed null if $name was not a valid callback type or false if a method was invoked
|
150
|
+
* that was for a before_* callback and that method returned false. If this happens, execution
|
151
|
+
* of any other callbacks after the offending callback will not occur.
|
152
|
+
*/
|
153
|
+
public function invoke($model, $name, $must_exist=true)
|
154
|
+
{
|
155
|
+
if ($must_exist && !array_key_exists($name, $this->registry))
|
156
|
+
throw new ActiveRecordException("No callbacks were defined for: $name on " . get_class($model));
|
157
|
+
|
158
|
+
// if it doesn't exist it might be a /(after|before)_(create|update)/ so we still need to run the save
|
159
|
+
// callback
|
160
|
+
if (!array_key_exists($name, $this->registry))
|
161
|
+
$registry = array();
|
162
|
+
else
|
163
|
+
$registry = $this->registry[$name];
|
164
|
+
|
165
|
+
$first = substr($name,0,6);
|
166
|
+
|
167
|
+
// starts with /(after|before)_(create|update)/
|
168
|
+
if (($first == 'after_' || $first == 'before') && (($second = substr($name,7,5)) == 'creat' || $second == 'updat' || $second == 'reate' || $second == 'pdate'))
|
169
|
+
{
|
170
|
+
$temporal_save = str_replace(array('create', 'update'), 'save', $name);
|
171
|
+
|
172
|
+
if (!isset($this->registry[$temporal_save]))
|
173
|
+
$this->registry[$temporal_save] = array();
|
174
|
+
|
175
|
+
$registry = array_merge($this->registry[$temporal_save], $registry ? $registry : array());
|
176
|
+
}
|
177
|
+
|
178
|
+
if ($registry)
|
179
|
+
{
|
180
|
+
foreach ($registry as $method)
|
181
|
+
{
|
182
|
+
$ret = ($method instanceof Closure ? $method($model) : $model->$method());
|
183
|
+
|
184
|
+
if (false === $ret && $first === 'before')
|
185
|
+
return false;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return true;
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Register a new callback.
|
193
|
+
*
|
194
|
+
* @param string $name Name of callback type (see {@link VALID_CALLBACKS $VALID_CALLBACKS})
|
195
|
+
* @param mixed $closure_or_method_name Either a closure or the name of a method on the {@link Model}
|
196
|
+
* @param array $options Options array
|
197
|
+
* @return void
|
198
|
+
* @throws ActiveRecordException if invalid callback type or callback method was not found
|
199
|
+
*/
|
200
|
+
public function register($name, $closure_or_method_name=null, $options=array())
|
201
|
+
{
|
202
|
+
$options = array_merge(array('prepend' => false), $options);
|
203
|
+
|
204
|
+
if (!$closure_or_method_name)
|
205
|
+
$closure_or_method_name = $name;
|
206
|
+
|
207
|
+
if (!in_array($name,self::$VALID_CALLBACKS))
|
208
|
+
throw new ActiveRecordException("Invalid callback: $name");
|
209
|
+
|
210
|
+
if (!($closure_or_method_name instanceof Closure) && !$this->klass->hasMethod($closure_or_method_name))
|
211
|
+
{
|
212
|
+
// i'm a dirty ruby programmer
|
213
|
+
throw new ActiveRecordException("Unknown method for callback: $name" .
|
214
|
+
(is_string($closure_or_method_name) ? ": #$closure_or_method_name" : ""));
|
215
|
+
}
|
216
|
+
|
217
|
+
if (!isset($this->registry[$name]))
|
218
|
+
$this->registry[$name] = array();
|
219
|
+
|
220
|
+
if ($options['prepend'])
|
221
|
+
array_unshift($this->registry[$name], $closure_or_method_name);
|
222
|
+
else
|
223
|
+
$this->registry[$name][] = $closure_or_method_name;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
?>
|
@@ -0,0 +1,155 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Class for a table column.
|
9
|
+
*
|
10
|
+
* @package ActiveRecord
|
11
|
+
*/
|
12
|
+
class Column
|
13
|
+
{
|
14
|
+
// types for $type
|
15
|
+
const STRING = 1;
|
16
|
+
const INTEGER = 2;
|
17
|
+
const DECIMAL = 3;
|
18
|
+
const DATETIME = 4;
|
19
|
+
const DATE = 5;
|
20
|
+
const TIME = 6;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Map a type to an column type.
|
24
|
+
* @static
|
25
|
+
* @var array
|
26
|
+
*/
|
27
|
+
static $TYPE_MAPPING = array(
|
28
|
+
'datetime' => self::DATETIME,
|
29
|
+
'timestamp' => self::DATETIME,
|
30
|
+
'date' => self::DATE,
|
31
|
+
'time' => self::TIME,
|
32
|
+
|
33
|
+
'int' => self::INTEGER,
|
34
|
+
'tinyint' => self::INTEGER,
|
35
|
+
'smallint' => self::INTEGER,
|
36
|
+
'mediumint' => self::INTEGER,
|
37
|
+
'bigint' => self::INTEGER,
|
38
|
+
|
39
|
+
'float' => self::DECIMAL,
|
40
|
+
'double' => self::DECIMAL,
|
41
|
+
'numeric' => self::DECIMAL,
|
42
|
+
'decimal' => self::DECIMAL,
|
43
|
+
'dec' => self::DECIMAL);
|
44
|
+
|
45
|
+
/**
|
46
|
+
* The true name of this column.
|
47
|
+
* @var string
|
48
|
+
*/
|
49
|
+
public $name;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* The inflected name of this columns .. hyphens/spaces will be => _.
|
53
|
+
* @var string
|
54
|
+
*/
|
55
|
+
public $inflected_name;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* The type of this column: STRING, INTEGER, ...
|
59
|
+
* @var integer
|
60
|
+
*/
|
61
|
+
public $type;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* The raw database specific type.
|
65
|
+
* @var string
|
66
|
+
*/
|
67
|
+
public $raw_type;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* The maximum length of this column.
|
71
|
+
* @var int
|
72
|
+
*/
|
73
|
+
public $length;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* True if this column allows null.
|
77
|
+
* @var boolean
|
78
|
+
*/
|
79
|
+
public $nullable;
|
80
|
+
|
81
|
+
/**
|
82
|
+
* True if this column is a primary key.
|
83
|
+
* @var boolean
|
84
|
+
*/
|
85
|
+
public $pk;
|
86
|
+
|
87
|
+
/**
|
88
|
+
* The default value of the column.
|
89
|
+
* @var mixed
|
90
|
+
*/
|
91
|
+
public $default;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* True if this column is set to auto_increment.
|
95
|
+
* @var boolean
|
96
|
+
*/
|
97
|
+
public $auto_increment;
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Name of the sequence to use for this column if any.
|
101
|
+
* @var boolean
|
102
|
+
*/
|
103
|
+
public $sequence;
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Casts a value to the column's type.
|
107
|
+
*
|
108
|
+
* @param mixed $value The value to cast
|
109
|
+
* @param Connection $connection The Connection this column belongs to
|
110
|
+
* @return mixed type-casted value
|
111
|
+
*/
|
112
|
+
public function cast($value, $connection)
|
113
|
+
{
|
114
|
+
if ($value === null)
|
115
|
+
return null;
|
116
|
+
|
117
|
+
switch ($this->type)
|
118
|
+
{
|
119
|
+
case self::STRING: return (string)$value;
|
120
|
+
case self::INTEGER: return (int)$value;
|
121
|
+
case self::DECIMAL: return (double)$value;
|
122
|
+
case self::DATETIME:
|
123
|
+
case self::DATE:
|
124
|
+
if (!$value)
|
125
|
+
return null;
|
126
|
+
|
127
|
+
if ($value instanceof DateTime)
|
128
|
+
return $value;
|
129
|
+
|
130
|
+
if ($value instanceof \DateTime)
|
131
|
+
return new DateTime($value->format('Y-m-d H:i:s T'));
|
132
|
+
|
133
|
+
return $connection->string_to_datetime($value);
|
134
|
+
}
|
135
|
+
return $value;
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Sets the $type member variable.
|
140
|
+
* @return mixed
|
141
|
+
*/
|
142
|
+
public function map_raw_type()
|
143
|
+
{
|
144
|
+
if ($this->raw_type == 'integer')
|
145
|
+
$this->raw_type = 'int';
|
146
|
+
|
147
|
+
if (array_key_exists($this->raw_type,self::$TYPE_MAPPING))
|
148
|
+
$this->type = self::$TYPE_MAPPING[$this->raw_type];
|
149
|
+
else
|
150
|
+
$this->type = self::STRING;
|
151
|
+
|
152
|
+
return $this->type;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
?>
|