Yii Framework Forum: Make hooks available in code - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Make hooks available in code Rate Topic: -----

#1 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 29 March 2010 - 05:19 PM

I've created an application component to handle hooks.

It has some documentation inside the files, but here's a short manual:

in the code at the place where you'd want some code to hook in (called an "entry point"):
- Create a WEnvironment and set the desired variables.
- set the entry point: Yii::app()->hookManager->entryPoint('EntryPointName', $environment)

A hook function can be a php callback of the forms:
- CMyClass::staticMethod($environment);
- callbackFunc($environment);
- WMyHook (= a class which extends WHook);

A hook can be registered with:
- at runtime: Yii::app()->hookManager->registerHook($hook, $save); // set $save to true to save in the config file
// and never need to call this function again.
- in the config file at protected/config/hooks.php

see the code for details about this.
Just copy these files to a place where they can be automatically loaded, like protected/components






Could or should this be part of the core framework?

Leave your thoughts about this below.

If you people think this should become an enhancement to the framework I'll create a ticket on google projects.

Attached File(s)


0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 30 March 2010 - 01:49 AM

Maybe i don't get it, but can you explain, what's the difference between Hooks and Events?

(Moved here, to not pollute the other thread. Sorry for confusion.)
0

#3 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,739
  • Joined: 17-January 09
  • Location:Russia

Posted 30 March 2010 - 03:19 AM

Mike
Events do require listeners to subscribe. Hooks don't. When hook is invoked, it checks all possible listeners (usually by naming
convention).

Generally hooks are a bit easier to use but they are not so performance efficient.

Onman
This is the major feature so I don't think it can be included in 1.1.x. It's better to keep it as an extension with good documentation and examples.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#4 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 18 February 2013 - 05:21 AM

View PostOnman, on 29 March 2010 - 05:19 PM, said:

I've created an application component to handle hooks.

It has some documentation inside the files, but here's a short manual:

in the code at the place where you'd want some code to hook in (called an "entry point"):
- Create a WEnvironment and set the desired variables.
- set the entry point: Yii::app()->hookManager->entryPoint('EntryPointName', $environment)

A hook function can be a php callback of the forms:
- CMyClass::staticMethod($environment);
- callbackFunc($environment);
- WMyHook (= a class which extends WHook);

A hook can be registered with:
- at runtime: Yii::app()->hookManager->registerHook($hook, $save); // set $save to true to save in the config file
// and never need to call this function again.
- in the config file at protected/config/hooks.php

see the code for details about this.
Just copy these files to a place where they can be automatically loaded, like protected/components






Could or should this be part of the core framework?

Leave your thoughts about this below.

If you people think this should become an enhancement to the framework I'll create a ticket on google projects.



would you mind tell what to do stage-by-stage to use hook, more documents
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users