Saves the code into the file specified by [[path]].
Taken/modified from yii\gii\CodeFile
@param string $path
@param string $content
@return string|boolean the error occurred while saving the code file, or true if no error.
487413
protected function save($path, $content)
    {
        $newDirMode = 0755;
        $newFileMode = 0644;

        $dir = dirname($path);
        if (!is_dir($dir)) {
            $mask = @umask(0);
            $result = @mkdir($dir, $newDirMode, true);
            @umask($mask);
            if (!$result) {
                return "Unable to create the directory '$dir'.";
            }
        }
        if (@file_put_contents($path, $content) === false) {
            return "Unable to write the file '{$path}'.";
        } else {
            $mask = @umask(0);
            @chmod($path, $newFileMode);
            @umask($mask);
        }

        return true;
    }
809848
public function createFile($path, $contents)
    {
        $path = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path);

        $this->_io->out();

        $fileExists = is_file($path);
        if ($fileExists && empty($this->params['force']) && !$this->interactive) {
            $this->_io->out('<warning>File exists, skipping</warning>.');

            return false;
        }

        if ($fileExists && $this->interactive && empty($this->params['force'])) {
            $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
            $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');

            if (strtolower($key) === 'q') {
                $this->_io->out('<error>Quitting</error>.', 2);
                $this->_stop();

                return false;
            }
            if (strtolower($key) === 'a') {
                $this->params['force'] = true;
                $key = 'y';
            }
            if (strtolower($key) !== 'y') {
                $this->_io->out(sprintf('Skip `%s`', $path), 2);

                return false;
            }
        } else {
            $this->out(sprintf('Creating file %s', $path));
        }

        $File = new File($path, true);

        try {
            if ($File->exists() && $File->writable()) {
                $File->write($contents);
                $this->_io->out(sprintf('<success>Wrote</success> `%s`', $path));

                return true;
            }

            $this->_io->err(sprintf('<error>Could not write to `%s`</error>.', $path), 2);

            return false;
        } finally {
            $File->close();
        }
    }
887617
protected function _annotate($path, $content, array $annotations) {
		if (!count($annotations)) {
			return false;
		}

		$file = $this->_getFile($path, $content);

		$phpOpenTagIndex = $file->findNext(T_OPEN_TAG, 0);
		if ($phpOpenTagIndex === false) {
			$phpOpenTagIndex = null;
		}

		$needsPhpTag = $phpOpenTagIndex === null || $this->_needsPhpTag($file, $phpOpenTagIndex);
		$docBlockCloseTagIndex = null;
		if ($needsPhpTag) {
			$phpOpenTagIndex = null;
		} else {
			$docBlockCloseTagIndex = $this->_findExistingDocBlock($file, $phpOpenTagIndex);
		}

		$this->_resetCounter();
		if ($docBlockCloseTagIndex && !$this->isInlineDocBlock($file, $docBlockCloseTagIndex)) {
			$newContent = $this->_appendToExistingDocBlock($file, $docBlockCloseTagIndex, $annotations);
		} else {
			$newContent = $this->_addNewTemplateDocBlock($file, $annotations, $phpOpenTagIndex, $docBlockCloseTagIndex);
		}

		$this->_displayDiff($content, $newContent);
		$this->_storeFile($path, $newContent);

		$this->_report();

		return true;
	}
1059087
private function createContextFile($path, $content)
    {
        file_put_contents($path, $content);

        if ($this->logger) {
            $this->logger->fileCreated($path, 'place your definitions, transformations and hooks here');
        }
    }
360342
public function save($filename, $content) {
        if ($this->driver) {
            return $this->driver->save($filename, $content);
        }

        return false;
    }
1319311
private function writeFile(
        InputInterface $input,
        OutputInterface $output,
        $path,
        $content
    ) {
        // A shorter path to the new file, relative to the site root.
        $shortPath = str_replace(getcwd() . '/', '', $path);

        /** @var Filesystem $filesystem */
        $filesystem = $this->getContainer()->get('filesystem');

        if (!$filesystem->exists($path) || $input->getOption('force')) {
            $filesystem->dumpFile($path, $content);

            $output->writeln('<info>' . sprintf('%s has been created.', $shortPath) . '</info>');
        } else {
            $output->writeln('<error>' . sprintf('%s already exists.', $shortPath) . '</error>');
        }

        return $this;
    }
