Esempio n. 1
0
    });
    /**
     * Main logger file
     */
    $di->set('logger', function () {
        return new FileLogger(__DIR__ . '/../var/logs/' . date('Y-m-d') . '.log');
    }, true);
    /**
     * Error handler
     */
    set_error_handler(function ($errno, $errstr, $errfile, $errline) use($di) {
        if (!(error_reporting() & $errno)) {
            return;
        }
        $di->getFlash()->error($errstr);
        $di->getLogger()->log($errstr . ' ' . $errfile . ':' . $errline, Logger::ERROR);
        return true;
    });
    /**
     * Handle the request
     */
    $application = new Application();
    $application->setDI($di);
    /**
     * Register application modules
     */
    $application->registerModules(require __DIR__ . '/../common/config/modules.php');
    echo $application->handle()->getContent();
} catch (Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
Esempio n. 2
0
$di->set('notifications', function () {
    return new NotificationsChecker();
}, true);
//Translation application use Gettext or Native Array
$di->set('translation', function () use($di) {
    $language = $di->get('config')->language;
    $code = $language->code;
    if ($di->getCookies()->has('code')) {
        $code = $di->getCookies()->get('code')->getValue();
    }
    if ($language->gettext) {
        $translation = new Gettext(['locale' => $code, 'directory' => ROOT_DIR . 'core/lang', 'defaultDomain' => 'messages']);
    } else {
        $path = ROOT_DIR . 'core/lang/messages/' . $code . '.php';
        if (!file_exists($path)) {
            $di->getLogger()->error("You must specify a language file for language '{$code}'");
            $path = ROOT_DIR . 'core/lang/messages/en.php';
        }
        $translation = new NativeArray(['content' => require_once $path]);
    }
    return $translation;
}, true);
//Queue to deliver e-mails in real-time
$di->set('queue', function () use($di) {
    $config = $di->get('config');
    if (isset($config->beanstalk->disabled) && $config->beanstalk->disabled) {
        return new DummyServer();
    }
    if (!isset($config->beanstalk->host)) {
        throw new \Exception('Beanstalk is not configured');
    }