Beispiel #1
0
 public function testMethod()
 {
     $class = new ReflectionClass('Psc\\Code\\Generate\\TestClass2');
     $factory = GMethod::reflectorFactory($class->getMethod('factory'));
     $method2 = GMethod::reflectorFactory($class->getMethod('method2'));
     $banane = GMethod::reflectorFactory($class->getMethod('banane'));
     $parameters = $method2->getParameters();
     foreach ($parameters as $param) {
         $this->assertInstanceOf('Psc\\Code\\Generate\\GParameter', $param);
     }
     $cr = "\n";
     $factoryCode = 'public static function factory(TestHintMethod $dunno) {' . $cr;
     $factoryCode .= '}';
     $this->assertEquals(0, count($factory->getBodyCode()));
     $this->assertEquals('', $factory->getBody(0));
     $method2Code = 'public function method2($num, Array $p1, stdClass $std = NULL, $bun = array()) { // does matter' . $cr;
     $body = NULL;
     $body .= '$bimbam = \'pling\';' . $cr;
     $body .= $cr;
     $body .= '// anotherinline comment' . $cr;
     $body .= 'return \'schnurpsel\';' . $cr;
     $method2Code .= S::indent($body, 2, $cr);
     $method2Code .= '}';
     $method2->getBodyCode();
     // 2 mal holen darf die anzahl nicht verdoppeln
     $this->assertEquals(4, count($method2->getBodyCode()));
     /* method2 method */
     $this->assertEquals($body, $method2->getBody(0), \Webforge\Common\String::debugEquals($body, $method2->getBody(0)));
     $this->assertEquals($method2Code, $method2->php(), \Webforge\Common\String::debugEquals($method2Code, $method2->php()));
     /* Factory method */
     $this->assertEquals(TRUE, $factory->isStatic());
     $this->assertEquals($factoryCode, $factory->php(), \Webforge\Common\String::debugEquals($factoryCode, $factory->php()));
     $this->assertEquals('abstract public function banane();', $banane->php(), sprintf("output: '%s'", $banane->php()));
 }
Beispiel #2
0
 protected function phpBody($baseIndent = 0)
 {
     $php = NULL;
     $cr = "\n";
     // das hier zuerst ausführen, damit möglicherweise cbraceComment noch durchrs extracten gesetzt wird
     $body = $this->getBody($baseIndent + 2, $cr);
     // Body direkt + 2 einrücken
     $php .= ' {';
     // das nicht einrücken, weil das direkt hinter der signatur steht
     if ($this->cbraceComment != NULL) {
         // inline comment wie dieser
         $php .= ' ' . $this->cbraceComment;
     }
     $php .= $cr;
     // jetzt beginnt der eigentlich body
     $php .= $body;
     $php .= S::indent('}', $baseIndent, $cr);
     // das auf Base einrücken
     return $php;
 }
Beispiel #3
0
 /**
  * Gibt das Template als String zurück
  *
  * @return string
  */
 public function get()
 {
     $__html = NULL;
     if ($this->validate()) {
         /* dies ersetzt variablen die durch das template verändert werden können: $$__varName */
         extract((array) $this->vars);
         $tpl = $this;
         /* get as String */
         try {
             ob_start();
             require $this->file;
             $__html = ob_get_contents();
             ob_end_clean();
         } catch (\Psc\Exception $e) {
             $e->setMessage(sprintf('in TPL(%s): %s', $this->getDisplayName(), $e->getMessage()));
             throw $e;
         }
         /* testen ob noch variablen übrig sind */
         //if (DEV) {
         //  $__matches = array();
         //  if (preg_match_all('/\{\$([a-zA-Z_0-9]*)\}/',$__html,$__matches,PREG_SET_ORDER) > 0) {
         //    foreach ($__matches as $__match) {
         //    //throw new Exception('in Template: '.$__fileName.' ist Variable "'.$__match[1].'" nicht definiert');
         //      trigger_error('in Template: '.$__fileName.' wird die Variable "'.$__match[1].'" nicht definiert (die von einem anderen Template benötigt wird)',E_USER_WARNING);
         //    }
         //  }
         //}
         if ($this->indent !== NULL) {
             $__html = S::indent($__html, $this->indent);
         }
     }
     return $__html;
 }
Beispiel #4
0
 public function phpDocBlock($baseIndent = 0)
 {
     if (isset($this->docBlock)) {
         return \Webforge\Common\String::indent($this->docBlock->toString(), $baseIndent);
     }
 }
Beispiel #5
0
 public function html()
 {
     /* js chains */
     if ($this->getOption('closeTag', TRUE) == TRUE) {
         foreach ($this->jsChain as $code) {
             jQuery::chain($this, $code);
         }
         $this->jsChain = array();
     }
     $tagIndent = (int) $this->getOption('tag.indent', 0);
     $indent = max((int) $this->getOption('indent', 0), (int) $this->getOption('content.indent', 0));
     if ($this->tag == 'textarea' || $this->tag == 'pre') {
         $indent = $tagIndent = 0;
     }
     $html = '<' . HTML::esc($this->tag) . $this->htmlAttributes();
     if ($this->getOption('selfClosing', FALSE)) {
         /* self closing element ohne inhalt */
         $html .= ' />' . ($this->getOption('br.selfClosing', FALSE) ? "\n" : NULL);
     } elseif ($this->getOption('onlyOpen', FALSE)) {
         /* nur open-tag schließen, kein content, kein schließendes tag */
         $html .= '>' . ($this->getOption('br.onlyOpen', FALSE) ? "\n" : NULL);
     } else {
         /* open-tag schließen, content, schließendes tag */
         $html .= '>' . ($this->getOption('br.openTag', FALSE) ? "\n" : NULL) . ($this->getOption('br.beforeContent', FALSE) ? "\n" : NULL) . ($indent > 0 ? S::indent($this->htmlContent(), $indent) : $this->htmlContent()) . ($this->getOption('br.afterContent', FALSE) ? "\n" : NULL);
         if ($this->getOption('closeTag', TRUE)) {
             $html .= '</' . HTML::esc($this->tag) . '>' . ($this->getOption('br.closeTag', FALSE) ? "\n" : NULL);
         }
     }
     if ($tagIndent > 0) {
         $html = S::indent($html, $tagIndent, "\n");
     } else {
         $html;
     }
     if (isset($this->template)) {
         $contentsArray = array_merge($this->convertContent(), $this->convertTemplateContent());
         $contentsArray['self'] = $html;
         $html = str_replace(array_map(create_function('$a', 'return "%".$a."%"; '), array_keys($contentsArray)), array_values($contentsArray), $this->template);
     }
     return $html;
 }
Beispiel #6
0
 protected function indent($code, $relative = 0)
 {
     return S::indent($code, ($relative + $this->indent) * 2);
 }