{"id":16506068,"url":"https://github.com/rmp-up/wp-di","last_synced_at":"2025-07-19T13:10:08.651Z","repository":{"id":49639288,"uuid":"183819534","full_name":"rmp-up/wp-di","owner":"rmp-up","description":"Simple PHP Dependency Injection for WordPress","archived":false,"fork":false,"pushed_at":"2021-06-11T16:13:47.000Z","size":378,"stargazers_count":16,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"release/0.8","last_synced_at":"2025-03-17T22:54:50.992Z","etag":null,"topics":["magic","php","php-dependency-injection","pimple","psr-11","wordpress","wp-di"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmp-up.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-27T20:38:01.000Z","updated_at":"2024-07-05T18:28:56.000Z","dependencies_parsed_at":"2022-08-30T17:00:40.892Z","dependency_job_id":null,"html_url":"https://github.com/rmp-up/wp-di","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmp-up%2Fwp-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmp-up%2Fwp-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmp-up%2Fwp-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmp-up%2Fwp-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmp-up","download_url":"https://codeload.github.com/rmp-up/wp-di/tar.gz/refs/heads/release/0.8","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244764925,"owners_count":20506732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magic","php","php-dependency-injection","pimple","psr-11","wordpress","wp-di"],"created_at":"2024-10-11T15:16:54.325Z","updated_at":"2025-03-21T08:31:12.581Z","avatar_url":"https://github.com/rmp-up.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://img.shields.io/badge/PHP-7.0%20--%208.0-blue?style=for-the-badge\u0026logo=php)\n![](https://img.shields.io/badge/WordPress-4.8%20--%205.6-blue?style=for-the-badge\u0026logo=wordpress)\n\n[![Build Status](https://travis-ci.org/rmp-up/wp-di.svg?branch=release/0.8)](https://travis-ci.org/rmp-up/wp-di)\n[![Coverage Status](https://coveralls.io/repos/github/rmp-up/wp-di/badge.svg?branch=release/0.8)](https://coveralls.io/github/rmp-up/wp-di?branch=release/0.8)\n\n# WP DI\n\n\u003e PHP Dependency Injection for WordPress (based on Pimple)\n\nThis is nothing new but we added some magic:\n\n* Compatible with projects using Pimple already\n* Configuration via plain arrays, Yaml or other\n* \"Less WordPress more OOP\"\n\nand still searching for other magic to apply.\n\n\n## Getting started\n\nAdd the package to your project\n\n```bash\ncomposer require rmp-up/wp-di\n```\n\nand set up the container provider\n\n```php\nRmpUp\\WpDi\\WpDi::load( require 'services.php' );\n\n$container = \\RmpUp\\WpDi\\WpDi::pimple();\n```\n\nFriends of YAML can add `composer require symfony/yaml`\nand use\n\n```php\nRmpUp\\WpDi\\WpDi::load(\n\tRmpUp\\WpDi\\Yaml::parseFile( 'services.yaml' )\n);\n```\n\n\n## Features\n\nA full documentation can be found in the\n[documentation of the latest releases](https://github.com/rmp-up/wp-di/releases).\nThe following is just a sneak peek into some of the possibilities.\nTry using the \"preload.php\" when you have PHP \u003e= 7.4\nor a composer workflow to get even more performance:\n\n```json\n{\n  \"autoload\": {\n    \"files\": [ \"vendor/rmp-up/wp-di/preload.php\" ]\n  }\n}\n```\n\n### Services and parameters\n\nDefine services as known from classical DI but also ...\n\n* Primitive parameters as usual\n* Default values for options\n* Path to templates\n* Inject all of them into services\n* Allow factories to create services\n\n```yaml\n# Primitive parameters as usual\nparameters:\n  some: \"primitives\"\n  like: 42\n\n# Default values for options\noptions:\n  _my_plugin_rating: 5/7\n  _this_is: cool\n\n# Path to templates\ntemplates:\n  admin-view: my-own-plugin/template-parts/fester.php\n  frontend-view: my-own-plugin/public/coogan.jpg\n  # looks up the file in theme, theme-compat and plugin directory\n\n# Inject all of them into services\nservices:\n  SimpleOne:\n    arguments:\n      - \"Hello there!\" \n      - 1337\n \n  SomeThing:\n    arguments:\n      - \"%like%\" # the parameter\n      - \"%_this_is%\" # the option\n      - \"%frontend-view%\" # path to the template\n      - \"@SimpleOne\" # the other service\n```\n\n\n### Register services in WordPress\n\nServices can also be used to ...\n\n* Add actions / filters\n* Add Meta-Boxes\n* Register Post-Types\n* Register Shortcodes\n* Register Widgets\n* Add WP-CLI commands\n\n```yaml\nservices:\n  StrrevEverything:\n    filter: the_content\n    # calling `::__invoke` for the \"the_content\"-filter\n\n  BackendAdminListThing:\n    meta_box:\n      title: Greatest box in the World!\n      screen: post\n\n  MyOwnPostType:\n    post_type: animals\n    # cast service to array and forward to register_post_type\n\n  BestShortcodeEver:\n    shortcode: shortcode_wont_die\n    widget: ~\n    # Shortcode and widget at once. Wow!\n\n  DoItCommand:\n    wp_cli:\n      do-it: __invoke\n      doit: __invoke\n      seriously do-it do-it do-it: seriously\n      # cli commands mapped to methods \n```\n\n\n### Use tags to enhance YAML\n\nWithin YAML you can:\n\n* Access PHP-Constants\n* Concatenate text\n* Translate text\n\nMostly lazy to get the best performance.\n\n```yaml\nservices:\n  # Access PHP-Constants\n  InjectingConstants:\n    arguments:\n      - !php/const ABSPATH\n\n  # Concatenate text\n  ThisIsSomeTemplate:\n    arguments:\n      - !join [ !php/const WP_CONTENT_DIR, \"/plugins/grey-matter/walter.jpg\" ]\n\n  # Translations within YAML\n  ThisThingNeedsTranslations:\n    arguments:\n      - !__ [ Who is Adam?, dark ]\n      - !esc_attr__ [ white ]\n      # ... many more translation functions available ...\n```\n\nAll of this is only possible when using `\\RmpUp\\WpDi\\Yaml::parseFile(...)`\nor `::parse(...)`.\n\n\n## Contributing\n\nWe used this in some projects\nand still maintain/enhance it,\nso please [open an issue](https://github.com/rmp-up/wp-di/issues/new)\nif there is anything we can help with.\n\nIf you'd like to contribute,\nplease fork the repository and make changes as you'd like.\nPull requests are warmly welcome.\n\n\n## Related projects\n\nPlease also note the following projects\nabout dependency injection container in WordPress:\n\n* [Pimple Dependency Injection Container](https://packagist.org/packages/pimple/pimple)\n* [Plugin-Boilerplate by Gary Jones](https://github.com/GaryJones/plugin-boilerplate)\n\n## Licensing\n\nSee the [LICENSE.txt](./LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmp-up%2Fwp-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmp-up%2Fwp-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmp-up%2Fwp-di/lists"}