Scott
Scott

Reputation: 823

Zend framework 2 - zftool.phar Windows 7 environment variable

I'm trying to access the zftool.phar (for Zend Framework 2) globally using an environment variable in Windows 7. I can't get it to work. Has anyone successfully achieved this?

Upvotes: 2

Views: 1906

Answers (3)

Alymbek
Alymbek

Reputation: 26

or create and run as administrator "install-zftool.bat" file with code:

@echo off

::setting directory for installing zftool - change if necessary
set folder="C:\zftool"

::making directory
md "%folder%"

::downloading latest version of zftool.phar
bitsadmin.exe /transfer "ZFTool" "http://packages.zendframework.com/zftool.phar" "%folder%\zftool.phar"

::creating empty zftool and zftool.bat files
@echo. 2> %folder%\zftool
@echo. 2> %folder%\zftool.bat

::making zftool.bat file
@echo @echo off > %folder%\zftool.bat
@echo php %%~dp0zftool.phar %%*>> %folder%\zftool.bat

::making zftool file
@echo #!/bin/sh > %folder%\zftool
@echo dir=$(d=$(dirname "$0"); cd "$d" ^&^& pwd) >> %folder%\zftool
@echo if command -v 'cygpath' ^>/dev/null 2^>^&1; then >> %folder%\zftool
@echo if [[ $(which php) == /cygdrive/* ]]; then >> %folder%\zftool
@echo dir=$(cygpath -m $dir); >> %folder%\zftool
@echo fi>> %folder%\zftool
@echo fi>> %folder%\zftool
@echo dir=$(echo $dir ^| sed 's/ /\ /g')>> %folder%\zftool
@echo php "${dir}/zftool.phar" $*>> %folder%\zftool

::adding folder to PATH environment variable
setx path "%PATH%;%folder%" /M

exit

bat file will do all that is said above

do not forget run as administrator!

Upvotes: 0

Alymbek
Alymbek

Reputation: 26

  1. Make folder C:\zftool

  2. Download the "zftool.phar" from packages.zendframework.com(http://packages.zendframework.com/zftool.phar) into C:\zftool

  3. Make "zftool.bat" file in C:\zftool with code:

    @echo off
    php %~dp0zftool.phar %*
    
  4. Make "zftool" file(without extension) in C:\zftool with code:

    #!/bin/sh
    dir=$(d=$(dirname "$0"); cd "$d" && pwd)
    
    # see if we are running in cygwin by checking for cygpath program
    if command -v 'cygpath' >/dev/null 2>&1; then
    
        # cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin.
    
        if [[ $(which php) == /cygdrive/* ]]; then
            dir=$(cygpath -m $dir);
        fi
    fi
    
    dir=$(echo $dir | sed 's/ /\ /g')
    php "${dir}/zftool.phar" $*
    
  5. files in C:\zftool :
    zftool
    zftool.bat
    zftool.phar

  6. Add "C:\zftool" into PATH environment variable

  7. Open CMD and type "zftool", check command "zftool version"

  8. This allow you use in CMD short command "zftool" in any place without "php zftool.phar"

  9. You have to run "zftool" command in the project folder to use in the current project

Upvotes: 1

Iwona Kubowicz
Iwona Kubowicz

Reputation: 374

Try to use command:

> php zftool.phar

But remember that before that path to the php.exe file must be added to your PATH environment variable.

Upvotes: 2

Related Questions