Beispiel #1
0
<?php

/**
 * My Application bootstrap file.
 */
// Load Nette Framework
require LIBS_DIR . '/Nette/loader.php';
// Enable Nette Debugger for error visualisation & logging
NDebugger::$logDirectory = dirname(__FILE__) . '/../log';
NDebugger::$strictMode = TRUE;
NDebugger::enable();
// Configure application
$configurator = new NConfigurator();
$configurator->setTempDirectory(dirname(__FILE__) . '/../temp');
// Enable RobotLoader - this will load all classes automatically
$configurator->createRobotLoader()->addDirectory(APP_DIR)->addDirectory(LIBS_DIR)->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(dirname(__FILE__) . '/config/config.neon');
$container = $configurator->createContainer();
// Opens already started session
if ($container->session->exists()) {
    $container->session->start();
}
// Setup router
$router = $container->router;
$router[] = new NRoute('index.php', 'Dashboard:default', NRoute::ONE_WAY);
$router[] = new NRoute('<presenter>/<action>[/<id>]', 'Dashboard:default');
// Configure and run the application!
$application = $container->application;
//$application->catchExceptions = TRUE;
$application->errorPresenter = 'Error';
Beispiel #2
0
 public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
 {
     error_reporting(E_ALL | E_STRICT);
     if (is_bool($mode)) {
         self::$productionMode = $mode;
     } elseif ($mode !== self::DETECT || self::$productionMode === NULL) {
         $mode = is_string($mode) ? preg_split('#[,\\s]+#', $mode) : array($mode);
         $mode[] = '127.0.0.1';
         $mode[] = '::1';
         self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $mode, TRUE);
     }
     if (is_string($logDirectory)) {
         self::$logDirectory = realpath($logDirectory);
         if (self::$logDirectory === FALSE) {
             throw new DirectoryNotFoundException("Directory '{$logDirectory}' is not found.");
         }
     } elseif ($logDirectory === FALSE) {
         self::$logDirectory = FALSE;
     } elseif (self::$logDirectory === NULL) {
         self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
     }
     if (self::$logDirectory) {
         ini_set('error_log', self::$logDirectory . '/php_error.log');
     }
     if (function_exists('ini_set')) {
         ini_set('display_errors', !self::$productionMode);
         ini_set('html_errors', FALSE);
         ini_set('log_errors', FALSE);
     } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) {
         throw new NotSupportedException('Function ini_set() must be enabled.');
     }
     if ($email) {
         if (!is_string($email)) {
             throw new InvalidArgumentException('Email address must be a string.');
         }
         self::$email = $email;
     }
     if (!defined('E_DEPRECATED')) {
         define('E_DEPRECATED', 8192);
     }
     if (!defined('E_USER_DEPRECATED')) {
         define('E_USER_DEPRECATED', 16384);
     }
     if (!self::$enabled) {
         register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
         set_exception_handler(array(__CLASS__, '_exceptionHandler'));
         set_error_handler(array(__CLASS__, '_errorHandler'));
         self::$enabled = TRUE;
     }
 }
Beispiel #3
0
	/**
	 * Enables displaying or logging errors and exceptions.
	 * @param  mixed         production, development mode, autodetection or IP address(es) whitelist.
	 * @param  string        error log directory; enables logging in production mode, FALSE means that logging is disabled
	 * @param  string        administrator email; enables email sending in production mode
	 * @return void
	 */
	public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
	{
		error_reporting(E_ALL | E_STRICT);

		// production/development mode detection
		if (is_bool($mode)) {
			self::$productionMode = $mode;

		} elseif ($mode !== self::DETECT || self::$productionMode === NULL) { // IP addresses or computer names whitelist detection
			$list = is_string($mode) ? preg_split('#[,\s]+#', $mode) : (array) $mode;
			if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$list[] = '127.0.0.1';
				$list[] = '::1';
			}
			self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $list, TRUE);
		}

		// logging configuration
		if (is_string($logDirectory)) {
			self::$logDirectory = realpath($logDirectory);
			if (self::$logDirectory === FALSE) {
				echo __METHOD__ . "() error: Log directory is not found or is not directory.\n";
				exit(254);
			}
		} elseif ($logDirectory === FALSE) {
			self::$logDirectory = FALSE;

		} elseif (self::$logDirectory === NULL) {
			self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
		}
		if (self::$logDirectory) {
			ini_set('error_log', self::$logDirectory . '/php_error.log');
		}

		// php configuration
		if (function_exists('ini_set')) {
			ini_set('display_errors', !self::$productionMode); // or 'stderr'
			ini_set('html_errors', FALSE);
			ini_set('log_errors', FALSE);

		} elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { // intentionally ==
			echo __METHOD__ . "() error: Unable to set 'display_errors' because function ini_set() is disabled.\n";
			exit(254);
		}

		if ($email) {
			if (!is_string($email)) {
				echo __METHOD__ . "() error: Email address must be a string.\n";
				exit(254);
			}
			self::$email = $email;
		}

		if (!defined('E_DEPRECATED')) {
			define('E_DEPRECATED', 8192);
		}

		if (!defined('E_USER_WARNING')) {
			define('E_USER_WARNING', 16384);
		}

		if (!self::$enabled) {
			register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
			set_exception_handler(array(__CLASS__, '_exceptionHandler'));
			set_error_handler(array(__CLASS__, '_errorHandler'));
			self::$enabled = TRUE;
		}
	}