1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace smtech\StMarksSearch\WordPress; |
4
|
|
|
|
5
|
|
|
use smtech\StMarksSearch\AbstractSearchDomain; |
6
|
|
|
use smtech\StMarksSearch\AbstractSearchDomainFactory; |
7
|
|
|
use smtech\StMarksSearch\WordPress\Pages\PagesSearch; |
8
|
|
|
use smtech\StMarksSearch\WordPress\Posts\PostsSearch; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A parent object for WordPress search domains |
12
|
|
|
* |
13
|
|
|
* @author Seth Battis <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class WordPressSearchDomainFactory extends AbstractSearchDomainFactory |
16
|
|
|
{ |
17
|
|
|
const POSTS = 'posts'; |
18
|
|
|
const PAGES = 'pages'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Construct a WordPress search domain: `$params` must contain a `url` |
22
|
|
|
* field with a valid URL to a WordPress blog |
23
|
|
|
* |
24
|
|
|
* @param mixed[string] $params |
|
|
|
|
25
|
|
|
* @return AbstractSearchDomain[] |
26
|
|
|
*/ |
27
|
|
|
public static function constructSearchDomains($params) |
28
|
|
|
{ |
29
|
|
|
$domains = []; |
30
|
|
|
|
31
|
|
|
$consumedParams = [self::POSTS, self::PAGES]; |
32
|
|
|
|
33
|
|
|
/* |
34
|
|
|
* FIXME this is really meant to be "if they didn't specify something, |
35
|
|
|
* assume they meant posts" -- not sure that this the best way of |
36
|
|
|
* saying that, though |
37
|
|
|
*/ |
38
|
|
|
if (!isset($params['posts']) && !isset($params[self::PAGES])) { |
39
|
|
|
$params[self::PAGES] = true; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$params[self::POSTS] = static::forceBooleanParameter($params, self::POSTS); |
43
|
|
|
$params[self::PAGES] = static::forceBooleanParameter($params, self::PAGES); |
44
|
|
|
|
45
|
|
|
if ($params[self::POSTS]) { |
46
|
|
|
$domains[] = new PostsSearch(static::consumeParameters($params, $consumedParams)); |
47
|
|
|
} |
48
|
|
|
if ($params[self::PAGES]) { |
49
|
|
|
$domains[] = new PagesSearch(static::consumeParameters($params, $consumedParams)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $domains; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.