Author: dr
Date: Wed Jul 4 17:02:14 2007
New Revision: 5689
Log:
- Fixed issue #11057: The ezcBaseConfigurationInitializer inteface is not
enforced for callback classes.
Added:
trunk/Base/src/exceptions/invalid_callback_class.php (with props)
Modified:
trunk/Base/ChangeLog
trunk/Base/src/base_autoload.php
trunk/Base/src/init.php
trunk/Base/tests/base_init_test.php
Modified: trunk/Base/ChangeLog
==============================================================================
--- trunk/Base/ChangeLog [iso-8859-1] (original)
+++ trunk/Base/ChangeLog [iso-8859-1] Wed Jul 4 17:02:14 2007
@@ -1,3 +1,10 @@
+1.3.1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed issue #11057: The ezcBaseConfigurationInitializer inteface is not
+ enforced for callback classes.
+
+
1.3 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Modified: trunk/Base/src/base_autoload.php
==============================================================================
--- trunk/Base/src/base_autoload.php [iso-8859-1] (original)
+++ trunk/Base/src/base_autoload.php [iso-8859-1] Wed Jul 4 17:02:14 2007
@@ -19,6 +19,7 @@
'ezcBaseFileNotFoundException' =>
'Base/exceptions/file_not_found.php',
'ezcBaseFilePermissionException' =>
'Base/exceptions/file_permission.php',
'ezcBaseInitCallbackConfiguredException' =>
'Base/exceptions/init_callback_configured.php',
+ 'ezcBaseInitInvalidCallbackClassException' =>
'Base/exceptions/invalid_callback_class.php',
'ezcBaseInvalidParentClassException' =>
'Base/exceptions/invalid_parent_class.php',
'ezcBasePropertyNotFoundException' =>
'Base/exceptions/property_not_found.php',
'ezcBasePropertyPermissionException' =>
'Base/exceptions/property_permission.php',
Added: trunk/Base/src/exceptions/invalid_callback_class.php
==============================================================================
--- trunk/Base/src/exceptions/invalid_callback_class.php (added)
+++ trunk/Base/src/exceptions/invalid_callback_class.php [iso-8859-1] Wed Jul
4 17:02:14 2007
@@ -1,0 +1,31 @@
+<?php
+/**
+ * File containing the ezcBaseInitInvalidCallbackClassException class
+ *
+ * @package Configuration
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception that is thrown if an invalid class is passed as callback class for
+ * delayed object configuration.
+ *
+ * @package Configuration
+ * @version //autogen//
+ */
+class ezcBaseInitInvalidCallbackClassException extends ezcBaseException
+{
+ /**
+ * Constructs a new ezcBaseInitInvalidCallbackClassException for the
$callbackClass.
+ *
+ * @param string $callbackClass
+ * @return void
+ */
+ function __construct( $callbackClass )
+ {
+ parent::__construct( "Class '{$callbackClass}' does not exist, or does
not implement the 'ezcBaseConfigurationInitializer' interface." );
+ }
+}
+?>
Propchange: trunk/Base/src/exceptions/invalid_callback_class.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Base/src/init.php
==============================================================================
--- trunk/Base/src/init.php [iso-8859-1] (original)
+++ trunk/Base/src/init.php [iso-8859-1] Wed Jul 4 17:02:14 2007
@@ -86,6 +86,21 @@
}
else
{
+ // Check if the passed classname actually exists
+ if ( !ezcBaseFeatures::classExists( $callbackClassname, true ) )
+ {
+ throw new ezcBaseInitInvalidCallbackClassException(
$callbackClassname );
+ }
+
+ // Check if the passed classname actually implements the
interface. We
+ // have to do that with reflection here unfortunately
+ $interfaceClass = new ReflectionClass(
'ezcBaseConfigurationInitializer' );
+ $handlerClass = new ReflectionClass( $callbackClassname );
+ if ( !$handlerClass->isSubclassOf( $interfaceClass ) )
+ {
+ throw new ezcBaseInitInvalidCallbackClassException(
$callbackClassname );
+ }
+
self::$callbackMap[$identifier] = $callbackClassname;
}
}
Modified: trunk/Base/tests/base_init_test.php
==============================================================================
--- trunk/Base/tests/base_init_test.php [iso-8859-1] (original)
+++ trunk/Base/tests/base_init_test.php [iso-8859-1] Wed Jul 4 17:02:14 2007
@@ -15,6 +15,32 @@
public function setUp()
{
testBaseInitClass::$instance = null;
+ }
+
+ public function testCallbackWithClassThatDoesNotExists()
+ {
+ try
+ {
+ ezcBaseInit::setCallback( 'testBaseInit', 'classDoesNotExist' );
+ $this->fail( "Expected exception not thrown." );
+ }
+ catch ( ezcBaseInitInvalidCallbackClassException $e )
+ {
+ $this->assertEquals( "Class 'classDoesNotExist' does not exist, or
does not implement the 'ezcBaseConfigurationInitializer' interface.",
$e->getMessage() );
+ }
+ }
+
+ public function testCallbackWithClassThatDoesNotImplementTheInterface()
+ {
+ try
+ {
+ ezcBaseInit::setCallback( 'testBaseInit', 'ezcBaseFeatures' );
+ $this->fail( "Expected exception not thrown." );
+ }
+ catch ( ezcBaseInitInvalidCallbackClassException $e )
+ {
+ $this->assertEquals( "Class 'ezcBaseFeatures' does not exist, or
does not implement the 'ezcBaseConfigurationInitializer' interface.",
$e->getMessage() );
+ }
}
public function testCallback1()
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components