-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QueryEngine and StoreAware interface
- Loading branch information
Showing
17 changed files
with
406 additions
and
135 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
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,74 @@ | ||
<?php | ||
|
||
namespace SMW\Query; | ||
|
||
use SMW\Store; | ||
use SMW\QueryEngine; | ||
use SMW\StoreAware; | ||
use RuntimeException; | ||
|
||
/** | ||
* @private | ||
* | ||
* @license GNU GPL v2+ | ||
* @since 2.5 | ||
* | ||
* @author mwjames | ||
*/ | ||
class QuerySourceFactory { | ||
|
||
/** | ||
* @var Store | ||
*/ | ||
private $store; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $querySources = array(); | ||
|
||
/** | ||
* @since 2.5 | ||
* | ||
* @param Store $store | ||
* @param array $querySources | ||
*/ | ||
public function __construct( Store $store, $querySources = array() ) { | ||
$this->store = $store; | ||
$this->querySources = $querySources; | ||
} | ||
|
||
/** | ||
* @see DefaultSettings::$smwgQuerySources | ||
* | ||
* @since 2.5 | ||
* | ||
* @param string|null $source | ||
* | ||
* @return QueryEngine|Store | ||
* @throws RuntimeException | ||
*/ | ||
public function getWithLocalFallback( $source = null ) { | ||
|
||
if ( $source !== '' && isset( $this->querySources[$source] ) ) { | ||
$source = $this->querySources[$source]; | ||
} | ||
|
||
if ( $source !== '' && class_exists( $source ) ) { | ||
$source = new $source; | ||
} else { | ||
$source = $this->store; | ||
} | ||
|
||
if ( !$source instanceof QueryEngine && !$source instanceof Store ) { | ||
throw new RuntimeException( get_class( $source ) . " does not match the expected QueryEngine interface." ); | ||
} | ||
|
||
if ( $source instanceof StoreAware ) { | ||
$source->setStore( $this->store ); | ||
} | ||
|
||
return $source; | ||
} | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace SMW; | ||
|
||
use SMWQuery as Query; | ||
use SMWQueryResult as QueryResult; | ||
|
||
/** | ||
* Interface for query answering that depend on concrete implementations to | ||
* provide the filtering and matching process for specific conditions against a | ||
* select back-end. | ||
* | ||
* @license GNU GPL v2 | ||
* @since 2.5 | ||
* | ||
* @author mwjames | ||
*/ | ||
interface QueryEngine { | ||
|
||
/** | ||
* Returns a QueryResult object that matches the condition described by a | ||
* query. | ||
* | ||
* @note If the request was made for a debug (querymode MODE_DEBUG) query | ||
* then a simple HTML-compatible string is returned. | ||
* | ||
* @since 2.5 | ||
* | ||
* @param Query $query | ||
* | ||
* @return QueryResult|string | ||
*/ | ||
public function getQueryResult( Query $query ); | ||
|
||
} |
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
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,22 @@ | ||
<?php | ||
|
||
namespace SMW; | ||
|
||
/** | ||
* Describes an instance that is aware of a Store object. | ||
* | ||
* @license GNU GPL v2 | ||
* @since 2.5 | ||
* | ||
* @author mwjames | ||
*/ | ||
interface StoreAware { | ||
|
||
/** | ||
* @since 2.5 | ||
* | ||
* @param Store $store | ||
*/ | ||
public function setStore( Store $store ); | ||
|
||
} |
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.