Skip to content

Commit

Permalink
Merge pull request #10 from nojimage/develop
Browse files Browse the repository at this point in the history
Add CakePHP 3.7 Support & Drop PHP 7.0 support
  • Loading branch information
nojimage authored Jan 7, 2019
2 parents 7d78103 + 009213b commit 1ca7d04
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2

Expand All @@ -14,6 +13,7 @@ env:
- CAKE_VERSION='3.4.*' DB=mysql db_dsn='mysql://root@0.0.0.0/cakephp_test'
- CAKE_VERSION='3.5.*' DB=mysql db_dsn='mysql://root@0.0.0.0/cakephp_test'
- CAKE_VERSION='3.6.*' DB=mysql db_dsn='mysql://root@0.0.0.0/cakephp_test'
- CAKE_VERSION='3.7.*' DB=mysql db_dsn='mysql://root@0.0.0.0/cakephp_test'
global:
- DEFAULT=1

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ The recommended way to install composer packages is:
composer require nojimage/cakephp-remember-me
```

You will need to add the following line to your application's bootstrap.php file:
(CakePHP >= 3.6.0) Load the plugin by adding the following statement in your project's `src/Application.php`:

```
$this->addPlugin('RememberMe');
```

(CakePHP <= 3.5.x) Load the plugin by adding the following statement in your project's `config/bootstrap.php` file:

```
Plugin::load('RememberMe');
Expand Down
15 changes: 15 additions & 0 deletions src/Auth/CookieAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cake\Controller\Component\AuthComponent;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\Http\Cookie\Cookie;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\I18n\FrozenTime;
Expand Down Expand Up @@ -142,6 +143,20 @@ protected function setCookie(Response $response, $cookie)
{
$config = $this->getConfig('cookie');
$expires = new FrozenTime($config['expires']);
if (class_exists(Cookie::class)) {
$cookieObj = new Cookie(
$this->getConfig('cookie.name'),
$cookie,
$expires,
$this->getConfig('cookie.path', '/'),
$this->getConfig('cookie.domain', ''),
$this->getConfig('cookie.secure', true),
$this->getConfig('cookie.httpOnly', true)
);

return $response->withCookie($cookieObj);
}

$config['value'] = $cookie;
$config['expire'] = $expires->format('U');

Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Auth/CookieAuthenticateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ public function testOnLogout()
];

// set login cookie
error_reporting(E_ALL ^ E_USER_DEPRECATED);
$response = (new Response())->withCookie('rememberMe', 'dummy');
error_reporting(E_ALL);

// test logout
$subject = $this->getMockBuilder(AuthComponent::class)
Expand Down Expand Up @@ -451,7 +453,9 @@ public function testWorkWithEncryptedCookieMiddleware()

$encoded = $this->auth->encryptToken('foo', 'series_foo_1', '123456');

error_reporting(E_ALL ^ E_USER_DEPRECATED);
$response = $response->withCookie('rememberMe', ['value' => $encoded]);
error_reporting(E_ALL);
$response = $middleware($request, $response, function ($request, $response) {
return $response;
});
Expand Down
9 changes: 9 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Cake\Core\Configure;
use Cake\Core\Plugin;

/**
Expand Down Expand Up @@ -28,5 +29,13 @@
require $root . '/config/bootstrap.php';
} else {
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

// Disable deprecations for now when using 3.6
if (version_compare(Configure::version(), '3.6.0', '>=')) {
error_reporting(E_ALL ^ E_USER_DEPRECATED);
}

Plugin::load('RememberMe', ['path' => dirname(dirname(__FILE__)) . DS]);

error_reporting(E_ALL);
}

0 comments on commit 1ca7d04

Please sign in to comment.