本文整理汇总了PHP中ReflectionMethod::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getName方法的具体用法?PHP ReflectionMethod::getName怎么用?PHP ReflectionMethod::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertMethodAnnotations
public function convertMethodAnnotations(\ReflectionMethod $method, array $annotations)
{
$parameters = array();
foreach ($method->getParameters() as $index => $parameter) {
$parameters[$parameter->getName()] = $index;
}
$methodMetadata = new MethodMetadata($method->getDeclaringClass()->getName(), $method->getName());
foreach ($annotations as $annotation) {
if ($annotation instanceof Secure) {
$methodMetadata->roles = $annotation->roles;
} else {
if ($annotation instanceof SecureParam) {
if (!isset($parameters[$annotation->name])) {
throw new \InvalidArgumentException(sprintf('The parameter "%s" does not exist for method "%s".', $annotation->name, $method->getName()));
}
$methodMetadata->addParamPermissions($parameters[$annotation->name], $annotation->permissions);
} else {
if ($annotation instanceof SecureReturn) {
$methodMetadata->returnPermissions = $annotation->permissions;
} else {
if ($annotation instanceof SatisfiesParentSecurityPolicy) {
$methodMetadata->satisfiesParentSecurityPolicy = true;
} else {
if ($annotation instanceof RunAs) {
$methodMetadata->runAsRoles = $annotation->roles;
}
}
}
}
}
}
return $methodMetadata;
}
示例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: validate_action
public function validate_action(Request $request)
{
try {
$rmethod = new ReflectionMethod($this->controller, $request->parameter('action'));
} catch (ReflectionException $rfEx) {
throw new ChainError($rfEx->getMessage());
}
if (!$rmethod->isPublic() || $rmethod->isStatic()) {
throw new ChainError('Method `' . $rmethod->getName() . '` should be declared as public on class instance `' . get_class($this->controller) . '`');
}
$rparams = $rmethod->getParameters();
$action_args = array();
foreach ($rparams as $arg) {
$arg_name = $arg->getName();
$arg_value = $request->parameter($arg_name);
// XXX: detect behavior on Merb / Django
if (null === $arg_value) {
if ($arg->isOptional()) {
continue;
} else {
throw new ChainError('Mandatory agrument `' . $arg_name . '` for action `' . $rmethod->getName() . '` not in request!');
}
}
$action_args[$arg_name] = $arg_value;
}
// ready to fire this action later
$this->chain['action'] = array($rmethod, $action_args);
// return true for now
return true;
}
示例4: build
/**
* @param \ReflectionMethod $method
* @return mixed|string
*/
public function build(\ReflectionMethod $method)
{
$functionDefinition = file_get_contents(__DIR__ . '/template/Function.php.template');
$functionDefinition = str_replace('%name%', $method->getName(), $functionDefinition);
$arguments = '';
// TODO I guess this won't cut it
if (substr($method->getName(), 0, 2) !== '__') {
foreach ($method->getParameters() as $parameter) {
$type = '';
if ($parameter->getClass() !== null) {
$type = $parameter->getClass()->getName();
} elseif ($parameter->isArray()) {
$type = 'array';
}
$default = '';
if ($parameter->isDefaultValueAvailable()) {
if (null === $parameter->getDefaultValue()) {
$default = '= NULL';
} else {
$default = sprintf("='%s'", $parameter->getDefaultValue());
}
} elseif ($parameter->isOptional()) {
// Workaround for optional parameters of internal methods
$default = '= NULL';
}
$arguments .= sprintf('%s $%s %s ,', $type, $parameter->getName(), $default);
}
$arguments = rtrim($arguments, ',');
}
$functionDefinition = str_replace('%arguments%', $arguments, $functionDefinition);
return $functionDefinition;
}
示例5: testInterfaceMethods
/**
* @dataProvider getDriverInterfaceMethods
*/
public function testInterfaceMethods(\ReflectionMethod $method)
{
$refl = new \ReflectionClass('Behat\\Mink\\Driver\\CoreDriver');
$this->assertFalse($refl->getMethod($method->getName())->isAbstract(), sprintf('CoreDriver should implement a dummy %s method', $method->getName()));
$driver = $this->getMockForAbstractClass('Behat\\Mink\\Driver\\CoreDriver');
$this->setExpectedException('Behat\\Mink\\Exception\\UnsupportedDriverActionException');
call_user_func_array(array($driver, $method->getName()), $this->getArguments($method));
}
示例6: configureRoute
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
{
if ($annot instanceof BrickRoute) {
$route->setDefault('_controller', $annot->getService() . ':' . $method->getName());
} else {
$route->setDefault('_controller', $class->getName() . '::' . $method->getName());
}
}
示例7: getMethodDetails
/**
* Gets a method's details
*
* @param string $visibility Method visibility
* @param \ReflectionMethod $method Method's \ReflectionMethod instance
* @return MethodData
*/
private function getMethodDetails($visibility, \ReflectionMethod $method)
{
$details = new MethodData();
$details->name = $method->getName();
$details->visibility = $visibility;
$details->isSetter = preg_match('/^set/', $method->getName()) === 1 ? true : false;
$details->arguments = $this->argumentWorker->generateArgumentObjects($method);
return $details;
}
示例8: getName
public function getName()
{
$name = $this->getAnnotation('name');
if (!$name) {
$name = $this->reflection->getName();
}
$name = $this->convertName($name);
return $name;
}
示例9: execute
public function execute($object)
{
$handler = $this->factory->getInstance($this->method->getDeclaringClass()->getName());
$properties = $this->getProperties($object);
$args = [];
foreach ($this->method->getParameters() as $parameter) {
$args[] = $properties[$parameter->getName()]->get($object);
}
return call_user_func_array([$handler, $this->method->getName()], $args);
}
示例10: createHandler
/**
* @param string | object $listener
* @param \ReflectionMethod $methodReflection
* @return array
*/
protected function createHandler($listener, \ReflectionMethod $methodReflection)
{
if (is_string($listener) && $methodReflection->isStatic()) {
return [$listener, $methodReflection->getName()];
} elseif (is_object($listener) && $methodReflection->isStatic()) {
return [get_class($listener), $methodReflection->getName()];
} elseif (is_object($listener) && $methodReflection->isStatic() == false) {
return [$listener, $methodReflection->getName()];
}
return false;
}
示例11: 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));
}
示例12: runMethod
/**
* Runs the test method.
* @return void
*/
private function runMethod($method)
{
$method = new \ReflectionMethod($this, $method);
if (!$method->isPublic()) {
throw new TestCaseException("Method {$method->getName()} is not public. Make it public or rename it.");
}
$data = array();
$info = Helpers::parseDocComment($method->getDocComment()) + array('dataprovider' => NULL, 'throws' => NULL);
if ($info['throws'] === '') {
throw new TestCaseException("Missing class name in @throws annotation for {$method->getName()}().");
} elseif (is_array($info['throws'])) {
throw new TestCaseException("Annotation @throws for {$method->getName()}() can be specified only once.");
} else {
$throws = preg_split('#\\s+#', $info['throws'], 2) + array(NULL, NULL);
}
$defaultParams = array();
foreach ($method->getParameters() as $param) {
$defaultParams[$param->getName()] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL;
}
foreach ((array) $info['dataprovider'] as $provider) {
$res = $this->getData($provider);
if (!is_array($res)) {
throw new TestCaseException("Data provider {$provider}() doesn't return array.");
}
foreach ($res as $set) {
$data[] = is_string(key($set)) ? array_merge($defaultParams, $set) : $set;
}
}
if (!$info['dataprovider']) {
if ($method->getNumberOfRequiredParameters()) {
throw new TestCaseException("Method {$method->getName()}() has arguments, but @dataProvider is missing.");
}
$data[] = array();
}
foreach ($data as $args) {
try {
if ($info['throws']) {
$tmp = $this;
$e = Assert::error(function () use($tmp, $method, $args) {
$tmp->runTest($method->getName(), $args);
}, $throws[0], $throws[1]);
if ($e instanceof AssertException) {
throw $e;
}
} else {
$this->runTest($method->getName(), $args);
}
} catch (AssertException $e) {
throw $e->setMessage("{$e->origMessage} in {$method->getName()}" . substr(Dumper::toLine($args), 5));
}
}
}
示例13: handleMethodAnnotations
/**
* Handle method annotations
*
* @param mixed $targetObj
* @param \ReflectionMethod $reflection
* @param array $annotations
*
* @return mixed
*/
public function handleMethodAnnotations(\ReflectionMethod $reflection, array $annotations, $targetObj = null)
{
if (isset($annotations['Route'])) {
foreach ($annotations['Route'] as $route) {
if ($route instanceof \stdClass && isset($route->path)) {
$symfonyRoute = new Route($route->path, isset($route->defaults) ? $route->defaults : [], isset($route->requirements) ? $route->requirements : [], isset($route->options) ? $route->options : [], isset($route->host) ? $route->host : '', isset($route->schemes) ? $route->schemes : [], isset($route->methods) ? $route->methods : []);
$symfonyRoute->setOption('karmaController', $reflection->getDeclaringClass()->getName());
$symfonyRoute->setOption('karmaAction', $reflection->getName());
$this->routeCollection->add(isset($route->name) ? $route->name : $reflection->getDeclaringClass()->getName() . ':' . $reflection->getName(), $symfonyRoute);
}
}
}
}
示例14: assertEqualMethods
/**
* @param \ReflectionMethod $reflectionMethod
* @param \Donquixote\HastyReflectionCommon\Reflection\FunctionLike\MethodReflectionInterface $methodReflection
*/
private function assertEqualMethods(\ReflectionMethod $reflectionMethod, MethodReflectionInterface $methodReflection)
{
$this->assertEquals($reflectionMethod->isAbstract(), $methodReflection->isAbstract());
$this->assertEquals($reflectionMethod->getDeclaringClass()->getName(), $methodReflection->getDeclaringClassName());
$this->assertEquals($reflectionMethod->getDocComment(), $methodReflection->getDocComment());
$this->assertEquals($reflectionMethod->getShortName(), $methodReflection->getName());
$this->assertEquals($reflectionMethod->getName(), $methodReflection->getName());
$this->assertEquals($reflectionMethod->class . '::' . $reflectionMethod->getName(), $methodReflection->getQualifiedName());
$this->assertEquals($reflectionMethod->returnsReference(), $methodReflection->isByReference());
$this->assertEquals($reflectionMethod->isPrivate(), $methodReflection->isPrivate());
$this->assertEquals($reflectionMethod->isProtected(), $methodReflection->isProtected());
$this->assertEquals($reflectionMethod->isPublic(), $methodReflection->isPublic());
$this->assertEquals($reflectionMethod->isStatic(), $methodReflection->isStatic());
}
示例15: configureRoute
/**
* Configures the _controller default parameter and eventually the _method
* requirement of a given Route instance.
*
* @param Route $route A Route instance
* @param ReflectionClass $class A ReflectionClass instance
* @param ReflectionMethod $method A ReflectionClass method
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
{
// controller
if ($service = $annot->getService()) {
$route->setDefault('_controller', $service . ':' . $method->getName());
} else {
$route->setDefault('_controller', $class->getName() . '::' . $method->getName());
}
// requirements (@extra:Method)
foreach ($this->configReader->getMethodAnnotations($method) as $configuration) {
if ($configuration instanceof Method) {
$route->setRequirement('_method', implode('|', $configuration->getMethods()));
}
}
}