public function injectLogger()
 {
     if (null !== $this->logger) {
         ErrorHandler::setLogger($this->logger, $this->channel);
         $this->logger = null;
     }
 }
 public function register(\Pimple\Container $pimple)
 {
     $pimple['debugbar.http_driver.drupal'] = function (\Pimple\Container $c) {
         return new DrupalHttpDriver();
     };
     $pimple['debugbar.collector.drupal_database'] = function ($c) {
         return new DrupalDbTngCollector();
     };
     $pimple['debugbar.collector.time_data'] = function ($c) {
         return new DrupalTimeDataCollector();
     };
     $pimple['debugbar.collector.menu_item'] = function ($c) {
         $item = menu_get_item();
         if (!$item) {
             $item = array();
         }
         return new \DebugBar\DataCollector\ConfigCollector($item, 'Menu');
     };
     $pimple['debugbar.collector.globals'] = function ($c) {
         return new GlobalsConfigCollector();
     };
     $pimple['debugbar.storage.drupal'] = function ($c) {
         /** @var \PDO $pdo */
         $pdo = $c['db']->getWrappedConnection();
         return new \DebugBar\Storage\PdoStorage($pdo);
     };
     $pimple['debugbar.storage.file'] = function ($c) {
         return new \DebugBar\Storage\FileStorage('var://debugbar');
     };
     $pimple->extend('debugbar', function (\DebugBar\DebugBar $debugbar, \Pimple\Container $c) {
         $debugbar->setStorage($c['debugbar.storage.drupal']);
         $debugbar->setHttpDriver($c['debugbar.http_driver.drupal']);
         \Symfony\Component\Debug\ErrorHandler::setLogger($c['debugbar.collector.messages'], 'scream');
         set_exception_handler(array($c['debugbar.collector.exceptions'], 'addException'));
         return $debugbar;
     });
     $pimple->extend('debugbar.renderer', function (\DebugBar\JavascriptRenderer $renderer, \Pimple\Container $c) {
         $renderer->setOpenHandlerUrl('/debugbar/open');
         return $renderer;
     });
 }
