Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Profiler / Profiler.php
blob8a0c6d2b32ecfb9848ed57a518c064f56bbea92f
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Adapter\Profiler;
12 use Zend\Db\Adapter\StatementContainerInterface;
13 use Zend\Db\Adapter\Exception;
15 class Profiler implements ProfilerInterface
17 /**
18 * @var array
20 protected $profiles = array();
22 /**
23 * @var null
25 protected $currentIndex = 0;
27 /**
28 * @param string|StatementContainerInterface $target
29 * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
30 * @return Profiler
32 public function profilerStart($target)
34 $profileInformation = array(
35 'sql' => '',
36 'parameters' => null,
37 'start' => microtime(true),
38 'end' => null,
39 'elapse' => null
41 if ($target instanceof StatementContainerInterface) {
42 $profileInformation['sql'] = $target->getSql();
43 $profileInformation['parameters'] = clone $target->getParameterContainer();
44 } elseif (is_string($target)) {
45 $profileInformation['sql'] = $target;
46 } else {
47 throw new Exception\InvalidArgumentException(__FUNCTION__ . ' takes either a StatementContainer or a string');
50 $this->profiles[$this->currentIndex] = $profileInformation;
52 return $this;
55 /**
56 * @return Profiler
58 public function profilerFinish()
60 if (!isset($this->profiles[$this->currentIndex])) {
61 throw new Exception\RuntimeException('A profile must be started before ' . __FUNCTION__ . ' can be called.');
63 $current = &$this->profiles[$this->currentIndex];
64 $current['end'] = microtime(true);
65 $current['elapse'] = $current['end'] - $current['start'];
66 $this->currentIndex++;
67 return $this;
70 /**
71 * @return array|null
73 public function getLastProfile()
75 return end($this->profiles);
78 /**
79 * @return array
81 public function getProfiles()
83 return $this->profiles;