server/src/app/Services/TranscriptManager.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2016 23:43:29 +0200
changeset 304 20071981ba2a
parent 163 59c68fc4848e
child 396 c8f651e7e4ff
permissions -rw-r--r--
add location and geonames resolvers and api

<?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);

    }
}