commonphp / di Goto Github PK
View Code? Open in Web Editor NEWLightweight and easy-to-use dependency injection library for PHP to simplify object management and promote loose coupling.
License: Other
Lightweight and easy-to-use dependency injection library for PHP to simplify object management and promote loose coupling.
License: Other
We are planning to better organize our codebase by creating clear separations of concern. As part of this, we intend to move all service-related tasks to a standalone library.
Current State:
Currently, service-related tasks such as managing service providers and service collections are spread across different parts of our codebase, including the Dependency Injector (DI). This mixing of responsibilities makes the code harder to understand and maintain.
Expected Changes:
Identify all service-related tasks currently present in the codebase.
Design and develop a new standalone Service Library to manage these tasks.
Refactor the existing code to delegate these tasks to the new Service Library.
Expected Benefits:
Clear separation of concerns, enhancing maintainability and understandability of the code.
Isolation of service-related tasks in a dedicated library will make it easier to extend and improve our service management functionality.
Future developers can easily locate and understand service-related tasks, speeding up the development process.
When using the instantiate
method from the DependencyInjector
class, the return object's class-specific methods are not readily available in the autocomplete suggestions of the IDE. This behavior may hinder the ease of use and speed of development for users of the library.
The goal of this issue is to improve type hinting in the instantiate
method. By using PHPDoc annotations that employ templates, we can provide better support for autocomplete features in IDEs. This way, developers will have access to method suggestions based on the specific class being instantiated, leading to a faster and more accurate code writing experience.
Please note that this change will not affect the actual functionality of the instantiate
method, but is intended to enhance the user experience for developers.
Consider splitting the DI and Service Container into separate libraries for better modularity and adherence to the Single Responsibility Principle.
Implement unit tests to validate the functionality of the libraries and to prevent regressions.
We should test the following:
Explore the use of Architectural Decision Records (ADRs) in the project to document the rationale behind design decisions.
In an effort to clearly delineate the responsibilities of the Dependency Injector (DI) and the Service Container, this issue aims to refactor the DI to remove all service-related tasks. The goal is to ensure that the DI focuses on its core function: analyzing dependencies and injecting them as needed.
Current State:
The DI currently has responsibilities that overlap with what should be part of the Service Container, such as managing service providers and service collections. This blurs the boundaries of the DI's responsibility and potentially makes the code harder to maintain and understand.
Expected Changes:
Move the management of service providers to the Service Container. Any method related to service providers in the DI should be relocated and refactored as necessary.
The DI's ServiceCollection should be refactored into a more general ObjectPool or equivalent that only deals with objects, not services.
Expected Benefits:
Clear separation of concerns between the DI and Service Container, enhancing maintainability.
Improved understandability of the code, as each class has a well-defined role.
Paves the way for enhancing and expanding the capabilities of the Service Container.
As part of an ongoing effort to make our codebase more understandable and accurate, we should refactor the CommonPHP\DependencyInjection\Collections namespace to CommonPHP\DependencyInjection\Support. This new naming more accurately represents the purpose of the classes within this namespace.
In the process, we should also move the InstantiationStack class to this newly named namespace.
Acceptance Criteria:
All references to classes in the CommonPHP\DependencyInjection\Collections namespace in the codebase should be updated to CommonPHP\DependencyInjection\Support
InstantiationStack should be moved to CommonPHP\DependencyInjection\Support\InstantiationStack, with all references updated accordingly.
Evaluate the Service Container's compliance with the PSR-11 standard. Make necessary modifications to ensure it meets the standard.
A recommendation was made to have a method available that allows a callback to be responsible for the creation of a specific class. This could technically be done by a service provider in the service-management library, however, that's better suited for a type of class (has interface, has attribute, etc) but is heavy impact performance-wise if it needs to iterate through multiple theoretical nested loops just to find the specific class name.
'delegate' would instruct the DI to use the provided callback for the instantiating of a class, which would pass class name, parameters and instance of the $DI as parameters
Create a CONTRIBUTING.md guide to help prospective contributors understand how they can help with the project.
Improve code comments and README to provide more clarity on how to use the library. Consider adding guides, examples, and API documentation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.