示例#1
0
 /**
  * Reflects on a given file, parsing out classes and methods
  * for serialization.
  * 
  * @param string $path the path of a file to reflect.
  * @return object the serialized documentation object.
  */
 public function reflectFile($path)
 {
     // adding ./ to the beginning of relative paths fixes an issue including php files
     if (!preg_match('/^(?:[a-zA-Z]:\\|\\/)/', $path)) {
         $path = '.' . DIRECTORY_SEPARATOR . $path;
     }
     require_once $path;
     $filename = $filename = preg_replace("|^.*[\\\\/]|", $path, '');
     $serial = new StdClass();
     $serial->constants = array();
     $serial->variables = array();
     $serial->namespaces = array();
     $serial->classes = array();
     $serial->interfaces = array();
     $serial->functions = array();
     $file_reflector = new Zend_Reflection_File($path);
     $serial->tags = array();
     try {
         $db = $file_reflector->getDocBlock();
         $tags = $db->getTags();
         foreach ($tags as $tag) {
             $tagSerial = new StdClass();
             $tagSerial->name = $tag->getName();
             $tagSerial->description = $tag->getDescription();
             $serial->tags[] = $tagSerial;
         }
     } catch (Zend_Reflection_Exception $e) {
         $db = false;
     }
     $classes = $file_reflector->getClasses();
     foreach ($classes as $class) {
         $classSerial = $this->reflectClass($class);
         $isInterface = $classSerial->interface;
         unset($classSerial->interface);
         if ($isInterface == false) {
             $serial->classes[$classSerial->name] = $classSerial;
         } else {
             $serial->interfaces[$classSerial->name] = $classSerial;
         }
         unset($classSerial->name);
     }
     $functions = $file_reflector->getFunctions();
     foreach ($functions as $function) {
         $functionSerial = $this->reflectMethod($function);
         $serial->functions[$function->name] = $functionSerial;
     }
     $serial->meta = $this->_getMeta();
     $serial->meta->path = $path;
     return $serial;
 }
