Req #69385 [Wfx]: Add glob_get_base_path() function

From: Date: Mon, 06 Apr 2015 20:20:23 +0000
Subject: Req #69385 [Wfx]: Add glob_get_base_path() function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191857@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69385&edit=1 ID: 69385 User updated by: bschussek at gmail dot com Reported by: bschussek at gmail dot com Summary: Add glob_get_base_path() function Status: Wont fix Type: Feature/Change Request Package: Filesystem function related PHP Version: 5.6.8RC1 Block user comment: N Private report: N New Comment: > There are a number of situations this function couldn't handle The point of the function is not to return the directory name, but the *most specific base path*. Maybe an extension from my examples before makes it clearer: glob_get_base_path('css/**/*.css') // => css glob_get_base_path('/home/me/data{,.bak}/.settings/*.conf') // => /home/me So no, dirname() is unfortunately not a solution. Previous Comments: ------------------------------------------------------------------------ [2015-04-06 18:52:43] requinix@php.net There are a number of situations this function couldn't handle, like ** from your #69382, or braces in the directory portion (like "{css,js}/*"). For everything else the regular dirname() works just fine - it's really more of a string function than a filesystem function. http://3v4l.org/ULTrU ------------------------------------------------------------------------ [2015-04-06 14:05:44] bschussek at gmail dot com Description: ------------ I'd love to see a glob_get_base_path() function that returns the base path of a glob following the rules used by glob(). The base path is the most specific directory path of a glob. Knowing the base path is useful when mapping a glob to a target directory. This mapping can be used, for example, to copy the matched files to the directory. Signature: glob_get_base_path(string $glob[, int $flags = 0]) $glob - a glob $flags - the glob() flags Result: string - the base path of the glob Usage example: <?php // could be stored in the application configuration define('SOURCE_GLOB', 'css/*.css'); define('TARGET_DIR', 'public_html/css'); // runtime $basePath = glob_get_base_path(SOURCE_GLOB); $basePathLength = strlen($basePath); foreach (glob($glob) as $sourcePath) { $targetPath = substr_replace($sourcePath, TARGET_DIR, 0, $basePathLength); copy($sourcePath, $targetPath); } Test script: --------------- <?php echo glob_get_base_path('*.css')."\n"; echo glob_get_base_path('/*.css')."\n"; echo glob_get_base_path('css/*.css)."\n"; echo glob_get_base_path('css/foo*.css)."\n"; echo glob_get_base_path('css/foo{bar,baz}.css)."\n"; Expected result: ---------------- . / css css css ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69385&edit=1

« previous php.bugs (#191857) next »