Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Standard.php
Go to the documentation of this file.
1 <?php
9 
14 
15 class Standard implements DriverInterface
16 {
22  protected $_stat;
23 
29  protected $_outputs = [];
30 
36  public function __construct(array $config = null)
37  {
38  $this->_initOutputs($config);
39  $this->_initStat($config);
40  register_shutdown_function([$this, 'display']);
41  }
42 
49  protected function _initOutputs(array $config = null)
50  {
51  if (!$config) {
52  return;
53  }
54 
55  $outputFactory = $this->_getOutputFactory($config);
56  foreach ($this->_getOutputConfigs($config) as $code => $outputConfig) {
57  $outputConfig = $this->_parseOutputConfig($outputConfig);
58  if (false === $outputConfig) {
59  continue;
60  }
61  if (!isset($outputConfig['type']) && !is_numeric($code)) {
62  $outputConfig['type'] = $code;
63  }
64  if (!isset($outputConfig['baseDir']) && isset($config['baseDir'])) {
65  $outputConfig['baseDir'] = $config['baseDir'];
66  }
67  $this->registerOutput($outputFactory->create($outputConfig));
68  }
69  }
70 
77  protected function _parseOutputConfig($outputConfig)
78  {
79  $result = false;
80  if (is_array($outputConfig)) {
81  $result = $outputConfig;
82  } elseif (is_scalar($outputConfig) && $outputConfig) {
83  if (is_numeric($outputConfig)) {
84  $result = [];
85  } else {
86  $result = ['type' => $outputConfig];
87  }
88  }
89  return $result;
90  }
91 
98  protected function _getOutputConfigs(array $config = null)
99  {
100  $result = [];
101  if (isset($config['outputs'])) {
102  $result = $config['outputs'];
103  } elseif (isset($config['output'])) {
104  $result[] = $config['output'];
105  }
106  return $result;
107  }
108 
115  protected function _getOutputFactory(array $config = null)
116  {
117  if (isset($config['outputFactory']) && $config['outputFactory'] instanceof OutputFactory) {
118  $result = $config['outputFactory'];
119  } else {
120  $result = new OutputFactory();
121  }
122  return $result;
123  }
124 
131  protected function _initStat(array $config = null)
132  {
133  if (isset($config['stat']) && $config['stat'] instanceof Stat) {
134  $this->_stat = $config['stat'];
135  } else {
136  $this->_stat = new Stat();
137  }
138  }
139 
146  public function clear($timerId = null)
147  {
148  $this->_stat->clear($timerId);
149  }
150 
159  public function start($timerId, array $tags = null)
160  {
161  $this->_stat->start($timerId, microtime(true), memory_get_usage(true), memory_get_usage());
162  }
163 
170  public function stop($timerId)
171  {
172  $this->_stat->stop($timerId, microtime(true), memory_get_usage(true), memory_get_usage());
173  }
174 
182  {
183  $this->_outputs[] = $output;
184  }
185 
191  public function display()
192  {
193  if (\Magento\Framework\Profiler::isEnabled()) {
194  foreach ($this->_outputs as $output) {
195  $output->display($this->_stat);
196  }
197  }
198  }
199 }
registerOutput(OutputInterface $output)
Definition: Standard.php:181
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
start($timerId, array $tags=null)
Definition: Standard.php:159
$code
Definition: info.phtml:12