[Solar-svn] Revision 2575
pmjones at solarphp.com
pmjones at solarphp.com
Tue Jul 10 14:01:56 CDT 2007
Solar: [ADD] Method isDir() as a corollary to fileExists() in that it checks the include_path for the requested directory.
Modified: trunk/Solar.php
===================================================================
--- trunk/Solar.php 2007-07-10 19:01:00 UTC (rev 2574)
+++ trunk/Solar.php 2007-07-10 19:01:56 UTC (rev 2575)
@@ -525,9 +525,9 @@
// using a relative path on the file
$path = explode(PATH_SEPARATOR, ini_get('include_path'));
- foreach ($path as $dir) {
+ foreach ($path as $base) {
// strip Unix '/' and Windows '\'
- $target = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR . $file;
+ $target = rtrim($base, '\\/') . DIRECTORY_SEPARATOR . $file;
if (file_exists($target)) {
return $target;
}
@@ -539,6 +539,57 @@
/**
*
+ * Hack for [[php::is_dir() | ]] that checks the include_path.
+ *
+ * Use this to see if a directory exists anywhere in the include_path.
+ *
+ * {{code: php
+ * $dir = Solar::isDir('path/to/dir')
+ * if ($dir) {
+ * $files = scandir($dir);
+ * } else {
+ * echo "Not found in the include-path.";
+ * }
+ * }}
+ *
+ * @param string $dir Check for this directory in the include_path.
+ *
+ * @return mixed If the directory exists in the include_path, returns the
+ * absolute path; if not, returns boolean false.
+ *
+ */
+ public static function isDir($dir)
+ {
+ // no file requested?
+ $dir = trim($dir);
+ if (! $dir) {
+ return false;
+ }
+
+ // using an absolute path for the file?
+ // dual check for Unix '/' and Windows '\',
+ // or Windows drive letter and a ':'.
+ $abs = ($dir[0] == '/' || $dir[0] == '\\' || $dir[1] == ':');
+ if ($abs && is_dir($dir)) {
+ return $dir;
+ }
+
+ // using a relative path on the file
+ $path = explode(PATH_SEPARATOR, ini_get('include_path'));
+ foreach ($path as $base) {
+ // strip Unix '/' and Windows '\'
+ $target = rtrim($base, '\\/') . DIRECTORY_SEPARATOR . $dir;
+ if (is_dir($target)) {
+ return $target;
+ }
+ }
+
+ // never found it
+ return false;
+ }
+
+ /**
+ *
* Convenience method to instantiate and configure an object.
*
* @param string $class The class name.
More information about the Solar-svn
mailing list