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,510 points
516 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,880 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,420 points
359 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,050 points
247 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,010 points
2,186 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,880 points
1,382 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,880 points
1,112 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,880 points
771 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,880 points
1,908 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,880 points
591 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,880 points
3,446 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