Automap User's Guide

Read : 5,888 times
(0 votes, average 0 out of 5)

1 - Building a map file

The syntax to extract the symbols from one or more PHP script files to a map file is :

php <automap.phk> register [-m <map-path>] [-b <base-path>] [-a] <path1> [<path2>... ]

where :

Automap-specific directives can be inserted in the PHP scripts. Their syntax and use are detailed here.

2 - Runtime - using maps

In order to be able to autoload symbols from one or several existing map files, there are two steps :

  1. Load the Automap runtime code. This means require()ing the 'automap.phk' file.
  2. \Automap\Mgr::load() one or several map files.

Example :

// This loads the Automap runtime :


// This loads the map :


:note As we use a fully-qualified class name, this code works whatever namespace you define for your code.

You can then load another map, using a similar syntax, and so on... There is no limit to the number of maps that can be active at the same time. When resolving a symbol, maps are searched starting with the most recent load, up to the map loaded the longest time ago.

Of course, these steps are executed only once per request. Don't include the code above at the beginning of all your scripts ! Just insert it at the entry point(s) of your application.

:note If the map file cannot be loaded (because the file does not exists, or for any other reason), \Automap\Mgr::load() throws an exception with an informative message.

That's all. From now on, every symbols defined in any of the loaded maps will be autoloaded when first referenced.

3 - automap.phk CLI commands

For more information on the commands available using automap.phk, run :

php automap.phk help

Joomla SEO powered by JoomSEF