forked from tomasnorre/crawler
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add CrawlStrategyFactory to move logic from QueueExecutor
- Loading branch information
1 parent
c01e5db
commit c9d0889
Showing
6 changed files
with
117 additions
and
57 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
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\CrawlStrategy; | ||
|
||
use AOE\Crawler\Configuration\ExtensionConfigurationProvider; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
final class CrawlStrategyFactory | ||
{ | ||
/** | ||
* @var ExtensionConfigurationProvider | ||
*/ | ||
private $configurationProvider; | ||
|
||
public function __construct(?ExtensionConfigurationProvider $configurationProvider = null) | ||
{ | ||
$this->configurationProvider = $configurationProvider ?? GeneralUtility::makeInstance(ExtensionConfigurationProvider::class); | ||
} | ||
|
||
public function create(): CrawlStrategy | ||
{ | ||
$settings = $this->configurationProvider->getExtensionConfiguration(); | ||
$extensionSettings = is_array($settings) ? $settings : []; | ||
|
||
if ($extensionSettings['makeDirectRequests']) { | ||
/** @var CrawlStrategy $instance */ | ||
$instance = GeneralUtility::makeInstance(SubProcessExecutionStrategy::class); | ||
} else { | ||
$instance = GeneralUtility::makeInstance(GuzzleExecutionStrategy::class); | ||
} | ||
|
||
return $instance; | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Tests\Unit\CrawlStrategy; | ||
|
||
/* | ||
* (c) 2020 AOE GmbH <dev@aoe.com> | ||
* | ||
* This file is part of the TYPO3 Crawler Extension. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use AOE\Crawler\CrawlStrategy\CrawlStrategyFactory; | ||
use AOE\Crawler\CrawlStrategy\GuzzleExecutionStrategy; | ||
use AOE\Crawler\CrawlStrategy\SubProcessExecutionStrategy; | ||
use Nimut\TestingFramework\TestCase\UnitTestCase; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class CrawlStrategyFactoryTest extends UnitTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function crawlerStrategyFactoryReturnsGuzzleExecutionStrategy(): void | ||
{ | ||
$configuration = [ | ||
'makeDirectRequests' => 0, | ||
'frontendBasePath' => '/', | ||
]; | ||
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crawler'] = $configuration; | ||
$crawlStrategy = GeneralUtility::makeInstance(CrawlStrategyFactory::class)->create(); | ||
|
||
self::assertInstanceOf( | ||
GuzzleExecutionStrategy::class, | ||
$crawlStrategy | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function crawlerStrategyFactoryReturnsSubProcessExecutionStrategy(): void | ||
{ | ||
$configuration = [ | ||
'makeDirectRequests' => 1, | ||
'frontendBasePath' => '/', | ||
]; | ||
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crawler'] = $configuration; | ||
$crawlStrategy = GeneralUtility::makeInstance(CrawlStrategyFactory::class)->create(); | ||
|
||
self::assertInstanceOf( | ||
SubProcessExecutionStrategy::class, | ||
$crawlStrategy | ||
); | ||
} | ||
} |
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