object.php
Go to the documentation of this file.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
00056 function Object() {
00057 $args = func_get_args();
00058 if (method_exists($this, '__destruct')) {
00059 register_shutdown_function (array(&$this, '__destruct'));
00060 }
00061 call_user_func_array(array(&$this, '__construct'), $args);
00062 }
00063
00064
00065
00066
00067
00068
00069 function __construct() {
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079 function toString() {
00080 $class = get_class($this);
00081 return $class;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 function requestAction($url, $extra = array()) {
00093 if (!empty($url)) {
00094 $dispatcher =& new Dispatcher();
00095 if (isset($this->plugin)) {
00096 $extra['plugin'] = $this->plugin;
00097 }
00098 if (in_array('return', $extra, true)) {
00099 $extra['return'] = 0;
00100 $extra['bare'] = 1;
00101 $extra['requested'] = 1;
00102 ob_start();
00103 $out = $dispatcher->dispatch($url, $extra);
00104 $out = ob_get_clean();
00105 return $out;
00106 } else {
00107 $extra['return'] = 1;
00108 $extra['bare'] = 1;
00109 $extra['requested'] = 1;
00110 return $dispatcher->dispatch($url, $extra);
00111 }
00112 } else {
00113 return false;
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 function log($msg, $type = LOG_ERROR) {
00124 if (!class_exists('CakeLog')) {
00125 uses('cake_log');
00126 }
00127
00128 if (is_null($this->_log)) {
00129 $this->_log = new CakeLog();
00130 }
00131
00132 if (!is_string($msg)) {
00133 ob_start();
00134 print_r ($msg);
00135 $msg=ob_get_contents();
00136 ob_end_clean();
00137 }
00138
00139 switch($type) {
00140 case LOG_DEBUG:
00141 return $this->_log->write('debug', $msg);
00142 break;
00143 default:
00144 return $this->_log->write('error', $msg);
00145 break;
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 function cakeError($method, $messages) {
00159 if (!class_exists('ErrorHandler')) {
00160 uses('error');
00161 if (file_exists(APP . 'error.php')) {
00162 include_once (APP . 'error.php');
00163 }
00164 }
00165
00166 if (class_exists('AppError')) {
00167 $error = new AppError($method, $messages);
00168 } else {
00169 $error = new ErrorHandler($method, $messages);
00170 }
00171 return $error;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 function _persist($name, $return = null, &$object, $type = null) {
00189 $file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
00190 if ($return === null) {
00191 if (!file_exists($file)) {
00192 return false;
00193 } else {
00194 return true;
00195 }
00196 }
00197
00198 if (!file_exists($file)) {
00199 $this->_savePersistent($name, $object);
00200 return false;
00201 } else {
00202 $this->__openPersistent($name, $type);
00203 return true;
00204 }
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 function _savePersistent($name, &$object) {
00218 $file = 'persistent' . DS . strtolower($name) . '.php';
00219 $objectArray = array(&$object);
00220 $data = str_replace('\\', '\\\\', serialize($objectArray));
00221 $data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
00222 cache($file, $data, '+1 day');
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 function __openPersistent($name, $type = null) {
00234 $file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
00235 include($file);
00236
00237 switch($type) {
00238 case 'registry':
00239 $vars = unserialize(${$name});
00240 foreach ($vars['0'] as $key => $value) {
00241 loadModel(Inflector::classify($key));
00242 }
00243 unset($vars);
00244 $vars = unserialize(${$name});
00245 foreach ($vars['0'] as $key => $value) {
00246 ClassRegistry::addObject($key, $value);
00247 unset ($value);
00248 }
00249 unset($vars);
00250 break;
00251 default:
00252 $vars = unserialize(${$name});
00253 $this->{$name} = $vars['0'];
00254 unset($vars);
00255 break;
00256 }
00257 }
00258 }
00259 ?>