Skip to content

Commit e2f5162

Browse files
authored
Merge pull request #70 from UseMuffin/cake-4.x
Cake 4.x
2 parents 804cbba + 5c6a9b0 commit e2f5162

File tree

15 files changed

+191
-174
lines changed

15 files changed

+191
-174
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/composer.lock
22
/plugins
33
/vendor
4+
.phpunit.result.cache
5+
.idea

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
language: php
22

3-
dist: trusty
4-
53
php:
6-
- 5.6
74
- 7.2
8-
- 7.3
95
- 7.4
106

117
env:
@@ -16,25 +12,32 @@ matrix:
1612
fast_finish: true
1713

1814
include:
19-
- php: 7.1
15+
- php: 7.2
2016
env: PHPCS=1 DEFAULT=0
2117

22-
- php: 5.6
18+
- php: 7.2
19+
env: STATIC_ANALYSIS=1 DEFAULT=0
20+
21+
- php: 7.2
2322
env: PREFER_LOWEST=1
2423

2524
before_script:
26-
- if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi
25+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi
2726

2827
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction; fi
2928
- if [[ $PREFER_LOWEST = 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi
3029

30+
- if [[ $STATIC_ANALYSIS == 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi
31+
3132
script:
32-
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
33-
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
34-
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
33+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
34+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
35+
36+
- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
37+
- if [[ $STATIC_ANALYSIS == 1 ]]; then vendor/bin/phpstan analyse src; fi
3538

3639
after_success:
37-
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi
40+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi
3841

3942
notifications:
4043
email: false

README.md

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,96 +5,57 @@
55
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/footprint.svg?style=flat-square)](https://packagist.org/packages/muffin/footprint)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
77

8-
This plugin allows you to pass the currently logged in user to the model layer of a CakePHP 3
9-
application.
8+
This plugin allows you to pass the currently logged in user info to the model layer
9+
of a CakePHP application.
1010

11-
It comes bundled with the `FootprintBehavior` to allow you control over columns such as `user_id`,
12-
`created_by`, `company_id` just like the core's `TimestampBehavior`.
11+
It comes bundled with the `FootprintBehavior` to allow you control over columns
12+
such as `user_id`, `created_by`, `company_id` similar to the core's `TimestampBehavior`.
1313

1414
## Install
1515

1616
Using [Composer][composer]:
1717

1818
```
1919
composer require muffin/footprint
20-
2120
```
2221

2322
You then need to load the plugin by running console command:
2423

2524
```bash
26-
bin/cake plugin load Muffin/Footprint
25+
bin/cake plugin load Muffin/Footprint
2726
```
2827

2928
## Usage
3029

3130
### Trait
3231

33-
First, you will need to include the `Muffin\Footprint\Auth\FootprintAwareTrait` to your `AppController`:
32+
First, you will need to include the `Muffin\Footprint\Auth\FootprintAwareTrait`
33+
to your `AppController`:
3434

3535
```php
3636
use Muffin\Footprint\Auth\FootprintAwareTrait;
3737

3838
class AppController extends Controller
3939
{
4040
use FootprintAwareTrait;
41-
}
42-
```
43-
44-
This will attach the `Muffin\Footprint\Event\FootprintListener` to models
45-
which will inject the currently logged in user's instance on `Model.beforeSave`
46-
and `Model.beforeFind` in the `_footprint` key of `$options`.
47-
48-
The user record provided by `AuthComponent` is converted to `User` entity before
49-
passing to models. If your `AuthComponent` is configured to use a non-default
50-
users table you must set the `$_userModel` property of the trait to same table:
51-
52-
```php
53-
public function initialize()
54-
{
55-
parent::initialize();
5641

5742
// Specify the user model if required. Defaults to "Users".
5843
$this->_userModel = 'YourPlugin.Members';
59-
60-
$this->loadComponent('Auth', [
61-
'authenticate' => [
62-
'Form' => [
63-
'userModel' => $this->_userModel, // Use same model for AuthComponent
64-
],
65-
],
66-
]);
6744
}
6845
```
6946

70-
#### Using Footprint with cakephp/authentication
71-
72-
If you are using the `cakephp/authentication` plugin instead of the `AuthComponent`, you will need to update your controller to tell Footprint where to find the identity. To do so, update the trait declaration and overwride `_setCurrentUser` to get the identity from the request:
73-
74-
```php
75-
use Muffin\Footprint\Auth\FootprintAwareTrait;
47+
This will attach the `Muffin\Footprint\Event\FootprintListener` to models
48+
which will inject the currently logged in user's instance on `Model.beforeSave`
49+
and `Model.beforeFind` in the `_footprint` key of `$options`.
7650

77-
class AppController extends Controller
78-
{
79-
use FootprintAwareTrait {
80-
_setCurrentUser as _footprintSetCurrentUser;
81-
}
82-
83-
protected function _setCurrentUser($user = null)
84-
{
85-
if (!$user) {
86-
$user = $this->request->getAttribute('identity')->getOriginalData();
87-
}
88-
89-
return $this->_footprintSetCurrentUser($user);
90-
}
91-
}
92-
```
51+
Your controller needs to have either `cakephp/authentication` plugin's `AuthenticationComponent`
52+
or CakePHP core's deprecated `AuthComponent` loaded so that the user identity
53+
can be fetched.
9354

9455
### Behavior
9556

96-
To use the included behavior to automatically update the `created_by` and `modified_by` fields of a record for example,
97-
add the following to your table's `initialize()` method:
57+
To use the included behavior to automatically update the `created_by` and `modified_by`
58+
fields of a record for example, add the following to your table's `initialize()` method:
9859

9960
```php
10061
$this->addBehavior('Muffin/Footprint.Footprint');
@@ -117,9 +78,10 @@ $this->addBehavior('Muffin/Footprint.Footprint', [
11778
]);
11879
```
11980

120-
This will insert the currently logged in user's primary key in `user_id` and `modified_by` fields when creating
121-
a record, on the `modified_by` field again when updating the record and it will use the associated user record's
122-
company `id` in the `company_id` field when creating a record.
81+
This will insert the currently logged in user's primary key in `user_id` and `modified_by`
82+
fields when creating a record, on the `modified_by` field again when updating
83+
the record and it will use the associated user record's company `id` in the
84+
`company_id` field when creating a record.
12385

12486
## Warning
12587

@@ -136,18 +98,14 @@ is attached after `Controller::initialize()` is run.
13698
* Fork
13799
* Mod, fix
138100
* Test - this is important, so it's not unintentionally broken
139-
* Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of
140-
their own that I can ignore when I pull)
101+
* Commit - do not mess with license, todo, version, etc. (if you do change any,
102+
bump them into commits of their own that I can ignore when I pull)
141103
* Pull request - bonus point for topic branches
142104

143105
## Bugs & Feedback
144106

145107
http://github.com/usemuffin/footprint/issues
146108

147-
## Credits
148-
149-
This was originally inspired by [Ceeram/Blame].
150-
151109
## License
152110

153111
Copyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "muffin/footprint",
3-
"description": "CakePHP 3.0+ plugin to allow passing currently logged in user to model layer",
3+
"description": "CakePHP plugin to allow passing currently logged in user to model layer",
44
"type": "cakephp-plugin",
55
"keywords": [
66
"cakephp",
@@ -30,11 +30,15 @@
3030
"source": "https://github.com/usemuffin/footprint"
3131
},
3232
"require": {
33-
"cakephp/cakephp": "^3.5"
33+
"cakephp/cakephp": "^4.0"
3434
},
3535
"require-dev": {
36-
"cakephp/cakephp-codesniffer": "^3.0",
37-
"phpunit/phpunit": "^5.7.14|^6.0"
36+
"cakephp/cakephp-codesniffer": "^4.0",
37+
"phpunit/phpunit": "~8.5.0"
38+
},
39+
"scripts": {
40+
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
41+
"cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
3842
},
3943
"autoload": {
4044
"psr-4": {

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: 6
3+
checkGenericClassInNonGenericObjectType: false
4+
checkMissingIterableValueType: false
5+
treatPhpDocTypesAsCertain: false
6+
ignoreErrors:
7+
-
8+
message: "#^Negated boolean expression is always true\\.$#"
9+
count: 1
10+
path: src/Model/Behavior/FootprintBehavior.php

phpunit.xml.dist

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@
2222
</listener>
2323
</listeners>
2424

25-
<!-- Prevent coverage reports from looking in tests and vendors -->
2625
<filter>
27-
<blacklist>
28-
<directory suffix=".php">./vendor/</directory>
29-
<directory suffix=".ctp">./vendor/</directory>
30-
31-
<directory suffix=".php">./tests/</directory>
32-
<directory suffix=".ctp">./tests/</directory>
33-
</blacklist>
26+
<whitelist>
27+
<directory suffix=".php">./src/</directory>
28+
</whitelist>
3429
</filter>
3530
</phpunit>

0 commit comments

Comments
 (0)