NFePHP\Common\Files\FilesFolders::readFile PHP Method

readFile() public static method

readFile
public static readFile ( string $pathFile = '' ) : string
$pathFile string
return string
    public static function readFile($pathFile = '')
    {
        if ($pathFile == '') {
            $msg = "Um caminho para o arquivo deve ser passado!!";
            throw new Exception\InvalidArgumentException($msg);
        }
        if (!is_file($pathFile)) {
            $msg = "O arquivo indicado não foi localizado!! {$pathFile}";
            throw new Exception\InvalidArgumentException($msg);
        }
        if (!is_readable($pathFile)) {
            $msg = "O arquivo indicado não pode ser lido. Permissões!! {$pathFile}";
            throw new Exception\RuntimeException($msg);
        }
        return file_get_contents($pathFile);
    }

Usage Example

示例#1
0
 /**
  * verifica
  * Verifica o status da SEFAZ com o webservice e retorna tags html com o resultado
  * @param string $config json do arquivo de configuração
  * @return string
  */
 public static function verifica($config = '')
 {
     $aRetorno = array();
     if (empty($config)) {
         return '';
     }
     self::$config = $config;
     if (is_file(APP_ROOT . '/base/status.json')) {
         $aRetorno = (array) json_decode(FilesFolders::readFile(APP_ROOT . '/base/status.json'));
     }
     $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']);
     $tsnow = time();
     $dif = $tsnow - $tstmp;
     //caso tenha passado mais de uma hora desde a ultima verificação
     if ($dif > 3600) {
         self::$nfe = new ToolsNFe($config);
         self::$certTS = self::$nfe->certExpireTimestamp;
         self::$nfe->sefazStatus('', '', $aRetorno);
         $retJson = json_encode($aRetorno);
         FilesFolders::saveFile(APP_ROOT . '/base', 'status.json', $retJson);
     }
     $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']);
     $dhora = date('d/m/Y H:i:s', $tstmp);
     $htmlStatus = "<p class=\"smallred\">OFF-LINE</p>\n<p class=\"smallred\">{$dhora}</p>";
     if ($aRetorno['cStat'] == '107') {
         $htmlStatus = "<p class=\"smallgreen\">SEFAZ On-Line</p>\n<p class=\"smallgreen\">{$dhora}</p>";
     }
     return $htmlStatus;
 }
All Usage Examples Of NFePHP\Common\Files\FilesFolders::readFile