-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factory.php
48 lines (41 loc) · 1.23 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Conradoojr\ThiefLinks;
use Conradoojr\ThiefLinks\Url;
/**
* class SimpleFactory.
*/
class Factory
{
/**
* @var array
*/
protected $availableSiteList;
protected $url;
public function __construct()
{
$this->availableSiteList =[
'http://www.seriesonlinehd.org' => __NAMESPACE__.'\Crawler\SeriesOnlineHd',
];
}
public function search($term)
{
$result = [];
foreach ($this->availableSiteList as $key => $site) {
$availableClass = $this->availableSiteList[$key];
$availableObject = new $availableClass($key);
$lowerAvailableClassName = strtolower($availableObject->getClassName());
$result[$lowerAvailableClassName] =$availableObject->search($term);
}
return $result;
}
public function createCrawler($url)
{
$this->url = new Url();
$this->url->fill($url);
if (!array_key_exists($this->url->domain, $this->availableSiteList)) {
throw new \InvalidArgumentException($this->url->domain . ' is not available');
}
$className = $this->availableSiteList[$this->url->domain];
return new $className($this->url->full);
}
}