Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
DriverPool Class Reference

Public Member Functions

 __construct ($extraTypes=[])
 
 getDriver ($code)
 

Data Fields

const FILE = 'file'
 
const HTTP = 'http'
 
const HTTPS = 'https'
 
const ZLIB = 'compress.zlib'
 

Protected Attributes

 $types
 

Detailed Description

A pool of stream wrappers

Definition at line 12 of file DriverPool.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $extraTypes = [])

Obtain extra types in constructor

Parameters
array$extraTypes
Exceptions

Definition at line 44 of file DriverPool.php.

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  }
is_subclass_of($obj, $className)
$type
Definition: item.phtml:13
$code
Definition: info.phtml:12

Member Function Documentation

◆ getDriver()

getDriver (   $code)

Gets a driver instance by code

Parameters
string$code
Returns
DriverInterface

Definition at line 70 of file DriverPool.php.

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  }
$_option $_optionId $class
Definition: date.phtml:13
$code
Definition: info.phtml:12

Field Documentation

◆ $types

$types
protected
Initial value:
= [
self::FILE => \Magento\Framework\Filesystem\Driver\File::class,
self::HTTP => \Magento\Framework\Filesystem\Driver\Http::class,
self::HTTPS => \Magento\Framework\Filesystem\Driver\Https::class,
self::ZLIB => \Magento\Framework\Filesystem\Driver\Zlib::class,
]

#- #-

Definition at line 24 of file DriverPool.php.

◆ FILE

const FILE = 'file'

#+ Available driver types

Definition at line 17 of file DriverPool.php.

◆ HTTP

const HTTP = 'http'

Definition at line 18 of file DriverPool.php.

◆ HTTPS

const HTTPS = 'https'

Definition at line 19 of file DriverPool.php.

◆ ZLIB

const ZLIB = 'compress.zlib'

Definition at line 20 of file DriverPool.php.


The documentation for this class was generated from the following file: