{"id":28373237,"url":"https://github.com/sciactive/requirephp","last_synced_at":"2026-03-09T04:01:39.598Z","repository":{"id":16644021,"uuid":"19399332","full_name":"sciactive/requirephp","owner":"sciactive","description":"An implementation of dependency injection/service location (like RequireJS) in PHP.","archived":false,"fork":false,"pushed_at":"2016-07-02T22:45:21.000Z","size":858,"stargazers_count":24,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-03-01T07:33:41.240Z","etag":null,"topics":["dependency-injection","php"],"latest_commit_sha":null,"homepage":"http://requirephp.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sciactive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-03T09:01:53.000Z","updated_at":"2024-10-29T14:30:37.000Z","dependencies_parsed_at":"2022-08-27T00:20:15.032Z","dependency_job_id":null,"html_url":"https://github.com/sciactive/requirephp","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/sciactive/requirephp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sciactive%2Frequirephp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sciactive%2Frequirephp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sciactive%2Frequirephp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sciactive%2Frequirephp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sciactive","download_url":"https://codeload.github.com/sciactive/requirephp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sciactive%2Frequirephp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30282529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dependency-injection","php"],"created_at":"2025-05-29T18:40:05.938Z","updated_at":"2026-03-09T04:01:39.586Z","avatar_url":"https://github.com/sciactive.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg alt=\"logo\" src=\"https://raw.githubusercontent.com/sciactive/2be-extras/master/logo/product-icon-40-bw.png\" align=\"top\" /\u003e RequirePHP\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/sciactive/requirephp.svg?style=flat)](https://packagist.org/packages/sciactive/requirephp) [![License](https://img.shields.io/packagist/l/sciactive/requirephp.svg?style=flat)](https://packagist.org/packages/sciactive/requirephp) [![Total Downloads](https://img.shields.io/packagist/dt/sciactive/requirephp.svg?style=flat)](https://packagist.org/packages/sciactive/requirephp) [![Open Issues](https://img.shields.io/github/issues/sciactive/requirephp.svg?style=flat)](https://github.com/sciactive/requirephp/issues)\n\nAn implementation of dependency injection and service locator (like RequireJS) in PHP.\n\n## Installation\n\nYou can install RequirePHP with Composer or Bower.\n\n```sh\ncomposer require sciactive/requirephp\n\nbower install https://github.com/sciactive/requirephp.git\n```\n\n## Getting Started\n\nIf you don't use an autoloader, all you need to do is include the RequirePHP.php file.\n\n```php\nrequire(\"RequirePHP.php\");\n```\n\nNow you can start giving code that requires a module, or modules, to run. This code will not run until all the required modules (in this case, only 'test') are available.\n\n```php\n\\SciActive\\RequirePHP::_(array('test'), function($test){\n\t$test-\u003evalue = '\u003cp\u003eHello, world.\u003c/p\u003e';\n});\n```\n\nYou can define modules. This module has no dependencies, hence the empty array.\n\n```php\n\\SciActive\\RequirePHP::_('test', array(), function(){\n\tclass test {\n\t\tpublic $value;\n\n\t\tpublic function talk() {\n\t\t\techo $this-\u003evalue;\n\t\t}\n\t}\n\n\t// Returning a new instantiation is important if you are\n\t// providing a service.\n\treturn new test();\n});\n```\n\nYou can create aliases to modules (and other aliases).\n\n```php\n\\SciActive\\RequirePHP::alias('testing', 'test');\n```\n\nYou can keep using the same instance in other code, using RequirePHP as a service locator. This function uses the alias from above.\n\n```php\n\\SciActive\\RequirePHP::_(array('testing'), function($test){\n\t$test-\u003etalk(); // Prints '\u003cp\u003eHello, world.\u003c/p\u003e'.\n});\n```\n\nYou can also retrieve modules outside of a closure. However, if this module is not available at the time you request it, RequirePHP will throw a RequireModuleFailedException. Such is the price of not using a closure.\n\n```php\n$test = \\SciActive\\RequirePHP::_('test');\n$test-\u003etalk(); // Prints '\u003cp\u003eHello, world.\u003c/p\u003e'.\n```\n\n## Service Location\n\nThe repository contains [an example](https://github.com/sciactive/requirephp/blob/master/test_service_locator.php) of using RequirePHP as a service locator.\n\n## Dependency Injection\n\nThe repository contains [an example](https://github.com/sciactive/requirephp/blob/master/test_dependency_injector.php) of using RequirePHP as a dependency injector.\n\n## Contacting the Developer\n\nThere are several ways to contact RequirePHP's developer with your questions, concerns, comments, bug reports, or feature requests.\n\n- RequirePHP is part of [SciActive on Twitter](http://twitter.com/SciActive).\n- Bug reports, questions, and feature requests can be filed at the [issues page](https://github.com/sciactive/requirephp/issues).\n- You can directly [email Hunter Perrin](mailto:hunter@sciactive.com), the creator of RequirePHP.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsciactive%2Frequirephp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsciactive%2Frequirephp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsciactive%2Frequirephp/lists"}