Jump to content

Problems with addHookAfter WireHttp::send


pwFoo
 Share

Recommended Posts

Hi,

after sone time playing without hooks I tried to hook the WireHttp method send() with the latest devns (send is now public and hookable!), but it doesn't work.

What's wrong with this call inside a module?

$this->addHookAfter('WireHttp::send', $this, 'hookCheckAuth');

Inside the "hookCheckAuth" I tried to echo, exit() / die() or modifiy $event->return. Works if I call the method direct, but nothing happens if I call the WireHttp send() method...?

Tried it also from a template and it works with the following code:

wire()->addHookAfter('WireHttp::send', function($event) {
  die("TEST");
});

Same code modified to use it inside a module doesn't work:

		$this->addHookAfter('WireHttp::send', function($event) {
		  die("TEST");
		});
		$this->wire()->addHookAfter('WireHttp::send', function($event) {
		  die("TEST");
		});
		wire()->addHookAfter('WireHttp::send', function($event) {
		  die("TEST");
		});

I'll reinstall PW to have a clean new install... But maybe I missed something...

*UPDATE*

Also tested without success:

$wire->addHookAfter('WireHttp::send', function($event) {
    die("TEST");
});
Link to comment
Share on other sites

The problem is very likely something not visible in your post above. Testing with the setup below, I had no issues getting this to work under latest version of the devns branch:

<?php
# /site/modules/TestHook.module
class TestHook extends WireData implements Module {
    public static function getModuleInfo() {
	return array('autoload' => true);
    }
    public function init() {
	$this->addHookAfter('WireHttp::send', $this, 'hookCheckAuth');
    }
    public function hookCheckAuth(HookEvent $event) {
	die("dying");
    }
}
<?php
# /site/templates/basic-page.php
$http = new \ProcessWire\WireHttp;
$http->send('/');
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...