melonsmasher/ethos-laravel

一个利用ethos-php与Ellucian Ethos API交互的Laravel扩展包。

v0.1.7 2021-04-29 16:25 UTC

README

基于MelonSmasher/ethos-php的Ellucian Ethos客户端库,为Laravel提供增强。

License GitHub issues GitHub top language Codacy grade

安装

将库拉入您的项目

composer require melonsmasher/ethos-laravel

发布 ethos.php 到配置目录

php artisan vendor:publish --tag ethos

API 文档

完整的API文档可以在这里找到

功能

  • .env读取Ethos设置。

  • Ethos会话被缓存。

  • 高效处理身份验证。

    • 在之前的会话过期之前创建新的已认证会话。
  • 为316个Ethos数据模型提供特质,通过Ethos对象ID进行关联。

  • 特质模型响应可以被缓存一定时间。

配置选项

# Your Ethos API key / refresh token.
ETHOS_SECRET=YourEthosApiKey
# The base url that should be used to connect to Ethos. If omitted https://integrate.elluciancloud.com is used.
ETHOS_BASE_URL=https://integrate.elluciancloud.com
# The ERP backend that is connected to Ethos. Must be either 'banner' or 'colleague'. If nothing is supplied 'colleague' is used.
ETHOS_ERP_BACKEND=banner
# How long trait responses should remain in the cache in seconds. Set to 0 to disable. If omitted this option is disabled.
ETHOS_TRAIT_CACHE_TTL=300

用法/示例

使用辅助函数

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MelonSmasher\EthosPHP\Student\CoursesClient;

class ExampleController extends Controller
{
    public function index()
    {
        $ethos = getEthosSession();
        $courses = new CoursesClient($ethos);
        return $courses->read()->toJson();
    }
}

使用外观

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MelonSmasher\EthosPHP\Laravel\Facade\Ethos;
use MelonSmasher\EthosPHP\Foundation\BuildingsClient;

class ExampleController extends Controller
{
    public function index()
    {
        $ethos = Ethos::get();
        $buildings = new BuildingsClient($ethos);
        return $buildings->read()->data();
    }
}

特质

HasEthosPersonModel

如何在Laravel用户模型上使用HasEthosPersonModel特质的示例。

用户迁移

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('ethos_person_id')->unique(); // Add this to your user's model and fill it with the related Ethos Person ID.
            $table->string('username');
            $table->string('name');
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

用户模型

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use MelonSmasher\EthosPHP\Laravel\Traits\Foundation\HasEthosPersonModel;

class User extends Authenticatable
{
    use HasEthosPersonModel;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'ethos_person_id', // <--- This attribute must be present on your model.
        'username',
        'name'
    ];
}

示例用法

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\User;

class MyController extends Controller
{
    
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
    
    /**
    * Shows a user's Ethos Person Model
    */
    public function showUserAccount($id) 
    {
        $user = User::findOrFail($id);
        
        return $user->ethosPerson(); // Returns the Ethos account
    }
}

开发设置

安装PHIVE

安装构建工具

phive install

安装composer需求

./composer install