本文整理汇总了PHP中ReflectionMethod::getNumberOfParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getNumberOfParameters方法的具体用法?PHP ReflectionMethod::getNumberOfParameters怎么用?PHP ReflectionMethod::getNumberOfParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getNumberOfParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadController
/**
*
* @global array $config
* @param string $class naziv kotrolera koji se instancira
* @param string $method metod koji se poziva
* @param array $params parametri metode
*/
public static function loadController($controller, $method, $params = array())
{
global $config;
$path_to_controller = realpath("controllers/" . strtolower($controller) . "Controller.php");
if (file_exists($path_to_controller)) {
include_once $path_to_controller;
$controller = strtolower($controller) . "Controller";
$controller_instance = new $controller();
if (!is_subclass_of($controller_instance, 'baseController')) {
echo $config['Poruke']['noBaseCont'];
die;
}
if (method_exists($controller_instance, $method)) {
$refl = new ReflectionMethod(get_class($controller_instance), $method);
$numParams = $refl->getNumberOfParameters();
if ($numParams > 0 && count($params) < $numParams) {
echo $config['Poruke']['noParams'];
die;
}
call_user_func_array(array($controller_instance, $method), $params);
} else {
echo $config['Poruke']['noMethod'];
}
} else {
echo $config['Poruke']['error404'];
}
}
示例2: dispatch
public function dispatch()
{
$acao = self::sulfixo_controle . $this->paginaSolicitada;
if (method_exists($this, $acao)) {
$reflection = new ReflectionMethod($this, $acao);
$qtdArgumentos = $reflection->getNumberOfParameters();
$parametros = array();
$i = 0;
foreach ($_GET as $key => $value) {
if (!empty($value) && $key != 'a' && $i <= $qtdArgumentos) {
$parametros[$i] = $value;
}
$i++;
}
if (count($parametros) < $qtdArgumentos) {
$i = $qtdArgumentos - count($parametros);
for ($index = 0; $index < $i; $index++) {
$parametros[$index + count($parametros) + 1] = '';
}
}
call_user_func_array(array($this, $acao), $parametros);
} else {
$this->erro_404();
}
}
示例3: run
public static function run()
{
$currentPath = substr($_SERVER['REQUEST_URI'], 44);
$currentMethod = $_SERVER['REQUEST_METHOD'];
if (strpos($currentPath, '?') !== false) {
$currentPath = explode('?', $currentPath);
$currentPath = $currentPath[0];
}
foreach (static::$routes as $value) {
$matches[] = array();
if (preg_match($value['path'], $currentPath, $matches) === 0) {
continue;
}
if ($currentMethod !== $value['method']) {
continue;
}
unset($matches[0]);
$controller = new $value['class']();
$info = new \ReflectionMethod($controller, $value['function']);
if ($info->getNumberOfParameters() !== count($matches)) {
throw new \Exception('Numero de parametros incorrecto: ' . $value['class'] . '::' . $value['function']);
}
$response = $info->invokeArgs($controller, $matches);
if (is_null($response)) {
return;
}
if ($response instanceof View) {
Response::view($response);
}
return;
}
// Lanzar 404
App::abort(404, 'No se encuentra la ruta');
}
示例4: isAutoloadMethod
/**
* @param \ReflectionMethod $method
* @return bool
*/
private function isAutoloadMethod(\ReflectionMethod $method)
{
if (strpos($method->getName(), KnotConsts::AUTOLOAD_METHOD_PREFIX) !== 0 || $method->getNumberOfParameters() != 1 || $method->getNumberOfRequiredParameters() != 1 || $method->isStatic() || $method->isAbstract() || !Extractor::instance()->has($method, KnotConsts::AUTOLOAD_ANNOTATIONS)) {
return false;
}
return true;
}
示例5: run
/**
* Runs the action.
* The action method defined in the controller is invoked.
* This method is required by {@link CAction}.
*/
public function run()
{
$controller = $this->getController();
$methodName = 'action' . $this->getId();
$method = new ReflectionMethod($controller, $methodName);
if (($n = $method->getNumberOfParameters()) > 0) {
$params = array();
foreach ($method->getParameters() as $i => $param) {
$name = $param->getName();
if (isset($_GET[$name])) {
if ($param->isArray()) {
$params[] = is_array($_GET[$name]) ? $_GET[$name] : array($_GET[$name]);
} else {
if (!is_array($_GET[$name])) {
$params[] = $_GET[$name];
} else {
throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
}
}
} else {
if ($param->isDefaultValueAvailable()) {
$params[] = $param->getDefaultValue();
} else {
throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
}
}
}
$method->invokeArgs($controller, $params);
} else {
$controller->{$methodName}();
}
}
示例6: loadRules
/**
* Call this method to load all rules
*/
public function loadRules()
{
$this->rules = [];
foreach (get_class_methods($this) as $rule) {
if (mb_substr($rule, 0, 6) === 'rule__') {
$name = mb_substr($rule, 6);
$method = new \ReflectionMethod($this, $rule);
if (!$method->getNumberOfParameters() === 3) {
//the method expects too much/less arguments
$this->errorHandler->log('methods', "The method \"{$name}\" expects " . $method->getNumberOfParameters() . " but it should expect 3 arguments.");
continue;
}
$this->rules[] = ['name' => $name, 'class' => $method];
}
}
}
示例7: gettersToArray
public static function gettersToArray($object)
{
if (!is_object($object)) {
throw new \InvalidArgumentException('$object must be an object.');
}
$result = [];
// Iterate over all getters.
foreach (get_class_methods($object) as $method) {
if (strncmp('get', $method, 3) == 0) {
$reflector = new \ReflectionMethod($object, $method);
if ($reflector->isPublic() && $reflector->getNumberOfParameters() == 0) {
$key = lcfirst(substr($method, 3));
$value = $object->{$method}();
if (is_array($value)) {
foreach ($value as &$entry) {
if (is_object($entry)) {
$entry = static::gettersToArray($entry);
}
}
}
$result[$key] = is_object($value) ? static::gettersToArray($value) : $value;
} elseif ($object instanceof Question && $method === 'getQuestions') {
for ($i = 0; $i < $object->getDimensions(); $i++) {
foreach ($object->getQuestions($i) as $question) {
$result['questions'][$i][] = self::gettersToArray($question);
}
}
}
}
}
return $result;
}
示例8: __construct
public function __construct($class, $method)
{
parent::__construct();
$ref = new ReflectionMethod($class, $method);
$this->_ref = $ref;
$this->_args = $ref->getParameters();
$this->_args_cnt = $ref->getNumberOfParameters();
}
示例9: testSearchMethod
public function testSearchMethod()
{
$et = new ExactTarget("", "");
$this->assertTrue(method_exists('ExactTarget', 'search'), "search method exists");
$method = new ReflectionMethod('ExactTarget', 'search');
$num = $method->getNumberOfParameters();
$this->assertEquals(2, $num, "has 2 function argument");
}
示例10: getNumberOfParameters
/**
* Returns the number of parameters
*
* @return integer The number of parameters
* @since PHP 5.0.3
*/
public function getNumberOfParameters()
{
if ($this->reflectionSource instanceof ReflectionMethod) {
return $this->reflectionSource->getNumberOfParameters();
} else {
return parent::getNumberOfParameters();
}
}
示例11: 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);
}
示例12: runWithParams
public function runWithParams($params)
{
$method = new ReflectionMethod($this, 'run');
if ($method->getNumberOfParameters() > 0) {
return $this->runWithParamsInternal($this, $method, $params);
} else {
return $this->run();
}
}
示例13: setDefaultOptions
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setRequired(array('fields'));
$reflection = new \ReflectionMethod($resolver, 'setAllowedTypes');
if ($reflection->getNumberOfParameters() === 2) {
$resolver->setAllowedTypes('fields', 'array');
} else {
$resolver->setAllowedTypes(array('fields' => 'array'));
}
}
示例14: elseif
function resolve2($context, array $path)
{
$original_path = $path;
$head = array_shift($path);
$args = $path;
$head = $this->translate($head);
// If the head is empty, then the URL ended in a slash (/), assume
// the index is implied
if (!$head) {
$head = 'index';
}
try {
$method = new \ReflectionMethod($context, $head);
// Ensure that the method is visible
if (!$method->isPublic()) {
return false;
}
// Check if argument count matches the rest of the URL
if (count($args) < $method->getNumberOfRequiredParameters()) {
// Not enough parameters in the URL
return false;
}
if (count($args) > ($C = $method->getNumberOfParameters())) {
// Too many parameters in the URL — pass as many as possible to the function
$path = array_slice($args, $C);
$args = array_slice($args, 0, $C);
}
// Try to call the method and see what kind of response we get
$result = $method->invokeArgs($context, $args);
if ($result instanceof View\BaseView) {
return $result;
} elseif (is_callable($result)) {
// We have a callable to be considered the view. We're done.
return new View\BoundView($result, $args);
} elseif ($result instanceof Dispatcher) {
// Delegate to a sub dispatcher
return $result->resolve(implode('/', $path));
} elseif (is_object($result)) {
// Recurse forward with the remainder of the path
return $this->resolve2($result, $path);
}
// From here, we assume that the call failed
} catch (\ReflectionException $ex) {
// No such method, try def() or recurse backwards
} catch (Exception\ConditionFailed $ex) {
// The matched method refused the request — recurse backwards
}
// Not able to dispatch the method. Try def()
if ($head != 'def') {
$path = array_merge(['def'], $original_path);
return $this->resolve2($context, $path);
}
// Unable to dispatch the request
return false;
}
示例15: runWithParams
/**
* Выполняет действие с переданными параметрами запроса. Данный метод
* вызывается методом {@link CController::runAction()}
* @param array $params параметры запроса (имя => значение)
* @return boolean верны ли параметры запроса
* @since 1.1.7
*/
public function runWithParams($params)
{
$methodName = 'action' . $this->getId();
$controller = $this->getController();
$method = new ReflectionMethod($controller, $methodName);
if ($method->getNumberOfParameters() > 0) {
return $this->runWithParamsInternal($controller, $method, $params);
} else {
return $controller->{$methodName}();
}
}