Phpake is a make-like utility built for PHP.

Overview

Phpake

Phpake is a make-like utility built for PHP. It is pronounced fake because the second p is silent just like the second p in the word elephpant.

I've always found writing a Makefile quite challenging because the syntax is similar to the shell syntax, but quite different at the same time. When I'm working with Ruby, I use rake and it's awesome because it uses Ruby syntax. When I work with PHP, I often miss having a similar tool that is easy to install, easy to use, and allows full-fledged PHP syntax. Thus, Phpake was born.

I invite you to use it, and I hope you like it.

~ Jigarius

Installation

Phpake can easily be installed with composer, either within a project or globally on your system.

System-wide installation

To install Phpake globally on your system, use the following command:

composer global require jigarius/phpake

Now, to run phpake from anywhere on your system, Composer's vendor/bin directory needs to be included in the the PATH variable.

Project installation

To install Phpake in a particular project, run the following command:

composer require jigarius/phpake

You should then be able to run it with composer exec phpake.

Usage

To use Phpake, start by creating a Phpakefile to define some tasks. Each task is simply a PHP function. You can read more on creating a Phpakefile under the Phpakefile section.

Here are some common Phpake commands. You need to run them from a directory containing a Phpakefile.

  • phpake - shows a list of available commands.
  • phpake hello-world - runs the command defined by function hello_world().
  • phpake hello-human Bunny Wabbit - passes 2 parameters to the task.
  • phpake hello-group --help - shows help text for the task.

Phpakefile

A Phpakefile contains definitions of tasks that can be executed by Phpake. The following subheadings are about defining such tasks. A Phpake task definition is simply a PHP function (a task callback). Here's are some examples:

Simple tasks

Here's a simple task that takes no input and prints some output. Just make sure that the function name doesn't coincide with any existing functions.

/**
 * Say hello world.
 */
function hello_world() {
  echo 'Hello world' . PHP_EOL;
}

This task can then be executed as phpake hello-world. You can also organize functions with PHP namespaces.

Regular Parameters

If your task needs some input from the user, simply introduce one or more arguments in the function definition.

function hello_human($fname, $lname = NULL) {
  // Do something
}

Since $lname has a default value, it is treated as an optional argument.

Special parameters

Phpake is built with Symfony Console, which provides certain special parameters that can help you enrich your application even further. If your task has a parameter with one of these special names, it will behave specially. For more info on these objects, please refer to the Symfony Console documentation.

$input

A Symfony Console input object.

$output

A Symfony Console output object that makes it easier to generate well-formatted, colorful output.

