View on GitHub

Yii2-phar

Phar builder based on Yii2

Download this project as a .zip file Download this project as a tar.gz file

yii2-phar

Build Status Latest Stable Version Dependency Status Scrutinizer Quality Score Code Coverage Total Downloads License

This module provides console interface for building PHAR archives for Yii2 applications.

Installation

The preferred way to install this extension is through composer.

php composer.phar require --prefer-dist index0h/yii2-phar "*"

or add line to require section of composer.json

"index0h/yii2-phar": "*"

Standalone usage

php composer.phar global require index0h/yii2-phar:*
yii2-phar
# Or with external configuration
yii2-phar phar/build myConfiguration.php

Usage

Once module is installed, modify your application configuration as follows:

return [
    'modules' => [
        'phar' => 'index0h\\phar\\Module',
        ...
    ],
    ...
];

You can access to yii2-phar module though console:

yii phar/build

Options

Components

Components - php classes for files modifications in phar archives. For example: remove all whitespaces from php code. Components configuration is just like yii Application components, for example:

return [
    'modules' => [
        'phar' => [
            'class' => 'index0h\\phar\\Module',
            'components' => [
                'fixer' => [
                    'class' => 'index0h\\phar\\components\\php\\Fixer',
                    'match' => '/.*\.php/'
                ]
            ]
        ]
        ...
    ],
    ...
];

Available components

Fixer

Fixer changes realpath functions in files that doesn't work in phar.

Minimize

Removes all whitespaces form php files by php_strip_whitespace.

Writing own component

Simply create class that extends index0h\phar\base\Component and implement processFile method.

For example minimize component:

namespace index0h\phar\components\php;

use index0h\phar\base\Component;
use index0h\phar\base\FileEvent;

/**
 * Removes whitespace and comments from php files.
 */
class Minimize extends Component
{
    /**
     * For all php files without suffix Controller (because help command parses comments).
     */
    protected $match = ['/(?<!Controller)\.php/us'];

    /**
     * Modification of file.
     *
     * @param FileEvent $event Event with file information.
     */
    public function processFile(FileEvent $event)
    {
        file_put_contents($event->realPath, php_strip_whitespace($event->realPath));
    }
}

FileEvent structure

Testing

Run tests from IDE (example for PhpStorm)

Run tests from IDE (example for PhpStorm) inside phar archive

Run tests from console

make test-all