src/FelixOnline/Base/App.php
public function run()
    {
        if (!$this->isRunningUnitTests())
        {
            $runner = new \League\BooBoo\Runner();

            if ($this->getMode() == self::MODE_HTTP) {
                $aFtr = new \League\BooBoo\Formatter\HtmlTableFormatter;
            } else {
                $aFtr = new \League\BooBoo\Formatter\CommandLineFormatter;
            }

            $null = new \League\BooBoo\Formatter\NullFormatter;

            if ($this->getOption('production')) {
                $aFtr->setErrorLimit(E_ERROR | E_USER_ERROR);
            } else {
                $aFtr->setErrorLimit(E_ERROR | E_WARNING | E_USER_ERROR | E_USER_WARNING);
            }
            $null->setErrorLimit(E_ALL);

            $runner->pushFormatter($null);
            $runner->pushFormatter($aFtr);

            if (
                !isset($this->container['sentry']) ||
                !($this->container['sentry'] instanceof \Raven_Client)
            ) {
                if (!isset(self::$options['sentry_dsn'])) {
                    $dsn = '';
                } else {
                    $dsn = self::$options['sentry_dsn'];
                }

                $app['sentry'] = new \Raven_Client($dsn);
            }

            $raven = new \League\BooBoo\Handler\RavenHandler($app['sentry']);
            $runner->pushHandler($raven);

            $runner->register();

            $this->container['booboo'] = $runner;
        } else {
            $this->container['booboo'] = null;
            $this->container['sentry'] = null;
        }

        if (
            !isset($this->container['env'])
            || is_null($this->container['env'])
        ) {
            if (
                $this->getMode() == self::MODE_HTTP ||
                $this->isRunningUnitTests()
            ) {
                try {
                    $this->getOption('base_url');
                } catch (\Exception $e) {
                    throw new InternalException('base_url must be set when running in a HTTP or Unit Test environment');
                }

                $this->container['env'] = new HttpEnvironment();
            } else {
                $this->container['env'] = new CliEnvironment();
            }
        }

        if (
            !isset($this->container['akismet']) ||
            is_null($this->container['akismet'])
        ) {
            // Initialize Akismet
            if (self::$options['production']) {
                $connector = new \Riv\Service\Akismet\Connector\Curl();
            } else {
                $connector = new \Riv\Service\Akismet\Connector\Test();
            }

            $this->container['akismet'] = new \Riv\Service\Akismet\Akismet($connector);
        }

        if (
            !isset($this->container['email']) ||
            is_null($this->container['email'])
        ) {
            // Initialize email
            if($this->isRunningUnitTests()) {
                $transport = \Swift_NullTransport::newInstance();
            } else {
                $transport = \Swift_MailTransport::newInstance(); // This is removed in swiftmailer 6, FIXME
            }

            $this->container['email'] = \Swift_Mailer::newInstance($transport);
        }

        if (
            !isset($this->container['cache']) ||
            is_null($this->container['cache'])
        ) {
            if (!(self::$options['production'])) {
                $driver = new \Stash\Driver\BlackHole();
            } else {
                if (!isset(self::$options['stash_cache_folder'])) {
                    $driver = new \Stash\Driver\FileSystem(array('path' => self::$options['stash_cache_folder']));
                } else {
                    $driver = new \Stash\Driver\FileSystem();
                }
            }

            $this->container['cache'] = new \Stash\Pool($driver);
        }

        if (
            !isset($this->container['currentuser'])
            || is_null($this->container['currentuser'])
            || !($this->container['currentuser'] instanceof AbstractCurrentUser)
        ) {
            $this->container['currentuser'] = new StubCurrentUser();
        }

        if (
            !isset($this->container['db']) ||
            !($this->container['db'] instanceof \ezSQL_mysqli)
        ) {
            if (isset(self::$options['db_port'])) {
                $port = self::$options['db_port'];
            } else {
                $port = null;
            }

            $db = new \ezSQL_mysqli();
            $status = @$db->quick_connect(
                self::$options['db_user'],
                self::$options['db_pass'],
                self::$options['db_name'],
                self::$options['db_host'],
                $port,
                'utf8'
            );

            if (!$status) {
                throw new DBConnectionException('Could not connect to database');
            }

            $db->show_errors();

            $this->container['db'] = $db;

            $this->container['db_log'] = array();
        }

        if (
            !isset($this->container['safesql']) ||
            !($this->container['safesql'] instanceof \SafeSQL_MySQLi)
        ) {
            $this->container['safesql'] = new \SafeSQL_MySQLi($this->container['db']->dbh);
        }
    }
