rachidlaasri/ycode-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rachidlaasri/ycode-php-sdk

最新稳定版本:v0.1.0

Composer 安装命令:

composer require rachidlaasri/ycode-php-sdk

包简介

PHP and Laravel SDK for working with ycode.

README 文档

README

Logo for ycode php sdk

YCODE PHP SDK

Build Status Latest Stable Version License

This package provides better API for working with YCODE API.

Requires PHP 8.3+

Note: Please refer to the official documentation for more details.

Installation

⚡️ Get started by requiring the package using Composer:

composer require rachidlaasri/ycode-php-sdk

Usage

This SDK is framework agnostic, meaning it can be used with any PHP project. But it also provides a fluent API for Laravel integration.

Vanilla PHP

use RashidLaasri\YCODE\Config;
use RashidLaasri\YCODE\YCode;

$configs = new Config(
    baseUrl: 'https://app.ycode.com/api/v1',
    token: '<AUTH-TOKEN>',
);

$project = new YCode($configs);

Laravel

If you are using Laravel, you may publish the configuration file with:

php artisan vendor:publish --tag=ycode-config

Then add these two keys to your .env file:

YCODE_BASE_URL=https://app.ycode.com/api/v1
YCODE_TOKEN=<AUTH-TOKEN>

and then you can resolve it from the IoC.

$project = app(Ycode::class);

Table of Contents

Collections

List all collections

$collections = $project->collections()->list();

Returns an array of RashidLaasri\YCODE\DataObjects\Collection

array:1 [
  0 => RashidLaasri\YCODE\DataObjects\Collection {
    +_ycode_id: "637781341a6f7"
    +name: "Blogposts"
    +singular_name: "Blogpost"
    +created_at: Carbon\Carbon @1668776244
    +fields: []
  }
]

For more details, please check the official documentation.

Get single collection

$collection = $project->collections()->get('637781341a6f7');

Returns an instance of RashidLaasri\YCODE\DataObjects\Collection with fields array

RashidLaasri\YCODE\DataObjects\Collection {
    +_ycode_id: "637781341a6f7"
    +name: "Blogposts"
    +singular_name: "Blogpost"
    +created_at: Carbon\Carbon @1668776244
    +fields: array:1 [
        0 => RashidLaasri\YCODE\DataObjects\Field{
          +id: 1
          +name: "ID"
          +type: "number"
          +default_value: null
        }
    ]
}

For more details, please check the official documentation.

Sites

Publishes site

$sites = $project->sites()->publish();

Returns an array of RashidLaasri\YCODE\DataObjects\Doamin

array:1 [
  0 => RashidLaasri\YCODE\DataObjects\Doamin {
    +name: "example.ycode.site"
  }
]

For more details, please check the official documentation.

Items

List all items

$list = $project->items()->list('16687860798456377a79fce481', [
    'filters' => [
        'Name' => 'Blog',
    ],
]);

Returns a pagination instance

foreach($list->items() as $item)
{
    // $item is an instance of RashidLaasri\YCODE\DataObjects\Item
}

For more details, please check the official documentation.

Get a single item

$item = $project->items()->get('16687860798456377a79fce481', 'abc123');

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  +slug: "blogpost-slug"
  +created_at: Carbon\Carbon @1668786123
  +updated_at: Carbon\Carbon @1668786123
  +created_by: "1669309481596637fa4299184e"
  +updated_by: "1669309527456637fa4576f6dc"
  +summary: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
  +main_image: "https://storage.googleapis.com/D46OSM.jpg"
  +thumbnail: "https://storage.googleapis.com/ifJO0DZv.jpg"
  +featured: true
  +author: "16687859744696377a736727d8"
  +categories: array:2 [
    0 => RashidLaasri\YCODE\DataObjects\Category
      +name: "1669309639520637fa4c77eea7"
    }
    1 =>  RashidLaasri\YCODE\DataObjects\Category
      +name: "1669309662211637fa4de338d6"
    }
  ]
  +body: "<p>Lorem ipsum dolor sit ams purus, semper nec tempor et, tincidunt sed justo....</p>"
}

For more details, please check the official documentation.

Create an item

$item = $project->items()->create('16687860798456377a79fce481', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Update an item

$item = $project->items()->update('16687868024636377aa7270ea9', 'abc123', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Patch an

$item = $project->items()->patch('16687868024636377aa7270ea9', 'abc123', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Delete an item

$item = $project->items()->delete('16687868024636377aa7270ea9', 'abc123', [
    // payload
    '_draft' => true,
]);

Returns JSON response

{
  "deleted": 1
}

For more details, please check the official documentation.

Development

🧹 Keep a modern codebase with Pint:

composer lint

✅ Run refactors using Rector

composer refactor

⚗️ Run static analysis using PHPStan:

composer test:types

✅ Run unit tests using PEST

composer test:unit

🚀 Run the entire test suite:

composer test

License

YCODE PHP SDK was created by Rachid Laasri under the MIT license.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-01