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,490 points
90 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,560 points

Related Questions In PHP

0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
1,978 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,560 points
275 views
0 votes
1 answer

What is Php Mysql Database? How php connect to database?

Hello kartik, MySQL is the most popular database ...READ MORE

answered Feb 25, 2020 in PHP by Dey
227 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,560 points
296 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,560 points
323 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,560 points
299 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,560 points
148 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,560 points
278 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,560 points
151 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,560 points
850 views