-
Notifications
You must be signed in to change notification settings - Fork 360
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
Enhancement: Allow creating ContainerBuilder
with definitions for default extensions
#732
Conversation
65ac7e3
to
9a38b6d
Compare
public static function withDefaultExtensions(): self | ||
{ | ||
$instance = new self(); | ||
|
||
foreach (self::defaultExtensions() as $id => $definition) { | ||
$instance->add($id, $definition); | ||
} | ||
|
||
return $instance; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can provide an extension point for people who want to
- add extensions
- override default extensions
<?php
declare(strict_types=1);
use Faker\Container;
use Faker\Extension;
use Faker\Generator;
require_once __DIR__ . '/../vendor/autoload.php';
$container = Container\ContainerBuilder::withDefaultExtensions()
->add(Extension\FileExtension::class, static function (): Extension\FileExtension {
return new CustomFileExtension();
})
->build();
$faker = new Generator($container);
This method is similar to the method simplified in #720, but returns the ContainerBuilder
instead of the built Container
.
public static function getDefault(): ContainerInterface | ||
{ | ||
return new Container(self::defaultExtensions()); | ||
return self::withDefaultExtensions()->build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably remove this method - I don't see any use for it (also see changes below).
One conflict to resolve, @localheinz Otherwise LGTM |
9a38b6d
to
4180f39
Compare
4180f39
to
fc6fbc2
Compare
Thank you, @bram-pkg! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fakerphp/faker](https://togithub.com/FakerPHP/Faker) | `1.23.0` -> `1.23.1` | [![age](https://developer.mend.io/api/mc/badges/age/packagist/fakerphp%2ffaker/1.23.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/fakerphp%2ffaker/1.23.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/fakerphp%2ffaker/1.23.0/1.23.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/fakerphp%2ffaker/1.23.0/1.23.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>FakerPHP/Faker (fakerphp/faker)</summary> ### [`v1.23.1`](https://togithub.com/FakerPHP/Faker/releases/tag/v1.23.1) [Compare Source](https://togithub.com/FakerPHP/Faker/compare/v1.23.0...v1.23.1) #### What's Changed - fix typos: "assymetric" -> asymmetric by [@​ivastly](https://togithub.com/ivastly) in [https://github.com/FakerPHP/Faker/pull/660](https://togithub.com/FakerPHP/Faker/pull/660) - Fix: lv_LV postcode format by [@​edgarsn](https://togithub.com/edgarsn) in [https://github.com/FakerPHP/Faker/pull/661](https://togithub.com/FakerPHP/Faker/pull/661) - composer(deps): bump vimeo/psalm from 5.12.0 to 5.13.1 in /vendor-bin/psalm by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/669](https://togithub.com/FakerPHP/Faker/pull/669) - composer(deps): bump rector/rector from 0.17.0 to 0.17.2 in /vendor-bin/rector by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/667](https://togithub.com/FakerPHP/Faker/pull/667) - composer(deps): bump phpstan/phpstan from 1.10.15 to 1.10.22 in /vendor-bin/phpstan by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/666](https://togithub.com/FakerPHP/Faker/pull/666) - composer(deps): bump friendsofphp/php-cs-fixer from 3.17.0 to 3.20.0 in /vendor-bin/php-cs-fixer by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/668](https://togithub.com/FakerPHP/Faker/pull/668) - Add `$format` to `image` DocBlock by [@​vintagesucks](https://togithub.com/vintagesucks) in [https://github.com/FakerPHP/Faker/pull/670](https://togithub.com/FakerPHP/Faker/pull/670) - Fix: lv_LV generating invalid personal identity numbers by [@​edgarsn](https://togithub.com/edgarsn) in [https://github.com/FakerPHP/Faker/pull/663](https://togithub.com/FakerPHP/Faker/pull/663) - Fix for polish street names + more polish TLDs by [@​tomaszklim](https://togithub.com/tomaszklim) in [https://github.com/FakerPHP/Faker/pull/664](https://togithub.com/FakerPHP/Faker/pull/664) - Fix psalm baseline in .gitattributes by [@​VincentLanglet](https://togithub.com/VincentLanglet) in [https://github.com/FakerPHP/Faker/pull/674](https://togithub.com/FakerPHP/Faker/pull/674) - composer(deps): bump rector/rector from 0.17.2 to 0.17.7 in /vendor-bin/rector by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/676](https://togithub.com/FakerPHP/Faker/pull/676) - composer(deps): bump phpstan/phpstan from 1.10.22 to 1.10.26 in /vendor-bin/phpstan by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/677](https://togithub.com/FakerPHP/Faker/pull/677) - composer(deps): bump friendsofphp/php-cs-fixer from 3.20.0 to 3.22.0 in /vendor-bin/php-cs-fixer by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/679](https://togithub.com/FakerPHP/Faker/pull/679) - composer(deps): bump vimeo/psalm from 5.13.1 to 5.14.1 in /vendor-bin/psalm by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/678](https://togithub.com/FakerPHP/Faker/pull/678) - chore: ensure php 8.3 compatibility by [@​Chris53897](https://togithub.com/Chris53897) in [https://github.com/FakerPHP/Faker/pull/684](https://togithub.com/FakerPHP/Faker/pull/684) - Remove invalid postcode pattern for France by [@​ker0x](https://togithub.com/ker0x) in [https://github.com/FakerPHP/Faker/pull/683](https://togithub.com/FakerPHP/Faker/pull/683) - Fix: Allow tests to fail on PHP 8.3 by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/693](https://togithub.com/FakerPHP/Faker/pull/693) - Fix: Test does not perform any assertions by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/695](https://togithub.com/FakerPHP/Faker/pull/695) - Fix: Operator by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/696](https://togithub.com/FakerPHP/Faker/pull/696) - Fix: Use boolean expressions by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/697](https://togithub.com/FakerPHP/Faker/pull/697) - composer(deps): bump rector/rector from 0.17.7 to 0.18.1 in /vendor-bin/rector by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/688](https://togithub.com/FakerPHP/Faker/pull/688) - composer(deps): bump phpstan/phpstan from 1.10.26 to 1.10.32 in /vendor-bin/phpstan by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/689](https://togithub.com/FakerPHP/Faker/pull/689) - composer(deps): bump vimeo/psalm from 5.14.1 to 5.15.0 in /vendor-bin/psalm by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/687](https://togithub.com/FakerPHP/Faker/pull/687) - composer(deps): bump phpstan/phpstan-deprecation-rules from 1.1.3 to 1.1.4 in /vendor-bin/phpstan by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/690](https://togithub.com/FakerPHP/Faker/pull/690) - composer(deps): bump friendsofphp/php-cs-fixer from 3.22.0 to 3.25.0 in /vendor-bin/php-cs-fixer by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/686](https://togithub.com/FakerPHP/Faker/pull/686) - Fix: Require to pass name to `ContainerBuilder::add()` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/702](https://togithub.com/FakerPHP/Faker/pull/702) - Enhancement: Run tests in random order by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/701](https://togithub.com/FakerPHP/Faker/pull/701) - Fix: Add property type declarations by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/699](https://togithub.com/FakerPHP/Faker/pull/699) - Fix: Enable and configure `type_declaration_spaces` instead of deprecated `function_typehint_space` fixer by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/698](https://togithub.com/FakerPHP/Faker/pull/698) - composer(deps): bump phpstan/phpstan from 1.10.32 to 1.10.33 in /vendor-bin/phpstan by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/704](https://togithub.com/FakerPHP/Faker/pull/704) - composer(deps): bump friendsofphp/php-cs-fixer from 3.25.0 to 3.25.1 in /vendor-bin/php-cs-fixer by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/705](https://togithub.com/FakerPHP/Faker/pull/705) - github-actions(deps): bump actions/checkout from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/FakerPHP/Faker/pull/706](https://togithub.com/FakerPHP/Faker/pull/706) - Fix: Switch order of parameters by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/703](https://togithub.com/FakerPHP/Faker/pull/703) - Fix: Remove unused method by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/711](https://togithub.com/FakerPHP/Faker/pull/711) - Fix: Rename parameter by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/707](https://togithub.com/FakerPHP/Faker/pull/707) - Fix: Add parameter type declaration by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/710](https://togithub.com/FakerPHP/Faker/pull/710) - Fix: Order by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/712](https://togithub.com/FakerPHP/Faker/pull/712) - Enhancement: Reuse `NumberExtension` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/715](https://togithub.com/FakerPHP/Faker/pull/715) - Fix: Methods are instance methods by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/708](https://togithub.com/FakerPHP/Faker/pull/708) - Fix: Add property type declarations by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/713](https://togithub.com/FakerPHP/Faker/pull/713) - Fix: Reduce visibility by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/714](https://togithub.com/FakerPHP/Faker/pull/714) - Fix: Do not memoize invalid service by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/709](https://togithub.com/FakerPHP/Faker/pull/709) - Fix: Consistently describe experimental status by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/717](https://togithub.com/FakerPHP/Faker/pull/717) - Fix: Mark classes as experimental by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/716](https://togithub.com/FakerPHP/Faker/pull/716) - Fix: Mark class as `final` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/718](https://togithub.com/FakerPHP/Faker/pull/718) - Fix: Return string by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/726](https://togithub.com/FakerPHP/Faker/pull/726) - Fix: Order by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/722](https://togithub.com/FakerPHP/Faker/pull/722) - Fix: Avoid unnecessary imports by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/721](https://togithub.com/FakerPHP/Faker/pull/721) - Enhancement: Enable `self_static_accessor` fixer by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/728](https://togithub.com/FakerPHP/Faker/pull/728) - Fix: Cache for `friendsofphp/php-cs-fixer` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/729](https://togithub.com/FakerPHP/Faker/pull/729) - Fix: Add parameter type declarations by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/724](https://togithub.com/FakerPHP/Faker/pull/724) - Fix: Add tests for `Container` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/727](https://togithub.com/FakerPHP/Faker/pull/727) - Fix: Simplify by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/720](https://togithub.com/FakerPHP/Faker/pull/720) - updated polish license plates by [@​scybulski](https://togithub.com/scybulski) in [https://github.com/FakerPHP/Faker/pull/685](https://togithub.com/FakerPHP/Faker/pull/685) - Fix: Update `CHANGELOG.md` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/734](https://togithub.com/FakerPHP/Faker/pull/734) - Fix: Avoid useless tests for `ContainerBuilder` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/730](https://togithub.com/FakerPHP/Faker/pull/730) - Fix: Rename parameter by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/731](https://togithub.com/FakerPHP/Faker/pull/731) - Add changelog mention in review checklist by [@​bram-pkg](https://togithub.com/bram-pkg) in [https://github.com/FakerPHP/Faker/pull/735](https://togithub.com/FakerPHP/Faker/pull/735) - Enhancement: Allow creating `ContainerBuilder` with definitions for default extensions by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/732](https://togithub.com/FakerPHP/Faker/pull/732) - Fix: Reduce visibility by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/719](https://togithub.com/FakerPHP/Faker/pull/719) - Fix: Remove unused method by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/736](https://togithub.com/FakerPHP/Faker/pull/736) - Enhancement: Add `SECURITY.md` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/739](https://togithub.com/FakerPHP/Faker/pull/739) - Fix: Do not use `static` in callables by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/785](https://togithub.com/FakerPHP/Faker/pull/785) - Fixed incorrect female name among male names ([#​794](https://togithub.com/FakerPHP/Faker/issues/794)) by [@​pimjansen](https://togithub.com/pimjansen) in [https://github.com/FakerPHP/Faker/pull/795](https://togithub.com/FakerPHP/Faker/pull/795) - Removed suppressed State from it_IT by [@​BoGnY](https://togithub.com/BoGnY) in [https://github.com/FakerPHP/Faker/pull/802](https://togithub.com/FakerPHP/Faker/pull/802) - Update Address.php to fix country name errors by [@​supgeek-rod](https://togithub.com/supgeek-rod) in [https://github.com/FakerPHP/Faker/pull/809](https://togithub.com/FakerPHP/Faker/pull/809) - fix [#​832](https://togithub.com/FakerPHP/Faker/issues/832) by [@​gam6itko](https://togithub.com/gam6itko) in [https://github.com/FakerPHP/Faker/pull/836](https://togithub.com/FakerPHP/Faker/pull/836) - Fix: Do not use deprecated `MT_RAND_PHP` constant on PHP 8.3 by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/844](https://togithub.com/FakerPHP/Faker/pull/844) - Enhancement: Prepare release for `1.23.1` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/788](https://togithub.com/FakerPHP/Faker/pull/788) - Fix: Remove branch alias for `1.23` by [@​localheinz](https://togithub.com/localheinz) in [https://github.com/FakerPHP/Faker/pull/843](https://togithub.com/FakerPHP/Faker/pull/843) #### New Contributors - [@​ivastly](https://togithub.com/ivastly) made their first contribution in [https://github.com/FakerPHP/Faker/pull/660](https://togithub.com/FakerPHP/Faker/pull/660) - [@​edgarsn](https://togithub.com/edgarsn) made their first contribution in [https://github.com/FakerPHP/Faker/pull/661](https://togithub.com/FakerPHP/Faker/pull/661) - [@​vintagesucks](https://togithub.com/vintagesucks) made their first contribution in [https://github.com/FakerPHP/Faker/pull/670](https://togithub.com/FakerPHP/Faker/pull/670) - [@​tomaszklim](https://togithub.com/tomaszklim) made their first contribution in [https://github.com/FakerPHP/Faker/pull/664](https://togithub.com/FakerPHP/Faker/pull/664) - [@​VincentLanglet](https://togithub.com/VincentLanglet) made their first contribution in [https://github.com/FakerPHP/Faker/pull/674](https://togithub.com/FakerPHP/Faker/pull/674) - [@​Chris53897](https://togithub.com/Chris53897) made their first contribution in [https://github.com/FakerPHP/Faker/pull/684](https://togithub.com/FakerPHP/Faker/pull/684) - [@​BoGnY](https://togithub.com/BoGnY) made their first contribution in [https://github.com/FakerPHP/Faker/pull/802](https://togithub.com/FakerPHP/Faker/pull/802) - [@​supgeek-rod](https://togithub.com/supgeek-rod) made their first contribution in [https://github.com/FakerPHP/Faker/pull/809](https://togithub.com/FakerPHP/Faker/pull/809) - [@​gam6itko](https://togithub.com/gam6itko) made their first contribution in [https://github.com/FakerPHP/Faker/pull/836](https://togithub.com/FakerPHP/Faker/pull/836) **Full Changelog**: FakerPHP/Faker@v1.23.0...v1.23.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/RadioRoster/backend). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMjEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEyMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
What is the reason for this PR?
ContainerBuilder
with definitions for default extensionsRelated to #719.
Author's checklist
Summary of changes
Review checklist