Rabbit

PHP is fun again


Suppose we want to add or fix a feature to our site. We could just start changing our code, but that way, every visitor would face a buggy or unfinished feature. Masking is a technique that allows you to have different versions of files on two branches, a development and a production. The development branch should be viewed by the developers of your project, while the product branch is the one that the visitors view. That way, you can build any feature you want, test it on a private space and when they are ready, go public with them.

So, how can I use masking?

In order to use masking, you need to copy the file you want to mask into another one, with the underscore ( _ ) character prepended to the name of the file. Then, you can edit the masked file without considering the production branch. For example, if you want to use a masked version of the file elements/user/view.php copy it into the file elements/user/_view.php, edit it and when it's ready merge the changes to the first file.

Not everything can be masked

You can only mask files that are under the folders elements, actions, units, and libs. Folders cannot be masked.

Which files should I mask, and what if I don't?

Masking is usually used when a feature is still under progress, or is being changed. To avoid confusion, we recommend that you merge the masked version into the unmasked, and then delete the first, after you fix or add a feature.

| Branch | Masked Version | Normal Version | Version loaded | | development | doesn't exist | doesn't exist | none | | development | doesn't exist | exists | Normal Version | | development | exists | doesn't exist | Masked Version | | development | exists | exists | Masked Version | | production | doesn't exist | doesn't exist | none | | production | doesn't exist | exists | Normal Version | | production | exists | doesn't exist | none | | production | exists | exists | Normal Version |

How to use the masked files

The purpose of this technique is to have two versions of a page, with the same code. Thus, not any changes to the code are needed between the masked and the unmasked files. So, you actually don't need to do anything more to support masking, than changing the names of the files. For example, if you need to include the library file /libs/user/login.php you just need to use $libs->Load( 'user/login' ) and NOT $libs->Load( 'user/_login' ).

Example

Suppose you have a file into the folder "elements/frontpage" named view.php, and you want to change something on it. The first thing you need to do is to mask the file. Copy it into the file /elements/frontpage/_view.php and then write whatever you want. The changes will take place only at the development branch. When you are ready to publish your changes, just merge the masked file into the normal. If you need to call that element, whether you are on the development, or on the production branch use the function Element() like that:

<?php
    Element( 'frontpage/view' );
?>

^ Back to top