PHP Classes

File: bin/net_bazzline_create_executable_command_line_file

Recommend this page to a friend!
  Classes of nvb   PHP Executable Script Generator   bin/net_bazzline_create_executable_command_line_file   Download  
File: bin/net_bazzline_create_executable_command_line_file
Role: Auxiliary script
Content type: text/plain
Description: Script that generates the new script code
Class: PHP Executable Script Generator
Generate shell scripts that can execute PHP code
Author: By
Last change:
Date: 7 months ago
Size: 1,681 bytes
 

Contents

Class file image Download
#!/bin/env php
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2015-10-10
 * @todo implement way of finding path to autoload to remove dependency that
 * executable has to lay in predefined paths
 */

if (!isset($argv[1])) {
    echo
'Usage: ' . basename(__FILE__) . ' <path to command line executable file>' . PHP_EOL;
    exit(
1);
}

$filePath = $argv[1];

if (
file_exists($filePath)) {
    echo
$filePath . ' exists already' . PHP_EOL;
    exit(
1);
}

file_put_contents($filePath, '#!/bin/env php
<?php
/**
 * @author '
. basename(__FILE__) . '
 * @since '
. date('Y-m-d') . '
 */

//begin of including composer autoload.php
$possiblePathsToComposerAutoloadFile = [
    __DIR__ . \'/../../../autoload.php\',
    __DIR__ . \'/../../vendor/autoload.php\',
    __DIR__ . \'/../vendor/autoload.php\'
];
$pathToAutoloadFileNotFound = true;
$pathToAutoloadFile = null;
foreach ($possiblePathsToComposerAutoloadFile as $path) {
    if (file_exists($path)) {
        $pathToAutoloadFile = $path;
        $pathToAutoloadFileNotFound = false;
        break;
    }
}
if ($pathToAutoloadFileNotFound) {
    echo \'could not find composer autoload.php, no composer installed?\' . PHP_EOL;
    exit(1);
}

require_once $pathToAutoloadFile;
//end of including composer autoload.php

use Net\Bazzline\Component\Cli\Environment\CommandLineEnvironment;

$environment = new CommandLineEnvironment($argv);
$usage = basename(__FILE__) . \' [-v|--verbose]\';

$environment->execute(
    function (CommandLineEnvironment $environment) {
        //begin of business logic
        //end of business logic
    },
    $usage
);'
);

chmod($filePath, 0755);