https://github.com/hhpack/package
Package utility library for vendor
https://github.com/hhpack/package
hacklang hhvm loader selector stream
Last synced: about 2 months ago
JSON representation
Package utility library for vendor
- Host: GitHub
- URL: https://github.com/hhpack/package
- Owner: hhpack
- License: mit
- Created: 2015-10-04T07:02:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-08-20T03:12:23.000Z (over 6 years ago)
- Last Synced: 2025-10-07T01:58:17.428Z (6 months ago)
- Topics: hacklang, hhvm, loader, selector, stream
- Language: Shell
- Homepage:
- Size: 150 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
package
==============================
Package utility library for vendor.
Easily and quickly, and you can find a class or interface.
[](https://packagist.org/packages/hhpack/package)
[](https://circleci.com/gh/hhpack/package/tree/master)
[](https://www.versioneye.com/user/projects/5610e428a193340015000009)
[](https://packagist.org/packages/hhpack/package)
Basic usage
------------------------------
Find the source file from the package.
```hack
use HHPack\Package\VendorPackage;
$sources = VendorPackage::fromItems([
Pair { 'package\\examples\\classes\\', realpath(__DIR__ . '/src') }
])->sources();
foreach ($sources as $source) {
var_dump($source->name()); // /path/to/example.hh
var_dump($source->directory()); // /path/to
}
```
Selection of elements
------------------------------
You can select the elements in the following function.
* HHPack\Package\implementsInterface
* HHPack\Package\subclassOf
* HHPack\Package\classes
* HHPack\Package\abstractClasses
* HHPack\Package\traits
* HHPack\Package\interfaces
* HHPack\Package\instantiable
* HHPack\Package\startsWith
* HHPack\Package\endsWith
In the following we are looking for a interface and traits.
```hack
use HHPack\Package as package;
use HHPack\Package\VendorPackage;
$interfaces = VendorPackage::fromItems([
Pair { 'Package\\Examples\\Classes\\', realpath(__DIR__ . '/src') }
])->classes(package\interfaces());
foreach ($interfaces as $interface) {
var_dump($interface->name()); // interface
}
$traits = VendorPackage::fromItems([
Pair { 'Package\\Examples\\Classes\\', realpath(__DIR__ . '/src') }
])->classes(package\traits());
foreach ($traits as $trait) {
var_dump($trait->getName()); // trait
}
```
Instantiation of class
------------------------------
Get an instance from the source files
```hack
use HHPack\Package\VendorPackage;
$instances = VendorPackage::fromItems([
Pair { 'Package\\Examples\\Classes\\', realpath(__DIR__ . '/src') }
])->classes()->map(($class) ==> $class->instantiate());
foreach ($instances as $instance) {
var_dump($instance);
}
```
Pipeline of stream
------------------------------
You can build a pipeline.
You can achieve when implement the interface **Middleware** and **Stream**.
Please look at the **example/pipeline.hh** for details.
```hack
use HHPack\Package\VendorPackage;
use HHPack\Package\Examples\Classes\FileStatTransformer;
use HHPack\Package\Examples\Classes\FileStatOutput;
$package = VendorPackage::fromItems([
Pair { 'Package\\Examples\\Classes\\', realpath(__DIR__ . '/src') }
]);
$package->sources()
->pipeTo(new FileStatTransformer())
->pipeTo(new FileStatOutput());
```
Run the test
------------------------------
composer install
composer test