setFinal() публичный Метод

Set the method final flag
public setFinal ( boolean $final = false ) : MethodGenerator
$final boolean
Результат MethodGenerator
Пример #1
0
 /**
  * Get methods
  *
  * @return void
  */
 protected function getClassMethods()
 {
     // Detect and set methods
     $methods = $this->getMethods();
     if (count($methods) > 0) {
         foreach ($methods as $value) {
             $methodExport = \ReflectionMethod::export($value->class, $value->name, true);
             // Get the method docblock
             if (strpos($methodExport, '/*') !== false && strpos($methodExport, '*/') !== false) {
                 $docBlock = substr($methodExport, strpos($methodExport, '/*'));
                 $docBlock = substr($docBlock, 0, strpos($methodExport, '*/') + 2);
             } else {
                 $docBlock = null;
             }
             $method = $this->getMethod($value->name);
             $visibility = 'public';
             if ($method->isPublic()) {
                 $visibility = 'public';
             } else {
                 if ($method->isProtected()) {
                     $visibility = 'protected';
                 } else {
                     if ($method->isPrivate()) {
                         $visibility = 'private';
                     }
                 }
             }
             $mthd = new Generator\MethodGenerator($value->name, $visibility, $method->isStatic());
             if (null !== $docBlock && strpos($docBlock, '/*') !== false) {
                 $mthd->setDocblock(Generator\DocblockGenerator::parse($docBlock, $mthd->getIndent()));
             }
             $mthd->setFinal($method->isFinal())->setAbstract($method->isAbstract());
             // Get the method parameters
             if (stripos($methodExport, 'Parameter') !== false) {
                 $matches = array();
                 preg_match_all('/Parameter \\#(.*)\\]/m', $methodExport, $matches);
                 if (isset($matches[0][0])) {
                     foreach ($matches[0] as $param) {
                         $name = null;
                         $value = null;
                         $type = null;
                         // Get name
                         $name = substr($param, strpos($param, '$'));
                         $name = trim(substr($name, 0, strpos($name, ' ')));
                         // Get value
                         if (strpos($param, '=') !== false) {
                             $value = trim(substr($param, strpos($param, '=') + 1));
                             $value = trim(substr($value, 0, strpos($value, ' ')));
                             $value = str_replace('NULL', 'null', $value);
                         }
                         // Get type
                         $type = substr($param, strpos($param, '>') + 1);
                         $type = trim(substr($type, 0, strpos($type, '$')));
                         if ($type == '') {
                             $type = null;
                         }
                         $mthd->addArgument($name, $value, $type);
                     }
                 }
             }
             // Get method body
             if (strpos($methodExport, '@@') !== false && file_exists($this->getFilename())) {
                 $lineNums = substr($methodExport, strpos($methodExport, '@@ ') + 3);
                 $start = trim(substr($lineNums, strpos($lineNums, ' ')));
                 $end = substr($start, strpos($start, ' - ') + 3);
                 $start = substr($start, 0, strpos($start, ' '));
                 $end = (int) $end;
                 if (is_numeric($start) && is_numeric($end)) {
                     $classLines = file($this->getFilename());
                     $body = null;
                     $start = $start + 1;
                     $end = $end - 1;
                     for ($i = $start; $i < $end; $i++) {
                         if (isset($classLines[$i])) {
                             if (substr($classLines[$i], 0, 8) == '        ') {
                                 $body .= substr($classLines[$i], 8);
                             } else {
                                 if (substr($classLines[$i], 0, 4) == '    ') {
                                     $body .= substr($classLines[$i], 4);
                                 } else {
                                     if (substr($classLines[$i], 0, 2) == "\t\t") {
                                         $body .= substr($classLines[$i], 2);
                                     } else {
                                         if (substr($classLines[$i], 0, 1) == "\t") {
                                             $body .= substr($classLines[$i], 1);
                                         } else {
                                             $body .= $classLines[$i];
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $mthd->setBody(rtrim($body), false);
                 }
             }
             $this->generator->code()->addMethod($mthd);
         }
     }
 }