ソースたどってみた


ソースをたどることがすごく苦手なので
どういう動きをしているのか知る為+ソース読解力を高める為
ちょっと気になった関数を調べてみました。


cakeError関数


/**
* Used to report user friendly errors.
* If there is a file app/error.php or app/app_error.php this file will be loaded
* error.php is the AppError class it should extend ErrorHandler class.
*
* @param string $method Method to be called in the error class (AppError or ErrorHandler classes)
* @param array $messages Message that is to be displayed by the error class
* @return error message
* @access public
*/
function cakeError($method, $messages = array()) {
if (!class_exists('ErrorHandler')) {
App::import('Core', 'Error');

if (file_exists(APP . 'error.php')) {
include_once (APP . 'error.php');
} elseif (file_exists(APP . 'app_error.php')) {
include_once (APP . 'app_error.php');
}
}

if (class_exists('AppError')) {
$error = new AppError($method, $messages);
} else {
$error = new ErrorHandler($method, $messages);
}
return $error;
}






/**
* Redirects to given $url, after turning off $this->autoRender.
* Script execution is halted after the redirect.
*
* @param mixed $url A string or array-based URL pointing to another location within the app, or an absolute URL
* @param integer $status Optional HTTP status code (eg: 404)
* @param boolean $exit If true, exit() will be called after the redirect
* @return mixed void if $exit = false. Terminates script if $exit = true
* @access public
* @link http://book.cakephp.org/view/425/redirect
*/
function redirect($url, $status = null, $exit = true) {
$this->autoRender = false;

if (is_array($status)) {
extract($status, EXTR_OVERWRITE);
}
$response = $this->Component->beforeRedirect($this, $url, $status, $exit);

if ($response === false) {
return;
}
if (is_array($response)) {
foreach ($response as $resp) {
if (is_array($resp) && isset($resp['url'])) {
extract($resp, EXTR_OVERWRITE);
} elseif ($resp !== null) {
$url = $resp;
}
}
}

if (function_exists('session_write_close')) {
session_write_close();
}

if (!empty($status)) {
$codes = array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Large',
415 => 'Unsupported Media Type',
416 => 'Requested range not satisfiable',
417 => 'Expectation Failed',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Time-out'
);
if (is_string($status)) {
$codes = array_flip($codes);
}

if (isset($codes[$status])) {
$code = $msg = $codes[$status];
if (is_numeric($status)) {
$code = $status;
}
if (is_string($status)) {
$msg = $status;
}
$status = "HTTP/1.1 {$code} {$msg}";
} else {
$status = null;
}
}

if (!empty($status)) {
$this->header($status);
}
if ($url !== null) {
$this->header('Location: ' . Router::url($url, true));
}

if (!empty($status) && ($status >= 300 && $status < 400)) {
$this->header($status);
}
if ($exit) {
$this->_stop();
}
}





「::」はインスタンス化無しでstaticなメソッドを実行ということなんだろうけど、
PHP4の場合は戻り値の変数がstatic宣言されていれば、そのメソッドはstaticなメソッドでみなされるのかな?