2017 © Pedro Peláez
 

composer-plugin hhvm-autoload

image

fredemmott/hhvm-autoload

  • Friday, January 27, 2017
  • by fredemmott
  • Repository
  • 3 Watchers
  • 14 Stars
  • 390 Installations
  • Hack
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

HHVM-Autoload Build Status

A Composer plugin for autoloading classes, enums, functions, typedefs, and constants on HHVM., (*1)

FAQ

Do I need to use Hack?

No, PHP is fine - but HHVM is required because:, (*2)

  • 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 :), (*3)

Why does this project use Composer's autoloader?

It can't depend on itself :), (*4)

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:, (*5)

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., (*6)

For any other issue, please file an issue against this project., (*7)

Usage

  1. Add an hh_autoload.json file (see section below) and optionally remove your configuration from composer.json
  2. composer require facebook/hhvm-autoload
  3. Replace any references to vendor/autoload.php with vendor/hh_autoload.php
  4. If you are using PHPUnit, you will need to add vendor/hh_autoload.php to your bootstrap.php, or to phpunit.xml as a bootstrap file if you don't already have one. This is because PHPUnit automatically loads vendor/autoload.php, but is not aware of vendor/hh_autoload.php
  5. 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:, (*8)

{
  "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., (*9)

The following settings are optional:, (*10)

  • "extraFiles": ["file1.php"] - files that should not be autoloaded, but should be require()ed by vendor/hh_autoload.php. This should be needed much less frequently than under Composer
  • "includeVendor": false - do not include vendor/ definitions in vendor/hh_autoload.php
  • "autoloadFilesBehavior": "scan"|"exec" - whether autoload files from vendor should be scanned for definitions, or executed by vendor/hh_autoload.php - scan is the default, and generally favorable, but exec is needed if you have dependencies that need code to be executed on startup. scan is sufficient if your dependencies just use files 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, (*11)

Contributing

We welcome GitHub issues and pull requests - please see CONTRIBUTING.md for details., (*12)

License

hhvm-autoload is BSD-licensed. We also provide an additional patent grant., (*13)

The Versions

27/01 2017

dev-master

9999999-dev

  Sources   Download

The Requires

 

The Development Requires

27/01 2017

v1.2.0

1.2.0.0

  Sources   Download

The Requires

 

The Development Requires

23/01 2017

v1.1.0

1.1.0.0

  Sources   Download

The Requires

 

The Development Requires

30/09 2016

v1.0.0

1.0.0.0

  Sources   Download

The Requires

 

The Development Requires

18/12 2015

v0.1

0.1.0.0

  Sources   Download

The Requires