fredemmott / hhvm-autoload
Installs: 390
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 18
Language:Hack
Type:composer-plugin
Requires
- composer-plugin-api: ^1.0
- hhvm: ^3.12
- 91carriage/phpunit-hhi: ^5.1
- facebook/definition-finder: ^1.0
- fredemmott/hack-error-suppressor: ^1.0
- fredemmott/type-assert: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.1
This package is auto-updated.
Last update: 2020-11-09 23:43:36 UTC
README
A Composer plugin for autoloading classes, enums, functions, typedefs, and constants on HHVM.
FAQ
Do I need to use Hack?
No, PHP is fine - but HHVM is required because:
- PHP does not support autoloading anything other than classes
- this project and the parser are written in Hack
Can I autoload functions and constants if I'm not writing Hack?
Yes :)
Why does this project use Composer's autoloader?
It can't depend on itself :)
Preview Warning
The autoload mechanism itself is very heavily tested at Facebook, however the library used to find the autoloadables (classes, functions, etc) is fairly new, and has not been used on a wide variety of projects. It's been tested on:
- The PHP and Hack code inside HHVM and Hack
- The Hack/HHVM documentation site
- The dependencies of the Hack/HHVM documentation site
If you encounter a parse error, please file an issue against hhvm/definition-finder with either example code, or a link to an open source project that it can't parse.
For any other issue, please file an issue against this project.
Usage
- Add an
hh_autoload.json
file (see section below) and optionally remove your configuration from composer.json composer require facebook/hhvm-autoload
- Replace any references to
vendor/autoload.php
withvendor/hh_autoload.php
- If you are using PHPUnit, you will need to add
vendor/hh_autoload.php
to yourbootstrap.php
, or tophpunit.xml
as abootstrap
file if you don't already have one. This is because PHPUnit automatically loadsvendor/autoload.php
, but is not aware ofvendor/hh_autoload.php
- To re-generate the map, run
composer dump-autoload
or any other command that generates the map
Configuration (hh_autoload.json
)
A minimal configuration file is:
{ "roots": [ "src/" ] }
This will look for autoloadable definitions in src/
, and also look in vendor/
. It will pay attention to the autoload
sections of composer.json
inside the vendor/
directory.
The following settings are optional:
"extraFiles": ["file1.php"]
- files that should not be autoloaded, but should berequire()
ed byvendor/hh_autoload.php
. This should be needed much less frequently than under Composer"includeVendor": false
- do not includevendor/
definitions invendor/hh_autoload.php
"autoloadFilesBehavior": "scan"|"exec"
- whether autoloadfiles
from vendor should bescan
ned for definitions, orexec
uted byvendor/hh_autoload.php
-scan
is the default, and generally favorable, butexec
is needed if you have dependencies that need code to be executed on startup.scan
is sufficient if your dependencies just usefiles
because they need to define things that aren't classes, which is usually the case.
How It Works
facebook/definition-finder
provides a list of all PHP and Hack definitions in the specified locations- This is used to generate something similar to a classmap, except including other kinds of definitions
- The map is provided to HHVM with
HH\autoload_set_paths()
The Composer plugin API allows it to re-generate the vendor/hh_autoload.php
file automatically whenever Composer itself regenerates vendor/autoload.php
Contributing
We welcome GitHub issues and pull requests - please see CONTRIBUTING.md for details.
License
hhvm-autoload is BSD-licensed. We also provide an additional patent grant.