<commit_before><?php
/*
 * This file is part of the AlphaLemonThemeEngineBundle and it is distributed
 * under the MIT License. In addiction, to use this bundle, you must leave
 * intact this copyright notice.
 *
 * Copyright (c) AlphaLemon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://alphalemon.com
 *
 * @license    MIT License
 */

namespace AlphaLemon\ThemeEngineBundle\Twig;

use AlphaLemon\ThemeEngineBundle\Core\PageTree\AlPageTree;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
 * Adds the renderSlot function to Twig engine
 *
 * @author <NAME>
 */
class SlotRendererExtension extends \Twig_Extension
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function render($slotName = null)
    {
        if(null === $slotName)
        {
            throw new InvalidArgumentException("renderSlot function requires a valid slot name to render the contents");
        }

        try
        {
            $result = '';
            $slotContents = $this->container->get('al_page_tree')->getPageBlocks($slotName);
            if(count($slotContents) > 0)
            {
                foreach($slotContents as $contents)
                {
                    if(\array_key_exists('RenderView', $contents))
                    {
                        $params = (isset($contents['RenderView']['params'])) ? $contents['RenderView']['params'] : array();
                        $result .= $this->container->get('templating')->render($contents['RenderView']['view'], $params);
                    }
                    else if(\array_key_exists('HtmlContent', $contents))
                    {
                        $result .= $contents['HtmlContent'];
                    }
                }<commit_msg>verifies when the al_page_tree service is available and returns null when it isn't<commit_after><?php
/*
 * This file is part of the AlphaLemonThemeEngineBundle and it is distributed
 * under the MIT License. In addiction, to use this bundle, you must leave
 * intact this copyright notice.
 *
 * Copyright (c) AlphaLemon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For extra documentation and help please visit http://alphalemon.com
 *
 * @license    MIT License
 */

namespace AlphaLemon\ThemeEngineBundle\Twig;

use AlphaLemon\ThemeEngineBundle\Core\PageTree\AlPageTree;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
 * Adds the renderSlot function to Twig engine
 *
 * @author <NAME>
 */
class SlotRendererExtension extends \Twig_Extension
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function render($slotName = null)
    {
        if(null === $slotName)
        {
            throw new InvalidArgumentException("renderSlot function requires a valid slot name to render the contents");
        }

        try
        {
            $result = '';

            if (!$this->container->has('al_page_tree')) {
                return $result;
            }

            $slotContents = $this->container->get('al_page_tree')->getPageBlocks($slotName);
            if(count($slotContents) > 0)
            {
                foreach($slotContents as $contents)
                {
                    if(\array_key_exists('RenderView', $contents))
                    {
                        $params = (isset($contents['RenderView']['params'])) ? $contents['RenderView']['params'] : array();
                        $result .= $this->container->get('templating')->render($contents['RenderView']['view'], $params);
                    }
                    else if(\array_key_exists('HtmlContent', $contents))
                    {
                        $result .= $contents['HtmlContent'];
                    }
                }
{'fraction_non_alphanumeric': 0.10769946499185858, 'fraction_numerical': 0.00046522447080716444, 'mean_word_length': 2.3463035019455254, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2950031', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1032, 'n_words': 284}