<commit_before><?php
/**
 * LIMBO
 *
 * @author <NAME> <<EMAIL>>
 *
 * MIT LICENSE
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

use \limbo\log;
use \limbo\web\web;
use \limbo\util\file;

/**
 * This is the main class for the application. It builds and maintains all the other objects
 * used for compiling the request and response.
 * 
 * Class limbo
 */
class limbo
	{
	/**
	 * @var string The version of the Limbo application
	 */
	public static $version	= '0.1.5.1135';
	
	/**
	 * @var array Contains the array of configuration options
	 */
	public static $config;
	
	/**
	 * @var array Contains a list of variables that will be extracted for each template
	 */
	public static $globals;
	
	/**
	 * @var object The micro timestamp of when the framework started up
	 */
	public static $startup;
	
	/**
	 * @var object Our lovely IoC controller Pimple
	 */
	private static $ioc;
	
	/**
	 * During construction we are going to perform a lot of bootstrapping. Collecting
	 * the helper functions, setting up the autoloader, error handler, timezone, etc.
	 * 
	 * We also create our request and response objects. Those are used regardless of how
	 * the application is called.
	 * 
	 * If this request is from the web though, we'll need to pass processing on to the
	 * web_init() method. Otherwise our job here of booting the app is done.
	 *
	 * If this is from a CLI call then the rest of the processing is done there.
	 */
	public function __construct ($bootstrap_only = false)
		{
		require (__DIR__ . '/../startup/helpers.php');
		
		$this->load_config ();
		$this->autoload_registration ();
		
		self::$startup = \limbo\util\time::microtime_float ();
		
		set_error_handler (array ('\limbo', 'error_handler'));
		
		date_default_timezone_set (config ('limbo.timezone'));
		
		if (config ('limbo.production'))
			{
			ini_set ('log_errors', 'On');
			ini_set ('display_errors', 'Off');
			ini_set ('error_reporting', E_ERROR | E_WARNING);
			}
			else
			{
			ini_set ('log_errors', 'On');
			ini_set ('display_errors', 'On');
			ini_set ('error_reporting', E_ALL | E_STRICT);
			}
		
		// Setup our IoC container to hold our objects
		self::$ioc = new \limbo\pimple\container ();
		
		self::$ioc['request'] = function ()
			{
			// Contains information regarding the current request
			return new \limbo\web\request ();
			};
		
		self::$ioc['response'] = function ()
			{
			// The response object that determines how we will respond to the request
			return new \limbo\web\response ();
			};
		
		register ('l', $this);
		
		// Is this a website request?
		if (self::invoked_from () == 'web')
			{
			$this->web_init ($bootstrap_only);
			}
		}
	
	/********************************************************************************
	 * Autoload methods
	 *******************************************************************************/
	
	public static function autoload_registration ()
		{
		spl_autoload_register (array (__CLASS__, 'autoload'));
		}
	
	/**
	 * Your run of the mill PSR-0 autoloader
	 * 
	 * @param string $class The class name to search for
	 */
	public static function autoload ($class)
		{
		$class = str_replace (array ('\\', '_'), DIRECTORY_SEPARATOR, $class);
		
		foreach ((array) config ('path.class') as $path)
			{
			$filename = $path . $class . '.php';
			
			if (is_readable ($filename))
				{
				require ($filename);
				
				return;
				}
			}
		}
	
	/********************************************************************************
	 * Initialization method
	 *******************************************************************************/
	
	/**
	 * This is the main processing unit of the application for web requests.
	 */
	public function web_init ($bootstrap_only = false)
		{
		config ('web.protocol', ((config ('web.ssl')) ? 'https' : 'http'));
		
		// Let's figure out where exactly we're being called from
		// and setup some useful variables.
		foreach (config ('web.domains') as $hostname)
			{
			if (self::request ()->server == $hostname)
				{
				config ('web.hostname', $hostname);
				
				// If this app requires SSL, make sure we have it.
				if (config ('web.ssl') && self::request ()->port == 80)
					{
					self::response ()
						->header ('Location', 'https://' . $hostname . self::request ()->url)
						->send ();
					}
				
				ini_set ('session.cookie_domain', $hostname);
				
				break;
				}
			}
		
		// Did we figure out a valid hostname? Redirect to a known one if not.
		if (config ('web.hostname') === null)
			{
			self::response ()
				->header ('Location', config ('web.protocol') . '://' . config ('web.domains')[0] . self::request ()->url)
				->send ();
			}
		
		limbo\log::debug ('Web request for: ' . self::request()->url);
		
		// Start the output buffer
		web::clear_buffer ();
		
		// We want to manage caching ourselves
		session_cache_limiter (false);
		
		// Begin the session
		if (! session_id ())
			{<commit_msg>New config option 'web.http'.<commit_after><?php
/**
 * LIMBO
 *
 * @author <NAME> <<EMAIL>>
 *
 * MIT LICENSE
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

use \limbo\log;
use \limbo\web\web;
use \limbo\util\file;

/**
 * This is the main class for the application. It builds and maintains all the other objects
 * used for compiling the request and response.
 * 
 * Class limbo
 */
class limbo
	{
	/**
	 * @var string The version of the Limbo application
	 */
	public static $version	= '0.1.5.1135';
	
	/**
	 * @var array Contains the array of configuration options
	 */
	public static $config;
	
	/**
	 * @var array Contains a list of variables that will be extracted for each template
	 */
	public static $globals;
	
	/**
	 * @var object The micro timestamp of when the framework started up
	 */
	public static $startup;
	
	/**
	 * @var object Our lovely IoC controller Pimple
	 */
	private static $ioc;
	
	/**
	 * During construction we are going to perform a lot of bootstrapping. Collecting
	 * the helper functions, setting up the autoloader, error handler, timezone, etc.
	 * 
	 * We also create our request and response objects. Those are used regardless of how
	 * the application is called.
	 * 
	 * If this request is from the web though, we'll need to pass processing on to the
	 * web_init() method. Otherwise our job here of booting the app is done.
	 *
	 * If this is from a CLI call then the rest of the processing is done there.
	 */
	public function __construct ($bootstrap_only = false)
		{
		require (__DIR__ . '/../startup/helpers.php');
		
		$this->load_config ();
		$this->autoload_registration ();
		
		self::$startup = \limbo\util\time::microtime_float ();
		
		set_error_handler (array ('\limbo', 'error_handler'));
		
		date_default_timezone_set (config ('limbo.timezone'));
		
		if (config ('limbo.production'))
			{
			ini_set ('log_errors', 'On');
			ini_set ('display_errors', 'Off');
			ini_set ('error_reporting', E_ERROR | E_WARNING);
			}
			else
			{
			ini_set ('log_errors', 'On');
			ini_set ('display_errors', 'On');
			ini_set ('error_reporting', E_ALL | E_STRICT);
			}
		
		// Setup our IoC container to hold our objects
		self::$ioc = new \limbo\pimple\container ();
		
		self::$ioc['request'] = function ()
			{
			// Contains information regarding the current request
			return new \limbo\web\request ();
			};
		
		self::$ioc['response'] = function ()
			{
			// The response object that determines how we will respond to the request
			return new \limbo\web\response ();
			};
		
		register ('l', $this);
		
		// Is this a website request?
		if (self::invoked_from () == 'web')
			{
			$this->web_init ($bootstrap_only);
			}
		}
	
	/********************************************************************************
	 * Autoload methods
	 *******************************************************************************/
	
	public static function autoload_registration ()
		{
		spl_autoload_register (array (__CLASS__, 'autoload'));
		}
	
	/**
	 * Your run of the mill PSR-0 autoloader
	 * 
	 * @param string $class The class name to search for
	 */
	public static function autoload ($class)
		{
		$class = str_replace (array ('\\', '_'), DIRECTORY_SEPARATOR, $class);
		
		foreach ((array) config ('path.class') as $path)
			{
			$filename = $path . $class . '.php';
			
			if (is_readable ($filename))
				{
				require ($filename);
				
				return;
				}
			}
		}
	
	/********************************************************************************
	 * Initialization method
	 *******************************************************************************/
	
	/**
	 * This is the main processing unit of the application for web requests.
	 */
	public function web_init ($bootstrap_only = false)
		{
		config ('web.protocol', ((config ('web.ssl')) ? 'https' : 'http'));
		
		// Let's figure out where exactly we're being called from
		// and setup some useful variables.
		foreach (config ('web.domains') as $hostname)
			{
			if (self::request ()->server == $hostname)
				{
				config ('web.hostname', $hostname);
				
				// If this app requires SSL, make sure we have it.
				if (config ('web.ssl') && self::request ()->port == 80)
					{
					self::response ()
						->header ('Location', 'https://' . $hostname . self::request ()->url)
						->send ();
					}
				
				ini_set ('session.cookie_domain', $hostname);
				
				break;
				}
			}
		
		// Did we figure out a valid hostname? Redirect to a known one if not.
		if (config ('web.hostname') === null)
			{
			self::response ()
				->header ('Location', config ('web.protocol') . '://' . config ('web.domains')[0] . self::request ()->url)
				->send ();
			}
		
		// Generate an easy to call web url
		config ('web.http', config ('web.protocol') . '://' . config ('web.hostname') . config ('web.root'));
		
		limbo\log::debug ('Web request for: ' . self::request()->url);
		
		// Start the output buffer
		web::clear_buffer ();
		
		// We want to manage caching ourselves
		session_cache_limiter (false);
		
		// Begin the session
		if (! session_id ())
			{
{'fraction_non_alphanumeric': 0.17055163832434675, 'fraction_numerical': 0.0018249688925756947, 'mean_word_length': 3.2691218130311617, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5679186', 'n_tokens_mistral': 3967, 'n_tokens_neox': 3316, 'n_words': 1274}