Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package debug
- */
- namespace Crane\Extensions\Debug;
- use XSLTProcessor;
- use Crane\Libs\Delegate;
- use Crane\Libs\Dom;
- use Crane\Libs\Instance;
- // Announce this extension:
- Delegate\trigger('extension.announce', array(
- 'name' => 'Debug Controller',
- 'delegate' => 'extension.debug',
- 'file' => __FILE__
- ));
- /**
- * Initialize the Debug extension when Crane is ready.
- *
- * @param string $context
- * 'extension.debug.initialize'
- */
- Delegate\register('extension.debug.initialize');
- /**
- * Register the Debug controller class.
- *
- * @param string $context
- * 'extension.debug.register-controller'
- */
- Delegate\register('extension.debug.register-controller');
- /**
- * Get the extension directory.
- */
- function getDir() {
- return __DIR__;
- }
- /**
- * Get the extension URL.
- */
- function getUrl() {
- $href = \Crane\getServerUrl();
- $path = substr(getDir(), strlen(\Crane\getServerDir()));
- $path = ltrim($path, '/');
- return sprintf(
- '%s/%s',
- $href, $path
- );
- }
- /**
- * Transform a document with the debug template.
- *
- * @param Dom\Document $document
- */
- function transform(Dom\Document $document) {
- $stylesheet = new DOM\Document();
- $stylesheet->load(__DIR__ . '/assets/template.xsl');
- $xslt = new XSLTProcessor();
- $xslt->importStylesheet($stylesheet);
- return $xslt->transformToXML($document);
- }
- // Wait to be turned on:
- Delegate\listen('extension.debug.initialize', function() {
- Delegate\listen('extension.debug.register-controller', function() {
- $crane = Instance::current();
- if (isset($crane->parameters()->{'debug'})) {
- $crane->registerController(new Libs\Controller());
- }
- });
- });
- ?>
Add Comment
Please, Sign In to add comment