code_junkie

Dynamically Create Subclass

Nov 13th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // Class extension to be evaluated
  2. $extension = 'class '.$class.' extends '.$class.'_Core { }';
  3.  
  4. // Start class analysis
  5. $core = new ReflectionClass($class.'_Core');
  6.  
  7. if ($core->isAbstract())
  8. {
  9. // Make the extension abstract
  10. $extension = 'abstract '.$extension;
  11. }
  12.  
  13. // Transparent class extensions are handled using eval. This is
  14. // a disgusting hack, but it gets the job done.
  15. eval($extension);
  16.  
  17. if(true)
  18. {
  19. class foo
  20. {
  21. // methods
  22. }
  23. }
  24.  
  25. $proxyClassOnDisk = '/path/to/proxyCodeCache/' . $clazz .'.cachedProxyClass';
  26. if ( ! file_exists($proxyClassOnDisk) ) {
  27. // Generate the proxy and put it into the proxy class on disk.
  28. file_put_contents($proxyClassOnDisk, $this->generateProxy($object));
  29. }
  30. require_once($proxyClassOnDisk);
Add Comment
Please, Sign In to add comment