Skip to content
Snippets Groups Projects
Select Git revision
  • 85b0fd02b679bec781ea7593a04f2ce8654b6f8e
  • main default protected
  • issue-56
  • testing-systems
4 results

Plugin.php

Blame
  • user avatar
    Jan-Hendrik Willms authored
    85b0fd02
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Plugin.php 1.69 KiB
    <?php
    namespace TracToGitlab;
    
    use Config;
    use Gitlab;
    use GuzzleHttp;
    use Http;
    use Parsedown;
    use Pimple;
    
    abstract class Plugin extends \StudIPPlugin
    {
        private $container = null;
    
        public function getDIContainer()
        {
            if ($this->container === null) {
                require_once $this->getPluginPath() . '/vendor/autoload.php';
    
                $this->container = new Pimple\Container();
    
                $this->container['trac'] = function () {
                    return new TracLookup(Config::get()->TRAC2GITLAB_TRAC_URL);
                };
    
                $this->container['gitlab'] = function () {
                    $builder = new Gitlab\HttpClient\Builder(
                        new GuzzleHttp\Client(),
                        new Http\Factory\Guzzle\RequestFactory(),
                        new Http\Factory\Guzzle\StreamFactory(),
                        new Http\Factory\Guzzle\UriFactory()
                    );
    
                    $client = new Gitlab\Client($builder);
                    $client->setUrl(Config::get()->TRAC2GITLAB_GITLAB_URL);
                    $client->authenticate(Config::get()->TRAC2GITLAB_GITLAB_TOKEN, Gitlab\Client::AUTH_HTTP_TOKEN);
                    return $client;
                };
    
                $this->container['gitlabProjectId'] = function () {
                    return Config::get()->TRAC2GITLAB_GITLAB_PROJECT_ID;
                };
    
                $this->container['gitlabPager'] = function ($c) {
                    return new Gitlab\ResultPager($c['gitlab']);
                };
    
                $this->container['parsedown'] = function () {
                    $parsedown = new Parsedown();
                    $parsedown->setSafeMode(true);
                    return $parsedown;
                };
            }
            return $this->container;
        }
    }