<?php namespace Felixkiss\UniqueWithValidator;

use Illuminate\Support\ServiceProvider;

class UniqueWithValidatorServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadTranslationsFrom(
            __DIR__ . '/../../lang',
            'uniquewith-validator'
        );

        // Registering the validator extension with the validator factory
        $this->app['validator']->resolver(
            function($translator, $data, $rules, $messages, $customAttributes = array())
            {
                return new ValidatorExtension(
                    $translator,
                    $data,
                    $rules,
                    $messages,
                    $customAttributes
                );
            }
        );
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {

    }
}

<?php namespace Felixkiss\UniqueWithValidator;

use Illuminate\Support\ServiceProvider;

class UniqueWithValidatorServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadTranslationsFrom(
            __DIR__ . '/../../lang',
            'uniquewith-validator'
        );
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // Whenever the validator factory is accessed in the container, we set
        // the custom resolver on it (this works in Larvel >= 5.2 as well).
        $this->app->resolving('validator', function ($factory, $app) {
            $factory->resolver(function ($translator, $data, $rules, $messages, $customAttributes = []) {
                return new ValidatorExtension(
                    $translator,
                    $data,
                    $rules,
                    $messages,
                    $customAttributes
                );
            });
        });
    }
}

Switch to a new way of setting the resolver on the validation factory
Switch to a new way of setting the resolver on the validation factory

This is necessary, because since Laravel 5.2 the validator service provider is
deferred. We can't set it once at the beginning. Now it gets set in a callback
whenever someone resolves `validator` from the service container.

This also solves #18. We don't really need to defer anymore, because if the
validator service is not used, this service provider essentially only adds a
single entry to an array in the service container.
