Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 08081eb

Browse files
committed
First Push
0 parents  commit 08081eb

12 files changed

+594
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
/vendor
3+
composer.lock

.php-cs-fixer.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"8.0.10","version":"3.2.1:v3.2.1#13ae36a76b6e329e44ca3cafaa784ea02db9ff14","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"phpdoc_var_annotation_correct_order":true,"array_syntax":{"syntax":"short"},"no_singleline_whitespace_before_semicolons":true,"no_extra_blank_lines":{"tokens":["break","case","continue","curly_brace_block","default","extra","parenthesis_brace_block","return","square_brace_block","switch","throw","use","use_trait"]},"cast_spaces":{"space":"single"},"concat_space":{"spacing":"one"},"ordered_imports":{"sort_algorithm":"length"},"single_quote":true,"lowercase_cast":true,"lowercase_static_reference":true,"no_empty_phpdoc":true,"no_empty_comment":true,"array_indentation":true,"increment_style":{"style":"post"},"short_scalar_cast":true,"class_attributes_separation":{"elements":{"const":"one","method":"one","property":"one"}},"no_mixed_echo_print":{"use":"echo"},"no_unused_imports":true,"binary_operator_spaces":{"default":"single_space"},"no_empty_statement":true,"unary_operator_spaces":true,"standardize_not_equals":true,"native_function_casing":true,"ternary_operator_spaces":true,"ternary_to_null_coalescing":true,"declare_equal_normalize":{"space":"single"},"function_typehint_space":true,"no_leading_import_slash":true,"blank_line_before_statement":{"statements":["break","case","continue","declare","default","do","exit","for","foreach","goto","if","include","include_once","require","require_once","return","switch","throw","try","while","yield"]},"combine_consecutive_unsets":true,"method_chaining_indentation":true,"no_whitespace_in_blank_line":true,"blank_line_after_opening_tag":true,"no_trailing_comma_in_list_call":true,"list_syntax":{"syntax":"short"},"compact_nullable_typehint":true,"explicit_string_variable":true,"no_leading_namespace_whitespace":true,"not_operator_with_successor_space":true,"object_operator_without_whitespace":true,"single_blank_line_before_namespace":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_whitespace_before_comma_in_array":true,"no_trailing_comma_in_singleline_array":true,"multiline_whitespace_before_semicolons":{"strategy":"no_multi_line"},"no_multiline_whitespace_around_double_arrow":true,"no_useless_return":true,"phpdoc_add_missing_param_annotation":true,"phpdoc_order":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"single_trait_insert_per_statement":true,"ordered_class_elements":{"order":["use_trait","constant","property","construct","public","protected","private"],"sort_algorithm":"none"},"return_type_declaration":{"space_before":"none"},"single_line_comment_style":{"comment_types":["hash"]},"trailing_comma_in_multiline":{"elements":["arrays"]}},"hashes":{"src\/SqsDiskConnector.php":3891659355,"src\/SqsDiskJob.php":2008078318,"src\/ResolvesPointers.php":3921232520,"src\/SqsDiskServiceProvider.php":3749898051,"src\/SqsDiskQueue.php":2844702818}}

