ErrorException: Undefined index: HTTP_ACCEPT_LANGUAGE
/var/vhosts/lasanbea/app/modules/Core/Bootstrap.php (126)
#0Engine\Application->Engine\{closure}(8, Undefined index: HTTP_ACCEPT_LANGUAGE, /var/vhosts/lasanbea/app/modules/Core/Bootstrap.php, 126, Array(di => Object(Phalcon\DI\FactoryDefault), config => Object(Engine\Config), languageObject => null, language => auto))
/var/vhosts/lasanbea/app/modules/Core/Bootstrap.php (126)
<?php
/*
  +------------------------------------------------------------------------+
  | PhalconEye CMS                                                         |
  +------------------------------------------------------------------------+
  | Copyright (c) 2013-2014 PhalconEye Team (http://phalconeye.com/)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file LICENSE.txt.                             |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@phalconeye.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Author: Ivan Vorontsov <ivan.vorontsov@phalconeye.com>                 |
  +------------------------------------------------------------------------+
*/
 
namespace Core;
 
use Core\Model\Language;
use Core\Model\LanguageTranslation;
use Core\Model\Settings;
use Core\Model\Widget;
use Engine\Bootstrap as EngineBootstrap;
use Engine\Cache\System;
use Engine\Config;
use Engine\Translation\Db as TranslationDb;
use Phalcon\DI;
use Phalcon\DiInterface;
use Phalcon\Events\Manager;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Mvc\View;
use Phalcon\Translate\Adapter\NativeArray as TranslateArray;
use User\Model\User;
 
/**
 * Core Bootstrap.
 *
 * @category  PhalconEye
 * @package   Core
 * @author    Ivan Vorontsov <ivan.vorontsov@phalconeye.com>
 * @copyright 2013-2014 PhalconEye Team
 * @license   New BSD License
 * @link      http://phalconeye.com/
 */
class Bootstrap extends EngineBootstrap
{
    /**
     * Current module name.
     *
     * @var string
     */
    protected $_moduleName = "Core";
 
    /**
     * Bootstrap construction.
     *
     * @param DiInterface $di Dependency injection.
     * @param Manager     $em Events manager object.
     */
    public function __construct($di, $em)
    {
        parent::__construct($di, $em);
 
        /**
         * Attach this bootstrap for all application initialization events.
         */
        $em->attach('init', $this);
    }
 
