QueryHandler::handler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 21
rs 9.3142
1
<?php
2
namespace samsonframework\orm;
3
4
/**
5
 * Class for saving external query handlers
6
 * @author Vitaly Iegorov <[email protected]>
7
 * @version 2.0
8
 * @deprecated
9
 */
10
class QueryHandler
11
{
12
    /** @var callback[] Collection of external query handlers(callbacks) */
13
    private $handlers = array();
14
15
    /** @var array Collection of external query handlers(callbacks) additional parameters */
16
    private $params = array();
17
18
    /**
19
     * Add extenal query handler
20
     * @param callable $callable External handler
21
     * @return self Chaining
22
     * @deprecated Not used
23
     */
24
    public function handler($callable)
25
    {
26
        // If normal handler is passed
27
        if (is_callable($callable)) {
28
            // Add handler
29
            $this->handlers[] = $callable;
30
31
            // Get passed arguments
32
            $args = func_get_args();
33
34
            // Remove first argument
35
            array_shift($args);
36
37
            // Add handler parameters stack
38
            $this->params[] = &$args;
39
        } else {
40
            //e('Cannot set Query handler - function(##) does not exists', E_SAMSON_ACTIVERECORD_ERROR, $callable);
41
        }
42
43
        return $this;
44
    }
45
46
    /** Execute all available external query handlers */
47
    protected function callHandlers()
48
    {
49
        // Iterate handlers and run them
50
        foreach ($this->handlers as $i => $handler) {
51
            // Create handler params array with first parameter pointing to this query object
52
            $params = array(& $this);
53
54
            // Combine params with existing ones in one array
55
            $params = array_merge($params, $this->params[$i]);
56
57
            // Execute handler
58
            call_user_func_array($handler, $params);
59
        }
60
    }
61
}
62