Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sifex committed Jan 14, 2022
1 parent f423e6e commit e3fd68b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Flysystem Adapter for BunnyCDN Storage

[![Build Status](https://github.com/PlatformCommunity/flysystem-bunnycdn/actions/workflows/php.yml/badge.svg)](https://github.com/PlatformCommunity/flysystem-bunnycdn/actions) [![Codecov](https://img.shields.io/codecov/c/github/PlatformCommunity/flysystem-bunnycdn)](https://codecov.io/gh/PlatformCommunity/flysystem-bunnycdn) [![Packagist Version](https://img.shields.io/packagist/v/platformcommunity/flysystem-bunnycdn)](https://packagist.org/packages/platformcommunity/flysystem-bunnycdn) [![Packagist](https://img.shields.io/packagist/l/platformcommunity/flysystem-bunnycdn)](https://github.com/PlatformCommunity/flysystem-bunnycdn/blob/master/LICENSE) [![Packagist](https://img.shields.io/packagist/dm/platformcommunity/flysystem-bunnycdn)](https://packagist.org/packages/platformcommunity/flysystem-bunnycdn)
[![Build Status](https://github.com/PlatformCommunity/flysystem-bunnycdn/actions/workflows/php.yml/badge.svg)](https://github.com/PlatformCommunity/flysystem-bunnycdn/actions) [![Codecov](https://img.shields.io/codecov/c/github/PlatformCommunity/flysystem-bunnycdn)](https://codecov.io/gh/PlatformCommunity/flysystem-bunnycdn) [![Packagist Version](https://img.shields.io/packagist/v/platformcommunity/flysystem-bunnycdn)](https://packagist.org/packages/platformcommunity/flysystem-bunnycdn) ![Minimum PHP Version: 7.2](https://img.shields.io/badge/php-min%207.2-important) [![Licence: MIT](https://img.shields.io/packagist/l/platformcommunity/flysystem-bunnycdn)](https://github.com/PlatformCommunity/flysystem-bunnycdn/blob/master/LICENSE) [![Downloads](https://img.shields.io/packagist/dm/platformcommunity/flysystem-bunnycdn)](https://packagist.org/packages/platformcommunity/flysystem-bunnycdn)

## Installation

Expand Down
35 changes: 24 additions & 11 deletions src/BunnyCDNAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use League\Flysystem\UnableToWriteFile;
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
use League\Flysystem\Visibility;
use RuntimeException;
use stdClass;
use League\Flysystem\PathPrefixer;

Expand All @@ -41,13 +42,20 @@ class BunnyCDNAdapter implements FilesystemAdapter
private $prefixer;

/**
* BunnyCDNAdapter constructor.
* Pull Zone URL
* @var string
*/
private $pullzone_url;

/**
* @param BunnyCDNStorage $bunnyCDNStorage
* @param string $pullzone_url
*/
public function __construct(BunnyCDNStorage $bunnyCDNStorage)
public function __construct(BunnyCDNStorage $bunnyCDNStorage, string $pullzone_url = '')
{
$this->bunnyCDNStorage = $bunnyCDNStorage;
$this->prefixer = new PathPrefixer($this->bunnyCDNStorage->storageZoneName);
$this->pullzone_url = $pullzone_url;
}

/**
Expand Down Expand Up @@ -208,15 +216,6 @@ protected function normalizeObject(stdClass $fileObject): array
];
}

/**
* @param $path
* @return array
*/
public function getMetadata($path): array
{
return $this->normalizeObject($this->getObject($path));
}

/**
* @param $path
* @return string
Expand Down Expand Up @@ -376,4 +375,18 @@ public function move(string $source, string $destination, Config $config): void
$this->write($destination, $this->read($source), new Config());
$this->delete($source);
}

/**
* getURL method for Laravel users who want to use BunnyCDN's PullZone to retrieve a public URL
* @param string $path
* @return string
*/
public function getUrl(string $path): string
{
if($this->pullzone_url === '') {
throw new RuntimeException('In order to get a visible URL for a BunnyCDN object, you must pass the "pullzone_url" parameter to the BunnyCDNAdapter.');
}

return $this->pullzone_url.'/'.ltrim($path, '/');
}
}
34 changes: 32 additions & 2 deletions tests/BunnyCDNAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function getBunnyCDNMockObject($storageZoneName = self::STORAGE_ZONE_NAM
$mock->apiAccessKey = $apiAccessKey;
return $mock;

// return new BunnyCDNStorage('test12391248982', 'f053a6e4-5b85-46a3-922fc6664a1e-cb04-47e0', 'de');
return new BunnyCDNStorage('', '', 'sg');
}

/**
Expand Down Expand Up @@ -134,7 +134,12 @@ protected static function getBunnyCDNAdapterMethod($name): \ReflectionMethod
public function it_write()
{
$adapter = new BunnyCDNAdapter($this->getBunnyCDNMockObject());
$this->assertNull($adapter->write('testing/test123.txt', self::TEST_FILE_CONTENTS, new Config()));
try {
self::assertNull($adapter->delete('testing/test.txt'));
} catch (Exception $exception) {

}
$this->assertNull($adapter->write('testing/test.txt', self::TEST_FILE_CONTENTS, new Config()));
}

/**
Expand Down Expand Up @@ -263,6 +268,8 @@ public function it_list_contents()
/**
* @test
* @return void
* @throws Exception
* @throws Exception
*/
public function it_get_size()
{
Expand Down Expand Up @@ -294,6 +301,7 @@ public function it_rename()
/**
* @test
* @throws Exception
* @throws \League\Flysystem\FilesystemException
*/
public function it_create_dir()
{
Expand Down Expand Up @@ -331,6 +339,8 @@ public function it_get_timestamp()
/**
* @test
* @return void
* @throws \League\Flysystem\FilesystemException
* @throws \League\Flysystem\FilesystemException
*/
public function it_get_visibility()
{
Expand All @@ -344,6 +354,8 @@ public function it_get_visibility()
/**
* @test
* @return void
* @throws \League\Flysystem\FilesystemException
* @throws \League\Flysystem\FilesystemException
*/
public function it_set_visibility()
{
Expand All @@ -352,7 +364,25 @@ public function it_set_visibility()
self::expectException(\League\Flysystem\UnableToSetVisibility::class);

$adapter->setVisibility('testing/test.txt', 878);
}

/**
* @test
* @return void
* @throws \League\Flysystem\FilesystemException
* @throws \League\Flysystem\FilesystemException
*/
public function it_get_public_url()
{
$adapter = new BunnyCDNAdapter($this->getBunnyCDNMockObject(), 'https://testing1827129361.b-cdn.net');

$this->assertEquals('https://testing1827129361.b-cdn.net/testing/test.txt', $adapter->getUrl('/testing/test.txt'));

$adapter = new BunnyCDNAdapter($this->getBunnyCDNMockObject());

$this->expectException(RuntimeException::class);

$adapter->getUrl('/testing/test.txt');
}

}

0 comments on commit e3fd68b

Please sign in to comment.