private function body_for_pattern_matcher($patterns, $context) { $body = ''; foreach ($patterns as $regex => $native_method) { $regex = new Literal($regex); $body .= 'if (preg_match(' . $regex->to_php() . ', $method, $matches)) {'; $body .= ' $args[] = $matches;'; $body .= ' return call_user_func_array(array(' . $context . ', "' . $native_method . '"), $args);'; $body .= '}'; } $body .= 'throw new \\Exception("Unknown method \'$method\'");'; return $body; }