Skip to content

Commit

Permalink
Merge pull request #92 from ARCANEDEV/update-package
Browse files Browse the repository at this point in the history
Updating the package
  • Loading branch information
arcanedev-maroc committed Oct 2, 2019
2 parents 2c67130 + 94610fe commit 007d706
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 151 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reCAPTCHA comes in the form of a widget that you can easily add to your blog, fo
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `4.2` and `5.0` to `6.0` are supported.
* Laravel `4.2 | 5.x | 6.x` are supported.
* PSR-7 Support (ServerRequest verification).
* Made with :heart: & :coffee:.

Expand Down
2 changes: 1 addition & 1 deletion _docs/0-Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ reCAPTCHA comes in the form of a widget that you can easily add to your blog, fo
* Easy setup & configuration.
* Well documented & IDE Friendly.
* Well tested with maximum code quality.
* Laravel `4.2` and `5.0` to `6.0` are supported.
* Laravel `4.2 | 5.x | 6.x` are supported.
* PSR-7 Support (ServerRequest verification).
* Made with :heart: & :coffee:.

Expand Down
28 changes: 12 additions & 16 deletions _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

## Requirements

- PHP >= 7.1.3
- ext-curl: *
- ext-json: *

To use reCAPTCHA, you need to have a `site key` and a `secret key`. [Click here](https://www.google.com/recaptcha/admin) to setup a domain and get your keys.

The `site key` is using for the widget and the `secret key` is used to validate the response we get from Google.
Expand All @@ -31,7 +27,7 @@ For more details, check the [official documentation](https://developers.google.c
| ![noCaptcha v6.x][no_captcha_6_x] | ![Laravel v5.6][laravel_5_6] |
| ![noCaptcha v7.x][no_captcha_7_x] ![noCaptcha v8.x][no_captcha_8_x] | ![Laravel v5.7][laravel_5_7] |
| ![noCaptcha v9.x][no_captcha_9_x] | ![Laravel v5.8][laravel_5_8] |
| ![noCaptcha v10.x][no_captcha_10_x] | ![Laravel v6.0][laravel_6_0] |
| ![noCaptcha v10.x][no_captcha_10_x] | ![Laravel v6.x][laravel_6_x] |

> **Note :** This is a framework-agnostic package, so you can use any version of this package in your PHP project.
Expand All @@ -45,17 +41,17 @@ For more details, check the [official documentation](https://developers.google.c
[laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6"
[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7"
[laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8"
[laravel_6_0]: https://img.shields.io/badge/v6.0-supported-brightgreen.svg?style=flat-square "Laravel v6.0"

[no_captcha_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "noCaptcha v1.*"
[no_captcha_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "noCaptcha v3.*"
[no_captcha_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "noCaptcha v4.*"
[no_captcha_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "noCaptcha v5.*"
[no_captcha_6_x]: https://img.shields.io/badge/version-6.*-blue.svg?style=flat-square "noCaptcha v6.*"
[no_captcha_7_x]: https://img.shields.io/badge/version-7.*-blue.svg?style=flat-square "noCaptcha v7.*"
[no_captcha_8_x]: https://img.shields.io/badge/version-8.*-blue.svg?style=flat-square "noCaptcha v8.*"
[no_captcha_9_x]: https://img.shields.io/badge/version-9.*-blue.svg?style=flat-square "noCaptcha v9.*"
[no_captcha_10_x]: https://img.shields.io/badge/version-10.*-blue.svg?style=flat-square "noCaptcha v10.*"
[laravel_6_x]: https://img.shields.io/badge/v6.x-supported-brightgreen.svg?style=flat-square "Laravel v6.x"

[no_captcha_1_x]: https://img.shields.io/badge/version-1.x-blue.svg?style=flat-square "noCaptcha v1.x"
[no_captcha_3_x]: https://img.shields.io/badge/version-3.x-blue.svg?style=flat-square "noCaptcha v3.x"
[no_captcha_4_x]: https://img.shields.io/badge/version-4.x-blue.svg?style=flat-square "noCaptcha v4.x"
[no_captcha_5_x]: https://img.shields.io/badge/version-5.x-blue.svg?style=flat-square "noCaptcha v5.x"
[no_captcha_6_x]: https://img.shields.io/badge/version-6.x-blue.svg?style=flat-square "noCaptcha v6.x"
[no_captcha_7_x]: https://img.shields.io/badge/version-7.x-blue.svg?style=flat-square "noCaptcha v7.x"
[no_captcha_8_x]: https://img.shields.io/badge/version-8.x-blue.svg?style=flat-square "noCaptcha v8.x"
[no_captcha_9_x]: https://img.shields.io/badge/version-9.x-blue.svg?style=flat-square "noCaptcha v9.x"
[no_captcha_10_x]: https://img.shields.io/badge/version-10.x-blue.svg?style=flat-square "noCaptcha v10.x"

## Composer

Expand Down
28 changes: 1 addition & 27 deletions _docs/2-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,8 @@ NOCAPTCHA_SITEKEY=your-site-key
## Option 2 - Publish configuration file:

Run `php artisan vendor:publish` to publish the config file.
Run `php artisan vendor:publish --provider="Arcanedev\NoCaptcha\NoCaptchaServiceProvider"` to publish the config file.

Edit the `secret` and `sitekey` values in `config/no-captcha.php` file:

> For Laravel 4.2, run `php artisan config:publish arcanedev/no-captcha` and the file is located in `app/config/packages/arcanedev/no-captcha/config.php`.
```php
<?php

return [
'secret' => getenv('NOCAPTCHA_SECRET') ?: 'no-captcha-secret',
'sitekey' => getenv('NOCAPTCHA_SITEKEY') ?: 'no-captcha-sitekey',
'lang' => app()->getLocale(),

// ...
];
```

###### To :

```php
<?php

return [
'secret' => 'your-secret-key',
'sitekey' => 'your-site-key',
'lang' => 'en', // Optional

// ...
];
```
4 changes: 2 additions & 2 deletions _docs/3-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ Insert reCAPTCHA inside your form using one of this examples:
```php
{!! Form::open([...]) !!}
// Other inputs...
{!! Form::captcha() !!} OR {!! no_captcha()->display() !!}
{!! no_captcha()->display() !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}

// Remember what your mother told you
{!! Captcha::script() !!}
{!! no_captcha()->script() !!}
```

> For Laravel 4.2, use `{{ ... }}` instead of `{!! ... !!}`
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
"php": ">=7.2.0",
"ext-curl": "*",
"ext-json": "*",
"arcanedev/php-html": "~3.0.0",
"arcanedev/support": "~5.0.0",
"psr/http-message": "~1.0"
"arcanedev/php-html": "^3.0",
"arcanedev/support": "^5.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"arcanedev/laravel-html": "~6.0.0",
"orchestra/testbench": "~4.0.0",
"phpunit/phpunit": "~8.0",
"phpunit/phpcov": "~6.0"
"orchestra/testbench": "^4.0",
"phpunit/phpunit": "^8.0",
"phpunit/phpcov": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/no-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| -----------------------------------------------------------------
*/

'lang' => 'en',
'lang' => null,

/* -----------------------------------------------------------------
| Skip IPs
Expand Down
66 changes: 49 additions & 17 deletions src/NoCaptchaManager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php namespace Arcanedev\NoCaptcha;

use Illuminate\Support\Manager;
use Arcanedev\NoCaptcha\Contracts\NoCaptchaManager as NoCaptchaManagerContract;
use Arcanedev\NoCaptcha\Contracts\{
NoCaptchaManager as NoCaptchaManagerContract,
NoCaptcha as NoCaptchaContract,
};

/**
* Class NoCaptchaManager
Expand All @@ -21,9 +24,9 @@ class NoCaptchaManager extends Manager implements NoCaptchaManagerContract
*
* @return string
*/
public function getDefaultDriver()
public function getDefaultDriver(): string
{
return config('no-captcha.version');
return $this->config('version');
}

/* -----------------------------------------------------------------
Expand All @@ -38,32 +41,61 @@ public function getDefaultDriver()
*
* @return \Arcanedev\NoCaptcha\NoCaptchaV3|\Arcanedev\NoCaptcha\NoCaptchaV2
*/
public function version($version = null)
public function version($version = null): NoCaptchaContract
{
return $this->driver($version);
}

/**
* @return \Arcanedev\NoCaptcha\NoCaptchaV3
* Create the v2 captcha.
*
* @return \Arcanedev\NoCaptcha\NoCaptchaV2
*/
public function createV2Driver()
public function createV2Driver(): NoCaptchaContract
{
return new NoCaptchaV2(
config('no-captcha.secret'),
config('no-captcha.sitekey'),
config('no-captcha.lang') ?: $this->app->getLocale()
);
return $this->buildDriver(NoCaptchaV2::class);
}

/**
* Create the v3 captcha.
*
* @return \Arcanedev\NoCaptcha\NoCaptchaV3
*/
public function createV3Driver()
public function createV3Driver(): NoCaptchaContract
{
return $this->buildDriver(NoCaptchaV3::class);
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Build a driver.
*
* @param string $driver
*
* @return \Arcanedev\NoCaptcha\Contracts\NoCaptcha
*/
protected function buildDriver(string $driver): NoCaptchaContract
{
return $this->container->make($driver, [
'secret' => $this->config('secret'),
'siteKey' => $this->config('sitekey'),
'locale' => $this->config('lang') ?: $this->container->getLocale(),
]);
}

/**
* Get a value from the config file.
*
* @param string $key
*
* @return mixed
*/
protected function config(string $key = '')
{
return new NoCaptchaV3(
config('no-captcha.secret'),
config('no-captcha.sitekey'),
config('no-captcha.lang') ?: $this->app->getLocale()
);
return $this->container['config']->get("no-captcha.{$key}");
}
}
40 changes: 11 additions & 29 deletions src/NoCaptchaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php namespace Arcanedev\NoCaptcha;

use Arcanedev\LaravelHtml\Contracts\FormBuilder;
use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
use Arcanedev\Support\Providers\PackageServiceProvider as ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;

/**
* Class NoCaptchaServiceProvider
*
* @package Arcanedev\NoCaptcha
* @author ARCANEDEV <[email protected]>
*/
class NoCaptchaServiceProvider extends ServiceProvider
class NoCaptchaServiceProvider extends ServiceProvider implements DeferrableProvider
{
/* -----------------------------------------------------------------
| Properties
Expand All @@ -32,7 +32,7 @@ class NoCaptchaServiceProvider extends ServiceProvider
/**
* Register the service provider.
*/
public function register()
public function register(): void
{
parent::register();

Expand All @@ -43,20 +43,17 @@ public function register()
/**
* Bootstrap the application events.
*/
public function boot()
public function boot(): void
{
parent::boot();

$this->publishConfig();
$this->registerFormMacros($this->app);
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
public function provides(): array
{
return [
Contracts\NoCaptcha::class,
Expand All @@ -68,11 +65,12 @@ public function provides()
| -----------------------------------------------------------------
*/

private function registerNoCaptchaManager()
/**
* Register noCaptcha manager & contract.
*/
private function registerNoCaptchaManager(): void
{
$this->singleton(Contracts\NoCaptchaManager::class, function ($app) {
return new NoCaptchaManager($app);
});
$this->singleton(Contracts\NoCaptchaManager::class, NoCaptchaManager::class);

$this->bind(Contracts\NoCaptcha::class, function (Application $app) {
/** @var \Illuminate\Contracts\Config\Repository $config */
Expand All @@ -83,20 +81,4 @@ private function registerNoCaptchaManager()
);
});
}

/**
* Register Form Macros.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*/
private function registerFormMacros($app)
{
foreach ([FormBuilder::class, 'form'] as $alias) {
if ($app->bound($alias)) {
$app[$alias]->macro('captcha', function($name = null) use ($app) {
return $app[Contracts\NoCaptcha::class]->input($name);
});
}
}
}
}
31 changes: 0 additions & 31 deletions tests/Laravel/FormMacroTest.php

This file was deleted.

18 changes: 1 addition & 17 deletions tests/LaravelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,10 @@ abstract class LaravelTestCase extends BaseTestCase
*
* @return array
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
\Arcanedev\LaravelHtml\HtmlServiceProvider::class,
\Arcanedev\NoCaptcha\NoCaptchaServiceProvider::class,
];
}

/**
* Get package aliases.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageAliases($app)
{
return [
'Form' => \Arcanedev\LaravelHtml\Facades\Form::class,
'HTML' => \Arcanedev\LaravelHtml\Facades\Html::class,
];
}
}
Loading

0 comments on commit 007d706

Please sign in to comment.