HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers85/equichecker.com/app/Helpers/KommaHelpers.php
<?php

namespace App\Helpers;
use DateTime;

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */
class KommaHelpers
{
    /**
     * This function will localize the date
     *
     * @param $date
     * @return DateTime
     */
    static function localize_date($date, $format = 'd-m-Y H:i')
    {

        date_default_timezone_set('UTC');
        $datetime = new DateTime($date);
        $la_time = new \DateTimeZone('Europe/Amsterdam');
        $datetime->setTimezone($la_time);
        return $datetime->format($format);
    }


    static function komma_ip()
    {
        if ($_SERVER['REMOTE_ADDR'] == '84.246.3.230') return true;
        return false;
    }

    static function price($value, $parameters = array())
    {
        return number_format($value / 100, 2, ',', '.');
    }


    /**
     * Create an empty file on the fly based on the filePath
     * Check if it already exist, if it exist return true
     * Check if the folder exist, create when needed
     * Create a file and fill with the given data.
     *
     * @param $filePath
     * @param $data | String
     * @return bool
     */
    static function createFile($filePath, $data = '')
    {
        //Check if file exist, if true return
        if (is_file($filePath)) return true;

        //split the path in parts based on / (folder)
        $parts = explode('/', $filePath);

        //Pop the last item from the array, this is the file name
        $fileName = array_pop($parts);

        //Glue the path back together, without filename
        $path = implode('/', $parts);


        //If the dir doesn't exist, create this
        if (!is_dir($path)) mkdir($path, 0777, true);

        //Create an empty file on the location
        file_put_contents($path . '/' . $fileName, $data);

        return true;
    }

    /**
     * Remove a file from the disc
     *
     *
     * @param $filePath
     * @return bool
     */
    static function removeFile($filePath)
    {
        //Check if file exist, if false, return
        if (!is_file($filePath)) return true;
        //Remove the file
        unlink($filePath);
    }

    /**
     * Replace the / to a -
     * for the given string.
     *
     * @param $string
     * @return string
     */
    static function slashToDash($string)
    {
        return str_replace('/', '-', $string);
    }

    /**
     * Replace the - to a /
     * for the given string.
     *
     * @param $string
     * @return string
     */
    static function dashToSlash($string)
    {
        return str_replace('-', '/', $string);
    }


    /**
     * Replace the / to a _
     * for the given string.
     *
     * @param $string
     * @return string
     */
    static function slashToUnderScore($string)
    {
        return str_replace('/', '_', $string);
    }

    /**
     * Replace the _ to a /
     * for the given string.
     *
     * @param $string
     * @return string
     */
    static function UnderScoreToSlash($string)
    {
        return str_replace('_', '/', $string);
    }

    /**
     * Get data from the input.
     * based on the given key
     * and the language id
     *
     * @param $key
     * @param $language
     * @return mixed
     */
    static function getTranslationInput($key, $language, $suffix = '')
    {
        $key = $key;
        $key .= '_' . $language->id;

        if ($suffix != '') $key .= '_' . $suffix;
        return \Input::get($key);
    }
    
    /**
     * This method checks if an Kms attribute is required
     *
     * @param $attribute
     * @return bool
     */
    static function isRequired($attribute){
        if(!isset($attribute->options)) return false;
        if(!isset($attribute->options['validation'])) return false;
        if(!isset($attribute->options['validation']['rules'])) return false;
        if(!preg_match('/required/', $attribute->options['validation']['rules'])) return false;
        return true;
    }


}