承接 nictorgersen/kreg-php-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nictorgersen/kreg-php-client

最新稳定版本:1.1.0

Composer 安装命令:

composer require nictorgersen/kreg-php-client

包简介

PHP client for KREG API using Laravel HTTP client

README 文档

README

A modern PHP wrapper for the KREG API (Norwegian competence registry system) built with Laravel's HTTP client.

Features

  • 🚀 Laravel Integration - Service provider, facade, and auto-discovery
  • 🔒 Session Management - Automatic session handling with SHA-256 authentication
  • 📦 Resource-Based API - Clean, intuitive interface for all KREG resources
  • Fully Tested - Comprehensive test suite with Pest
  • 🎯 Type-Safe - PHP 8.2+ with readonly properties and strict types
  • 🔄 Laravel 10, 11, 12 - Full support for all modern Laravel versions

Installation

Install via Composer:

composer require nictorgersen/kreg-php-client

Quick Start

Laravel

The package auto-registers in Laravel. Just publish the config and start using the facade:

php artisan vendor:publish --tag="kreg-config"

Configure your credentials in .env:

KREG_SYSTEM_TOKEN=your-system-token
KREG_COMPANY_TOKEN=your-company-token

Use the facade:

use NicTorgersen\KregApiSdk\Facades\Kreg;

// List persons
$persons = Kreg::person()->list();

// Create a person
$person = Kreg::person()->create(
    firstName: 'John',
    lastName: 'Doe',
    birthDate: '1990-01-01'
);

// Manage competences
$competence = Kreg::competence()->create(
    personId: $person->id,
    competenceId: 123,
    validFrom: '2024-01-01',
    validTo: '2025-01-01'
);

Plain PHP

use NicTorgersen\KregApiSdk\KregClient;
use NicTorgersen\KregApiSdk\KregConfig;

$config = KregConfig::make(
    systemToken: 'your-system-token',
    companyToken: 'your-company-token'
);

$client = KregClient::make($config);

// Use the client
$persons = $client->person()->list();

Available Resources

The package provides access to all KREG API resources:

  • Person - Manage persons (create, read, update, delete, find)
  • Competence - Manage competences for persons
  • Document - Manage documents for persons
  • Catalog - Access catalog data (competence types, etc.)
  • Companies - Manage and list companies
  • ExternalCourse - Manage LMS courses linked to KREG's competency catalog

Examples

Comprehensive examples are available in the examples/ directory:

  • Laravel Example - Complete Laravel integration with facade usage, dependency injection, and testing
  • Plain PHP Example - Framework-agnostic usage with runnable examples

Requirements

  • PHP 8.2 or higher
  • Laravel 10.x, 11.x, or 12.x (for Laravel integration)

Testing

Run the test suite:

composer test

Format code with Laravel Pint:

composer format

Configuration

The package uses the following configuration options:

Option Description Default
system_token Your KREG system token Required
company_token Your KREG company token Required
base_url KREG API base URL https://kreg.sr.no/kreg/v1/
session_duration Session validity in seconds 86400 (24 hours)
timeout HTTP request timeout in seconds 30

Error Handling

The package provides specific exception types:

use NicTorgersen\KregApiSdk\Exceptions\Kregception;
use NicTorgersen\KregApiSdk\Exceptions\KregAuthenticationException;
use NicTorgersen\KregApiSdk\Exceptions\KregNotFoundException;
use NicTorgersen\KregApiSdk\Exceptions\KregValidationException;

try {
    $person = Kreg::person()->get($id);
} catch (KregNotFoundException $e) {
    // Person not found
} catch (KregAuthenticationException $e) {
    // Authentication failed
} catch (KregValidationException $e) {
    // Validation error
} catch (Kregception $e) {
    // General API error
}

License

MIT

Credits

Support

For issues or questions, please use the GitHub issue tracker.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-03