-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/shopware 145 add plugin logic #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4ae668e
FEAT: Add plugin default structure
TheBreaken be73ded
FEAT: Add logic to generate urls with image proxy
TheBreaken cf7320c
FEAT: Remove infection because we don't use it properly yet
TheBreaken e3576c2
FEAT: Define random execution test order
TheBreaken 27bab53
FEAT: Add workflows
TheBreaken 470a06d
FIX: Typo
TheBreaken 765f360
FEAT: Try using actions in an action
TheBreaken ddcc95d
FEAT: This line is now in an action
TheBreaken bb1dfc3
FEAT: Add actions directory
TheBreaken 1d4dec7
FIX: Remove token definition
TheBreaken d30bb48
FIX: Prevent using intern actions because this public repo has no acc…
TheBreaken 060c83c
FIX: Ignore warnings
TheBreaken 489032e
FIX: Use newer php version
TheBreaken 6453c89
FIX: Add covers classes
TheBreaken 00d3d7c
FIX: Change coverage path
TheBreaken 4ccc30f
FIX: Change path name
TheBreaken b93f790
FIX: Prevent generate code coverage in pr because it doesn't work at …
TheBreaken 5479d7e
FIX: Prevent using netlogix action
TheBreaken 74bd7e3
FEAT: Add test for Subscriber
TheBreaken d9a8a9c
FEAT: Use more universe pattern
TheBreaken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Apply Coding Standard | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'src/**' | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
php-coding-standard: | ||
name: 'Apply PHP Coding Standard' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout Code' | ||
uses: actions/checkout@v4 | ||
|
||
- name: 'Composer install' | ||
uses: netlogix/actions/.github/actions/composer-install@main | ||
with: | ||
php-version: '8.2' | ||
github_token: ${{ secrets.COMPOSER_AUTH }} | ||
|
||
- name: 'ECS PHP Code' | ||
shell: bash | ||
run: composer lint-fix | ||
|
||
- name: 'Create pull-request' | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
commit-message: "[automated] Apply Coding Standard" | ||
branch: 'automated-apply-coding-standards' | ||
title: '[automated] Apply Coding Standard' | ||
labels: 'automated' | ||
delete-branch: true | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: 'Enable Pull Request Merge when ready' | ||
if: steps.cpr.outputs.pull-request-operation == 'created' | ||
run: gh pr merge --auto "${{ steps.cpr.outputs.pull-request-number }}" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-platform: | ||
name: 'Test' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 'Checkout Code' | ||
uses: actions/checkout@v3 | ||
|
||
- uses: netlogix/actions/.github/actions/composer-install@main | ||
with: | ||
php-version: '8.2' | ||
coverage: 'xdebug3' | ||
args: '--prefer-dist --no-progress --no-interaction --optimize-autoloader' | ||
github_token: ${{ secrets.COMPOSER_AUTH }} | ||
|
||
- name: 'Run Unit Tests' | ||
shell: bash | ||
env: | ||
XDEBUG_MODE: 'coverage' | ||
run: vendor/bin/phpunit --coverage-clover Build/Artifacts/Reports/Unit/clover.xml | ||
|
||
- name: 'Generate Unit Test Code Coverage Summary Report' | ||
uses: saschanowak/CloverCodeCoverageSummary@0.3.1 | ||
with: | ||
filename: Build/Artifacts/Reports/Unit/clover.xml | ||
|
||
- name: 'Add Unit Test Code Coverage to file' | ||
shell: bash | ||
run: | | ||
echo '## Code Coverage Summery for unit tests' >> code-coverage-merged.md | ||
cat code-coverage-summary.md >> code-coverage-merged.md | ||
|
||
echo '## Code Coverage for unit tests' >> $GITHUB_STEP_SUMMARY | ||
cat code-coverage-summary.md >> $GITHUB_STEP_SUMMARY | ||
cat code-coverage-details.md >> $GITHUB_STEP_SUMMARY | ||
|
||
- name: 'Add Code Coverage as PR Comment' | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
if: github.event_name == 'pull_request' | ||
with: | ||
recreate: true | ||
path: code-coverage-merged.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/src/Resources/app/storefront/dist/ | ||
/.phpunit.result.cache | ||
/.phpunit.cache | ||
/vendor/ | ||
composer.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "netlogix/nlxshopwareimageproxy", | ||
"version": "v1.0.0", | ||
"description": "Plugin to allow shopware to authenticate and support image proxy", | ||
"type": "shopware-platform-plugin", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"nlxShopwareImageProxy\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"shopware/core": "dev-trunk" | ||
}, | ||
"require-dev": { | ||
"php": ">= 8.2", | ||
"phpunit/phpunit": "^12.0", | ||
"netlogix/coding-guidelines-php": "^1.0" | ||
}, | ||
"conflict": { | ||
"shopware/core": "<6.7.0" | ||
}, | ||
"scripts": { | ||
"lint": "ecs check", | ||
"lint-fix": "ecs check --fix", | ||
"unit": "vendor/bin/phpunit tests/Unit" | ||
}, | ||
"extra": { | ||
"shopware-plugin-class": "nlxShopwareImageProxy\\nlxShopwareImageProxy", | ||
"label": { | ||
"de-DE": "Bilder Proxy Unterstützung", | ||
"en-GB": "Image proxy support" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"symfony/runtime": true | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Netlogix\CodingGuidelines\Php\DefaultPhp; | ||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
return static function (ECSConfig $ecsConfig): void { | ||
(new DefaultPhp())->configure($ecsConfig); | ||
|
||
$ecsConfig->paths( | ||
[ | ||
__DIR__ . '/src', | ||
] | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
cacheDirectory=".phpunit.cache" | ||
executionOrder="random" | ||
requireCoverageMetadata="true" | ||
beStrictAboutCoverageMetadata="true" | ||
beStrictAboutOutputDuringTests="true" | ||
displayDetailsOnPhpunitDeprecations="true" | ||
failOnPhpunitDeprecation="true" | ||
failOnRisky="true" | ||
failOnWarning="true"> | ||
|
||
<php> | ||
<ini name="display_errors" value="1" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="SHELL_VERBOSITY" value="-1" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>./tests/Unit/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage ignoreDeprecatedCodeUnits="true" | ||
disableCodeCoverageIgnore="true"> | ||
</coverage> | ||
|
||
<source> | ||
<include> | ||
<directory >src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy\DTO; | ||
|
||
class ImageProxyOptionDTO | ||
{ | ||
public function __construct( | ||
public readonly string $width, | ||
public readonly string $height, | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy\Decorators; | ||
|
||
use nlxShopwareImageProxy\Services\UrlGeneratorInterface; | ||
use Shopware\Core\Content\Media\Core\Application\AbstractMediaUrlGenerator; | ||
use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||
|
||
#[AsDecorator(decorates: AbstractMediaUrlGenerator::class)] | ||
class MediaUrlGeneratorDecorator extends AbstractMediaUrlGenerator | ||
{ | ||
public function __construct( | ||
private readonly UrlGeneratorInterface $urlGenerator | ||
) { | ||
} | ||
|
||
public function generate(array $paths): array | ||
{ | ||
return array_map(function ($value) { | ||
return $this->urlGenerator->generateUrl($value->path); | ||
}, $paths); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy\Services; | ||
|
||
use nlxShopwareImageProxy\DTO\ImageProxyOptionDTO; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class UrlGenerator implements UrlGeneratorInterface | ||
{ | ||
public function __construct( | ||
#[Autowire(env: 'default::string:IMGPROXY_KEY')] | ||
private ?string $imgProxySecret, | ||
#[Autowire(env: 'default::string:IMGPROXY_SALT')] | ||
private ?string $imgProxySalt, | ||
#[Autowire(env: 'default::string:IMAGE_PROXY_HOST')] | ||
private ?string $imageProxyHost, | ||
) { | ||
$this->imgProxySecret = pack("H*", $imgProxySecret); | ||
$this->imgProxySalt = pack("H*", $imgProxySalt); | ||
} | ||
|
||
public function generateUrl(string $imagePath, ?ImageProxyOptionDTO $imageProxyOption = null): string | ||
{ | ||
$mediaPath = 'local://' . $imagePath; | ||
$path = rtrim(strtr(base64_encode($mediaPath), '+/', '-_'), '='); | ||
|
||
if ($imageProxyOption !== null) { | ||
$path = sprintf('resize:fit:%s:%s:no:0/%s', $imageProxyOption->width, $imageProxyOption->height, $path); | ||
} | ||
|
||
$sha256 = hash_hmac('sha256', $this->imgProxySalt . '/' . $path, $this->imgProxySecret, true); | ||
$sha256Encoded = base64_encode($sha256); | ||
$signature = str_replace(["+", "/", "="], ["-", "_", ""], $sha256Encoded); | ||
|
||
return sprintf('%s/%s/%s', $this->imageProxyHost, $signature, $path); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy\Services; | ||
|
||
use nlxShopwareImageProxy\DTO\ImageProxyOptionDTO; | ||
|
||
interface UrlGeneratorInterface | ||
{ | ||
public function generateUrl(string $imagePath, ?ImageProxyOptionDTO $imageProxyOption = null): string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy\Subscriber; | ||
|
||
use nlxShopwareImageProxy\DTO\ImageProxyOptionDTO; | ||
use nlxShopwareImageProxy\Services\UrlGeneratorInterface; | ||
use Shopware\Core\Content\Media\Extension\ResolveRemoteThumbnailUrlExtension; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
#[AsEventListener(ResolveRemoteThumbnailUrlExtension::NAME . '.pre')] | ||
class RemoteThumbnailUrlExtensionSubscriber | ||
{ | ||
public function __construct( | ||
private readonly UrlGeneratorInterface $urlGenerator, | ||
) { | ||
} | ||
|
||
public function __invoke(ResolveRemoteThumbnailUrlExtension $extension): void | ||
{ | ||
$extension->stopPropagation(); | ||
|
||
$extension->result = $this->urlGenerator->generateUrl( | ||
$extension->mediaPath, | ||
new ImageProxyOptionDTO(width: $extension->width, height: $extension->height), | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Created by netlogix GmbH & Co. KG | ||
* | ||
* @copyright netlogix GmbH & Co. KG | ||
*/ | ||
|
||
namespace nlxShopwareImageProxy; | ||
|
||
use Shopware\Core\Framework\Plugin; | ||
|
||
class nlxShopwareImageProxy extends Plugin | ||
{ | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.