PHP code example of devly / repository

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

    

devly / repository example snippets


$repository = new \Devly\Repository();

// Or create with initial data
$repository = new \Devly\Repository(['user' => [...]]);

$repository->set('user.name', 'johndoe');

// Or as array
$repository['user.name'] = 'johndoe';

// Equivalent vanilla PHP
$array['user']['name'] = 'johndoe';

$username = $repository->get('user.name');

// Or as array
$username = $repository['user.name'];

// Equivalent vanilla PHP
$username = $array['user']['name'];

$repository->has('user.name');

// Or as array
isset($repository['user.name']);

// Equivalent vanilla PHP
isset($array['user']['name']);

$array = $repository->all();

$repository->remove('user.name');

// Or as array
unset($repository['user.name']);

$repository->clear();

$repository->count();

// Or using the count function
count($repository);

$repository->isEmpty();

$repository->toJson('user');

$repository->toJson();

// Same as:
json_encode($repository);

$repository  = new Repository(['name' => ['first' => 'John', 'last' => 'Doe']]);
$repository2 = $repository->createFrom('name');

$repository2->all(); // ['first' => 'John', 'last' => 'Doe']

$repository = new Repository(['first' => 'John', 'last' => 'Doe']);

$repository->merge(new Repository(['first' => 'Johnny']));

// Can also be merged with an object
$repository->merge((object) ['first' => 'Johnny']);

// Can also be merged with an object
$repository->merge(['first' => 'Johnny']);

$repository->all(); // ['first' => 'Johnny', 'last' => 'Doe']

$repository = new Repository(['name' => ['first' => 'John', 'last' => 'Doe']]);

$repository->mergeRecursive(['name' => ['first' => 'Johnny']]);

$repository->all(); // ['name' => ['first' => 'Johnny', 'last' => 'Doe']