1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 
<?php
namespace Omeka\DataType;

use Omeka\Entity\Value;
use Omeka\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\ServiceNotFoundException;

class Manager extends AbstractPluginManager
{
    protected $autoAddInvokableClass = false;

    protected $instanceOf = DataTypeInterface::class;

    public function getForExtract(Value $value)
    {
        $dataType = $value->getType();
        $dataTypeFallback = 'literal';
        if (is_string($value->getUri())) {
            $dataTypeFallback = 'uri';
        } elseif ($value->getValueResource()) {
            $dataTypeFallback = 'resource';
        }
        try {
            $instance = $this->get($dataType);
        } catch (ServiceNotFoundException $e) {
            $instance = $this->get($dataTypeFallback);
        }
        return $instance;
    }
}