.php-cs-fixer.php

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('bootstrap/cache')
5+
->exclude('storage')
6+
->exclude('vendor')
7+
->exclude('bower_components')
8+
->exclude('node_modules')
9+
->in(__DIR__)
10+
->name('*.php')
11+
->notName('*.blade.php')
12+
->ignoreDotFiles(true)
13+
->ignoreVCS(true);
14+
15+
return (new PhpCsFixer\Config)
16+
->setFinder($finder)
17+
->setRules([
18+
'@PSR2' => true,
19+
'phpdoc_no_empty_return' => false,
20+
'phpdoc_var_annotation_correct_order' => true,
21+
'array_syntax' => [
22+
'syntax' => 'short',
23+
],
24+
'no_singleline_whitespace_before_semicolons' => true,
25+
'no_extra_blank_lines' => [
26+
'tokens' => [
27+
'break', 'case', 'continue', 'curly_brace_block', 'default',
28+
'extra', 'parenthesis_brace_block', 'return',
29+
'square_brace_block', 'switch', 'throw', 'use', 'use_trait',
30+
],
31+
],
32+
'cast_spaces' => [
33+
'space' => 'single',
34+
],
35+
'concat_space' => [
36+
'spacing' => 'one',
37+
],
38+
'ordered_imports' => [
39+
'sort_algorithm' => 'length',
40+
],
41+
'single_quote' => true,
42+
'lowercase_cast' => true,
43+
'lowercase_static_reference' => true,
44+
'no_empty_phpdoc' => true,
45+
'no_empty_comment' => true,
46+
'array_indentation' => true,
47+
'increment_style' => ['style' => 'post'],
48+
'short_scalar_cast' => true,
49+
'class_attributes_separation' => [
50+
'elements' => [
51+
'const' => 'one',
52+
'method' => 'one',
53+
'property' => 'one',
54+
],
55+
],
56+
'no_mixed_echo_print' => [
57+
'use' => 'echo',
58+
],
59+
'no_unused_imports' => true,
60+
'binary_operator_spaces' => [
61+
'default' => 'single_space',
62+
],
63+
'no_empty_statement' => true,
64+
'unary_operator_spaces' => true, // $number ++ becomes $number++
65+
'standardize_not_equals' => true, // <> becomes !=
66+
'native_function_casing' => true,
67+
'ternary_operator_spaces' => true,
68+
'ternary_to_null_coalescing' => true,
69+
'declare_equal_normalize' => [
70+
'space' => 'single',
71+
],
72+
'function_typehint_space' => true,
73+
'no_leading_import_slash' => true,
74+
'blank_line_before_statement' => [
75+
'statements' => [
76+
'break', 'case', 'continue',
77+
'declare', 'default',
78+
'do', 'exit', 'for', 'foreach',
79+
'goto', 'if', 'include',
80+
'include_once', 'require', 'require_once',
81+
'return', 'switch', 'throw', 'try', 'while', 'yield',
82+
],
83+
],
84+
'combine_consecutive_unsets' => true,
85+
'method_chaining_indentation' => true,
86+
'no_whitespace_in_blank_line' => true,
87+
'blank_line_after_opening_tag' => true,
88+
'no_trailing_comma_in_list_call' => true,
89+
'list_syntax' => ['syntax' => 'short'],
90+
'compact_nullable_typehint' => true,
91+
'explicit_string_variable' => true,
92+
'no_leading_namespace_whitespace' => true,
93+
'not_operator_with_successor_space' => true,
94+
'object_operator_without_whitespace' => true,
95+
'single_blank_line_before_namespace' => true,
96+
'no_blank_lines_after_class_opening' => true,
97+
'no_blank_lines_after_phpdoc' => true,
98+
'no_whitespace_before_comma_in_array' => true,
99+
'no_trailing_comma_in_singleline_array' => true,
100+
'multiline_whitespace_before_semicolons' => [
101+
'strategy' => 'no_multi_line',
102+
],
103+
'no_multiline_whitespace_around_double_arrow' => true,
104+
'no_useless_return' => true,
105+
'phpdoc_add_missing_param_annotation' => true,
106+
'phpdoc_order' => true,
107+
'phpdoc_scalar' => true,
108+
'phpdoc_separation' => true,
109+
'phpdoc_single_line_var_spacing' => true,
110+
'single_trait_insert_per_statement' => true,
111+
'ordered_class_elements' => [
112+
'order' => [
113+
'use_trait',
114+
'constant',
115+
'property',
116+
'construct',
117+
'public',
118+
'protected',
119+
'private',
120+
],
121+
'sort_algorithm' => 'none',
122+
],
123+
'return_type_declaration' => [
124+
'space_before' => 'none',
125+
],
126+
'single_line_comment_style' => [
127+
'comment_types' => ['hash'],
128+
],
129+
'trailing_comma_in_multiline' => [
130+
'elements' => ['arrays'],
131+
],
132+
])
133+
->setLineEnding("\n");

composer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "simplesoftwareio/simple-sqs-extended-client",
3+
"description": "Simple SQS Extended Client is a SQS driver for Laravel that supports extended payloads beyond 256kb.",
4+
"keywords": [
5+
"laravel",
6+
"simple",
7+
"sqs",
8+
"extended",
9+
"driver"
10+
],
11+
"homepage": "https://www.simplesoftware.io/#/docs/simple-sqs-extended-client",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Simple Software LLC",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"require": {
20+
"php": ">=8.0",
21+
"aws/aws-sdk-php": "^3.189.0",
22+
"league/flysystem": "^1.1",
23+
"illuminate/container": "^v8.0.0",
24+
"illuminate/contracts": "^v8.0.0",
25+
"illuminate/filesystem": "^v8.0.0",
26+
"illuminate/queue": "^v8.0.0",
27+
"illuminate/support": "^v8.0.0"
28+
},
29+
"require-dev": {
30+
"mockery/mockery": "~1",
31+
"phpunit/phpunit": "~9",
32+
"friendsofphp/php-cs-fixer": "^3.2"
33+
},
34+
"autoload": {
35+
"psr-4": {
36+
"SimpleSoftwareIO\\SqsDisk\\": "src"
37+
}
38+
},
39+
"scripts": {
40+
"test": "phpunit"
41+
},
42+
"extra": {
43+
"laravel": {
44+
"providers": [
45+
"SimpleSoftwareIO\\SqsDisk\\SqsDiskServiceProvider"
46+
]
47+
}
48+
}
49+
}

readme.md

Whitespace-only changes.

src/ResolvesPointers.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace SimpleSoftwareIO\SqsDisk;
4+
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Container\Container;
7+
use Illuminate\Filesystem\FilesystemAdapter;
8+
9+
trait ResolvesPointers
10+
{
11+
/**
12+
* Resolves the job payload pointer.
13+
*
14+
* @return string|null
15+
*/
16+
protected function resolvePointer(): ?string
17+
{
18+
return json_decode($this->job['Body'])->pointer ?? null;
19+
}
20+
21+
/**
22+
* Resolves the configured queue disk that stores large payloads.
23+
*
24+
* @return FilesystemAdapter
25+
*/
26+
protected function resolveDisk(): FilesystemAdapter
27+
{
28+
return Container::getInstance()->make('filesystem')->disk(Arr::get($this->diskOptions, 'disk'));
29+
}
30+
}

src/SqsDiskConnector.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace SimpleSoftwareIO\SqsDisk;
4+
5+
use Aws\Sqs\SqsClient;
6+
use Illuminate\Support\Arr;
7+
use Illuminate\Queue\Connectors\SqsConnector;
8+
use Illuminate\Queue\Connectors\ConnectorInterface;
9+
10+
class SqsDiskConnector extends SqsConnector implements ConnectorInterface
11+
{
12+
/**
13+
* Establish a queue connection.
14+
*
15+
* @param array $config
16+
*
17+
* @return \Illuminate\Contracts\Queue\Queue
18+
*/
19+
public function connect(array $config)
20+
{
21+
$config = $this->getDefaultConfiguration($config);
22+
23+
if (! empty($config['key']) && ! empty($config['secret'])) {
24+
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
25+
}
26+
27+
return new SqsDiskQueue(
28+
new SqsClient($config),
29+
$config['queue'],
30+
$config['disk_options'],
31+
$config['prefix'] ?? '',
32+
$config['suffix'] ?? '',
33+
$config['after_commit'] ?? null,
34+
);
35+
}
36+
}

src/SqsDiskJob.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace SimpleSoftwareIO\SqsDisk;
4+
5+
use Aws\Sqs\SqsClient;
6+
use Illuminate\Support\Arr;
7+
use Illuminate\Queue\Jobs\SqsJob;
8+
use Illuminate\Container\Container;
9+
use Illuminate\Contracts\Queue\Job as JobContract;
10+
11+
class SqsDiskJob extends SqsJob implements JobContract
12+
{
13+
use ResolvesPointers;
14+
15+
/**
16+
* The Amazon SQS client instance.
17+
*
18+
* @var \Aws\Sqs\SqsClient
19+
*/
20+
protected $sqs;
21+
22+
/**
23+
* The Amazon SQS job instance.
24+
*
25+
* @var array
26+
*/
27+
protected $job;
28+
29+
/**
30+
* Holds the raw body to prevent fetching the file from
31+
* the disk multiple times.
32+
*
33+
* @var string
34+
*/
35+
protected $cachedRawBody;
36+
37+
/**
38+
* The disk options for the job.
39+
*
40+
* @var array
41+
*/
42+
protected $diskOptions;
43+
44+
/**
45+
* Create a new job instance.
46+
*
47+
* @param \Illuminate\Container\Container $container
48+
* @param \Aws\Sqs\SqsClient $sqs
49+
* @param array $job
50+
* @param string $connectionName
51+
* @param string $queue
52+
*
53+
* @return void
54+
*/
55+
public function __construct(Container $container, SqsClient $sqs, array $job, $connectionName, $queue, array $diskOptions)
56+
{
57+
$this->sqs = $sqs;
58+
$this->job = $job;
59+
$this->queue = $queue;
60+
$this->container = $container;
61+
$this->connectionName = $connectionName;
62+
$this->diskOptions = $diskOptions;
63+
}
64+
65+
/**
66+
* Delete the job from the queue.
67+
*
68+
* @return void
69+
*/
70+
public function delete()
71+
{
72+
parent::delete();
73+
74+
if (Arr::get($this->diskOptions, 'cleanup') && $pointer = $this->resolvePointer()) {
75+
$this->resolveDisk()->delete($pointer);
76+
}
77+
}
78+
79+
/**
80+
* Get the raw body string for the job.
81+
*
82+
* @return string
83+
*/
84+
public function getRawBody()
85+
{
86+
if ($this->cachedRawBody) {
87+
return $this->cachedRawBody;
88+
}
89+
90+
if ($pointer = $this->resolvePointer()) {
91+
return $this->cachedRawBody = $this->resolveDisk()->get($pointer);
92+
}
93+
94+
return parent::getRawBody();
95+
}
96+
}

0 commit comments

Comments
 (0)