Skip to content

Maslosoft/Hedron

Repository files navigation

PHP source code class header applier

Latest Stable Version License

Quick Install

composer require maslosoft/hedron

Documentation

Full Hedron Documentation

Keeping class headers consitent

When developing projects, we ofter require that file containing PHP class should have some predefined comment header. This might include package information, licensing, homepage address etc.

Apply all at once

This tools provides facility to modify class headers in entire project in a safe way - using PHP Tokenizer, so that it will only modify file if it's 100% safe to change it.

Hedron helps you make your class headers up to date and consistent. It will apply predefined header to all files containing namespaced class definitions.

Instalation

composer require maslosoft/hedron --dev

Usage

Preview list of files to apply headers

vendor/bin/hedron preview

Display rendered template

vendor/bin/hedron show

Apply header to all class files.

Backup/commit your project before continue. This will write headers to files.

vendor/bin/hedron commit

Configuration

Configuration can be provided in yaml file .hedron.yml in root of your project. Hedron also uses composer.json to make your config easier, or even unnessesary.

Here is how config might look like with example values (see .hedron.example.yml):

# All paths are realtive to your project root
# Root path or paths with sources. If blank will use composer.autoload paths.
sources: ""
# Path to template file, if blank will use vendor/maslosoft/hedron/templates/default.html (no it's not html)
template: ""
# Filter configuration, by default empty. Below is some example filter.
filter:
	whitelist:
		include:
			- app/*
		exclude:
			- app/cache/*
	blacklist:
		include:
			- app/controllers/*
		exclude:
			- app/cache/CacheProvider.php
# Reserved 
# This contains composer.json as array
composer: ""
tmp: ""

All of this configuration is available in template.

Template

Template uses handlebars as templating engine. It contains all data from .hedron.yml and composer.json.

Here is example, default template:

This software package is licensed under {{composer.license}} license.

@package {{composer.name}}
@licence {{composer.license}}
{{#each composer.authors}}
@copyright Copyright (c) {{name}} <{{email}}>
{{/each}}
{{#if composer.homepage}}@link {{composer.homepage}}{{/if}}

And after rendering it looks like that:

/**
 * This software package is licensed under New BSD license.
 *
 * @package maslosoft/hedron
 * @licence New BSD
 *
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
 *
 * @link http://maslosoft.com/hedron/
 */

Replacing

This script modifies source files en masse. For safety and robustness it uses native php tokenizer and replaces everything before namespace token. Only that. If there is no namespace declaration file will not be modified.

Resources

About

Header applier for php projects

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE-AGPL.mkd
Unknown
LICENSE-PROPRIETARY.mkd

Stars

Watchers

Forks

Packages

No packages published

Languages