[Solar-svn] Revision 3174
pmjones at solarphp.com
pmjones at solarphp.com
Sat May 24 09:45:12 CDT 2008
Solar_Dir: [ADD] Methods mkdir() and rmdir() to mimic the PHP functions, but throw exceptions instead of issuing warnings.
Modified: trunk/Solar/Dir.php
===================================================================
--- trunk/Solar/Dir.php 2008-05-22 16:08:46 UTC (rev 3173)
+++ trunk/Solar/Dir.php 2008-05-24 14:45:12 UTC (rev 3174)
@@ -14,7 +14,7 @@
* @version $Id$
*
*/
-class Solar_Dir
+class Solar_Dir extends Solar_Base
{
/**
*
@@ -196,4 +196,60 @@
// final fallback for Windows
return getenv('SystemRoot') . '\\temp';
}
+
+ /**
+ *
+ * Replacement for mkdir() to supress warnings and throw exceptions in
+ * their place.
+ *
+ * @param string $path The directory path to create.
+ *
+ * @param int $mode The permissions mode for the directory.
+ *
+ * @param bool $recursive Recursively create directories along the way.
+ *
+ * @return bool True on success; throws exception on failure.
+ *
+ * @see [[php::mkdir() | ]]
+ *
+ */
+ public static function mkdir($path, $mode = 0777, $recursive = false)
+ {
+ $result = @mkdir($path, $mode, $recursive);
+ if (! $result) {
+ $self = Solar::factory(__CLASS__);
+ $info = error_get_last();
+ $info['mkdir_path'] = $path;
+ $info['mkdir_mode'] = $mode;
+ $info['mkdir_recursive'] = $recursive;
+ throw $self->_exception('ERR_MKDIR_FAILED', $info);
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ *
+ * Replacement for rmdir() to supress warnings and throw exceptions in
+ * their place.
+ *
+ * @param string $path The directory path to remove
+ *
+ * @return bool True on success; throws exception on failure.
+ *
+ * @see [[php::rmdir() | ]]
+ *
+ */
+ public static function rmdir($path)
+ {
+ $result = @rmdir($path);
+ if (! $result) {
+ $self = Solar::factory(__CLASS__);
+ $info = error_get_last();
+ $info['rmdir_path'] = $path;
+ throw $self->_exception('ERR_RMDIR_FAILED', $info);
+ } else {
+ return true;
+ }
+ }
}
\ No newline at end of file
More information about the Solar-svn
mailing list