Download the PHP package purpleharmonie/dependency-injection without Composer
On this page you can find all versions of the php package purpleharmonie/dependency-injection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download purpleharmonie/dependency-injection
More information about purpleharmonie/dependency-injection
Files in purpleharmonie/dependency-injection
Package dependency-injection
Short Description Purple Container is a lightweight dependency injection container for managing class dependencies and performing dependency injection in PHP applications.
License MIT
Informations about the package dependency-injection
Purple Framework Documentation
Table of Contents
- Introduction
- Core Components
- Dependency Injection Container
- Kernel
- Service Management
- Event System
- Kernel Extensions
- Configuration Management
- Caching
- Service Discovery
- Compiler Passes
- Error Handling
Introduction
Purple is a comprehensive PHP framework designed to provide a robust foundation for building scalable and maintainable applications. It features a powerful dependency injection container, modular architecture, and various tools to enhance development productivity. Inspired by popular frameworks like Symfony but with its own unique features. It provides a flexible and extensible way to manage dependencies and services in PHP applications. NOTE STILL UNDER DEVELOPMENT BUT CAN BE USED IN APPLLICATIONS.
Installation
You can install PHP Container via Composer. Run the following command in your terminal:
Core Components
Dependency Injection Container
The heart of the Purple framework, managing service instantiation and dependencies.
Features:
- Service registration and retrieval
- Autowiring
- Lazy loading
- Scoped services (asGlobal, asShared)
- Aliasing
- Tagging
- Service decoration
- Middleware
Kernel
Manages the application's lifecycle and bootstraps the framework.
Features:
- Environment management
- Debug mode
-
Bundle registration and booting in using bundle registration, your set the $configDir path. the bunlde classes whould be organised in an array and with each class extending the bundle interface. Find an example bundles in the examples folder this is to cretae the bundle registry in the $config path. It loaded into services during kernel boot
- Container initialization
- Error handler setup
Service Management
Service Registration
set($id, $class)
: Register a servicealias($alias, $service)
: Create an alias for a serviceaddTag($id, $attributes)
: Tag a serviceConfiguring service visibility:
(asGlobal, asShared)asGlobal(true)
/asGlobal(true)
: Set service visibility. false by defaultasShared(true)
: Mark a service as shared (singleton)setLazy(true)
: Enable/disable lazy loading for a service
Service Configuration
addArgument($id, $argument)
: Add an argument to a service.arguments($id, array $arguments)
: Set all arguments for a serviceaddMethodCall($id, $method, $arguments)
: Add a method call to a servicefactory($id, $factory)
: Set a factory for a service. inline factorie are not cached and also only php not yamlimplements($name, $interface)
: Specify an interface implementationextends($id, $abstract)
: Set a service to extend anotherautowire($id)
: Enable autowiring for a service using type hintsannotwire($id)
: Enable autowiring for a service using annotation
New Methods
bindIf($abstract, $concrete)
: Conditionally bind a servicecallable($abstract, callable $factory)
: Register a service with a callable factory
Event System
Allows hooking into various points of the application lifecycle.
Features:
- Event dispatching
- Listener registration with priorities
Kernel Extensions
Modular way to extend and configure the kernel and container.
Features:
- Extension registration
- Container configuration through extensions
Configuration Management
- Environment-specific configurations
- Parameter management
- Configuration file loading (YAML, PHP)
- Support for .env files
- Programmatic service definition
Caching
- Service graph caching
- Cached container compilation
- Configurable cache type (Redis, file, memory)
- Cache size and eviction policy settings
Service Discovery
Automatic discovery and registration of services based on directory structure and namespaces.
Service Tracking
Monitors service usage and implements basic garbage collection:
- Tracks service usage frequency and last usage time
- Implements a configurable garbage collection mechanism
Compiler Passes
Custom logic for modifying container configuration before it's compiled. view usage examples below and the examples folder
Features:
- Priority-based execution
- Access to container for modifications
Error Handling
Customizable error handling and logging system.
This documentation provides an overview of the main features and components of the Purple framework. For detailed usage instructions and advanced configurations, please refer to the specific component documentation or code examples.
USAGE EXAMPLES
EventDispatcherInterface:
Defines methods for dispatching events and adding listeners. The example implementation allows adding listeners with priorities and dispatching events to all registered listeners.
KernelExtensionInterface:
Defines a load method that extensions use to configure the container. The example DatabaseExtension shows how you might set up a database connection service.
bindIf() usage:
Allows setting a default implementation that won't be overwritten if already defined. In the example, we set a FileLogger as the default, and a subsequent attempt to bind a ConsoleLogger doesn't overwrite it.
callable() usage:
Allows defining a service using a callable factory. In the example, we define a Mailer service that depends on other services from the container.
Decorator Usage
Alias Usage
The setAlias() method in Container now automatically sets the alias as public.
Middleware Usage
middleware interface