Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Adapter.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class Adapter
16 {
29  public static function factory($type, $directory, $source, $options = null)
30  {
31  if (!is_string($type) || !$type) {
32  throw new \Magento\Framework\Exception\LocalizedException(
33  __('The adapter type must be a non-empty string.')
34  );
35  }
36  $adapterClass = 'Magento\ImportExport\Model\Import\Source\\' . ucfirst(strtolower($type));
37 
38  if (!class_exists($adapterClass)) {
39  throw new \Magento\Framework\Exception\LocalizedException(
40  __('\'%1\' file extension is not supported', $type)
41  );
42  }
43  $adapter = new $adapterClass($source, $directory, $options);
44 
45  if (!$adapter instanceof AbstractSource) {
46  throw new \Magento\Framework\Exception\LocalizedException(
47  __('Adapter must be an instance of \Magento\ImportExport\Model\Import\AbstractSource')
48  );
49  }
50  return $adapter;
51  }
52 
62  public static function findAdapterFor($source, $directory, $options = null)
63  {
64  return self::factory(pathinfo($source, PATHINFO_EXTENSION), $directory, $source, $options);
65  }
66 }
static findAdapterFor($source, $directory, $options=null)
Definition: Adapter.php:62
$source
Definition: source.php:23
__()
Definition: __.php:13
$adapter
Definition: webapi_user.php:16
$type
Definition: item.phtml:13
static factory($type, $directory, $source, $options=null)
Definition: Adapter.php:29