Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Factory.php
Go to the documentation of this file.
1 <?php
9 
11 
12 class Factory
13 {
20 
27 
34  public function __construct(
35  $defaultDriverPrefix = 'Magento\Framework\Profiler\Driver\\',
36  $defaultDriverType = 'standard'
37  ) {
38  $this->_defaultDriverPrefix = $defaultDriverPrefix;
39  $this->_defaultDriverType = $defaultDriverType;
40  }
41 
49  public function create(array $config = null)
50  {
51  $type = isset($config['type']) ? $config['type'] : $this->_defaultDriverType;
52  if (class_exists($type)) {
53  $class = $type;
54  } else {
55  $class = $this->_defaultDriverPrefix . ucfirst($type);
56  if (!class_exists($class)) {
57  throw new \InvalidArgumentException(
58  sprintf("Cannot create profiler driver, class \"%s\" doesn't exist.", $class)
59  );
60  }
61  }
62  $driver = new $class($config);
63  if (!$driver instanceof DriverInterface) {
64  throw new \InvalidArgumentException(
65  sprintf(
66  "Driver class \"%s\" must implement \Magento\Framework\Profiler\DriverInterface.",
67  get_class($driver)
68  )
69  );
70  }
71  return $driver;
72  }
73 }
$config
Definition: fraud_order.php:17
__construct( $defaultDriverPrefix='Magento\Framework\Profiler\Driver\\', $defaultDriverType='standard')
Definition: Factory.php:34
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13