Crontab\CrontabFileHandler::parseFromFile PHP Méthode

parseFromFile() public méthode

Reads cron jobs from a file.
public parseFromFile ( Crontab $crontab, string $filename ) : CrontabFileHandler
$crontab Crontab
$filename string
Résultat CrontabFileHandler
    public function parseFromFile(Crontab $crontab, $filename)
    {
        if (!is_readable($filename)) {
            throw new \InvalidArgumentException('File ' . $filename . ' is not readable.');
        }
        $file = file_get_contents($filename);
        foreach ($this->parseString($file) as $element) {
            $crontab->addItem($element);
        }
        return $this;
    }

Usage Example

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testWriteToFileThrowsExceptionWhenFileIsNotWritable()
 {
     $this->crontabFileHandler->parseFromFile($this->crontab, $this->fixtureFile);
     touch($this->tempFile);
     chmod($this->tempFile, 0400);
     $this->crontabFileHandler->writeToFile($this->crontab, $this->tempFile);
     // Expected an InvalidArgumentException because the file is not writable.
 }
All Usage Examples Of Crontab\CrontabFileHandler::parseFromFile