Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba5be03

Browse files
author
tobiasz.cudnik
committed
2 new callback handling classes
1 parent 1b98e71 commit ba5be03

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

phpQuery/Callback.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,48 @@ public function param() {
2424
return new Callback($this->callback, $this->params+$params);
2525
}
2626
}
27-
class CallbackReference extends Callback{
27+
class CallbackReturnReference extends Callback {
28+
protected $reference;
29+
public function __construct(&$reference, $name = null){
30+
$this->reference =& $reference;
31+
$this->callback = array($this, 'callback');
32+
}
33+
public function callback() {
34+
return $this->reference;
35+
}
36+
}
37+
class CallbackReturnValue extends Callback {
38+
protected $value;
39+
public function __construct($value, $name = null){
40+
$this->value =& $value;
41+
$this->callback = array($this, 'callback');
42+
}
43+
public function callback() {
44+
return $this->value;
45+
}
46+
}
47+
/**
48+
* CallbackParameterToReference can be used when we don't really want a callback,
49+
* only parameter passed to it. CallbackReference takes first parameter's value
50+
* and passes it to reference. Thanks to that, we can use *if statement* instead
51+
* of *callback function*.
52+
*
53+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
54+
*
55+
*/
56+
class CallbackParameterToReference extends Callback {
57+
/**
58+
*
59+
* @param $reference
60+
* @param $paramIndex
61+
* @TODO implement $paramIndex;
62+
* param index choose which callback param will be passed to reference
63+
*/
64+
public function __construct(&$reference, $paramIndex = null){
65+
$this->callback =& $reference;
66+
}
67+
}
68+
class CallbackReference extends Callback {
2869
/**
2970
*
3071
* @param $reference

0 commit comments

Comments
 (0)