PHP code example of dashifen / repository
1. Go to this page and download the library: Download dashifen/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/ */
dashifen / repository example snippets
class Foo extends AbstractRepository {
protected $bar;
protected $baz;
protected $bing;
protected function getHiddenPropertyNames(): array
{
return ["baz"];
}
protected function getCustomPropertyDefaults(): array
{
return ["bing" => strtotime('Y-m-d h:i:s')];
}
protected function getRequiredProperties(): array
{
return ["bar"];
}
protected function setBar(string $bar): void
{
$this->bar = $bar;
}
protected function getBar(): string
{
return ucfirst($this->bar);
}
}
$foo = new Foo(["bar" => "apple"]);
echo $foo->bar; // echos "Apple" because of the getBar() getter
echo $foo->baz; // throws RepositoryException (baz is hidden)
echo $foo->bing; // echos current timestamp (based on custom default value)
$oof = new Foo([]); // throws RepositoryException (bar is
$foo = new Foo(['bar' => 'Hello, World!']);
foreach ($foo as $field => $value) {
echo "$field: $value" . PHP_EOL;
}