Skip to content

Instantly share code, notes, and snippets.

@TomoakiNagahara
Last active November 25, 2015 10:02
Show Gist options
  • Save TomoakiNagahara/9c7746bc4b4cde77fbad to your computer and use it in GitHub Desktop.
Save TomoakiNagahara/9c7746bc4b4cde77fbad to your computer and use it in GitHub Desktop.
<?php
/**
* app.php
*
* There are web application that has been made in full scratch.
* Work in onepiece-framework.
*
* @creation 2015-11-12
* @version 1.0
* @package erabuhonyaku
* @author Tomoaki Nagahara <[email protected]>
*/
/****************************************************************************************************
*
* OnePiece
*
****************************************************************************************************/
// Include of OnePiece framework.
include('/www/op/core/OnePiece5.class.php');
// Set administrator setting.
Env::Set('admin-ip', '');
Env::Set('admin-mail', '');
// Re:Setting error reporting.
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 0);
// Re:Set Debug mode.
if( OnePiece5::Admin() and Toolbox::GetRequest('debug') ){
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);
}
// Instantiate
$op = new OnePiece5();
/****************************************************************************************************
*
* Dispatch
*
****************************************************************************************************/
// Remove URL Query.
list($uri, $query) = explode('?', $_SERVER['REQUEST_URI'].'?');
// Generate URL.
if( preg_match('|^(.+)(\.php)$|', $uri, $match) ){
// index.php
$url = $uri;
}else if( preg_match('|\.[0-9a-z]{3,4}$|', $uri) ){
// Does not exist file.
OnePiece5::StackError("Does not exist file.\n($uri)");
$url = '/index.php';
}else{
// directory
$url = rtrim($uri,'/').'/index.php';
}
// Change current directory.
$chdir = dirname(dirname(__FILE__).$url);
chdir($chdir);
// Get application root.
$app_root = dirname(__FILE__);
// Do dispatch.
$dispatch = $app_root.$url;
if( $io = file_exists($dispatch) ){
$io = $op->Template($dispatch);
}
// Dispatch was failed.
if( $io === false ){
OnePiece5::StackError("\Dispatch\ was failed.\n (file={$dispatch}, URI={$_SERVER['REQUEST_URI']})",'en');
}
/****************************************************************************************************
*
* Finish
*
****************************************************************************************************/
if( Toolbox::isHtml() ){
// Debug.
$temp = array();
$temp['app_root'] = $app_root;
$temp['chdir'] = $chdir;
$temp['dispatch'] = $dispatch;
$temp['uri'] = $uri;
$temp['url'] = $url;
$temp['match'] = $match;
OnePiece5::D($temp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment