Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

Autoload

> 编程语言
Open source

A lightweight php namespace aware autoload generator and phar archive builder

392 stars0 likes1 views
WebsiteGitHub

About

A lightweight php namespace aware autoload generator and phar archive builder

PHP Autoload Builder

The PHP AutoloadBuilder CLI tool phpab is a command line application to automate the process of generating an autoload require file with the option of creating static require lists as well as phar archives.

Features

  • scan multiple directories recursively in one run, optionally follow symlinks, wildcards or based on composer.json
  • Cache scan results
  • Template based autoload code
  • Custom variables for templates
  • Compatibility mode for PHP 5.2 compliant autoloader
  • Case sensitive as well as case insensitive classname mapping
  • Phar generation, with or without compression and openssl key signing
  • Static require list generation
  • Opcache warming list generation
  • Linting of generated code

Requirements

  • PHP 5.3+ (Runtime, for development / tests: 7.2+)
  • Fileinfo (ext/fileinfo)
  • Tokenizer (ext/tokenizer)
  • For PHAR generation support:
    • ext/phar (write enabled: phar.readonly = Off)
    • ext/gzip (optional)
    • ext/bzip2 (optional)
    • ext/openssl (optional, for phar signing only)

Installation

Executable PHAR

The recommended way to install phpab is by using phive:

phive install phpab

Manual install

If you do not have phive installed or want to install manually, you can download the PHAR archive from the Releases tab.

Please note: On Linux/Unix based system the phar needs to be marked executable for direct execution:

[theseer@rikka ~]$ chmod +x phpab*.phar

Other Downloads

  • Latest development snapshot (ZIP Archive)
  • Releases (Source)

Usage

…

Usage Examples

[theseer@rikka ~]$ phpab -o src/autoload.php -b src composer.json

[theseer@rikka ~]$ phpab -o opcache_warming.php -w --reset src

[theseer@rikka ~]$ phpab -o src/autoload.inc.php src

[theseer@rikka ~]$ phpab -c -o src/autoload.inc.php src

[theseer@rikka ~]$ phpab -o src/core/autoload.inc.php -b src src

[theseer@rikka ~]$ phpab -p -o framework.phar -b src composer.json

[theseer@rikka ~]$ phpab -p -o framework.phar framework/src

[theseer@rikka ~]$ phpab -p -o framework.phar --bzip2 --key sign.key framework/src

[theseer@rikka ~]$ phpab -b . --tolerant -o zf1_autoload.php -e '*/Test/*' Zend

Automation

When using phpab it is necessary to recreate the autoload file every time a new class is created. This usually also happens after pulling from a repo or when switchting branches. Using a git post-checkout hook placed in .git/hooks/post-update this can be automated for most cases.

Basic Sample:

bash
#!/bin/bash
phpab -c -o src/autoload.inc.php src

Sample using an ant build.xml file.

bash
#!/bin/bash
if [ -f build.xml ]; then
    ant -p | grep phpab > /dev/null

    if [ $? -eq 0 ]; then
        ant phpab > /dev/null &
    fi
fi

Template Variables

The generated code is based uppon templates provided by default in the templates subfolder. The template engine allows for simply replacing of name based placeholders. For now, only a few default variables are defined but API hooks / CLI parameters exist to set custom variables.

Known variables are:

  • ___CREATED___ Set to a timestamp of creation, format can be adjusted
  • ___CLASSLIST___ The found list classes in form of a generated map
  • ___BASEDIR___ If a Basedir is set, the value will get removed from the file path and get replaced by DIR

Used in PHAR Mode only:

  • ___PHAR___ The filename of the generated phar or it's alias when --alias is given (see src/templates/phar.php.tpl)

Custom variables as defined by passing --var name=value via cli are accessed by pre- and appending ___ to it:

  • ___name___ Going to be replaced by the value provided via cli param

Changelog

The changelog moved to its own document

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言