Skip to content

Commit

Permalink
#33 and get{Foo, Bar, Baz} style wildcards for instances
Browse files Browse the repository at this point in the history
  • Loading branch information
antecedent committed Feb 12, 2016
1 parent 0d3ae29 commit b5c98f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/CallRerouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function applyWildcard($wildcard, callable $target, Handle $handle = null)
$handle = $handle ?: new Handle;
list($class, $method, $instance) = Utils\interpretCallable($wildcard);
if (!empty($instance)) {
foreach (get_class_methods($instance) as $item) {
foreach (Utils\matchWildcard($method, get_class_methods($instance)) as $item) {
if (!$handle->hasTag($item)) {
connect([$instance, $item], $target, $handle);
$handle->tag($item);
}
}
$wildcard = $method;
return $handle;
}

$callables = Utils\matchWildcard($wildcard, Utils\getUserDefinedCallables());
Expand Down Expand Up @@ -191,7 +191,9 @@ function disconnectAll()
foreach ($routesByClass as $method => $routes) {
foreach ($routes as $route) {
list($callback, $handle) = $route;
$handle->expire();
if ($handle !== null) {
$handle->expire();
}
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/wildcards-and-restoreall.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
https://github.com/antecedent/patchwork/issues/33

--FILE--
<?php

assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
error_reporting(E_ALL | E_STRICT);

require __DIR__ . '/../Patchwork.php';
require __DIR__ . '/includes/Inheritance.php';

Patchwork\redefine('BarObject::*', function() {
return 'redefined';
});

$bar = new BarObject;

assert($bar->getFoo() === 'redefined');
assert($bar->getBar() === 'redefined');

Patchwork\restoreAll();

assert($bar->getFoo() === 'foo');
assert($bar->getBar() === 'bar');

?>
===DONE===

--EXPECT--
===DONE===

0 comments on commit b5c98f8

Please sign in to comment.