本文整理汇总了PHP中ReflectionParameter::getPosition方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionParameter::getPosition方法的具体用法?PHP ReflectionParameter::getPosition怎么用?PHP ReflectionParameter::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionParameter
的用法示例。
在下文中一共展示了ReflectionParameter::getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fillParameter
/**
* Setup arguments for current action
*
* @param \ReflectionParameter $Parameter
*
* @return array
*/
public function fillParameter(\ReflectionParameter $Parameter)
{
$UrlParts = Application::$i->URL->parts();
if (!isset($UrlParts[$Parameter->getPosition() + 2])) {
if ($Parameter->isDefaultValueAvailable() === false) {
showError('Parameter $' . $Parameter->getName() . ' not found');
}
$value = $Parameter->getDefaultValue();
} else {
$value = Application::$i->URL->parts($Parameter->getPosition() + 2);
}
return $value;
}
示例2: __construct
public function __construct(\ReflectionParameter $parameter, $message = null, $code = null, \Exception $previous = null)
{
if (null === $message) {
$message = sprintf('Unable to resolve argument $%s (#%d) of %s.', $parameter->name, $parameter->getPosition(), static::getFunctionName($parameter->getDeclaringFunction()));
}
parent::__construct($message, $code, $previous);
}
示例3: __construct
public function __construct(\ReflectionParameter $parameter)
{
$this->name = $parameter->getName();
$this->position = $parameter->getPosition();
$this->has_default = $parameter->isDefaultValueAvailable();
$this->default_value = $this->getHasDefault() ? $parameter->getDefaultValue() : null;
}
示例4: __construct
public function __construct(ReflectionParameter $param)
{
if (method_exists('ReflectionParameter', 'getType')) {
if ($type = $param->getType()) {
$this->type_hint = (string) $type;
}
} else {
if ($param->isArray()) {
$this->type_hint = 'array';
} else {
try {
if ($this->type_hint = $param->getClass()) {
$this->type_hint = $this->type_hint->name;
}
} catch (ReflectionException $e) {
preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
$this->type_hint = isset($matches[1]) ? $matches[1] : '';
}
}
}
$this->reference = $param->isPassedByReference();
$this->position = $param->getPosition();
$this->name = $param->getName();
if ($param->isDefaultValueAvailable()) {
$this->default = var_export($param->getDefaultValue(), true);
}
}
示例5: createParameterTypeWithRef
protected static function createParameterTypeWithRef(ReflectionParameter $ref)
{
if ($ref->isArray()) {
$parameter = new HermitSqlParameterSequence();
$parameter->add($ref->getName(), $ref->getPosition());
return $parameter;
}
$class = $ref->getClass();
if (is_null($class)) {
$parameter = new HermitSqlParameterHash();
$parameter->add($ref->getName(), $ref->getPosition());
return $parameter;
}
$parameter = new HermitSqlParameterClassHash($class);
$parameter->add($ref->getName(), $ref->getPosition());
return $parameter;
}
示例6:
function it_generates_correct_message_based_on_function_and_parameter(\ReflectionParameter $parameter, \ReflectionMethod $function, \ReflectionClass $class)
{
$parameter->getPosition()->willReturn(2);
$function->getDeclaringClass()->willReturn($class);
$class->getName()->willReturn('Acme\\Foo');
$function->getName()->willReturn('bar');
$this->getMessage()->shouldStartWith('Collaborator must be an object: argument 2 defined in Acme\\Foo::bar.');
}
示例7: getPosition
/**
* Returns whether this parameter is an optional parameter
* @return integer
* @since PHP 5.2.3
*/
public function getPosition()
{
if ($this->parameter != null) {
return $this->parameter->getPosition();
} else {
return parent::getPosition();
}
}
示例8:
function __construct(API_Doc_Method $method, ReflectionParameter $parameter)
{
$this->name = $parameter->getName();
$this->is_passed_by_reference = $parameter->isPassedByReference();
$this->allows_null = $parameter->allowsNull();
$this->is_optional = $parameter->isOptional();
$this->is_default_value_available = $parameter->isDefaultValueAvailable();
$this->position = $parameter->getPosition();
$this->declaring_method = $method;
}
示例9: testDebugInfo
public function testDebugInfo()
{
$this->skipIf(php_sapi_name() === 'cli', 'Only for webtest runner');
$functionLists = ['Array' => ['array_change_key_case', 'array_chunk', 'array_combine', 'array_count_values', 'array_diff_assoc', 'array_diff_key', 'array_diff_uassoc', 'array_diff_ukey', 'array_diff', 'array_fill_keys', 'array_fill', 'array_filter', 'array_flip', 'array_intersect_assoc', 'array_intersect_key', 'array_intersect_uassoc', 'array_intersect_ukey', 'array_intersect', 'array_key_exists', 'array_keys', 'array_map', 'array_merge_recursive', 'array_merge', 'array_multisort', 'array_pad', 'array_pop', 'array_product', 'array_push', 'array_rand', 'array_reduce', 'array_replace_recursive', 'array_replace', 'array_reverse', 'array_search', 'array_shift', 'array_slice', 'array_splice', 'array_sum', 'array_udiff_assoc', 'array_udiff_uassoc', 'array_udiff', 'array_uintersect_assoc', 'array_uintersect_uassoc', 'array_uintersect', 'array_unique', 'array_unshift', 'array_values', 'array_walk_recursive', 'array_walk', 'array', 'arsort', 'asort', 'compact', 'count', 'current', 'each', 'end', 'extract', 'in_array', 'key', 'krsort', 'ksort', 'list', 'natcasesort', 'natsort', 'next', 'pos', 'prev', 'range', 'reset', 'rsort', 'shuffle', 'sizeof', 'sort', 'uasort', 'uksort', 'usort'], 'String' => ['addcslashes', 'addslashes', 'bin2hex', 'chop', 'chr', 'chunk_split', 'convert_cyr_string', 'convert_uudecode', 'convert_uuencode', 'count_chars', 'crc32', 'crypt', 'echo', 'explode', 'fprintf', 'get_html_translation_table', 'hebrev', 'hebrevc', 'hex2bin', 'html_entity_decode', 'htmlentities', 'htmlspecialchars_decode', 'htmlspecialchars', 'implode', 'join', 'lcfirst', 'levenshtein', 'localeconv', 'ltrim', 'md5_file', 'md5', 'metaphone', 'money_format', 'nl_langinfo', 'nl2br', 'number_format', 'ord', 'parse_str', 'print', 'printf', 'quoted_printable_decode', 'quoted_printable_encode', 'quotemeta', 'rtrim', 'setlocale', 'sha1_file', 'sha1', 'similar_text', 'soundex', 'sprintf', 'sscanf', 'str_getcsv', 'str_ireplace', 'str_pad', 'str_repeat', 'str_replace', 'str_rot13', 'str_shuffle', 'str_split', 'str_word_count', 'strcasecmp', 'strchr', 'strcmp', 'strcoll', 'strcspn', 'strip_tags', 'stripcslashes', 'stripos', 'stripslashes', 'stristr', 'strlen', 'strnatcasecmp', 'strnatcmp', 'strncasecmp', 'strncmp', 'strpbrk', 'strpos', 'strrchr', 'strrev', 'strripos', 'strrpos', 'strspn', 'strstr', 'strtok', 'strtolower', 'strtoupper', 'strtr', 'substr_compare', 'substr_count', 'substr_replace', 'substr', 'trim', 'ucfirst', 'ucwords', 'vfprintf', 'vprintf', 'vsprintf', 'wordwrap']];
$res = '';
foreach ($functionLists as $type => $functions) {
$res .= "{$type} functions:\n";
foreach ($functions as $function) {
try {
$needle = new ReflectionParameter($function, "needle");
$haystack = new ReflectionParameter($function, "haystack");
$order = $needle->getPosition() < $haystack->getPosition() ? '$needle, $haystack' : '$haystack, $needle';
$res .= sprintf("%20s %s\n", $function, $order);
} catch (ReflectionException $e) {
continue;
}
}
$res .= "\n";
}
$this->debug($res);
}
示例10: resolveParameter
protected function resolveParameter($parameters, \ReflectionParameter $constructorArg)
{
$parameterName = $constructorArg->getName();
$parameterPosition = $constructorArg->getPosition();
if (isset($parameters[$parameterName])) {
return $parameters[$parameterName];
} else {
if (isset($parameters[$parameterPosition])) {
return $parameters[$parameterPosition];
} else {
if (isset($this->parameters[$parameterName])) {
return $this->parameters[$parameterName];
} else {
if (isset($this->parameters[$parameterPosition])) {
return $this->parameters[$parameterPosition];
} else {
if ($constructorArg->getClass() !== null) {
try {
return $this->factory->get($constructorArg->getClass()->getName());
} catch (InstantiationException $e) {
if ($constructorArg->isDefaultValueAvailable()) {
return $constructorArg->getDefaultValue();
} else {
throw $e;
}
}
} else {
if ($constructorArg->isDefaultValueAvailable()) {
return $constructorArg->getDefaultValue();
} else {
throw new ParameterMissingException($parameterName);
}
}
}
}
}
}
}
示例11: denormalizeParam
/**
* @param array $data
* @param \ReflectionParameter $param
* @param string $format
* @param array $context
*
* @return object
*/
protected function denormalizeParam($data, $param, $format, $context)
{
$name = $param->getName();
$index = $param->getPosition();
if (array_key_exists($name, $data)) {
$value = $data[$name];
} elseif (array_key_exists($index, $data)) {
$value = $data[$index];
} elseif ($param->isDefaultValueAvailable()) {
$value = $param->getDefaultValue();
} else {
$message = sprintf('Missing parameter #%s: %s', $index, $name);
throw new \RuntimeException($message);
}
if ($param->getClass()) {
$class = $param->getClass()->getName();
} elseif ($this->serializer->supportsDenormalization($value, MixedDenormalizer::TYPE, $format)) {
$class = MixedDenormalizer::TYPE;
}
if (isset($class)) {
$value = $this->serializer->denormalize($value, $class, $format, $context);
}
return $value;
}
示例12: argData
function argData(ReflectionParameter $arg)
{
$details = "";
$declaringclass = $arg->getDeclaringClass();
$name = $arg->getName();
$class = $arg->getClass();
$position = $arg->getPosition();
$details .= "\${$name} has position {$position}\n";
if (!empty($class)) {
$classname = $class->getName();
$details .= "\${$name} must be a {$classname} object\n";
}
if ($arg->isPassedByReference()) {
$details .= "\${$name} is passed by reference\n";
}
if ($arg->isDefaultValueAvailable()) {
$def = $arg->getDefaultValue();
$details .= "\${$name} has default: {$def}\n";
}
if ($arg->allowsNull()) {
$details .= "\${$name} can be null\n";
}
return $details;
}
示例13: implementParameter
/**
* Generates the code for an individual method parameter.
*
* @param ReflectionParameter $parameter
*
* @return string
*/
protected function implementParameter(ReflectionParameter $parameter)
{
$default = '';
$type = '';
if ($parameter->isArray()) {
$type = 'array ';
} elseif ($parameter->getClass() !== null) {
$type = $parameter->getClass()->getName() . ' ';
}
if ($parameter->isDefaultValueAvailable()) {
$default = ' = ' . var_export($parameter->getDefaultValue(), true);
} elseif ($parameter->isOptional()) {
$default = ' = null';
}
return $type . ($parameter->isPassedByReference() ? '&' : '') . '$parm' . $parameter->getPosition() . $default;
}
示例14: normalizeParam
/**
* normalize one param of a method
*
* @since 7-5-11
* @param ReflectionParameter $rparam
* @param array $params see {@link normalizeParams()} for description of the $params array
* @return mixed the normalized param
*/
public function normalizeParam(\ReflectionParameter $rparam, array $params = array())
{
$ret_param = null;
$index = $rparam->getPosition();
// first try and resolve numeric keys, then do string keys...
// we use array_key_exists because values could be null
if (array_key_exists($index, $params)) {
$ret_param = $params[$index];
} else {
$field_name = $rparam->getName();
if (array_key_exists($field_name, $params)) {
$ret_param = $params[$field_name];
} else {
try {
$rclass = $rparam->getClass();
} catch (\ReflectionException $e) {
throw new \ReflectionException(sprintf('%s which is param %s of method %s::%s()', $e->getMessage(), $index + 1, $rparam->getDeclaringClass()->getName(), $rparam->getDeclaringFunction()->getName()));
}
//try/catch
if ($rclass === null) {
if ($this->existsField($field_name)) {
$ret_param = $this->getField($field_name);
} else {
if ($rparam->isDefaultValueAvailable()) {
$ret_param = $rparam->getDefaultValue();
} else {
$declaring_class = $rparam->getDeclaringClass();
$declaring_func = $rparam->getDeclaringFunction();
throw new \UnexpectedValueException(sprintf('no suitable value could be found for %s::%s() param "%s"', empty($declaring_class) ? 'unknown' : $declaring_class->getName(), empty($declaring_func) ? 'unkown' : $declaring_func->getName(), $field_name));
}
}
//if/else if/else
} else {
$class_name = $rclass->getName();
try {
$ret_param = $this->getInstance($class_name);
} catch (\Exception $e) {
if ($rparam->isDefaultValueAvailable()) {
$ret_param = $rparam->getDefaultValue();
} else {
throw $e;
}
//if/else
}
//try/catch
}
//if/else
}
//if/else
}
//if/else
return $ret_param;
}
示例15: fixParameters
/**
* Fixes parameters indexed by the parameter name -> reindex by position.
*
* This is necessary so that merging definitions between sources is possible.
*
* @param ObjectDefinition $definition
* @param string $method
* @param array $parameters
* @return array
*/
private function fixParameters(ObjectDefinition $definition, $method, $parameters)
{
$fixedParameters = array();
foreach ($parameters as $index => $parameter) {
// Parameter indexed by the parameter name, we reindex it with its position
if (is_string($index)) {
$callable = array($definition->getClassName(), $method);
$reflectionParameter = new \ReflectionParameter($callable, $index);
$index = $reflectionParameter->getPosition();
}
$fixedParameters[$index] = $parameter;
}
return $fixedParameters;
}