Re: Using CLI as a shell

From: Date: Mon, 03 Feb 2003 19:26:15 +0000
Subject: Re: Using CLI as a shell
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-93959@lists.php.net to get a copy of this message
At 07:31 PM 2/3/2003 +0100, Marcus Börger wrote:
After adding -B, -F, -R and -E which will hopefully liked by the rest of development team so that the stuff need not to be removed. I (or better a friend of mine) had another idea. Here comes:
I am glad to hear someone else is interested in php.cli improvements. I have written an extension to Gnu Make which enables using sapi/cli/php in a makefile environment with auto-detection of dependencies. See: http://www.xmake.org I have previously posted twice on the subject of a -M switch (similar to gcc -M), for enabling proper use of sapi/cli/php in a makefile environment - I got no responses. Here is the proposal: * Add a '-M' option to sapi/cli/php that would behave essentially the same as gcc -M and enable the use of php command-line scripts to work properly in a makefile build environment (See below for explanation of gcc -M). * 'php -M -f myFile.php' should differ from 'gcc -M myFile.c', in two ways:
        a) Command output should only list prerequisite files rather than a complete dependency makefile rule since there is no standard suffix for php output as for C [ myFile.o : myFile.c ... ]
        b) Detect dependencies other than included and required files, as reported by get_included_files(). There are many other ways that a PHP script could become dependent on other files which cannot easily be determined automatically unless a function is available for a script to explicitly declare that it depends on an external file. [Example: <? if (file_exists($myFile)) echo "hello";?>].
* Add two built-in PHP functions to allow '-M' option to accurately identify file dependencies in PHP source files (the names could change):
        void register_prerequisite_file( string $myFile )
        Array get_prerequisite_files( )
* With the above two functions, this is how the system should work: In the following example, /usr/local/bin/php-cli is the command-line version of PHP: sapi/cli/php --------- file: test.php #!/usr/local/bin/php-cli <? php include( "myIncludedFile.php" ); register_prerequisite_file( "myRequiredFile") if (file_exists( "myRequiredFile" )) echo "got file"; ?> -------- eof Internally php-cli -M would call get_included_files() and get_prerequisite_files() and join them together in a space separated list, with the first item being the source file. Here is what php-cli would do from the command line: $/usr/local/bin/php-cli -M -f test.php test.php myIncludedFile.php myRequiredFile --------------- # example makefile which implements the functionality without php -M # Command for generating output files from source files # the command-line version of php binary must be specified in: XME_php.cli_outfileCmd # this is built under <php_source_dir>/sapi/cli/php XME_php.cli_outfileCmd:=/usr/local/bin/php # Command to generate a list of dependencies from a source file (including the source file) # $(1) - source file define XME_php.cli_dependCmd $(shell $(XME_php.cli_outfileCmd) -r 'include "$(1)"; $$tmpFile = "$(XMAKE_TMP_DIR)/php.cli_dependCmd_out"; if (function_exists('get_prerequisite_files')){ $$files = get_prerequisite_files();}else{$$files = get_included_files();} $$str = join(" ",$$files); $$fp = @fopen( $$tmpFile, "w"); fputs( $$fp, $$str );' 1>$(XMAKE_TMP_DIR)/php.cli_dependCmd_junk || { cat $(XMAKE_TMP_DIR)/php.cli_dependCmd_junk; exit 1; }; cat $(XMAKE_TMP_DIR)/php.cli_dependCmd_out; ) endef # end of makefile Below is what the include file looks like <?php /* These functions supporting php dependency makefile rule generation This file would become obsolete if sapi/cli/php -M option is approved for inclusion in PHP USAGE: // paths to files must be ABSOLUTE paths, resolving any symbolic links // assume your script uses a file 'file1', in the same directory as the script file // $file1=realpath(file1) doesn't work since it returns false if the file doesn't exist // since file1 may be created by XMake, we need the path whether or not it exists // Try this: require_once( getenv("XMAKE_HOME")."/config/XMExtensions/php.cli.inc" ); $filesArray=array( dirname(__FILE__).'/file1' ); register_prerequisite_files( $filesArray ); */ $XMAKE_PHP_PREREQUISITE_FILES=array();
        function register_prerequisite_files( $filesArray ){
                global $XMAKE_PHP_PREREQUISITE_FILES;
                $XMAKE_PHP_PREREQUISITE_FILES = array_merge($XMAKE_PHP_PREREQUISITE_FILES, $filesArray);
        }
        function get_prerequisite_files(){
                global $XMAKE_PHP_PREREQUISITE_FILES;
                $filesArray = array_merge(get_included_files(), $XMAKE_PHP_PREREQUISITE_FILES);
                return $filesArray;
        }
?> - Greg Keraunen http://www.xmake.org http://www.xmlmake.com

« previous php.dev (#93959) next »