• Increase font size
  • Default font size
  • Decrease font size
Home Software Automap Automap User's Guide

Automap User's Guide

E-mail Print
Read : 1,514 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.phk> is the path to the downloaded automap runtime package (see the installation guide for instructions to get this file).
  • <map-path> is the path to the map file to create. Default is to create a file named 'auto.map' in the current working directory. If the file exists, it will be overwritten, unless the '-a' option is set.
  • <base-path> is a base path to combine with the directory containing the map. See this document for more about base paths. Default is no base path.
  • '-a' means 'append'. It is used if you want to add symbols to an existing map without recreating it from scratch. Beware of the combination of the '-a' and '-b' options as this can make previously registered paths invalid (as the base path will be registered in the map, overriding the previous value).
  • <path1> [<path2> ... ] is a list of one or more relative paths. Directories are searched recursively for PHP scripts. Specifying a directory here is the easiest solution to register a whole file tree.

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


Please login or register to add a comment