Skip to content

Commit aab7e9f

Browse files
committed
Merge pull request #1 from loadsys/f/initial-version
f/initial-version
2 parents ab3049e + 42facde commit aab7e9f

File tree

13 files changed

+893
-32
lines changed

13 files changed

+893
-32
lines changed

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
CakePHP 3
2-
31
/vendor/*
42
/config/app.php
53
/tmp/*
64
/logs/*
75

8-
CakePHP 2
9-
10-
/app/tmp/*
11-
/app/Config/core.php
12-
/app/Config/database.php
13-
/vendors/*
6+
# Ignore the composer lock file-- it should never be included in a distributed package.
7+
/composer.lock

.travis.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 5.6
7+
8+
# Cache the composer directories
9+
cache:
10+
directories:
11+
- $HOME/.composer/cache
12+
13+
# Environment Variables to set
14+
env:
15+
global:
16+
- APP_ENV=travis
17+
# Contains a $GITHUB_TOKEN env var for use with composer to avoid API limits.
18+
- secure: "WeyyqsgrzPQwi6/de/njgDhfrzKoqPPuUlpIvFg2v+blo42FbrdvTqmZyPRvNwc9to7ZMOC6ZTXXumU+KZuY3c4xUQXR8mO6T0wrqcTVhs7HRmIeqq4HWe3+O7dUIXibXv30TRYMuM9hwKPM9uRO6Xpj4v1WosylGUUpCcms6Qn4FwwjfK9VtfsOo6+jyG8rBc5fcMsdQ3IlBzw6wuDwVHRgOXKNCbBcaqD/KgE440qyQ20l0MKuKXu78Z0GQiF0GdIcqnEUOm802uYD0YY0x68xREk4NG8S4KV2hz8Glqex03jVUPV3sO+w60nFzmvcu6WeUuTvWaxc1g9k2b+2cNLJiIO/MDAkSghFtn8jY0pr/c9GNDzpXSXzD1ywu3npnZLcVshLZ/ZvLsUddNoyx4Rw61DJpu/NHHhXL3KUnlWQ6uFRe0IDoNNG3f9F94rt1r3sRMsSDoO7zNUrZhaW8cmhl31O3BqOWPxDoK1ARokfN9ox13EGtQb45ZFVCfRHTI1OpDpdWabrjcPQC7n7r5DpAq6Lupc9ufFYV9t0q8Gob4oQ2J/NwCFZozBMtbUMOAv7SjAc4wHWABUPQDEJN6OaM0ROzza+eXUreNXwlAlBtmPZ3TtglhPFxlFGyiMPs7UL7i1unTHHl556pRm1AmXqmFoCJn/aEI1N3YgT68s="
19+
20+
# Services to Enable
21+
services:
22+
23+
# Branches to be built or not
24+
branches:
25+
# Blacklist these branches
26+
except:
27+
- staging
28+
- gh-pages
29+
30+
before_install:
31+
- composer self-update
32+
33+
install:
34+
- composer config -g github-oauth.github.com $GITHUB_TOKEN
35+
- composer install --no-interaction
36+
37+
before_script:
38+
- phpenv rehash
39+
- vendor/bin/phpcs --config-set installed_paths vendor/loadsys/loadsys_codesniffer,vendor/cakephp/cakephp-codesniffer
40+
41+
script:
42+
- vendor/bin/phpcs -p --extensions=php --standard=Loadsys ./src ./tests ./config
43+
- vendor/bin/phpunit
44+
45+
notifications:
46+
email: false

LICENSE

Lines changed: 0 additions & 22 deletions
This file was deleted.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2015 Loadsys Web Strategies
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
# CakePHP-CreatorModifier
2-
A Cake 3 plugin that provides a Behavior to automatically set creator_id and modifier_id fields on save.
1+
# CakePHP 3 CreatorModifier plugin
2+
3+
[![Latest Version](https://img.shields.io/github/release/loadsys/CakePHP-CreatorModifier.svg?style=flat-square)](https://github.com/loadsys/CakePHP-CreatorModifier/releases)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Build Status](https://travis-ci.org/loadsys/CakePHP-CreatorModifier.svg?branch=master&style=flat-square)](https://travis-ci.org/loadsys/CakePHP-SocialLinks)
6+
[![Coverage Status](https://coveralls.io/repos/loadsys/CakePHP-CreatorModifier/badge.svg)](https://coveralls.io/r/loadsys/CakePHP-CreatorModifier)
7+
[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/cakephp-creatormodifier.svg?style=flat-square)](https://packagist.org/packages/loadsys/cakephp-creatormodifier)
8+
9+
Sets a `creator_id` and `modifier_id` on records during save using the logged in User.id field. Operates almost identically to the core's [Timestamp behavior](http://book.cakephp.org/3.0/en/orm/behaviors/timestamp.html).
10+
11+
12+
## Requirements
13+
14+
* PHP 5.4.16+
15+
* CakePHP 3.0+
16+
17+
18+
## Installation
19+
20+
### Composer
21+
22+
````bash
23+
$ composer require loadsys/loadsys/cakephp-creatormodifier:~1.0
24+
````
25+
26+
27+
## Usage
28+
29+
* Add this plugin for use in an Table, by adding this line to your Table's `initialize()` method.
30+
31+
````php
32+
$this->addBehavior('CreatorModifier.CreatorModifier');
33+
````
34+
35+
* Or to customize the behavior
36+
37+
````php
38+
$this->addBehavior('CreatorModifier.CreatorModifier', [
39+
'events' => [
40+
'Model.beforeSave' => [
41+
// Field storing the User.id who created the record,
42+
// only triggers on beforeSave when the Entity is new.
43+
'user_who_created_me_id' => 'new',
44+
45+
// Field storing the User.id who modified the record,
46+
// always triggers on beforeSave.
47+
'user_who_modified_me_id' => 'always'
48+
]
49+
],
50+
// The key to read from `\Cake\Network\Request->session()->read();`
51+
// to obtain the User.id value to set during saves.
52+
'sessionUserIdKey' => 'Auth.User.id',
53+
]);
54+
````
55+
56+
57+
## Contributing
58+
59+
### Reporting Issues
60+
61+
Please use [GitHub Isuses](https://github.com/loadsys/CakePHP-CreatorModifier/issues) for listing any known defects or issues.
62+
63+
### Development
64+
65+
When developing this plugin, please fork and issue a PR for any new development.
66+
67+
68+
## License
69+
70+
[MIT](https://github.com/loadsys/CakePHP-CreatorModifier/blob/master/LICENSE.md)
71+
72+
73+
## Copyright
74+
75+
[Loadsys Web Strategies](http://www.loadsys.com) 2015

composer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "loadsys/cakephp-creatormodifier",
3+
"description": "CakePHP 3.x Plugin to set Creator and Modifier automagic fields during save.",
4+
"type": "cakephp-plugin",
5+
"keywords": [
6+
"cakephp",
7+
"plugin",
8+
"behavior",
9+
"user",
10+
"creator",
11+
"modifier"
12+
],
13+
"homepage": "https://github.com/loadsys/CakePHP-CreatorModifier",
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Justin Yost",
18+
"email": "[email protected]",
19+
"homepage": "https://www.yostivanich.com/",
20+
"role": "Author"
21+
}
22+
],
23+
"support": {
24+
"issues": "https://github.com/loadsys/CakePHP-CreatorModifier/issues",
25+
"source": "https://github.com/loadsys/CakePHP-CreatorModifier"
26+
},
27+
"require": {
28+
"php": ">=5.4.16",
29+
"cakephp/cakephp": "~3.0"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "~4.1",
33+
"loadsys/loadsys_codesniffer": "~3.0"
34+
},
35+
"autoload": {
36+
"psr-4": {
37+
"CreatorModifier\\": "src"
38+
}
39+
},
40+
"autoload-dev": {
41+
"psr-4": {
42+
"CreatorModifier\\Test\\": "tests",
43+
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
44+
}
45+
}
46+
}

config/routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
use Cake\Routing\Router;
3+
4+
Router::plugin('CreatorModifier', function ($routes) {
5+
$routes->fallbacks('InflectedRoute');
6+
});

phpunit.xml.dist

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
colors="true"
4+
processIsolation="false"
5+
stopOnFailure="false"
6+
syntaxCheck="false"
7+
bootstrap="./tests/bootstrap.php"
8+
>
9+
<php>
10+
<ini name="memory_limit" value="-1"/>
11+
<ini name="apc.enable_cli" value="1"/>
12+
</php>
13+
14+
<!-- Add any additional test suites you want to run here -->
15+
<testsuites>
16+
<testsuite name="CreatorModifier Test Suite">
17+
<directory>./tests/TestCase</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<!-- Setup a listener for fixtures -->
22+
<listeners>
23+
<listener
24+
class="\Cake\TestSuite\Fixture\FixtureInjector"
25+
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
26+
<arguments>
27+
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
28+
</arguments>
29+
</listener>
30+
</listeners>
31+
32+
<!-- Prevent coverage reports from looking in tests and vendors -->
33+
<filter>
34+
<blacklist>
35+
<directory suffix=".php">./vendor/</directory>
36+
<directory suffix=".ctp">./vendor/</directory>
37+
38+
<directory suffix=".php">./tests/</directory>
39+
<directory suffix=".ctp">./tests/</directory>
40+
</blacklist>
41+
</filter>
42+
43+
</phpunit>

src/Controller/AppController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace CreatorModifier\Controller;
4+
5+
use App\Controller\AppController as BaseController;
6+
7+
class AppController extends BaseController {
8+
}

0 commit comments

Comments
 (0)