#!/usr/bin/php
<?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',
	// DEPRECATED
	'ROOT_PATH' => '..',
);

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

$host = explode('.', explode(DIRECTORY_SEPARATOR,$realpath)[4]);
$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';
}else{
    system('pon tutko');
}

// 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'
);

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

array_shift($argv);

if ($argc == 2) {
	$file = array_shift($argv);
	require $file;
}
elseif ($argc > 3) {
	$class = array_shift($argv);
	$method = array_shift($argv);
	$params = $argv;
	$class::$method($params);
}
elseif ($argc == 3) {
	$class = array_shift($argv);
	$method = array_shift($argv);
	$class::$method();
}
else {
	echo "\nUsage: php index.php CLASS METHOD [par1 par2 par3 (...) parn]\n";
	echo "\nMethod will be called statically.\n";
	echo "\n";
	echo "\nUsage: php index.php FILENAME\n";
	echo "\nFile will be included and parsed.\n";
	echo "\n";
}
