定制 pvguerra/laravel-trakt 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

pvguerra/laravel-trakt

Composer 安装命令:

composer require pvguerra/laravel-trakt

包简介

Integrate Laravel with Trakt API

README 文档

README

Latest Version on Packagist Tests PHPStan Software License PHP Version Total Downloads

This package provides a convenient way to integrate the Trakt.tv API with your Laravel application.

The whole package was developed following the official Trakt API Documentation.

Installation

You can install the package via composer:

composer require pvguerra/laravel-trakt

You can publish the config file with:

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

This will publish the trakt.php config file to your config directory:

// config/trakt.php

return [
    'api_url' => env('TRAKT_API_URL', 'https://api.trakt.tv'),
    'client_id' => env('TRAKT_CLIENT_ID'),
    'client_secret' => env('TRAKT_CLIENT_SECRET'),
    'redirect_url' => env('TRAKT_REDIRECT_URL'),
    'staging_api_url' => env('STAGING_TRAKT_API_URL', 'https://api-staging.trakt.tv'),
];

You should add your Trakt API credentials and redirect URI to your .env file:

TRAKT_CLIENT_ID=your-trakt-client-id
TRAKT_CLIENT_SECRET=your-trakt-client-secret
TRAKT_REDIRECT_URL=your-trakt-redirect-url

If you don't have a Trakt client ID, you'll need to create a new API app.

Usage

This package provides a fluent interface to interact with the Trakt API. You can either use the Trakt facade or dependency injection to access the client.

Most methods return a Illuminate\Http\Client\Response object. You can call ->json() or ->object() on the response to get the data.

Here is a list of available classes you can use:

  • TraktCalendar
  • TraktCertification
  • TraktCheckIn
  • TraktCountry
  • TraktEpisode
  • TraktGenre
  • TraktLanguage
  • TraktList
  • TraktMovie
  • TraktNetwork
  • TraktPerson
  • TraktRecommendation
  • TraktSearch
  • TraktSeason
  • TraktShow
  • TraktSync
  • TraktUser

Authentication

Some endpoints require authentication. This package does not handle the OAuth2 flow for you, but it's easy to integrate with Laravel Socialite and the Trakt Socialite Provider.

Using with Laravel Socialite

use Laravel\Socialite\Facades\Socialite;

public function redirect()
{
    return Socialite::driver('trakt')->redirect();
}

// Receiving the callback from the provider after authentication.
public function callback()
{
    $socialiteUser = Socialite::driver('trakt')->user();
    
    // Store the token in your database
    $user = auth()->user();
    $user->trakt_token = $socialiteUser->token;
    $user->trakt_id = $socialiteUser->id;
    $user->save();
    
    return redirect()->route('dashboard');
}

Using the token

Once you have an access token, you can set it on the client:

use Pvguerra\LaravelTrakt\Facades\Trakt;

// Using the facade
Trakt::setToken('your-access-token');

// Now you can make authenticated requests
$history = Trakt::sync()->history();

// Or using dependency injection
use Pvguerra\LaravelTrakt\TraktUser;

$user = auth()->user();
$traktUser = new TraktUser($user->trakt_token);
return $traktUser->collection($user->trakt_id, 'movies');

Examples

Movies

Get a single movie:

use Pvguerra\LaravelTrakt\Facades\Trakt;

$movie = Trakt::movie()->get('the-batman-2022');

Get popular movies:

use Pvguerra\LaravelTrakt\Facades\Trakt;

$popularMovies = Trakt::movie()->popular();

TV Shows

Get a single show:

use Pvguerra\LaravelTrakt\Facades\Trakt;

$show = Trakt::show()->get('game-of-thrones');

Get trending shows:

use Pvguerra\LaravelTrakt\Facades\Trakt;

$trendingShows = Trakt::show()->trending();

Search

Search for a movie, show, person, etc.

use Pvguerra\LaravelTrakt\Facades\Trakt;

$results = Trakt::search()->query('batman', 'movie');

User

Get a user's profile (requires authentication):

use Pvguerra\LaravelTrakt\Facades\Trakt;

Trakt::setToken('user-access-token');
$profile = Trakt::user()->profile('me');

Get a user's watched history (requires authentication):

use Pvguerra\LaravelTrakt\Facades\Trakt;

Trakt::setToken('user-access-token');
$history = Trakt::user()->history('me', 'movies');

Calendar

Get all shows airing in the next 7 days:

use Pvguerra\LaravelTrakt\Facades\Trakt;

$calendar = Trakt::calendar()->myShows();

Quality Assurance

Testing

This package uses Pest for testing. Run the tests with:

composer test

Static Analysis

This package uses PHPStan level 5 for static code analysis. Run the analysis with:

composer analyse

CI/CD

This package uses GitHub Actions to run tests and static analysis on each pull request and push to the main branch. The CI pipeline ensures that:

  1. All tests pass
  2. PHPStan analysis passes with no errors
  3. Branch protection rules prevent merging to main if tests or analysis fail

Requirements

  • PHP 8.1 or higher
  • Laravel 9.0 or higher

Compatibility

Laravel PHP
9.x 8.1, 8.2
10.x 8.1, 8.2, 8.3

Documentation

Full documentation will be available soon.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Pull requests are welcome!

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

pvguerra/laravel-trakt 适用场景与选型建议

pvguerra/laravel-trakt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「trakt」 「pvguerra」 「laravel-trakt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pvguerra/laravel-trakt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pvguerra/laravel-trakt 我们能提供哪些服务?
定制开发 / 二次开发

基于 pvguerra/laravel-trakt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-01