简体   繁体   中英

Makefile for php scripts

I have order to create multiple php scripts that reads data from stdin. I have to put source files to ftp in to special folder and make something called Makefile for php. I cannot find any documentation about it. Can you please give me some informations about it? Sorry for my bad english

Nowadays, a couple of approaches come to my mind:

1. Composer ( Dependency Manager)

If you've never used it: use it . This is the tool you don't want to miss, unless you already have dependency management process in place (ie git submodules).

The first working and well-established dependency manager, finally allowing to split up and require (+ autoload) php components in a comprehensive manner. Almost every active php project on github has a composer.json , which you may also expand with custom script hooks , which may reside in a seperate build class and call whatever build process you have implemented.

Note : Driving build process is strictly speaking not in the domain of dependency management, so we may look for other alternatives

Anyway, it works - and can be as easy as

composer.json :

...
"require-dev": {
    "phpunit/phpunit": "4.1.*"
},
"autoload": {
    "psr-0": {
        "Build": ""
    },
},
"scripts": {
    "post-autoload-dump": [
        "Build::afterUpdateInstall"
    ]
}  
...

Build.php (in project root):

use Composer\Script\Event;
class Build {

    public static function afterUpdateInstall(Event $event) {
        if(true === $event->isDevMode()) {
            passthru(./vendor/bin/phpunit test);
        }
    }
}

One can easily see how such a trigger - which in this case runs the test suite after every development install, update of dependencies or when their class autoloader is updated. For more complex tasks, i guess you would look into an actual build system like

2. Phing

Have not used it yet - it's a php-based build system that is configured via xml files, similar to Ant (see below or earlier SO post for some two cents on Phing vs. Ant).

3. Roll your own CLI executable (/ framework)

Write your own deploy scripts in php - there are libraries available to do the boring stuff (parameter checking, output formatting, documentation output, etc...) so you just focus on implementing the CLI commands needed ( https://github.com/jlogsdon/php-cli-tools ). I'd then compile it to a php archive executable and included as a dependency in your main project.


And of course you can always break out of the php world and use, (eg)

1. Ant

Dominant in the Java world. Well, if you're an advanced Ant-user and love working with it - then you have a good business case to apply it as your default build manager for php projects. Personally, i am very glad i could stop wrapping my head around it, as there is

2. Grunt

NodeJs based build system with a massively growing number of plugins of varying code quality. The philosophy emphasizes configuration, which is partially the reason there's so many grunt-plugins - each of them abstracts tasks that are purely configured via a json dictionary object. Hard to find a grunt plugin that doesn't exist yet!

3. Gulp

If your relationship with grunt is getting stale or its' (compared to Ant) already awesome build speed is not enough - there is Gulp. Also NodeJs based, similar to grunt in some ways - completely different in two others:

a. Performance: more Speed - less Memory-Consumption because of
b. Approach: centered around piping data as a stream through the stages of your build process, avoiding generation of any intermediate / temporary files on disc or serialisation of objects in memory while passing them to different plugins asynchronously (like grunt does).

Some people (like me) simply keep falling over the coordination of several asynchronously happening callbacks, like commonly found in non-blocking nodejs, thus i found it easier to successfully implement my first complex gulp script - other people's mileage may vary...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM