Skip to content

Commit

Permalink
Merge pull request #3 from elstc/develop
Browse files Browse the repository at this point in the history
Drop CakePHP <=3.3 support
  • Loading branch information
nojimage authored Jan 24, 2019
2 parents 5e63432 + 927414b commit e431365
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 121 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ matrix:
fast_finish: true

include:
- php: 5.6
env: DEFAULT=1 CAKE_VERSION='3.1.*' DB=mysql db_dsn='mysql://[email protected]/cakephp_test'

- php: 5.6
env: DEFAULT=1 CAKE_VERSION='3.2.*' DB=mysql db_dsn='mysql://[email protected]/cakephp_test'

- php: 5.6
env: DEFAULT=1 CAKE_VERSION='3.3.*' DB=mysql db_dsn='mysql://[email protected]/cakephp_test'

- php: 7.2
env: PHPCS=1 DEFAULT=0

Expand Down
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# ActivityLogger plugin for CakePHP 3.x

<p align="center">
<a href="LICENSE.txt" target="_blank">
<img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square">
</a>
<a href="https://travis-ci.org/elstc/cakephp-activity-logger" target="_blank">
<img alt="Build Status" src="https://img.shields.io/travis/elstc/cakephp-activity-logger/master.svg?style=flat-square">
</a>
<a href="https://codecov.io/gh/elstc/cakephp-activity-logger" target="_blank">
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/elstc/cakephp-activity-logger.svg?style=flat-square">
</a>
<a href="https://packagist.org/packages/elstc/cakephp-activity-logger" target="_blank">
<img alt="Latest Stable Version" src="https://img.shields.io/packagist/v/elstc/cakephp-activity-logger.svg?style=flat-square">
</a>
</p>

## Installation

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
Expand All @@ -10,13 +25,18 @@ The recommended way to install composer packages is:
composer require elstc/cakephp-activity-logger
```

### Load plugin bootstrap
### Load plugin

in `config/bootstrap.php`
(CakePHP >= 3.6.0) Load the plugin by adding the following statement in your project's `src/Application.php`:

```(php)
use Cake\Core\Plugin;
Plugin::load('Elastic/ActivityLogger', ['bootstrap' => true]);
```
$this->addPlugin('Elastic/ActivityLogger');
```

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

```
Plugin::load('Elastic/ActivityLogger');
```

### Create activity_logs table
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"type": "cakephp-plugin",
"license": ["MIT"],
"require": {
"php": ">=5.4.16",
"cakephp/cakephp": "~3.1",
"php": ">=5.6",
"ext-pdo": "*",
"ext-json": "*",
"cakephp/cakephp": "^3.4",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.7|^6.0"
"phpunit/phpunit": "^5.7|^6.0"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 13 additions & 9 deletions src/Controller/Component/AutoIssuerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Component\AuthComponent;
use Cake\Event\Event;
use Cake\Event\EventListenerInterface;
use Cake\Event\EventManager;
use Cake\ORM\Entity;
use Cake\ORM\Locator\LocatorInterface;
Expand All @@ -17,7 +16,7 @@
/**
* AutoIssuer component
*/
class AutoIssuerComponent extends Component implements EventListenerInterface
class AutoIssuerComponent extends Component
{
/**
* Default configuration.
Expand Down Expand Up @@ -57,8 +56,13 @@ public function __construct(ComponentRegistry $registry, array $config = [])
{
parent::__construct($registry, $config);

$this->tableLocator = TableRegistry::locator();
$this->setInitializedTables($this->config('initializedTables'));
if (method_exists(TableRegistry::class, 'getTableLocator')) {
$this->tableLocator = TableRegistry::getTableLocator();
} else {
$this->tableLocator = TableRegistry::locator();
}

$this->setInitializedTables($this->getConfig('initializedTables'));
}

/**
Expand Down Expand Up @@ -137,10 +141,10 @@ public function onAfterIdentify(Event $event)
*/
public function onInitializeModel(Event $event)
{
$table = $event->subject();
$table = $event->getSubject();
/* @var $table Table */
if (!array_key_exists($table->registryAlias(), $this->tables)) {
$this->tables[$table->registryAlias()] = $table;
if (!array_key_exists($table->getRegistryAlias(), $this->tables)) {
$this->tables[$table->getRegistryAlias()] = $table;
}

// ログインユーザーが取得できていればセットする
Expand Down Expand Up @@ -188,7 +192,7 @@ private function setIssuerToAllModel(Entity $issuer)
private function getIssuerFromUserArray($user)
{
$table = $this->getUserModel();
$userId = Hash::get((array)$user, $table->primaryKey());
$userId = Hash::get((array)$user, $table->getPrimaryKey());
if ($userId) {
return $table->get($userId);
}
Expand All @@ -203,6 +207,6 @@ private function getIssuerFromUserArray($user)
*/
private function getUserModel()
{
return TableRegistry::get($this->config('userModel'));
return TableRegistry::get($this->getConfig('userModel'));
}
}
Loading

0 comments on commit e431365

Please sign in to comment.