1. Go to this page and download the library: Download legolabs/values 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/ */
legolabs / values example snippets
namespace Acme;
use Legolabs\Values\ValuesTrait;
use Legolabs\Values\ObjectsTrait;
use function Legolabs\Values\set_values;
class Repo
{
use ValuesTrait;
use ObjectsTrait;
public function getStargazersCount()
{
return $this->getValue('stargazers_count');
}
/** @return Owner */
public function getOwner()
{
return $this->getObject('owner', Owner::class);
}
}
class Owner
{
use ValuesTrait;
public function getId()
{
return $this->getValue('id');
}
public function getLogin()
{
return $this->getValue('login');
}
}
$data = json_decode('
{
"id":458058,
"name":"symfony",
"full_name":"symfony/symfony",
"owner":{
"login":"symfony",
"id":143937,
},
"stargazers_count":13945,
}
', true);
$repo = new Repo();
set_values($repo, $data);
$repo->getStargazersCount(); // 13945
$repo->getOwner()->getLogin(); // symfony
namespace Acme;
use Legolabs\Values\ObjectsTrait;
use Legolabs\Values\ValuesTrait;
class Gist
{
use ValuesTrait;
use ObjectsTrait;
public function setDescription($description)
{
$this->setValue('description', $description);
}
public function setPublic($bool)
{
$this->setValue('public', $bool);
}
public function addFile($fileName, GistFile $file)
{
$this->addObject('files', $file, $fileName);
}
}
class GistFile
{
use ValuesTrait;
public function __construct($content)
{
$this->setValue('content', $content);
}
}
$file = new GistFile('String file contents');
$gist = new Gist();
$gist->setDescription('the description for this gist');
$gist->setPublic(true);
$gist->addFile('file1.txt', $file);
get_values($gist);
/*
[
'description' => 'the description for this gist',
'public' => true,
'files' => [
'file1.txt' => [
'content' => 'String file contents',
]
]
]
*/
// now you can send it to api.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.