Wp Dev is a versatile WordPress plugin designed to streamline and enhance the capabilities of developers. By leveraging the DependencyInjection Component, it offers a standardized and centralized approach to object construction within WordPress. Inspired by Symfony's DependencyInjection Component, this plugin equips developers with powerful tools to optimize their workflow.
Features:
-
The DependencyInjection Component For WordPress
-
Standardize and centralize object construction.
-
Inspired by The DependencyInjection Component from Symfony.
-
Before you begin, ensure you have met the following requirements:
-
You have installed Docker and added support for Docker Compose commands. Instructions are available here.
-
You have installed GNU Make utility, which is commonly used to automate the build process of software projects. Make is often pre-installed if you're using a Unix-like system (such as Linux or macOS). Run this command to verify the installation:
make --version
Ensure that ./bin/wp.sh
is executable before using the make build
command:
chmod +x ./bin/wp.sh
To build the WordPress plugin archive, run the following command:
make build
This command generates wp-dev.zip
, a self-contained archive ready for WordPress installation.
Wp Dev utilizes YAML for service definitions, promoting organization and scalability in applications. By default, it searches for services.yaml in /wp-content/config
.
services.yaml follows the convention of the Configuration Files defined in the documentation.
Modify the configuration directory using the wp_dev_config_dir
filter,
add_filter( 'wp_dev_config_dir', function( string $config_dir ): string {
return WP_CONTENT_DIR . '/custom-config';
});
Alter the configuration file name with the wp_dev_config_file
filter,
add_filter( 'wp_dev_config_file', function( string $config_file ): string {
return 'custom.yaml';
});
Wp Dev supports WordPress environment variables via configuration files. Default supported variables include,
- WP_ENVIRONMENT_TYPE
- DB_NAME
- DB_USER
- DB_PASSWORD
- DB_HOST
- DB_CHARSET
- DB_COLLATE
- WP_CONTENT_DIR
- WP_CONTENT_URL
- WP_PLUGIN_DIR
- WP_PLUGIN_URL
- WP_UPLOAD_DIR
- WP_UPLOAD_URL
- WP_SITE_URL
- WP_HOME_URL
Referencing these variables in YAML is straightforward:
services:
myService:
class: MyService
arguments:
db: '%wp_env(DB_NAME)%'
To register a service, ensure your service class defines the __invoke() method. Then, add it to services.yaml:
class MyService {
public function __invoke() {
// Do WordPress stuff
}
}
services:
myService:
class: MyService
To load services from the container, use the wp_dev_load_services filter:
add_filter( 'wp_dev_load_services', function( array $service_aliases ): array {
return array_merge( $service_aliases, array( 'myService' ) );
});
Explore this GitHub repository for usage examples.
Wp Dev is free software released under the GNU General Public License version 2 or any later version. Refer to LICENSE for details.