2014-05-06 18:22:31 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2014-08-18 15:42:27 +04:00
|
|
|
* This file is a part of Mibew Messenger.
|
|
|
|
*
|
2023-05-30 21:49:59 +03:00
|
|
|
* Copyright 2005-2023 the original author or authors.
|
2014-05-06 18:22:31 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Initialize libraries
|
|
|
|
require_once(dirname(__FILE__) . '/libs/init.php');
|
|
|
|
|
|
|
|
use Mibew\Application;
|
2014-07-04 17:11:40 +04:00
|
|
|
use Mibew\Authentication\AuthenticationManager;
|
2015-03-20 17:59:11 +03:00
|
|
|
use Mibew\Cache\CacheFactory;
|
2014-12-10 19:21:59 +03:00
|
|
|
use Mibew\Mail\MailerFactory;
|
2016-12-28 19:31:22 +03:00
|
|
|
use Mibew\Plugin\PluginManager;
|
2014-07-02 14:44:16 +04:00
|
|
|
use Mibew\Routing\Router;
|
2015-03-20 16:08:04 +03:00
|
|
|
use Mibew\Routing\Loader\CacheLoader;
|
2014-11-11 13:34:04 +03:00
|
|
|
use Mibew\Routing\Loader\PluginLoader;
|
2014-07-02 14:44:16 +04:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
2014-11-11 13:34:04 +03:00
|
|
|
use Symfony\Component\Config\Loader\LoaderResolver;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
2014-07-02 14:44:16 +04:00
|
|
|
|
2015-03-20 17:59:11 +03:00
|
|
|
$configs = load_system_configs();
|
|
|
|
|
|
|
|
// Prepare the cache
|
|
|
|
$cache_factory = new CacheFactory($configs['cache']);
|
|
|
|
// For now directory for cache files cannot be changed via the configs file.
|
|
|
|
// TODO: Evaluate possibility of using custom cache directory.
|
|
|
|
$cache_factory->setOption('path', MIBEW_FS_ROOT . '/cache/stash');
|
2015-03-20 16:08:04 +03:00
|
|
|
|
2016-12-28 19:31:22 +03:00
|
|
|
// Run plugins
|
|
|
|
if (get_maintenance_mode() === false) {
|
2016-12-28 19:51:11 +03:00
|
|
|
$plugin_manager = PluginManager::getInstance();
|
|
|
|
$plugin_manager->setCache($cache_factory->getCache());
|
|
|
|
$plugin_manager->loadPlugins($configs['plugins']);
|
2016-12-28 19:31:22 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 16:08:04 +03:00
|
|
|
// The main route loader which loads nothig but works as a cache proxy for other
|
|
|
|
// loaders.
|
2015-03-20 17:59:11 +03:00
|
|
|
$route_loader = new CacheLoader($cache_factory->getCache());
|
2015-03-20 16:08:04 +03:00
|
|
|
// Real loaders are attached via the resolver.
|
2014-11-11 13:34:04 +03:00
|
|
|
$loader_resolver = new LoaderResolver(array(
|
|
|
|
$route_loader,
|
2015-03-20 16:08:04 +03:00
|
|
|
new YamlFileLoader(new FileLocator(array(MIBEW_FS_ROOT))),
|
2014-11-11 13:34:04 +03:00
|
|
|
new PluginLoader(),
|
|
|
|
));
|
2015-03-20 16:08:04 +03:00
|
|
|
|
2014-11-11 13:34:04 +03:00
|
|
|
$router = new Router($route_loader, 'configs/routing.yml');
|
2014-05-06 18:22:31 +04:00
|
|
|
|
2014-12-10 19:21:59 +03:00
|
|
|
$application = new Application($router, new AuthenticationManager());
|
2015-03-20 17:59:11 +03:00
|
|
|
$application->setCache($cache_factory->getCache());
|
2014-05-06 18:22:31 +04:00
|
|
|
|
2014-12-10 19:21:59 +03:00
|
|
|
// Use custom config-dependent mailer factory
|
|
|
|
$application->setMailerFactory(new MailerFactory($configs['mailer']));
|
|
|
|
|
2014-05-06 18:22:31 +04:00
|
|
|
// Process request
|
|
|
|
$request = Request::createFromGlobals();
|
|
|
|
$response = $application->handleRequest($request);
|
|
|
|
|
|
|
|
// Send response to the user
|
|
|
|
$response->send();
|