PHPackages                             leon2012/phpapi - 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. [API Development](/categories/api)
4. /
5. leon2012/phpapi

ActiveLibrary[API Development](/categories/api)

leon2012/phpapi
===============

php api library

461PHP

Since Jul 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Leon2012/php-api)[ Packagist](https://packagist.org/packages/leon2012/phpapi)[ RSS](/packages/leon2012-phpapi/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-api
=======

[](#php-api)

### 调用方法

[](#调用方法)

```
    define('APP_PATH',realpath(dirname(__FILE__)));
    require_once __DIR__."/../vendor/autoload.php";
    use leon2012\phpapi\Application;
    $config = [
        'id' => 'api',
        'appPath' => APP_PATH,
        'controllerNamespace' => 'api\controllers',
        'defaultRoute' => 'site/index',
        'modules' => [
            'v1' => 'api\modules\v1\Module',
        ],
        'outputFormat' => 'json',
        'log' => [
            'output' => 'file',
            'level'  => 1, //info
            'file'   => '/tmp/out.log',
        ],
        'database' => [
            'driver' => 'pdo',  //support driver
            'type' => 'mysql',  //only support mysql
            'host' => '127.0.0.1',       //mysql host
            'port' => '3306',       //mysql port
            'name' => '3db',       //database name
            'username' => 'root',   //user name
            'password' => '******',   //password
            'tablePrefix' => 'cms_',
            'charset' => 'utf8',
        ],
    ];
    $app = Application::getInstance();
    try{
        $app->setConfig($config);
        $app->run();
    }catch(Exception $e) {
        $app->response->setRet($e->getCode());
        $app->response->setMsg($e->getMessage());
        $app->response->setData(null);
    }
    $app->response->enableCache(true);
    $app->response->output();

    ###Model调用###

    class UserModel extends Model
    {
        public function tableName()
        {
            return 'cms_user';
        }

        public function pkId()
        {
            return 'id';
        }
    }
    $config = [
        'driver' => 'pdo',  //support driver
        'type' => 'mysql',  //only support mysql
        'host' => '127.0.0.1',       //mysql host
        'port' => '3306',       //mysql port
        'name' => '3db',       //database name
        'username' => 'root',   //user name
        'password' => '******',   //password
        'tablePrefix' => 'cms_',
        'charset' => 'utf8',
    ];
    $database = new Database($config);
    var_dump($database);

    $userModel = new UserModel($database);
    var_dump($userModel);

    $userModel->username = "username";
    $userModel->auth_key = "auth_key";
    $userModel->status = 1;
    $userModel->used = false;
    $data = ['username' => 'leon', 'auth_key' => 'test', 'status' => 1, 'used' => true];
    $userModel->insert($data);

    $userModel->id = 1;
    $userModel->delete($data);
    $userModel->id = 1;
    $userModel->update($data);

    $userModel->id = 1;
    $ret = $userModel->one(2);
    if ($ret) {
        echo $userModel->username;
    }

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9378161?v=4)[Leon](/maintainers/Leon2012)[@Leon2012](https://github.com/Leon2012)

---

Top Contributors

[![Leon2012](https://avatars.githubusercontent.com/u/9378161?v=4)](https://github.com/Leon2012 "Leon2012 (18 commits)")[![xingskycn](https://avatars.githubusercontent.com/u/1008172?v=4)](https://github.com/xingskycn "xingskycn (6 commits)")

### Embed Badge

![Health badge](/badges/leon2012-phpapi/health.svg)

```
[![Health](https://phpackages.com/badges/leon2012-phpapi/health.svg)](https://phpackages.com/packages/leon2012-phpapi)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M19](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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