コード例 #1
0
ファイル: Vonnegut.php プロジェクト: pete-otaqui/vonnegut
 /**
  * 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
 /**
  * Scan the files in the configured path for controllers
  *
  * To dynamically scan controllers from the source files
  * use PHP Reflection to find the controllers.
  *
  * The returning result is an array of Admin_Model_DbRow_Controller elements
  *
  * @return array
  */
 public function getControllers()
 {
     $resources = array();
     $directory = new DirectoryIterator($this->path);
     $CcFilter = new Zend_Filter_Word_CamelCaseToDash();
     while ($directory->valid()) {
         if ($directory->isFile() && !in_array($directory->getFilename(), $this->skip, TRUE)) {
             // load the file
             require_once $directory->getPathname();
             $reflect = new Zend_Reflection_File($directory->getPathName());
             $name = substr($reflect->getClass()->getName(), strrpos($reflect->getClass()->getName(), "_") + 1);
             $controller = new Admin_Model_DbRow_Controller(array('moduleName' => 'webdesktop', 'controllerName' => strtolower($name), 'virtual' => 1));
             $resources[] = $controller;
         }
         $directory->next();
     }
     return $resources;
 }
コード例 #3
0
ファイル: Vonnegut.php プロジェクト: bbc-frameworks/vonnegut
 /**
  * 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;
 }
コード例 #4
0
ファイル: Reader.php プロジェクト: BGCX262/zsoc-svn-to-git
 public function handleMethod($object, $method, $args = null)
 {
     $reflection = new Zend_Reflection_File($this->_file);
     $reflectionClass = $reflection->getClass(get_class($object));
     $reflectionMethod = $reflectionClass->getMethod($method);
     $docblock = $reflectionMethod->getDocblock();
     $tags = $docblock->getTags();
     foreach ($tags as $tag) {
         //$tag = new Zend_Reflection_Docblock_Tag();
         $name = ucfirst($tag->getName());
         $className = $name . 'Annotation';
         var_dump($className);
         try {
             $className = $this->getLoader()->load($className);
             $annotation = new $className();
             $annotation->handle($tag->getDescription(), $object, $args);
         } catch (Zend_Loader_PluginLoader_Exception $e) {
             throw $e;
         }
     }
 }
コード例 #5
0
foreach ($dir as $entry) {
    /* @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;
コード例 #6
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;
 }
コード例 #7
0
 /**
  * @group ZF-12155
  */
 public function testFileCanReflectFunctionsContainingVariablesEmbeddedInStringWithCurlyBraces()
 {
     $fileToRequire = dirname(__FILE__) . '/_files/FunctionWithEmbeddedVariableInString.php';
     require_once $fileToRequire;
     $reflectionFile = new Zend_Reflection_File($fileToRequire);
     $functions = $reflectionFile->getFunctions();
     $this->assertEquals(2, count($functions));
     $this->assertContainsOnly('Zend_Reflection_Function', $functions);
     $this->assertEquals('firstOne', $functions[0]->getName());
     $this->assertEquals('secondOne', $functions[1]->getName());
 }
コード例 #8
0
ファイル: FileTest.php プロジェクト: omusico/logica
 public function testFileCanReflectFileWithInterface()
 {
     $fileToRequire = dirname(__FILE__) . '/_files/TestSampleInterface.php';
     require_once $fileToRequire;
     $reflectionFile = new Zend_Reflection_File($fileToRequire);
     $class = $reflectionFile->getClass();
     $this->assertEquals('Zend_Reflection_TestSampleInterface', $class->getName());
     $this->assertTrue($class->isInterface());
 }
コード例 #9
0
ファイル: MVC.php プロジェクト: BGCX262/zupal-svn-to-git
 /**
  *
  * @param string $pParam
  * @return string
  */
 public function get_controller_class_object()
 {
     if (file_exists($this->controller_path())) {
         $zrf = new Zend_Reflection_File($this->controller_path());
         $crf = array_shift($zrf->getClass($this->controller_class_name()));
         $class = new Zend_CodeGenerator_Php_Class($crf);
     } else {
         $params = array('name' => $this->controller_class_name(), 'extendsClass' => 'Zupal_Controller_Abstract');
         if ($this->get_action()) {
             $mp = array('name' => $this->get_action() . 'Action');
             $action = new Zend_CodeGenerator_Php_Method($mp);
         }
         $class = new Zend_CodeGenerator_Php_Class($params);
     }
     return $class;
 }
コード例 #10
0
ファイル: FlagFlippers.php プロジェクト: omusico/logica
    $path = dirname($path);
} 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;