Completed
Pull Request — master (#505)
by Richard
10:42
created

XoopsDebugStack::startQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Core\Database\Logging;
13
14
use Doctrine\DBAL\Logging\DebugStack;
15
16
/**
17
 * Extend Doctrine DebugStack to trigger XOOPS event
18
 *
19
 * @category  Xoops\Core\Database\Logging
20
 * @package   Xoops\Core
21
 * @author    Richard Griffith <[email protected]>
22
 * @copyright 2013 XOOPS Project (http://xoops.org)
23
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24
 * @version   Release: 1.0
25
 * @link      http://xoops.org
26
 * @see       www.doctrine-project.org
27
 */
28
class XoopsDebugStack extends DebugStack
29
{
30
    /**
31
     * Logs a SQL statement somewhere.
32
     *
33
     * @param string $sql The SQL to be executed.
34
     * @param array $params The SQL parameters.
35
     * @param array $types The SQL parameter types.
36
     * @return void
37
     */
38 101
    public function startQuery($sql, array $params = null, array $types = null)
39
    {
40 101
        \Xoops::getInstance()->events()->triggerEvent(
41 101
            'core.database.query.begin',
42 101
            [$sql, $params, $types]
43
        );
44 101
        parent::startQuery($sql, $params, $types);
45 101
    }
46
47
    /**
48
     * stopQuery
49
     *
50
     * Perform usual Doctrine DebugStack stopQuery() and trigger event for loggers
51
     *
52
     * Event argument is array:
53
     *   - 'sql'         => string SQL statement
54
     *   - 'params'      => array of bound parameters
55
     *   - 'types'       => array of parameter types
56
     *   - 'executionMS' => float of execution time in microseconds
57
     *
58
     * @return void
59
     */
60 97
    public function stopQuery()
61
    {
62 97
        parent::stopQuery();
63 97
        \Xoops::getInstance()->events()->triggerEvent(
64 97
            'core.database.query.complete',
65 97
            $this->queries[$this->currentQuery]
66
        );
67 97
    }
68
}
69