Elgg  Version 2.3
MethodMatcher.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
11 
15  private $type;
16 
20  private $method;
21 
28  public function __construct($type, $method) {
29  $this->type = strtolower(ltrim($type, '\\'));
30  $this->method = strtolower($method);
31  }
32 
39  public function matches($subject) {
40  // We don't use the callable type-hint because it unnecessarily autoloads for static methods.
41 
42  if (is_string($subject)) {
43  if (false === strpos($subject, '::')) {
44  return false;
45  }
46 
47  $subject = explode('::', $subject, 2);
48  }
49 
50  if (!is_array($subject) || empty($subject[0]) || empty($subject[1]) || !is_string($subject[1])) {
51  return false;
52  }
53 
54  if (strtolower($subject[1]) !== $this->method) {
55  return false;
56  }
57 
58  if (is_object($subject[0])) {
59  $subject[0] = get_class($subject[0]);
60  }
61 
62  if (!is_string($subject[0])) {
63  return false;
64  }
65 
66  return (strtolower(ltrim($subject[0], '\\')) === $this->type);
67  }
68 
69 
70 }
$subject
Definition: exceptions.php:25
$method
Definition: form.php:25
__construct($type, $method)
Constructor.
list style type
Definition: admin.css.php:808
Save menu items.
matches($subject)
Does the given callable match the specification?
Identify a static/dynamic method callable, even if contains an object to which you don&#39;t have a refer...
if(!$display_name) $type
Definition: delete.php:27