QueryHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 52
rs 10
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handler() 0 21 2
A callHandlers() 0 14 2
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