grinder_php_minify 2.0.0

  • Installing
  • Versions
  • 52


Runtime Release License Coverage Build

Grinder plug-in minifying PHP source code by removing comments and whitespace.

Getting started

If you haven't used Grinder before, be sure to check out the related documentation, as it explains how to create a grind.dart file and to define project tasks. Once you're familiar with that process, you may install this plug-in.

Installing via Pub

1. Depend on it

Add this to your package's pubspec.yaml file:

  grinder_php_minify: *

2. Install it

Install this package and its dependencies from a command prompt:

$ pub get

Once the plug-in has been installed, it may be enabled inside your grind.dart file:

import 'package:grinder_php_minify/grinder_php_minify.dart' as php_minify;


The plug-in provides a set of functions that take a list of PHP scripts as input, and remove the comments and whitespace in this file by applying the php_strip_whitespace() function on their contents.

Whenever a function expects a directory or file parameter, you can specify it as an instance of FileSystemEntity or as a string (e.g. its path).

Future compressDirectory(Directory source, Directory destination, {String pattern = '*.php', bool recurse: true})

Minifies the PHP files of a given source directory and saves the resulting output to a destination directory:

import 'dart:async';
import 'package:grinder/grinder.dart';
import 'package:grinder_php_minify/grinder_php_minify.dart' as php_minify;

@Task('Compress the PHP scripts from a given directory')
Future compressPhp() => php_minify.compressDirectory('path/to/src', 'path/to/out');

When the function processes a directory, a filter is applied on the names of the processed files to determine whether they are PHP scripts. A filename pattern is used to match the eligible PHP scripts, by default it's set to "*.php". You can change use the pattern option to select a different set of PHP scripts:

php_minify.compressDirectory('path/to/src', 'path/to/out', pattern: '*.inc.php7');

The source directories are scanned recursively. You can force the function to only process the files located at the root of the source directory by setting the recurse option to false:

php_minify.compressDirectory('path/to/src', 'path/to/out', recurse: false);

Future compressFile(File source, File destination)

Minifies a single PHP source file and saves the resulting output to a given destination file:

import 'dart:async';
import 'package:grinder/grinder.dart';
import 'package:grinder_php_minify/grinder_php_minify.dart' as php_minify;

@Task('Compress a given PHP script')
Future compressPhp() => php_minify.compressFile('path/to/src.php', 'path/to/out.php');

Future compressFiles(Iterable sources, Directory destination, {String base})

Minifies the given set of PHP files and saves the resulting output to a destination directory:

import 'dart:async';
import 'package:grinder/grinder.dart';
import 'package:grinder_php_minify/grinder_php_minify.dart' as php_minify;

@Task('Compress a given set of PHP scripts')
Future compressPhp() {
  var sourceDir = getDir('path/to/src');
  var fileSet = new FileSet.fromDirectory(sourceDir, pattern: '*.php', recurse: true);
  return php_minify.compressFiles(fileSet.files, 'path/to/out', base: sourceDir.path);

The base parameter is used to customize the resulting file tree in the destination directory. It is treated as a base path that is stripped from the computed path of the destination files:

// Will create the file "out/src/script.php".
php_minify.compressFiles(['src/script.php'], 'out');

// Will create the file "out/script.php": the "src/" component was removed.
php_minify.compressFiles(['src/script.php'], 'out', base: 'src');


All functions also support the following optional named parameters:

String binary = "php"

The functions rely on the availability of the PHP executable on the target system. By default, the functions will use the php binary found on the system path.

If a function cannot find the default php binary, or if you want to use a different one, you can provide the path to the php executable by using the binary option:

php_minify.compressFile('path/to/src', 'path/to/out', binary: r'C:\Program Files\PHP\php.exe');

TransformMode mode =

The functions can work in two manners, which can be selected using the mode option:

  • the safe mode: as its name implies, this mode is very reliable. But it is also very slow as it spawns a new PHP process for every file to be processed. This is the default mode.
  • the fast mode: as its name implies, this mode is very fast, but it is not very reliable. It spawns a PHP web server that processes the input files, but on some systems this fails. This mode requires a PHP runtime version 7.0 or later.
php_minify.compressFile('path/to/src', 'path/to/out', mode: 'fast');

The transform mode can be specified as a value of the TransformMode enumeration or as a string (e.g. the name of the enumerated value).

bool silent = false

By default, the functions print to the standard output the paths of the minified scripts. You can disable this output by setting the silent option to true.

php_minify.compressFile('path/to/src', 'path/to/out', silent: true);

See also


Grinder-PHP-Minify is distributed under the MIT License.


This file contains highlights of what changes on each version of the Grinder-PHP-Minify package.

Version 2.0.0

  • Breaking change: changed the signature of the Minifier and Transformer constructors.
  • Breaking change: renamed the Minifier.processDirectory() method to compressDirectory.
  • Breaking change: renamed the Minifier.processFile() method to compressFile.
  • Breaking change: splitted the phpMinify() function into the compressDirectory(), compressFile() and compressFiles() functions.
  • Added the Minifier.compressFiles() method.
  • Added the TransformMode enumeration.

Version 1.0.1

  • Fixed a bug with relative file paths.

Version 1.0.0

  • Breaking change: changed the signature of most class constructors.
  • Breaking change: merged the compress() and compressFile() functions into the phpMinify() function.
  • Breaking change: raised the required Dart version.
  • Breaking change: removed the binary and mode properties from the Minifier class.
  • Breaking change: the Minifier.transformer property is now final.
  • Added a factory constructor to the Transformer class.
  • Added new unit tests.
  • Changed licensing for the MIT License.
  • Updated the package dependencies.

Version 0.2.0

  • Breaking change: renamed the main script to grinder_php_minify.dart.

Version 0.1.0

  • Initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  grinder_php_minify: "^2.0.0"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:grinder_php_minify/grinder_php_minify.dart';
Version Uploaded Documentation Archive
2.0.0 Nov 6, 2017 Go to the documentation of grinder_php_minify 2.0.0 Download grinder_php_minify 2.0.0 archive
1.0.1 Oct 9, 2017 Go to the documentation of grinder_php_minify 1.0.1 Download grinder_php_minify 1.0.1 archive
1.0.0 Oct 5, 2017 Go to the documentation of grinder_php_minify 1.0.0 Download grinder_php_minify 1.0.0 archive
0.2.0 May 24, 2017 Go to the documentation of grinder_php_minify 0.2.0 Download grinder_php_minify 0.2.0 archive
0.1.0 May 24, 2017 Go to the documentation of grinder_php_minify 0.1.0 Download grinder_php_minify 0.1.0 archive


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
8 / 100
Code health derived from static analysis. [more]
95 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, other

Primary library: package:grinder_php_minify/grinder_php_minify.dart with components: io, isolate.


  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 7 hints.

    Run dartfmt to format lib/src/fast_transformer.dart.

    Run dartfmt to format lib/src/functions.dart.

    Similar analysis of the following files failed:

    • lib/src/minifier.dart (hint)
    • lib/src/safe_transformer.dart (hint)
    • lib/src/transform_mode.dart (hint)
    • lib/src/transformer.dart (hint)
  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use grinder_php_minify.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.0
grinder ^0.8.0 0.8.2
http ^0.11.3 0.11.3+16
path ^1.4.2 1.6.1
where ^2.2.0 2.2.0 4.0.0
Transitive dependencies
args 1.4.3
async 2.0.7
charcode 1.1.1
cli_util 0.1.3
collection 1.14.10
glob 1.1.5
http_parser 3.1.2
meta 1.1.5
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
coverage ^0.9.3
coveralls ^2.0.1
test ^0.12.27