本文整理汇总了PHP中ReflectionMethod::getDocComment方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getDocComment方法的具体用法?PHP ReflectionMethod::getDocComment怎么用?PHP ReflectionMethod::getDocComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getDocComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public static function create($name, ReflectionMethod $method)
{
$result = new ckWsdlOperation();
$result->setName($name);
$params = ckDocBlockParser::parseParameters($method->getDocComment());
$headers = ckDocBlockParser::parseHeader($method->getDocComment());
$return = ckDocBlockParser::parseReturn($method->getDocComment());
$result->input = new ckWsdlMessage($name . 'Request');
foreach ($params as $param) {
$type = ckXsdType::get($param['type']);
$result->input->addPart(new ckWsdlPart($param['name'], $type));
}
foreach ($headers as $header) {
$type = ckXsdType::get($header['type']);
$type->setName($header['name']);
$type->setIsElement(true);
ckXsdType::set($header['name'], $type);
ckXsdType::set($header['type'], null);
$result->input->addPart(new ckWsdlPart($header['name'], $type, true));
}
if (!empty($return)) {
$type = ckXsdType::get($return['type']);
$result->output = new ckWsdlMessage($name . 'Response');
$result->output->addPart(new ckWsdlPart('return', $type));
}
return $result;
}
示例2: createClassDefinition
private function createClassDefinition()
{
$fullClassName = $this->getClass();
if (class_exists($fullClassName)) {
return;
}
$parts = explode('\\', $fullClassName);
$shortName = array_pop($parts);
$namespace = implode('\\', $parts);
$properties = [];
$parameters = [];
$body = [];
$getters = [];
foreach ($this->method->getParameters() as $parameter) {
$name = $parameter->getName();
$parameters[] = '$' . $name . ($parameter->isDefaultValueAvailable() ? ' = ' . var_export($parameter->getDefaultValue(), true) : '');
$body[] = '$this->' . $name . ' = $' . $name . ';';
$properties[] = 'private $' . $name . ';';
$hint = null;
$matches = [];
if ($parameter->getClass()) {
$hint = $parameter->getClass()->getName();
} else {
if (preg_match('/@param\\s+(\\S+)\\s+\\$' . $name . '/', $this->method->getDocComment(), $matches)) {
$hint = $matches[1];
}
}
$getters[] = ($hint ? "/**\n * @return " . $hint . "\n */\n " : '') . 'function get' . ucfirst($name) . '() { return $this->' . $name . '; }';
}
$code = ($namespace ? "namespace {$namespace};\n" : '') . "class {$shortName} {\n" . ' ' . implode("\n ", $properties) . "\n" . ' function __construct(' . implode(', ', $parameters) . ") {\n" . ' ' . implode("\n ", $body) . "\n" . ' }' . "\n" . ' ' . implode("\n ", $getters) . "\n" . '}';
eval($code);
}
示例3: getAnnotationReflection
/**
* @return IAnnotationReflection
*/
public function getAnnotationReflection()
{
if ($this->annotationReflection === null) {
$this->annotationReflection = AnnotationReflection::build($this->reflectionMethod->getDocComment());
}
return $this->annotationReflection;
}
示例4: __construct
public function __construct(Controller $controller, $action)
{
$this->controller = $controller;
$this->name = $action;
$this->reflector = new \ReflectionMethod($controller, $action);
$this->docComment = $this->reflector->getDocComment();
$this->parameters = $this->reflector->getParameters();
$this->initializeAttributes();
}
示例5: extractCommentWithoutLeadingShashesAndStars
public function extractCommentWithoutLeadingShashesAndStars()
{
$this->comment = explode("\n", $this->reflector->getDocComment());
foreach ($this->comment as &$line) {
$line = preg_replace('#^\\s*(/\\*+|\\*+/|\\*)\\s?#', '', $line);
}
$this->trimLeadingBlankLinesFromComment();
$this->trimTrailingBlankLinesFromComment();
}
示例6: getAnnotationType
private function getAnnotationType($annotation)
{
$matches = array();
$found = preg_match('/@' . $annotation . '\\s+(\\S+)/', $this->reflection->getDocComment(), $matches);
if (!$found) {
return new UnknownType();
}
$type = new TypeFactory($this->reflection->getDeclaringClass());
return $type->fromTypeHints(explode("|", $matches[1]));
}
示例7: description
/**
* @return string|null
*/
public function description()
{
$lines = array_slice(explode("\n", $this->method->getDocComment()), 1, -1);
$lines = array_map(function ($line) {
return ltrim($line, ' *');
}, $lines);
$lines = array_filter($lines, function ($line) {
return substr($line, 0, 1) != '@';
});
return $this->parser->parse(trim(implode("\n", $lines)));
}
示例8: getParsedDocs
/**
* Returns an array with parsed lines from PHPDoc.
*
* @return array
*/
protected function getParsedDocs()
{
$lines_docs = explode("\n", $this->reflection->getDocComment());
// Remove first line (/**)
array_shift($lines_docs);
// Remove last line (*/)
array_pop($lines_docs);
return array_map(function ($item) {
return ltrim($item, '* ');
}, $lines_docs);
}
示例9: handleMockSubscribers
public function handleMockSubscribers()
{
$reflection = new \ReflectionMethod(get_class($this), $this->getName());
if (false == ($mockFile = self::parseDocBlock($reflection->getDocComment()))) {
return;
}
$mockPath = self::parseDocBlock($reflection->getDocComment(), self::ANNOTATION_PATH);
$mockFilePath = $this->getTestFilePath($mockFile, $mockPath);
if (file_exists($mockFilePath)) {
$this->getClient()->getEventDispatcher()->removeListener('request.before_send', 'onRequestBeforeSend');
$this->addMockSubscriber($mockFilePath, 0);
}
}
示例10: loadParameters
/**
* This method is used to return an iteration-friendly list of parameters for a given method.
*
* @param string $className
* @param string $method
* @return array
*/
protected function loadParameters($className, $method)
{
// dig for data on the chosen method, in the chosen class
$parameters = array();
$reflectionMethod = new ReflectionMethod($className, $method);
$PHPDoc = $reflectionMethod->getDocComment();
/*
* This regex filters out all parameters, along with their PHPDoc. We use this instead
* of $reflectionMethod->getParameters(), since that returns ReflectionParameter objects
* that, rather shamefully, do not contain PHPDoc.
*/
preg_match_all('/@param[\\s\\t]+(.*)[\\s\\t]+\\$(.*)[\\s\\t]+(.*)$/Um', $PHPDoc, $matches);
if (array_key_exists(0, $matches) && empty($matches[0])) {
continue;
}
$phpdoc = array();
// we have to build up a custom stack of parameters
foreach ($matches[0] as $i => $row) {
$name = $matches[2][$i];
if ($name === 'language') {
continue;
}
$parameters[] = array('name' => $name, 'label' => $name . '-' . rand(1, 99999), 'optional' => substr_count($matches[2][$i], '[optional]') > 0, 'description' => $matches[3][$i]);
}
return $parameters;
}
示例11: testAutoload
/**
* Test valid public function/method names.
*
* @return void
*/
public function testAutoload()
{
try {
$object = new SQLI_CodeSniffer();
$this->assertTrue($object instanceof SQLI_CodeSniffer);
} catch (Exception $e) {
$this->fail('Autoload an SQLI_CodeSniffer Core class');
}
try {
$object = new PHP_CodeSniffer_Exception("test");
$this->assertTrue($object instanceof PHP_CodeSniffer_Exception);
} catch (Exception $e) {
$this->fail('Autoload a PHP_CodeSniffer Core class ' . $e->getMessage());
}
try {
$object = new Generic_Sniffs_Classes_DuplicateClassNameSniff();
// trick to recognize SQLI implemented sniffer
$method = new ReflectionMethod('Generic_Sniffs_Classes_DuplicateClassNameSniff', 'process');
$this->assertContains('SQLI_CodeSniffer_File', $method->getDocComment());
} catch (Exception $e) {
$this->fail('Autoload an SQLI_CodeSniffer sniffer');
}
try {
$object = new Generic_Sniffs_CodeAnalysis_UnnecessaryFinalModifierSniff();
// trick to recognize classical sniffer
$method = new ReflectionMethod('Generic_Sniffs_CodeAnalysis_UnnecessaryFinalModifierSniff', 'process');
$this->assertContains('PHP_CodeSniffer_File', $method->getDocComment());
} catch (Exception $e) {
$this->fail('Autoload a PHP_CodeSniffer sniffer');
}
}
示例12: getActionAuthorization
public function getActionAuthorization($class, $action)
{
$refMethod = new \ReflectionMethod($class, $action);
$doc = $refMethod->getDocComment();
preg_match_all("/@Authorize/", $doc, $authorizations);
return $authorizations[0];
}
示例13: getDocAttribute
public static function getDocAttribute(\ReflectionMethod $reflectionMethod, $attributeName)
{
$doc = $reflectionMethod->getDocComment();
if ($doc && preg_match('/\\* @' . $attributeName . '\\s?(.*)\\r?\\n/', $doc, $matches)) {
return $matches[1];
}
}
示例14: extractFeature
private function extractFeature(\PHPUnit_Framework_Test $test)
{
$class = get_class($test);
$method = $test->getName();
$reflection = new \ReflectionMethod($class, $method);
return $this->parseDocBlock($reflection->getDocComment(), '@feature');
}
示例15: generate
/**
*
* @param GenerationContext $context
* @param \Nucleus\IService\CommandLine\Consolable $annotation
*/
public function generate(GenerationContext $context, $annotation)
{
$docParser = new DocBlockParser();
$serviceName = $context->getServiceName();
$methodName = $context->getParsingContextName();
$definition = $context->getContainerBuilder()->getDefinition($serviceName);
$shortDesc = 'N/A';
$reflectedMethod = new \ReflectionMethod($definition->getClass(), $methodName);
$methodComment = $reflectedMethod->getDocComment();
if ($methodComment !== false) {
$docMethod = $docParser->parse($methodComment);
$shortDesc = $docMethod->getShortDesc();
}
$paramsArray = array();
$paramArrayComments = self::extractParamDocComment($docMethod->getTag('param'));
foreach ($reflectedMethod->getParameters() as $reflectionParameter) {
$paramComment = 'N/A';
if (isset($paramArrayComments[$reflectionParameter->getName()])) {
$paramComment = $paramArrayComments[$reflectionParameter->getName()]['comment'];
}
$paramsArray[$reflectionParameter->getName()]['optional'] = false;
if ($reflectionParameter->isDefaultValueAvailable()) {
$paramsArray[$reflectionParameter->getName()]['optional'] = true;
}
$paramsArray[$reflectionParameter->getName()]['comment'] = $paramComment;
}
if (!empty($annotation->name)) {
$name = $annotation->name;
} else {
$name = $serviceName . ':' . $methodName;
}
$context->getContainerBuilder()->getDefinition("console")->addMethodCall("addCommand", array("applicatiomName" => $name, "serviceName" => $serviceName, "methodName" => $methodName, "shortDesc" => $shortDesc, "paramsMethod" => $paramsArray));
}