PHP code example of tomkyle / repository-persistence

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

    

tomkyle / repository-persistence example snippets

 


use tomkyle\RepositoryPersistence\Repositories\Repository;
use tomkyle\RepositoryPersistence\Persistence;

$repo = new Repository(
	new Persistence\JsonFilePersistence('path/to/json')
);

try {
  $person = $repo->get('john-doe');
  print_r($person);
} 
catch (\OutOfBoundsException) {
  // Not found
}

$repo->findOneBy([
  'name' => 'John'
]);  

$repo->findAll();

$repo->findBy([
  'color' => 'blue'
]);

$saved = $repo->save(['id' => 43, 'name' => 'John']));

$repo->delete(43);

$saved = $repo->save(['name' => 'Angie']));

$new_id = $repo->getNextId();
$repo->save(['id' => $new_id, 'name' => 'Angie']));


use tomkyle\RepositoryPersistence\Repositories;
use tomkyle\RepositoryPersistence\Persistence;

$persistence = new Persistence\JsonFilePersistence('path/to/json');
$persistence = new Persistence\YamlFilePersistence('path/to/yaml');

$persistence = new Persistence\FrontmatterFilePersistence(
	new Persistence\JsonFilePersistence('path/to/json')
);

$persistence = new Persistence\PersistenceChain(
	new Persistence\JsonFilePersistence('path/to/json'),
	new Persistence\YamlFilePersistence('path/to/yaml')
);

$persistence = new Persistence\InMemoryPersistence();

$persistence = new Persistence\NoPersistence();


use tomkyle\RepositoryPersistence\Repositories\Repository;
use tomkyle\RepositoryPersistence\Persistence; 

// Feed a persistence to the repo:
$persistence = new Persistence\InMemoryPersistence();
$repository = new Repository($persistence)