code: private function ensureDirectoryExists($path)
      {
          if (!is_dir($path)) {
              if (!mkdir($path, 0777, true)) {
                  throw new \RuntimeException(sprintf('Could not create directory "%s"', $path));
              }
          }
  
          return $path;
      }
docs: Attempts to create the given directory, throwing an exception if unable to
  
  @param string $path
  
  @return string            $path
  @throws \RuntimeException