Newer
Older
Demian Katz
committed
<?php
// If the XHProf profiler is enabled, set it up now:
$xhprof = getenv('VUFIND_PROFILER_XHPROF');
if (!empty($xhprof)) {
if (extension_loaded('xhprof')) {
xhprof_enable();
} elseif (extension_loaded('tideways')) {
tideways_enable();
} else {
$xhprof = false;
}
Demian Katz
committed
}
// Define path to application directory
defined('APPLICATION_PATH')
|| define(
'APPLICATION_PATH',
(getenv('VUFIND_APPLICATION_PATH') ? getenv('VUFIND_APPLICATION_PATH')
: dirname(__DIR__))
);
Demian Katz
committed
// Define application environment
defined('APPLICATION_ENV')
|| define(
'APPLICATION_ENV',
(getenv('VUFIND_ENV') ? getenv('VUFIND_ENV') : 'production')
);
Demian Katz
committed
// Define default search backend identifier
defined('DEFAULT_SEARCH_BACKEND') || define('DEFAULT_SEARCH_BACKEND', 'Solr');
Demian Katz
committed
// Define path to local override directory
defined('LOCAL_OVERRIDE_DIR')
|| define(
'LOCAL_OVERRIDE_DIR',
(getenv('VUFIND_LOCAL_DIR') ? getenv('VUFIND_LOCAL_DIR') : '')
);
Demian Katz
committed
// Define path to cache directory
defined('LOCAL_CACHE_DIR')
|| define(
'LOCAL_CACHE_DIR',
(getenv('VUFIND_CACHE_DIR')
? getenv('VUFIND_CACHE_DIR')
: (strlen(LOCAL_OVERRIDE_DIR) > 0 ? LOCAL_OVERRIDE_DIR . '/cache' : ''))
// Save original working directory in case we need to remember our context, then
// switch to the application directory for convenience:
define('ORIGINAL_WORKING_DIRECTORY', getcwd());
Demian Katz
committed
chdir(APPLICATION_PATH);
// Ensure vendor/ is on include_path; some PEAR components may not load correctly
// otherwise (i.e. File_MARC may cause a "Cannot redeclare class" error by pulling
// from the shared PEAR directory instead of the local copy):
$pathParts[] = APPLICATION_PATH . '/vendor';
$pathParts[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $pathParts));
Demian Katz
committed
// Composer autoloading
if (file_exists('vendor/autoload.php')) {
$loader = include 'vendor/autoload.php';
}
if (!class_exists('Zend\Loader\AutoloaderFactory')) {
throw new RuntimeException('Unable to load Zend Framework autoloader.');
Demian Katz
committed
}
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
Demian Katz
committed
// Handle final profiling details, if necessary:
if ($xhprof) {
$xhprofData = extension_loaded('xhprof') ? xhprof_disable() : tideways_disable();
$xhprofRunId = uniqid();
$dir = ini_get('xhprof.output_dir');
if (empty($dir)) {
$dir = sys_get_temp_dir();
}
file_put_contents("$dir/$xhprofRunId.$suffix.xhprof", serialize($xhprofData));
Demian Katz
committed
$url = "$xhprof?run=$xhprofRunId&source=$suffix";
echo "<a href='$url'>Profiler output</a>";