-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2346 from chihiro-adachi/dev-ext-sample
プラグイン拡張サンプルを追加
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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 | ||
{ | ||
/** | ||
* BaseInfoが更新されたタイミングで、更新前/更新後の値をerror_logで出力するサンプルです. | ||
* | ||
* @param LifecycleEventArgs $eventArgs | ||
*/ | ||
public function execute(LifecycleEventArgs $eventArgs) | ||
{ | ||
/** @var PreUpdateEventArgs $eventArgs */ | ||
if ($eventArgs->hasChangedField('company_name')) { | ||
$new = $eventArgs->getNewValue('company_name'); | ||
$old = $eventArgs->getOldValue('company_name'); | ||
|
||
error_log($new); | ||
error_log($old); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/Plugin/EntityEvent/ServiceProvider/EntityEventServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: Entityイベント拡張のサンプル | ||
code: EntityEvent | ||
version: 1.0.0 | ||
service: | ||
- EntityEventServiceProvider |
30 changes: 30 additions & 0 deletions
30
app/Plugin/QueryCustomize/Entity/AdminCustomerCustomizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Plugin\QueryCustomize\Entity; | ||
|
||
use Eccube\Annotation\QueryExtension; | ||
use Eccube\Doctrine\Query\WhereClause; | ||
use Eccube\Doctrine\Query\WhereCustomizer; | ||
use Eccube\Repository\QueryKey; | ||
|
||
/** | ||
* @QueryExtension(QueryKey::CUSTOMER_SEARCH) | ||
*/ | ||
class AdminCustomerCustomizer extends WhereCustomizer | ||
{ | ||
/** | ||
* 1回以上購入している会員を抽出 | ||
* | ||
* @param array $params | ||
* @param $queryKey | ||
* @return WhereClause[] | ||
*/ | ||
protected function createStatements($params, $queryKey) | ||
{ | ||
// travis-ciのテストが通らないため、コメントアウト | ||
// 試してみるにはコメントアウトを解除してください. | ||
//return [WhereClause::gte('c.buy_times', ':buy_times', ['buy_times' => 1])]; | ||
|
||
return []; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/Plugin/QueryCustomize/ServiceProvider/QueryCustomizeServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Plugin\QueryCustomize\ServiceProvider; | ||
|
||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
use Plugin\QueryCustomize\Entity\AdminCustomerCustomizer; | ||
use Silex\Api\BootableProviderInterface; | ||
use Silex\Application; | ||
|
||
class QueryCustomizeServiceProvider implements ServiceProviderInterface, BootableProviderInterface | ||
{ | ||
public function register(Container $app) | ||
{ | ||
$app['plugin.query_customize.customer_search'] = function (Container $container) { | ||
return new AdminCustomerCustomizer(); | ||
}; | ||
} | ||
|
||
public function boot(Application $app) | ||
{ | ||
$app['eccube.queries'] | ||
->addCustomizer($app['plugin.query_customize.customer_search']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: クエリビルダ拡張のサンプル | ||
code: QueryCustomize | ||
version: 1.0.0 | ||
service: | ||
- QueryCustomizeServiceProvider |