PHP Classes

File: app/helpers.php

Recommend this page to a friend!
  Packages of Pierre-Henry Soria   Link2Payment   app/helpers.php   Download  
File: app/helpers.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Link2Payment
Application to generate links for people to pay
Author: By
Last change:
Date: 4 years ago
Size: 1,118 bytes
 

 

Contents

Class file image Download
<?php
/**
 * @author         Pierre-Henry Soria <hi@ph7.me>
 * @copyright      (c) 2017-2022, Pierre-Henry Soria. All Rights Reserved.
 * @license        GNU General Public License; <https://www.gnu.org/licenses/gpl-3.0.en.html>
 */

declare(strict_types=1);

namespace PH7App {

}

namespace {
    function site_url(string $var = ''): string
    {
        $siteUrl = $_ENV['SITE_URL'];

        if (!empty($var)) {
            return $siteUrl . $var;
        }

        return $siteUrl;
    }

    function site_name(): string
    {
        return $_ENV['SITE_NAME'];
    }

    function asset_url(string $var): string
    {
        return $_ENV['SITE_URL'] . 'assets/' . $var;
    }

    function redirect(string $url, bool $permanent = true): void
    {
        if ($permanent) {
            header('HTTP/1.1 301 Moved Permanently');
        }

        if (strpos($url, 'http') === false) {
            $url = $_ENV['SITE_URL'] . $url;
        }

        header('Location: ' . $url);
        exit;
    }

    function escape(string $value): string
    {
        return htmlspecialchars($value, ENT_QUOTES);
    }
}