PHP Event API

Events

I tried a couple of existing plugin solutions most did 95% of what I needed and the other 5% was next to impossible to force.

After wasting days I decided I would write my own, what follows is an overview of Tentacle event API.

Contact me if you have any questions.

Registering an event:

[sourcecode language="php"]
function method_one (){
echo ‘one ‘;
}

function method_two (){
echo ‘two ‘;
}

event::on(‘event_trigger’, ‘method_one’, 2);
event::on(‘event_trigger’, ‘method_two’, 1);

event::trigger(‘event_trigger’);
[/sourcecode]

Turning events off:

[sourcecode language="php"]event::off(‘event_trigger’);

event::off(‘event_trigger’, ‘method_two’);

event::off(null, ‘method_one’);[/sourcecode]

Test if an event exists:

[sourcecode language="php"]var_dump(event::exists(‘event_trigger’));
[/sourcecode]
boolean true

Trigger an event:

[sourcecode language="php"]function method_name ( )
{
echo ‘my method name’;
}

event::on(‘event_name’, ‘method_name’);

event::trigger(‘event_name’);[/sourcecode]
my method name

Trigger an event and pass data to it:

[sourcecode language="php"]function method_data ( $text = ” )
{
echo ‘ 1 my method data is ‘.$text;
}

function method_data_two ( $text = ” )
{
echo ‘ 2 my method data is ‘.$text;
}

event::on(‘event_data’, ‘method_data’, 1);
event::on(‘event_data’, ‘method_data_two’, 2);

event::trigger(‘event_data’, ‘this’);[/sourcecode]
1 my method data is this 2 my method data is this

Triggering a class and passing data to the method

[sourcecode language="php"]class my
{
static function method_name ( $text = ” )
{
echo ‘my class method name is ‘.$text;
}
}

event::on(‘event_class’, ‘my::method_name’);

event::trigger(‘event_class’, ‘Lary’);[/sourcecode]
my class method name is Lary

Event chaining

[sourcecode language="php"]function method_sad ( $text = ” )
{
return str_replace(‘blah’, "sad", $text);
}

function method_happy ( $text = ” )
{
return str_replace(‘sad’, "happy", $text);
}

event::on(‘event_mood’, ‘method_sad’, 1);
event::on(‘event_mood’, ‘method_happy’, 2);

echo event::filter(‘event_mood’, ‘I am blah!’);
[/sourcecode]
I am happy!

Serpent an Extension API

I had posted this question on Forrst, and it got me wondering how best to go about keeping track of an applications core version and pushing updates ( not using GIT ).

Using git would be ideal if I was the one managing a single web application. Obviously using Git would complicate things for beginner users. But its likely that Extension and Theme developers will be using some form of source control.

I then set off to build a developer portal to manage this versioning.

Read the rest here.

Announcing the Inkdit API

Big news for the Inkdit team – today we’re officially opening up our API to the public! You can register and find documentation on our API’s site.

Our API allows developers at your organization to write applications that can create, share and sign contracts that will be securely stored with cryptographic tamper-resistance on Inkdit.

There are a lot of applications that involve agreements – license agreements, sign-offs, waivers, etc. Using Inkdit’s API your applications can capture those agreements in a tightly integrated way.

Shortly before the holidays we quietly released a Ruby library for interacting with Inkdit’s API (available as a gem named ‘inkdit’, with documentation here).

If you’re using we hope you’ll take a look at the library. If you’re not using Ruby, we hope you’ll look at it anyways – we’ve written it so that it can work as an example for other languages as well.

So what’s coming next? We’ve got big plans for our API; we have a sophisticated tiered user authentication system in the works, and we’d like to make that available for developers to build on top of.

The exciting thing about putting out an API is people are going to find uses for it that we’ve never thought of ourselves. We want to make it as easy as possible for people to use Inkdit to create new applications, so tell us what you need!

Is there a new application you’d like to see built on top of Inkdit?

Do you use an application that would integrate well with us?

Are there new capabilities you’d like us to expose to the API?

We’re looking into other languages to build libraries for. Is there a particular language that you would like code examples or a library for?

Via: Inkdit