1. Go to this page and download the library: Download rogermaciel/audit-log library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rogermaciel / audit-log example snippets
'Datasources' => [
'auditlog_elastic' => [
'className' => 'Cake\ElasticSearch\Datasource\Connection',
'driver' => 'Cake\ElasticSearch\Datasource\Connection',
'host' => '127.0.0.1', // server where elasticsearch is running
'port' => 9200
],
...
]
'Datasources' => [
'auditlog_elastic' => [
'className' => 'Cake\ElasticSearch\Datasource\Connection',
'driver' => 'Cake\ElasticSearch\Datasource\Connection',
'host' => '127.0.0.1', // server where elasticsearch is running
'port' => 9200
],
...
]
class ArticlesTable extends Table
{
public function initialize(array $config = [] )
{
...
$this->addBehavior('AuditLog.AuditLog');
}
}
class ArticlesTable extends Table
{
public function initialize(array $config = [] )
{
...
$this->addBehavior('AuditLog.AuditLog', [
'blacklist' => ['created', 'modified', 'another_field_name']
]);
}
}
public function initialize(array $config = [] )
{
...
$this->addBehavior('AuditLog.AuditLog', [
'whitelist' => ['title', 'description', 'author_id']
]);
}
use AuditLog\Meta\RequestMetadata;
...
class AppController extends Controller
{
public function beforeFilter(Event $event)
{
...
$eventManager = $this->loadModel()->eventManager();
$eventManager->on(new RequestMetadata($this->request, $this->Auth->user('id')));
}
}
use AuditLog\Meta\RequestMetadata;
use Cake\Event\EventManager;
...
class AppController extends Controller
{
public function beforeFilter(Event $event)
{
...
EventManager::instance()->on(new RequestMetadata($this->request, $this->Auth->user('id')));
}
}
use AuditLog\Meta\ApplicationMetadata;
use Cake\Event\EventManager;
EventManager::instance()->on(new ApplicationMetadata('my_blog_app', [
'server' => $theServerID,
'extra' => $somExtraInformation,
'moon_phase' => $currentMoonPhase
]));
EventManager::instance()->on('AuditLog.beforeLog', function ($event, array $logs) {
foreach ($logs as $event) {
$event->setMetaInfo($event->getMetaInfo() + ['extra' => 'This is extra data to be stored']);
}
});
namespace App\Model\Audit;
use Cake\Utility\Text;
use SplObjectStorage;
class AuditTrail
{
protected $_auditQueue;
protected $_auditTransaction;
public function __construct()
{
$this->_auditQueue = new SplObjectStorage;
$this->_auditTransaction = Text::uuid();
}
public function toSaveOptions()
{
return [
'_auditQueue' => $this->_auditQueue,
'_auditTransaction' => $this->_auditTransaction
];
}
}
use App\Model\Audit\AuditTrail;
use Cake\Event\Event;