author | ymh <ymh.work@gmail.com> |
Mon, 19 Mar 2018 16:04:43 +0100 | |
changeset 571 | 6f852d0f7760 |
parent 396 | c8f651e7e4ff |
permissions | -rw-r--r-- |
163 | 1 |
<?php |
2 |
namespace CorpusParole\Services; |
|
3 |
||
4 |
use CorpusParole\Models\Document; |
|
5 |
||
6 |
use GuzzleHttp\Client; |
|
7 |
||
8 |
class TranscriptManager implements TranscriptManagerInterface { |
|
9 |
||
10 |
public function __construct(Client $client) { |
|
11 |
$this->client = $client; |
|
12 |
} |
|
13 |
||
14 |
||
396
c8f651e7e4ff
correct proble on transcript manager
ymh <ymh.work@gmail.com>
parents:
163
diff
changeset
|
15 |
public function getConverterUrl($converterKey, Document $document, $url) { |
163 | 16 |
|
17 |
$response = $this->client->get($url); |
|
18 |
$statusCode = $response->getStatusCode(); |
|
19 |
if($statusCode < 200 || $statusCode > 299 ) { |
|
20 |
throw new TranscriptManagerException("Can not get transcript content : $statusCode -> ".$response->getReasonPhrase()); |
|
21 |
} |
|
22 |
||
23 |
return $this->getConverter($converterKey, $document, $response->getBody()); |
|
24 |
||
25 |
} |
|
26 |
||
396
c8f651e7e4ff
correct proble on transcript manager
ymh <ymh.work@gmail.com>
parents:
163
diff
changeset
|
27 |
public function getConverter($converterKey, Document $document, $source) { |
163 | 28 |
|
29 |
$converterClassMapping = config('corpusparole.transcrit_decoder_mapping'); |
|
30 |
if(!array_key_exists($converterKey, $converterClassMapping)) { |
|
31 |
throw new TranscriptManagerException("Transcript type $converterKey doe not exists"); |
|
32 |
} |
|
33 |
$converterClass = $converterClassMapping[$converterKey]; |
|
34 |
if(empty($converterClass)) { |
|
35 |
throw new TranscriptManagerException("Transcript type $converterKey doe not exists (empty class)"); |
|
36 |
} |
|
37 |
||
38 |
return new $converterClass($document, $source); |
|
39 |
||
40 |
} |
|
41 |
} |