本文整理匯總了PHP中MapUtils::MapToMethodParameters方法的典型用法代碼示例。如果您正苦於以下問題:PHP MapUtils::MapToMethodParameters方法的具體用法?PHP MapUtils::MapToMethodParameters怎麽用?PHP MapUtils::MapToMethodParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MapUtils
的用法示例。
在下文中一共展示了MapUtils::MapToMethodParameters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Create
/**
* Creates a new object of the given type, using the optional parameters.
* When pseudo-namespace support is enabled class names can become very long,
* and this function provides an alternative way to create objects that is
* more readable.
* @param string $type the type of object to create
* @param array $params parameters to pass into the constructor, as either
* flat array in the correct order for the constructor or as an
* associative array from parameter name to value
* @return mixed a new instance of a class that represents that type
*/
public function Create($type, $params = null)
{
if (array_key_exists($type, $this->options['classmap'])) {
$class = $this->options['classmap'][$type];
$reflectionClass = new ReflectionClass($class);
if (isset($params)) {
if (MapUtils::IsMap($params)) {
$params = MapUtils::MapToMethodParameters($params, $reflectionClass->getConstructor());
}
return $reflectionClass->newInstanceArgs($params);
} else {
return $reflectionClass->newInstance();
}
} else {
trigger_error('Unknown type: ' . $type, E_USER_ERROR);
}
}
示例2: testMapToMethodParameters
/**
* Test converting a map to a set of method parameters.
* @param array $map the map of parameter names to values
* @param array $expected the expected array of parameter values
* @covers MapUtils::MapToMethodParameters
* @dataProvider MapToMethodParametersProvider
*/
public function testMapToMethodParameters(array $map, array $expected)
{
$reflectionClass = new ReflectionClass($this);
$reflectionMethod = $reflectionClass->getMethod('SampleMethod');
$result = MapUtils::MapToMethodParameters($map, $reflectionMethod);
$this->assertEquals($expected, $result);
}