PHP code example of rosalana / configure

1. Go to this page and download the library: Download rosalana/configure 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/ */

    

rosalana / configure example snippets


use Rosalana\Configure\Configure;

$file = Configure::file('database');

$file->section('connections');
$file->value('default');

$file->section('connections')
          ->section('mysql')
               ->value('host');

$file->value('connections.mysql.host');

$file->value('connections.mysql.host', 'localhost');

$value = $file->value('connections.mysql.host');

$value->get();               // current value
$value->set('localhost');    // hard set
$value->add('localhost');    // soft set
$value->remove();            // delete value

$file->value('connections.mysql.host', 'localhost');

$value->set('3306');                         // int
$value->set('true');                         // bool
$value->set('null');                         // null
$value->set('My App');                       // string
$value->set("['a', 'b']");                   // array
$value->set("env('DB_HOST', 'localhost')");  // function
$value->set("User::class");                  // class constant

$file->value('connections.mysql.host')
     ->rename('hostname');

$file->value('connections.mysql.hostname');

$file->section('connections')->moveUp();
$file->section('connections')->moveDown();
$file->section('connections')->keepStart();
$file->section('connections')->keepEnd();
$file->section('connections')->before('redis');
$file->section('connections')->after('redis');

$file->section('connections')->cut('redis.options');
$file->section('connections')->copy('redis.options');

$file
    ->section('connections')
        ->value('default')->set('sqlite')
        ->section('mysql')
            ->value('host')->moveUp();

$file
    ->section('connections')
        ->value('default', 'sqlite')
     ->section('.redis');

$file->value('connections.mysql.host');

$file->section('connections')
     ->comment('Database connections');

'connections' => [
    // Database connections
]

$file->section('connections')
     ->comment("Line one\nLine two");

'connections' => [
    // Line one
    // Line two
]

$file->section('connections')
     ->comment(
         'Database connections',
         "Used by the application\nDo not edit manually"
     );

'connections' => [

    /*
    |----------------------------------------------------
    | Database connections
    |----------------------------------------------------
    |
    | Used by the application
    | Do not edit manually
    |
    */

]

$file->section('connections')
     ->withComment('Main database configuration'); // rich comment

$file->value('default')
     ->withComment('Default connection'); // simple comment

$file->section('connections')->withoutComment();

$file->save();

$render = $file->render(); // array of lines
$diff = $file->diff();     // array-based diff

/**
 * Get the node array representation.
 * @return array<string, mixed>
 */
$node->toArray();

/**
 * Get the type of the node.
 *
 * @return string 'file', 'section', 'value', 'comment', 'richcomment'
 */
$node->type();

/**
 * Get the node path.
 * @return string
 */
$node->path(): string;

/**
 * Get the node name.
 * @return string
 */
$node->name(): string;

/**
 * Get the node start line number.
 * @return int
 */
$node->start(): int;

/**
 * Get the node end line number.
 * @return int
 */
$node->end(): int;

/**
 * Get the node raw array of lines.
 * @return array<int, string>
 */
$node->raw(): array;

/**
 * Render the node to array of lines.
 * @return array<int, string>
 */
$node->render(): array;

/**
 * Get the node indentation level. (including padding)
 * @return int
 */
$node->scale(): int;

/**
 * Get the node parent instance.
 * @return ?ParentNode
 */
$node->parent(): ?ParentNode;

/**
 * Get the node siblings collection.
 * @return Collection<Node>
 */
$node->siblings(): Collection;

/**
 * Get the sibling nodes before the current node.
 * @return Collection<Node>
 */
$node->siblingsBefore(): Collection;

/**
 * Get the sibling nodes after the current node.
 * @return Collection<Node>
 */
$node->siblingsAfter(): : Collection;

/**
 * Get the root file instance.
 * @return File
 */
$node->root(): File;

/** Determine if the node was created during this session. */
$node->isNew(): bool;

/** Determine if the node has unsaved changes. */
$node->isDirty(): bool;

/** Determine if the node is of a specific type. */
$node->isTypeOf(string $type): bool;

/** Determine if the node is a sub-node (not top-level). */
$node->isSubNode(): bool;

/** Determine if the node is at root top-level. */
$node->isRoot(): bool;

/** Determine if the node is the first child of its parent. */
$node->isFirstChild(): bool;

/** Determine if the node is the last child of its parent. */
$node->isLastChild(): bool;

$value->isNull(): bool;
$value->isString(): bool;
$value->isNumber(): bool;
$value->isBoolean(): bool;
$value->isArray(): bool;
$value->isFunction(): bool;
$value->isClass(): bool;

$parent->nodes(): Collection;

$comment->label(): string;
$comment->setLabel(string $label): static;

// RichComment only
$comment->description(): string;
$comment->setDescription(string $body): static;