Download the PHP package picamator/object-manager without Composer
On this page you can find all versions of the php package picamator/object-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package object-manager
ObjectManager
Master
Dev
Object Manager is one class tool to build objects supplied with a Singleton wrapper and unit test stub helper.
The main usage are:
- refactoring legacy code with unit-testable style without break backwards compatibility
- having one place for creating new instances
Installation
Update to your composer.json
with:
Requirements
Examples
Legacy
Let's application has an UserRepository
:
The Connection
instance here was created inside constructor make it hard to mock for unit testing.
One of the solution to keep backward compatibility is using ObjectManagerSingleton
:
Inside unit test before running the test needs to stub ObjectManagerSingleton
with mock ObjectManagerSingleton::setInstance($mockObjectManager)
.
Having such is open the door for mocking Connection
class.
Please follow link to find example source and unit test for them.
Factory
Let's application has a ConnectionFactory
:
With ObjectManager
it can be rewritten to:
As a result it's possible to use Dependency Injection to override $className
with new implementation.
With PHP 7 features ConnectionFactory
would look like:
Please follow link to find example source and unit test for them.
Statistics
Suppose application needs to collect objects statistics without using any additional tools.
The solution might be ObjectManager
overriding with injection in development environment.
Please follow link to find example source and unit test for them.
Documentation
- UML class diagram
- Usage examples
Developing
To configure developing environment please:
- Follow Docker installation steps
- Run inside Docker container
composer install
Contribution
To start helping the project please review CONTRIBUTING.
License
ObjectManager is licensed under the MIT License. Please see the LICENSE file for details.