Skip to content

Commit e9e43fb

Browse files
committed
initial commit
0 parents  commit e9e43fb

File tree

16 files changed

+551
-0
lines changed

16 files changed

+551
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
.editorconfig export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
.php-cs-fixer.dist.php export-ignore
7+
phpstan.neon export-ignore
8+
phpunit.xml.dist export-ignore

.github/workflows/ci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Continuous Integration
2+
on: push
3+
4+
jobs:
5+
code-quality:
6+
name: Run code quality checks on PHP 8.0
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
dependency-version: [ '', '--prefer-lowest' ]
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '8.0'
20+
21+
- name: Install dependencies
22+
run: composer update ${{ matrix.dependency-version }} --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist
23+
24+
- name: Run PHPStan
25+
run: vendor/bin/phpstan analyze --error-format=github
26+
27+
- name: Run PHP CS Fixer
28+
run: vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run --diff
29+
30+
test:
31+
runs-on: ${{ matrix.os }}
32+
needs: code-quality
33+
timeout-minutes: 5
34+
strategy:
35+
fail-fast: true
36+
matrix:
37+
os: [ubuntu-latest, windows-latest]
38+
php: [8.0, 8.1, 8.2, 8.3]
39+
laravel: [9.*, 10.*, 11.*]
40+
stability: [prefer-lowest, prefer-stable]
41+
include:
42+
- laravel: 9.*
43+
testbench: 7.*
44+
carbon: ^2.63
45+
- laravel: 10.*
46+
testbench: 8.*
47+
carbon: ^2.63
48+
- laravel: 11.*
49+
testbench: 9.*
50+
carbon: ^2.63
51+
exclude:
52+
- laravel: 10.*
53+
php: 8.0
54+
- laravel: 11.*
55+
php: 8.0
56+
- laravel: 11.*
57+
php: 8.1
58+
59+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
60+
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v4
64+
65+
- name: Setup PHP
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: ${{ matrix.php }}
69+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
70+
coverage: none
71+
72+
- name: Setup problem matchers
73+
run: |
74+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
75+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
76+
77+
- name: Install dependencies
78+
run: |
79+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update
80+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
81+
82+
- name: Execute tests
83+
run: vendor/bin/phpunit

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/composer.lock
2+
/vendor
3+
.phpunit.result.cache
4+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
This file is part of Optimole Laravel Package.
5+
6+
(c) Optimole Team <[email protected]>
7+
8+
For the full copyright and license information, please view the LICENSE
9+
file that was distributed with this source code.
10+
EOF;
11+
12+
$finder = PhpCsFixer\Finder::create()
13+
->in([
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
])
17+
;
18+
19+
$config = new PhpCsFixer\Config();
20+
$config
21+
->setRiskyAllowed(true)
22+
->setRules([
23+
'@Symfony' => true,
24+
'@Symfony:risky' => true,
25+
'align_multiline_comment' => true,
26+
'array_syntax' => ['syntax' => 'short'],
27+
'blank_line_before_statement' => true,
28+
'combine_consecutive_issets' => true,
29+
'combine_consecutive_unsets' => true,
30+
'declare_strict_types' => true,
31+
// one should use PHPUnit methods to set up expected exception instead of annotations
32+
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp']],
33+
'explicit_string_variable' => true,
34+
'header_comment' => ['header' => $header],
35+
'heredoc_to_nowdoc' => true,
36+
'list_syntax' => ['syntax' => 'long'],
37+
'method_chaining_indentation' => false,
38+
'native_function_invocation' => false,
39+
'native_constant_invocation' => false,
40+
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
41+
'no_null_property_initialization' => true,
42+
'echo_tag_syntax' => ['format' => 'long'],
43+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => false],
44+
'no_unneeded_curly_braces' => true,
45+
'no_unneeded_final_method' => true,
46+
'no_unreachable_default_argument_value' => true,
47+
'no_useless_else' => true,
48+
'no_useless_return' => true,
49+
'ordered_class_elements' => [
50+
'order' => [
51+
'use_trait',
52+
'constant_public',
53+
'constant_protected',
54+
'constant_private',
55+
'property_public',
56+
'property_protected',
57+
'property_private',
58+
'construct',
59+
'destruct',
60+
'magic',
61+
'phpunit',
62+
'method_public_static',
63+
'method_protected_static',
64+
'method_private_static',
65+
'method_public',
66+
'method_public_abstract',
67+
'method_protected',
68+
'method_protected_abstract',
69+
'method_private',
70+
],
71+
'sort_algorithm' => 'alpha'
72+
],
73+
'ordered_imports' => true,
74+
'php_unit_construct' => true,
75+
'php_unit_method_casing' => ['case' => 'camel_case'],
76+
'php_unit_dedicate_assert' => true,
77+
'phpdoc_order' => true,
78+
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
79+
'semicolon_after_instruction' => true,
80+
'single_line_comment_style' => true,
81+
'yoda_style' => true,
82+
])
83+
->setFinder($finder)
84+
;
85+
86+
return $config;

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
phpunit.xml.distCopyright (c) Optimole Team
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "codeinwp/optimole-laravel",
3+
"description": "Integrate Optimole cloud-based image optimization service with your Laravel application",
4+
"homepage": "https://optimole.com",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Optimole Team",
9+
"email": "[email protected]",
10+
"homepage": "https://optimole.com"
11+
}
12+
],
13+
"support": {
14+
"issues": "https://github.com/Codeinwp/codeinwp/optimole-laravel/issues",
15+
"source": "https://github.com/Codeinwp/optimole-laravel"
16+
},
17+
"require": {
18+
"illuminate/support": "^9.0|^10.0|^11.0",
19+
"codeinwp/optimole-sdk": "^1.0"
20+
},
21+
"require-dev": {
22+
"friendsofphp/php-cs-fixer": "^3.0",
23+
"laravel/framework": "^9.0|^10.0|^11.0",
24+
"orchestra/testbench": "^7.0|^8.0|^9.0",
25+
"phpstan/phpstan": "^1.0"
26+
},
27+
"config": {
28+
"optimize-autoloader": true,
29+
"preferred-install": "dist",
30+
"sort-packages": true
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"Optimole\\Laravel\\": "src"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"Optimole\\Laravel\\Tests\\": "tests"
40+
}
41+
},
42+
"extra": {
43+
"laravel": {
44+
"providers": [
45+
"Optimole\\Laravel\\ServiceProvider"
46+
],
47+
"aliases": {
48+
"Optimole": "Optimole\\Laravel\\Facade"
49+
}
50+
}
51+
}
52+
}

