本文整理汇总了PHP中ReflectionFunction::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getName方法的具体用法?PHP ReflectionFunction::getName怎么用?PHP ReflectionFunction::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function_signature
function function_signature($function_name)
{
try {
$rf = new ReflectionFunction($function_name);
} catch (Exception $e) {
return null;
}
$params = array();
$unknown_param_name = 'unk0';
foreach ($rf->getParameters() as $rp) {
$param = $rp->isPassedByReference() ? '&' : '';
$name = $rp->getName();
if ($name == '') {
$name = '$' . $unknown_param_name;
$unknown_param_name++;
} elseif ($name == '...') {
} else {
$name = '$' . $name;
}
$param .= $name;
if ($rp->isOptional()) {
$param .= ' = null';
// is there better way to show that it's optional?
}
$params[] = $param;
}
$str = "";
$str .= $rf->returnsReference() ? '&' : '';
$str .= $rf->getName();
$str .= '(' . implode(", ", $params) . ')';
return $str;
}
示例2: onWildcardEvent
public function onWildcardEvent()
{
$name = $this->events->firing();
$time = microtime(true);
// Get the arguments passed to the event
$params = $this->prepareParams(func_get_args());
// Find all listeners for the current event
foreach ($this->events->getListeners($name) as $i => $listener) {
// Check if it's an object + method name
if (is_array($listener) && count($listener) > 1 && is_object($listener[0])) {
list($class, $method) = $listener;
// Skip this class itself
if ($class instanceof static) {
continue;
}
// Format the listener to readable format
$listener = get_class($class) . '@' . $method;
// Handle closures
} elseif ($listener instanceof \Closure) {
$reflector = new \ReflectionFunction($listener);
// Skip our own listeners
if ($reflector->getNamespaceName() == 'Barryvdh\\Debugbar') {
continue;
}
// Format the closure to a readable format
$filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
$listener = $reflector->getName() . ' (' . $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine() . ')';
} else {
// Not sure if this is possible, but to prevent edge cases
$listener = $this->formatVar($listener);
}
$params['listeners.' . $i] = $listener;
}
$this->addMeasure($name, $time, $time, $params);
}
示例3: callsFuncGetArgs
/**
* @param mixed $nodes
* @return bool
*/
private function callsFuncGetArgs($nodes) : bool
{
foreach ($nodes as $node) {
if (is_array($node)) {
if ($this->callsFuncGetArgs($node)) {
return true;
}
}
if (!$node instanceof \PhpParser\Node) {
continue;
}
if ($node instanceof Function_) {
$functionName = $node->name;
if ((string) $node->namespacedName) {
$functionName = (string) $node->namespacedName;
}
if ($functionName === $this->reflection->getName()) {
return $this->functionCallStatementFinder->findFunctionCallInStatements(self::VARIADIC_FUNCTIONS, $node->getStmts()) !== null;
}
continue;
}
if ($this->callsFuncGetArgs($node)) {
return true;
}
}
return false;
}
示例4: override
/**
* @return $this
*/
public function override()
{
if (!function_exists($this->targetNamespace . '\\' . $this->reflectionFunction->getName())) {
eval($this->getCode());
}
return $this;
}
示例5: 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;
}
示例6: getName
/**
* Returns this function's name
*
* @return string This function's name
*/
public function getName()
{
if ($this->reflectionSource instanceof ReflectionFunction) {
return $this->reflectionSource->getName();
} else {
return parent::getName();
}
}
示例7: testExecutionShouldCollectName
function testExecutionShouldCollectName()
{
$stubName = testFake();
$reflector = new \ReflectionFunction($stubName);
$test = new FunctionTest($stubName);
$result = $test->execute()[0];
$this->assertSame($reflector->getName(), $result->getName());
}
示例8: unwrap
public static function unwrap(\Closure $closure)
{
$reflectionFunction = new \ReflectionFunction($closure);
if (substr($reflectionFunction->getName(), -1) === '}') {
$vars = $reflectionFunction->getStaticVariables();
return isset($vars['_callable_']) ? $vars['_callable_'] : $closure;
} else {
if ($obj = $reflectionFunction->getClosureThis()) {
return [$obj, $reflectionFunction->getName()];
} else {
if ($class = $reflectionFunction->getClosureScopeClass()) {
return [$class->getName(), $reflectionFunction->getName()];
}
}
}
return $reflectionFunction->getName();
}
示例9: describeValue
protected function describeValue($value, $recursive = false)
{
if (is_callable($value)) {
$function = new \ReflectionFunction($value);
$name = $function->getName();
if ($name == '{closure}') {
$name = 'function';
} else {
$name = 'function ' . $name;
}
$parameters = array();
foreach ($function->getParameters() as $parameter) {
$synopsis = '';
if ($parameter->isArray()) {
$synopsis .= 'array ';
} else {
if ($parameter->getClass()) {
$synopsis .= $parameter->getClass() . ' ';
}
}
if ($parameter->isPassedByReference()) {
$synopsis .= '&';
}
$synopsis .= '$' . $parameter->getName();
if ($parameter->isOptional()) {
$synopsis .= ' = ' . var_export($parameter->getDefaultValue(), true);
}
$parameters[] = $synopsis;
}
return sprintf('(callable) %s(<br> %s<br>)', $name, implode(',<br> ', $parameters));
} else {
if (is_object($value)) {
if ($value instanceof \ArrayObject) {
if ($recursive) {
$values = array_map(array($this, 'describeValue'), $value->getArrayCopy());
return sprintf('(object) %s(<br> %s<br>)', get_class($value), implode(',<br> ', $values));
} else {
return sprintf('(object) %s(…)', get_class($value));
}
} else {
return sprintf('(object) %s', get_class($value));
}
} else {
if (is_array($value)) {
if ($recursive) {
$values = array_map(array($this, 'describeValue'), $value);
return sprintf('(array) [%s]', implode(', ', $values));
} else {
return sprintf('(array) […]');
}
} else {
return sprintf('(%s) %s', gettype($value), var_export($value, true));
}
}
}
}
示例10: dumpFuncInfo
function dumpFuncInfo($name)
{
$funcInfo = new ReflectionFunction($name);
var_dump($funcInfo->getName());
var_dump($funcInfo->isInternal());
var_dump($funcInfo->isUserDefined());
var_dump($funcInfo->getStartLine());
var_dump($funcInfo->getEndLine());
var_dump($funcInfo->getStaticVariables());
}
示例11: functionListFromReflectionFunction
/**
* @return Func[]
* One or more (alternate) methods begotten from
* reflection info and internal method data
*/
public static function functionListFromReflectionFunction(CodeBase $code_base, \ReflectionFunction $reflection_function) : array
{
$context = new Context();
$parts = explode('\\', $reflection_function->getName());
$method_name = array_pop($parts);
$namespace = '\\' . implode('\\', $parts);
$fqsen = FullyQualifiedFunctionName::make($namespace, $method_name);
$function = new Func($context, $fqsen->getName(), new UnionType(), 0, $fqsen);
$function->setNumberOfRequiredParameters($reflection_function->getNumberOfRequiredParameters());
$function->setNumberOfOptionalParameters($reflection_function->getNumberOfParameters() - $reflection_function->getNumberOfRequiredParameters());
return self::functionListFromFunction($function, $code_base);
}
示例12: fromReflection
/**
* Creates a ClosureLocation and seeds it with all the data that can be gleaned from the closure's reflection
*
* @param \ReflectionFunction $reflection The reflection of the closure that this ClosureLocation should represent
*
* @return ClosureLocation
*/
public static function fromReflection(\ReflectionFunction $reflection)
{
$location = new self();
$location->directory = dirname($reflection->getFileName());
$location->file = $reflection->getFileName();
$location->function = $reflection->getName();
$location->line = $reflection->getStartLine();
// @codeCoverageIgnoreStart
if (version_compare(PHP_VERSION, '5.4', '>=')) {
$closureScopeClass = $reflection->getClosureScopeClass();
$location->closureScopeClass = $closureScopeClass ? $closureScopeClass->getName() : null;
}
// @codeCoverageIgnoreEnd
return $location;
}
示例13: execute
/**
* Execute the command
* @param array $args Arguments gived to the command
* @return array Response
*/
public function execute($args = array())
{
$functions = array('names' => array(), 'values' => array());
$functions = get_defined_functions();
foreach ($functions['internal'] as $functionName) {
try {
$function = new \ReflectionFunction($functionName);
} catch (\Exception $e) {
continue;
}
$functions['names'][] = $function->getName();
$args = $this->getMethodArguments($function);
$functions['values'][$function->getName()] = array(array('isMethod' => true, 'args' => $args));
}
return $functions;
}
示例14: __construct
/**
* @param string $name
* @param \ReflectionFunction $reflection
*
* @throws \RuntimeException
*/
public function __construct($name, \ReflectionFunction $reflection = null)
{
if (!is_string($name) || empty($name)) {
throw new \RuntimeException('Name should be string and not empty');
}
$this->name = $name;
if ($reflection) {
if ($reflection->getName() != $name) {
throw new \RuntimeException('Reflection getName not equal with name which you provides');
}
$this->setReflection($reflection);
} else {
if (function_exists($name)) {
$reflection = $this->getReflection();
}
}
if ($reflection && $reflection->isInternal()) {
throw new \RuntimeException('You can not works with internal PHP functions, only user defined');
}
$this->arguments = new Arguments(array(), $reflection);
}
示例15: printOptions
/**
* Print cUrl options
*
* @param array $options
*/
public static function printOptions($options)
{
if ($options instanceof \Traversable || is_array($options)) {
foreach ($options as $key => $value) {
$key = self::getOptionName($key);
switch (gettype($value)) {
case 'array':
echo "{$key} => " . print_r($value, true) . PHP_EOL;
break;
case 'object':
$func = new \ReflectionClass($value);
echo "{$key} => class " . $func->getName() . PHP_EOL;
break;
case 'function':
$func = new \ReflectionFunction($value);
echo "{$key} => function " . $func->getName() . PHP_EOL;
break;
default:
echo "{$key} => {$value}" . PHP_EOL;
break;
}
}
}
}