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