本文整理汇总了PHP中ReflectionFunction::getDocComment方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getDocComment方法的具体用法?PHP ReflectionFunction::getDocComment怎么用?PHP ReflectionFunction::getDocComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::getDocComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: from
/**
* @return self
*/
public static function from($from) : self
{
if (is_string($from) && strpos($from, '::')) {
$from = new \ReflectionMethod($from);
} elseif (is_array($from)) {
$from = new \ReflectionMethod($from[0], $from[1]);
} elseif (!$from instanceof \ReflectionFunctionAbstract) {
$from = new \ReflectionFunction($from);
}
$method = new static();
$method->name = $from->isClosure() ? NULL : $from->getName();
foreach ($from->getParameters() as $param) {
$method->parameters[$param->getName()] = Parameter::from($param);
}
if ($from instanceof \ReflectionMethod) {
$method->static = $from->isStatic();
$method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
$method->final = $from->isFinal();
$method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
$method->body = $from->isAbstract() ? FALSE : '';
}
$method->returnReference = $from->returnsReference();
$method->variadic = PHP_VERSION_ID >= 50600 && $from->isVariadic();
$method->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
$returnType = $from->getReturnType();
$method->returnType = $returnType->isBuiltin() ? (string) $returnType : '\\' . $returnType;
}
return $method;
}
示例2: getAnnotationReflection
/**
* @return IAnnotationReflection
*/
public function getAnnotationReflection()
{
if ($this->annotationReflection === null) {
$this->annotationReflection = AnnotationReflection::build($this->reflectionFunction->getDocComment());
}
return $this->annotationReflection;
}
示例3: testParse
public function testParse()
{
$fn = function ($param1 = true, $param2 = 'bho') {
// function body
};
$reflector = new \ReflectionFunction($fn);
$comment = $reflector->getDocComment();
$parser = new DocBlockParser($comment);
$this->assertEquals('Anonymous function description splitted in two lines', $parser->getDescription());
$this->assertFalse($parser->hasParam('param4'));
$this->assertTrue($parser->hasParam('param1'));
$param1 = $parser->getParam('param1');
$this->assertEquals('param1', $param1['name']);
$this->assertEquals('bool', $param1['type']);
$this->assertEquals('parameter1 description', $param1['description']);
$this->assertEquals('parameter1 description', $parser->getParamDescription('param1'));
$this->assertEquals('', $parser->getParamDescription('param4'));
$params = $parser->getParams();
$this->assertTrue(is_array($params));
$this->assertEquals(3, count($params));
$this->assertEquals('param1', $params['param1']['name']);
$this->assertEquals('bool', $params['param1']['type']);
$this->assertEquals('parameter1 description', $params['param1']['description']);
$this->assertEquals('param3', $params['param3']['name']);
$this->assertEquals('string', $params['param3']['type']);
$this->assertEquals('', $params['param3']['description']);
}
示例4: routesAction
/**
* Show page documenting all routes available in this app.
*
* @param \Silex\Application $app
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function routesAction(\Silex\Application $app)
{
/**
* @var \Symfony\Component\Routing\RouteCollection $routes
*/
$routes = $app['routes'];
$routes = self::pullRoutesFromCollection($routes);
$docs = array();
foreach ($routes as $route) {
/**
* @var \Silex\Route $route
*/
$controller = $route->getDefault('_controller');
$docKey = $route->getPattern();
if (is_array($controller)) {
$method = new \ReflectionMethod($controller[0], $controller[1]);
} elseif ($controller instanceof \Closure) {
$method = new \ReflectionFunction($controller);
} else {
$docs[$docKey] = '';
continue;
}
$docs[$docKey] = self::parseSummaryFromDocComment($method->getDocComment());
}
$bootstrap = $_SERVER['SCRIPT_FILENAME'];
return $app['twig']->render('list-routes.html.twig', array('routes' => $routes, 'docs' => $docs, 'bootstrap' => $bootstrap));
}
示例5: getDocComment
/**
* Returns the doc comment for this function
*
* @return string Doc comment for this function
* @since PHP 5.1.0
*/
public function getDocComment()
{
if ($this->reflectionSource instanceof ReflectionFunction) {
return $this->reflectionSource->getDocComment();
} else {
return parent::getDocComment();
}
}
示例6: update_script_selection_form
function update_script_selection_form()
{
$form = array();
$count = 0;
$form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE);
// Ensure system.module's updates appear first
$form['start']['system'] = array();
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
foreach ($modules as $module => $schema_version) {
$pending = array();
$updates = drupal_get_schema_versions($module);
// Skip incompatible module updates completely, otherwise test schema versions.
if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
// module_invoke returns NULL for nonexisting hooks, so if no updates
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
$form['start'][$module] = array('#title' => $module, '#item' => '<em>' . $module . '</em> module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.', '#prefix' => '<div class="warning">', '#suffix' => '</div>');
continue;
}
$updates = drupal_map_assoc($updates);
foreach (array_keys($updates) as $update) {
if ($update > $schema_version) {
// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
$pending[] = "{$update} - {$description}";
if (!isset($default)) {
$default = $update;
}
}
}
if (!empty($pending)) {
if (!isset($default)) {
$default = $schema_version;
}
$form['start'][$module] = array('#type' => 'hidden', '#value' => $default);
$form['start'][$module . '_updates'] = array('#markup' => theme('item_list', $pending, $module . ' module'));
}
}
unset($default);
$count = $count + count($pending);
}
if (empty($count)) {
drupal_set_message(t('No pending updates.'));
unset($form);
$form['links'] = array('#markup' => theme('item_list', update_helpful_links()));
} else {
$form['help'] = array('#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', '#weight' => -5);
$form['start']['#title'] = strtr('!num pending updates', array('!num' => $count));
$form['has_js'] = array('#type' => 'hidden', '#default_value' => FALSE);
$form['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates');
}
return $form;
}
示例7: testFunction
/**
* Test a function or method for a given class
*
* @dataProvider dataReflectionTestFunctions
*
* @param string|array $function The function name, or array of class name and method name.
*/
public function testFunction($function)
{
// We can't pass Reflector objects in here because they get printed out as the
// data set when a test fails
if (is_array($function)) {
$ref = new \ReflectionMethod($function[0], $function[1]);
$name = $function[0] . '::' . $function[1] . '()';
} else {
$ref = new \ReflectionFunction($function);
$name = $function . '()';
}
$docblock = new \phpDocumentor\Reflection\DocBlock($ref);
$doc_comment = $ref->getDocComment();
$method_params = $ref->getParameters();
$doc_params = $docblock->getTagsByName('param');
$this->assertNotFalse($doc_comment, sprintf('The docblock for `%s` should not be missing.', $name));
$this->assertNotEmpty($docblock->getShortDescription(), sprintf('The docblock description for `%s` should not be empty.', $name));
$this->assertSame(count($method_params), count($doc_params), sprintf('The number of @param docs for `%s` should match its number of parameters.', $name));
// @TODO check description ends in full stop
foreach ($method_params as $i => $param) {
$param_doc = $doc_params[$i];
$description = $param_doc->getDescription();
$content = $param_doc->getContent();
// @TODO decide how to handle variadic functions
// ReflectionParameter::isVariadic — Checks if the parameter is variadic
$is_hash = 0 === strpos($description, '{') && strlen($description) - 1 === strrpos($description, '}');
if ($is_hash) {
$lines = explode("\n", $description);
$description = $lines[1];
}
$this->assertNotEmpty($description, sprintf('The @param description for the `%s` parameter of `%s` should not be empty.', $param_doc->getVariableName(), $name));
list($param_doc_type, $param_doc_name) = preg_split('#\\s+#', $param_doc->getContent());
$this->assertSame('$' . $param->getName(), $param_doc_name, sprintf('The @param name for the `%s` parameter of `%s` is incorrect.', '$' . $param->getName(), $name));
if ($param->isArray()) {
$this->assertNotFalse(strpos($param_doc_type, 'array'), sprintf('The @param type hint for the `%s` parameter of `%s` should state that it accepts an array.', $param_doc->getVariableName(), $name));
}
if (($param_class = $param->getClass()) && 'stdClass' !== $param_class->getName()) {
$this->assertNotFalse(strpos($param_doc_type, $param_class->getName()), sprintf('The @param type hint for the `%s` parameter of `%s` should state that it accepts an object of type `%s`.', $param_doc->getVariableName(), $name, $param_class->getName()));
}
$this->assertFalse(strpos($param_doc_type, 'callback'), sprintf('`callback` is not a valid type. `callable` should be used in the @param type hint for the `%s` parameter of `%s` instead.', $param_doc->getVariableName(), $name));
if ($param->isCallable()) {
$this->assertNotFalse(strpos($param_doc_type, 'callable'), sprintf('The @param type hint for the `%s` parameter of `%s` should state that it accepts a callable.', $param_doc->getVariableName(), $name));
}
if ($param->isOptional()) {
$this->assertNotFalse(strpos($description, 'Optional.'), sprintf('The @param description for the optional `%s` parameter of `%s` should state that it is optional.', $param_doc->getVariableName(), $name));
} else {
$this->assertFalse(strpos($description, 'Optional.'), sprintf('The @param description for the required `%s` parameter of `%s` should not state that it is optional.', $param_doc->getVariableName(), $name));
}
if ($param->isDefaultValueAvailable() && array() !== $param->getDefaultValue()) {
$this->assertNotFalse(strpos($description, 'Default '), sprintf('The @param description for the `%s` parameter of `%s` should state its default value.', $param_doc->getVariableName(), $name));
} else {
$this->assertFalse(strpos($description, 'Default '), sprintf('The @param description for the `%s` parameter of `%s` should not state a default value.', $param_doc->getVariableName(), $name));
}
}
}
示例8: docBlock
public static function docBlock($function)
{
if (preg_match('/^(.*)::(.*)$/', $function, $matches)) {
$reflection = new \ReflectionMethod($matches[1], $matches[2]);
} elseif (preg_match('/([A-Z]+[\\w\\-\\d]+)$/', $function, $matches)) {
$reflection = new \ReflectionClass('\\' . $function);
} else {
$reflection = new \ReflectionFunction($function);
}
return "<h3>{$function}</h3><br>" . preg_replace('/\\n/', ' <br>', $reflection->getDocComment());
}
示例9: buildFromCode
/**
* @param callable $code
*/
public function buildFromCode($code)
{
$this->assertCallable($code);
$this->setCode($code);
$reflector = new \ReflectionFunction($code);
$parser = new DocBlockParser($reflector->getDocComment());
$this->setDescription($parser->getDescription());
foreach ($reflector->getParameters() as $parameter) {
$description = $parser->getParamDescription($parameter->getName());
$this->addParameter($parameter, $description);
}
}
示例10: setupFunction
protected function setupFunction($function)
{
if (is_array($function)) {
$ref = new \ReflectionMethod($function[0], $function[1]);
$this->function_name = $function[0] . '::' . $function[1] . '()';
} else {
$ref = new \ReflectionFunction($function);
$this->function_name = $function . '()';
}
$this->docblock = new \phpDocumentor\Reflection\DocBlock($ref);
$this->doc_comment = $ref->getDocComment();
$this->method_params = $ref->getParameters();
$this->doc_params = $this->docblock->getTagsByName('param');
}
示例11: getAnnotations
/**
* Fetches all the annotations for a given suite and test block.
*
* @note repeated names are sorted with deepest first
*
* @param Spec\TestSuite $suite
* @param Closure $cb
* @return array
*/
protected function getAnnotations(Spec\TestSuite $suite, $cb)
{
$anns = array();
// Get annotations from the callback function first
$reflFn = new \ReflectionFunction($cb);
$docblock = $reflFn->getDocComment();
if (preg_match_all('/@(?P<name>[A-Za-z_-]+)(?:[ \\t]+(?P<value>.*?))?(\\*\\/|$)/m', $docblock, $matches)) {
$numMatches = count($matches[0]);
for ($i = 0; $i < $numMatches; ++$i) {
$anns[$matches['name'][$i]][] = trim($matches['value'][$i]);
}
}
// Fetch annotations from parent suites (deepest first)
do {
$anns = array_merge_recursive($anns, $suite->getAnnotations());
} while ($suite = $suite->getParent());
return $anns;
}
示例12: fromReflection
public static function fromReflection(\ReflectionFunction $ref)
{
$function = new static();
if (false === ($pos = strrpos($ref->name, '\\'))) {
$function->setName(substr($ref->name, $pos + 1));
$function->setNamespace(substr($ref->name, $pos));
} else {
$function->setName($ref->name);
}
$function->referenceReturned = $ref->returnsReference();
$function->docblock = ReflectionUtils::getUnindentedDocComment($ref->getDocComment());
foreach ($ref->getParameters() as $refParam) {
assert($refParam instanceof \ReflectionParameter);
$param = PhpParameter::fromReflection($refParam);
$function->addParameter($param);
}
return $function;
}
示例13: getDocCommentRaw
/**
* DocCommentを取得する
*
* @param mixed $object
* @return string
*/
public static function getDocCommentRaw($object)
{
if ($object instanceof ReflectionMethod || $object instanceof ReflectionClass || $object instanceof ReflectionFunction || $object instanceof Injection\Spec) {
return $object->getDocComment();
}
// オブジェクトを判定
if (is_callable($object) && is_array($object)) {
$rs = new ReflectionMethod($object[0], $object[1]);
return $rs->getDocComment();
}
if ($object instanceof Closure) {
$rs = new ReflectionFunction($object);
return $rs->getDocComment();
}
if (is_array($object) && is_callable($object[count($object) - 1])) {
return self::getDocCommentRaw($object[count($object) - 1]);
}
if (is_object($object)) {
$rs = new ReflectionClass($object);
return $rs->getDocComment();
}
throw new Exception\CantRetriveDocComment($object);
}
示例14: introspectFunction
/**
* Introspect a php callable and its phpdoc block and extract information about its signature
*
* @param callable $callable
* @param string $plainFuncName
* @return array|false
*/
protected function introspectFunction($callable, $plainFuncName)
{
// start to introspect PHP code
if (is_array($callable)) {
$func = new \ReflectionMethod($callable[0], $callable[1]);
if ($func->isPrivate()) {
error_log('XML-RPC: ' . __METHOD__ . ': method to be wrapped is private: ' . $plainFuncName);
return false;
}
if ($func->isProtected()) {
error_log('XML-RPC: ' . __METHOD__ . ': method to be wrapped is protected: ' . $plainFuncName);
return false;
}
if ($func->isConstructor()) {
error_log('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the constructor: ' . $plainFuncName);
return false;
}
if ($func->isDestructor()) {
error_log('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the destructor: ' . $plainFuncName);
return false;
}
if ($func->isAbstract()) {
error_log('XML-RPC: ' . __METHOD__ . ': method to be wrapped is abstract: ' . $plainFuncName);
return false;
}
/// @todo add more checks for static vs. nonstatic?
} else {
$func = new \ReflectionFunction($callable);
}
if ($func->isInternal()) {
// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
// instead of getparameters to fully reflect internal php functions ?
error_log('XML-RPC: ' . __METHOD__ . ': function to be wrapped is internal: ' . $plainFuncName);
return false;
}
// retrieve parameter names, types and description from javadoc comments
// function description
$desc = '';
// type of return val: by default 'any'
$returns = Value::$xmlrpcValue;
// desc of return val
$returnsDocs = '';
// type + name of function parameters
$paramDocs = array();
$docs = $func->getDocComment();
if ($docs != '') {
$docs = explode("\n", $docs);
$i = 0;
foreach ($docs as $doc) {
$doc = trim($doc, " \r\t/*");
if (strlen($doc) && strpos($doc, '@') !== 0 && !$i) {
if ($desc) {
$desc .= "\n";
}
$desc .= $doc;
} elseif (strpos($doc, '@param') === 0) {
// syntax: @param type $name [desc]
if (preg_match('/@param\\s+(\\S+)\\s+(\\$\\S+)\\s*(.+)?/', $doc, $matches)) {
$name = strtolower(trim($matches[2]));
//$paramDocs[$name]['name'] = trim($matches[2]);
$paramDocs[$name]['doc'] = isset($matches[3]) ? $matches[3] : '';
$paramDocs[$name]['type'] = $matches[1];
}
$i++;
} elseif (strpos($doc, '@return') === 0) {
// syntax: @return type [desc]
if (preg_match('/@return\\s+(\\S+)(\\s+.+)?/', $doc, $matches)) {
$returns = $matches[1];
if (isset($matches[2])) {
$returnsDocs = trim($matches[2]);
}
}
}
}
}
// execute introspection of actual function prototype
$params = array();
$i = 0;
foreach ($func->getParameters() as $paramObj) {
$params[$i] = array();
$params[$i]['name'] = '$' . $paramObj->getName();
$params[$i]['isoptional'] = $paramObj->isOptional();
$i++;
}
return array('desc' => $desc, 'docs' => $docs, 'params' => $params, 'paramDocs' => $paramDocs, 'returns' => $returns, 'returnsDocs' => $returnsDocs);
}
示例15: logDeprecatedFunction
/**
* Logs a call to a deprecated function.
* The log message will be taken from the annotation.
* @return void
*/
public static function logDeprecatedFunction()
{
if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
return;
}
// This require_once is needed for deprecation calls
// thrown early during bootstrap, if the autoloader is
// not instantiated yet. This can happen for example if
// ext_localconf triggers a deprecation.
require_once 'utility/class.t3lib_utility_debug.php';
$trail = debug_backtrace();
if ($trail[1]['type']) {
$function = new ReflectionMethod($trail[1]['class'], $trail[1]['function']);
} else {
$function = new ReflectionFunction($trail[1]['function']);
}
$msg = '';
if (preg_match('/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
$msg = $match[1];
}
// trigger PHP error with a short message: <function> is deprecated (called from <source>, defined in <source>)
$errorMsg = 'Function ' . $trail[1]['function'];
if ($trail[1]['class']) {
$errorMsg .= ' of class ' . $trail[1]['class'];
}
$errorMsg .= ' is deprecated (called from ' . $trail[1]['file'] . '#' . $trail[1]['line'] . ', defined in ' . $function->getFileName() . '#' . $function->getStartLine() . ')';
// write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)
$logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function'];
$logMsg .= '() - ' . $msg . ' - ' . t3lib_utility_Debug::debugTrail();
$logMsg .= ' (' . substr($function->getFileName(), strlen(PATH_site)) . '#' . $function->getStartLine() . ')';
self::deprecationLog($logMsg);
}