-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
30 changed files
with
1,491 additions
and
169 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 SMW\Importer; | ||
|
||
use Onoi\MessageReporter\MessageReporterAware; | ||
|
||
/** | ||
* @license GNU GPL v2+ | ||
* @since 3.0 | ||
* | ||
* @author mwjames | ||
*/ | ||
interface ContentCreator extends MessageReporterAware { | ||
|
||
/** | ||
* @since 3.0 | ||
* | ||
* @param ImportContents $importContents | ||
* | ||
* @return boolean | ||
*/ | ||
public function canCreateContentsFor( ImportContents $importContents ); | ||
|
||
/** | ||
* @since 3.0 | ||
* | ||
* @param ImportContents $importContents | ||
*/ | ||
public function doCreateFrom( ImportContents $importContents ); | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
src/Importer/ContentCreators/DispatchingContentCreator.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,82 @@ | ||
<?php | ||
|
||
namespace SMW\Importer\ContentCreators; | ||
|
||
use Onoi\MessageReporter\MessageReporter; | ||
use SMW\Importer\ImportContents; | ||
use SMW\Importer\ContentCreator; | ||
use RuntimeException; | ||
|
||
/** | ||
* @license GNU GPL v2+ | ||
* @since 3.0 | ||
* | ||
* @author mwjames | ||
*/ | ||
class DispatchingContentCreator implements ContentCreator { | ||
|
||
/** | ||
* @var MessageReporter | ||
*/ | ||
private $messageReporter; | ||
|
||
/** | ||
* @var ContentCreator[] | ||
*/ | ||
private $contentCreators = array(); | ||
|
||
/** | ||
* @since 3.0 | ||
* | ||
* @param ContentCreator[] | ||
*/ | ||
public function __construct( array $contentCreators ) { | ||
$this->contentCreators = $contentCreators; | ||
} | ||
|
||
/** | ||
* @see MessageReporterAware::setMessageReporter | ||
* | ||
* @since 3.0 | ||
* | ||
* @param MessageReporter $messageReporter | ||
*/ | ||
public function setMessageReporter( MessageReporter $messageReporter ) { | ||
$this->messageReporter = $messageReporter; | ||
} | ||
|
||
/** | ||
* @since 3.0 | ||
* | ||
* @param ImportContents $importContents | ||
*/ | ||
public function canCreateContentsFor( ImportContents $importContents ) { | ||
|
||
foreach ( $this->contentCreators as $contentCreator ) { | ||
if ( $contentCreator->canCreateContentsFor( $importContents ) ) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @since 3.0 | ||
* | ||
* @param ImportContents $importContents | ||
* @throws RuntimeException | ||
*/ | ||
public function doCreateFrom( ImportContents $importContents ) { | ||
|
||
foreach ( $this->contentCreators as $contentCreator ) { | ||
if ( $contentCreator->canCreateContentsFor( $importContents ) ) { | ||
$contentCreator->setMessageReporter( $this->messageReporter ); | ||
return $contentCreator->doCreateFrom( $importContents ); | ||
} | ||
} | ||
|
||
throw new RuntimeException( "No dispatchable ContentsCreator is assigned to type " . $importContents->getContentType() ); | ||
} | ||
|
||
} |
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
Oops, something went wrong.