PHPackages                             lvinkim/stdclass-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lvinkim/stdclass-adapter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lvinkim/stdclass-adapter
========================

v1.0.0(6y ago)02PHPPHP &gt;=7.1

Since Jun 29Pushed 6y agoCompare

[ Source](https://github.com/lvinkim/stdclass-adapter)[ Packagist](https://packagist.org/packages/lvinkim/stdclass-adapter)[ RSS](/packages/lvinkim-stdclass-adapter/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

stdclass-adapter
================

[](#stdclass-adapter)

将一个标准类 stdClass 对象适配成自定义的 class 类对象

#### 安装

[](#安装)

```
$ composer require lvinkim/stdclass-adapter

```

#### 应用场景

[](#应用场景)

假设有 json 数据

```
{
  "name": "lvinkim",
  "age": 18,
  "address": {
    "city": "guang zhou"
  },
  "tags": [
    "programmer"
  ]
}
```

通过 `json_decode` 方法能够获得一个 stdClass 类型的对像 `$object`

```
$json = '{
  "name": "lvinkim",
  "age": 18,
  "address": {
    "city": "guang zhou"
  },
  "tags": [
    "programmer"
  ]
}';
$object = json_decode($json);

```

假如，有一个类 People 定义如下：

```
use Lvinkim\StdClassAdapter\Annotations as Json;

class People
{
    /**
     * @var string
     * @Json\Json(type="string")
     */
    public $name;

    /**
     * @var int
     * @Json\Json(type="int")
     */
    public $age;

    /**
     * @var Address
     * @Json\JsonEmbedOne(target="Address")
     */
    public $address;

    /**
     * @var string[]
     * @Json\Json(type="array")
     */
    public $tags;
}

class Address
{
    /**
     * @var string
     * @Json\Json(type="string")
     */
    public $city;
}

```

可以通过 `StdClassAdapter` 可完成由 `$object` 适配成 `People` 类型的对象 `$people`

```
use Lvinkim\StdClassAdapter\StdClassAdapter;

$people = (new StdClassAdapter())->adaptToEntity($object, People::class);

```

#### 备注说明

[](#备注说明)

支持的 Json 注释有

- JsonArray，表示适配为基础类型的数组
- JsonBool，表示适配为 bool 类型
- JsonEmbedMany，表示适配为对象数组，需要指定 target 为要适配的类名
- JsonEmbedOne，表示适配为对象，需要指定 target 为要适配的类名
- JsonFloat，表示适配为 float 类型
- JsonInt，表示适配为 int 类型
- JsonRaw，表示适配为保持原来的类型
- JsonString，表示适配为 string 类型

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2512d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01d0ca591c3a6b31fb49935eb9ef6c2556ac5f1d44057d207fd06a5316b45457?d=identicon)[lvinkim](/maintainers/lvinkim)

### Embed Badge

![Health badge](/badges/lvinkim-stdclass-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/lvinkim-stdclass-adapter/health.svg)](https://phpackages.com/packages/lvinkim-stdclass-adapter)
```

###  Alternatives

[friendsofsymfony/comment-bundle

This Bundle provides threaded comment functionality for Symfony applications

460751.2k5](/packages/friendsofsymfony-comment-bundle)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[koriym/attributes

An annotation/attribute reader

433.4M12](/packages/koriym-attributes)[hostnet/entity-tracker-component

Provides an event when a Tracked entity changes

16158.1k4](/packages/hostnet-entity-tracker-component)[gomachan46/state-machine

simple state machine with annotations for PHP, inspired by AASM known as a Ruby state machine.

1893.9k](/packages/gomachan46-state-machine)[hostnet/accessor-generator-plugin-lib

Generate get, set, add, remove methods on the fly.

10118.9k](/packages/hostnet-accessor-generator-plugin-lib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
