HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/mobilech/nepalapplesupport.com/wp-content/plugins/timetics/base/csv-reader.php
<?php
/**
 * Read CSV file
 *
 * @package Timetics
 */
namespace Timetics\Base;

/**
 * CSV Reader Class
 */
class CsvReader implements FileReaderInterface {
    /**
     * Store file
     *
     * @var string
     */
    private static $file;

    /**
     * Get data that will be read from csv file
     *
     * @param   file  $file
     *
     * @return  array
     */
    public static function get_data( $file ) {
        self::$file = $file;

        return self::read_file();
    }

    /**
     * Get from file
     *
     * @return  array
     */
    private static function read_file() {
        $file     = self::$file;
        $csv_data = [];

        $handle  = fopen( $file, 'r' );
        $headers = fgetcsv( $handle );

        if ( ! $headers ) {
            return $csv_data;
        }

        if ( $handle !== false ) {
            $header_count = count( $headers );

            while (  ( $data = fgetcsv( $handle ) ) !== false ) {
                $row = [];

                for ( $i = 0; $i < $header_count; $i++ ) {
                    $row[$headers[$i]] = $data[$i];
                }

                $csv_data[] = $row;
            }
        }

        fclose( $handle );

        return $csv_data;
    }
}