Homepage of www.easymagazine.net | Wem site map of www.easymagazine.net | Email the author of www.easymagazine.net

 

How to create a Command

A command is an implementation of the command pattern.
You can download the command sandbox in order to have a skeleton to develop your plug-in but you'll see how simple it is!

As software developer we like to start with some code:

require_once(COMMANDPATH.'/command.php');
require_once(COMMANDPATH.'/remote.php');

class ProofCommand implements Command {

function execute(){
    echo "I'm a command!!!";
}

}

$command= new ProofCommand();

$remote = Remote::getInstance();

$remote->addCommandBeforeIndex($command);

So few lines of code?
Yes! :-)

Ad the start of the script we include the command interface and the remote singleton.
If you are curious about this script just check the files command.php and remote.php in the admin/command directory in your EasyMagazine installation.

Then we create the class ProofCommand that implements the interface Command. This means that we must create a method execute(). This method will be executed every time the trigger is pulled.

That's it, the command is ready! :-)

Now we need to decide when the command has to be executed.
We decide to let it execute before the index page is loaded, that means that every time an user opens our index page our command will be triggered!

So we create an instance of the command ProofCommand, we get the instance of the remote singleton and we add the $command instance to the command array that have to be executed before the index is loaded.

Now we finished, the command will be executed as we desire, every time the index page is loaded.

The events we can use to triger a command are:

  • addCommandBeforeArticle
  • Commands added to this array will be executed before the Article page is showed.
  • addCommandAfterArticle
  • Commands added to this array will be executed before the Article page is showed.
  • addCommandBeforeArticlesPerson
  • Commands added to this array will be executed before the ArticlesPerson page is showed.
  • addCommandAfterArticlesPerson
  • Commands added to this array will be executed before the ArticlesPerson page is showed.
  • addCommandBeforeCategory
  • Commands added to this array will be executed before the Category page is showed.
  • addCommandAfterCategory
  • Commands added to this array will be executed before the Category page is showed.
  • addCommandBeforeComments
  • Commands added to this array will be executed before the Comments page is showed.
  • addCommandAfterComments
  • Commands added to this array will be executed before the Comments page is showed.
  • addCommandBeforeNumber
  • Commands added to this array will be executed before the Number page is showed.
  • addCommandAfterNumber
  • Commands added to this array will be executed before the Number page is showed.
  • addCommandBeforeNumbersList
  • Commands added to this array will be executed before the NumbersList page is showed.
  • addCommandAfterNumbersList
  • Commands added to this array will be executed before the NumbersList page is showed.
  • addCommandBeforePage
  • Commands added to this array will be executed before the Page page is showed.
  • addCommandAfterPage
  • Commands added to this array will be executed before the Page page is showed.
  • addCommandBeforePeople
  • Commands added to this array will be executed before the People page is showed.
  • addCommandAfterPeople
  • Commands added to this array will be executed before the People page is showed.
  • addCommandBeforeResults
  • Commands added to this array will be executed before the Results page is showed.
  • addCommandAfterResults
  • Commands added to this array will be executed before the Results page is showed.
  • addCommandBeforeIndex
  • Commands added to this array will be executed before the Index page is showed.
  • addCommandAfterIndex
  • Commands added to this array will be executed before the Index page is showed.
  • addCommandBeforeHeader
  • Commands added to this array will be executed before the Header of a page is showed.
  • addCommandAfterHeader
  • Commands added to this array will be executed before the Header of a page is showed.
  • addCommandBeforeFooter
  • Commands added to this array will be executed before the Footer of a page is showed.
  • addCommandAfterFooter
  • Commands added to this array will be executed before the Footer of a page is showed.

 


Copyright © 2009, 2010, 2011 Fabio Mattei, designed by zuudesign.sk