1. Go to this page and download the library: Download dealnews/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/ */
dealnews / repository example snippets
$repo = new \DealNews\Repository\Repository();
$dao = new My_Data_Object();
// assuming $dao has a load() method that takes
// an array of ids
$repo->register("my_data", [$dao, "load"]);
// $data is returned as an array with keys matching the ids passed
// in to the getMulti() method
$data = $repo->getMulti("my_data", [1,2,3]);
// Or, the get method can be used to return just on object
$obj = $repo->get("my_data", 1);
$repo = new \DealNews\Repository\Repository();
$dao = new My_Data_Object();
// assuming $dao has a load() method that takes
// an array of ids
$repo->register("my_data", [$dao, "load"], [$dao, "save"]);
$foo = new Foo();
$foo->name = "example";
// save returns the data (possibly updated by the storage later)
// that it is sent
$foo = $repo->save("my_data", $foo);
namespace MyAPP;
class DataRepository {
public static function init() {
static $repo;
if (empty($repo)) {
$repo = new \DealNews\Repository\Repository();
// All of these handlers are only setting read callbacks
// There is no writing for this repository.
$book = new Book();
$repo->register("book", [$book, "fetch"]);
$author = new Author();
$repo->register("author", [$author, "fetch"]);
}
return $repo;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.