Jul 082017
 

Hey! Long time no see! Heehee.

I am just dropping a note here about the basic steps of how to install XDebug for a specific setup.

Here is my configuration:

  • host:
    • OS: Windows 7 64 bits
    • IP: 192.168.0.3
    • IDE: Netbeans 8.2
  • guest:
    • OS: Debian Jessie 64 bits in VirtualBox
    • IP: 192.168.0.4 (bridged network in VirtualBox settings)
    • standard Apache2, PHP 5, MySQL from official repositories

The idea is: I want to use the stepper on a website located inside a virtual machine from an IDE on the host machine.

Step by step

XDebug installation

  1. On the guest machine, get the phpinfo() output. If you have no idea how to do this quickly:
    1. From the command line, run php --info > ~/tempphpinfo.txt (you can safely delete this file later).
    2. Open the file: gedit ~/tempphpinfo.txt.
    3. Copy all the contents.
  2. Go to https://xdebug.org/wizard.php and follow the instructions: you will have to paste the contents of the phpinfo obtained earlier. The wizard will tell you exactly how to build xdebug. Make sure you are in the correct folder when running the phpize command.
  3. Locate the xdebug.ini files (named 20-xdebug.ini on my Debian) on the guest machine:
    1. cd /etc/php5
    2. find | grep xdebug
  4. Edit one of the files listed by the last command and add those lines:
  5. sudo service apache2 restart, just in case.

Testing XDebug

We will create a small php file which will react to XDebug calls.

  1. Create a php file:
    • touch ~/testxdebug.php
    • gedit ~/testxdebug.php
    • Insert the following:
    • Save and close.
  2. Start the command line debugger: php ~/testxdebug.php. You may have a warning about the xdebug extension already started: you can ignore it or fix this later by commenting/removing the zend_extension=path/to/xdebug.so line you have added to the /etc/php5/cli/php.ini file (not the xdebug.ini files!).
  3. In the web browser, go to your website location, a Drupal 8 in my case and add an attribute at the end of the URL, e.g.: http://localhost/DrupalXDebug/web/index.php?XDEBUG_SESSION_START=mysession.
  4. In the terminal where you have run the php ~/testxdebug.php command, you should see a message like this one:

    connection established: Resource id #5

    If not, the configuration is wrong and check the steps again or the resources links at the end of this article.

Setup remote debugging

Until now, we have only ran the debugger (the little php script we have created earlier, which you can safely delete now) from inside the guest machine. We will configure xdebug to work with remote machines, in my case, the Windows host.

  1. Edit one of the xdebug.ini files you have edited earlier: replace the xdebug.remote_host value by the IP of the host, 192.168.0.3 in my case.
  2. sudo service apache2 restart, just in case.

Netbeans configuration

Now we can configure Netbeans to run the debugger.

  1. Open the website project.
  2. Right click on the project in the Projects list and click on Properties.
  3. Enter the URL of your website in Run Configuration > Project URL. In my case, it was like this:
    Screenshot from netbeans

    Where to set the website URL

  4. Click on the Advanced button.
  5. Set the path mappings. In my case:
    Screenshot of path mapping on Netbeans

    How to set path mappings

You should now be set for debugging with the stepper!

Run the debug

  1. Click on the Debug Project button in the top toolbar of Netbeans and it should launch automatically a browser with a session id already set!
  2. Put a breakpoint somewhere in the code.
  3. Each time a request is sent to the website, Netbeans will control the page generation.

Additional Information

Feb 182017
 

Instructions

I will be creating a dedicated module using Drupal Console for this event subscriber. But feel free to use your own if you already have one! (don’t forget to backup)

  1. Access the drupal root folder in command line.
  2. Generate a new module:
  3. Generate the event subscriber. We will subscribe to the kernel.request event:
  4. Current state:
  5. Install the module using either drupal module:install or drush pm-enable:
  6. Now, refresh your web page and on each request received server side, a message will tell you the event occurred!

Additional Information

  • Instructions made on Drupal 8.2.x.
  • Using Drupal Console, you can easily inject services such as the current_user one by answering yes when it asks if you want to load services from the container. Please check this article about service dependency injection: [Drupal] Service dependency injection in a service type class.
  • After editing your files, remember to run a cache rebuild either with drupal cache:rebuild or drush cache-rebuild.
  • Events documentation entry point: Events on Drupal 8. You will find a few core events here.
  • The callback function’s name can be changed to whatever you want.
Feb 162017
 

The code

Additional Information

Feb 162017
 

The code

Additional Information

  • Unlike service type class service dependency injection, there may be no need to implement an interface to be able to load the needed services, such as extending from ControllerBase. So if you are extending from a class which already has the dependency injection implementation, you can just override the create and __construct methods. Don’t forget to call parent methods if needed.
  • Think of the create method as the model used by the __construct of your class.
  • The create signature needs to respect the one of the implemented interface (use your IDE to check against the original declaration).
  • Originally made and tested on Drupal 8.2.x.
  • A convenient list of core services can be found here: https://api.drupal.org/api/drupal/core%21core.services.yml/8.2.x (don’t forget to select the Drupal version if you are not on 8.2.x).
  • Some classes such as ones extending BlockBase will need to implement interfaces to access this pattern:
Aug 082011
 

Vous avez le code source ici : Lien vers le code

Il s’agit d’un script PHP qui permet de sélectionner le bon lecteur en fonction de la plateforme. Par exemple, sur Flash, le player Blip va être un <video> tandis que sur PC et autres, il s’agira d’un <object> contenant un lecteur Flash.

Le code HTML généré est valide XHTML 1.0 Strict avec un contenu de type text/html (je ne sais pas ce que ça donne avec application/xhtml+xml). Il va de soi que la partie <video> n’est pas validable. Mais cette balise ne se trouve dans le code que lorsque la vidéo est lue depuis un iPhone, iPod ou iPad, et il s’agit de la seule manière disponible d’avoir des vidéos dans Safari Mobile.

Le script PHP fonctionne sur 5.3.0, mais il est simple de ne prendre qu’une seule partie du script pour correspondre à vos besoins, notamment des versions inférieures de PHP.

Encore une chose, si vous êtes en HTML 4 ou 5, vous pouvez utiliser les <iframe> par défaut de Youtube et Blip. Mais attendez-vous à ne plus avoir le contrôle sur les changements de lecteurs, ni sur la justesse du marquage HTML.

J’ai juste un dernier mot sur le sujet, je ne sais pas si le bout de code est compatible avec la nouvelle version du player de Youtube, celui en noir.

Apr 152011
 

Bon, en fait, je ne sais pas si je suis le premier à coder ainsi. Mais comme j’aime vraiment le modèle que j’ai conçu pour organiser les scripts de Fuu-Doh! v2, je pense que je partagerai bientôt le concept aux développeurs PHP qui pourraient en être intéressés.

C’est un modèle de conception qui est très simple à comprendre et très structuré, avec beaucoup d’imbrications d’objets. Je suis actuellement sur du PHP 5.2, je ne peux pas garantir pour l’instant que le modèle sera compatible aux versions précédentes de PHP qui gèrent les classes. Mais je pense qu’il n’y a pas vraiment de problème sur ce point.

J’espère me trouver un peu de temps libre pour pouvoir vous l’expliquer. 🙂