What is the best way to allow plugins for a PHP application

0 votes
I want to create something that people can extend by using a plugin interface.

How does one go about writing 'hooks' into their code so that plugins can attach to specific events?
Apr 15, 2020 in PHP by kartik
• 37,520 points
762 views

1 answer to this question.

0 votes

Hello @kartik,

I've used, it's an attempt to copy from Qt signals/slots mechanism, a kind of Observer pattern. Objects can emit signals. 

Every signal has an ID in the system - it's composed by sender's id + object name Every signal can be binded to the receivers, which simply is a "callable" You use a bus class to pass the signals to anybody interested in receiving them When something happens, you "send" a signal. 

Below is and example implementation

    <?php

    class SignalsHandler {
    private static $connections = array();
    private static $sender;
    public static function connect($sender, $signal, $slot) {
    if (is_object($sender)) {
            self::$connections[spl_object_hash($sender)][$signal][] = $slot;
     }
    else {
            self::$connections[md5($sender)][$signal][] = $slot;
        }
    }

Hope this works!!

Thank You!!

answered Apr 15, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
0 answers

What is the best IDE for PHP?

I use Notepad++ for code editing, I need an ...READ MORE

Jun 23, 2022 in PHP by narikkadan
• 63,600 points
648 views
0 votes
0 answers

What is the correct syntax for PHP/SQL prepared statements?

The PHP/SQL statement that I have created ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
459 views
0 votes
0 answers

Does the string "php?id=1" within a http GET request mean there is necesseraly an sql request to a back-end database?

You can use Google dorks like "inurl:.php?id=" ...READ MORE

Aug 6, 2022 in PHP by Kithuzzz
• 38,000 points
3,007 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,699 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,491 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,043 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
2,472 views
0 votes
1 answer

What are the best way to allow plugins for a PHP application?

Hii, Here is an approach I have  used, it's ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,840 points
764 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,819 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP