<commit_before><?php
/**
 * View - load template pages
 *
 * @author <NAME> - <EMAIL>
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Core;

use Support\Facades\Facade;


class View extends Facade
{
    /**
     * @var array Array of legacy View instances
     */
    private static $items = array();

    /**
     * @var array Array of legacy HTTP headers
     */
    private static $headers = array();


    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'view'; }

    /**
     * Magic Method for handling dynamic functions.
     *
     * @param  string  $method
     * @param  array   $params
     * @return void|mixed
     */
    public static function __callStatic($method, $params)
    {
        $accessor = static::getFacadeAccessor();

        $instance = static::resolveFacadeInstance($accessor);

        // Process the required action.
        $view = null;

        $template = static::resolveFacadeInstance('template');

        switch ($method) {
            case 'addHeader':
            case 'addHeaders':
                // Add the Header(s) using the legacy method.
                return call_user_func_array(array(static::class, 'addLegacyHeaders'), $params);

            case 'sendHeaders':
                // No Headers will be sent from there.
                return null;

            case 'render':
                // Create a standard View instance.
                $view = call_user_func_array(array($instance, 'make'), $params);

                break;
            case 'renderTemplate':
                // Create a Template View instance.
                $view = call_user_func_array(array($template, 'make'), $params);

                break;
            default:
                // Call the non-static method from the View Factory instance.
                return call_user_func_array(array($instance, $method), $params);
        }

        //
        // We can arrive there only for the methods: 'render' and 'renderTemplate'

        array_push(static::$items, $view);
    }

    //--------------------------------------------------------------------
    // Legacy API Methods
    //--------------------------------------------------------------------

    /**
     * Return the stored (legacy) View instances.
     *
     * @return array
     */
    public static function getItems()
    {
        return static::$items;
    }

    /**
     * Return the stored (legacy) Headers.
     *
     * @return array
     */
    public static function getHeaders()
    {
        return static::$headers;
    }

    /**
     * Add the HTTP header(s) to the legacy Headers array.
     *
     * @param  string  $header HTTP header text
     */
    protected static function addLegacyHeaders($headers)
    {
        if(! is_array($headers)) $headers = array($headers);

        foreach ($headers as $header) {
            list($key, $value) = explode(' ', $header, 1);

            $key = ltrim($key, ':');

            static::$headers[$key] = trim($value);
        }
    }

}
<commit_msg>Improve Core\View<commit_after><?php
/**
 * View - load template pages
 *
 * @author <NAME> - <EMAIL>
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Core;

use Support\Facades\Facade;


class View extends Facade
{
    /**
     * @var array Array of legacy View instances
     */
    private static $items = array();

    /**
     * @var array Array of legacy HTTP headers
     */
    private static $headers = array();


    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'view'; }

    /**
     * Magic Method for handling dynamic functions.
     *
     * @param  string  $method
     * @param  array   $params
     * @return void|mixed
     */
    public static function __callStatic($method, $params)
    {
        $accessor = static::getFacadeAccessor();

        $instance = static::resolveFacadeInstance($accessor);

        // Process the required action.
        $view = null;

        switch ($method) {
            case 'addHeader':
            case 'addHeaders':
                // Add the Header(s) using the legacy method.
                return call_user_func_array(array(static::class, 'addLegacyHeaders'), $params);

            case 'sendHeaders':
                // No Headers will be sent from there.
                return null;

            case 'render':
                // Create a standard View instance.
                $view = call_user_func_array(array($instance, 'make'), $params);

                break;
            case 'renderTemplate':
                // Create a Template View instance.
                $factory = static::resolveFacadeInstance('template');

                $view = call_user_func_array(array($factory, 'make'), $params);

                break;
            default:
                // Call the non-static method from the View Factory instance.
                return call_user_func_array(array($instance, $method), $params);
        }

        //
        // We can arrive there only for the methods: 'render' and 'renderTemplate'

        array_push(static::$items, $view);
    }

    //--------------------------------------------------------------------
    // Legacy API Methods
    //--------------------------------------------------------------------

    /**
     * Return the stored (legacy) View instances.
     *
     * @return array
     */
    public static function getItems()
    {
        return static::$items;
    }

    /**
     * Return the stored (legacy) Headers.
     *
     * @return array
     */
    public static function getHeaders()
    {
        return static::$headers;
    }

    /**
     * Add the HTTP header(s) to the legacy Headers array.
     *
     * @param  string  $header HTTP header text
     */
    protected static function addLegacyHeaders($headers)
    {
        if(! is_array($headers)) $headers = array($headers);

        foreach ($headers as $header) {
            list($key, $value) = explode(' ', $header, 1);

            $key = ltrim($key, ':');

            static::$headers[$key] = trim($value);
        }
    }

}

{'fraction_non_alphanumeric': 0.15702875399361022, 'fraction_numerical': 0.0009584664536741214, 'mean_word_length': 1.5990037359900373, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5963212', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1596, 'n_words': 469}