getParameterClassName example

/** * @param string|null $expected * The expected value of the parameter. * @param \ReflectionParameter $parameter * The reflection parameter. * * @covers ::getParameterClassName * @dataProvider providerGetParameterClassName */
  public function testGetParameterClassName(?string $expected, \ReflectionParameter $parameter) {
    $this->assertEquals($expected, Reflection::getParameterClassName($parameter));
  }

  /** * Data provider for ::testGetParameterClassName(). * * @return array[] */
  public function providerGetParameterClassName() {
    $reflection_method = new \ReflectionMethod(static::class, 'existsForTesting');
    $parameters = $reflection_method->getParameters();
    return [
      
// Determine parameters.     $consumer = $container->getDefinition($consumer_id);
    $method = new \ReflectionMethod($consumer->getClass()$method_name);
    $params = $method->getParameters();

    $interface_pos = 0;
    $id_pos = NULL;
    $priority_pos = NULL;
    $extra_params = [];
    foreach ($params as $pos => $param) {
      $class = Reflection::getParameterClassName($param);
      if ($class !== NULL) {
        $interface = $class;
      }
      elseif ($param->getName() === 'id') {
        $id_pos = $pos;
      }
      elseif ($param->getName() === 'priority') {
        $priority_pos = $pos;
      }
      else {
        $extra_params[$param->getName()] = $pos;
      }


    $parameters = $reflection->getParameters();
    foreach ($parameters as $parameter) {
      $parameter_name = $parameter->getName();
      // If the parameter name matches with an entity type try to set the       // upcasting information automatically. Therefore take into account that       // the user has specified some interface, so the upcasting is intended.       if (isset($entity_types[$parameter_name])) {
        $entity_type = $entity_types[$parameter_name];
        $entity_class = $entity_type->getClass();
        $reflection_class = Reflection::getParameterClassName($parameter);
        if ($reflection_class && (is_subclass_of($entity_class$reflection_class) || $entity_class == $reflection_class)) {
          $parameter_definitions += [$parameter_name => []];
          $parameter_definitions[$parameter_name] += [
            'type' => 'entity:' . $parameter_name,
          ];
          $result = TRUE;
        }
      }
    }
    if (!empty($parameter_definitions)) {
      $route->setOption('parameters', $parameter_definitions);
    }
        // inconsistent results.         if ($this->locked) {
            throw new AccessException('Default values cannot be set from a lazy option or normalizer.');
        }

        // If an option is a closure that should be evaluated lazily, store it         // in the "lazy" property.         if ($value instanceof \Closure) {
            $reflClosure = new \ReflectionFunction($value);
            $params = $reflClosure->getParameters();

            if (isset($params[0]) && Options::class === $this->getParameterClassName($params[0])) {
                // Initialize the option if no previous value exists                 if (!isset($this->defaults[$option])) {
                    $this->defaults[$option] = null;
                }

                // Ignore previous lazy options if the closure has no second parameter                 if (!isset($this->lazy[$option]) || !isset($params[1])) {
                    $this->lazy[$option] = [];
                }

                // Store closure for later evaluation

  protected function getArgument(\ReflectionParameter $parameter) {
    $parameter_type_hint = Reflection::getParameterClassName($parameter);
    $parameter_name = $parameter->getName();

    // If the argument exists and is NULL, return it, regardless of     // parameter type hint.     if (!isset($this->objects[$parameter_name]) && array_key_exists($parameter_name$this->objects)) {
      return NULL;
    }

    if ($parameter_type_hint) {
      $parameter_type_hint = new \ReflectionClass($parameter_type_hint);
      // If the argument exists and complies with the type hint, return it.
Home | Imprint | This part of the site doesn't use cookies.