droath / hostsfile-manager
Manage hosts file on nix based systems.
Installs: 6 411
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^5.5
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2024-11-09 21:42:39 UTC
README
Provides a class to add/remove lines from the hosts file. It has been tested to work on *nix based systems, otherwise you'll need to supply the path to the hosts file.
Getting Started
First, you'll need to download the hostsfile manager library using composer:
composer require droath/hostsfile-manager:^0.0.1
Examples
Add lines to the hosts file contents:
The below code appends two entries to the hosts file contents. If any of those lines already exists then nothing is appended.
<?php $hosts_file = (new \Droath\HostsFileManager\HostsFile()) ->setLine('127.0.0.1', 'local.sickslap.com') ->setLine('127.0.0.2', 'local.hiphopsmack.com'); (new \Droath\HostsFileManager\HostsFileWriter($hosts_file)) ->add();
Remove a single line from hosts file:
The below code removes the one entry from the hosts file. All other lines within the hosts file remain untouched.
<?php $hosts_file = (new \Droath\HostsFileManager\HostsFile()) ->setLine('127.0.0.2', 'local.hiphopsmack.com'); (new \Droath\HostsFileManager\HostsFileWriter($hosts_file)) ->remove();