public static function register(Di $di) { static::$hostname = gethostname(); $di->remove('log'); static::$logger = null; $di->setShared('log', function () { $filePath = storagePath('logs'); is_dir($filePath) or mkdir($filePath, 0777, true); $filePath .= '/' . Config::get('app.log.file', 'phwoolcon.log'); $logger = new File($filePath); $formatter = $logger->getFormatter(); if ($formatter instanceof Line) { $formatter->setDateFormat('Y-m-d H:i:s'); $formatter->setFormat('[%date%]{host}[%type%] {request} %message%'); } return $logger; }); }
public static function initialize($rootPath, $hostname = null) { static::$initializeTime = microtime(true); // get site root if ($rootPath) { static::$rootPath = $rootPath; } elseif (!static::$rootPath) { throw new Exception('No site root detected'); } // load config if (!(static::$_config = apc_fetch(static::$rootPath))) { if (is_readable(static::$rootPath . '/site.json')) { static::$_config = json_decode(file_get_contents(static::$rootPath . '/site.json'), true); apc_store(static::$rootPath, static::$_config); } elseif (is_readable(static::$rootPath . '/Site.config.php')) { include static::$rootPath . '/Site.config.php'; apc_store(static::$rootPath, static::$_config); } } static::$config = static::$_config; // TODO: deprecate // get hostname if ($hostname) { static::$hostname = $hostname; } elseif (!static::$hostname) { if (!empty(static::$config['primary_hostname'])) { static::$hostname = static::$config['primary_hostname']; } else { throw new Exception('No hostname detected'); } } // get path stack if (!empty($_SERVER['REQUEST_URI'])) { $path = $_SERVER['REQUEST_URI']; if (false !== ($qPos = strpos($path, '?'))) { $path = substr($path, 0, $qPos); } static::$pathStack = static::$requestPath = static::splitPath($path); } // set useful transaction name for newrelic if (extension_loaded('newrelic')) { newrelic_name_transaction(static::getConfig('handle') . '/' . implode('/', site::$requestPath)); } // register class loader spl_autoload_register('Site::loadClass'); // set error handle set_error_handler('Site::handleError'); // register exception handler set_exception_handler('Site::handleException'); // check virtual system for site config static::loadConfig(__CLASS__); // get site title if (!static::$title) { static::$title = static::getConfig('label'); } // configure error display ini_set('display_errors', static::$debug); // check virtual system for proxy config if (class_exists('HttpProxy')) { static::loadConfig('HttpProxy'); } if (is_callable(static::$onInitialized)) { call_user_func(static::$onInitialized); } }
/** * get the hostname * @return string */ protected static function getHostname() { if (static::$hostname) { return static::$hostname; } return static::$hostname = isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] : NULL; }