PHP code example of alexandre-daubois / phikl

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

    

alexandre-daubois / phikl example snippets


use Phikl\Pkl;

$module = Pkl::eval('config/simple.pkl');

// you can then interact with the module
echo $module->get('name'); // Pkl: Configure your Systems in New Ways
echo $module->get('attendants'); // 100
echo $module->get('isInteractive'); // true
echo $module->get('amountLearned'); // 13.37

use Phikl\Pkl;

$module = Pkl::eval('config/nested.pkl');

// you can then interact with the module
echo $module->get('woodPigeon')->get('name'); // Common wood pigeon
echo $module->get('woodPigeon')->get('diet'); // Seeds
echo $module->get('woodPigeon')->get('taxonomy')->get('species'); // Columba palumbus

use Phikl\Pkl;

class User
{
    public int $id;
    public string $name;
    public Address $address;
}

class Address
{
    public string $street;
    public string $city;
    public string $state;
    public string $zip;
}

$module = Pkl::eval('config/user.pkl');
$user = $module->get('myUser')->cast(User::class);

use Phikl\Pkl;

// ...

$user = Pkl::eval('config/user.pkl', User::class)['myUser'];

use Phikl\PklProperty;

class User
{
    #[PklProperty('id')]
    public int $userId;

    #[PklProperty('name')]
    public string $userName;

    public Address $address;
}