graham-campbell/bitbucket

Bitbucket 是 Laravel 的 Bitbucket 桥接器


README

Laravel Bitbucket 由 Graham Campbell 创建并维护,是用于 Laravel 的 Bitbucket PHP API 客户端桥接器。它使用了我的 Laravel Manager 包。您可以查看 变更日志发行版安全策略许可协议行为准则贡献指南

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

安装

此版本需要 PHP 7.4-8.3,并支持 Laravel 8-11。

要获取最新版本,请使用 Composer 引入项目。

$ composer require "graham-campbell/bitbucket:^10.4"

安装完成后,如果您没有使用自动包发现,那么您需要在 config/app.php 中注册 GrahamCampbell\Bitbucket\BitbucketServiceProvider 服务提供者。

您还可以选择性地别名我们的外观

        'Bitbucket' => GrahamCampbell\Bitbucket\Facades\Bitbucket::class,

配置

Laravel Bitbucket 需要连接配置。

要开始,您需要发布所有供应商资产

$ php artisan vendor:publish

这将在您的应用中创建一个 config/bitbucket.php 文件,您可以修改它来设置配置。同时,请确保检查此包中原始配置文件在各个版本间的更改。

有两个配置选项

默认连接名称

此选项('default')指定您希望使用以下哪个连接作为所有工作的默认连接。当然,您可以使用管理类同时使用多个连接。此设置的默认值是 'main'

Bitbucket 连接

此选项('connections')为您的应用程序设置每个连接。已包括示例配置,但您可以添加您想要的任何数量的连接。请注意,支持五种认证方法:"jwt""none""oauth""private""password"

HTTP 缓存

此选项('cache')为您的应用程序设置每个缓存配置。默认提供 "illuminate" 驱动。已包括示例配置。

用法

BitbucketManager

这是最感兴趣的类。它绑定到 ioc 容器中的 'bitbucket',可以通过 Facades\Bitbucket 外观访问。该类通过扩展 AbstractManager 实现 ManagerInterface。该接口和抽象类都是我的 Laravel Manager 包的一部分,因此您可能想查看 该存储库 中的文档,了解如何使用管理器类。请注意,返回的连接类始终是 Bitbucket\Client 的实例。

Facades\Bitbucket

这个外观会将静态方法调用动态地传递给 ioc 容器中的 'bitbucket' 对象,默认情况下是 BitbucketManager 类。

BitbucketServiceProvider

这个类没有感兴趣的公开方法。这个类应该添加到 config/app.php 中的 providers 数组。这个类将设置 ioc 绑定。

实际例子

在这里,您可以看到这个包是如何简单易用的。默认情况下,默认适配器是 main。在配置文件中输入您的认证信息后,它就会正常工作。

use GrahamCampbell\Bitbucket\Facades\Bitbucket;
// you can alias this in config/app.php if you like

Bitbucket::currentUser()->show();
// we're done here - how easy was that, it just works!

bitbucket 管理器将表现得像一个 Bitbucket\Client 类。如果您想调用特定的连接,可以使用 connection 方法。

use GrahamCampbell\Bitbucket\Facades\Bitbucket;

// writing this:
Bitbucket::connection('main')->currentUser()->show();

// is identical to writing this:
Bitbucket::currentUser()->show();

// and is also identical to writing this:
Bitbucket::connection()->currentUser()->show();

// this is because the main connection is configured to be the default
Bitbucket::getDefaultConnection(); // this will return main

// we can change the default connection
Bitbucket::setDefaultConnection('alternative'); // the default is now alternative

// Get all the repositories info
Bitbucket::repositories()->list();

// Get all the repositories info filtered by workspace
Bitbucket::repositories()->workspaces('example')->list();

如果您像我一样喜欢使用依赖注入而不是外观,那么您可以轻松地这样注入管理器。

use GrahamCampbell\Bitbucket\BitbucketManager;

class Foo
{
    private BitbucketManager $bitbucket;

    public function __construct(BitbucketManager $bitbucket)
    {
        $this->bitbucket = $bitbucket;
    }

    public function bar()
    {
        $this->bitbucket->currentUser()->show();
    }
}

app(Foo::class)->bar();

有关如何使用我们这里调用的后台 Bitbucket\Client 类的更多信息,请查看 https://github.com/BitbucketPHP/Client/tree/v4.7.0#usage 上的文档,以及管理器类 https://github.com/GrahamCampbell/Laravel-Manager#usage

更多信息

此包中还有其他一些未在此处记录的类。这是因为它们不是供公共使用,而是由这个包内部使用的。

安全

如果您在此包中发现安全漏洞,请发送电子邮件到 security@tidelift.com。所有安全漏洞都将得到及时处理。您可以在此查看我们的完整安全策略 这里

许可证

Laravel Bitbucket 使用 MIT 许可证 (MIT) 许可。

企业版

作为 Tidelift 订阅的一部分提供

graham-campbell/bitbucket 的维护者以及成千上万的其他包的维护者正在与 Tidelift 合作,为您使用的构建应用程序的开源依赖项提供商业支持和维护。节省时间,降低风险,并提高代码质量,同时支付您使用的确切依赖项的维护者。了解更多信息 点击这里