isInstance example

$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.       if (isset($this->objects[$parameter_name]) && is_object($this->objects[$parameter_name]) && $parameter_type_hint->isInstance($this->objects[$parameter_name])) {
        return $this->objects[$parameter_name];
      }
      // Otherwise, resolve wildcard arguments by type matching.       foreach ($this->wildcards as $wildcard) {
        if ($parameter_type_hint->isInstance($wildcard)) {
          return $wildcard;
        }
      }
    }
    elseif (isset($this->scalars[$parameter_name])) {
      return $this->scalars[$parameter_name];
    }
class InstanceOfExtension extends AbstractExtension
{
    public function getTests(): array
    {
        return [
            'instanceof' => new TwigTest('instanceof', $this->isInstanceOf(...)),
        ];
    }

    public function isInstanceOf($var$class): bool
    {
        return (new \ReflectionClass($class))->isInstance($var);
    }
}
Home | Imprint | This part of the site doesn't use cookies.