Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lumen support #22

Closed
sky93 opened this issue Jun 19, 2015 · 4 comments
Closed

Add Lumen support #22

sky93 opened this issue Jun 19, 2015 · 4 comments

Comments

@sky93
Copy link

sky93 commented Jun 19, 2015

Please add Lumen support. http://lumen.laravel.com

@hotrush
Copy link

hotrush commented Jun 23, 2015

Copy NoCaptchaServiceProvider.php to your app/Providers and make some changes

<?php namespace App\Providers;

use Anhskohbo\NoCaptcha\NoCaptcha;
use Illuminate\Support\ServiceProvider;

class NoCaptchaServiceProvider extends ServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $app = $this->app;

        $this->bootConfig();

        $app['validator']->extend('captcha', function($attribute, $value) use ($app)
        {
            return $app['captcha']->verifyResponse($value, $app['request']->getClientIp());
        });

        if ($app->bound('form'))
        {
            $app['form']->macro('captcha', function($attributes = []) use ($app)
            {
                return $app['captcha']->display($attributes, $app->getLocale());
            });
        }
    }

    /**
     * //
     *
     * @return void
     */
    protected function bootConfig()
    {
        $path = __DIR__.'/../../vendor/anhskohbo/no-captcha/src/config/captcha.php';

        $this->mergeConfigFrom($path, 'captcha');
        // here all the problems... lumen does not have config_path() method
        $this->publishes([$path => storage_path('captcha')]);
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('captcha', function($app)
        {
            return new NoCaptcha(
                $app['config']['captcha.secret'],
                $app['config']['captcha.sitekey']
            );
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return ['captcha'];
    }

}

than add

$app->register('App\Providers\NoCaptchaServiceProvider');

and don't forget to turn on cookies/sessions middlewares

@anhskohbo
Copy link
Owner

Done
e372cff

@anhskohbo
Copy link
Owner

And thanks @hotrush

@hotrush
Copy link

hotrush commented Sep 8, 2015

@anhskohbo 👍 good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants