Skip to content

Commit

Permalink
Merge pull request #139 from drjdr/main
Browse files Browse the repository at this point in the history
Update for Laravel 11, PHP8 and ZipStream 3.1
  • Loading branch information
aarondfrancis authored May 15, 2024
2 parents 17d5d36 + 4e1e251 commit 1fd2f35
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 68 deletions.
43 changes: 25 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,57 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.1, 8.2, 8.3 ]
laravel: [ 9.*, 10.*, 11.* ]
guzzle: [ 6.*, 7.* ]
php: ['8.1', '8.2', '8.3' ]
laravel: [ '8.*', '9.*', '10.*', '11.*' ]
guzzle: [ '6.*', '7.*' ]
dependency-version: [ prefer-lowest, prefer-stable ]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 9.*
testbench: 7.*

- laravel: 10.*
testbench: 8.*

- laravel: 11.*
testbench: 9.*

exclude:
# Laravel 9 requires Guzzle ^7.2
- laravel: 9.*
guzzle: 6.*
- laravel: 8.*
php: 8.1
dependency-version: prefer-lowest
- laravel: 8.*
php: 8.2
dependency-version: prefer-lowest
- laravel: 8.*
php: 8.3
dependency-version: prefer-lowest

# PHP 8.2 requires Laravel 9.33 at least, so skip lowest
- laravel: 9.*
php: 8.2
dependency-version: prefer-lowest
- laravel: 9.*
php: 8.3
dependency-version: prefer-lowest

# Laravel 10 requires Guzzle ^7.2
- laravel: 10.*
guzzle: 6.*

# Laravel 11 requires PHP 8.2
- laravel: 11.*
php: 8.1

# Laravel 11 requires Guzzle ^7.2
# Guzzle restrictions
- laravel: 9.*
guzzle: 6.*
- laravel: 10.*
guzzle: 6.*
- laravel: 11.*
guzzle: 6.*

name: P${{ matrix.php }} / L${{ matrix.laravel }} / G${{ matrix.guzzle }} / ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -72,7 +79,7 @@ jobs:
- name: Install dependencies
run: |
composer self-update ${{ matrix.composer-version }}
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "guzzlehttp/guzzle:${{ matrix.guzzle }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "guzzlehttp/guzzle:${{ matrix.guzzle }}" --no-interaction --no-update --dev
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor
/storage/framework/testing
.env
.phpunit.cache
.phpunit.result.cache
npm-debug.log
yarn-error.log
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
}
],
"require": {
"php": "^7.4|^8.0",
"illuminate/support": "^8.0|^9.0|^10|^11",
"illuminate/filesystem": "^8.0|^9.0|^10|^11",
"illuminate/console": "^8.0|^9.0|^10|^11",
"maennchen/zipstream-php": "^2.1",
"guzzlehttp/guzzle": "^6.3|^7.2",
"php": "^8.1",
"illuminate/filesystem": "^8|^9|^10|^11",
"illuminate/console": "^8|^9|^10|^11",
"illuminate/support": "^8|^9|^10|^11",
"maennchen/zipstream-php": "^3.1",
"guzzlehttp/guzzle": "^6.5.8|^7.2",
"aws/aws-sdk-php": "^3.216.1"
},
"require-dev": {
Expand Down
Binary file added contents.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</testsuites>
<php>

</php>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
Expand Down
4 changes: 2 additions & 2 deletions src/Clients/LambdaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function latestVersionHasAlias(LambdaFunction $function, $alias)

/**
* @param null|string $marker
* @return \Aws\Result
* @return Result
*/
public function getVersions(LambdaFunction $function, $marker = null)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public function aliasVersion(LambdaFunction $function, $alias, $version = null)
}

/**
* @return \Aws\Result|false
* @return Result|false
*/
public function getAliasWithoutException(LambdaFunction $function, $name)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/SidecarException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Hammerstone\Sidecar\Exceptions;

class SidecarException extends \Exception
use Exception;

class SidecarException extends Exception
{
}
15 changes: 9 additions & 6 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

namespace Hammerstone\Sidecar;

use Exception;
use Generator;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder as SymfonyFinder;

class Finder
{
/** @var \Illuminate\Support\Collection */
/** @var Collection */
protected $includeFilesAndDirectories;

/** @var \Illuminate\Support\Collection */
/** @var Collection */
protected $excludeFilesAndDirectories;

/** @var bool */
Expand Down Expand Up @@ -69,7 +72,7 @@ public function selected()
}

