apie / service-provider-generator
Creates a service provider for Laravel from a Symfony services.yaml
Installs: 19 787
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- illuminate/support: 7.*|8.*|9.*|10.*
- symfony/dependency-injection: 6.*
- symfony/yaml: 6.*
Requires (Dev)
- phpunit/phpunit: 10.*
- symfony/finder: 6.*
README
ServiceProvider generator
This package is part of the Apie library.
Documentation
One issue with writing framework agnostic code is that most frameworks have different ways to register classes in their service container.
- The Symfony framework works with configuration files, attributes and autowiring.
- Laravel works with autowiring everything or writing PHP code in a ServiceProvider how to instantiate a specific service.
If we want our code to be framework agnostic we need a way to make sure we do not need maintain 2 'service container registries'.
That's where this library comes in. We use the Symfony yaml configuration files as basis and let it generate a ServiceProvider class that Laravel can use. That way we can make our library work effortlessly
Code usage
The class only creates a string with the source code, you have to manually store it in a file (recommended) or use the 'evil' eval() method.
<?php use Apie\ServiceProviderGenerator\ServiceProviderGenerator; $generator = new ServiceProviderGenerator(); file_put_contents('/src/ExampleServiceProvider.php', $generator->generateClass(App\ExampleServiceProvider::class, 'resources/config/example-service.yaml'));
Supported Symfony dependency injection features:
Here is a list of everything supported. Not much is supported, because a transition is not trivial or Laravel does not support it without hacks. For example private services do not exist in Laravel. Also some of these features are considered bad practices if you use them outside your application in your package, so are highly likely not to be implemented.