PHP code example of benfiratkaya / laravel-setenv

1. Go to this page and download the library: Download benfiratkaya/laravel-setenv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

benfiratkaya / laravel-setenv example snippets


 namespace Your\Namespace;

// ...

use dacoto\SetEnv\Facades\SetEnv;

class YourClass
{
    public function yourMethod()
    {
        SetEnv::doSomething();
    }
}

 namespace App\Http\Controllers;

// ...

use dacoto\SetEnv;

class TestSetEnvController extends Controller
{
    protected $editor;

    public function __construct(SetEnv $editor)
    {
        $this->editor = $editor;
    }

    public function doSomething()
    {
        $editor = $this->editor->doSomething();
    }
}

/**
 * Get raw content of file
 *
 * @return string
 */
public function getContent();

$rawContent = SetEnv::getContent();

/**
 * Get all lines from file
 *
 * @return array
 */
public function getLines();

$lines = SetEnv::getLines();

/**
 * Get all or exists given keys in file content
 *
 * @param  array  $keys
 *
 * @return array
 */
public function getKeys($keys = []);

// Get all keys
$keys = SetEnv::getKeys();

// Only get two given keys if exists
$keys = SetEnv::getKeys(['APP_DEBUG', 'APP_URL']);

/**
 * Check, if a given key is exists in the file content
 *
 * @param  string  $keys
 *
 * @return bool
 */
public function keyExists($key);

$keyExists = SetEnv::keyExists('APP_URL');

/**
 * Return the value matching to a given key in the file content
 *
 * @param  $key
 *
 * @throws \dacoto\SetEnv\Exceptions\KeyNotFoundException
 *
 * @return string
 */
public function getValue($key);

$value = SetEnv::getValue('APP_URL');

/**
 * Add empty line to buffer
 *
 * @return SetEnv
 */
public function addEmpty();

$file = SetEnv::addEmpty();

/**
 * Add comment line to buffer
 *
 * @param object
 *
 * @return SetEnv
 */
public function addComment($comment);

$file = SetEnv::addComment('This is a comment line');

/**
 * Set one key to buffer
 *
 * @param string       $key      Key name of setter
 * @param string|null  $value    Value of setter
 * @param string|null  $comment  Comment of setter
 * @param boolean      $export   Leading key name by "export "
 *
 * @return SetEnv
 */
public function setKey($key, $value = null, $comment = null, $export = false);

// Set key ENV_KEY with empty value
$file = SetEnv::setKey('ENV_KEY');

// Set key ENV_KEY with none empty value
$file = SetEnv::setKey('ENV_KEY', 'anything-you-want');

// Set key ENV_KEY with a value and comment
$file = SetEnv::setKey('ENV_KEY', 'anything-you-want', 'your-comment');

// Update key ENV_KEY with a new value and keep earlier comment
$file = SetEnv::setKey('ENV_KEY', 'new-value-1');

// Update key ENV_KEY with a new value, keep earlier comment and use 'export ' before key name
$file = SetEnv::setKey('ENV_KEY', 'new-value', null, true);

// Update key ENV_KEY with a new value and clear comment
$file = SetEnv::setKey('ENV_KEY', 'new-value-2', '', false);

/**
 * Set many keys to buffer
 *
 * @param  array  $data
 *
 * @return SetEnv
 */
public function setKeys($data);

$file = SetEnv::setKeys([
    [
        'key'     => 'ENV_KEY_1',
        'value'   => 'your-value-1',
        'comment' => 'your-comment-1',
        'export'  => true
    ],
    [
        'key'     => 'ENV_KEY_2',
        'value'   => 'your-value-2',
        'export'  => true
    ],
    [
        'key'     => 'ENV_KEY_3',
        'value'   => 'your-value-3',
    ]
]);

$file = SetEnv::setKeys([
    'ENV_KEY_1' => 'your-value-1',
    'ENV_KEY_2' => 'your-value-2',
    'ENV_KEY_3' => 'your-value-3',
]);

/**
 * Delete on key in buffer
 *
 * @param  string  $key
 *
 * @return SetEnv
 */
public function deleteKey($key);

$file = SetEnv::deleteKey('ENV_KEY');

/**
 * Delete many keys in buffer
 *
 * @param  array $keys
 *
 * @return SetEnv
 */
public function deleteKeys($keys = []);

// Delete two keys
$file = SetEnv::deleteKeys(['ENV_KEY_1', 'ENV_KEY_2']);

/**
 * Save buffer to file
 *
 * @return SetEnv
 */
public function save();

$file = SetEnv::save();