rfc:autoloader_error_handling
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:autoloader_error_handling [2011/11/15 11:01] – akkie | rfc:autoloader_error_handling [2011/11/24 21:33] – akkie | ||
---|---|---|---|
Line 9: | Line 9: | ||
I use the following terms in the subsequent examples: | I use the following terms in the subsequent examples: | ||
- | * application | + | * project |
- | * autoloader(Exception) - for an autoloader | + | * autoloader(Exception) - for an autoloader |
- | * autoloader(Error) - for an autoloader | + | * autoloader(Error) - for an autoloader |
- | * autoloader(Silent) - for an autoloader | + | * autoloader(Silent) - for an autoloader |
- | * policy(Exception) - for a policy | + | * policy(Exception) - for a policy |
- | * policy(Error) - for a policy | + | * policy(Error) - for a policy |
- | * policy(Silent) - for a policy | + | * policy(Silent) - for a policy |
===== Introduction ===== | ===== Introduction ===== | ||
- | If working in a multi application | + | If working in a multi project |
===== Problems ===== | ===== Problems ===== | ||
- | | + | |
- | * If an application | + | **Notes: |
+ | |||
+ | * If an project | ||
* All autoloader implementations aren't compatible. They cannot load classes across projects. | * All autoloader implementations aren't compatible. They cannot load classes across projects. | ||
* The notation autoloader(...)-1 describes the position of the loader in the stack. The first position in this example. | * The notation autoloader(...)-1 describes the position of the loader in the stack. The first position in this example. | ||
- | - A third party library | + | **Examples: |
- | | + | |
- | | + | * A third party project |
- | | + | |
+ | | ||
+ | | ||
===== Requirements ===== | ===== Requirements ===== | ||
- | The consideration | + | As a consequence of the the previous problems now we have the following requirements which have to be fulfilled to work error-free across multiple projects. |
+ | |||
+ | * Autoloaders may not interfere with each other | ||
+ | * If I have an autoloader(Error) in project A and an autoloader(Exception) in project B then both autoloaders must be processed. Only if both autoloaders fails to load the class, a decision | ||
+ | * For the main project | ||
+ | * If an autoloader(Silent) fails to load a class from a sub project, it should be possible to change the behavior of the autoloader to the effect | ||
+ | * On the other side it should be possible to manipulate an autoloader(Exception) or autoloader(Error), | ||
+ | * Sub projects(libraries, | ||
+ | * If I have defined an autoloader(Exception) in my sub project, then it must be guaranteed that I can catch(in this sub project) exceptions thrown by this autoloader. Even if the main project changes the behavior of this autoloader. | ||
+ | |||
+ | ===== Solution ===== | ||
+ | |||
+ | **Stop interference between autoloaders** | ||
+ | |||
+ | To fulfill the first requirement the engine must catch all errors or exceptions until all autoloaders are executed. If the class could be loaded by one of the autoloaders, | ||
+ | |||
+ | **Allow manipulation of autoloader results** | ||
+ | |||
+ | After a class couldn' | ||
+ | |||
+ | As example: If the user sets the policy to: | ||
+ | |||
+ | * **POLICY_EXCEPTION**, | ||
+ | * **POLICY_ERROR**, | ||
+ | * **POLICY_SILENT**, | ||
+ | |||
+ | ** Sub projects must rely on their own policy** | ||
+ | |||
+ | A possible solution for this point would be the introduction of a namespace based autoloader. So a subproject can use its own autoloader mechanism which doesn' | ||
+ | |||
+ | |||
+ | ===== The big picture ===== | ||
+ | |||
+ | It would be a huge BC break to implement all this features. Therefore a new class could be implemented for the spl extension. The next code example describes a possible interface for this class. | ||
+ | <code php> | ||
+ | |||
+ | interface SplClassAutoloader { | ||
+ | |||
+ | const POLICY_ERROR = 1; | ||
+ | const POLICY_EXCEPTION = 2; | ||
+ | const POLICY_SILENT = 3; | ||
+ | |||
+ | /** | ||
+ | * Creates a new autoloader instance. | ||
+ | * | ||
+ | * @param int $policy The policy for this autoloader. | ||
+ | */ | ||
+ | | ||
+ | |||
+ | /** | ||
+ | * Registers a namespace for this autoloader. | ||
+ | * | ||
+ | * @param string $namespace The namespace to register. | ||
+ | */ | ||
+ | | ||
+ | |||
+ | /** | ||
+ | * Registers a class loader implementation. | ||
+ | * | ||
+ | * @param SplClassLoader $classLoader The class loader to register. | ||
+ | */ | ||
+ | | ||
+ | |||
+ | /** | ||
+ | * Hook the autoloader into the engine. | ||
+ | */ | ||
+ | | ||
+ | |||
+ | /** | ||
+ | * Remove the autoloader from engine. | ||
+ | */ | ||
+ | | ||
+ | } | ||
- | - Autoloaders must not interfere with each other | + | </ |
===== Changelog ===== | ===== Changelog ===== |