1077289
public function saveXmlFile($path = '')
    {
        $this->formatOutput = true;

        if ($path) {
            $bool = @$this->save($path);
            if (!$bool) {
                $this->error = 'save_file_error';
                return false;
            }

            return true;
        }

        return $this->saveXML();
    }
2792
protected function putContentToTmpFile($content)
    {
        $path = $this->createTempFilePath(self::HTML_EXTENSION);

        $this->createFile($path, $content);

        return $path;
    }
405034
public function saveFile($path, $data)
    {
        $storage = $data;

        if ($data instanceof Slice)
        {
            $storage = $data->asArray();
        }

        switch ($this->type)
        {
            case PHP:
                $result = '<?php'
                    . PHP_EOL
                    . PHP_EOL .
                    'return ' . var_export($storage, true) . ';';
                break;

            case YML:
                $result = \Symfony\Component\Yaml\Yaml::dump($storage);
                break;

            case JSON:
                $json = clone $this->helper->json();
                $json->addOption(JSON_PRETTY_PRINT);
                $result = $json->encode($storage);
                break;

            default:
                throw new Exceptions\TypeNotFound($this->type);
        }

        $filePath = $this->path($path);

        return file_put_contents($filePath, $result);
    }
258755
protected function writeObject($path, $content, array $metadata)
	{
		try {
			if (\is_resource($content)) {
				$id = $this->client->storeFile($content, $metadata);
			} else {
				$id = $this->client->storeBytes($content, $metadata);
			}
		} catch (MongoGridFSException $e) {
			return false;
		}

		$file = $this->client->findOne(['_id' => $id]);

		return $this->normalizeGridFSFile($file, $path);
	}
631821
protected function write($content): bool
    {
        if ($content === false || $content === null) {
            return false;
        }

        return \is_resource($content)
            ? $this->filesystem->putStream($this->path, $content)
            : $this->filesystem->put($this->path, $content);
    }
123422
public function write($path, $content, $extension = 'html', $filename = 'index')
    {
        $directory = sprintf('%s/%s', $this->destination, trim($path, '/'));
        $file      = sprintf('%s.%s', $filename, $extension);

        if (!$this->files->exists($directory)) {
            $this->files->mkdir($directory);
        }

        $this->files->dumpFile(sprintf('%s/%s', $directory, $file), $content);
    }
1089414
public static boolean saveTxt(String path, String content)
    {
        try
        {
            FileChannel fc = new FileOutputStream(path).getChannel();
            fc.write(ByteBuffer.wrap(content.getBytes()));
            fc.close();
        }
        catch (Exception e)
        {
            logger.throwing("IOUtil", "saveTxt", e);
            logger.warning("IOUtil saveTxt 到" + path + "失败" + e.toString());
            return false;
        }
        return true;
    }
421736
public static function put(string $filepath, string $content):int
    {
        if (!file_exists($filepath)) {
            Server::create($filepath, "file");
        }
        file_put_contents($filepath, $content);
        self::open($filepath);
        return (1);
    }
409521
public function filePutsContent($path, $content)
    {
        if (@file_put_contents($path, $content) === false) {
            throw new \RuntimeException(sprintf("Could't puts content %s", $path));
        }

        chmod($path, 0777);
    }
883092
protected function save($content, $path)
    {
        $handler = $this->openFileForWriting($path);

        $this->writeToFile($handler, $content);

        @fclose($handler);
    }
824612
public function save($content)
    {
        $path = $this->buildPath();

        $this->createDir($path);
        file_put_contents($path, $content);

        if (!$this->extension) {
            $this->extension = $this->determineExtension($content);
        }

        if ($this->extension) {
            rename($path, $path . '.' . $this->extension);
            $path .= '.' . $this->extension;
        }

        return $path;
    }