Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DriverPool.php
Go to the documentation of this file.
1 <?php
8 
13 {
17  const FILE = 'file';
18  const HTTP = 'http';
19  const HTTPS = 'https';
20  const ZLIB = 'compress.zlib';
24  protected $types = [
25  self::FILE => \Magento\Framework\Filesystem\Driver\File::class,
26  self::HTTP => \Magento\Framework\Filesystem\Driver\Http::class,
27  self::HTTPS => \Magento\Framework\Filesystem\Driver\Https::class,
28  self::ZLIB => \Magento\Framework\Filesystem\Driver\Zlib::class,
29  ];
30 
36  private $pool = [];
37 
44  public function __construct($extraTypes = [])
45  {
46  foreach ($extraTypes as $code => $typeOrObject) {
47  if (is_object($typeOrObject)) {
48  $type = get_class($typeOrObject);
49  $object = $typeOrObject;
50  } else {
51  $type = $typeOrObject;
52  $object = false;
53  }
54  if (!is_subclass_of($type, \Magento\Framework\Filesystem\DriverInterface::class)) {
55  throw new \InvalidArgumentException("The specified type '{$type}' does not implement DriverInterface.");
56  }
57  $this->types[$code] = $type;
58  if ($object) {
59  $this->pool[$code] = $typeOrObject;
60  }
61  }
62  }
63 
70  public function getDriver($code)
71  {
72  if (!isset($this->types[$code])) {
73  $code = self::FILE;
74  }
75  if (!isset($this->pool[$code])) {
76  $class = $this->types[$code];
77  $this->pool[$code] = new $class();
78  }
79  return $this->pool[$code];
80  }
81 }
is_subclass_of($obj, $className)
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
$code
Definition: info.phtml:12