Beispiel #1
0
 public function generate()
 {
     if (!$this->isSourceDirty()) {
         return $this->getSourceContent();
     }
     $output = '';
     if ($this->_docblock) {
         $output .= $this->_docblock->generate();
     }
     if ($this->_isAbstract) {
         $output .= 'abstract ';
     }
     $output .= 'class ' . $this->_name;
     if ($this->_extendedClass) {
         $output .= ' extends ' . $this->_extendedClass;
     }
     if ($this->_implementedInterfaces) {
         $output .= ' implements ' . implode(', ', $this->_implementedInterfaces);
     }
     $output .= PHP_EOL . '{' . PHP_EOL . PHP_EOL;
     if ($this->_properties) {
         foreach ($this->_properties as $property) {
             $output .= $property->generate() . PHP_EOL . PHP_EOL;
         }
     }
     if ($this->_methods) {
         foreach ($this->_methods as $method) {
             $output .= $method->generate() . PHP_EOL . PHP_EOL;
         }
     }
     $output .= PHP_EOL . '}' . PHP_EOL;
     return $output;
 }
Beispiel #2
0
 public function generate()
 {
     if ($this->isSourceDirty() === false) {
         return $this->_sourceContent;
     }
     // start with the body (if there), or open tag
     $output = $this->_body ? $this->_body : '<?php' . PHP_EOL;
     // need to start with the body and then produce a php file
     // put file docblock in
     if ($this->_docblock) {
         $regex = preg_quote(self::$_markerDocblock, '#');
         if (preg_match('#' . $regex . '#', $output, $matches)) {
             $output = preg_replace('#' . $regex . '#', $this->_docblock->generate(), $output, 1);
         } else {
             $output .= $this->_docblock->generate() . PHP_EOL;
         }
     }
     // newline
     $output .= PHP_EOL;
     // process required files
     // @todo marker replacement for required files
     if ($this->_requiredFiles) {
         foreach ($this->_requiredFiles as $requiredFile) {
             $output .= 'require_once \'' . $requiredFile . '\';' . PHP_EOL;
         }
         $output .= PHP_EOL;
     }
     // process classes
     if ($this->_classes) {
         foreach ($this->_classes as $class) {
             $regex = str_replace('?', $class->getName(), self::$_markerClass);
             $regex = preg_quote($regex, '#');
             if (preg_match('#' . $regex . '#', $output, $matches)) {
                 $output = preg_replace('#' . $regex . '#', $class->generate(), $output, 1);
             } else {
                 $output .= $class->generate() . PHP_EOL;
             }
         }
         $output .= PHP_EOL;
     }
     return $output;
 }