code: protected function fileWrite($file, $str)
      {
          $return = false;
          $dir = \dirname($file);
          if (!\file_exists($dir)) {
              \mkdir($dir, 0755, true);
          }
          if (\is_writable($file) || !\file_exists($file) && \is_writeable($dir)) {
              $return = \file_put_contents($file, $str);
          }
          return $return;
      }
docs: Write string to file / creates file if doesn't exist
  
  @param string $file filepath
  @param string $str  string to write
  
  @return integer|boolean number of bytes written or false on error