function hello_joey($output) {
  $output->writeln('Hello 
   
    Joey
   !');
}

The text included in will appear in color.

$command

Name of the Symfony Console command that is being executed. It looks like the task function name with some minor differences.

  • For a function hello_world() the command becomes hello-world
  • If defined in a namespace, it becomes namespace:hello-world.

$rest

Often there are tasks that can accept an unlimited number of arguments. These can be handled with a $rest parameter. It must be defined as the last argument to your function.

function hello_group(string $you, string $rest) {
  // Do something.
}

If a default value of NULL is assigned to $rest, it becomes optional, otherwise, it requires one or more values.

Helpers

Say, you have a function that helps other tasks but it is not a command by itself. Such functions can be put in a Phpakefile too. However, so that Phpake doesn't confuse them for commands, the function name must begin with an underscore. For example a function named _foo() will not result in a command named phpake foo because the function name starts with an underscore.

Development

This project uses a Dockerized development environment. Run the project as you would any other docker-compose based project.

When developing for the first time,

  • Clone the repository with git clone
  • cd into the cloned repository
  • Build Docker images: docker compose build
  • Bring up the containers: docker compose up -d

After the initial setup, you can use the following commands:

  • docker compose start: Start the project's containers
  • docker compose exec main sh: Launch a shell inside the project's container
    • You'll spend most of your time here
    • The command phpake should be available
  • docker compose stop: Stops the project's containers when you're done

Links

Comments
  • Add PHP 7 compatibility?

    Add PHP 7 compatibility?

    Requirements

    There are several projects that still use PHP 7. More people might use the tool if PHP 7 is supported.

    This will mean maintaining 2 versions of the project: 7.x-x.x and 8.x-x.x.

    enhancement 
    opened by jigarius 2
  • Allow @usage annotations that start with

    Allow @usage annotations that start with "phpake"

    Requirements

    Say, a task has the @usage annotation set to @usage phpake hello-world. When running phpake hello-world --help, the usage is documented as:

    phpake phpake hello-world
    

    This should not happen.

    Proposed solution

    Remove initial phpake while registering the command with the app.

    enhancement good first issue 
    opened by jigarius 1
  • Support for interactive shell commands

    Support for interactive shell commands

    Requirements

    • I've used Makefile for doing things like docker compose exec main sh
    • This doesn't work with the Phpakefile 😞 Gotta find a way to make it work
    enhancement 
    opened by jigarius 1
  • Support for namespaced functions/commands

    Support for namespaced functions/commands

    Requirements

    • If a function is declared in a namespace, it should be detected and called back correctly.
      • e.g. foobar\hello_world() should create a command foobar:hello-world
    enhancement 
    opened by jigarius 1
  • Only auto-detect Phpakefile in CWD

    Only auto-detect Phpakefile in CWD

    Requirements

    Turns out that tools like make don't simply lookup a Makefile in parent directories. Need to investigate why they do so and remove that feature from Phpake if required. Alternatively, a confirmation message can be displayed:

    A Phpakefile was not found in the current working directory, but one was found in one of the parent directories. Would you like to use that one instead?

    Priority: High 
    opened by jigarius 1
  • Allow users to include Phpakefile

    Allow users to include Phpakefile

    Requirements

    If a user wants to organize their commands into different Phpakefile, they can include one Phpakefile from another like:

    require('path/to/Phpakefile1')
    require('path/to/Phpakefile2')
    require('path/to/Phpakefile3')
    

    This should work by default, but need to test it so that it can be called done.

    opened by jigarius 0
  • Support tasks with parameters

    Support tasks with parameters

    Requirements

    • [x] function task($fname, $lname = NULL)
      • [x] $lname is treated as an optional argument.
    • [x] An argument named $input gets the Symfony Console $input variable
    • [x] An argument named $output gets the Symfony Console $output variable
      • This makes it easier to print stuff in a fancy way.
    • [x] An argument named $command gets the name of the command.
      • e.g. function hello_world() becomes the command hello-world.
    enhancement 
    opened by jigarius 0
  • Support tasks with no parameters

    Support tasks with no parameters

    Requirements

    • [x] Callback should be called correctly
    • [x] _ in function name becomes - in command name
    • [x] Function doc block becomes command description

    Example

    # Phpakefile
    /**
      * Short description.
      *
      * Long description.
      */
    function hello_world() {}
    
    # Command
    phpake hello-world
    
    opened by jigarius 0
  • Use PHP attributes instead of annotations

    Use PHP attributes instead of annotations

    Currently, we use @something annotations to add metadata to the Phpake callbacks. Consider using PHP's in-built attribute support for this purpose.

    Reference: Attributes in PHP 8

    enhancement 
    opened by jigarius 0
  • Support a special `$shell` parameter

    Support a special `$shell` parameter

    Currently, for running shell commands, one has to run proc_open(), proc_close(), etc. It'd be great to have a special $shell variable, which would have a method execute($command) to easily execute commands.

    function shell_example($shell) {
      $shell->execute('docker compose exec main sh');
    }
    
    enhancement 
    opened by jigarius 1
  • Force Phpake tasks to be in a namespace?

    Force Phpake tasks to be in a namespace?

    Requirements

    • Currently, Phpake tasks are defined in the global namespace, which might make some people sad.

    Proposed solution

    • Provision for a special namespace, Phpake\Task or simply Phpake?
    • All Phpake tasks must be defined in this namespace - this will also simplify task discovery.
    enhancement 
    opened by jigarius 0
  • Support for command aliases

    Support for command aliases

    Requirements

    Allow Phpake callbacks to declare command aliases using a @alias annotation. For example,

    # Phpakefile
    
    namespace Input_Output;
    
    /**
     * Say hello world.
     *
     * @alias hhum
     * @alias helo
     */
    function hello_human() {
      echo 'Hello human' . PHP_EOL;
    }
    

    At the end of all the changes, running phpake input-output:hello-human --help should show the command alias(es) correctly. Running phpake helo should work the same way as phpake input-output::hello-human.

    enhancement good first issue 
    opened by jigarius 1
Releases(v1.0.0)
  • v1.0.0(Oct 15, 2022)

  • v1.0.0-beta.1(Oct 9, 2021)

    The first release! All the basic features work and most of the code is unit tested.

    Features

    • Initial documentation
    • Tasks with no parameters
    • Tasks with parameters
    • Tasks with variadic parameters
    • Phpakefile examples
    • Ability to run shell commands with proc_open()
    Source code(tar.gz)
    Source code(zip)
Owner
Jigar Mehta
I'm a software engineer based in Montréal, specialized in web development, working with tech like PHP, Ruby, Python, JS and SQL.
Jigar Mehta
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

The Phing Project 1.1k Dec 22, 2022
Easy CI - Tools that make easy to setup CI.

Easy CI Tools that make easy to setup CI. Check git conflicts in CI Check TWIG and Latte templates for missing classes, non-existing static calls and

null 14 Dec 22, 2022
A PHP project/micro-package generator for PDS compliant projects or micro-packages.

Construct A PHP project/micro-package generator for PDS compliant projects or micro-packages. Installation Construct should be installed globally thro

Jonathan Torres 263 Sep 28, 2022
Hi I'm Bob! I'm a tiny and messy build tool for PHP projects

Bob, your friendly builder Hello World Put this in a file named bob_config.php in your project's root: <?php namespace Bob\BuildConfig; task('defaul

Christoph Hochstrasser 105 Mar 4, 2022
A starter-kit for your PHP project.

PHP Noise A starter-kit for your PHP project. It includes frequently needed boilerplate setups (ci, badges, etc.) ?? Installation To install this appl

medunes 52 Dec 17, 2022
remake of doxbin in php

DOXBIN $Version V1.6 $Warnings [ THIS IS NOT THE ORG SRC OF DOXBIN.ORG, PLEASE DON'T FALSE CLAIM AROUND SAYING U HACKED DOXBIN, THE OWNER OF DOXBIN IS

Nano 28 Dec 1, 2021
Glob-like file and pattern matching utility.

Glob-like file and pattern matching utility.

Chris Kankiewicz 94 Dec 14, 2022
Xr - Lightweight debug server utility built on ReactPHP.

XR ?? Subscribe to the newsletter to don't miss any update regarding Chevere. XR is a dump server utility built on top of ReactPHP. Features ✨ Dump si

Chevere 195 Dec 17, 2022
I gues i tried to make a shell that's looks like a terminal in single php file

php-shell-gui Terms of service This tool can only be used for legal purposes. You take full responsibility for any actions performed using this. The o

Squar3 4 Aug 23, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
Simple utility and class library for generating php classes from a wsdl file.

wsdl2phpgenerator Simple WSDL to PHP classes converter. Takes a WSDL file and outputs class files ready to use. Uses the MIT license. Announcement: We

null 802 Dec 10, 2022
Utility PHP class to simplify interacting with persistent dismissible WordPress notices, promos, and banners

Persistent Dismissible A class for encapsulating the logic required to maintain a relationship between the database, a dismissible UI element (with an

Sandhills Development, LLC 22 Oct 11, 2022
A PHP wrapper around the Git command line utility.

Git Wrapper provides a readable API that abstracts challenges of executing Git commands from within a PHP process for you.

Chris Pliakas 503 Nov 21, 2022
WebDirStat is a disk usage utility for web servers written in PHP

WebDirStat is disk usage utility for web servers, it’s a single PHP file that gives you statistics about disk usage inside a specific Directory ordered by size, in a form of a simple tree table.

Yassine 2 Oct 14, 2021
A utility package that helps inspect functions in PHP.

A utility package that helps inspect functions in PHP. This package provides some utilities for inspecting functions (callables) in PHP. You can use i

Ryan Chandler 14 May 24, 2022
Php-timer - Utility class for timing

phpunit/php-timer Utility class for timing things, factored out of PHPUnit into a stand-alone component. Installation You can add this library as a lo

Sebastian Bergmann 7.4k Jan 5, 2023
An utility component for XML usage and best practices in PHP

An utility component for XML usage and best practices in PHP

Laminas Project 13 Nov 26, 2022
A PHP utility for managing secrets in the cloud using AWS KMS and DynamoDB

CredStash for PHP This is a PHP port of original CredStash (written in python). Encryption and DynamoDB storage are compatible with python version so

Global Media Outreach 21 Nov 15, 2022
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Renoki Co. 720 Jan 3, 2023
Utility that helps you switch git configurations with ease.

git-profile Utility that helps you switch git configurations with ease Preface It is possible that you have multiple git configurations. For example:

Zeeshan Ahmad 240 Jul 18, 2022