本文整理汇总了PHP中ReflectionMethod::getModifiers方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getModifiers方法的具体用法?PHP ReflectionMethod::getModifiers怎么用?PHP ReflectionMethod::getModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getModifiers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportCode
/**
* Exports the PHP code
*
* @return string
*/
public function exportCode()
{
$modifiers = \Reflection::getModifierNames($this->_method->getModifiers());
$params = array();
// Export method's parameters
foreach ($this->_method->getParameters() as $param) {
$reflection_parameter = new ReflectionParameter($param);
$params[] = $reflection_parameter->exportCode();
}
return sprintf('%s function %s(%s) {}', join(' ', $modifiers), $this->_method->getName(), join(', ', $params));
}
示例2: writeMethod
public function writeMethod(\ReflectionMethod $method)
{
$args = [];
foreach ($method->getParameters() as $parameter) {
$arg = '';
if ($parameter->isArray()) {
$arg .= 'array ';
} else {
if ($parameter->getClass()) {
$arg .= '\\' . $parameter->getClass()->getName() . ' ';
}
}
if ($parameter->isPassedByReference()) {
$arg .= '&';
}
$arg .= '$' . $parameter->getName();
try {
$defaultValue = $parameter->getDefaultValue();
$arg .= ' = ' . var_export($defaultValue, true);
} catch (ReflectionException $e) {
if ($parameter->isOptional()) {
$arg .= ' = null';
}
}
$args[] = $arg;
}
$modifiers = array_diff(\Reflection::getModifierNames($method->getModifiers()), ['abstract']);
$methodName = ($method->returnsReference() ? '&' : '') . $method->getName();
$this->code[] = ' ' . implode(' ', $modifiers) . ' function ' . $methodName . '(' . implode(', ', $args) . ') {';
$this->code[] = ' $result = $this->' . $this->propertyName . '->invoke($this, \'' . $method->getName() . '\', func_get_args());';
$this->code[] = ' return $result;';
$this->code[] = ' }';
}
示例3: getModifiers
/**
* Returns a bitfield of the access modifiers for this method
*
* @return integer Bitfield of the access modifiers for this method
*/
public function getModifiers()
{
if ($this->reflectionSource instanceof ReflectionMethod) {
return $this->reflectionSource->getModifiers();
} else {
return parent::getModifiers();
}
}
示例4: methodListFromReflectionClassAndMethod
/**
* @return Method[]
*/
public static function methodListFromReflectionClassAndMethod(Context $context, CodeBase $code_base, \ReflectionClass $class, \ReflectionMethod $reflection_method) : array
{
$reflection_method = new \ReflectionMethod($class->getName(), $reflection_method->name);
$method = new Method($context, $reflection_method->name, new UnionType(), $reflection_method->getModifiers());
$method->setNumberOfRequiredParameters($reflection_method->getNumberOfRequiredParameters());
$method->setNumberOfOptionalParameters($reflection_method->getNumberOfParameters() - $reflection_method->getNumberOfRequiredParameters());
$method->setFQSEN(FullyQualifiedMethodName::fromStringInContext($method->getName(), $context));
return self::functionListFromFunction($method, $code_base);
}
示例5: checkMethodsInNewClasses
/**
* @param ReflectionMethod[] $methods
*/
private function checkMethodsInNewClasses($methods)
{
foreach ($methods as $method) {
list($expectedMethod, $class) = $this->explodeCamel($method->getName());
$this->assertTrue(method_exists($class, $expectedMethod), 'Method ' . $expectedMethod . ' is not found in class ' . $class);
$newMethod = new ReflectionMethod($class, $expectedMethod);
$this->assertEquals($method->getModifiers(), $newMethod->getModifiers(), 'Incorrect modifier for ' . $class . '::' . $expectedMethod);
$this->assertEquals(substr_count(file_get_contents($method->getFileName()), $method->getName()), substr_count(file_get_contents($newMethod->getFileName()), $newMethod->getName()), 'Incorrect usage for ' . $class . '::' . $expectedMethod);
}
}
示例6: analyze
/**
* {@inheritdoc}
* @throws MethodDefinitionAlreadyExistsException
* @throws MethodDefinitionNotFoundException
*/
public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionMethod $reflectionMethod)
{
$methodName = $reflectionMethod->getName();
// Constructor definition is required
if ($methodName === '__construct' && !$classDefinition->hasMethod('__construct')) {
$classDefinition->defineConstructor()->end();
}
// Set method metadata
if ($classDefinition->hasMethod($methodName)) {
$classDefinition->getMethod($methodName)->setModifiers($reflectionMethod->getModifiers())->setIsPublic($reflectionMethod->isPublic());
}
}
示例7: getMethodModifier
/**
* @param ReflectionMethod $method
* @return int
*/
private function getMethodModifier($method)
{
switch ($method->getModifiers()) {
case '134283520':
return self::PUBLIC_MODIFIER;
case '134283776':
return self::PROTECTED_MODIFIER;
case '134284288':
return self::PRIVATE_MODIFIER;
default:
return self::PUBLIC_MODIFIER;
}
}
示例8: __construct
public function __construct($class, $method)
{
$method = new ReflectionMethod($class, $method);
$this->name = $method->name;
$class = $parent = $method->getDeclaringClass();
if ($modifiers = $method->getModifiers()) {
$this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> ';
}
$comment = '';
do {
if ($parent->hasMethod($this->name)) {
$comment = $parent->getMethod($this->name)->getDocComment();
// Found a description for this method
break;
}
} while ($parent = $parent->getParentClass());
list($this->description, $tags) = Kodoc::parse($comment);
if ($file = $class->getFileName()) {
$this->source = Kodoc::source($file, $method->getStartLine(), $method->getEndLine());
}
if (isset($tags['param'])) {
$params = array();
foreach ($method->getParameters() as $i => $param) {
$param = new Kodoc_Method_Param(array($method->class, $method->name), $i);
if (isset($tags['param'][$i])) {
if (preg_match('/^(\\S*)\\s*(\\$\\w+)?(?:\\s*(.+?))?$/', $tags['param'][$i], $matches)) {
$param->type = $matches[1];
$param->description = arr::get($matches, 3);
}
}
$params[] = $param;
}
$this->params = $params;
unset($tags['param']);
}
if (isset($tags['return'])) {
foreach ($tags['return'] as $return) {
if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $return, $matches)) {
$this->return[] = array($matches[1], isset($matches[2]) ? $matches[2] : '');
}
}
unset($tags['return']);
}
$this->tags = $tags;
}
示例9: resolveMethodMetadata
/**
* Generic class method resolver.
*
* @param \ReflectionMethod $method
* @param ClassMetadata $classMetadata
*
* @return MethodMetadata Resolved method metadata
*/
protected function resolveMethodMetadata(\ReflectionMethod $method, ClassMetadata $classMetadata) : MethodMetadata
{
// Create method metadata instance
$methodMetadata = $classMetadata->methodsMetadata[$method->name] ?? new MethodMetadata($classMetadata);
$methodMetadata->name = $method->name;
$methodMetadata->modifiers = $method->getModifiers();
$methodMetadata->isPublic = $method->isPublic();
/** @var \ReflectionParameter $parameter */
$parameterMetadata = new ParameterMetadata($classMetadata, $methodMetadata);
foreach ($method->getParameters() as $parameter) {
$parameterMetadata = $methodMetadata->parametersMetadata[$parameter->name] ?? clone $parameterMetadata;
$parameterMetadata->name = $parameter->name;
$parameterMetadata->typeHint = (string) $parameter->getType();
// Store parameters metadata in method metadata
$methodMetadata->parametersMetadata[$parameterMetadata->name] = $parameterMetadata;
}
// Store method metadata in class metadata
return $classMetadata->methodsMetadata[$methodMetadata->name] = $methodMetadata;
}
示例10: add_class
function add_class($class_name, $flags)
{
global $classes, $internal_arginfo;
$lc = strtolower($class_name);
$class = new \ReflectionClass($class_name);
if ($class->isFinal()) {
$flags |= \ast\flags\CLASS_FINAL;
}
if ($class->isAbstract()) {
$flags |= \ast\flags\CLASS_ABSTRACT;
}
$classes[$lc] = ['file' => 'internal', 'conditional' => false, 'flags' => $flags, 'lineno' => 0, 'endLineno' => 0, 'name' => $class_name, 'docComment' => '', 'traits' => []];
foreach ($class->getDefaultProperties() as $name => $value) {
$prop = new \ReflectionProperty($class_name, $name);
$classes[$lc]['properties'][strtolower($name)] = ['flags' => $prop->getModifiers(), 'name' => $name, 'lineno' => 0, 'value' => $value];
}
foreach ($class->getConstants() as $name => $value) {
$classes[$lc]['constants'][strtolower($name)] = ['name' => $name, 'lineno' => 0, 'value' => $value];
}
foreach ($class->getMethods() as $method) {
$meth = new \ReflectionMethod($class_name, $method->name);
$required = $meth->getNumberOfRequiredParameters();
$optional = $meth->getNumberOfParameters() - $required;
$lmname = strtolower($method->name);
$classes[$lc]['methods'][$lmname] = ['file' => 'internal', 'conditional' => false, 'flags' => $meth->getModifiers(), 'lineno' => 0, 'endLineno' => 0, 'name' => $method->name, 'docComment' => '', 'required' => $required, 'optional' => $optional, 'ret' => null];
$arginfo = null;
if (!empty($internal_arginfo["{$class_name}::{$method->name}"])) {
$arginfo = $internal_arginfo["{$class_name}::{$method->name}"];
$classes[$lc]['methods'][$lmname]['ret'] = $arginfo[0];
}
foreach ($method->getParameters() as $param) {
$flags = 0;
if ($param->isPassedByReference()) {
$flags |= \ast\flags\PARAM_REF;
}
if ($param->isVariadic()) {
$flags |= \ast\flags\PARAM_VARIADIC;
}
$classes[$lc]['methods'][strtolower($method->name)]['params'][] = ['file' => 'internal', 'flags' => $flags, 'lineno' => 0, 'name' => $param->name, 'type' => empty($arginfo) ? null : next($arginfo), 'def' => null];
}
}
}
示例11: writeMethod
function writeMethod(ReflectionMethod $method, ReflectionClass $class)
{
if ($method->getDeclaringClass() != $class) {
return "";
}
$acc = $method->getModifiers();
$func = "";
if ($acc & ReflectionMethod::IS_STATIC) {
$func .= "static ";
}
if ($acc & ReflectionMethod::IS_ABSTRACT) {
$func .= "abstract ";
}
if ($acc & ReflectionMethod::IS_FINAL) {
$func .= "final ";
}
if ($acc & ReflectionMethod::IS_PUBLIC) {
$func .= "public ";
}
if ($acc & ReflectionMethod::IS_PROTECTED) {
$func .= "protected ";
}
if ($acc & ReflectionMethod::IS_PRIVATE) {
$func .= "private ";
}
$data = methodData($method);
$params = $data[1];
if (empty($params)) {
$refparams = $method->getParameters();
if (!empty($refparams)) {
foreach ($refparams as $param) {
$params[] = "\$" . $param->name;
}
} else {
for ($i = 0; $i < $method->getNumberOfParameters(); $i++) {
$params[] = "\$arg{$i}";
}
}
}
$params = join(",", $params);
return "{$data['0']}{$func}function {$method->name}({$params}) {}\n";
}
示例12: getMethod
function getMethod()
{
$method_call = '';
if (!$this->hasClassName()) {
if ($this->hasFuncName()) {
$method_call = $this->funcName();
}
//if
} else {
if (!$this->hasFuncName()) {
$method_call = $this->className();
} else {
$class = $this->className();
$method = $this->funcName();
$method_reflect = new ReflectionMethod($class, $method);
$method_modifiers = join(' ', Reflection::getModifierNames($method_reflect->getModifiers()));
$method_caller = '->';
if (mb_stripos($method_modifiers, 'static') !== false) {
$method_caller = '::';
}
//if
$method_call = sprintf('%s %s%s%s', $method_modifiers, $class, $method_caller, $method);
}
//if/else
}
//if/else
$method_args = '';
if ($this->hasFuncArgs()) {
$arg_list = array();
foreach ($this->funcArgs() as $arg) {
if (is_object($arg)) {
$arg_list[] = get_class($arg);
} else {
if (is_array($arg)) {
$arg_list[] = sprintf('Array(%s)', count($arg));
} else {
if (is_bool($arg)) {
$arg_list[] = $arg ? 'TRUE' : 'FALSE';
} else {
if (is_null($arg)) {
$arg_list[] = 'NULL';
} else {
if (is_string($arg)) {
$arg_list[] = sprintf('"%s"', $arg);
} else {
$arg_list[] = $arg;
}
}
}
}
//if/else
}
//if/else
}
//foreach
$method_args = join(', ', $arg_list);
}
//if
return sprintf('%s(%s)', $method_call, $method_args);
}
示例13: methodListFromReflectionClassAndMethod
/**
* @return Method[]
*/
public static function methodListFromReflectionClassAndMethod(Context $context, CodeBase $code_base, \ReflectionClass $class, \ReflectionMethod $method) : array
{
$reflection_method = new \ReflectionMethod($class->getName(), $method->name);
$number_of_required_parameters = $reflection_method->getNumberOfRequiredParameters();
$number_of_optional_parameters = $reflection_method->getNumberOfParameters() - $number_of_required_parameters;
$method = new Method($context, $method->name, new UnionType(), $reflection_method->getModifiers(), $number_of_required_parameters, $number_of_optional_parameters);
return self::methodListFromMethod($method, $code_base);
}
示例14: f
} catch (TypeError $re) {
echo "Ok - " . $re->getMessage() . PHP_EOL;
}
try {
new ReflectionMethod('a', 'b', 'c');
} catch (TypeError $re) {
echo "Ok - " . $re->getMessage() . PHP_EOL;
}
class C
{
public function f()
{
}
}
$rm = new ReflectionMethod('C', 'f');
var_dump($rm->isFinal(1));
var_dump($rm->isAbstract(1));
var_dump($rm->isPrivate(1));
var_dump($rm->isProtected(1));
var_dump($rm->isPublic(1));
var_dump($rm->isStatic(1));
var_dump($rm->isConstructor(1));
var_dump($rm->isDestructor(1));
var_dump($rm->getModifiers(1));
var_dump($rm->isInternal(1));
var_dump($rm->isUserDefined(1));
var_dump($rm->getFileName(1));
var_dump($rm->getStartLine(1));
var_dump($rm->getEndLine(1));
var_dump($rm->getStaticVariables(1));
var_dump($rm->getName(1));
示例15: visibility
/**
* Finds the visibility of a ReflectionMethod.
*
* @param object ReflectionMethod
* @return string
*/
protected function visibility(ReflectionMethod $method)
{
$vis = array_flip(Reflection::getModifierNames($method->getModifiers()));
if (isset($vis['public'])) {
return 'public';
}
if (isset($vis['protected'])) {
return 'protected';
}
if (isset($vis['private'])) {
return 'private';
}
return FALSE;
}