00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class Object {
00040
00041
00042
00043
00044
00045
00046 var $_log = null;
00047
00048
00049
00050
00051
00052
00053
00054
00055 function Object() {
00056 $args = func_get_args();
00057 if (method_exists($this, '__destruct')) {
00058 register_shutdown_function (array(&$this, '__destruct'));
00059 }
00060 call_user_func_array(array(&$this, '__construct'), $args);
00061 }
00062
00063
00064
00065 function __construct() {
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075 function toString() {
00076 $class = get_class($this);
00077 return $class;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 function requestAction($url, $extra = array()) {
00088 if (empty($url)) {
00089 return false;
00090 }
00091 if (!class_exists('dispatcher')) {
00092 require CAKE . 'dispatcher.php';
00093 }
00094 if (in_array('return', $extra, true)) {
00095 $extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
00096 }
00097 $params = am(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
00098 $dispatcher = new Dispatcher;
00099 return $dispatcher->dispatch($url, $params);
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 function dispatchMethod($method, $params = array()) {
00112 switch (count($params)) {
00113 case 0:
00114 return $this->{$method}();
00115 case 1:
00116 return $this->{$method}($params[0]);
00117 case 2:
00118 return $this->{$method}($params[0], $params[1]);
00119 case 3:
00120 return $this->{$method}($params[0], $params[1], $params[2]);
00121 case 4:
00122 return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
00123 case 5:
00124 return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
00125 default:
00126 return call_user_func_array(array(&$this, $method), $params);
00127 break;
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 function _stop($status = 0) {
00138 exit($status);
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 function log($msg, $type = LOG_ERROR) {
00148 if (!class_exists('CakeLog')) {
00149 uses('cake_log');
00150 }
00151 if (is_null($this->_log)) {
00152 $this->_log = new CakeLog();
00153 }
00154 if (!is_string($msg)) {
00155 $msg = print_r($msg, true);
00156 }
00157 return $this->_log->write($type, $msg);
00158 }
00159
00160
00161
00162
00163
00164
00165 function _set($properties = array()) {
00166 if (is_array($properties) && !empty($properties)) {
00167 $vars = get_object_vars($this);
00168 foreach ($properties as $key => $val) {
00169 if (array_key_exists($key, $vars)) {
00170 $this->{$key} = $val;
00171 }
00172 }
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 function cakeError($method, $messages = array()) {
00186 if (!class_exists('ErrorHandler')) {
00187 App::import('Core', 'Error');
00188
00189 if (file_exists(APP . 'error.php')) {
00190 include_once (APP . 'error.php');
00191 } elseif (file_exists(APP . 'app_error.php')) {
00192 include_once (APP . 'app_error.php');
00193 }
00194 }
00195
00196 if (class_exists('AppError')) {
00197 $error = new AppError($method, $messages);
00198 } else {
00199 $error = new ErrorHandler($method, $messages);
00200 }
00201 return $error;
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 function _persist($name, $return = null, &$object, $type = null) {
00216 $file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
00217 if ($return === null) {
00218 if (!file_exists($file)) {
00219 return false;
00220 } else {
00221 return true;
00222 }
00223 }
00224
00225 if (!file_exists($file)) {
00226 $this->_savePersistent($name, $object);
00227 return false;
00228 } else {
00229 $this->__openPersistent($name, $type);
00230 return true;
00231 }
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 function _savePersistent($name, &$object) {
00244 $file = 'persistent' . DS . strtolower($name) . '.php';
00245 $objectArray = array(&$object);
00246 $data = str_replace('\\', '\\\\', serialize($objectArray));
00247 $data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
00248 cache($file, $data, '+1 day');
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258 function __openPersistent($name, $type = null) {
00259 $file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
00260 include($file);
00261
00262 switch($type) {
00263 case 'registry':
00264 $vars = unserialize(${$name});
00265 foreach ($vars['0'] as $key => $value) {
00266 App::import('Model', Inflector::classify($key));
00267 }
00268 unset($vars);
00269 $vars = unserialize(${$name});
00270 foreach ($vars['0'] as $key => $value) {
00271 foreach ($vars['0'][$key]->Behaviors->_attached as $behavior) {
00272 App::import('Behavior', $behavior);
00273 }
00274 ClassRegistry::addObject($key, $value);
00275 unset ($value);
00276 }
00277 unset($vars);
00278 break;
00279 default:
00280 $vars = unserialize(${$name});
00281 $this->{$name} = $vars['0'];
00282 unset($vars);
00283 break;
00284 }
00285 }
00286 }
00287 ?>