Codync
무료 오픈소스 1:1 대안, Grok Bot과 Muse 대신
개인 계정의 공개 저장소 소유자는 GitHub로 로그인해 운영자를 확인하고 소개를 직접 관리할 수 있습니다. 관리자 승인은 필요하지 않습니다.
로그인한 뒤 확인 파일을 만들어 이 저장소의 기본 브랜치에 30분 안에 커밋해 주세요. 다른 브랜치나 포크의 파일은 인정하지 않습니다. 파일을 올린 뒤 아래에서 확인하면 관리자 승인 없이 관리할 수 있습니다. 자격을 유지하려면 파일을 남겨 두세요.
로그인이 필요하면 로그인 화면으로 이동합니다. 로그인 후 이곳으로 돌아와 원하는 확인 버튼을 다시 눌러 주세요.
프로젝트 폴더에서 /nomorevibe verify를 실행하면 소유권을 확인하고 소개를 직접 관리할 수 있습니다.
1분 만에 확인하기Map nested JSON structures to PHP classes
저장소 README에서 가져옴
README 전체를 불러오는 중입니다.
README 전문 보기 ↗JsonMapper is a PHP library that allows you to map a JSON response to your PHP objects that are either annotated using doc blocks or use typed properties. For more information see the project website: https://jsonmapper.net/
Continuously mapping your JSON responses to your own objects becomes tedious and is error-prone. Not mentioning the tests that need to be written for said mapping.
JsonMapper has been built with the most common usages in mind. To allow for those edge cases which are not supported by default, it can easily be extended as its core has been designed using middleware.
JsonMapper supports the following features
The installation of JsonMapper can easily be done with Composer
$ composer require json-mapper/json-mapper
The example shown above assumes that composer is on your $PATH.
Given the following class definition
class User
{
/** @var string */
private $name;
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
}
Combined with the following JsonMapper code as part of your application
$mapper = (new \JsonMapper\JsonMapperFactory())->default();
$user = $mapper->mapToClassFromString('{ "name": "John Doe" }', User::class);
echo $user->getName(); // "John Doe"
The property is private, so JsonMapper fills it through setName(). A non-public property with no
matching setter raises a RuntimeException, so your model keeps its encapsulation either way.
Writing your own middleware has been made as easy as possible with an AbstractMiddleware that can be extended with the functionality
you need for your project.
$mapper = (new \JsonMapper\JsonMapperFactory())->bestFit();
$mapper->push(new class extends \JsonMapper\Middleware\AbstractMiddleware {
public function handle(
\stdClass $json,
\JsonMapper\Wrapper\ObjectWrapper $object,
\JsonMapper\ValueObjects\PropertyMap $map,
\JsonMapper\JsonMapperInterface $mapper
): void {
/* Custom logic here */
}
});
Please refer to CONTRIBUTING.md for information on how to contribute to JsonMapper.
Thanks to everyone who has contributed to JsonMapper! You can find a detailed list of people that contributed to JsonMapper on GitHub.
This project is sponsored by JetBrains providing a license for PhpStorm to continue building on JsonMapper.
The MIT License (MIT). Please see License File for more information.