<?php

/**
 * Minds S3 Torrent Builder
 *
 * @author emi
 */

namespace Minds\Core\Torrent\TorrentBuilders;

use Minds\Core\Di\Di;
use Minds\Core\Media\Services\AWS;

class S3 implements TorrentBuilderInterface
{
    /** @var AWS */
    protected $aws;

    /** @var string */
    protected $key;

    /** @var string */
    protected $file;

    public function __construct($aws = null)
    {
        $this->aws = $aws ?: new AWS([
            's3' => [
                'endpoint' => Di::_()->get('Config')->get('cinemr_url'),
                'force_path_style' => true,
                'bucket_endpoint' => true,
            ]
        ]);
    }

    /**
     * @param $key
     * @return $this
     */
    public function setKey($key)
    {
        $this->key = $key;
        return $this;
    }

    /**
     * @param mixed $file
     * @return S3
     */
    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }

    /**
     * Downloads a pre-built torrent from a cinemr S3 object
     * @return bool|string
     */
    public function build()
    {
        $this->aws->setKey($this->key);
        return $this->aws->getTorrent($this->file);
    }
}

<?php

/**
 * Minds S3 Torrent Builder
 *
 * @author emi
 */

namespace Minds\Core\Torrent\TorrentBuilders;

use Minds\Core\Di\Di;
use Minds\Core\Media\Services\AWS;
use Minds\Core\Media\Services\Factory;

class S3 implements TorrentBuilderInterface
{
    /** @var AWS */
    protected $aws;

    /** @var string */
    protected $key;

    /** @var string */
    protected $file;

    public function __construct($aws = null)
    {
        $this->aws = $aws ?: Factory::build('AWS');
    }

    /**
     * @param $key
     * @return $this
     */
    public function setKey($key)
    {
        $this->key = $key;
        return $this;
    }

    /**
     * @param mixed $file
     * @return S3
     */
    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }

    /**
     * Downloads a pre-built torrent from a cinemr S3 object
     * @return bool|string
     */
    public function build()
    {
        $this->aws->setKey($this->key);
        return $this->aws->getTorrent($this->file);
    }
}

Allow using roles and default AWS config
(fix): Allow using roles and default AWS config