/**
* @return \Generator|string[]
* @return Generator|string[]
*/
protected function yieldSelectedFiles()
{
Expand Down Expand Up @@ -110,7 +113,7 @@ protected function includedFiles()
return $this->includeFilesAndDirectories
->each(function ($path) {
if (!is_file($path) && !is_dir($path)) {
throw new \Exception($path . ' is neither a file nor a directory.');
throw new Exception($path . ' is neither a file nor a directory.');
}
})
->filter(function ($path) {
Expand All @@ -124,7 +127,7 @@ protected function includedDirectories()
return $this->includeFilesAndDirectories
->each(function ($path) {
if (!is_file($path) && !is_dir($path)) {
throw new \Exception($path . ' is neither a file nor a directory.');
throw new Exception($path . ' is neither a file nor a directory.');
}
})
->reject(function ($path) {
Expand All @@ -146,7 +149,7 @@ protected function shouldExclude(string $path): bool

/**
* @param string|array $paths
* @return \Illuminate\Support\Collection
* @return Collection
*/
protected function sanitize($paths)
{
Expand Down
11 changes: 7 additions & 4 deletions src/LambdaFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
namespace Hammerstone\Sidecar;

use Aws\Result;
use Exception;
use GuzzleHttp\Promise\PromiseInterface;
use Hammerstone\Sidecar\Exceptions\SidecarException;
use Hammerstone\Sidecar\Results\PendingResult;
use Hammerstone\Sidecar\Results\SettledResult;
use Illuminate\Http\Response;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Throwable;

abstract class LambdaFunction
{
Expand Down Expand Up @@ -44,7 +47,7 @@ public static function executeAsync($payload = [])
* @param bool $async
* @return array
*
* @throws \Throwable
* @throws Throwable
*/
public static function executeMany($payloads, $async = false)
{
Expand All @@ -56,7 +59,7 @@ public static function executeMany($payloads, $async = false)
*
* @return array
*
* @throws \Throwable
* @throws Throwable
*/
public static function executeManyAsync($payloads)
{
Expand Down Expand Up @@ -176,9 +179,9 @@ public function warmingConfig()
/**
* The default representation of this function as an HTTP response.
*
* @return \Illuminate\Http\Response
* @return Response
*
* @throws \Exception
* @throws Exception
*/
public function toResponse($request, SettledResult $result)
{
Expand Down
25 changes: 16 additions & 9 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,16 @@ public function upload()
// a writeable local disk!
$stream = fopen($path, 'w');

$options = new Archive;
$options->setEnableZip64(false);
$options->setOutputStream($stream);

$zip = new ZipStream($name = null, $options);
$zip = new ZipStream(
outputStream: $stream,
enableZip64: false,
sendHttpHeaders: false,
outputName: null
);

// Set the time to now so that hashes are
// stable during testing.
$options = tap(new FileOptions)->setTime(Carbon::now());
$now = Carbon::now();

foreach ($this->files() as $file) {
// Add the base path so that ZipStream can
Expand All @@ -354,19 +355,25 @@ public function upload()
// Remove the base path so that everything inside
// the zip is relative to the project root.
$zip->addFileFromPath(
$this->normalizeSeparators($this->removeBasePath($file)), $file, $options
fileName: $this->normalizeSeparators($this->removeBasePath($file)),
path: $file,
lastModificationDateTime: $now,
);
}

foreach ($this->exactIncludes as $source => $destination) {
$zip->addFileFromPath(
$this->normalizeSeparators($destination), $source, $options
fileName: $this->normalizeSeparators($this->removeBasePath($destination)),
path: $source,
lastModificationDateTime: $now
);
}

foreach ($this->stringContents as $destination => $stringContent) {
$zip->addFile(
$this->normalizeSeparators($destination), $stringContent, $options
fileName: $this->normalizeSeparators($this->removeBasePath($destination)),
data: $stringContent,
lastModificationDateTime: $now
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Hammerstone\Sidecar;

use ReflectionClass;

class Region
{
const US_EAST_1 = 'us-east-1'; // US East (N. Virginia)
Expand Down Expand Up @@ -55,6 +57,6 @@ class Region

public static function all()
{
return (new \ReflectionClass(static::class))->getConstants();
return (new ReflectionClass(static::class))->getConstants();
}
}
9 changes: 6 additions & 3 deletions src/Results/PendingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

namespace Hammerstone\Sidecar\Results;

use Exception;
use GuzzleHttp\Promise\PromiseInterface;
use Hammerstone\Sidecar\LambdaFunction;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class PendingResult implements Responsable, ResultContract
{
Expand Down Expand Up @@ -58,10 +61,10 @@ public function rawPromise()
/**
* Defer to the SettledResult.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Request $request
* @return Response
*
* @throws \Exception
* @throws Exception
*/
public function toResponse($request)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Results/ResultContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
namespace Hammerstone\Sidecar\Results;

use Hammerstone\Sidecar\LambdaFunction;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

interface ResultContract
{
public function __construct($raw, LambdaFunction $function);

/**
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Request $request
* @return Response
*/
public function toResponse($response);

Expand Down
6 changes: 4 additions & 2 deletions src/Results/SettledResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Hammerstone\Sidecar\Exceptions\LambdaExecutionException;
use Hammerstone\Sidecar\LambdaFunction;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Throwable;
Expand Down Expand Up @@ -79,8 +81,8 @@ public function settled()
}

/**
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Request $request
* @return Response
*
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Sidecar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Sidecar extends Facade
{
/**
* @see \Hammerstone\Sidecar\Manager
* @see Manager
*
* @return string
*/
Expand Down
Loading

0 comments on commit 1fd2f35

Please sign in to comment.