server/src/app/Services/TranscriptManager.php
changeset 163 59c68fc4848e
child 396 c8f651e7e4ff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/app/Services/TranscriptManager.php	Sun May 29 16:50:17 2016 +0200
@@ -0,0 +1,41 @@
+<?php
+namespace CorpusParole\Services;
+
+use CorpusParole\Models\Document;
+
+use GuzzleHttp\Client;
+
+class TranscriptManager implements TranscriptManagerInterface {
+
+    public function __construct(Client $client) {
+        $this->client = $client;
+    }
+
+
+    public function getConverterUrl(string $converterKey, Document $document, string $url) {
+
+        $response = $this->client->get($url);
+        $statusCode = $response->getStatusCode();
+        if($statusCode < 200 || $statusCode > 299 ) {
+            throw new TranscriptManagerException("Can not get transcript content : $statusCode -> ".$response->getReasonPhrase());
+        }
+
+        return $this->getConverter($converterKey, $document, $response->getBody());
+
+    }
+
+    public function getConverter(string $converterKey, Document $document, string $source) {
+
+        $converterClassMapping = config('corpusparole.transcrit_decoder_mapping');
+        if(!array_key_exists($converterKey, $converterClassMapping)) {
+            throw new TranscriptManagerException("Transcript type $converterKey doe not exists");
+        }
+        $converterClass = $converterClassMapping[$converterKey];
+        if(empty($converterClass)) {
+            throw new TranscriptManagerException("Transcript type $converterKey doe not exists (empty class)");
+        }
+
+        return new $converterClass($document, $source);
+
+    }
+}