Download the PHP package vaibhavpandeyvpz/katora without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/katora. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/katora
More information about vaibhavpandeyvpz/katora
Files in vaibhavpandeyvpz/katora
Package katora
Short Description Simple service container implementing PSR-11 for PHP >= 8.2.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/katora
Informations about the package katora
Katora
Simple, lightweight service container implementing PSR-11 for PHP 8.2+.
Katora (
कटोरा) means "Bowl" in Hindi - a container that holds things together.
Features
- ✅ PSR-11 Compliant - Full implementation of the ContainerInterface standard
- ✅ Lazy Resolution - Services defined as callables are resolved only when accessed
- ✅ Singleton Support - Built-in
share()method for singleton pattern - ✅ Service Providers - Modular service registration via providers
- ✅ Multiple Access Patterns - Use methods, array access, or property access
- ✅ Type Safe - Full PHP 8.2+ type hints and return types
- ✅ 100% Test Coverage - Comprehensive test suite with full coverage
- ✅ Zero Dependencies - Only requires PSR-11 interface (no other dependencies)
Installation
Install via Composer:
Quick Start
Usage
Basic Operations
Setting Services
Getting Services
Multiple Access Patterns
Lazy Service Resolution
Services defined as callables are automatically resolved when accessed:
Singleton Pattern
Use share() to ensure a service is resolved only once:
Raw Callables
Prevent automatic resolution when you need to store a callable as a value:
Service Providers
Organize service registration with providers:
Constructor Initialization
You can pre-populate the container:
Method Chaining
Most methods return $this for fluent interfaces:
Container-Aware Classes
Use the HasContainer trait to make classes container-aware:
API Reference
Container
__construct(array $entries = [])
Creates a new container instance, optionally with initial entries.
get(string $id): mixed
Retrieves a service from the container. Throws NotFoundException if the service doesn't exist.
Throws: NotFoundException
has(string $id): bool
Checks if a service exists in the container.
set(string $id, mixed $entry): static
Registers a service in the container. Returns $this for method chaining.
install(ServiceProviderInterface $provider): static
Installs a service provider. Returns $this for method chaining.
share(callable $entry): callable
Wraps a callable to ensure it's only resolved once (singleton pattern).
raw(callable $entry): callable
Wraps a callable to prevent automatic resolution when retrieved.
Exceptions
ContainerException
Base exception for container-related errors. Extends InvalidArgumentException and implements ContainerExceptionInterface.
NotFoundException
Thrown when a requested service is not found. Extends ContainerException and implements NotFoundExceptionInterface.
Interfaces
ServiceProviderInterface
Interface for service providers. Implement this to create modular service registration.
Methods:
provide(Container $container): void- Registers services with the container
KeepsContainer
Interface for container-aware classes. Use with the HasContainer trait.
Methods:
getContainer(): ?ContainerInterface- Gets the container instancesetContainer(ContainerInterface $container): void- Sets the container instance
Requirements
- PHP >= 8.2
- PSR-11 Container Interface
Testing
Run the test suite with PHPUnit:
With coverage:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Vaibhav Pandey
- GitHub: @vaibhavpandeyvpz
- Email: [email protected]
Support
For issues, questions, or contributions, please visit the GitHub repository.