PHP code example of reisraff / phulp
1. Go to this page and download the library: Download reisraff/phulp library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
reisraff / phulp example snippets
use Phulp\Output as out;
// Define the default task
$phulp->task('default', function ($phulp) {
out::outln(out::colorize('Arguments:', 'green'));
out::outln(print_r($phulp->getArguments(), true));
$phulp->start(['clean', 'iterate_src_folder', 'sync_command', 'async_command']);
if ($phulp->getArgument('repeat-clean', false)) {
out::outln(out::colorize('Repeating "clean"', 'green'));
$phulp->start(['clean']);
}
});
// Define the clean task
$phulp->task('clean', function ($phulp) {
if (! file_exists('dist')) {
mkdir('dist');
}
$phulp->src(['dist/*'])
->pipe($phulp->clean());
});
// Define the iterate_src_folder task
$phulp->task('iterate_src_folder', function ($phulp) {
// Define the source folder
$phulp->src(['src/*php'])
->pipe($phulp->iterate(function ($file) {
out::outln(sprintf(
'%s %s',
out::colorize('Iterated ->', 'green'),
out::colorize($file->getFullPath() . DIRECTORY_SEPARATOR . $file->getName(), 'blue')
));
}))
->pipe($phulp->dest('dist/'));
});
// Define the sync_command task
$phulp->task('sync_command', function ($phulp) {
$command = $phulp->exec(
'sleep 1 && echo $MSG',
[
'env' => [
'MSG' => 'Sync-command'
],
'cwd' => '/tmp',
'sync' => true, // defines sync,
'quiet' => true,
'onStdOut' => function ($line) { out::outln($line); },
'onStdErr' => function ($line) { },
'onFinish' => function ($exitCode, $stdOut, $stdErr) { },
]
);
$exitCode = $command->getExitCode();
$stdout = $command->getStdout();
$stderr = $command->getStderr();
out::outln('done');
});
// Define the async_command task
$phulp->task('async_command', function ($phulp) {
$command = $phulp->exec(
'sleep 1 && echo $MSG',
[
'env' => [
'MSG' => 'Async-command'
],
'cwd' => '/tmp',
'sync' => false, // defines async,
'quiet' => false,
'onStdOut' => function ($line) { },
'onStdErr' => function ($line) { },
'onFinish' => function ($exitCode, $stdOut, $stdErr) { },
]
);
out::outln('done');
});
// Define the watch task
$phulp->task('watch', function ($phulp) {
// Phulp will watch 'src' folder
$phulp->watch(
$phulp->src(['src/*php']),
function ($phulp, $distFile) {
out::outln(sprintf(
'%s %s',
out::colorize('File Changed ->', 'green'),
out::colorize($distFile->getFullPath() . DIRECTORY_SEPARATOR . $distFile->getName(), 'blue')
));
$phulp->start(['default']);
}
);
});