<?php

// Define paths
$paths = array(
	'APPLICATION_PATH' => '../application',
        'APP_CLASSES_PATH' => '../application/classes',
        'MODULES_PATH' => '../application/modules',
        'LIBRARY_PATH' => '../library',
        'VENDORS_PATH' => '../library/Vendors',
        'CLASSES_PATH' => '../library/classes',
        'PUBLIC_PATH' => '../public',
        'PUBLIC_LIBRARY_PATH' => '../library/public',
        'STORAGE_PATH' => '../storage',
        // DEPRECATED
        'ROOT_PATH' => '..',
);

if (!function_exists('mb_ucfirst')) {
    function mb_ucfirst($str, $encoding = "UTF-8", $lower_str_end = false) {
      $first_letter = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding);
      $str_end = "";
      if ($lower_str_end) {
	$str_end = mb_strtolower(mb_substr($str, 1, mb_strlen($str, $encoding), $encoding), $encoding);
      }
      else {
	$str_end = mb_substr($str, 1, mb_strlen($str, $encoding), $encoding);
      }
      $str = $first_letter . $str_end;
      return $str;
    }
  }

foreach ($paths as $define => $path) {
	define($define, realpath($path) . DIRECTORY_SEPARATOR);
}

$host = explode('.', 'www.oil.szczecin.pl');
$sub = array_shift($host);
if ($sub == 'sklep') {
	$env = 'production';
}
elseif ($sub == 'qa') {
	$env = 'qa';
}
elseif ($sub == 'testing') {
	$env = 'testing';
}
else {
	$env = 'development';
}

// Define application environment
define('APPLICATION_ENV', $env);

if (APPLICATION_ENV != 'production') {
	require_once APPLICATION_PATH . 'debug.php';
}

// Ensure library/ is on include_path
set_include_path(join(PATH_SEPARATOR, array(
	CLASSES_PATH,
	get_include_path(),
)));

require_once APPLICATION_PATH . 'bootstrap.php';

$application = new Rtn_Application(
	APPLICATION_ENV, APPLICATION_PATH . 'configs/application.ini'
);

require_once APPLICATION_PATH . 'routes.php';

$application->bootstrap()->run();
