src/helpers/FileHelper.php
public static function write($path, $content)
    {
        $path = Yii::getAlias($path);
        if (is_file($path) && file_get_contents($path) === $content) {
            return false;
        }

        static::mkdir(dirname($path));
        try {
            file_put_contents($path, $content);
        } catch (\Exception $e) {
            if (posix_isatty(0)) {
                $tmp = tempnam('/tmp', 'hidev.');
                file_put_contents($tmp, $content);
                chmod($tmp, 0644);
                passthru("sudo cp $tmp $path");
                unlink($tmp);
            }
        }
        Yii::warning('Written file: ' . $path, 'file');

        return true;
    }
public static function write($path, $content)
    {
        $path = Yii::getAlias($path);
        if (is_file($path) && file_get_contents($path) === $content) {
            return false;
        }

        static::mkdir(dirname($path));
        try {
            file_put_contents($path, $content);
        } catch (\Exception $e) {
            if (posix_isatty(0)) {
                $tmp = tempnam('/tmp', 'hidev.');
                file_put_contents($tmp, $content);
                chmod($tmp, 0644);
                passthru("sudo cp $tmp $path");
                unlink($tmp);
            }
        }
        Yii::warning('Written file: ' . $path, 'file');

        return true;
    }
public static function write ( $ path , $ content ) { $ path = Yii :: getAlias ( $ path ) ; if ( is_file ( $ path ) && file_get_contents ( $ path ) === $ content ) { return false ; } static :: mkdir ( dirname ( $ path ) ) ; try { file_put_contents ( $ path , $ content ) ; } catch ( \ Exception $ e ) { if ( posix_isatty ( 0 ) ) { $ tmp = tempnam ( '/tmp' , 'hidev.' ) ; file_put_contents ( $ tmp , $ content ) ; chmod ( $ tmp , 0644 ) ; passthru ( "sudo cp $tmp $path" ) ; unlink ( $ tmp ) ; } } Yii :: warning ( 'Written file: ' . $ path , 'file' ) ; return true ; }
Writes given content to the file.
Doesn't touch file if it has exactly same content.
Creates intermediate directories when necessary.
@param string $path
@param string $content
@return bool true if file was changed
Writes given content to the file . Doesn t touch file if it has exactly same content . Creates intermediate directories when necessary .