Download the PHP package gp/loader without Composer
On this page you can find all versions of the php package gp/loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package loader
Short Description A Loader library to autoload the classes and a container to support the dependency injections
License MIT
Informations about the package loader
GP Loader
The GP Loader package provides a configuration and dependency loading framework for PHP. It is designed for managing configurations from various sources, dependency injection, and loading of application components.
Table of Contents
- Requirements
- Installation
- Getting Started
- Features
- Classes
- ConfigLoader
- ArrayLoader
- EnvLoader
- ValueLoader
- Container
- Loader
- Usage
- LoadingConfiguration
- DependencyInjection
- ServiceContainer
- AutoLoadingClasses
- Contributing
- License
- Author
- Contact
Requirements
- PHP 8.1 or higher
- composer
Installation
You can install gp_loader using Composer. Run the following command in your terminal:
Getting Started
After installation, you can start using the package by including the autoloader:
Features
-
Flexible Configuration Loading:
- Supports loading configurations from multiple sources, including
.envfiles, PHP arrays, Json, Xml, Yaml and direct values. - Easy merging, overriding, and retrieval of configuration data.
- Supports loading configurations from multiple sources, including
-
Easily load the Configuration from any files
- Load the config from any files .env, .json, .yaml, .php
- Access it anywhere in your application
- Eassy to load and manage
-
Dependency Injection Container:
- Manage services and instances with a built-in DI container.
- Supports singleton services and dynamic resolution of dependencies.
- Simplifies service management with the
loadFromConfigmethod.
-
Autoloading Classes:
- Automatically load classes based on namespace and path configurations.
- Supports dynamic resolution of controllers and other components.
-
Extensible Design:
- Abstract classes like
ConfigLoaderprovide the foundation for implementing custom loaders. - Easily extend functionality to support additional data sources or custom behaviors.
- Abstract classes like
-
Environment Variable Integration:
- Load environment variables directly from
.envfiles. - Simplifies managing sensitive configuration data.
- Load environment variables directly from
-
Lightweight and Modular:
- Designed to be lightweight and modular, making it easy to integrate into any PHP project.
- Provides only essential functionality without unnecessary overhead.
-
Error Handling and Validation:
- Includes methods for safely retrieving, setting, and overriding configuration values.
- Ensures proper resolution of constructor dependencies and method calls.
-
Dynamic Service Resolution:
- Resolve services dynamically via
Container::resolveandContainer::resolveMethod. - Allows for flexible service binding and retrieval.
- Resolve services dynamically via
- Factory-Based Loader Instantiation:
- Use
ConfigLoader::getInstanceto dynamically instantiate loaders based on the required type (e.g.,ENV_LOADER,ARRAY_LOADER).
- Use
These features make the GP Loader framework powerful, extensible, and easy to use for managing configurations and dependencies in PHP applications.
Classes
ConfigLoader
An abstract class that acts as the base for configuration loaders. It defines the common methods and structure for loading configurations from various sources.
Methods
load(): Loads the configuration data using theinnerLoadermethod and sets up the load handler.get(string $key): Retrieves a configuration value by its key.getAll(): Returns all configuration data.merge(array $data): Merges additional data into the existing configuration.set(string $key, $value, bool $strict = false): Sets a specific configuration value.override(array $data): Overrides the current configuration with new data.setLoadHandler(callable $_loadHandler): Sets a custom handler to process the loaded data.defaultHandler($data): Default handler to load configuration values into environment variables.getInstance($driver, $config = [], $name = ''): Factory method to create an instance of a specific loader.getConfig(string $name): Retrieves a named configuration instance.loadConfig(string $file, string $name = ''): Load the configs directly from the file.getFile(): Returns the file.
Constants
ENV_LOADER: Represents the environment file loader.ARRAY_LOADER: Represents the array-based php file loader.XML_LOADER: Represents the XML file loader.YAML_LOADER: Represents the YAML file loader.JSON_LOADER: Represents the JSON file loader.VALUE_LOADER: Represents the value-based loader.
Container
A dependency injection container for managing instances and services.
Methods
set(string $_name, mixed $_closure, bool $_singleton = false): Registers an instance or service.getInstance(string $_name): Retrieves a singleton instance.getService(string $_name): Retrieves a service.get(string $_name): Retrieves an object from the container.isClassRegistered(string $_name): Checks if a class is registered.resolve(string $_class_name, array $data = []): Resolves and creates an instance of a class.getConstrParams(string $_class_name, $data): Resolves constructor dependencies for a class.loadFromConfig(array $_config): Loads configuration and registers services.resolveMethod(string $class, string $method, array $data): Resolves dependencies for a specific method.resolveClassConstructor(string $class, array $params = []): Resolves the constructor dependencies of a class and creates an instance.resolveClassMethod($class, string $method, array $params = []): Resolves the dependencies for a specific method of a class and invokes it.
Loader
A class responsible for managing the loading of application components.
Methods
autoLoadClass($ctrl, $autoloads, ?ConfigLoader $config = null): Automatically loads classes based on the configuration.setPrefixes(array $prefixes): Sets the prefixes for autoloading classes.
Usage
Load the config from file.
Load the configuration directly from the file.
Loading Configuration
You can load configurations using the ConfigLoader factory method:
Dependency Injection
Use the Container class to manage services and resolve dependencies:
Service Container
Autoloading Classes
The Loader class can manage the loading of components, and make its available to your class object
Contributing
Contributions are welcome! If you would like to contribute to gp_validator, please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/- YourFeature).
- Make your changes and commit them (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/YourFeature).
- Open a pull request.
- Please ensure that your code adheres to the coding standards and includes appropriate tests.
License
This package is licensed under the MIT License. See the LICENSE file for more information.
Contact
For questions or issues, please reach out to the development team or open a ticket.
Author
- Periyandavar Github ([email protected])