2017 © Pedro Peláez
 

yii2-extension yii2-phar

Phar builder based on Yii2

image

index0h/yii2-phar

Phar builder based on Yii2

  • Sunday, November 2, 2014
  • by index0h
  • Repository
  • 4 Watchers
  • 5 Stars
  • 46 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

yii2-phar

Build Status Latest Stable Version Dependency Status Scrutinizer Quality Score Code Coverage Total Downloads License, (*1)

This module provides console interface for building PHAR archives for Yii2 applications., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

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

or add line to require section of composer.json, (*4)

"index0h/yii2-phar": "*"

Standalone usage

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

Usage

Once module is installed, modify your application configuration as follows:, (*5)

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

You can access to yii2-phar module though console:, (*6)

yii phar/build

Options

  • compress - Array of compress algorithms, \Phar::GZ, \Phar::BZ2. Creates compressed files of main phar.
  • files - List of files to compile.
  • folders - List of directories to compile.
  • ignore - List of regexp patterns that must be ignored on build. That means if any file will match to any of patterns - it will be ignored.
  • path - Path to phar file save.
  • pharName - Phar name.
  • signature - One of Phar signature algorithms. If it is Phar::OPENSSL - openSSLPrivateKeyAlias is required.
  • openSSLPrivateKeyAlias - Alias to OpenSSL certificate, should be on \Phar::OPENSSL signature set.
  • stub - Alias to stub file, if false - will not be set.

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:, (*7)

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., (*8)

  • match - List of regexp for files that must be modified.
  • replace - Array of regexp for [from => to] for modifications in files.

Minimize

Removes all whitespaces form php files by php_strip_whitespace., (*9)

  • match - List of regexp for files that must be modified.

Writing own component

Simply create class that extends index0h\phar\base\Component and implement processFile method., (*10)

For example minimize component:, (*11)

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

  • realPath - path to temporary file.
  • relativePath - path in phar file.

Testing

Run tests from IDE (example for PhpStorm)

  • Select Run/Debug Configuration -> Edit Configurations
  • Select Add New Configuration -> PHP Script
  • Type:
    • File: /path/to/yii2-phar/.test.php
    • Arguments run: run --coverage --html
  • OK

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

  • Select Run/Debug Configuration -> Edit Configurations
  • Select Add New Configuration -> PHP Script
  • Type:
    • File: /path/to/yii2-phar/.test.phar.php
    • Arguments run: run --no-exit
  • OK

Run tests from console

make test-all

The Versions

02/11 2014

dev-master

9999999-dev https://github.com/index0h/yii2-phar

Phar builder based on Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

phar module yii build yii-module yii2-phar

01/03 2014

0.0.3

0.0.3.0 https://github.com/index0h/yii2-phar

Phar builder based on Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

phar module yii build yii-module yii2-phar

02/02 2014

0.0.2

0.0.2.0 https://github.com/index0h/yii-phar

Phar builder based on Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

phar module yii build yii-module yii-phar

02/02 2014

dev-develop

dev-develop https://github.com/index0h/yii-phar

Phar builder based on Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

phar module yii build yii-module yii-phar

28/01 2014