{"id":13803601,"url":"https://github.com/krakphp/php-inc","last_synced_at":"2025-04-10T14:21:43.346Z","repository":{"id":47561870,"uuid":"83270757","full_name":"krakphp/php-inc","owner":"krakphp","description":"Composer Plugin for automatically including files for easing function usage in php.","archived":false,"fork":false,"pushed_at":"2021-08-23T23:08:12.000Z","size":18,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"v0.x","last_synced_at":"2024-05-03T01:20:19.758Z","etag":null,"topics":["autoloading","autoloading-functions","composer","composer-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-02-27T05:14:45.000Z","updated_at":"2022-01-11T10:53:11.000Z","dependencies_parsed_at":"2022-07-26T00:46:16.487Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/php-inc","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fphp-inc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fphp-inc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fphp-inc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fphp-inc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/php-inc/tar.gz/refs/heads/v0.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233935,"owners_count":21069493,"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":["autoloading","autoloading-functions","composer","composer-plugin"],"created_at":"2024-08-04T01:00:36.035Z","updated_at":"2025-04-10T14:21:43.327Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","readme":"# Php Inc\n\n![PHP Requirements](https://img.shields.io/badge/php-%5E7.1-8892BF.svg)\n\nPhp inc is a composer plugin for automatically including certain files into composer's `autoload` and `autoload-dev` `files` config. Given a set of file matchers, on the the `dump-autoload` event, php-inc will automatically include any matched files into the dumped autoloaded files.\n\nThis ameliorates the issues that come about when you want to include certain files that contain functions or maybe multiple classes but don't want to constantly update the composer autoload files configuration which can get hard to deal with when you start including more files.\n\n## Installation\n\nInstall via composer at `krak/php-inc`\n\n## Usage\n\nWith the default configuration, simply name any file in your `src` or `tests` directory starting with a lower case letter with a `.php` extension will automatically be included in the dumped autoload files when composer's `dump-autoload` event is triggered. This happens on install, update, or dump-autoload commands.\n\nThe composer plugin is automatically loaded after it is installed, so in most scenarios, you shouldn't have to do anything for the files to be automatically included. However, if you add files and want to include them right away during development, you can run `composer dump-autoload` to make sure they are included.\n\n## Configuration\n\nHere's an example of the default configuration that is applied:\n\n```json\n{\n  \"extra\": {\n    \"php-inc\": {\n      \"src-path\": \"src\",\n      \"test-path\": \"tests\",\n      \"matches\": {\n        \"type\": \"and\",\n        \"matches\": [\n          {\"type\":  \"ext\", \"exts\":  [\"php\"]},\n          {\"type\":  \"lowerCase\"},\n          {\"type\":  \"excludePath\", \"path\":  \"@.*/(Resources|Tests)/.*@\"}\n        ]\n      },\n      \"matches-dev-src\": {\n        \"type\": \"and\",\n        \"matches\": [\n          {\"type\":  \"ext\", \"exts\":  [\"php\"]},\n          {\"type\":  \"lowerCase\"},\n          {\"type\":  \"includePath\", \"path\":  \"@.*/Tests/.*@\"},\n          {\"type\":  \"excludePath\", \"path\":  \"@.*/Tests/.*/Fixtures/.*@\"}\n        ]\n      },\n      \"matches-dev-test\": {\n        \"type\": \"and\",\n        \"matches\": [\n          {\"type\":  \"ext\", \"exts\":  [\"php\"]},\n          {\"type\":  \"lowerCase\"},\n          {\"type\":  \"excludePath\", \"path\":  \"@.*/Fixtures/.*@\"}\n        ]\n      }\n    }\n  }\n}\n```\n\nLet's go through and explain what each part means and refers to.\n\n### src-path\n\n`src-path` will determine the path to your source code where any autoload files will be searched in.\n\nIf you are working with the standard Laravel file structure, you'll want to change the src-path to `app` instead of `src`.\n\n### test-path\n\n`test-path` will determine the path to your test code where the autoload-dev files will be searched.\n\n### matches\n\n`matches` can be any hierarchy of configured matches to determine how you want the src folder to be searched for files to be included in `autoload.files`. The default configuration ensures that all files that start with a lower case file name, have a `php` extension, and are not inside of a Resources or Tests directory will be included in the `autoload.files` composer configuration.\n\n### matches-dev-src\n\n`matches-dev-src` can be any hierarchy of configured matches to determine how you want the src folder to be searched for files to be included in `autoload-dev.files`. The default configuration ensures that all files that start with a lower case file name, have a `php` extension, are inside of a `Tests` directory, and *not* apart of a `Fixtures` directory will be included in the `autoload-dev.files` composer configuration.\n\n### matches-dev-test\n\n`matches-dev-test` can be any hierarchy of configured matches to determine how you want the test folder to be searched for files to be included in `autoload-dev.files`. The default configuration ensures that all files that start with a lower case file name, have a `php` extension, and are *not* apart of a `Fixtures` directory will be included in the `autoload-dev.files` composer configuration.\n\n## Debugging\n\nIf you are ever curious what files are being included, you can simply run `composer dump-autoload -v` and view the php-inc output to see which files are being merged with which composer files definition.\n\n## Managing Dependencies\n\nWith extended use, you may come into a situation where one file included needs to be loaded before another. If this comes up, the best solution I've found for now is to prefix those files with an `_` and just create a new file named inc.php which loads them in the correct order.\n\nFor example:\n\n```\nsrc/a.php\nsrc/b.php\n```\n\n`a.php` depends on `b.php` loading first. To enforce loading order, we'd make the following change:\n\n```\nsrc/_a.php\nsrc/_b.php\nsrc/inc.php\n```\n\nWhere `inc.php` is as follows:\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/_b.php';\nrequire_once __DIR__ . '/_a.php';\n```\n\nWhen you run `composer dump-autoload`, only `inc.php` will be included and will make sure to include those files correctly.\n\n## Why is this useful?\n\nhttps://nikic.github.io/2012/08/10/Are-PHP-developers-functophobic.html\n\nUntil php includes a spec for function autoloading, creating and using standard functions within a modern psr-4 codebase is cumbersome, especially compared to the simplicity of using autoloaded classes. Most devs will give up on using functions and just create abstract classes with static functions to circumvent the autoloading constraints instead of manually registering individual files in the composer autoload sections.\n\nThis is useful for more than just functions however. There are plenty of cases where one file with multiple definitions would make sense to keep together instead of splitting into several files which clutter the filesystem.\n\nThis plugin is an attempt to help php devs who use composer to have the ability to\n\n## Drawbacks\n\nThe main drawbacks to automatically including the php files in the composer autoload files section is that those files will be included anytime the composer autoloader is loaded. In larger projects, this can be a concern if you are loading files that are only needed during certain, less frequent paths of execution.\n\nOpcache does mitigate this problem tremendously, but it is something to consider when you start sprinkling files to be included throughout your codebase.\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Support"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fphp-inc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fphp-inc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fphp-inc/lists"}