create-berna-stencil 1.0.36 → 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_tools/res/templates/template.js +18 -22
- package/_tools/res/templates/template.njk +8 -8
- package/_tools/res/templates/template.scss +16 -16
- package/bin/create.js +1 -1
- package/package.json +70 -70
- package/src/404.njk +2 -2
- package/src/api/core/composer.lock +492 -492
- package/src/api/core/vendor/composer/autoload_static.php +10 -10
- package/src/api/core/vendor/composer/installed.json +6 -6
- package/src/api/core/vendor/composer/installed.php +2 -2
- package/src/api/core/vendor/graham-campbell/result-type/LICENSE +21 -21
- package/src/api/core/vendor/graham-campbell/result-type/composer.json +33 -33
- package/src/api/core/vendor/graham-campbell/result-type/src/Error.php +121 -121
- package/src/api/core/vendor/graham-campbell/result-type/src/Result.php +69 -69
- package/src/api/core/vendor/graham-campbell/result-type/src/Success.php +120 -120
- package/src/api/core/vendor/phpoption/phpoption/LICENSE +200 -200
- package/src/api/core/vendor/phpoption/phpoption/composer.json +50 -50
- package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/LazyOption.php +175 -175
- package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/None.php +136 -136
- package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/Option.php +434 -434
- package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/Some.php +169 -169
- package/src/api/core/vendor/symfony/polyfill-ctype/Ctype.php +232 -232
- package/src/api/core/vendor/symfony/polyfill-ctype/LICENSE +19 -19
- package/src/api/core/vendor/symfony/polyfill-ctype/README.md +12 -12
- package/src/api/core/vendor/symfony/polyfill-ctype/bootstrap.php +50 -50
- package/src/api/core/vendor/symfony/polyfill-ctype/bootstrap80.php +46 -46
- package/src/api/core/vendor/symfony/polyfill-ctype/composer.json +38 -38
- package/src/api/core/vendor/symfony/polyfill-mbstring/LICENSE +19 -19
- package/src/api/core/vendor/symfony/polyfill-mbstring/Mbstring.php +1077 -1077
- package/src/api/core/vendor/symfony/polyfill-mbstring/README.md +13 -13
- package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/caseFolding.php +119 -119
- package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php +1397 -1397
- package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php +5 -5
- package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/upperCase.php +1489 -1489
- package/src/api/core/vendor/symfony/polyfill-mbstring/bootstrap.php +171 -171
- package/src/api/core/vendor/symfony/polyfill-mbstring/bootstrap80.php +167 -167
- package/src/api/core/vendor/symfony/polyfill-mbstring/composer.json +39 -39
- package/src/api/core/vendor/symfony/polyfill-php80/LICENSE +19 -19
- package/src/api/core/vendor/symfony/polyfill-php80/Php80.php +115 -115
- package/src/api/core/vendor/symfony/polyfill-php80/PhpToken.php +106 -106
- package/src/api/core/vendor/symfony/polyfill-php80/README.md +25 -25
- package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/Attribute.php +31 -31
- package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/PhpToken.php +16 -16
- package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php +20 -20
- package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php +16 -16
- package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/ValueError.php +16 -16
- package/src/api/core/vendor/symfony/polyfill-php80/bootstrap.php +42 -42
- package/src/api/core/vendor/symfony/polyfill-php80/composer.json +37 -37
- package/src/api/core/vendor/vlucas/phpdotenv/LICENSE +30 -30
- package/src/api/core/vendor/vlucas/phpdotenv/composer.json +60 -60
- package/src/api/core/vendor/vlucas/phpdotenv/src/Dotenv.php +267 -267
- package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/ExceptionInterface.php +12 -12
- package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidEncodingException.php +12 -12
- package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidFileException.php +12 -12
- package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidPathException.php +12 -12
- package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/ValidationException.php +12 -12
- package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/Loader.php +48 -48
- package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php +20 -20
- package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/Resolver.php +65 -65
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Entry.php +59 -59
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/EntryParser.php +299 -299
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Lexer.php +58 -58
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Lines.php +127 -127
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Parser.php +53 -53
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/ParserInterface.php +19 -19
- package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Value.php +88 -88
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php +15 -15
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ApacheAdapter.php +89 -89
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ArrayAdapter.php +80 -80
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/EnvConstAdapter.php +88 -88
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/GuardedWriter.php +85 -85
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php +110 -110
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php +48 -48
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php +64 -64
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/PutenvAdapter.php +91 -91
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReaderInterface.php +17 -17
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReplacingWriter.php +104 -104
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ServerConstAdapter.php +88 -88
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/WriterInterface.php +27 -27
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/AdapterRepository.php +107 -107
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php +272 -272
- package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/RepositoryInterface.php +51 -51
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/File/Paths.php +44 -44
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/File/Reader.php +81 -81
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/FileStore.php +72 -72
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php +141 -141
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StoreInterface.php +17 -17
- package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StringStore.php +37 -37
- package/src/api/core/vendor/vlucas/phpdotenv/src/Util/Regex.php +112 -112
- package/src/api/core/vendor/vlucas/phpdotenv/src/Util/Str.php +108 -108
- package/src/api/core/vendor/vlucas/phpdotenv/src/Validator.php +207 -207
- package/src/components/global/header.njk +2 -6
- package/src/components/welcome.njk +8 -13
- package/src/data/site.json +43 -43
- package/src/js/pages/404.js +0 -3
- package/src/js/pages/homepage.js +0 -6
- package/src/api/core/vendor/graham-campbell/result-type/.gitattributes +0 -9
- package/src/api/core/vendor/graham-campbell/result-type/.github/CODE_OF_CONDUCT.md +0 -132
- package/src/api/core/vendor/graham-campbell/result-type/.github/CONTRIBUTING.md +0 -31
- package/src/api/core/vendor/graham-campbell/result-type/.github/FUNDING.yml +0 -2
- package/src/api/core/vendor/graham-campbell/result-type/.github/SECURITY.md +0 -14
- package/src/api/core/vendor/graham-campbell/result-type/.github/workflows/stale.yml +0 -11
- package/src/api/core/vendor/graham-campbell/result-type/.github/workflows/tests.yml +0 -40
- package/src/api/core/vendor/graham-campbell/result-type/CHANGELOG.md +0 -53
- package/src/api/core/vendor/graham-campbell/result-type/README.md +0 -42
- package/src/api/core/vendor/graham-campbell/result-type/phpunit.xml.dist +0 -13
- package/src/api/core/vendor/graham-campbell/result-type/tests/ResultTest.php +0 -95
- package/src/api/core/vendor/phpoption/phpoption/.gitattributes +0 -13
- package/src/api/core/vendor/phpoption/phpoption/.github/CODE_OF_CONDUCT.md +0 -132
- package/src/api/core/vendor/phpoption/phpoption/.github/CONTRIBUTING.md +0 -30
- package/src/api/core/vendor/phpoption/phpoption/.github/FUNDING.yml +0 -2
- package/src/api/core/vendor/phpoption/phpoption/.github/SECURITY.md +0 -14
- package/src/api/core/vendor/phpoption/phpoption/.github/workflows/static.yml +0 -40
- package/src/api/core/vendor/phpoption/phpoption/.github/workflows/tests.yml +0 -40
- package/src/api/core/vendor/phpoption/phpoption/Makefile +0 -17
- package/src/api/core/vendor/phpoption/phpoption/README.md +0 -201
- package/src/api/core/vendor/phpoption/phpoption/phpstan-baseline.neon +0 -44
- package/src/api/core/vendor/phpoption/phpoption/phpstan.neon.dist +0 -7
- package/src/api/core/vendor/phpoption/phpoption/phpunit.xml.dist +0 -13
- package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/EnsureTest.php +0 -72
- package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/LazyOptionTest.php +0 -357
- package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/NoneTest.php +0 -153
- package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/OptionTest.php +0 -166
- package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/SomeTest.php +0 -194
- package/src/api/core/vendor/phpoption/phpoption/tests/bootstrap.php +0 -8
- package/src/api/core/vendor/phpoption/phpoption/vendor-bin/phpstan/composer.json +0 -8
- package/src/api/core/vendor/vlucas/phpdotenv/.editorconfig +0 -15
- package/src/api/core/vendor/vlucas/phpdotenv/.gitattributes +0 -15
- package/src/api/core/vendor/vlucas/phpdotenv/.github/CODE_OF_CONDUCT.md +0 -132
- package/src/api/core/vendor/vlucas/phpdotenv/.github/CONTRIBUTING.md +0 -30
- package/src/api/core/vendor/vlucas/phpdotenv/.github/FUNDING.yml +0 -2
- package/src/api/core/vendor/vlucas/phpdotenv/.github/SECURITY.md +0 -14
- package/src/api/core/vendor/vlucas/phpdotenv/.github/workflows/static.yml +0 -40
- package/src/api/core/vendor/vlucas/phpdotenv/.github/workflows/tests.yml +0 -70
- package/src/api/core/vendor/vlucas/phpdotenv/Makefile +0 -17
- package/src/api/core/vendor/vlucas/phpdotenv/README.md +0 -370
- package/src/api/core/vendor/vlucas/phpdotenv/UPGRADING.md +0 -196
- package/src/api/core/vendor/vlucas/phpdotenv/phpstan-baseline.neon +0 -157
- package/src/api/core/vendor/vlucas/phpdotenv/phpstan.neon.dist +0 -7
- package/src/api/core/vendor/vlucas/phpdotenv/phpunit.xml.dist +0 -13
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/DotenvTest.php +0 -387
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Loader/LoaderTest.php +0 -86
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/EntryParserTest.php +0 -234
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/LexerTest.php +0 -40
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/LinesTest.php +0 -53
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/ParserTest.php +0 -98
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/ArrayAdapterTest.php +0 -57
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/EnvConstAdapterTest.php +0 -75
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/PutenvAdapterTest.php +0 -52
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/ServerConstAdapterTest.php +0 -75
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/RepositoryTest.php +0 -305
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Store/StoreTest.php +0 -141
- package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/ValidatorTest.php +0 -479
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/.env +0 -5
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/assertions.env +0 -18
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/booleans.env +0 -33
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/commented.env +0 -15
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/empty.env +0 -1
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/example.env +0 -1
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/exported.env +0 -7
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/immutable.env +0 -1
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/integers.env +0 -17
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/large.env +0 -2
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multibyte.env +0 -3
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multiline.env +0 -14
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multiple.env +0 -4
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/mutable.env +0 -1
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/nested.env +0 -15
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/quoted.env +0 -11
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/specialchars.env +0 -8
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/unicodevarnames.env +0 -2
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/utf8-with-bom-encoding.env +0 -3
- package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/windows.env +0 -1
- package/src/api/core/vendor/vlucas/phpdotenv/vendor-bin/phpstan/composer.json +0 -15
- package/src/data/lang.json +0 -36
- package/src/js/modules/forms/form.js +0 -45
- package/src/js/modules/langSwitcher.js +0 -69
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
name: Static Analysis
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
pull_request:
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
phpstan:
|
|
9
|
-
name: PHPStan
|
|
10
|
-
runs-on: ubuntu-24.04
|
|
11
|
-
|
|
12
|
-
steps:
|
|
13
|
-
- name: Checkout code
|
|
14
|
-
uses: actions/checkout@v6
|
|
15
|
-
|
|
16
|
-
- name: Setup PHP
|
|
17
|
-
uses: shivammathur/setup-php@v2
|
|
18
|
-
with:
|
|
19
|
-
php-version: '8.5'
|
|
20
|
-
tools: composer:v2
|
|
21
|
-
coverage: none
|
|
22
|
-
env:
|
|
23
|
-
update: true
|
|
24
|
-
|
|
25
|
-
- name: Install Dependencies
|
|
26
|
-
uses: nick-invision/retry@v3
|
|
27
|
-
with:
|
|
28
|
-
timeout_minutes: 5
|
|
29
|
-
max_attempts: 5
|
|
30
|
-
command: composer update --no-interaction --no-progress
|
|
31
|
-
|
|
32
|
-
- name: Install PHPStan
|
|
33
|
-
uses: nick-invision/retry@v3
|
|
34
|
-
with:
|
|
35
|
-
timeout_minutes: 5
|
|
36
|
-
max_attempts: 5
|
|
37
|
-
command: composer bin phpstan update --no-interaction --no-progress
|
|
38
|
-
|
|
39
|
-
- name: Execute PHPStan
|
|
40
|
-
run: vendor/bin/phpstan analyze --no-progress
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
name: Tests
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
pull_request:
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
tests:
|
|
9
|
-
name: PHP ${{ matrix.php }}
|
|
10
|
-
runs-on: ubuntu-24.04
|
|
11
|
-
|
|
12
|
-
strategy:
|
|
13
|
-
matrix:
|
|
14
|
-
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
|
|
15
|
-
|
|
16
|
-
steps:
|
|
17
|
-
- name: Checkout Code
|
|
18
|
-
uses: actions/checkout@v6
|
|
19
|
-
|
|
20
|
-
- name: Setup PHP
|
|
21
|
-
uses: shivammathur/setup-php@v2
|
|
22
|
-
with:
|
|
23
|
-
php-version: ${{ matrix.php }}
|
|
24
|
-
tools: composer:v2
|
|
25
|
-
coverage: none
|
|
26
|
-
env:
|
|
27
|
-
update: true
|
|
28
|
-
|
|
29
|
-
- name: Setup Problem Matchers
|
|
30
|
-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
|
31
|
-
|
|
32
|
-
- name: Install PHP Dependencies
|
|
33
|
-
uses: nick-invision/retry@v3
|
|
34
|
-
with:
|
|
35
|
-
timeout_minutes: 5
|
|
36
|
-
max_attempts: 5
|
|
37
|
-
command: composer update --no-interaction --no-progress
|
|
38
|
-
|
|
39
|
-
- name: Execute PHPUnit
|
|
40
|
-
run: vendor/bin/phpunit
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
install:
|
|
2
|
-
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.5-base update
|
|
3
|
-
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.5-base bin all update
|
|
4
|
-
|
|
5
|
-
phpunit:
|
|
6
|
-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.5-cli
|
|
7
|
-
|
|
8
|
-
phpstan-analyze:
|
|
9
|
-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.5-cli analyze
|
|
10
|
-
|
|
11
|
-
phpstan-baseline:
|
|
12
|
-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.5-cli analyze --generate-baseline
|
|
13
|
-
|
|
14
|
-
test: phpunit phpstan-analyze
|
|
15
|
-
|
|
16
|
-
clean:
|
|
17
|
-
@rm -rf .phpunit.result.cache composer.lock vendor vendor-bin/*/composer.lock vendor-bin/*/vendor
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# PHP Option Type
|
|
2
|
-
|
|
3
|
-
This package implements the Option type for PHP!
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg?style=flat-square" alt="Software License"></img></a>
|
|
9
|
-
<a href="https://packagist.org/packages/phpoption/phpoption"><img src="https://img.shields.io/packagist/dt/phpoption/phpoption.svg?style=flat-square" alt="Total Downloads"></img></a>
|
|
10
|
-
<a href="https://github.com/schmittjoh/php-option/releases"><img src="https://img.shields.io/github/release/schmittjoh/php-option.svg?style=flat-square" alt="Latest Version"></img></a>
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
<div align="center">
|
|
14
|
-
|
|
15
|
-
**Special thanks to [our sponsors](https://github.com/sponsors/GrahamCampbell)**
|
|
16
|
-
|
|
17
|
-
<hr>
|
|
18
|
-
</div>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## Motivation
|
|
22
|
-
|
|
23
|
-
The Option type is intended for cases where you sometimes might return a value
|
|
24
|
-
(typically an object), and sometimes you might return a base value (typically
|
|
25
|
-
null) depending on arguments, or other runtime factors.
|
|
26
|
-
|
|
27
|
-
Often times, you forget to handle the case where a base value should be
|
|
28
|
-
returned. Not intentionally of course, but maybe you did not account for all
|
|
29
|
-
possible states of the system; or maybe you indeed covered all cases, then time
|
|
30
|
-
goes on, code is refactored, some of these your checks might become invalid, or
|
|
31
|
-
incomplete. Suddenly, without noticing, the base value case is not handled
|
|
32
|
-
anymore. As a result, you might sometimes get fatal PHP errors telling you that
|
|
33
|
-
you called a method on a non-object; users might see blank pages, or worse.
|
|
34
|
-
|
|
35
|
-
On one hand, the Option type forces a developer to consciously think about both
|
|
36
|
-
cases (returning a value, or returning a base value). That in itself will
|
|
37
|
-
already make your code more robust. On the other hand, the Option type also
|
|
38
|
-
allows the API developer to provide more concise API methods, and empowers the
|
|
39
|
-
API user in how he consumes these methods.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Installation
|
|
43
|
-
|
|
44
|
-
Installation is super-easy via [Composer](https://getcomposer.org/):
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
$ composer require phpoption/phpoption
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
or add it by hand to your `composer.json` file.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## Usage
|
|
54
|
-
|
|
55
|
-
### Using the Option Type in your API
|
|
56
|
-
|
|
57
|
-
```php
|
|
58
|
-
class MyRepository
|
|
59
|
-
{
|
|
60
|
-
public function findSomeEntity($criteria): \PhpOption\Option
|
|
61
|
-
{
|
|
62
|
-
if (null !== $entity = $this->em->find(...)) {
|
|
63
|
-
return new \PhpOption\Some($entity);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// We use a singleton, for the None case.
|
|
67
|
-
return \PhpOption\None::create();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
If you are consuming an existing library, you can also use a shorter version
|
|
73
|
-
which by default treats `null` as `None`, and everything else as `Some` case:
|
|
74
|
-
|
|
75
|
-
```php
|
|
76
|
-
class MyRepository
|
|
77
|
-
{
|
|
78
|
-
public function findSomeEntity($criteria): \PhpOption\Option
|
|
79
|
-
{
|
|
80
|
-
return \PhpOption\Option::fromValue($this->em->find(...));
|
|
81
|
-
|
|
82
|
-
// or, if you want to change the none value to false for example:
|
|
83
|
-
return \PhpOption\Option::fromValue($this->em->find(...), false);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Case 1: You always Require an Entity in Calling Code
|
|
89
|
-
|
|
90
|
-
```php
|
|
91
|
-
$entity = $repo->findSomeEntity(...)->get(); // returns entity, or throws exception
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Case 2: Fallback to Default Value If Not Available
|
|
95
|
-
|
|
96
|
-
```php
|
|
97
|
-
$entity = $repo->findSomeEntity(...)->getOrElse(new Entity());
|
|
98
|
-
|
|
99
|
-
// Or, if you want to lazily create the entity.
|
|
100
|
-
$entity = $repo->findSomeEntity(...)->getOrCall(function() {
|
|
101
|
-
return new Entity();
|
|
102
|
-
});
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## More Examples
|
|
106
|
-
|
|
107
|
-
### No More Boiler Plate Code
|
|
108
|
-
|
|
109
|
-
```php
|
|
110
|
-
// Before
|
|
111
|
-
$entity = $this->findSomeEntity();
|
|
112
|
-
if (null === $entity) {
|
|
113
|
-
throw new NotFoundException();
|
|
114
|
-
}
|
|
115
|
-
echo $entity->name;
|
|
116
|
-
|
|
117
|
-
// After
|
|
118
|
-
echo $this->findSomeEntity()->get()->name;
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### No More Control Flow Exceptions
|
|
122
|
-
|
|
123
|
-
```php
|
|
124
|
-
// Before
|
|
125
|
-
try {
|
|
126
|
-
$entity = $this->findSomeEntity();
|
|
127
|
-
} catch (NotFoundException $ex) {
|
|
128
|
-
$entity = new Entity();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// After
|
|
132
|
-
$entity = $this->findSomeEntity()->getOrElse(new Entity());
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### More Concise Null Handling
|
|
136
|
-
|
|
137
|
-
```php
|
|
138
|
-
// Before
|
|
139
|
-
$entity = $this->findSomeEntity();
|
|
140
|
-
if (null === $entity) {
|
|
141
|
-
return new Entity();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return $entity;
|
|
145
|
-
|
|
146
|
-
// After
|
|
147
|
-
return $this->findSomeEntity()->getOrElse(new Entity());
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Trying Multiple Alternative Options
|
|
151
|
-
|
|
152
|
-
If you'd like to try multiple alternatives, the `orElse` method allows you to
|
|
153
|
-
do this very elegantly:
|
|
154
|
-
|
|
155
|
-
```php
|
|
156
|
-
return $this->findSomeEntity()
|
|
157
|
-
->orElse($this->findSomeOtherEntity())
|
|
158
|
-
->orElse($this->createEntity());
|
|
159
|
-
```
|
|
160
|
-
The first option which is non-empty will be returned. This is especially useful
|
|
161
|
-
with lazy-evaluated options, see below.
|
|
162
|
-
|
|
163
|
-
### Lazy-Evaluated Options
|
|
164
|
-
|
|
165
|
-
The above example has the flaw that we would need to evaluate all options when
|
|
166
|
-
the method is called which creates unnecessary overhead if the first option is
|
|
167
|
-
already non-empty.
|
|
168
|
-
|
|
169
|
-
Fortunately, we can easily solve this by using the `LazyOption` class:
|
|
170
|
-
|
|
171
|
-
```php
|
|
172
|
-
return $this->findSomeEntity()
|
|
173
|
-
->orElse(new LazyOption(array($this, 'findSomeOtherEntity')))
|
|
174
|
-
->orElse(new LazyOption(array($this, 'createEntity')));
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
This way, only the options that are necessary will actually be evaluated.
|
|
178
|
-
|
|
179
|
-
## Performance Considerations
|
|
180
|
-
|
|
181
|
-
Of course, performance is important. Attached is a performance benchmark which
|
|
182
|
-
you can run on a machine of your choosing. The overhead incurred by the Option
|
|
183
|
-
type comes down to the time that it takes to create one object, our wrapper,
|
|
184
|
-
and one additional method call to retrieve the value from the wrapper. Unless
|
|
185
|
-
you plan to call a method thousands of times during a request, there is no
|
|
186
|
-
reason to stick to the `object|null` return value; better give your code some
|
|
187
|
-
options!
|
|
188
|
-
|
|
189
|
-
## Security
|
|
190
|
-
|
|
191
|
-
If you discover a security vulnerability within this package, please send an email to security@tidelift.com. All security vulnerabilities will be promptly addressed. You may view our full security policy [here](https://github.com/schmittjoh/php-option/security/policy).
|
|
192
|
-
|
|
193
|
-
## License
|
|
194
|
-
|
|
195
|
-
PHP Option Type is licensed under [Apache License 2.0](LICENSE).
|
|
196
|
-
|
|
197
|
-
## For Enterprise
|
|
198
|
-
|
|
199
|
-
Available as part of the Tidelift Subscription
|
|
200
|
-
|
|
201
|
-
The maintainers of `phpoption/phpoption` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-phpoption-phpoption?utm_source=packagist-phpoption-phpoption&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
parameters:
|
|
2
|
-
ignoreErrors:
|
|
3
|
-
-
|
|
4
|
-
message: '#^Call to function is_callable\(\) with callable\(mixed \.\.\.\)\: PhpOption\\Option\<T\> will always evaluate to true\.$#'
|
|
5
|
-
identifier: function.alreadyNarrowedType
|
|
6
|
-
count: 1
|
|
7
|
-
path: src/PhpOption/LazyOption.php
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
message: '#^Method PhpOption\\Option\:\:ensure\(\) should return PhpOption\\Option\<S\> but returns PhpOption\\LazyOption\<mixed\>\.$#'
|
|
11
|
-
identifier: return.type
|
|
12
|
-
count: 1
|
|
13
|
-
path: src/PhpOption/Option.php
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
message: '#^Method PhpOption\\Option\:\:fromReturn\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
|
|
17
|
-
identifier: missingType.iterableValue
|
|
18
|
-
count: 1
|
|
19
|
-
path: src/PhpOption/Option.php
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
message: '#^Method PhpOption\\Option\:\:fromReturn\(\) should return PhpOption\\LazyOption\<S\> but returns PhpOption\\LazyOption\<mixed\>\.$#'
|
|
23
|
-
identifier: return.type
|
|
24
|
-
count: 1
|
|
25
|
-
path: src/PhpOption/Option.php
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
message: '#^Parameter \#1 \$callback of function array_map expects \(callable\(mixed\)\: mixed\)\|null, Closure\(PhpOption\\Option\)\: T given\.$#'
|
|
29
|
-
identifier: argument.type
|
|
30
|
-
count: 1
|
|
31
|
-
path: src/PhpOption/Option.php
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(bool\|TReturn, mixed\)\: \(bool\|TReturn\), Closure\(mixed, PhpOption\\Option\)\: \(bool\|TReturn\) given\.$#'
|
|
35
|
-
identifier: argument.type
|
|
36
|
-
count: 1
|
|
37
|
-
path: src/PhpOption/Option.php
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
message: '#^Template type S of method PhpOption\\Option\:\:lift\(\) is not referenced in a parameter\.$#'
|
|
41
|
-
identifier: method.templateTypeNotInParameter
|
|
42
|
-
count: 1
|
|
43
|
-
path: src/PhpOption/Option.php
|
|
44
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="tests/bootstrap.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd">
|
|
3
|
-
<testsuites>
|
|
4
|
-
<testsuite name="PhpOption Type Test Suite">
|
|
5
|
-
<directory>./tests/PhpOption/</directory>
|
|
6
|
-
</testsuite>
|
|
7
|
-
</testsuites>
|
|
8
|
-
<groups>
|
|
9
|
-
<exclude>
|
|
10
|
-
<group>performance</group>
|
|
11
|
-
</exclude>
|
|
12
|
-
</groups>
|
|
13
|
-
</phpunit>
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
namespace PhpOption\Tests;
|
|
4
|
-
|
|
5
|
-
use PhpOption\None;
|
|
6
|
-
use PhpOption\Option;
|
|
7
|
-
use PhpOption\Some;
|
|
8
|
-
use PHPUnit\Framework\TestCase;
|
|
9
|
-
|
|
10
|
-
class EnsureTest extends TestCase
|
|
11
|
-
{
|
|
12
|
-
private static function ensure($value, $noneValue = null): Option
|
|
13
|
-
{
|
|
14
|
-
$option = Option::ensure($value, $noneValue);
|
|
15
|
-
self::assertInstanceOf(Option::class, $option);
|
|
16
|
-
|
|
17
|
-
return $option;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public function testMixedValue(): void
|
|
21
|
-
{
|
|
22
|
-
$option = self::ensure(1);
|
|
23
|
-
self::assertTrue($option->isDefined());
|
|
24
|
-
self::assertSame(1, $option->get());
|
|
25
|
-
self::assertFalse(self::ensure(null)->isDefined());
|
|
26
|
-
self::assertFalse(self::ensure(1, 1)->isDefined());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public function testReturnValue(): void
|
|
30
|
-
{
|
|
31
|
-
$option = self::ensure(function () {
|
|
32
|
-
return 1;
|
|
33
|
-
});
|
|
34
|
-
self::assertTrue($option->isDefined());
|
|
35
|
-
self::assertSame(1, $option->get());
|
|
36
|
-
self::assertFalse(self::ensure(function () {
|
|
37
|
-
})->isDefined());
|
|
38
|
-
self::assertFalse(self::ensure(function () {
|
|
39
|
-
return 1;
|
|
40
|
-
}, 1)->isDefined());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public function testOptionReturnsAsSameInstance(): void
|
|
44
|
-
{
|
|
45
|
-
$option = self::ensure(1);
|
|
46
|
-
self::assertSame($option, self::ensure($option));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public function testOptionReturnedFromClosure(): void
|
|
50
|
-
{
|
|
51
|
-
$option = self::ensure(function () {
|
|
52
|
-
return Some::create(1);
|
|
53
|
-
});
|
|
54
|
-
self::assertTrue($option->isDefined());
|
|
55
|
-
self::assertSame(1, $option->get());
|
|
56
|
-
|
|
57
|
-
$option = self::ensure(function () {
|
|
58
|
-
return None::create();
|
|
59
|
-
});
|
|
60
|
-
self::assertFalse($option->isDefined());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public function testClosureReturnedFromClosure(): void
|
|
64
|
-
{
|
|
65
|
-
$option = self::ensure(function () {
|
|
66
|
-
return function () {
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
self::assertTrue($option->isDefined());
|
|
70
|
-
self::assertInstanceOf('Closure', $option->get());
|
|
71
|
-
}
|
|
72
|
-
}
|