Elgg  Version master
MethodMatcher.php
Go to the documentation of this file.
1 <?php
2 
4 
12 
16  private $type;
17 
21  private $method;
22 
29  public function __construct($type, $method) {
30  $this->type = strtolower(ltrim($type, '\\'));
31  $this->method = strtolower($method);
32  }
33 
40  public function matches($subject) {
41  // We don't use the callable type-hint because it unnecessarily autoloads for static methods.
42 
43  if (is_string($subject)) {
44  if (!str_contains($subject, '::')) {
45  return false;
46  }
47 
48  $subject = explode('::', $subject, 2);
49  }
50 
51  if (!is_array($subject) || empty($subject[0]) || empty($subject[1]) || !is_string($subject[1])) {
52  return false;
53  }
54 
55  if (strtolower($subject[1]) !== $this->method) {
56  return false;
57  }
58 
59  if (is_object($subject[0])) {
60  $subject[0] = get_class($subject[0]);
61  }
62 
63  if (!is_string($subject[0])) {
64  return false;
65  }
66 
67  return (strtolower(ltrim($subject[0], '\\')) === $this->type);
68  }
69 }
__construct($type, $method)
Constructor.
Identify a static/dynamic method callable, even if contains an object to which you don&#39;t have a refer...
$subject
Definition: useradd.php:54
matches($subject)
Does the given callable match the specification?