PHPackages                             rafrsr/licenser - 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. rafrsr/licenser

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

rafrsr/licenser
===============

Automates the prepending of a license header doc block to your source files.

v1.0.4(9y ago)319MITPHPPHP &gt;=5.6

Since Jul 22Pushed 9y ago2 watchersCompare

[ Source](https://github.com/rafrsr/licenser)[ Packagist](https://packagist.org/packages/rafrsr/licenser)[ Docs](http://rafrsr.github.io/licenser/)[ RSS](/packages/rafrsr-licenser/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

Licenser
========

[](#licenser)

[![Build Status](https://camo.githubusercontent.com/95d3ece4ff1d9daf94d4341912c119454db0576944840e67a1f5b948c92dc807/68747470733a2f2f7472617669732d63692e6f72672f7261667273722f6c6963656e7365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rafrsr/licenser)[![Coverage Status](https://camo.githubusercontent.com/820ee30db3e56b2475684181322514841c29d3863ec9ffbb0e5b38479c41f713/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7261667273722f6c6963656e7365722f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/rafrsr/licenser?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/389a87837c9c0fcc88925e189512be8b0d154267d374be2be2f1866b04f8634c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261667273722f6c6963656e7365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rafrsr/licenser/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/656d5c7bcf66bd95277da0c5be67ed4ca926ffc47e1d3725e923314f366c3fc7/68747470733a2f2f706f7365722e707567782e6f72672f7261667273722f6c6963656e7365722f76657273696f6e)](https://packagist.org/packages/rafrsr/licenser)[![Latest Unstable Version](https://camo.githubusercontent.com/ce1cf1827f2227404b6ed3d216609a54bb18bae8028d7ff9a4904ef233774ee4/68747470733a2f2f706f7365722e707567782e6f72672f7261667273722f6c6963656e7365722f762f756e737461626c65)](//packagist.org/packages/rafrsr/licenser)[![Total Downloads](https://camo.githubusercontent.com/877b3cb4f2339190dc337cbc87952b883a2eb70f4e491fadb1e22ca0daa91ac7/68747470733a2f2f706f7365722e707567782e6f72672f7261667273722f6c6963656e7365722f646f776e6c6f616473)](https://packagist.org/packages/rafrsr/licenser)[![License](https://camo.githubusercontent.com/b072844f0e10db4c4c80d36590a36a30b0c6d461adb5cdcecb6537e2f7e46ebc/68747470733a2f2f706f7365722e707567782e6f72672f7261667273722f6c6963656e7365722f6c6963656e7365)](https://packagist.org/packages/rafrsr/licenser)

[![SensioLabsInsight](https://camo.githubusercontent.com/569c5e059d59ac728999ed110c3d7d691b8d1c3a226bac12ff85466953006c43/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65336637316532372d336630302d346337312d383965612d3332336637363532613734652f6269672e706e67)](https://insight.sensiolabs.com/projects/e3f71e27-3f00-4c71-89ea-323f7652a74e)

Automates the prepending of a license header doc block to your directory(ies) of source files.

- Accept a directory of source files or a path to a single source file to process
- Accept a file path containing your custom license doc block
- Can check your source files for the correct license information
- Support global install with `.yml` Configuration per project

Install
-------

[](#install)

You can grab a copy of `rafrsr/licenser` in either of the following ways.

### As a phar

[](#as-a-phar)

You can simply download a pre-compiled and ready-to-use version as a Phar to any directory. Simply download the latest `licenser.phar` file from our releases page:

[Latest release](https://github.com/rafrsr/licenser/releases/latest)

Verify everything works by running this:

```
php licenser.phar --version

```

Now can copy this tool when you need to use in any project

#### Updating phar

[](#updating-phar)

There's no separate update procedure, simply download the latest release again and overwrite the existing phar.

### Installation using Composer

[](#installation-using-composer)

Alternatively, you can also install **Licenser** as part of your development dependencies. You will likely want to use the require-dev section to exclude rafrsr/licenser in your production environment.

1. [Install composer](https://getcomposer.org/download/)
2. Execute: `require rafrsr/licenser --dev`
3. Run `./vendor/bin/licenser --version`

#### Updating dependency

[](#updating-dependency)

Just run `composer update rafrsr/licenser` to update to the latest release.

Usage
-----

[](#usage)

### Using a built-in license type

[](#using-a-built-in-license-type)

Licenser supports the following built-in licenses and headers:

- The Apache 2.0 license (referred to as `apache2.0` in **Licenser**)
- The MIT license (referred to as `mit` in **Licenser**)
- Default - Is not a license, is a common header to add to any project (referred to as `default` in **Licenser**)
- Symfony - Is a header commonly used in symfony components and bundles (referred to as `symfony` in **Licenser**)

To use one of these built-in licenses you just replace the path to your custom licenses file with the name of the built-in license instead. For example if you wanted to use the MIT license then you would run something like:

```
./bin/licenser run /path/to/files mit
```

The `default` header is used when run something like this:

```
./bin/licenser run /path/to/files
```

### Value replacement in built-in licenses

[](#value-replacement-in-built-in-licenses)

When using a built-in license the **Licenser** will replace special placeholders with custom values. Placeholder can vary according to license:

licenseplaceholdersdefaultauthor, package, versionmitauthorapache2.0authorsymfonyauthor, package##### e.g.

[](#eg)

```
./bin/licenser /path/to/files -p author:"Author Name " -p version:1.0
./bin/licenser /path/to/files mit -p author:"Author Name "
./bin/licenser /path/to/files apache2.0 -p author:"Author Name "
./bin/licenser /path/to/files symfony -p author:"Author Name " -p package:MyPHPPackage
```

### Creating your custom license template

[](#creating-your-custom-license-template)

License template can be created using a simple text file. License templates are processed using [Twig](http://twig.sensiolabs.org/), then can use any twig feature.

##### e.g.

[](#eg-1)

```
This file is part of the {{ package }}.

(c) {{ 'now'|date('Y') }}

@version {{ version }}

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

```

To process this license:

```
./bin/licenser /path/to/files /path/to/license -p package:MyPHPPackage -p version:1.0
```

> NOTE: parameters passed in the commandline can be used in the license template

### Checking files for correct license

[](#checking-files-for-correct-license)

**Licenser** also allows you to check your source files for correct license information. It will warn you if there are any source files that do not have a license header that matches the options you provide.

```
./bin/licenser /path/to/files mit --only-check
```

By default the check only return if all files are ok or not, bu can use verbosity levels to view more details.

```
./bin/licenser /path/to/files mit --only-check -vv
```

> Verbosity levels are available in all actions

### Dry-run

[](#dry-run)

Licenser also allows you to verify all available changes using a `dry-run`. Is a mix between normal process and `only-check`, verify all changes to see affected files before adding headers.

```
./bin/licenser /path/to/files mit --dry-run -vv
```

### YML configuration per project

[](#yml-configuration-per-project)

Licenser support create a `.yml` file for each project with custom settings. Is helpful to use a global installation of **Licenser** and same commandline for all projects.

Create a yml file under your project directory

#### e.g:

[](#eg-2)

```
#.licenser.yml
finder:
  in:
    - src
    - tests
license: default
parameters:
   author: Rafael SR
   package: Licenser
   version: '@Rafrsr\Licenser\Licenser::VERSION'
```

and execute

```
./bin/licenser --config=.licenser.yml
```

or

```
./bin/licenser MyClass.php --config=.licenser.yml
```

In the second example the `finder` is overwritten and apply the given config to given file or directory.

### YML Settings

[](#yml-settings)

- **finder:** used to create instance of Finder to locate source files
    - **in:** *\[array, string\]* relative dir to find files
    - **name:** *\[array, string\]* name of files to process (default: \*.php)
    - **exclude:** *\[array, string\]* Exclude directories
    - **path**: *\[array, string\]* Restrict files and directories by path
    - **notPath**: *\[array, string\]* Exclude files and directories by path
    - **size**: *\[array, string\]* Restrict by a size, e.g. \['&gt;= 1K','&lt;= 2K'\]
    - **date**: *\[array, string\]* Restrict files by last modified dates

> To see all available options and usage refer to: [Finder](http://symfony.com/doc/current/components/finder.html). All options given in this configuration are used to build a instance of Finder.

- **finders:** *\[array\]* array of finders to use multiple finders for different file types or sources
- **license:** *\[string\]* name of build-in license to use or relative filename
- **license\_content:** *\[string\]* alternative to create your license inline without reference to any file
- **parameters:** *\[array\]* array of parameters to pass to template

> NOTE: can reference to a constant in parameters using `@` before the name of the constant, e.g: `@Rafrsr\Licenser\Licenser::VERSION`

### Usage in others files types like javascript source files

[](#usage-in-others-files-types-like-javascript-source-files)

By default licenser only find for files named `*.php` can change this behavior in the finder configuration.

#### e.g:

[](#eg-3)

```
#.licenser.yml
finder:
  in:
    - src
  name:
    - *.php
    - *.js
```

### Muti-finder for each type of file

[](#muti-finder-for-each-type-of-file)

**Licenser** support configure more than one finder in order to find different files types on different folders, use `finders` instead of `finder` to enable this.

#### e.g:

[](#eg-4)

```
#.licenser.yml
finders:
  php:
    in:
      - src
  javascript:
     in:
      - web/js/
     name: '*.js'
     notPath:
      - jquery
      - bootstrap
```

The above example find for default`*.php` files in *src* folder, and `*.js` files in *web/js* folder ignoring *jquery* and *bootstrap* folders in this location

### Caution

[](#caution)

It is recommended that you have your source files under version control when running the tool as it is still experimental.

Copyright
---------

[](#copyright)

This project is licensed under the [MIT license](LICENSE).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

3624d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a2b6fe4cdd0f7970b78769f972884c46759925b8bfe9814e47a2799b6439de7?d=identicon)[rafrsr](/maintainers/rafrsr)

---

Top Contributors

[![rafrsr](https://avatars.githubusercontent.com/u/7094012?v=4)](https://github.com/rafrsr "rafrsr (74 commits)")

---

Tags

licensedocblockheaderlicenserdocheader

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rafrsr-licenser/health.svg)

```
[![Health](https://phpackages.com/badges/rafrsr-licenser/health.svg)](https://phpackages.com/packages/rafrsr-licenser)
```

###  Alternatives

[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k45](/packages/friendsoftypo3-content-blocks)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19664.8M1.6k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M396](/packages/drupal-core-recommended)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
