/** * 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; }
/** * @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()); }
public function testFileGetFunctionsReturnsFunctions() { $this->markTestSkipped('Regex in Zend_Reflection_File needs work in the function department'); $fileToRequire = dirname(__FILE__) . '/_files/FileOfFunctions.php'; require_once $fileToRequire; $reflectionFile = new Zend_Reflection_File($fileToRequire); echo count($reflectionFile->getFunctions()); }