Author: Raymond Bosman Date: 2006-01-13 15:41:45 +0100 (Fri, 13 Jan 2006) New Revision: 1833
Log: - Updated to the new exception system. Removed: packages/EventLog/trunk/src/exceptions/file_exception.php Modified: packages/EventLog/trunk/src/exceptions/writer_exception.php packages/EventLog/trunk/src/log_autoload.php packages/EventLog/trunk/src/writers/writer_database.php packages/EventLog/trunk/src/writers/writer_file.php packages/EventLog/trunk/tests/log_test.php packages/EventLog/trunk/tests/writers/writer_file_test.php Deleted: packages/EventLog/trunk/src/exceptions/file_exception.php =================================================================== --- packages/EventLog/trunk/src/exceptions/file_exception.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/src/exceptions/file_exception.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -1,44 +0,0 @@ -<?php -/** - * File containing the ezcFileWriterException class. - * - * @package EventLog - * @version //autogen// - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - */ -/** - * Exception thrown when a file error occures. - * - * @package EventLog - * @version //autogen// - */ -class ezcLogFileException extends Exception -{ - /** - * The file could not be found on the filesystem. - */ - const FILE_NOT_FOUND = 1; - - /** - * The file could not be read from the filesystem. - */ - const FILE_NOT_READABLE = 2; - - /** - * The file could not be written to the filesystem. - */ - const FILE_NOT_WRITABLE = 3; - - /** - * Constructs a new ezcLogFileExcpetion with the message $message and the error code $code. - * - * @param string $message - * @param int $code - */ - public function __construct( $message, $code ) - { - parent::__construct( $message, $code ); - } -} -?> Modified: packages/EventLog/trunk/src/exceptions/writer_exception.php =================================================================== --- packages/EventLog/trunk/src/exceptions/writer_exception.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/src/exceptions/writer_exception.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -12,19 +12,23 @@ * The ezcLogWriterException will be thrown when an [EMAIL PROTECTED] ezcLogWriter} or * a subclass encounters an exceptional state. * + * This exception is a container, containing any kind of exception. + * * @package EventLog * @version //autogen// */ class ezcLogWriterException extends Exception { + public $exception; + /** - * Constructs a new ezcLogWriterException with the message $message. + * Constructs a new ezcLogWriterException with the original exception $e. * - * @param string $message + * @param Exception $e; */ - public function __construct( $message ) + public function __construct( Exception $e ) { - parent::__construct( $message, 0 ); + $this->exception = $e; } } ?> Modified: packages/EventLog/trunk/src/log_autoload.php =================================================================== --- packages/EventLog/trunk/src/log_autoload.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/src/log_autoload.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -27,7 +27,7 @@ 'ezcLogWriterUnixFile' => 'EventLog/writers/writer_unix_file.php', 'ezcLogWriterDatabase' => 'EventLog/writers/writer_database.php', - 'ezcLogFileException' => 'EventLog/exceptions/file_exception.php', + //'ezcLogFileException' => 'EventLog/exceptions/file_exception.php', 'ezcLogWriterException'=> 'EventLog/exceptions/writer_exception.php' ); Modified: packages/EventLog/trunk/src/writers/writer_database.php =================================================================== --- packages/EventLog/trunk/src/writers/writer_database.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/src/writers/writer_database.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -164,7 +164,7 @@ } catch ( PDOException $e ) { - throw new ezcLogWriterException( "SQL query failed in ezcLogWriterDatabase.\n". $e->getMessage() ); + throw new ezcLogWriterException( $e ); } } } @@ -180,7 +180,7 @@ } catch ( PDOException $e ) { - throw new ezcLogWriterException( "SQL query failed in ezcLogWriterDatabase.\n". $e->getMessage() ); + throw new ezcLogWriterException( $e ); } } } Modified: packages/EventLog/trunk/src/writers/writer_file.php =================================================================== --- packages/EventLog/trunk/src/writers/writer_file.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/src/writers/writer_file.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -151,13 +151,20 @@ if ( count( $fileHandles ) > 0 ) { - foreach ( $fileHandles as $fh ) + $failure = false; + foreach ( $fileHandles as $filename => $fh ) { if ( fwrite( $fh, $string ) === false) { - throw ezcLogWriterException( "Cannot write to the attached log file.", ezcLogWriterException::FILE_NOT_WRITABLE ); + $failure = $filename; } } + + if ( $failure ) + { + throw ezcLogWriterException(new ezcBaseFileIoException( $failure, ezcBaseFileIoException::WRITE ) ); + } + } else { @@ -165,7 +172,7 @@ { if ( fwrite( $this->openFiles[$this->defaultFile], $string ) === false ) { - throw ezcLogWriterException( "Cannot write to the default log file.", ezcLogWriterException::FILE_NOT_WRITABLE ); + throw ezcLogWriterException( new ezcBaseFileIoException( $this->defaultFile, ezcBaseFileIoException::WRITE ) ); } } } @@ -195,8 +202,16 @@ $fh = @fopen( $this->logDirectory ."/". $fileName, "w" ); if ( $fh === false ) { - // throw exception. - throw new ezcLogFileException( "Cannot open the file <{$fileName}> for writing", ezcLogFileException::FILE_NOT_FOUND ); + $path = $this->logDirectory ."/". $fileName; + + if( !file_exists( $path ) ) + { + throw new ezcBaseFileNotFoundException( $path, "log" ); + } + else + { + throw new ezcBaseFilePermissionException( $path, ezcBaseFilePermissionException::WRITE ); + } } $this->openFiles[$fileName] = $fh; Modified: packages/EventLog/trunk/tests/log_test.php =================================================================== --- packages/EventLog/trunk/tests/log_test.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/tests/log_test.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -311,11 +311,12 @@ $db->exec("DROP TABLE `audits`"); } + */ public function testException() { $this->log->reset(); - $this->log->map( new ezcLogFilter, $writer = new ezcLogWriterDatabase( ezcDbInstance::get(), "log" ) ); + $this->log->getMapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter, $writer = new ezcLogWriterDatabase( ezcDbInstance::get(), "log" ), true ) ); try { @@ -332,7 +333,7 @@ public function testDisableExceptions() { $this->log->reset(); - $this->log->map(new ezcLogFilter, $writer = new ezcLogWriterDatabase( ezcDbInstance::get(), "log")); + $this->log->getMapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter, $writer = new ezcLogWriterDatabase( ezcDbInstance::get(), "log"), true ) ); $this->log->throwWriterExceptions(false); try @@ -346,6 +347,7 @@ } } + /* public function testDetach() { $db = ezcDbInstance::get(); Modified: packages/EventLog/trunk/tests/writers/writer_file_test.php =================================================================== --- packages/EventLog/trunk/tests/writers/writer_file_test.php 2006-01-13 14:31:19 UTC (rev 1832) +++ packages/EventLog/trunk/tests/writers/writer_file_test.php 2006-01-13 14:41:45 UTC (rev 1833) @@ -86,9 +86,8 @@ $this->writer->setFile($filter, "" ); $this->fail("Should raise a ezcLogFileException"); } - catch ( ezcLogFileException $e ) + catch ( ezcBaseFilePermissionException $e ) { - $this->assertEquals(ezcLogFileException::FILE_NOT_FOUND, $e->getCode() ); } } -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
