Themsaid\Langman\Manager::createFile PHP Method

createFile() public method

Create a file for all languages if does not exist already.
public createFile ( $fileName ) : void
$fileName
return void
    public function createFile($fileName)
    {
        foreach ($this->languages() as $languageKey) {
            $file = $this->path . "/{$languageKey}/{$fileName}.php";
            if (!$this->disk->exists($file)) {
                file_put_contents($file, "<?php \n\n return[];");
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Array of requested file in different languages.
  *
  * @return array
  */
 private function filesFromKey()
 {
     try {
         return $this->manager->files()[$this->fileName];
     } catch (\ErrorException $e) {
         if ($this->confirm(sprintf('Language file %s.php not found, would you like to create it?', $this->fileName))) {
             $this->manager->createFile(str_replace($this->packageName . '::', '', $this->fileName));
         }
         return [];
     }
 }