/** * @Override */ public function render() { $file = Atto::makeAccessPath(array(Atto::dir_error(), Atto::dir_atto_error()), array($this->status, 'etc'), array('.html', '.php')); $this->error_message = $this->getMessage(); $this->title = $this->status . ' ' . AttoHttpHelper::getTextByResponseCode($this->status); AttoHttpHelper::setResponseCode($this->status); include $file; }
/** * @Override */ public function render() { if (is_file($this->view)) { ob_start(); include $this->view; if ($this->layout) { $this->content_for_layout = ob_get_clean(); ob_start(); include Atto::makeAccessPath(array(Atto::dir_layout(), '', Atto::dir_atto_layout()), array($this->layout, 'default'), array('', '.php')); } ob_end_flush(); } }
public function __construct(array $params) { $params['type'] = strtolower($params['type']); switch ($params['type']) { case 'mysql': case 'pgsql': break; case 'postgresql': $params['type'] = 'pgsql'; break; default: throw OutOfBoundsException('想定外のDBです'); } $class = 'AttoDbo_Connection' . ucfirst($params['type']); if (!class_exists($class, false)) { require Atto::dir_atto_classes() . 'atto-dao' . DS . 'connection-' . $params['type'] . '.php'; } $this->_con = new $class($params); }
/** * redirect * * @method redirect * @param {string} $url * @param {int} $response_code * @param {boolean} $is_exit exit()を実行するか */ public static function redirect($url, $response_code = 302, $is_exit = true) { if (preg_match('#^https?://#iu', $url) <= 0) { $url = Atto::baseUrl() . $url; } $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!]|iu', '', $url); $url = str_replace(array('%0d', '%0a'), '', $url); if (AttoServerSoftware::isIIS()) { Atto::setHeader('Refresh', '0;url=' . $url); } else { if (php_sapi_name() != 'cgi-fcgi') { self::setResponseCode($response_code); } self::setHeader('Location', $url); } if ($is_exit) { exit; } }
* * attophp (tm) : Tha Small Development Framework * Copyright (c) 2012 nulil * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright © 2012 nulil * @link * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /* * _atto-gate.php * * The Front Controller to handle request */ require dirname(__FILE__) . '/../atto/atto.php'; Atto::cascade('app_root', array('admin_teimezone' => 'Asia/Tokyo', 'logging_level' => 4, 'logging_MiBbyte' => 2, 'logging_files' => array('log1.txt', 'log2.txt', 'log3.txt'), 'root_uri' => '..', 'htdocs_uri' => '..', 'app_uri' => '')); /** * app_root * * callback from Atto#cascade */ function app_root() { class AppDispatcher extends AttoStaticSiteWrapperDispatcher { } $dispatcher = new AppDispatcher(); $dispatcher->dispatch(); }
/** * isCacheRead * * @method isCacheRead * @param {timestamp} $cache * @param {string} $huckFile * @param {string} &$cacheFile * @return {boolean} is use cache file */ protected function _isCacheRead($cache, $hook_file, $cache_uri, &$cache_file) { $cache_dir = dirname(Atto::dir_var_cache() . substr($hook_file, strlen(Atto::dir_hook()))); $cache_file = $cache_dir . DS . $cache_uri; if (!file_exists($cache_dir)) { mkdir($cache_dir, 0755, true); } elseif (file_exists($cache_file)) { $cache_filetime = filemtime($cache_file); if ($cache <= $cache_filetime && filemtime($hook_file) < $cache_filetime) { return true; } } return false; }
* * * PHP versions 5 * * attophp (tm) : Tha Small Development Framework * Copyright (c) 2012 nulil * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright © 2012 nulil * @link * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ // require_once Atto::dir_atto_common() . 'functions.php'; if (empty($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) { $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; } if (empty($_SERVER['REQUEST_URI'])) { if (!empty($_SERVER['HTTP_X_ORIGINAL_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; } else { if (!empty($_SERVER['HTTP_X_REWRITE_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; } else { if (isset($_SERVER['PATH_INFO'])) { if ($_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME']) { $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; } else { $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $this->title; ?> </title> <!--[if lt IE 9]> <script type="text/javascript" src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> <style type="text/css">header,footer,nav,section,article,figure,aside { display:block; }</style> <![endif]--> <script type="text/javascript">!function(){document.documentElement.className=document.documentElement.className.replace(/(^ *| +)no-js( +| *$)/,'$1on-js$2');}()</script> <script type="text/javascript" src="//css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script> <script type="text/javascript" src="<?php echo Atto::baseUri(true); ?> js/mm.min.js"></script> </head> <body> <section> <h1><?php echo $this->title; ?> </h1> <p><?php echo $this->error_message; ?> </p> </section> </body>
/** * dir_app * * @method dir_app * @return string app directry path */ public static function dir_app() { static $val = null; if ($val === null) { if (starts_with('/', self::$_options['app_uri'])) { $val = realpath(self::$_options['app_uri']) . DS; } else { $val = realpath(self::dir_htdocs() . self::$_options['app_uri']) . DS; } $val = realpath(Atto::dir_gateScript() . str_replace('/', DS, self::$_options['app_uri'])) . DS; } return $val; }
/** * logging * * @param {integer} $logLv * @param {string} $header * @param {string} $data */ public static function logging($logLv, $header = '', $data = '') { try { $options = Atto::getOptions(); if (!$options || $options['logging_level'] < $logLv) { return; } $files = $options['logging_files']; $dir = Atto::dir_var_log(); $max_byte = $options['logging_MiBbyte'] * 1048576; $words = array(); $words[] = "\n・"; $words[] = date('Y/m/d H:i:s'); $words[] = "\t"; $words[] = $header; $words[] = ' : '; $words[] = function_exists('json_encode') ? json_encode($data) : var_export($data, true); $file_paths = array(); foreach ($files as $val) { $file_paths[] = $dir . $val; } $idx = 0; $near = 0; $fTime = 0; for ($i = 0, $l = count($file_paths); $i < $l; $i++) { if (file_exists($file_paths[$i])) { $fTime = filemtime($file_paths[$i]); } if ($near < $fTime) { $near = $fTime; $idx = $i; } } if (!file_exists($file_paths[$idx]) || filesize($file_paths[$idx]) + strlen(bin2hex(implode($words))) / 2 <= $max_byte) { $file_path = $file_paths[$idx]; if (file_exists($file_path)) { $mode = 'a'; } else { $mode = 'w'; $words[0] = '・'; } } else { $file_path = $idx + 1 < count($file_paths) ? $file_paths[$idx + 1] : $file_paths[0]; $mode = 'w'; $words[0] = '・'; } $count = 0; while (true) { $fp = fopen($file_path, $mode); if ($fp == false) { if ($count < 100) { usleep(1000); $count++; } else { return false; } } else { break; } } $count = 0; while (flock($fp, LOCK_EX) == false) { if ($count < 100) { usleep(1000); $count++; } else { return false; } } fputs($fp, implode($words)); flock($fp, LOCK_UN); fclose($fp); } catch (Exception $e) { $e->getMessage(); } }