    /**
     * Init some subsystems after engine initialization.
     */
    public function afterEngine()
    {
        $di = $this->getDI();
        $config = $this->getConfig();
 
        $this->_initI18n($di, $config);
        if (!$config->installed) {
            return;
        }
 
        // Remove profiler for non-user.
        if (!User::getViewer()->id) {
            $di->remove('profiler');
        }
 
        // Init widgets system.
        $this->_initWidgets($di);
 
        /**
         * Listening to events in the dispatcher using the Acl.
         */
        if ($config->installed) {
            $this->getEventsManager()->attach('dispatch', $di->get('core')->acl());
        }
 
        // Install assets if required.
        if ($config->application->debug) {
            $di->get('assets')->installAssets(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
        }
    }
 
    /**
     * Init locale.
     *
     * @param DI     $di     Dependency injection.
     * @param Config $config Dependency injection.
     *
     * @return void
     */
    protected function _initI18n(DI $di, Config $config)
    {
        if ($di->get('app')->isConsole()) {
            return;
        }
 
        $languageObject = null;
        if (!$di->get('session')->has('language')) {
            /** @var Language $languageObject */
            if ($config->installed) {
                $language = Settings::getSetting('system_default_language');
                if ($language == 'auto') {
                    $locale = \Locale::acceptFromHttp($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
                    $languageObject = Language::findFirst("language = '" . $locale . "' OR locale = '" . $locale . "'");
                } else {
                    $languageObject = Language::findFirst("language = '" . $language . "'");
                }
            }
 
            if ($languageObject) {
                $di->get('session')->set('language', $languageObject->language);
                $di->get('session')->set('locale', $languageObject->locale);
            } else {
                $di->get('session')->set('language', Config::CONFIG_DEFAULT_LANGUAGE);
                $di->get('session')->set('locale', Config::CONFIG_DEFAULT_LOCALE);
            }
        }
 
        $language = $di->get('session')->get('language');
        $translate = null;
 
        if (!$config->application->debug || !$config->installed) {
            $messages = [];
            $directory = $config->application->languages->cacheDir;
            $extension = ".php";
 
            if (file_exists($directory . $language . $extension)) {
                require $directory . $language . $extension;
            } else {
                if (file_exists($directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension)) {
                    // fallback to default
                    require $directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension;
                }
            }
 
            $translate = new TranslateArray(
                [
                    "content" => $messages
                ]
            );
        } else {
            if (!$languageObject) {
                $languageObject = Language::findFirst(
                    [
                        'conditions' => 'language = :language:',
                        'bind' => (
                            [
                                "language" => $language
                            ]
                            )
                    ]
                );
 
                if (!$languageObject) {
                    $languageObject = Language::findFirst("language = '" . Config::CONFIG_DEFAULT_LANGUAGE . "'");
                }
            }
 
            $translate = new TranslationDb($di, $languageObject->getId(), new LanguageTranslation());
        }
 
        $di->set('i18n', $translate);
    }
 
    /**
     * Prepare widgets metadata for Engine.
     *
     * @param DI $di Dependency injection.
     *
     * @return void
     */
    protected function _initWidgets(DI $di)
    {
        if ($di->get('app')->isConsole()) {
            return;
        }
 
        $cache = $di->get('cacheData');
        $widgets = $cache->get(System::CACHE_KEY_WIDGETS_METADATA);
 
        if ($widgets === null) {
            $widgets = [];
            foreach (Widget::find() as $object) {
                $widgets[] = [$object->id, $object->getKey(), $object];
            }
 
            $cache->save(System::CACHE_KEY_WIDGETS_METADATA, $widgets, 0); // Unlimited.
        }
        $di->get('widgets')->addWidgets($widgets);
    }
#1Core\Bootstrap->_initI18n(Object(Phalcon\DI\FactoryDefault), Object(Engine\Config))
/var/vhosts/lasanbea/app/modules/Core/Bootstrap.php (80)
<?php
/*
  +------------------------------------------------------------------------+
  | PhalconEye CMS                                                         |
  +------------------------------------------------------------------------+
  | Copyright (c) 2013-2014 PhalconEye Team (http://phalconeye.com/)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file LICENSE.txt.                             |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@phalconeye.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Author: Ivan Vorontsov <ivan.vorontsov@phalconeye.com>                 |
  +------------------------------------------------------------------------+
*/
 
namespace Core;
 
use Core\Model\Language;
use Core\Model\LanguageTranslation;
use Core\Model\Settings;
use Core\Model\Widget;
use Engine\Bootstrap as EngineBootstrap;
use Engine\Cache\System;
use Engine\Config;
use Engine\Translation\Db as TranslationDb;
use Phalcon\DI;
use Phalcon\DiInterface;
use Phalcon\Events\Manager;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Mvc\View;
use Phalcon\Translate\Adapter\NativeArray as TranslateArray;
use User\Model\User;
 
/**
 * Core Bootstrap.
 *
 * @category  PhalconEye
 * @package   Core
 * @author    Ivan Vorontsov <ivan.vorontsov@phalconeye.com>
 * @copyright 2013-2014 PhalconEye Team
 * @license   New BSD License
 * @link      http://phalconeye.com/
 */
class Bootstrap extends EngineBootstrap
{
    /**
     * Current module name.
     *
     * @var string
     */
    protected $_moduleName = "Core";
 
    /**
     * Bootstrap construction.
     *
     * @param DiInterface $di Dependency injection.
     * @param Manager     $em Events manager object.
     */
    public function __construct($di, $em)
    {
        parent::__construct($di, $em);
 
        /**
         * Attach this bootstrap for all application initialization events.
         */
        $em->attach('init', $this);
    }
 
    /**
     * Init some subsystems after engine initialization.
     */
    public function afterEngine()
    {
        $di = $this->getDI();
        $config = $this->getConfig();
 
        $this->_initI18n($di, $config);
        if (!$config->installed) {
            return;
        }
 
        // Remove profiler for non-user.
        if (!User::getViewer()->id) {
            $di->remove('profiler');
        }
 
        // Init widgets system.
        $this->_initWidgets($di);
 
        /**
         * Listening to events in the dispatcher using the Acl.
         */
        if ($config->installed) {
            $this->getEventsManager()->attach('dispatch', $di->get('core')->acl());
        }
 
        // Install assets if required.
        if ($config->application->debug) {
            $di->get('assets')->installAssets(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
        }
    }
 
    /**
     * Init locale.
     *
     * @param DI     $di     Dependency injection.
     * @param Config $config Dependency injection.
     *
     * @return void
     */
    protected function _initI18n(DI $di, Config $config)
    {
        if ($di->get('app')->isConsole()) {
            return;
        }
 
        $languageObject = null;
        if (!$di->get('session')->has('language')) {
            /** @var Language $languageObject */
            if ($config->installed) {
                $language = Settings::getSetting('system_default_language');
                if ($language == 'auto') {
                    $locale = \Locale::acceptFromHttp($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
                    $languageObject = Language::findFirst("language = '" . $locale . "' OR locale = '" . $locale . "'");
                } else {
                    $languageObject = Language::findFirst("language = '" . $language . "'");
                }
            }
 
            if ($languageObject) {
                $di->get('session')->set('language', $languageObject->language);
                $di->get('session')->set('locale', $languageObject->locale);
            } else {
                $di->get('session')->set('language', Config::CONFIG_DEFAULT_LANGUAGE);
                $di->get('session')->set('locale', Config::CONFIG_DEFAULT_LOCALE);
            }
        }
 
        $language = $di->get('session')->get('language');
        $translate = null;
 
        if (!$config->application->debug || !$config->installed) {
            $messages = [];
            $directory = $config->application->languages->cacheDir;
            $extension = ".php";
 
            if (file_exists($directory . $language . $extension)) {
                require $directory . $language . $extension;
            } else {
                if (file_exists($directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension)) {
                    // fallback to default
                    require $directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension;
                }
            }
 
            $translate = new TranslateArray(
                [
                    "content" => $messages
                ]
            );
        } else {
            if (!$languageObject) {
                $languageObject = Language::findFirst(
                    [
                        'conditions' => 'language = :language:',
                        'bind' => (
                            [
                                "language" => $language
                            ]
                            )
                    ]
                );
 
                if (!$languageObject) {
                    $languageObject = Language::findFirst("language = '" . Config::CONFIG_DEFAULT_LANGUAGE . "'");
                }
            }
 
            $translate = new TranslationDb($di, $languageObject->getId(), new LanguageTranslation());
        }
 
        $di->set('i18n', $translate);
    }
 
    /**
     * Prepare widgets metadata for Engine.
     *
     * @param DI $di Dependency injection.
     *
     * @return void
     */
    protected function _initWidgets(DI $di)
    {
        if ($di->get('app')->isConsole()) {
            return;
        }
 
        $cache = $di->get('cacheData');
        $widgets = $cache->get(System::CACHE_KEY_WIDGETS_METADATA);
 
        if ($widgets === null) {
            $widgets = [];
            foreach (Widget::find() as $object) {
                $widgets[] = [$object->id, $object->getKey(), $object];
            }
 
            $cache->save(System::CACHE_KEY_WIDGETS_METADATA, $widgets, 0); // Unlimited.
        }
        $di->get('widgets')->addWidgets($widgets);
    }
#2Core\Bootstrap->afterEngine(Object(Phalcon\Events\Event), null, null)
#3Phalcon\Events\Manager->fireQueue(Array(0 => Object(Core\Bootstrap)), Object(Phalcon\Events\Event))
#4Phalcon\Events\Manager->fire(init:afterEngine, null)
/var/vhosts/lasanbea/app/engine/Application.php (158)
<?php
/*
  +------------------------------------------------------------------------+
  | PhalconEye CMS                                                         |
  +------------------------------------------------------------------------+
  | Copyright (c) 2013-2014 PhalconEye Team (http://phalconeye.com/)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file LICENSE.txt.                             |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@phalconeye.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Author: Ivan Vorontsov <ivan.vorontsov@phalconeye.com>                 |
  +------------------------------------------------------------------------+
*/
 
namespace Engine;
 
use Phalcon\DI;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Mvc\Application as PhalconApplication;
use Phalcon\Registry;
 
/**
 * Application class.
 *
 * @category  PhalconEye
 * @package   Engine
 * @author    Ivan Vorontsov <ivan.vorontsov@phalconeye.com>
 * @copyright 2013-2014 PhalconEye Team
 * @license   New BSD License
 * @link      http://phalconeye.com/
 */
class Application extends PhalconApplication
{
    const
        /**
         * Default module.
         */
        SYSTEM_DEFAULT_MODULE = 'core';
 
    use ApplicationInitialization;
 
    /**
     * Application configuration.
     *
     * @var Config
     */
    protected $_config;
 
    /**
     * Loaders for different modes.
     *
     * @var array
     */
    private $_loaders =
        [
            'normal' => [
                'environment',
                'cache',
                'annotations',
                'database',
                'router',
                'session',
                'flash',
                'engine'
            ],
            'console' => [
                'environment',
                'database',
                'cache',
                'engine'
            ],
            'session' => [
                'cache',
                'database',
                'session'
            ],
        ];
 
    /**
     * Constructor.
     */
    public function __construct()
    {
        /**
         * Create default DI.
         */
        $di = new DI\FactoryDefault();
 
        /**
         * Get config.
         */
        $this->_config = Config::factory();
 
        if (!$this->_config->installed) {
            define('CHECK_REQUIREMENTS', true);
            require_once(PUBLIC_PATH . '/requirements.php');
        }
 
        /**
         * Setup Registry.
         */
        $registry = new Registry();
        $registry->modules = array_merge(
            [self::SYSTEM_DEFAULT_MODULE, 'user'],
            $this->_config->modules->toArray()
        );
 
        $registry->directories = (object)[
            'engine' => ROOT_PATH . '/app/engine/',
            'modules' => ROOT_PATH . '/app/modules/',
            'plugins' => ROOT_PATH . '/app/plugins/',
            'widgets' => ROOT_PATH . '/app/widgets/',
            'libraries' => ROOT_PATH . '/app/libraries/'
        ];
 
        $di->set('registry', $registry);
 
        // Store config in the DI container.
        $di->setShared('config', $this->_config);
        parent::__construct($di);
    }
 
    /**
     * Runs the application, performing all initializations.
     *
     * @param string $mode Mode name.
     *
     * @return void
     */
    public function run($mode = 'normal')
    {
        if (empty($this->_loaders[$mode])) {
            $mode = 'normal';
        }
 
        // Set application main objects.
        $di = $this->_dependencyInjector;
        $di->setShared('app', $this);
        $config = $this->_config;
        $eventsManager = new EventsManager();
        $this->setEventsManager($eventsManager);
 
        // Init base systems first.
        $this->_initLogger($di, $config);
        $this->_initLoader($di, $config, $eventsManager);
 
        $this->_attachEngineEvents($eventsManager, $config);
 
        // Init services and engine system.
        foreach ($this->_loaders[$mode] as $service) {
            $serviceName = ucfirst($service);
            $eventsManager->fire('init:before' . $serviceName, null);
            $result = $this->{'_init' . $serviceName}($di, $config, $eventsManager);
            $eventsManager->fire('init:after' . $serviceName, $result);
        }
 
        $di->setShared('eventsManager', $eventsManager);
    }
 
    /**
     * Init modules and register them.
     *
     * @param array $modules Modules bootstrap classes.
     * @param null  $merge   Merge with existing.
     *
     * @return $this
     */
    public function registerModules($modules, $merge = null)
    {
        $bootstraps = [];
        $di = $this->getDI();
        foreach ($modules as $moduleName => $moduleClass) {
            if (isset($this->_modules[$moduleName])) {
                continue;
            }
 
            $bootstrap = new $moduleClass($di, $this->getEventsManager());
            $bootstraps[$moduleName] = function () use ($bootstrap, $di) {
                $bootstrap->registerServices();
 
                return $bootstrap;
            };
        }
 
        return parent::registerModules($bootstraps, $merge);
    }
 
    /**
     * Get application output.
     *
     * @return string
     */
    public function getOutput()
    {
        return $this->handle()->getContent();
    }
 
    /**
     * Clear application cache.
     *
     * @param string $themeDirectory Theme directory.
     *
     * @return void
     */
    public function clearCache($themeDirectory = '')
    {
        $cacheOutput = $this->_dependencyInjector->get('cacheOutput');
        $cacheData = $this->_dependencyInjector->get('cacheData');
        $config = $this->_dependencyInjector->get('config');
 
        $cacheOutput->flush();
        $cacheData->flush();
 
 
        // Files deleter helper.
        $deleteFiles = function ($files) {
            foreach ($files as $file) {
                if (is_file($file)) {
                    @unlink($file);
                }
            }
        };
 
        // Clear files cache.
        if (isset($config->application->cache->cacheDir)) {
            $deleteFiles(glob($config->application->cache->cacheDir . '*'));
        }
 
        // Clear view cache.
        $deleteFiles(glob($config->application->view->compiledPath . '*'));
 
        // Clear metadata cache.
        if ($config->application->metadata && $config->application->metadata->metaDataDir) {
            $deleteFiles(glob($config->application->metadata->metaDataDir . '*'));
        }
 
        // Clear annotations cache.
        if ($config->application->annotations && $config->application->annotations->annotationsDir) {
            $deleteFiles(glob($config->application->annotations->annotationsDir . '*'));
        }
 
        // Clear assets.
        $this->_dependencyInjector->getShared('assets')->clear(true, $themeDirectory);
    }
 
    /**
     * Check if application is used from console.
     *
     * @return bool
     */
    public function isConsole()
    {
        return (php_sapi_name() == 'cli');
    }
 
 
    /**
     * Attach required events.
     *
     * @param EventsManager $eventsManager Events manager object.
     * @param Config        $config        Application configuration.
     *
     * @return void
     */
    protected function _attachEngineEvents($eventsManager, $config)
    {
        // Attach modules plugins events.
        $events = $config->events->toArray();
        $cache = [];
        foreach ($events as $item) {
            list ($class, $event) = explode('=', $item);
            if (isset($cache[$class])) {
                $object = $cache[$class];
            } else {
                $object = new $class();
                $cache[$class] = $object;
            }
            $eventsManager->attach($event, $object);
        }
    }
#5Engine\Application->run()
/var/vhosts/lasanbea/public/index.php (70)
<?php
/*
  +------------------------------------------------------------------------+
  | PhalconEye CMS                                                         |
  +------------------------------------------------------------------------+
  | Copyright (c) 2013-2014 PhalconEye Team (http://phalconeye.com/)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file LICENSE.txt.                             |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@phalconeye.com so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Author: Ivan Vorontsov <ivan.vorontsov@phalconeye.com>                 |
  +------------------------------------------------------------------------+
*/

/**
 * Stages.
 */
define('APPLICATION_STAGE_DEVELOPMENT', 'development');
define('APPLICATION_STAGE_PRODUCTION', 'production');
define('APPLICATION_STAGE', (getenv('PHALCONEYE_STAGE') ? getenv('PHALCONEYE_STAGE') : APPLICATION_STAGE_PRODUCTION));

if (APPLICATION_STAGE == APPLICATION_STAGE_DEVELOPMENT) {
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
}

/**
 * Versions.
 */
define('PHALCONEYE_VERSION', '0.4.1');
define('PHALCON_VERSION_REQUIRED', '1.3.1');
define('PHP_VERSION_REQUIRED', '5.4.14');

/**
 * Check phalcon framework installation.
 */
if (!extension_loaded('phalcon')) {
    printf('Install Phalcon framework %s', PHALCON_VERSION_REQUIRED);
    exit(1);
}

/**
 * Pathes.
 */
define('DS', DIRECTORY_SEPARATOR);
if (!defined('ROOT_PATH')) {
    define('ROOT_PATH', dirname(dirname(__FILE__)));
}
if (!defined('PUBLIC_PATH')) {
    define('PUBLIC_PATH', dirname(__FILE__));
}

#require_once ROOT_PATH . "/vendor/autoload.php";
require_once ROOT_PATH . "/app/engine/Config.php";
require_once ROOT_PATH . "/app/engine/Exception.php";
require_once ROOT_PATH . "/app/engine/ApplicationInitialization.php";
require_once ROOT_PATH . "/app/engine/Application.php";

if (php_sapi_name() !== 'cli') {
    $application = new Engine\Application();
} else {
    require_once ROOT_PATH . "/app/engine/Cli.php";
    $application = new Engine\Cli();
}

$application->run();
echo $application->getOutput();
Phalcon Framework 1.3.2