Skip to content

Commit 104c08d

Browse files
committed
new method Extractor::createCustomDetectors to ease the custom detectors configuration #457
1 parent 673cc5b commit 104c08d

File tree

23 files changed

+121
-175
lines changed

23 files changed

+121
-175
lines changed

src/Adapters/Archive/Extractor.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44
namespace Embed\Adapters\Archive;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
1410
private Api $api;
1511

16-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
12+
public function getApi(): Api
1713
{
18-
parent::__construct($uri, $request, $response, $crawler);
19-
20-
$this->api = new Api($this);
21-
22-
$this->title = new Detectors\Title($this);
23-
$this->description = new Detectors\Description($this);
24-
$this->code = new Detectors\Code($this);
25-
$this->authorName = new Detectors\AuthorName($this);
26-
$this->providerName = new Detectors\ProviderName($this);
27-
$this->publishedTime = new Detectors\PublishedTime($this);
14+
return $this->api;
2815
}
2916

30-
public function getApi(): Api
17+
public function createCustomDetectors(): array
3118
{
32-
return $this->api;
19+
$this->api = new Api($this);
20+
21+
return [
22+
'title' => new Detectors\Title($this),
23+
'description' => new Detectors\Description($this),
24+
'code' => new Detectors\Code($this),
25+
'authorName' => new Detectors\AuthorName($this),
26+
'providerName' => new Detectors\ProviderName($this),
27+
'publishedTime' => new Detectors\PublishedTime($this),
28+
];
3329
}
3430
}

src/Adapters/Bandcamp/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\Bandcamp;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->providerName = new Detectors\ProviderName($this);
12+
return [
13+
'providerName' => new Detectors\ProviderName($this),
14+
];
1915
}
2016
}

src/Adapters/CadenaSer/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\CadenaSer;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->code = new Detectors\Code($this);
12+
return [
13+
'code' => new Detectors\Code($this),
14+
];
1915
}
2016
}

src/Adapters/Facebook/Extractor.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
namespace Embed\Adapters\Facebook;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
1812
$this->oembed = new OEmbed($this);
19-
$this->title = new Detectors\Title($this);
13+
14+
return [
15+
'title' => new Detectors\Title($this),
16+
];
2017
}
2118
}

src/Adapters/Flickr/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\Flickr;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->code = new Detectors\Code($this);
12+
return [
13+
'code' => new Detectors\Code($this),
14+
];
1915
}
2016
}

src/Adapters/Gist/Extractor.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@
44
namespace Embed\Adapters\Gist;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
1410
private Api $api;
1511

16-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
12+
public function getApi(): Api
1713
{
18-
parent::__construct($uri, $request, $response, $crawler);
19-
20-
$this->api = new Api($this);
21-
22-
$this->authorName = new Detectors\AuthorName($this);
23-
$this->authorUrl = new Detectors\AuthorUrl($this);
24-
$this->publishedTime = new Detectors\PublishedTime($this);
25-
$this->code = new Detectors\Code($this);
14+
return $this->api;
2615
}
2716

28-
public function getApi(): Api
17+
public function createCustomDetectors(): array
2918
{
30-
return $this->api;
19+
$this->api = new Api($this);
20+
21+
return [
22+
'authorName' => new Detectors\AuthorName($this),
23+
'authorUrl' => new Detectors\AuthorUrl($this),
24+
'publishedTime' => new Detectors\PublishedTime($this),
25+
'code' => new Detectors\Code($this),
26+
];
3127
}
3228
}

src/Adapters/Github/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\Github;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->code = new Detectors\Code($this);
12+
return [
13+
'code' => new Detectors\Code($this),
14+
];
1915
}
2016
}

src/Adapters/Ideone/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\Ideone;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->code = new Detectors\Code($this);
12+
return [
13+
'code' => new Detectors\Code($this),
14+
];
1915
}
2016
}

src/Adapters/ImageShack/Extractor.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@
44
namespace Embed\Adapters\ImageShack;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
1410
private Api $api;
1511

16-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
12+
public function getApi(): Api
1713
{
18-
parent::__construct($uri, $request, $response, $crawler);
19-
20-
$this->api = new Api($this);
21-
22-
$this->authorName = new Detectors\AuthorName($this);
23-
$this->authorUrl = new Detectors\AuthorUrl($this);
24-
$this->description = new Detectors\Description($this);
25-
$this->image = new Detectors\Image($this);
26-
$this->providerName = new Detectors\ProviderName($this);
27-
$this->publishedTime = new Detectors\PublishedTime($this);
28-
$this->title = new Detectors\Title($this);
14+
return $this->api;
2915
}
3016

31-
public function getApi(): Api
17+
public function createCustomDetectors(): array
3218
{
33-
return $this->api;
19+
$this->api = new Api($this);
20+
21+
return [
22+
'authorName' => new Detectors\AuthorName($this),
23+
'authorUrl' => new Detectors\AuthorUrl($this),
24+
'description' => new Detectors\Description($this),
25+
'image' => new Detectors\Image($this),
26+
'providerName' => new Detectors\ProviderName($this),
27+
'publishedTime' => new Detectors\PublishedTime($this),
28+
'title' => new Detectors\Title($this),
29+
];
3430
}
3531
}

src/Adapters/Pinterest/Extractor.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
namespace Embed\Adapters\Pinterest;
55

66
use Embed\Extractor as Base;
7-
use Embed\Http\Crawler;
8-
use Psr\Http\Message\RequestInterface;
9-
use Psr\Http\Message\ResponseInterface;
10-
use Psr\Http\Message\UriInterface;
117

128
class Extractor extends Base
139
{
14-
public function __construct(UriInterface $uri, RequestInterface $request, ResponseInterface $response, Crawler $crawler)
10+
public function createCustomDetectors(): array
1511
{
16-
parent::__construct($uri, $request, $response, $crawler);
17-
18-
$this->code = new Detectors\Code($this);
12+
return [
13+
'code' => new Detectors\Code($this),
14+
];
1915
}
2016
}

0 commit comments

Comments
 (0)