public function render() { $request = $this->_getController(); $ctrl = new ErrorController($this->request, $this->eventManager); if (!Configure::read('debug')) { $this->_template = 'error_fatal'; } $action = $this->request->action; if ($this->request->prefix) { $ctrl->layout = $this->request->prefix; $action = $this->request->prefix . '_' . $action; } $controller = ucfirst($this->request->controller); $action = $action; $error = $this->message; $code = $this->code; $file = $this->file; $line = $this->line; $ctrl->set(compact('controller', 'action', 'error', 'code', 'file', 'line')); if (isset($this->_template)) { $this->response->body($ctrl->render('/Error/' . $this->_template)); } else { $this->response->body($ctrl->render('/Error/' . $this->code)); } $this->response->send(); }
protected function table($table = null) { $conf = Configure::read('Datasources.' . $this->orm->database); if ($table) { return Inflector::camelCase($conf['prefix'] . $table); } else { return Inflector::camelCase($conf['prefix'] . $this->orm->table); } }
function pr($var, array $options = []) { if (Configure::read('debug')) { $opt = ''; if (isset($options)) { foreach ($options as $key => $value) { $opt .= $key . '="' . $value . '" '; } } printf('<pre %s>%s</pre>', $opt, print_r($var, true)); } }
public static function uuid() { $node = env('SERVER_ADDR'); if (strpos($node, ':') !== false) { if (substr_count($node, '::')) { $node = str_replace('::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node); } $node = explode(':', $node); $ipSix = ''; foreach ($node as $id) { $ipSix .= str_pad(base_convert($id, 16, 2), 16, 0, STR_PAD_LEFT); } $node = base_convert($ipSix, 2, 10); if (strlen($node) < 38) { $node = null; } else { $node = crc32($node); } } elseif (empty($node)) { $host = env('HOSTNAME'); if (empty($host)) { $host = env('HOST'); } if (!empty($host)) { $ip = gethostbyname($host); if ($ip === $host) { $node = crc32($host); } else { $node = ip2long($ip); } } } elseif ($node !== '127.0.0.1') { $node = ip2long($node); } else { $node = null; } if (empty($node)) { $node = crc32(Configure::read('Security.salt')); } if (function_exists('hphp_get_thread_id')) { $pid = hphp_get_thread_id(); } elseif (function_exists('zend_thread_id')) { $pid = zend_thread_id(); } else { $pid = getmypid(); } if (!$pid || $pid > 65535) { $pid = mt_rand(0, 0xfff) | 0x4000; } list($timeMid, $timeLow) = explode(' ', microtime()); return sprintf("%08x-%04x-%04x-%02x%02x-%04x%08x", (int) $timeLow, (int) substr($timeMid, 2) & 0xffff, mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node); }
public static function hash($string, $type = null, $salt = false) { if (empty($type)) { $type = static::$hashType; } $type = strtolower($type); if ($salt) { if (!is_string($salt)) { $salt = Configure::read('Security.hash'); } $string = $salt . $string; } return hash($type, $string); }
public function connection($conf) { $charset = $conf['encoding'] ? $conf['encoding'] : 'utf8'; try { $this->pdo = new PDO('mysql:host=' . $conf['host'] . ';dbname=' . $conf['database'] . ';', $conf['login'], $conf['password'], [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES {$charset}"]); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); return $this; } catch (PDOException $e) { if (Configure::read('debug') == 1) { die($e->getMessage()); } else { die('Impossible de se connecter à la base de donnée'); } } }