Zend tool include path

2019-04-14 18:03发布

问题:

Is it possible to install and use ZF (+ its console tool) without access to include_path direcotory? I've tried adding the ...Zend/library direcotry into include_path but without success.

I did it this way:

php -r 'set_include_path(get_include_path() . PATH_SEPARATOR . "/var/www/.../Zend/library")';

After var_dumping result of the function above it returned old include_path which should mean success. But next call of get_include_path() returned the old path too.

I've also tried to set the environment variable:

ZF_INCLUDE_PATH_PREPEND="/var/www/.../Zend/library"

There is our company framework in the old include_path directory so I can't (even if I could I should't) copy there the ZF library.

I think a proper framework shouldn't rely on any global PHP settings as include_path is. I think it should be possible to set the include path somewhere in ZF internal configuration file.

edit:
I added set_include_path('/var/www/.../Zend/library') into zf.php file and the tool stopped throwing 'wrong include_path' error. In fact it sopped printing any output. When executing command zf create project test it does nothing. ~/.zf folder wasn't created.

回答1:

If you can't copy the zf library in some "global" include path, e.g. /usr/share/php/, you can still copy it where your project is and start the zf tool from there. A folder structure like:

/var/www/zf_tool
                `/bin/
                      `zf.sh
                      `zf.php
                `/library
                      `/Zend

Copy the Zend folder under library, and the zf.sh and zf.php scripts under bin and set them to be executable chmod a+x zf.sh zf.php if they are not already. Next, if you run /var/www/project/bin/zf.sh it'll look for zf files in the include_path, but if it's not there, it'll go up one folder and go into the library folder. Only if the zf library is not to be found there, it'll die with an error. In the end, creating a new zf project is simple as:

$ pwd
/var/www/zf_tool/bin
$ ./zf.sh create project /var/www/test_project

That's it. HTH :)



回答2:

Using he set/get include_path functions is only going to set it for the life of the "request" so it goes back to normal as soon as the command/web request finishes. As far as setting the include path for your local copy you can do that in an environment variable as you tried or in your ~/.zf folder on the box. there are configs in there and there is a setting cor include path.

Beyond that you could also ad something like what you had in the php -r ... to the shell script youre executing directly although this wouldnt be the recommended way.