]> granicus.if.org Git - php/commitdiff
Changed stream_resolve_include_path to use zend_resolve_path
authorMikko Koppanen <mkoppanen@php.net>
Thu, 24 Dec 2009 13:12:03 +0000 (13:12 +0000)
committerMikko Koppanen <mkoppanen@php.net>
Thu, 24 Dec 2009 13:12:03 +0000 (13:12 +0000)
backported stream_resolve_include_path to PHP 5.3
backported stream_resolve_include_path test to PHP 5.3

NEWS
ext/standard/basic_functions.c
ext/standard/streamsfuncs.c
ext/standard/streamsfuncs.h
ext/standard/tests/streams/stream_resolve_include_path.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 480d92e7a6ae91cd1ada5137c71d221846280a6d..cbc022391c3ba66c91220317ed8fd8dfe2182104 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ PHP                                                                        NEWS
 - Added support for CURLOPT_CERTINFO. FR #49253.
   (Linus Nielsen Feltzing <linus@haxx.se>)
 - Added client-side server name indication support in openssl. (Arnaud)
+- Added stream_resolve_include_path() (Mikko)
 
 - Improved fix for bug #50006 (Segfault caused by uksort()). (Stas)
 
index 150afa1d18aa017972950be04a0522a56484f220..f29df3cec3bc92520c89de1b88b02912c0225053 100644 (file)
@@ -2010,6 +2010,10 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO(arginfo_stream_get_wrappers, 0)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO(arginfo_stream_resolve_include_path, 0)
+       ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_stream_is_local, 0)
        ZEND_ARG_INFO(0, stream)
 ZEND_END_ARG_INFO()
@@ -3115,6 +3119,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
        PHP_FE(stream_wrapper_restore,                                                                                  arginfo_stream_wrapper_restore)
        PHP_FE(stream_get_wrappers,                                                                                             arginfo_stream_get_wrappers)
        PHP_FE(stream_get_transports,                                                                                   arginfo_stream_get_transports)
+       PHP_FE(stream_resolve_include_path,                                                                             arginfo_stream_resolve_include_path)
        PHP_FE(stream_is_local,                                                                                         arginfo_stream_is_local)
        PHP_FE(get_headers,                                                                                                             arginfo_get_headers)
 
index 5759899316ca57cea9b3e4d5d999bbb614a57d1c..4be67f3fd860fb9992fb816bb517eb40e4ddff13 100644 (file)
@@ -1442,6 +1442,26 @@ PHP_FUNCTION(stream_socket_enable_crypto)
 }
 /* }}} */
 
+/* {{{ proto string stream_resolve_include_path(string filename)
+Determine what file will be opened by calls to fopen() with a relative path */
+PHP_FUNCTION(stream_resolve_include_path)
+{
+       char *filename, *resolved_path; 
+       int filename_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+               return;
+       }
+
+       resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC);
+
+       if (resolved_path) {
+               RETURN_STRING(resolved_path, 0);
+       }
+       RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto bool stream_is_local(resource stream|string url) U
 */
 PHP_FUNCTION(stream_is_local)
index a3052bac63bc31855f5fbf9b8d4832dfb6fde3c6..b59031e6552ac2b953a7a22bb8673f3bd243d03f 100644 (file)
@@ -56,6 +56,7 @@ PHP_FUNCTION(stream_filter_append);
 PHP_FUNCTION(stream_filter_remove);
 PHP_FUNCTION(stream_socket_enable_crypto);
 PHP_FUNCTION(stream_socket_shutdown);
+PHP_FUNCTION(stream_resolve_include_path);
 PHP_FUNCTION(stream_is_local);
 PHP_FUNCTION(stream_supports_lock);
 
diff --git a/ext/standard/tests/streams/stream_resolve_include_path.phpt b/ext/standard/tests/streams/stream_resolve_include_path.phpt
new file mode 100644 (file)
index 0000000..01c05a5
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+stream_resolve_include_path(string path)
+--FILE--
+<?php
+$include_path = __DIR__ . '/test_path';
+$include_path_nested = $include_path . '/nested';
+
+$include_path_file = $include_path . DIRECTORY_SEPARATOR . 'file';
+$include_path_nested_file = $include_path_nested . DIRECTORY_SEPARATOR . 'file';
+
+mkdir($include_path);
+mkdir($include_path_nested);
+
+file_put_contents($include_path_file, 'include_path');
+file_put_contents($include_path_nested_file, 'include_path');
+
+var_dump(stream_resolve_include_path());
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file-does-not-exist'));
+
+set_include_path($include_path . PATH_SEPARATOR . $include_path_nested);
+var_dump(stream_resolve_include_path('file'));
+set_include_path($include_path_nested . PATH_SEPARATOR . $include_path);
+var_dump(stream_resolve_include_path('file'));
+
+unlink($include_path_nested_file);
+rmdir($include_path_nested);
+unlink($include_path_file);
+rmdir($include_path);
+--EXPECTF--
+Warning: stream_resolve_include_path() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+bool(false)
+string(%d) "%s/test_path/file"
+string(%d) "%s/test_path/nested/file"
+