Skip to content

Commit

Permalink
Merge pull request #1 from loadsys/f/initial-version
Browse files Browse the repository at this point in the history
f/initial-version
  • Loading branch information
beporter committed Jul 22, 2015
2 parents ab3049e + 42facde commit aab7e9f
Show file tree
Hide file tree
Showing 13 changed files with 893 additions and 32 deletions.
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
CakePHP 3

/vendor/*
/config/app.php
/tmp/*
/logs/*

CakePHP 2

/app/tmp/*
/app/Config/core.php
/app/Config/database.php
/vendors/*
# Ignore the composer lock file-- it should never be included in a distributed package.
/composer.lock
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
language: php

sudo: false

php:
- 5.6

# Cache the composer directories
cache:
directories:
- $HOME/.composer/cache

# Environment Variables to set
env:
global:
- APP_ENV=travis
# Contains a $GITHUB_TOKEN env var for use with composer to avoid API limits.
- secure: "WeyyqsgrzPQwi6/de/njgDhfrzKoqPPuUlpIvFg2v+blo42FbrdvTqmZyPRvNwc9to7ZMOC6ZTXXumU+KZuY3c4xUQXR8mO6T0wrqcTVhs7HRmIeqq4HWe3+O7dUIXibXv30TRYMuM9hwKPM9uRO6Xpj4v1WosylGUUpCcms6Qn4FwwjfK9VtfsOo6+jyG8rBc5fcMsdQ3IlBzw6wuDwVHRgOXKNCbBcaqD/KgE440qyQ20l0MKuKXu78Z0GQiF0GdIcqnEUOm802uYD0YY0x68xREk4NG8S4KV2hz8Glqex03jVUPV3sO+w60nFzmvcu6WeUuTvWaxc1g9k2b+2cNLJiIO/MDAkSghFtn8jY0pr/c9GNDzpXSXzD1ywu3npnZLcVshLZ/ZvLsUddNoyx4Rw61DJpu/NHHhXL3KUnlWQ6uFRe0IDoNNG3f9F94rt1r3sRMsSDoO7zNUrZhaW8cmhl31O3BqOWPxDoK1ARokfN9ox13EGtQb45ZFVCfRHTI1OpDpdWabrjcPQC7n7r5DpAq6Lupc9ufFYV9t0q8Gob4oQ2J/NwCFZozBMtbUMOAv7SjAc4wHWABUPQDEJN6OaM0ROzza+eXUreNXwlAlBtmPZ3TtglhPFxlFGyiMPs7UL7i1unTHHl556pRm1AmXqmFoCJn/aEI1N3YgT68s="

# Services to Enable
services:

# Branches to be built or not
branches:
# Blacklist these branches
except:
- staging
- gh-pages

before_install:
- composer self-update

install:
- composer config -g github-oauth.github.com $GITHUB_TOKEN
- composer install --no-interaction

before_script:
- phpenv rehash
- vendor/bin/phpcs --config-set installed_paths vendor/loadsys/loadsys_codesniffer,vendor/cakephp/cakephp-codesniffer

script:
- vendor/bin/phpcs -p --extensions=php --standard=Loadsys ./src ./tests ./config
- vendor/bin/phpunit

notifications:
email: false
22 changes: 0 additions & 22 deletions LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2015 Loadsys Web Strategies

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
# CakePHP-CreatorModifier
A Cake 3 plugin that provides a Behavior to automatically set creator_id and modifier_id fields on save.
# CakePHP 3 CreatorModifier plugin

[![Latest Version](https://img.shields.io/github/release/loadsys/CakePHP-CreatorModifier.svg?style=flat-square)](https://github.com/loadsys/CakePHP-CreatorModifier/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://travis-ci.org/loadsys/CakePHP-CreatorModifier.svg?branch=master&style=flat-square)](https://travis-ci.org/loadsys/CakePHP-SocialLinks)
[![Coverage Status](https://coveralls.io/repos/loadsys/CakePHP-CreatorModifier/badge.svg)](https://coveralls.io/r/loadsys/CakePHP-CreatorModifier)
[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/cakephp-creatormodifier.svg?style=flat-square)](https://packagist.org/packages/loadsys/cakephp-creatormodifier)

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).


## Requirements

* PHP 5.4.16+
* CakePHP 3.0+


## Installation

### Composer

````bash
$ composer require loadsys/loadsys/cakephp-creatormodifier:~1.0
````


## Usage

* Add this plugin for use in an Table, by adding this line to your Table's `initialize()` method.

````php
$this->addBehavior('CreatorModifier.CreatorModifier');
````

* Or to customize the behavior

````php
$this->addBehavior('CreatorModifier.CreatorModifier', [
'events' => [
'Model.beforeSave' => [
// Field storing the User.id who created the record,
// only triggers on beforeSave when the Entity is new.
'user_who_created_me_id' => 'new',

// Field storing the User.id who modified the record,
// always triggers on beforeSave.
'user_who_modified_me_id' => 'always'
]
],
// The key to read from `\Cake\Network\Request->session()->read();`
// to obtain the User.id value to set during saves.
'sessionUserIdKey' => 'Auth.User.id',
]);
````


## Contributing

### Reporting Issues

Please use [GitHub Isuses](https://github.com/loadsys/CakePHP-CreatorModifier/issues) for listing any known defects or issues.

### Development

When developing this plugin, please fork and issue a PR for any new development.


## License

[MIT](https://github.com/loadsys/CakePHP-CreatorModifier/blob/master/LICENSE.md)


## Copyright

[Loadsys Web Strategies](http://www.loadsys.com) 2015
46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "loadsys/cakephp-creatormodifier",
"description": "CakePHP 3.x Plugin to set Creator and Modifier automagic fields during save.",
"type": "cakephp-plugin",
"keywords": [
"cakephp",
"plugin",
"behavior",
"user",
"creator",
"modifier"
],
"homepage": "https://github.com/loadsys/CakePHP-CreatorModifier",
"license": "MIT",
"authors": [
{
"name": "Justin Yost",
"email": "[email protected]",
"homepage": "https://www.yostivanich.com/",
"role": "Author"
}
],
"support": {
"issues": "https://github.com/loadsys/CakePHP-CreatorModifier/issues",
"source": "https://github.com/loadsys/CakePHP-CreatorModifier"
},
"require": {
"php": ">=5.4.16",
"cakephp/cakephp": "~3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1",
"loadsys/loadsys_codesniffer": "~3.0"
},
"autoload": {
"psr-4": {
"CreatorModifier\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"CreatorModifier\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
}
}
}
6 changes: 6 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
use Cake\Routing\Router;

Router::plugin('CreatorModifier', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
43 changes: 43 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="CreatorModifier Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>

<!-- Prevent coverage reports from looking in tests and vendors -->
<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
<directory suffix=".ctp">./vendor/</directory>

<directory suffix=".php">./tests/</directory>
<directory suffix=".ctp">./tests/</directory>
</blacklist>
</filter>

</phpunit>
8 changes: 8 additions & 0 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CreatorModifier\Controller;

use App\Controller\AppController as BaseController;

class AppController extends BaseController {
}
Loading

0 comments on commit aab7e9f

Please sign in to comment.