Exemplo n.º 1
0
 function onInit() {
   parent::onInit();
   $demos = FDRouterForm::getDemos();
   $d = $this->getDocument();
   $d->setVariable('prev', $prev = $this->getPrev());
   if($prev) {
     $d->setVariable('prevTitle', $demos[$prev->getAction()]);
   }
   $d->setVariable('next', $next = $this->getNext());
   if($next) {
     $d->setVariable('nextTitle', $demos[$next->getAction()]);
   }
   $d->setVariable('routerForm', new FDRouterForm($this->getRequest()));
   $d->setVariable('viewSource', new Location('FDViewSource', array('demo'=>get_class($this))));
   $d->setVariable('viewTemplate', new Location('FDViewSource', array('demo'=>get_class($this), 'template'=>'1')));
 }
 function process() {
   parent::process();
   $d = $this->getDocument();
   
   // Here we manually create a region with a single text node that will keep
   // the highlighted source. Normally this should be done in a tag class!
   $r = new HTMLRegion(new HTMLRootNode(new HTMLDocument(new Responce(new Request())), '', 'x'), '', 'HTMLRegion', array('name'=>'source'));
   $r->addNode($n = new HTMLTextNode($r, null));
   
   $demo =  $this->getRequest()->getParameter('demo');
   
   // Here we will try to invoke the static method getDescription of the requested demo
   // If we fail, the description will be the name of the demo class
   try {
     $rc = new ReflectionClass($demo);
     $rm = $rc->getMethod('getDescription');
     $desc = $rm->invoke(null);
   } catch(ReflectionException $re) {
     $desc = $demo;
   }
   
   // See if the request was to show template
   if($this->getRequest()->getParameter('template')) {
     $p = $this->getPackage()->getResourcePath($demo) . '.html';
     $n->setRaw(true);
     $type = 'template';
   } else {
     $n->setRaw(true);
     $p = $this->getPackage()->getPath() . '/' . $demo . '.php5';
     $type = 'source';
   }
   
   // See if the file is accessible, if not, redirect to the Welcome to Demo page
   if(is_file($p)) {
     $n->setContent(highlight_file($p, true));
     $d->setVariable('demo', $demo);
     $d->setRegion('source', $r);
     $d->setVariable('type', $type);
     $d->setVariable('desc', $desc);
   } else {
     $this->getResponce()->relocate(new Location('FDWelcome'));
   }
 }