{"id":13684072,"url":"https://github.com/UseMuffin/Footprint","last_synced_at":"2025-04-30T20:32:59.510Z","repository":{"id":31012577,"uuid":"34571038","full_name":"UseMuffin/Footprint","owner":"UseMuffin","description":"CakePHP plugin to allow passing currently logged in user to model layer.","archived":false,"fork":false,"pushed_at":"2023-11-18T14:46:18.000Z","size":158,"stargazers_count":95,"open_issues_count":0,"forks_count":23,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-12T13:18:40.302Z","etag":null,"topics":["cakephp","cakephp-plugin","php"],"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/UseMuffin.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-04-25T14:14:03.000Z","updated_at":"2025-01-10T21:08:30.000Z","dependencies_parsed_at":"2023-02-19T02:16:00.158Z","dependency_job_id":"4349bf97-e746-4b40-84ba-1365284cfff9","html_url":"https://github.com/UseMuffin/Footprint","commit_stats":{"total_commits":148,"total_committers":24,"mean_commits":6.166666666666667,"dds":0.4932432432432432,"last_synced_commit":"9a2d09f5394bb45b1b9b5b7d2a13864c0d908ae8"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FFootprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FFootprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FFootprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FFootprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UseMuffin","download_url":"https://codeload.github.com/UseMuffin/Footprint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251777698,"owners_count":21642212,"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":["cakephp","cakephp-plugin","php"],"created_at":"2024-08-02T14:00:24.667Z","updated_at":"2025-04-30T20:32:59.498Z","avatar_url":"https://github.com/UseMuffin.png","language":"PHP","readme":"# Footprint\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/UseMuffin/Footprint/ci.yml?style=flat-square)](https://github.com/UseMuffin/Footprint/actions?query=workflow%3ACI+branch%3Amaster)\n[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Footprint/master?style=flat-square)](https://codecov.io/github/UseMuffin/Footprint)\n[![Total Downloads](https://img.shields.io/packagist/dt/muffin/footprint.svg?style=flat-square)](https://packagist.org/packages/muffin/footprint)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n\nThis plugin allows you to pass the currently logged in user info to the model layer\nof a CakePHP application.\n\nIt comes bundled with the `FootprintBehavior` to allow you control over columns\nsuch as `user_id`, `created_by`, `company_id` similar to the core's `TimestampBehavior`.\n\n## Install\n\nUsing [Composer][composer]:\n\n```bash\ncomposer require muffin/footprint\n```\n\nYou then need to load the plugin by running console command:\n\n```bash\nbin/cake plugin load Muffin/Footprint\n```\n\nThe Footprint plugin must be loaded **before** the [Authentication](https://github.com/cakephp/authentication) plugin,\nso you should updated your `config/plugins.php` or `Application::bootstrap()` accordingly.\n\n## Usage\n\n### Middleware\n\nAdd the `FootprintMiddleware` to the middleware queue in your `Application::middleware()`\nmethod:\n\n```php\n$middleware-\u003eadd('Muffin/Footprint.Footprint');\n```\n\nIt must be added **after** `AuthenticationMiddleware` to ensure that it can read\nthe identify info after authentication is done.\n\nIf you don't have direct access to the place where `AuthenticationMiddleware` is added then check [here](#adding-middleware-via-event).\n\n### Behavior\n\nTo use the included behavior to automatically update the `created_by` and `modified_by`\nfields of a record for example, add the following to your table's `initialize()` method:\n\n```php\n$this-\u003eaddBehavior('Muffin/Footprint.Footprint');\n```\n\nYou can customize that like so:\n\n```php\n$this-\u003eaddBehavior('Muffin/Footprint.Footprint', [\n    'events' =\u003e [\n        'Model.beforeSave' =\u003e [\n            'user_id' =\u003e 'new',\n            'company_id' =\u003e 'new',\n            'modified_by' =\u003e 'always'\n        ]\n    ],\n    'propertiesMap' =\u003e [\n        'company_id' =\u003e '_footprint.company.id',\n    ],\n]);\n```\n\nThis will insert the currently logged in user's primary key in `user_id` and `modified_by`\nfields when creating a record, on the `modified_by` field again when updating\nthe record and it will use the associated user record's company `id` in the\n`company_id` field when creating a record.\n\nYou can also provide a closure that accepts an EntityInterface and returns a bool:\n\n```php\n$this-\u003eaddBehavior('Muffin/Footprint.Footprint', [\n    'events' =\u003e [\n        'Model.beforeSave' =\u003e [\n            'user_id' =\u003e 'new',\n            'company_id' =\u003e 'new',\n            'modified_by' =\u003e 'always',\n            'deleted_by' =\u003e function ($entity): bool {\n                return $entity-\u003edeleted !== null;\n            },\n        ]\n    ],\n]);\n```\n\n### Adding middleware via event\n\nIn some cases you don't have direct access to the place where the `AuthenticationMiddleware` is added. Then you will have to add this to your `src/Application.php`\n\n```php\nuse Authentication\\Middleware\\AuthenticationMiddleware;\nuse Cake\\Event\\EventInterface;\nuse Cake\\Http\\MiddlewareQueue;\nuse Muffin\\Footprint\\Middleware\\FootprintMiddleware;\n\n// inside the bootstrap() method\n$this-\u003egetEventManager()-\u003eon(\n    'Server.buildMiddleware',\n    function (EventInterface $event, MiddlewareQueue $middleware) {\n        $middleware-\u003einsertAfter(AuthenticationMiddleware::class, FootprintMiddleware::class);\n    }\n);\n```\n\n## Patches \u0026 Features\n\n* Fork\n* Mod, fix\n* Test - this is important, so it's not unintentionally broken\n* Commit - do not mess with license, todo, version, etc. (if you do change any,\n  bump them into commits of their own that I can ignore when I pull)\n* Pull request - bonus point for topic branches\n\n## Bugs \u0026 Feedback\n\nhttp://github.com/usemuffin/footprint/issues\n\n## License\n\nCopyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].\n\n[cakephp]:http://cakephp.org\n[composer]:http://getcomposer.org\n[mit]:http://www.opensource.org/licenses/mit-license.php\n[muffin]:http://usemuffin.com\n","funding_links":[],"categories":["Auditing / Logging"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUseMuffin%2FFootprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUseMuffin%2FFootprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUseMuffin%2FFootprint/lists"}