示例#2
0
 /**
  * Reflects on a given file parsing out classes and methods
  * for serialization.
  *
  * @param string $path the path of a file to reflect.
  * @return object the serialized documentation object.
  */
 public function reflectFile($path)
 {
     // adding ./ to the beginning of relative paths fixes an issue including php files
     if ($path[0] !== "/" && !preg_match('/^(?:[a-zA-Z]:\\|\\/)/', $path)) {
         $path = '.' . DIRECTORY_SEPARATOR . $path;
     }
     // don't require if the file has already been autoloaded.
     if (!in_array($path, get_included_files())) {
         require_once $path;
     }
     $filename = preg_replace("|^.*[\\\\/]|", $path, '');
     $serial = new Vonnegut_Namespace();
     $file_reflector = new Zend_Reflection_File($path);
     $serial->tags = array();
     try {
         $db = $file_reflector->getDocBlock();
         $tags = $db->getTags();
         foreach ($tags as $tag) {
             $tagSerial = new StdClass();
             $tagSerial->name = $tag->getName();
             $tagSerial->description = $tag->getDescription();
             $serial->tags[] = $tagSerial;
         }
     } catch (Zend_Reflection_Exception $e) {
         $db = false;
     }
     $classes = $file_reflector->getClasses();
     foreach ($classes as $class) {
         $classSerial = $this->reflectClass($class);
         $serial->classes->{$classSerial->name} = $classSerial;
     }
     /*
     $functions  = $file_reflector->getFunctions();
     foreach ( $functions as $function ) {
         $functionSerial = $this->reflectMethod($function);
         $serial->functions[$function->name] = $functionSerial;
     }
     */
     $serial->meta = $this->_getMeta();
     $serial->meta->path = $path;
     return $serial;
 }
 /* @var $entry DirectoryIterator */
 if (!$entry->isFile()) {
     continue;
 }
 $filename = $entry->getFilename();
 $match = array();
 if (!preg_match('/^(?P<controller>[A-Z][a-zA-Z]+?)Controller.php$/', $filename, $match)) {
     continue;
 }
 if ($limit && $limit != $match['controller']) {
     continue;
 }
 require_once $entry->getRealPath();
 $controller = $match['controller'];
 $r = new Zend_Reflection_File($entry->getRealPath());
 $classes = $r->getClasses();
 if (!count($classes)) {
     continue;
 }
 /* @var $class Zend_Reflection_Class */
 $class = $classes[0];
 $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
 if (!count($methods)) {
     continue;
 }
 foreach ($methods as $method) {
     /* @var $method Zend_Reflection_Method */
     $match = array();
     if (!preg_match('/^(?P<action>[a-z][A-Za-z]+?)Action$/', $method->getName(), $match)) {
         continue;
     }
示例#4
0
文件: File.php 项目: travisj/zf
 /**
  * fromReflection()
  *
  * @param Zend_Reflection_File $reflectionFile
  * @return Zend_CodeGenerator_Php_File
  */
 public static function fromReflection(Zend_Reflection_File $reflectionFile)
 {
     $file = new self();
     $file->setSourceContent($reflectionFile->getContents());
     $file->setSourceDirty(false);
     $body = $reflectionFile->getContents();
     // @todo this whole area needs to be reworked with respect to how body lines are processed
     foreach ($reflectionFile->getClasses() as $class) {
         $file->setClass(Zend_CodeGenerator_Php_Class::fromReflection($class));
         $classStartLine = $class->getStartLine(true);
         $classEndLine = $class->getEndLine();
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
             if ($lineNum == $classStartLine) {
                 $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass);
                 //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
                 $lineNum = $classEndLine;
             } else {
                 $bodyReturn[] = $bodyLines[$lineNum - 1];
                 // adjust for index -> line conversion
             }
         }
         $body = implode("\n", $bodyReturn);
         unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
     }
     if ($reflectionFile->getDocComment() != '') {
         $docblock = $reflectionFile->getDocblock();
         $file->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($docblock));
         $bodyLines = explode("\n", $body);
         $bodyReturn = array();
         for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) {
             if ($lineNum == $docblock->getStartLine()) {
                 $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock);
                 //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */';
                 $lineNum = $docblock->getEndLine();
             } else {
                 $bodyReturn[] = $bodyLines[$lineNum - 1];
                 // adjust for index -> line conversion
             }
         }
         $body = implode("\n", $bodyReturn);
         unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine);
     }
     $file->setBody($body);
     return $file;
 }
示例#5
0
} else {
    if (($dir = opendir($path)) !== false) {
        while (($file = readdir($dir)) !== false) {
            if (fnmatch('*.php', $file) && $file !== 'ErrorController.php') {
                $files[] = $file;
            }
        }
        closedir($dir);
    }
}
$resources = array();
foreach ($files as $file) {
    $filepath = $path . DIRECTORY_SEPARATOR . $file;
    require_once $filepath;
    $reflectionFile = new Zend_Reflection_File($filepath);
    foreach ($reflectionFile->getClasses() as $class) {
        $classInfo = array('description' => $class->getDocblock()->getShortDescription(), 'name' => strtolower($module) . '-' . App_Inflector::convertControllerName($class->getName()), 'methods' => array());
        foreach ($class->getMethods() as $method) {
            if (substr($method->getName(), -6) == 'Action') {
                $classInfo['methods'][] = array('description' => $method->getDocblock()->getShortDescription(), 'name' => App_Inflector::convertActionName($method->getName()));
            }
        }
        $resources[] = $classInfo;
    }
}
$flagFlippers = App_Cli_FlagFlippers::getInstance();
$inserts = $flagFlippers->generateInserts($resources);
if (empty($inserts)) {
    echo 'No new flags / privileges found.';
    exit;
}