public function run()
    {
        if (!$this->isRunningUnitTests())
        {
            $runner = new \League\BooBoo\Runner();

            if ($this->getMode() == self::MODE_HTTP) {
                $aFtr = new \League\BooBoo\Formatter\HtmlTableFormatter;
            } else {
                $aFtr = new \League\BooBoo\Formatter\CommandLineFormatter;
            }

            $null = new \League\BooBoo\Formatter\NullFormatter;

            if ($this->getOption('production')) {
                $aFtr->setErrorLimit(E_ERROR | E_USER_ERROR);
            } else {
                $aFtr->setErrorLimit(E_ERROR | E_WARNING | E_USER_ERROR | E_USER_WARNING);
            }
            $null->setErrorLimit(E_ALL);

            $runner->pushFormatter($null);
            $runner->pushFormatter($aFtr);

            if (
                !isset($this->container['sentry']) ||
                !($this->container['sentry'] instanceof \Raven_Client)
            ) {
                if (!isset(self::$options['sentry_dsn'])) {
                    $dsn = '';
                } else {
                    $dsn = self::$options['sentry_dsn'];
                }

                $app['sentry'] = new \Raven_Client($dsn);
            }

            $raven = new \League\BooBoo\Handler\RavenHandler($app['sentry']);
            $runner->pushHandler($raven);

            $runner->register();

            $this->container['booboo'] = $runner;
        } else {
            $this->container['booboo'] = null;
            $this->container['sentry'] = null;
        }

        if (
            !isset($this->container['env'])
            || is_null($this->container['env'])
        ) {
            if (
                $this->getMode() == self::MODE_HTTP ||
                $this->isRunningUnitTests()
            ) {
                try {
                    $this->getOption('base_url');
                } catch (\Exception $e) {
                    throw new InternalException('base_url must be set when running in a HTTP or Unit Test environment');
                }

                $this->container['env'] = new HttpEnvironment();
            } else {
                $this->container['env'] = new CliEnvironment();
            }
        }

        if (
            !isset($this->container['akismet']) ||
            is_null($this->container['akismet'])
        ) {
            // Initialize Akismet
            if (self::$options['production']) {
                $connector = new \Riv\Service\Akismet\Connector\Curl();
            } else {
                $connector = new \Riv\Service\Akismet\Connector\Test();
            }

            $this->container['akismet'] = new \Riv\Service\Akismet\Akismet($connector);
        }

        if (
            !isset($this->container['email']) ||
            is_null($this->container['email'])
        ) {
            // Initialize email
            if($this->isRunningUnitTests()) {
                $transport = \Swift_NullTransport::newInstance();
            } else {
                $transport = \Swift_MailTransport::newInstance(); // This is removed in swiftmailer 6, FIXME
            }

            $this->container['email'] = \Swift_Mailer::newInstance($transport);
        }

        if (
            !isset($this->container['cache']) ||
            is_null($this->container['cache'])
        ) {
            if (!(self::$options['production'])) {
                $driver = new \Stash\Driver\BlackHole();
            } else {
                if (!isset(self::$options['stash_cache_folder'])) {
                    $driver = new \Stash\Driver\FileSystem(array('path' => self::$options['stash_cache_folder']));
                } else {
                    $driver = new \Stash\Driver\FileSystem();
                }
            }

            $this->container['cache'] = new \Stash\Pool($driver);
        }

        if (
            !isset($this->container['currentuser'])
            || is_null($this->container['currentuser'])
            || !($this->container['currentuser'] instanceof AbstractCurrentUser)
        ) {
            $this->container['currentuser'] = new StubCurrentUser();
        }

        if (
            !isset($this->container['db']) ||
            !($this->container['db'] instanceof \ezSQL_mysqli)
        ) {
            if (isset(self::$options['db_port'])) {
                $port = self::$options['db_port'];
            } else {
                $port = null;
            }

            $db = new \ezSQL_mysqli();
            $status = @$db->quick_connect(
                self::$options['db_user'],
                self::$options['db_pass'],
                self::$options['db_name'],
                self::$options['db_host'],
                $port,
                'utf8'
            );

            if (!$status) {
                throw new DBConnectionException('Could not connect to database');
            }

            $db->show_errors();

            $this->container['db'] = $db;

            $this->container['db_log'] = array();
        }

        if (
            !isset($this->container['safesql']) ||
            !($this->container['safesql'] instanceof \SafeSQL_MySQLi)
        ) {
            $this->container['safesql'] = new \SafeSQL_MySQLi($this->container['db']->dbh);
        }
    }
Initialize app