ParserHandler.php 1.1 KB
<?php
namespace backend\components\parsers;
use common\components\debug\CustomVarDamp;

use Yii;


class ParserHandler {

/** @var string */
    private $filePath;

    /** @var instance of SplFileObject */
    private $fileObject;

    /** @var string - extension of file $filePath */
    private $extension;

    /** @var string - extension of file $filePath */
    private $mode;

    /**
     * @param string first line in file for parsing
     */
    public function __construct( $filePath, $mode  )
    {
        $this->filePath = $filePath;
        $this->mode = $mode;

        try {
            $this->fileObject = new \SplFileObject( $this->filePath , 'r' );;
        } catch (\ErrorException $e) {
            Yii::warning("Ошибка открытия файла {$this->filePath}");
        }

        //preg_match( '/\.[^\.]+$/i',$filePath, $resultArray );
        $this->extension = $this->fileObject->getExtension();
    }

    public function run(){

            $parser = Yii::createObject( ParserConfigurator::getConfiguration() );
            $parser->setup();
            return $parser->read();
    }
}