PHPackages                             zero-to-prod/package-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zero-to-prod/package-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zero-to-prod/package-helper
===========================

Helpers for a Composer Package

v1.1.4(1y ago)220.8k↓11.3%20MITPHPPHP &gt;=7.1CI passing

Since Jan 15Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/zero-to-prod/package-helper)[ Packagist](https://packagist.org/packages/zero-to-prod/package-helper)[ Docs](https://github.com/zero-to-prod/package-helper)[ Fund](https://github.com/sponsors/zero-to-prod)[ RSS](/packages/zero-to-prod-package-helper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (20)

Zerotoprod\\PackageHelper
=========================

[](#zerotoprodpackagehelper)

[![](art/logo.png)](art/logo.png)

[![Repo](https://camo.githubusercontent.com/9a90a3efeee26aed7d7f2feee9cd84566a26f9c362cc773b184d076210906e1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746875622d677261793f6c6f676f3d676974687562)](https://github.com/zero-to-prod/package-helper)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/2bb1e7ee1026d4bc84558702935142255cb7b51af6c5aa030444758ff1c309a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065722f746573742e796d6c3f6c6162656c3d74657374)](https://github.com/zero-to-prod/package-helper/actions)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/36a1175f8276ee4f804e4de3fb6d5dbacde16adda83f79b1e530c380a488856b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065722f6261636b77617264735f636f6d7061746962696c6974792e796d6c3f6c6162656c3d6261636b77617264735f636f6d7061746962696c697479)](https://github.com/zero-to-prod/package-helper/actions)[![Packagist Downloads](https://camo.githubusercontent.com/69f807db6c2c46d67ca4139ecbac58eb9eba46ea09d87b881158886b7bf60e2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065723f636f6c6f723d626c7565)](https://packagist.org/packages/zero-to-prod/package-helper/stats)[![php](https://camo.githubusercontent.com/e558fd84e41c6ad4a7d528df8cb9814c7df5c55977c80da882febc7d0a42c1f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065722e7376673f636f6c6f723d707572706c65)](https://packagist.org/packages/zero-to-prod/package-helper/stats)[![Packagist Version](https://camo.githubusercontent.com/af0a51ed8bcf383542fcf2a6c49ee893c065057d87dfb46081c556a766e8e4c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065723f636f6c6f723d663238643161)](https://packagist.org/packages/zero-to-prod/package-helper)[![License](https://camo.githubusercontent.com/0360f00a1c885d1892a09d7a5482cdf7b808c5b5bd73fd6127bdc1add5b2a408/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065723f636f6c6f723d70696e6b)](https://github.com/zero-to-prod/package-helper/blob/main/LICENSE.md)[![wakatime](https://camo.githubusercontent.com/9ccd3f8f5113ac3a91ccd054472f48940be658b917d24972afb658e1dbec11d4/68747470733a2f2f77616b6174696d652e636f6d2f62616467652f6769746875622f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065722e737667)](https://wakatime.com/badge/github/zero-to-prod/package-helper)[![Hits-of-Code](https://camo.githubusercontent.com/a3af91cfd8078da014d7b0062532c74a6ffba756df62a148be8902aab23d86cc/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f7a65726f2d746f2d70726f642f7061636b6167652d68656c7065723f6272616e63683d6d61696e)](https://hitsofcode.com/github/zero-to-prod/package-helper/view?branch=main)

Contents
--------

[](#contents)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Documentation Publishing](#documentation-publishing)
    - [Automatic Documentation Publishing](#automatic-documentation-publishing)
- [Usage](#usage)
- [Example](#example)
- [Local Development](./LOCAL_DEVELOPMENT.md)
- [Contributing](#contributing)

Introduction
------------

[](#introduction)

Helpers for a composer package.

Requirements
------------

[](#requirements)

- PHP 7.1 or higher.

Installation
------------

[](#installation)

Install `Zerotoprod\PackageHelper` via [Composer](https://getcomposer.org/):

```
composer require zero-to-prod/package-helper
```

This will add the package to your project’s dependencies and create an autoloader entry for it.

Documentation Publishing
------------------------

[](#documentation-publishing)

You can publish this README to your local documentation directory.

This can be useful for providing documentation for AI agents.

This can be done using the included script:

```
# Publish to default location (./docs/zero-to-prod/package-helper/)
vendor/bin/zero-to-prod-package-helper

# Publish to custom directory
vendor/bin/zero-to-prod-package-helper /path/to/your/docs
```

#### Automatic Documentation Publishing

[](#automatic-documentation-publishing)

You can automatically publish documentation by adding the following to your `composer.json`:

```
{
  "scripts": {
    "post-install-cmd": [
      "zero-to-prod-package-helper"
    ],
    "post-update-cmd": [
      "zero-to-prod-package-helper"
    ]
  }
}
```

Usage
-----

[](#usage)

Publish files in your package directory (recursively) while rewriting namespaces.

```
use Zerotoprod\PackageHelper\PackageHelper;

PackageHelper::publish(
    $from,
    $to,
    PackageHelper::determineNamespace($psr_4, $to),
    static function (string $from, string $to) {
        echo "Copied: $from to $to" . PHP_EOL;
    }
);
```

Copy a single file and get the destination path:

```
use Zerotoprod\PackageHelper\PackageHelper;

$copied = PackageHelper::copy(__DIR__.'/stubs/example.txt');
echo $copied; // e.g., getcwd().'/example.txt'

// Or copy into a specific directory and observe the callback
$copied = PackageHelper::copy(
    __DIR__.'/stubs/example.txt',
    getcwd().'/output',
    static function (string $from, string $to) {
        echo "Copied $from -> $to" . PHP_EOL;
    }
);
```

Example
-------

[](#example)

Integrate this into a composer package.

Update `composer.json`:

```
{
  "bin": [
    "bin/package-file"
  ]
}
```

Create a new file: `bin/package-file`

```
#!/usr/bin/env php
