PHP code example of aplia / support

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

    

aplia / support example snippets


use Aplia\Support\Arr;

Arr::get($array, 'key');

use Aplia\Support\Arr;

$array = ['products' => ['desk' => ['price' => 100]]];

$price = Arr::get($array, 'products.desk.price');

// 100

use Aplia\Support\Arr;

function search($query, $params = null)
{
    $limit = Arr::get($params, 'limit');
    $fields = Arr::get($params, 'fields', 1);
    // ...
}

Path::join(['var', 'storage']);
// "var/storage"

Path::join([]);
// ""

// Using a root
Path::join(['var', 'storage'], '/var/www');
// "/var/www/var/storage"

Path::make('vendor', 'composer');
// "vendor/composer"

use Aplia\Support\Val;

// Any regular value is simply returned
Val::value(5) === 5;

// Closures are called to fetch the actual value
Val::value(function () {
    return 5;
}) === 5;

/**
 * @property-read string $id
 * @property string $version
 * @property string $code
 *\/
class Topic
{
    use \Aplia\Support\Traits\VirtualProperties;

    public $name;
    protected $_id;
    protected $_version;

    public function __construct($id, $version, $name)
    {
        $this->_id = $id;
        $this->_version = $version;
        $this->name = $name;
    }
    public function cachedCode()
    {
        return $this->version !== null ? ($this->_id . '-' . $this->version) : $this->_id;
    }
    public function propId($id)
    {
        return $this->_id;
    }
    public function propVersion()
    {
        return $this->_version;
    }

    public function setpropVersion($version)
    {
        $this->_version = $version;
    }
    public function unsetpropVersion()
    {
        $this->_version = null;
    }
}

$t = new Topic('english', '1', 'foo');
$t->name; // returns 'foo' (regular property)
$t->id; // returns 'english'
$t->id = 'greek'; // *id* is read-only so this fails
$t->version; // returns '1'
$t->code; // returns 'english-1'
$t->version = '2';
$t->code; // returns 'english-2'
unset($t->version);
$t->code; // returns 'english'