-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilterFunctionParameter.php
66 lines (53 loc) · 1.39 KB
/
FilterFunctionParameter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Filter Function Parameter
*
* @author Whizark <devaloka@whizark.com>
* @see http://whizark.com
* @copyright Copyright (C) 2014 Whizark.
* @license MIT
*/
namespace Devaloka\Component\EventConverter;
use Ecailles\CallableObject\CallableObject;
use ReflectionParameter;
/**
* Class FilterFunctionParameter
*
* @package Devaloka\Component\EventConverter
*/
class FilterFunctionParameter
{
private $parameter;
public function __construct(CallableObject $callable, $parameter)
{
$rawCallable = $callable->get();
if ($callable->isInstanceMethod() || $callable->isClassMethod()) {
$object = $rawCallable[0];
$method = $rawCallable[1];
$rawCallable = [$object, $method];
}
$this->parameter = new ReflectionParameter($rawCallable, $parameter);
}
public function getParameter()
{
return $this->parameter;
}
public function allowsOnlyClass($acceptedClass)
{
$class = $this->parameter->getClass();
if ($class === null) {
return false;
}
if ($class->name === $acceptedClass) {
return true;
}
if ($class->isSubclassOf($acceptedClass)) {
return true;
}
return false;
}
public function isPassedByReference()
{
return $this->parameter->isPassedByReference();
}
}