{"id":26365472,"url":"https://github.com/felixdorn/flash","last_synced_at":"2025-10-29T05:14:34.879Z","repository":{"id":47548201,"uuid":"211369691","full_name":"felixdorn/Flash","owner":"felixdorn","description":"Framework agnostic flash notifications for PHP 7.3+","archived":false,"fork":false,"pushed_at":"2022-01-27T08:20:54.000Z","size":156,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T13:50:05.907Z","etag":null,"topics":["flash","package","php","session"],"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/felixdorn.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":"2019-09-27T17:27:02.000Z","updated_at":"2023-02-25T15:58:27.000Z","dependencies_parsed_at":"2022-07-26T12:17:05.072Z","dependency_job_id":null,"html_url":"https://github.com/felixdorn/Flash","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixdorn%2FFlash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixdorn%2FFlash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixdorn%2FFlash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixdorn%2FFlash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felixdorn","download_url":"https://codeload.github.com/felixdorn/Flash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243921611,"owners_count":20369251,"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":["flash","package","php","session"],"created_at":"2025-03-16T19:38:11.849Z","updated_at":"2025-10-29T05:14:29.828Z","avatar_url":"https://github.com/felixdorn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Library logo](art/logo.png)\n# Flash\n![Packagist Version](https://img.shields.io/packagist/v/felixdorn/flash)\n[![Build Status](https://travis-ci.org/felixdorn/flash.svg?branch=rc2.0.0)](https://travis-ci.org/felixdorn/flash)\n[![codecov](https://img.shields.io/codecov/c/github/felixdorn/flash)](https://codecov.io/gh/felixdorn/flash)\n\n* Extensible\n* Fully tested and easily testable\n* Allow functional use\n* Support templates\n\n\n## Getting started\n\n```bash\ncomposer require felixdorn/flash\n```\n\nBefore using `Flash`, you need a [Driver](#drivers) that implements the [DriverInterface](src/Drivers/DriverInterface.php) and a template.\n\n```php\nuse Felix\\Flash\\Drivers\\SessionDriver;\nuse Felix\\Flash\\Flash;\nuse Felix\\Flash\\Templates\\SpectreTemplate;\n\n$driver = new SessionDriver([\n    // session_start options\n    // see https://www.php.net/manual/fr/function.session-start.php\n]);\n\n\n// A random template\n$template = new SpectreTemplate();\n\n$flash = new Flash($driver, $template);\n```\n\n## Usage\n\nThese are common examples to work with flash.\n\n\u003e In these example, i assume that you have already made the setup and have a working Flash instance.\n\n### Flashing\n```php\n$flash-\u003esuccess('message');\n\n$flash-\u003ewarning('message');\n\n$flash-\u003eerror('message');\n\n$flash-\u003einfo('message');\n\n$flash-\u003eflash('type', 'message');\n```\n\n### Rendering\n\n```php\n$flash-\u003esuccess('message');\n$flash-\u003ewarning('message1');\n\n$flash-\u003erender(); // implicitly it's $flash-\u003erender('all')\n\n// render 'message' and 'message1' using the defined template\n\n$flash-\u003erender('success');\n\n// render 'message' but not 'message1'\n```\n\n### Custom types\n```php\n$flash-\u003emessage('really-important', 'In movie gone in 60 seconds, things are gone in 60 seconds');\n\n$flash-\u003erender(); // will also render `really-important` as a normal type.\n\n$flash-\u003erender('really-important'); // will render `really-important` flashes using the default template\n```\n\n### Clear messages\n\n```php\n$flash-\u003esuccess('Cool!');\n\n$flash-\u003eclear('success'); // delete every success flash using the Driver\n\n$flash-\u003erender(); // Won't render anything\n\n$flash-\u003esuccess('Cool!');\n$flash-\u003eerror('Uhhhh.');\n\n$flash-\u003eclear(); // Clear every flashes\n \n$flash-\u003erender(); // Won't render anything\n\n\n```\n\n### Enabling \u0026 Disabling\n\n```php\n$flash-\u003eerror('Bad thing.');\n\n$flash-\u003edisable();\n// NOTE: Here, when disabling, you can still clear or render\n\n$flash-\u003esuccess('Good thing');\n\n$flash-\u003eenable();\n\n$flash-\u003erender('all'); // 'all' is optional, it's the default value\n\n// Here, only 'Bad thing.' will be rendered.\n```\n\n\n## Drivers\n\nThere is only 2 but it's easy to implement a new one (PR appreciated :p).\n\n* [ArrayDriver](src/Drivers/ArrayDriver.php) Driver that should only be used for testing purpose.\n* [SessionDriver](src/Drivers/SessionDriver.php) Driver to work with the most common implementation of session in PHP.\n\nLet's dive into what they do, and how they work. This part is useful if you want to create your own, otherwise jump to the [next](#templates) session.\n\nA driver must implement these 3 methods :\n\n* clear(): self\n* push(FlashData $data): self\n* all(string $type = 'all'): array\n\n### The clear method\n\nThis is the simple one. It should clear any flash pushed.\n\n### The push method\n\nThis one receive a FlashData with the type of flash and the value and should register it to be able to get it back.\n\n### The all method\n\nThis one should if `$type = 'all'` return every flash pushed formatted like this :\n\n```php\nreturn [\n    '{someType}' =\u003e [\n        'someFlash'\n        // ...\n    ],\n    // ...\n];\n```\n\nIf the `$type` is something else then, it should return an array with only the flash inside this type.\n\n```php\nreturn [\n    'someFlash'\n];\n```\n\n## Templates\n\n* [BootstrapTemplate](src/Templates/BootstrapTemplate.php)\n* [BulmaTemplate](src/Templates/BulmaTemplate.php)\n* [Semantic2Template](src/Templates/SpectreTemplate.php)\n* [SpectreTemplate](src/Templates/SpectreTemplate.php)\n* [TestableTemplate](src/Templates/TestableTemplate.php)\n* [NullTemplate](src/Templates/NullTemplate.php)\n \n\u003e TestableTemplate just returns `{type}: {value}`, so it's easier to test if a flash worked well instead of typing all of the boring HTML.\n\n### Registering a template\n```php\n$flash-\u003esetTemplate(...);\n```\n\n\u003e You can also set it when constructing the *Flash* object\n\n### Template using a string\nThis one is the most basic, but also the most useful.\n\n```\n\u003cdiv class=\"alert {type}\"\u003e{flash}\u003c/div\u003e\n```\n\nSo, if you flash an success Hello! flash. It will output \n```\n\u003cdiv class=\"alert success\"\u003eHello!\u003c/div\u003e\n```\n\n### Template using a callable\n\n```php\nfunction (string $type, string $message): string {\n    return sprintf('\u003cdiv class=\"alert %s\"\u003e%s\u003c/div\u003e', $type, $message);\n}\n```\n\nIn this case, you don't need a callable, and you could just use a string based template but this is how it works. \n\n### Template using TemplateInterface\n\n```php\n\nuse Felix\\Flash\\Templates\\TemplateInterface;\n\nclass MyTemplate implements TemplateInterface {\n    public function toHtml(string $type,string $message){\n        return sprintf('\u003cdiv class=\"alert %s\"\u003e%s\u003c/div\u003e', $type, $message);\n    }\n}\n```\n\nIn this case, you don't need a Template class, and you could just use a string based template but this is how it works.\n\n\n## Testing\n\n```\ncomposer test\n```\n\n### Security\n\nIf you discover any security related issues, please email github@felixdorn.fr instead of using the issue tracker.\n\n## Credits\n* [Félix Dorn](https://felixdorn.fr)\n\n### Contributors\n* [Grafikart](https://github.com/grafikart)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixdorn%2Fflash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixdorn%2Fflash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixdorn%2Fflash/lists"}