<commit_before><?php 

    /**
     * Helpers
     * 
     * Helper PHP function.
     * 
     * @author <NAME> <<EMAIL>>
     * @link https://github.com/davidecesarano/embryo-framework
     */

    use Embryo\Facades\Container;

    /**
     * Debug for information about 
     * a variable.
     *
     * @param mixed $data
     * @return string
     */
    function debug($data)
    {
        echo '<pre>';
            print_r($data);
        echo '</pre>';
    }

    /**
     * Dumps information about a variable.
     *
     * @param mixed $data
     * @return string
     */
    function dump($data)
    {
        echo '<pre>';
            var_dump($data);
        echo '</pre>';
    }

    /**
     * Generate a fully qualified URL 
     * from to app url.
     *
     * @param string|null $path
     * @return string
     */
    function site_url(string $path = null)
    {
        $url = Container::get('baseUrl');
        return (!$path) ? $url : $url.'/'.trim($path, '/');
    }

    /**
     * Generate a fully qualified path
     * from the project root.
     *
     * @param string|null $path
     * @return string
     */
    function app_path(string $path = null) 
    {
        $settings = Container::get('settings');
        $app_path = rtrim($settings['app']['root_path'], '/'); 
        return (!$path) ? $app_path : $app_path.'/'.ltrim($path, '/');
    }

    /**
     * Generate a fully qualified URL
     * from the asset resources.
     * 
     * If versioning is true, append the 
     * filemtime to query param 'v'.
     *
     * @param string $path
     * @param bool $versioning
     * @return string
     */
    function asset(string $path, $versioning = false)
    {
        if ($versioning) {
            $res = filemtime(app_path('public/assets/'.trim($path, '/')));
            return site_url('assets/'.$path.'?v='.$res);
        } else {
            return site_url('assets/'.$path);
        }
    }

    /**
     * Return CSRF token from request session 
     * attribute.
     *
     * @param string $name
     * @return string
     */
    function csrf_token($name = 'csrf_token')
    {
        $request = Container::get('request');
        $session = $request->getAttribute('session');
        $tokens  = $session->get('csrf_token', []);
        return '<input type="hidden" name="'.$name.'" value="'.end($tokens).'">';
    }

    /**
     * Return message translation.
     *
     * @param string $key
     * @param array $context
     * @return string
     */
    function trans(string $key, array $context = [])
    {
        $locale = Container::get('settings')['app']['locale'];
        $session = Container::get('request')->getAttribute('session');
        
        if ($session) {
            $language = $session->get('language', $locale);
            $messages = Container::get('translate')->getMessages($language);
            return $messages->get($key, $context);
        }
        return $key;
    }<commit_msg>Edit helpers and add news<commit_after><?php 

    /**
     * Helpers
     * 
     * Helper PHP function.
     * 
     * @author <NAME> <<EMAIL>>
     * @link https://github.com/davidecesarano/embryo-framework
     */

    use Embryo\Facades\Container;

    /**
     * ------------------------------------------------------------
     * INFORMATION ABOUT A VARIABLE
     * ------------------------------------------------------------
     */

    /**
     * Debug for information about 
     * a variable.
     *
     * @param mixed $data
     * @return string
     */
    function debug($data)
    {
        echo '<pre>';
            print_r($data);
        echo '</pre>';
    }

    /**
     * Dumps information about a variable.
     *
     * @param mixed $data
     * @return string
     */
    function dump($data)
    {
        echo '<pre>';
            var_dump($data);
        echo '</pre>';
    }

    /**
     * ------------------------------------------------------------
     * SETTINGS APP
     * ------------------------------------------------------------
     */

    /**
     * Generate a fully qualified URL 
     * from to app url.
     *
     * @param string|null $path
     * @return string
     */
    function app_url(string $path = null)
    {
        $url = Container::get('baseUrl');
        return (!$path) ? $url : $url.'/'.trim($path, '/');
    }

    /**
     * Generate a fully qualified path
     * from the project root.
     *
     * @param string|null $path
     * @return string
     */
    function app_path(string $path = null) 
    {
        $settings = Container::get('settings');
        $app_path = rtrim($settings['app']['root_path'], '/'); 
        return (!$path) ? $app_path : $app_path.'/'.ltrim($path, '/');
    }

    /**
     * Get App name.
     *
     * @param string $prepend
     * @return string
     */
    function app_name(string $prepend = null)
    {
        $settings = Container::get('settings');
        return (!$append) ? $append.' - '.$settings['app']['name'] : $settings['app']['name'];
    }

    /**
     * Get app locale.
     *
     * @return string
     */
    function app_locale()
    {
        $settings = Container::get('settings');
        return $settings['app']['locale'];
    }

    /**
     * Get app charset.
     *
     * @return string
     */
    function app_charset()
    {
        $settings = Container::get('settings');
        return $settings['app']['charset'];
    }

    /**
     * Alias of app_url()
     *
     * @param string|null $path
     * @return string
     */
    function site_url(string $path = null)
    {
        return app_url($path);
    }

    /**
     * ------------------------------------------------------------
     * ASSETS
     * ------------------------------------------------------------
     */

    /**
     * Generate a fully qualified URL
     * from the asset resources.
     * 
     * If versioning is true, append the 
     * filemtime to query param 'v'.
     *
     * @param string $path
     * @param bool $versioning
     * @return string
     */
    function asset(string $path, $versioning = false)
    {
        if ($versioning) {
            $res = filemtime(app_path('public/assets/'.trim($path, '/')));
            return app_url('assets/'.$path.'?v='.$res);
        } else {
            return app_url('assets/'.$path);
        }
    }

    /**
     * ------------------------------------------------------------
     * EMBRYO CSRF
     * ------------------------------------------------------------
     */

    /**
     * Return CSRF token from request session 
     * attribute.
     *
     * @param string $name
     * @return string
     */
    function csrf_token($name = 'csrf_token')
    {
        $request = Container::get('request');
        $session = $request->getAttribute('session');
        $tokens  = $session->get($name, []);
        return '<input type="hidden" name="'.$name.'" value="'.end($tokens).'">';
    }

    /**
     * ------------------------------------------------------------
     * EMBRYO TRANSLATE
     * ------------------------------------------------------------
     */

    /**
     * Return message translation.
     *
     * @param string $key
     * @param array $context
     * @return string
     */
    function trans(string $key, array $context = [])
    {
        $locale = Container::get('settings')['app']['locale'];
        $session = Container::get('request')->getAttribute('session');
        
        if ($session) {
            $language = $session->get('language', $locale);
            $messages = Container::get('translate')->getMessages($language);
            return $messages->get($key, $context);
        }
        return $key;
    }
{'fraction_non_alphanumeric': 0.22801091334286086, 'fraction_numerical': 0.0, 'mean_word_length': 1.4169544740973312, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '3467484', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2132, 'n_words': 464}