config/optimole.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Optimole Laravel configuration file.
5+
*/
6+
return [
7+
'key' => env('OPTIMOLE_KEY'),
8+
9+
'base_domain' => env('OPTIMOLE_BASE_DOMAIN', 'i.optimole.com'),
10+
11+
'cache_buster' => env('OPTIMOLE_CACHE_BUSTER', ''),
12+
13+
'override_asset_helper' => env('OPTIMOLE_OVERRIDE_ASSET_HELPER', true),
14+
];

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src/

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<php>
13+
<server name="OPTIMOLE_KEY" value="optimole_key"/>
14+
</php>
15+
<testsuites>
16+
<testsuite name="integration">
17+
<directory suffix="Test.php">./tests/Integration</directory>
18+
</testsuite>
19+
</testsuites>
20+
</phpunit>

src/Facade.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Optimole Laravel Package.
7+
*
8+
* (c) Optimole Team <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Optimole\Laravel;
15+
16+
use Illuminate\Support\Facades\Facade as LaravelFacade;
17+
use Optimole\Sdk\Offload\Manager;
18+
use Optimole\Sdk\Optimole;
19+
use Optimole\Sdk\Resource\Asset;
20+
use Optimole\Sdk\Resource\Image;
21+
22+
/**
23+
* @method static Asset asset(string $assetUrl, string $cacheBuster = '')
24+
* @method static Image image(string $imageUrl, string $cacheBuster = '')
25+
* @method static Manager offload()
26+
*/
27+
class Facade extends LaravelFacade
28+
{
29+
/**
30+
* Get the registered name of the component.
31+
*
32+
* @return string
33+
*/
34+
protected static function getFacadeAccessor()
35+
{
36+
return Optimole::class;
37+
}
38+
}

0 commit comments

Comments
 (0)