本文整理汇总了PHP中Magento_Profiler::getTimers方法的典型用法代码示例。如果您正苦于以下问题:PHP Magento_Profiler::getTimers方法的具体用法?PHP Magento_Profiler::getTimers怎么用?PHP Magento_Profiler::getTimers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento_Profiler
的用法示例。
在下文中一共展示了Magento_Profiler::getTimers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getSortedTimers
/**
* Retrieve timer ids sorted to correspond the nesting
*
* @return array
*/
private function _getSortedTimers()
{
$timerIds = Magento_Profiler::getTimers();
if (count($timerIds) <= 2) {
/* No sorting needed */
return $timerIds;
}
/* Prepare PCRE once to use it inside the loop body */
$nestingSep = preg_quote(Magento_Profiler::NESTING_SEPARATOR, '/');
$patternLastTimerName = '/' . $nestingSep . '(?:.(?!' . $nestingSep . '))+$/';
$prevTimerId = $timerIds[0];
$result = array($prevTimerId);
for ($i = 1; $i < count($timerIds); $i++) {
$timerId = $timerIds[$i];
/* Skip already added timer */
if (!$timerId) {
continue;
}
/* Loop over all timers that need to be closed under previous timer */
while (strpos($timerId, $prevTimerId . Magento_Profiler::NESTING_SEPARATOR) !== 0) {
/* Add to result all timers nested in the previous timer */
for ($j = $i + 1; $j < count($timerIds); $j++) {
if (strpos($timerIds[$j], $prevTimerId . Magento_Profiler::NESTING_SEPARATOR) === 0) {
$result[] = $timerIds[$j];
/* Mark timer as already added */
$timerIds[$j] = null;
}
}
/* Go to upper level timer */
$count = 0;
$prevTimerId = preg_replace($patternLastTimerName, '', $prevTimerId, -1, $count);
/* Break the loop if no replacements was done. It is possible when we are */
/* working with top level (root) item */
if (!$count) {
break;
}
}
/* Add current timer to the result */
$result[] = $timerId;
$prevTimerId = $timerId;
}
return $result;
}
示例2: testGetTimers
public function testGetTimers()
{
$expectedTimers = array('some_root_timer', 'some_root_timer->some_nested_timer', 'some_root_timer->some_nested_timer->some_deeply_nested_timer', 'one_more_root_timer');
$actualTimers = Magento_Profiler::getTimers();
$this->assertEquals($expectedTimers, $actualTimers);
}