Skip to content

malc0mn/php-basher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Bash script generator/runner.

Build Status Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight

What! Why?

This is by no means a(n attempt at a) replacement tool for things like Robo. I just thought it would be fun to create a bash script generator and executor for PHP and it was a nice excuse to create an OO targeted PHP library again...

Install using composer

Open a shell, cd to your poject and type:

composer require malc0mn/php-basher

or edit composer.json and add:

{
    "require": {
        "malc0mn/php-basher": "~1.0"
    }
}

Usage

Generating a bash script

An extremely simple example:

<?php
use Basher\Tools\OSBase;

$base = new OSBase();

$base->set('-e', '-v')
    ->changeDir('/opt/approot')
    ->makeDir('build-new')
    ->delete('previous')
    ->renameIfExists('current', 'previous')
    ->link('build-new', 'current')
    ->set('-o pipefail')
;

echo (string)$base;

Would generate this output:

#!/bin/bash

set -e -v -o pipefail

cd /opt/approot
mkdir -p build-new
rm -f previous
if [ -d current -o -f current -o -L current ]; then mv -f current previous ; fi
ln -s build-new current

Execute commands

Say you would want to execute a command in a linux container to deploy new code, you could do this:

<?php

use Basher\Tools\Vcs\Git;
use Basher\Tools\Lxc\Lxc;

$destination = 'build-' . date('Ymd-His');

// Build the command stack we want to run INSIDE the container.
$git = new Git();
$commands = $git->clone(
      'https://github.com/malc0mn/php-basher',
      "/opt/approot/$destination",
      'master'
    )->changeDir('/opt/approot')
    ->delete('previous', true, true)
    ->renameIfExists('current', 'previous', true)
    ->link($destination, 'current', true)
    ->service('php-fpm', 'reload')
    ->getStacked()
;

// $commands now holds the command stack, joined by double ampersands: '&&' so
// that the stack is aborted immediately when a command fails!

// Attach to the container and run the above command set INSIDE it.
$result = Lxc::attach('my-lxc-container')
    ->execute($commands)
    ->run()
;

// Perform execution result handling.
if (!$result->wasSuccessful()) {
    throw new \RuntimeException($result->getOutput());
}

TODO: complete this readme :/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published