Files
Phraseanet/lib/Alchemy/Phrasea/Plugin/Importer/Importer.php
2014-01-06 15:28:12 +01:00

45 lines
1010 B
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Plugin\Importer;
use Alchemy\Phrasea\Plugin\Exception\ImportFailureException;
class Importer
{
private $importers;
private $strategy;
public function __construct(ImportStrategy $strategy, $importers)
{
$this->importers = $importers;
$this->strategy = $strategy;
}
/**
*
* @param string $source
* @param string $target
*
* @throws ImportFailureException
*/
public function import($source, $target)
{
$strategy = $this->strategy->detect($source);
if (!isset($this->importers[$strategy])) {
throw new ImportFailureException(sprintf('Unable to get an import for source `%s`', $source));
}
$this->importers[$strategy]->import($source, $target);
}
}