From 36e4bbe61009e0b06345a5b191828e7038baf6c0 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 15 Jun 2013 17:31:59 +0300 Subject: [PATCH] performance tricks. --- index.php | 4 ++-- ipf.php | 20 ++++++++++++++++---- ipf/project.php | 14 +------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/index.php b/index.php index 7e3a322..444325d 100644 --- a/index.php +++ b/index.php @@ -6,5 +6,5 @@ $ipf_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ipf' $project_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'project'; set_include_path(get_include_path() . PATH_SEPARATOR . $ipf_path . PATH_SEPARATOR . $project_path); require 'ipf.php'; -IPF::boot($ipf_path, $project_path); -return IPF_Project::getInstance()->run(); +return IPF::boot($ipf_path, $project_path) && IPF_Project::getInstance()->run(); + diff --git a/ipf.php b/ipf.php index 76d9767..bed0bf1 100644 --- a/ipf.php +++ b/ipf.php @@ -11,7 +11,7 @@ final class IPF { private static $settings = array(); - private static function applySettings($settings) + private static function applySettings(&$settings) { foreach($settings as $key=>$val) IPF::$settings[strtolower($key)] = $val; @@ -105,16 +105,28 @@ final class IPF } } + private static function requestedFileExists() + { + $parts = explode('?', $_SERVER['REQUEST_URI'], 2); + $path = $_SERVER['DOCUMENT_ROOT'] . urldecode($parts[0]); + return is_file($path); + } + public static function boot($ipf_path, $project_path) { - IPF::$settings['ipf_path']=$ipf_path; - IPF::$settings['project_path']=$project_path; + if (php_sapi_name() === 'cli-server' && IPF::requestedFileExists()) + return false; + + IPF::$settings['ipf_path'] = $ipf_path; + IPF::$settings['project_path'] = $project_path; + try { IPF::loadSettings(); - date_default_timezone_set(IPF::$settings['time_zone']); + date_default_timezone_set(IPF::$settings['time_zone']); } catch(IPF_Exception_Settings $e) { die('Setting Error: '.$e->getMessage()."\n"); } + return true; } private function __construct() {} diff --git a/ipf/project.php b/ipf/project.php index a2b3679..3f2de1b 100644 --- a/ipf/project.php +++ b/ipf/project.php @@ -153,19 +153,7 @@ final class IPF_Project{ $cli->run(); } - private function requestedFileExists() - { - $parts = explode('?', $_SERVER['REQUEST_URI'], 2); - $path = $_SERVER['DOCUMENT_ROOT'] . urldecode($parts[0]); - return is_file($path); - } - public function run() { - $sapiName = php_sapi_name(); - - if ($sapiName === 'cli-server' && $this->requestedFileExists()) - return false; - if (IPF::get('debug')) { $this->sqlProfiler = new IPF_ORM_Connection_Profiler(); IPF_ORM_Manager::getInstance()->dbListeners[] = $this->sqlProfiler; @@ -173,7 +161,7 @@ final class IPF_Project{ IPF_ORM_Manager::getInstance()->openConnection(IPF::get('database', IPF::get('dsn'))); - if ($sapiName === 'cli') { + if (php_sapi_name() === 'cli') { $this->cli(); } else { $this->loadModels(); -- 2.49.0