meyfarth/entity-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

meyfarth/entity-logger

Composer 安装命令:

composer require meyfarth/entity-logger

包简介

Allows to automatically log entities modification

关键字:

README 文档

README

By Sébastien Garcia

This bundle allows you to log every modification made to your entities, just by implementing the EntityLoggerInterface interface.

Installation

Using Composer:

php composer.phar require meyfarth/entity-logger dev-master

Enable the bundle in your kernel :

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Meyfarth\EntityLoggerBundle\MeyfarthEntityLoggerBundle(),
        );
        
        ...
        
        return $bundles;
    }

Update your database :

php app/console doctrine:schema:update --force

This will create a meyfarth_entity_log table. You can dump your database first using --dump-sql option if you want to know the table structure.

Usage

To log an entity, implement the EntityLoggerInterface interface in the entities you want to log :

<?php

namespace MyApp\MyBundle\Entity;

use Meyfarth\EntityLoggerBundle\Entity\EntityLoggerInterface;

/**
 * MyEntity
 */
class MyEntity implements EntityLoggerInterface
{
  // Your code
}

Configuration

# app/config/config.yml
meyfarth_entity_logger:
    enable: true # default false. If not enabled, nothing will be logged
    log:
        create: true  # log on new entities
        update: true  # log on updates, new entities will not be considered as updates
        delete: true  # log on deletion
    user_class: false # log the current user (see below for explainations)
    nb_logs_by_page: 50 # number of logs by page on listing page, default is 50

If you use the security component with your own user entity (managed by Doctrine in your database), you can automatically log the current user by specifying the user_class parameter:

# app/config/config.yml
meyfarth_entity_logger:
    user_class: MyApp\MyBundle\Entity\MyUser

Interfaces

You can now list all the logs. Simply add to your routing :

# app/config.routing.yml
#...
meyfarth_entity_log:
    resource: "@MeyfarthEntityLoggerBundle/Resources/config/routing.yml"
    prefix:   /entity-log

You can now access the log list by going to yourserver/entity-log/list/{page} and see the ugliest table you'll ever see. Note that the {page} token is by default 1.

To override the default template, add your own template named list.html.twig in app/Resouces/MeyfarthEntityLoggerBundle/views/Log/list.html.twig.

The controller pass those parameters to the view :

'logs' # the database result of the current page.
'page' # the current page
'nbByPage' # the number of elements by page
'nbPages' # the total number of pages

To access the EntityLog data in twig :

log.id      {# the EntityLog id #}
log.dateLog {# DateTime of the log #}
log.typeLog {# type of log. Possibles values are defined in EntityLoggerService #}
log.data    {# the data : an array of array #}

Note : to compare the values in log.typeLog, you can use the following class constants :

  • Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_INSERT
  • Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_UPDATE
  • Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_DELETE

The log.data is defined as following :

/* Note that only the fields modified will be in the data. 
It means that if you only modify the "string" field of your entity, only the "string" field 
will be present in the log.data
*/
array(
    '[FIELDNAME]' => array(
        0 => previousData,
        1 => currentData,
    ),
    '[FIELDNAME2]' => array(
        0 => previousData,
        1 => currentData,
    ),
);

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固