-
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.
- Loading branch information
Showing
6 changed files
with
189 additions
and
3 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
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,62 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Di\Scanner; | ||
|
||
|
||
use Eccube\Annotation\QueryExtension; | ||
use Eccube\Di\ComponentDefinition; | ||
|
||
class QueryExtensionScanner extends ComponentScanner | ||
{ | ||
/** | ||
* QueryExtensionScanner constructor. | ||
* @param array|string[] $scanDirs | ||
*/ | ||
public function __construct($scanDirs) | ||
{ | ||
parent::__construct($scanDirs); | ||
} | ||
|
||
public function getAnnotationClass() | ||
{ | ||
return QueryExtension::class; | ||
} | ||
|
||
public function createComponentDefinition($anno, $refClass) | ||
{ | ||
return new ComponentDefinition($refClass->getName(), $refClass); | ||
} | ||
|
||
public function generateExtend(\Twig_Environment $twig, array $components) | ||
{ | ||
return $twig->createTemplate( | ||
'$app->extend("eccube.queries", function ($queries, $app) { | ||
{% for extension in extensions -%} | ||
$queries->addCustomizer($app["{{ extension.id }}"]); | ||
{% endfor %} | ||
return $queries; | ||
});')->render(['extensions' => $components]); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
tests/Eccube/Tests/Di/Scanner/QueryExtensionScannerTest.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,63 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Tests\Di\Scanner; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use Eccube\Di\Scanner\QueryExtensionScanner; | ||
use Eccube\Doctrine\Query\Queries; | ||
use Eccube\Repository\QueryKey; | ||
use Eccube\Tests\Di\Test\QueryCustomizerClass; | ||
|
||
class QueryExtensionScannerTest extends AbstractScannerTest | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->container['eccube.queries'] = function() { | ||
return new Queries(); | ||
}; | ||
} | ||
|
||
protected function getAutoWiring() | ||
{ | ||
return new QueryExtensionScanner([__DIR__.'/../Test']); | ||
} | ||
|
||
public function testQueryExtension() | ||
{ | ||
$this->di->build($this->container); | ||
|
||
self::assertArrayHasKey(QueryCustomizerClass::class, $this->container); | ||
} | ||
|
||
public function testCustomize() | ||
{ | ||
$this->di->build($this->container); | ||
|
||
$qb = $this->createMock(QueryBuilder::class); | ||
$this->container['eccube.queries']->customize(QueryKey::PRODUCT_SEARCH, $qb, []); | ||
|
||
self::assertTrue($this->container[QueryCustomizerClass::class]->customized); | ||
} | ||
} |
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
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,51 @@ | ||
<?php | ||
/* | ||
* This file is part of EC-CUBE | ||
* | ||
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved. | ||
* | ||
* http://www.lockon.co.jp/ | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
namespace Eccube\Tests\Di\Test; | ||
|
||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use Eccube\Annotation\QueryExtension; | ||
use Eccube\Doctrine\Query\QueryCustomizer; | ||
use Eccube\Repository\QueryKey; | ||
|
||
/** | ||
* @QueryExtension(QueryKey::PRODUCT_SEARCH) | ||
*/ | ||
class QueryCustomizerClass implements QueryCustomizer | ||
{ | ||
|
||
public $customized = false; | ||
|
||
/** | ||
* クエリをカスタマイズします。 | ||
* | ||
* @param QueryBuilder $builder | ||
* @param array $params | ||
* @param string $queryKey | ||
*/ | ||
public function customize(QueryBuilder $builder, $params, $queryKey) | ||
{ | ||
$this->customized = true; | ||
} | ||
} |