Skip to content

Commit

Permalink
Entityイベント拡張のプラグインサンプル
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed May 29, 2017
1 parent e275172 commit c399e14
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/Plugin/EntityEvent/Entity/BaseInfoListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Plugin\EntityEvent\Entity;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Eccube\Annotation\PreUpdate;
use Eccube\Entity\Event\EntityEventListener;

/**
* @PreUpdate("Eccube\Entity\BaseInfo")
*/
class BaseInfoListener implements EntityEventListener
{
public function execute(LifecycleEventArgs $eventArgs)
{
/** @var PreUpdateEventArgs $eventArgs */
$new = $eventArgs->getNewValue('company_name');
$old = $eventArgs->getOldValue('company_name');

error_log($new);
error_log($old);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Plugin\EntityEvent\ServiceProvider;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Plugin\EntityEvent\Entity\BaseInfoListener;
use Silex\Api\BootableProviderInterface;
use Silex\Application;

class EntityEventServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['plugin.entity_event.base_info_listener'] = function (Container $container) {
return new BaseInfoListener();
};
}

public function boot(Application $app)
{
$app['eccube.entity.event.dispatcher']
->addEventListener($app['plugin.entity_event.base_info_listener']);
}
}
5 changes: 5 additions & 0 deletions app/Plugin/EntityEvent/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Entityイベント拡張のサンプル
code: EntityEvent
version: 1.0.0
service:
- EntityEventServiceProvider

0 comments on commit c399e14

Please sign in to comment.