<?php

namespace Ingot\Provider;

use Monolog\Handler\SyslogHandler;
use Ingot\Normalizer\NetGroupNormalizer;
use Silex\Application;

class IngotServiceProvider implements \Silex\ServiceProviderInterface
{
    public function register(Application $app)
    {
        $app['cache_dir']        = $app['root_dir'] . '/var/cache/' . $app['env'];
        $app['config.cache_dir'] = $app['cache_dir'] . '/config';

        $app['config.normalizer'] = $app->extend('config.normalizer', function ($normalizer, $app) {
            $normalizer->add(new NetGroupNormalizer($app['config.locator']));

            return $normalizer;
        });

        $app['monolog.handler'] = $app->share($app->extend('monolog.handler', function ($handler, $app) {
            if ($app['debug']) {
                return $handler;
            }

            return new SyslogHandler($app['syslog.identity'], $app['syslog.facility'], $app['monolog.level']);
        }));
    }

    public function boot(Application $app)
    {
    }
}
