server/src/app/Models/WebResourceManager.php
author ymh <ymh.work@gmail.com>
Thu, 02 Jun 2016 18:24:19 +0200
changeset 168 17f10b56c079
permissions -rw-r--r--
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Models;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use EasyRdf\Resource;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
/**
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
class WebResourceManager {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    public static function getResource(...$args) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        list($url,$graph) = $args;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        $webResource = new Resource($url, $graph);
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        $formatLit = $webResource->getLiteral("dc11:format");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
        $format = is_null($formatLit)?null:$formatLit->getValue();
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        if(is_null($format)) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
            throw new ModelsException("WebResourceManager: No dc:11 format on web resource");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        if(0 === strpos($format, 'audio/') ||
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
           0 === strpos($format, 'video/') ||
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
           0 === strpos($format, 'Sampling:') ) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
            return new MediaResource(...$args);
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        } else if(
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
            0 === strpos($format, 'application/xml') ||
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
            0 === strpos($format, 'application/pdf') ) {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
            return new TranscriptResource(...$args);
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        else {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
            throw new ModelsException("WebResourceManager: unknown format");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
}