GithubHelp home page GithubHelp logo

simonwelsh / hhvm-autoload Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hhvm/hhvm-autoload

0.0 1.0 0.0 174 KB

Autoload classes, functions, enums, constants, and typedefs on HHVM

License: Other

Shell 1.11% Hack 94.20% PHP 4.70%

hhvm-autoload's Introduction

HHVM-Autoload Build Status

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 :)

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 vendor/bin/hh-autoload, 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 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.
  • "parser": "ext-factparse"|"definition-finder" - how to parse files. FactParse is an HHVM extension in 3.18 and above, while DefinitionFinder is a library supporting older versions of HHVM.
  • "devRoot": [ "path/", ...] - additional roots to only include in dev mode, not when installed as a dependency.

How It Works

  • A parser (FactParse or DefinitionFinder) 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.

hhvm-autoload's People

Contributors

fredemmott avatar grahamcampbell avatar groovycarrot avatar hrmsimon avatar jesseschalken avatar simonwelsh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.