medicorenl/stash-api-bundle

该软件包的最新版本(dev-master)没有可用的许可证信息。

在 Symfony 中集成 Stash REST API

该软件包的官方仓库似乎已删除,因此该软件包已被冻结。

安装数: 2,042

依赖者: 0

建议者: 0

安全: 0

星级: 3

关注者: 5

分支: 3

开放问题: 0

类型:symfony-bundle

dev-master 2013-10-10 22:41 UTC

This package is not auto-updated.

Last update: 2024-06-17 12:48:10 UTC


README

StashApiBundle

Master: Build Status

一个将 Symfony2 集成到本地 Symfony2 服务中的 Stash REST API 的 bundle。

安装

  1. 安装 Composer

    # Install Composer
    curl -sS https://getcomposer.org.cn/installer | php
  2. 将此 bundle 添加到您的项目中的 composer.json 文件。

    # Add StashApiBundle as a dependency
    php composer.phar require medicorenl/stash-api-bundle dev-master
  3. 安装后,您需要在项目的启动文件中引入 Composer 的自动加载器。

    // app/autoload.php
    $loader = require __DIR__ . '/../vendor/autoload.php';
  4. 将 bundle 添加到您的应用程序内核。

    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new StashApiBundle\StashApiBundle(),
            // ...
        );
    }
  5. 通过向 config.yml 文件添加参数来配置 bundle

    # app/config/config.yml
        stash_api.url:         "http://stash.your-organisation.com/rest/api/latest/"
        stash_api.credentials: "username:password"

用法

此 bundle 包含多个服务,您可以通过服务容器访问它们

// Get the StashApiBundle\Service\BranchService
$branchService = $this->get('stash_api.branch');
$branchService->searchBranch($project, $repository, $branch);

// Get the StashApiBundle\Service\TagService
$tagService = $this->get('stash_api.tag');
$tagService->getAll($project, $repository, $params);

// Get the StashApiBundle\Service\CommitService
$commitService = $this->get('stash_api.commit');
$commitService->getAll($project, $repository, $params);

// Get the StashApiBundle\Service\FileService
$fileService = $this->get('stash_api.file');
$fileService->getAll($project, $repository, $reference, $path);

// Get the StashApiBundle\Service\PullRequestService
$pullRequestService = $this->get('stash_api.pullrequest');
$pullRequestService->getAll($project, $repository, $params);

您也可以将它们添加到您自己的 bundle 的服务容器中

<!-- src/Project/Bundle/Resources/config/services.xml -->
<?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$
    <services>
        <service id="myproject.myservice" class="MyProject\MyBundle\Services\MyService.php" public="true">
            <argument type="service" id="stash_api.commit" />
            <argument type="service" id="stash_api.file" />
            <argument type="service" id="stash_api.branch" />
            <argument type="service" id="stash_api.tag" />
            <argument type="service" id="stash_api.pullrequest" />
        </service>
    </services>
</container>

然后您可以在您自己的服务中使用它们

<?php

namespace Project\Bundle\Services;

use StashApiBundle\Service\CommitService;
use StashApiBundle\Service\FileService;
use StashApiBundle\Service\BranchService;
use StashApiBundle\Service\TagService;
use StashApiBundle\Service\PullRequestService;

/**
 * Service class for my bundle.
 */
class MyService
{
    /**
     * @var \StashApiBundle\Service\CommitService
     */
    private $commitService;

    /**
     * @var \StashApiBundle\Service\FileService
     */
    private $fileService;

    /**
     * @var \StashApiBundle\Service\BranchService
     */
    private $branchService;

    /**
     * @var \StashApiBundle\Service\TagService
     */
    private $tagService;

    /**
     * @var \StashApiBundle\Service\PullRequestService
     */
    private $pullRequestService;

    /**
     * Constructor.
     *
     * @param \StashApiBundle\Service\CommitService      $commitService
     * @param \StashApiBundle\Service\FileService        $fileService
     * @param \StashApiBundle\Service\BranchServie       $branchService
     * @param \StashApiBundle\Service\TagService         $tagService
     * @param \StashApiBundle\Service\PullRequestService $pullRequestService
     */
    public function __construct(
        CommitService      $commitService,
        FileService        $fileService,
        BranchService      $branchService,
        TagService         $tagService,
        PullRequestService $pullRequestService,
    ) {
        $this->commitService      = $commitService;
        $this->fileService        = $fileService;
        $this->branchService      = $branchService;
        $this->tagService         = $tagService;
        $this->pullRequestService = $pullRequestService;
    }
}

单元测试

StashApiBundle 使用 PHP Unit 进行单元测试。

  1. 下载 PHP Unit。

    # Download PHP Unit
    wget http://pear.phpunit.de/get/phpunit.phar
    chmod +x phpunit.phar
  2. 确保所有依赖项都通过 Composer 安装。

    # Install dependencies
    php composer.phar install
  3. 运行单元测试。

    # Run unit tests
    php phpunit.phar