file_put_contents

Supported Versions: PHP 5, PHP 7, PHP 8
Write data to a file
<?php file_put_contents(    string $filename,    mixed $data,    int $flags = 0,    ?resource $context = null): int|false
<?php     {

        $tmp = __DIR__ . '/_runtime_components.json';



        file_put_contents($tmp, json_encode($components, JSON_PRETTY_PRINT));

    }



    function wipeRuntimeComponentRegistration()
<?php if (! file_exists($cacheDir)) mkdir($cacheDir);

if (! file_exists($viewsDir)) mkdir($viewsDir);

$packagesCache = $cacheDir.'/packages.php';

file_put_contents($packagesCache, '<?php return [];');

$servicesCache = $cacheDir.'/services.php';

$appConfigCache = $cacheDir.'/config.php';

$routesCache = $cacheDir.'/routes.php';
<?php             (new Filesystem)->makeDirectory($stubsPath);

        }



        file_put_contents(

            $stubsPath.'/livewire.stub',

            file_get_contents(__DIR__.'/livewire.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.inline.stub',
<?php             file_get_contents(__DIR__.'/livewire.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.inline.stub',

            file_get_contents(__DIR__.'/livewire.inline.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.view.stub',
<?php             file_get_contents(__DIR__.'/livewire.inline.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.view.stub',

            file_get_contents(__DIR__.'/livewire.view.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.test.stub',
<?php             file_get_contents(__DIR__.'/livewire.view.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.test.stub',

            file_get_contents(__DIR__.'/livewire.test.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.pest.stub',
<?php             file_get_contents(__DIR__.'/livewire.test.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.pest.stub',

            file_get_contents(__DIR__.'/livewire.pest.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.form.stub',
<?php             file_get_contents(__DIR__.'/livewire.pest.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.form.stub',

            file_get_contents(__DIR__.'/livewire.form.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.attribute.stub',
<?php             file_get_contents(__DIR__.'/livewire.form.stub')

        );



        file_put_contents(

            $stubsPath.'/livewire.attribute.stub',

            file_get_contents(__DIR__.'/livewire.attribute.stub')

        );



        $this->info('Stubs published successfully.');

    }
<?php     {

        $tmp = __DIR__ . '/_runtime_components.json';



        file_put_contents($tmp, json_encode($components, JSON_PRETTY_PRINT));

    }



    static function wipeRuntimeComponentRegistration()
<?php     function can_test_component_using_magic_render()

    {

        mkdir($this->livewireViewsPath());

        file_put_contents($this->livewireViewsPath().'/foo.blade.php', <<<'PHP'

        <div>

            Im foo

        </div>

        PHP);



        mkdir($this->livewireClassesPath());

        file_put_contents($this->livewireClassesPath().'/Foo.php', <<<'PHP'
<?php         PHP);



        mkdir($this->livewireClassesPath());

        file_put_contents($this->livewireClassesPath().'/Foo.php', <<<'PHP'

        <?php



        namespace App\Livewire;



        use Livewire\Component;



        class Foo extends Component

        {


        }

        PHP);



        Livewire::test('foo')->assertSee('Im foo');

    }
<?php     public function refreshDatabaseFile()

    {

        file_put_contents($this->connection->getDatabaseName(), '');

    }

}
<?php     public function put($path, $contents, $lock = false)

    {

        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);

    }
<?php             chmod($tempPath, 0777 - umask());

        }



        file_put_contents($tempPath, $content);



        rename($tempPath, $path);

    }