You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 1, 2023. It is now read-only.
* Documentation update
Remove implied comparisons to composer autoloading.
Remove statement about global namespace fallback.
Document interactions with native autoloaders.
Document HH\Facts mode (not present in this commit).
* [Untested] Emit an HH\Facts autoload map
May still need to lowercase the names.
Will check in a Facts-enabled docker container.
* Lowercase the names and call the right functions
* Parens
* Escape `HH\Facts`, no need for a random form feed
* Rename useFactsIfAvailableAndDoNotEmitAStaticMap
Now named useFactsIfAvailable
* Support hhvm 4.109 and up
Hhvm 4.116 and below need a HH_FIXME.
Hhvm 4.117 has the hhi and the code typechecks on 4.117.
* Update HH_FIXME messages
The ext-facts hhi didn't make the cut for 4.117.
Copy file name to clipboardexpand all lines: README.md
+19-5
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,11 @@ The autoloader for autoloading classes, enums, functions, typedefs, and constant
5
5
Usage
6
6
=====
7
7
8
-
1. Add an `hh_autoload.json` file (see section below) and optionally remove your configuration from composer.json
8
+
1. Add an `hh_autoload.json` file (see section below)
9
9
2.`composer require hhvm/hhvm-autoload`
10
-
3. Replace any references to `vendor/autoload.php` with `vendor/autoload.hack` and call `Facebook\AutoloadMap\initialize()`
11
-
4. To re-generate the map, run `vendor/bin/hh-autoload`, `composer dump-autoload`, or any other command that generates the map
10
+
3. Require the autoload file from your entrypoint functions using `require_once (__DIR__ . '(/..)(repeat as needed)/vendor/autoload.hack');`
11
+
4. Call `Facebook\AutolaodMap\initialize()` to register the autoloader with hhvm.
12
+
5. To re-generate the map, run `vendor/bin/hh-autoload`, `composer dump-autoload`, or any other command that generates the map
12
13
13
14
Configuration (`hh_autoload.json`)
14
15
==================================
@@ -32,9 +33,10 @@ The following settings are optional:
32
33
-`"includeVendor": false` - do not include `vendor/` definitions in `vendor/autoload.hack`
33
34
-`"devRoots": [ "path/", ...]` - additional roots to only include in dev mode, not when installed as a dependency.
34
35
-`"relativeAutoloadRoot": false` - do not use a path relative to `__DIR__` for autoloading. Instead, use the path to the folder containing `hh_autoload.json` when building the autoload map.
35
-
-`"failureHandler:" classname<Facebook\AutoloadMap\FailureHandler>` - use the specified class to handle definitions that aren't the Map. Your handler will not be invoked for functions or constants
36
-
that aren't in the autoload map and have the same name as a definition in the global namespace. Defaults to none.
36
+
-`"failureHandler:" classname<Facebook\AutoloadMap\FailureHandler>` - use the specified class to handle definitions that aren't the Map. Defaults to none.
37
37
-`"devFailureHandler": classname<Facebook\AutoloadMap\FailureHandler>` - use a different handler for development environments. Defaults to the same value as `failureHandler`.
38
+
-`"parser:" any of [ext-factparse]"` - select a parser to use, but there is only one valid option. Defaults to a sensible parser.
39
+
-`"useFactsIfAvailable": false` - use ext-facts (HH\Facts\...) to back Facebook\AutoloadMap\Generated\map() instead of a codegenned dict. See _Use with HH\Facts_ for more information about this mode.
38
40
39
41
Use In Development (Failure Handlers)
40
42
=====================================
@@ -90,12 +92,24 @@ Information you may need is available from:
90
92
-`Facebook\AutoloadMap\Generated\root()`: the directory containing the
91
93
project root, i.e. the parent directory of `vendor/`
92
94
95
+
Use with HH\\Facts
96
+
=================
97
+
98
+
HHVM 4.109 introduced ext-facts and ext-watchman. Unlike the static pre-built autoloader which is built into a [repo authoratative](https://docs.hhvm.com/hhvm/advanced-usage/repo-authoritative) build, this native autoloader works incrementally and is suitable for autoloading in your development environment. For more information about setting up this autoloader, see the [blog post](https://hhvm.com/blog/2021/05/11/hhvm-4.109.html) for hhvm 4.109.
99
+
100
+
When using a native autoloader (either the repo auth or ext-facts autoloader), you do not need hhvm-autoload to require classes/functions/types/constants at runtime. If you (and your vendor dependencies) do not call any functions in the `Facebook\AutoloadMap` namespace, other than `Facebook\AutoloadMap\initialize()`, you don't need hhvm-autoload anymore. In that case, you could drop this dependency and remove the calls to `initialize()`. If you are using other functions, like `Facebook\AutoloadMap\Generated\map()`, you'd still need the vendor/autoload.hack file that hhvm-autoload generates.
101
+
102
+
Hhvm-autoload supports outputting a vendor/autoload.hack file which forwards all queries to ext-facts. `Facebook\AutoloadMap\Generated\map_uncached()` will always be up to date in this mode, since `HH\Facts` is always up to date. `Facebook\AutoloadMap\Generated\map()` is memoized (within a request), since some code may rely on getting the same result from multiple calls. You can enable this mode by adding `"useFactsIfAvailable": true` to the hh_autoload.json config file. Hhvm-autoload will emit a shim file instead of a full map. This option is ignored if `HH\Facts\enabled()` returns false, or when `--no-facts` is passed to `vendor/bin/hh-autoload`. We recommend passing `--no-facts` when building for production (specifically repo auth mode). Returning a hardcoded dict is faster than asking `HH\Facts`.
103
+
104
+
Important to note. Autoloading with a native autoloader does not respect hh_autoload.json. The repo auth autoloader allows any code to use any symbol. The facts autoloader honors the configuration in .hhvmconfig.hdf instead. Make sure that the configuration in hh_autoload.json and .hhvmconfig.hdf match.
105
+
93
106
How It Works
94
107
============
95
108
96
109
- A parser (FactParse) provides a list of all Hack definitions in the specified locations
97
110
- This is used to generate something similar to a classmap, except including other kinds of definitions
98
111
- The map is provided to HHVM with [`HH\autoload_set_paths()`](https://docs.hhvm.com/hack/reference/function/HH.autoload_set_paths/)
112
+
- If a native autoloader is registered, this autoloader will intentionally not register itself. So calling `Facebook\AutoloadMap\initialize()` in repo auth mode or when the facts based autoloader is registered is a noop.
0 commit comments