setono/kraken-io-bundle

Symfony 扩展,集成了 kraken.io PHP SDK

安装次数: 28,786

依赖者: 1

建议者: 0

安全性: 0

星级: 2

关注者: 3

分支: 3

开放问题: 6

类型:symfony-bundle


README

Latest Version Latest Unstable Version Software License Build Status Code Coverage

将 kraken.io PHP SDK 集成到 Symfony。

安装

步骤 1: 下载扩展包

$ composer require setono/kraken-io-bundle

步骤 2: 启用扩展包

通过将扩展包添加到 config/bundles.php 中注册的插件/扩展包列表中启用插件

<?php
$bundles = [
    // ...
    
    Setono\KrakenIoBundle\SetonoKrakenIoBundle::class => ['all' => true],
    
    // ...
];

步骤 3: 添加配置

# config/packages/setono_kraken_io.yaml
setono_kraken_io:
    api_key: your_api_key
    api_secret: your_api_secret

用法

现在您可以注入 ClientInterface 到您的服务中

<?php
namespace App\Image;

use Setono\Kraken\Client\ClientInterface;

final class Optimizer
{
    private $client;
    
    public function __construct(ClientInterface $client)
    {
        $this->client = $client;
    }
}

使用自动绑定,这将直接工作。如果您不使用自动绑定,您需要在服务定义中注入它

<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="https://symfony.com.cn/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://symfony.com.cn/schema/dic/services https://symfony.com.cn/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="YourService">
            <argument type="service" id="Setono\Kraken\Client\ClientInterface"/>
        </service>
    </services>
</container>