Skip to content

Instantly share code, notes, and snippets.

@cjsewell
Last active August 29, 2015 14:08
Show Gist options
  • Save cjsewell/b26410490b07dfdfc0f7 to your computer and use it in GitHub Desktop.
Save cjsewell/b26410490b07dfdfc0f7 to your computer and use it in GitHub Desktop.
Simple PHP PHAR wrapper for windows and linux
@ECHO OFF
REM Simple wrapper for PHP PHAR files for Windows command line
REM Executes a phar file in a with the same name as this script in a subfolder named phars
REM Eg. Calling this script c:\tools\runphar.bat will execute "php c:\tools\phars\runphar.phar"
SET BASE_DIR=%~dp0
SET SCRIPT_NAME=%~n0
SET PHAR=%BASE_DIR%phars\%SCRIPT_NAME%.phar
SET PHP=php
where %PHP% > NUL 2>&1
if not %ERRORLEVEL%==0 (
echo Error %PHP% not found
exit /B 1
) else (
if exist %PHAR% (
%PHP% %PHAR% %*
exit /B %ERRORLEVEL%
) else (
echo %PHAR% not found
exit /B 2
)
)
#!/bin/bash
# Simple wrapper for PHP PHAR files for Bash
# Executes a phar file in a with the same name as this script in a subfolder named phars
# Eg. Calling this script /usr/local/bin/runphar.sh will execute "php /usr/local/bin/phars/runphar.phar"
BASE_DIR=$(dirname $0);
SCRIPT_NAME=$(basename $0 | cut -d'.' --complement -f2- );
PHAR=${BASE_DIR}/phars/${SCRIPT_NAME}.phar;
PHP=php;
which $PHP > /dev/null 2>&1
if ! [ $? -eq 0 ] ; then
echo Error $PHP not found;
exit 1;
elif [ -f $PHAR ] ; then
$PHP $PHAR $@;
exit $?;
else
echo $PHAR not found;
exit 2;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment