Guest User

Untitled

a guest
Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @package debug
  5. */
  6.  
  7. namespace Crane\Extensions\Debug;
  8. use XSLTProcessor;
  9. use Crane\Libs\Delegate;
  10. use Crane\Libs\Dom;
  11. use Crane\Libs\Instance;
  12.  
  13. // Announce this extension:
  14. Delegate\trigger('extension.announce', array(
  15. 'name' => 'Debug Controller',
  16. 'delegate' => 'extension.debug',
  17. 'file' => __FILE__
  18. ));
  19.  
  20. /**
  21. * Initialize the Debug extension when Crane is ready.
  22. *
  23. * @param string $context
  24. * 'extension.debug.initialize'
  25. */
  26. Delegate\register('extension.debug.initialize');
  27.  
  28. /**
  29. * Register the Debug controller class.
  30. *
  31. * @param string $context
  32. * 'extension.debug.register-controller'
  33. */
  34. Delegate\register('extension.debug.register-controller');
  35.  
  36. /**
  37. * Get the extension directory.
  38. */
  39. function getDir() {
  40. return __DIR__;
  41. }
  42.  
  43. /**
  44. * Get the extension URL.
  45. */
  46. function getUrl() {
  47. $href = \Crane\getServerUrl();
  48. $path = substr(getDir(), strlen(\Crane\getServerDir()));
  49. $path = ltrim($path, '/');
  50.  
  51. return sprintf(
  52. '%s/%s',
  53. $href, $path
  54. );
  55. }
  56.  
  57. /**
  58. * Transform a document with the debug template.
  59. *
  60. * @param Dom\Document $document
  61. */
  62. function transform(Dom\Document $document) {
  63. $stylesheet = new DOM\Document();
  64. $stylesheet->load(__DIR__ . '/assets/template.xsl');
  65.  
  66. $xslt = new XSLTProcessor();
  67. $xslt->importStylesheet($stylesheet);
  68.  
  69. return $xslt->transformToXML($document);
  70. }
  71.  
  72. // Wait to be turned on:
  73. Delegate\listen('extension.debug.initialize', function() {
  74. Delegate\listen('extension.debug.register-controller', function() {
  75. $crane = Instance::current();
  76.  
  77. if (isset($crane->parameters()->{'debug'})) {
  78. $crane->registerController(new Libs\Controller());
  79. }
  80. });
  81. });
  82.  
  83. ?>
Add Comment
Please, Sign In to add comment