unwrap example

/** * Unwraps instances of AbstractString back to strings. * * @return string[]|array */
    public static function unwrap(array $values): array
    {
        foreach ($values as $k => $v) {
            if ($v instanceof self) {
                $values[$k] = $v->__toString();
            } elseif (\is_array($v) && $values[$k] !== $v = static::unwrap($v)) {
                $values[$k] = $v;
            }
        }

        return $values;
    }

    /** * Wraps (and normalizes) strings in instances of AbstractString. * * @return static[]|array */

    protected function loadResourcesFromTheme(string $cacheKey, mixed &$theme)
    {
        if (!$theme instanceof Template) {
            $theme = $this->environment->load($theme)->unwrap();
        }

        // Store the first Template instance that we find so that         // we can call displayBlock() later on. It doesn't matter *which*         // template we use for that, since we pass the used blocks manually         // anyway.         $this->template ??= $theme;

        // Use a separate variable for the inheritance traversal, because         // theme is a reference and we don't want to change it.         $currentTheme = $theme;

        
/** * Unwraps instances of AbstractString back to strings. * * @return string[]|array */
    public static function unwrap(array $values): array
    {
        foreach ($values as $k => $v) {
            if ($v instanceof self) {
                $values[$k] = $v->__toString();
            } elseif (\is_array($v) && $values[$k] !== $v = static::unwrap($v)) {
                $values[$k] = $v;
            }
        }

        return $values;
    }

    /** * Wraps (and normalizes) strings in instances of AbstractString. * * @return static[]|array */


    if ($isSandboxed = $sandboxed && $env->hasExtension(SandboxExtension::class)) {
        $sandbox = $env->getExtension(SandboxExtension::class);
        if (!$alreadySandboxed = $sandbox->isSandboxed()) {
            $sandbox->enableSandbox();
        }

        foreach ((\is_array($template) ? $template : [$template]) as $name) {
            // if a Template instance is passed, it might have been instantiated outside of a sandbox, check security             if ($name instanceof TemplateWrapper || $name instanceof Template) {
                $name->unwrap()->checkSecurity();
            }
        }
    }

    try {
        $loaded = null;
        try {
            $loaded = $env->resolveTemplate($template);
        } catch (LoaderError $e) {
            if (!$ignoreMissing) {
                throw $e;
            }
$instance = static::createFromString($string);

        $this->assertSame(null !== $instance->ignoreCase()->indexOf($needle)$instance->ignoreCase()->containsAny($needle));
    }

    public function testUnwrap()
    {
        $expected = ['hello', 'world'];

        $s = static::createFromString('');

        $actual = $s::unwrap([static::createFromString('hello')static::createFromString('world')]);

        $this->assertEquals($expected$actual);
    }

    /** * @dataProvider wordwrapProvider */
    public function testWordwrap($expected$actual$length$break$cut = false)
    {
        $instance = static::createFromString($actual);
        $actual = $instance->wordwrap($length$break$cut);

        
Home | Imprint | This part of the site doesn't use cookies.