Example #3
0
 /**
  * Called directly from index.php
  * Starts up the Symfony components and the FoolFrame components
  */
 public function __construct()
 {
     $this->container = new ContainerBuilder();
     $this->container->register('profiler', 'Foolz\\Profiler\\Profiler')->addMethodCall('enable', []);
     $this->profiler = $this->container->get('profiler');
     class_alias('Foolz\\FoolFrame\\Model\\Plugins', 'Plugins');
     class_alias('Foolz\\FoolFrame\\Model\\SchemaManager', 'SchemaManager');
     class_alias('Foolz\\FoolFrame\\Model\\System', 'System');
     class_alias('Foolz\\FoolFrame\\Model\\User', 'User');
     class_alias('Foolz\\FoolFrame\\Model\\Users', 'Users');
     $this->route_collection = new RouteCollection();
     $this->logger = new MonoLogger('foolframe');
     $this->logger->pushHandler(new RotatingFileHandler(VAPPPATH . 'foolz/foolframe/logs/foolframe.log', 7, MonoLogger::WARNING));
     $this->logger->pushProcessor(new IntrospectionProcessor());
     $this->logger->pushProcessor(new WebProcessor());
     // special logger that saves stack traces from the exception handler
     $this->logger_trace = new MonoLogger('foolframe_trace');
     $this->logger_trace->pushHandler(new RotatingFileHandler(VAPPPATH . 'foolz/foolframe/logs/foolframe_trace.log', 7, MonoLogger::WARNING));
     $this->logger_trace->pushProcessor(new IntrospectionProcessor());
     $this->logger_trace->pushProcessor(new WebProcessor());
     if ('cli' !== php_sapi_name()) {
         error_reporting(-1);
         $this->error_handler = ErrorHandler::register();
         $this->error_handler->setLogger($this->logger_trace);
         $this->exception_handler = ExceptionHandler::register(false);
         $this->exception_handler->setLogger($this->logger);
         $this->exception_handler->setLoggerTrace($this->logger_trace);
     } elseif (!ini_get('log_errors') || ini_get('error_log')) {
         ini_set('display_errors', 1);
     }
     $this->container->register('autoloader', 'Foolz\\FoolFrame\\Model\\Autoloader')->addArgument($this)->addMethodCall('register');
     $this->container->register('logger', 'Foolz\\FoolFrame\\Model\\Logger')->addArgument($this)->addMethodCall('addLogger', [$this->logger])->addMethodCall('addLogger', [$this->logger_trace]);
     $this->container->register('config', 'Foolz\\FoolFrame\\Model\\Config')->addArgument($this);
     $this->container->register('doctrine', 'Foolz\\FoolFrame\\Model\\DoctrineConnection')->addArgument($this)->addArgument(new Reference('config'));
     $this->container->register('mailer', 'Foolz\\FoolFrame\\Model\\Mailer')->addArgument($this);
     $this->container->register('preferences', 'Foolz\\FoolFrame\\Model\\Preferences')->addArgument($this);
     $this->container->register('plugins', 'Foolz\\FoolFrame\\Model\\Plugins')->addArgument($this);
     $this->container->register('users', 'Foolz\\FoolFrame\\Model\\Users')->addArgument($this);
     $this->container->register('auth', 'Foolz\\FoolFrame\\Model\\Auth')->addArgument($this);
     $this->container->register('security', 'Foolz\\FoolFrame\\Model\\Security')->addArgument($this);
     $this->config = $this->getService('config');
     $this->preferences = $this->getService('preferences');
     // start up the caching system
     $caching_config = $this->config->get('foolz/foolframe', 'cache', '');
     switch ($caching_config['type']) {
         case 'redis':
             $mem_config = \Foolz\Cache\Config::forgeRedis();
             $mem_config->setFormat($caching_config['format']);
             $mem_config->setPrefix($caching_config['prefix']);
             $mem_config->setServers($caching_config['servers']);
             $mem_config->setThrow(true);
             Cache::instantiate($mem_config);
             break;
         case 'memcached':
             $mem_config = \Foolz\Cache\Config::forgeMemcached();
             $mem_config->setFormat($caching_config['format']);
             $mem_config->setPrefix($caching_config['prefix']);
             $mem_config->setServers($caching_config['servers']);
             $mem_config->setThrow(true);
             Cache::instantiate($mem_config);
             break;
         case 'apc':
             $apc_config = \Foolz\Cache\Config::forgeApc();
             $apc_config->setFormat($caching_config['format']);
             $apc_config->setPrefix($caching_config['prefix']);
             $apc_config->setThrow(true);
             Cache::instantiate($apc_config);
             break;
         case 'dummy':
             $dummy_config = \Foolz\Cache\Config::forgeDummy();
             $dummy_config->setFormat($caching_config['format']);
             $dummy_config->setPrefix($caching_config['prefix']);
             $dummy_config->setThrow(true);
             Cache::instantiate($dummy_config);
             break;
     }
     // run the Framework class for each module
     foreach ($this->config->get('foolz/foolframe', 'config', 'modules.installed') as $module) {
         if ($module['namespace'] !== 'foolz/foolframe') {
             $context = $module['context'];
             $this->child_contextes[$module['namespace']] = new $context($this);
         }
     }
     $this->profiler->log('Start Plugin instantiation');
     if (count($this->child_contextes)) {
         $this->getService('plugins')->instantiate();
     }
     $this->profiler->log('Stop Plugin instantiation');
 }
Example #4
0
<?php

use Silex\Application;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\Debug\ErrorHandler;
// Handler de Errors
$app->before(function (SymfonyRequest $request) use($app) {
    if ($app['debug'] !== true) {
        ErrorHandler::setLogger($app['monolog'], 'emergency');
        ErrorHandler::register();
    }
}, Application::EARLY_EVENT);
// Route de Error
$app->error(function (\Exception $exception, $code) use($app) {
    switch ($code) {
        case 404:
            // Pagina não encontrada
            $view = 'errors/404.html';
            break;
        case 403:
            // Sem Permissão
            $view = 'errors/403.html';
            break;
        default:
            $view = 'errors/error.html';
            break;
    }
    return $app['twig']->render($view, compact('exception', 'code'));
});