{"id":26234288,"url":"https://github.com/tamtamchik/simple-flash","last_synced_at":"2025-04-11T22:29:58.319Z","repository":{"id":32700150,"uuid":"36289588","full_name":"tamtamchik/simple-flash","owner":"tamtamchik","description":"Easy, framework-agnostic flash notifications for PHP.","archived":false,"fork":false,"pushed_at":"2024-12-10T14:00:58.000Z","size":236,"stargazers_count":106,"open_issues_count":0,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-03T05:09:33.596Z","etag":null,"topics":["composer-package","framework-agnostic","notifications","php"],"latest_commit_sha":null,"homepage":"https://tamtamchik.github.io/simple-flash","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/tamtamchik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-26T10:45:39.000Z","updated_at":"2025-01-03T14:05:58.000Z","dependencies_parsed_at":"2024-06-18T13:53:32.467Z","dependency_job_id":"023c6d86-4f8a-4829-a0ad-eb81a5be667a","html_url":"https://github.com/tamtamchik/simple-flash","commit_stats":{"total_commits":211,"total_committers":4,"mean_commits":52.75,"dds":"0.014218009478673022","last_synced_commit":"37e31285119516a7f9f60f89cb38c13233fd85c4"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fsimple-flash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fsimple-flash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fsimple-flash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fsimple-flash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamtamchik","download_url":"https://codeload.github.com/tamtamchik/simple-flash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248489348,"owners_count":21112550,"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":["composer-package","framework-agnostic","notifications","php"],"created_at":"2025-03-13T01:29:50.788Z","updated_at":"2025-04-11T22:29:58.289Z","avatar_url":"https://github.com/tamtamchik.png","language":"PHP","readme":"# Simple Flash Messages\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n![PHP][ico-php]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-scrutinizer-build]][link-scrutinizer]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n\n[![SensioLabsInsight][ico-insight]][link-insight]\n\nEasy, framework-agnostic flash notifications for PHP. Inspired by [laracasts/flash](https://github.com/laracasts/flash) and [plasticbrain/PHP-Flash-Messages](https://github.com/plasticbrain/PHP-Flash-Messages). It supports multiple CSS frameworks out of the box:\n\n* [Bootstrap](https://getbootstrap.com) (default)\n* [Foundation](https://get.foundation)\n* [Bulma](https://bulma.io)\n* [Materialize](https://materializecss.com)\n* [Tailwind](https://tailwindcss.com)\n* [Premier](https://primer.style)\n* [UIKit](https://getuikit.com)\n* [Semantic UI](https://semantic-ui.com)\n* [Spectre.css](https://picturepan2.github.io/spectre)\n* [Halfmoon](https://www.gethalfmoon.com)\n\n![simple-flash](https://cloud.githubusercontent.com/assets/265510/24695879/c87b32f2-1a11-11e7-972e-b4b2c75f35b5.png)\n\n\u003e [!NOTE]\n\u003e The documentation below is for version 3.x!  \n\u003e If you are looking the documentation for version 2.x look [here](https://github.com/tamtamchik/simple-flash/blob/2.0.x/README.md).  \n\u003e If you are looking the documentation for version 1.x look [here](https://github.com/tamtamchik/simple-flash/blob/1.2.x/README.md).  \n\n## Install\n\nVia [Composer](http://getcomposer.org).\n\n```bash\n$ composer require tamtamchik/simple-flash\n```\n\nInside your project make sure to start a session and load [Composer](http://getcomposer.org) autoload to make everything work.\n\n````php\n\u003c?php\n// Start a Session\nif( !session_id() ) {\n    session_start();\n}\n\n// Initialize Composer Autoload\nrequire_once 'vendor/autoload.php';\n````\n\n## Usage\n\nThere are 3 ways to use library:\n\n```php\nuse \\Tamtamchik\\SimpleFlash\\Flash;\nuse function Tamtamchik\\SimpleFlash\\flash;\n\n// Instance\n$flash = new Flash();\n$flash-\u003emessage('Tea.');\n\n// Static\nFlash::message('Earl Gray.');\n\n// Function\nflash()-\u003emessage('Hot!');\n```\n\nMessages added by calling `message($message, $type = 'info')` method. In case of calling a function `flash()` you can pass `$message, $type` just to function like so: `flash('resistance is futile')`.\n\nBecause any of creation types return `\\Tamtamchik\\SimpleFlash\\Flash` instance, so you can always use chaining to add multiple messages. Shortcuts available for all types of base message types, also you can pass arrays as `$message`.\n\n```php\nuse function Tamtamchik\\SimpleFlash\\flash;\n\nflash()-\u003eerror(['Invalid email!', 'Invalid username!'])\n       -\u003ewarning('Warning message.')\n       -\u003einfo('Info message.')\n       -\u003esuccess('Success message!');\n```\n\nOut of the box library support 4 different types of messages: `error`, `warning`, `info`, `success`.\n\n```html\n\u003cdiv class=\"alert alert-danger\" role=\"alert\"\u003e\n  \u003cp\u003eInvalid email!\u003c/p\u003e\n  \u003cp\u003eInvalid username!\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"alert alert-warning\" role=\"alert\"\u003e\u003cp\u003eWarning message.\u003c/p\u003e\u003c/div\u003e\n\u003cdiv class=\"alert alert-info\" role=\"alert\"\u003e\u003cp\u003eInfo message.\u003c/p\u003e\u003c/div\u003e\n\u003cdiv class=\"alert alert-success\" role=\"alert\"\u003e\u003cp\u003eSuccess message!\u003c/p\u003e\u003c/div\u003e\n```\n\nRendering is simple:\n\n```php\nuse function Tamtamchik\\SimpleFlash\\flash;\n\n// Rendering specific type\n$output = flash()-\u003edisplay('error');\n\n// Rendering all flash\n$output = flash()-\u003edisplay();\n\n// Also rendering possible when you just read instance of \\Tamtamchik\\SimpleFlash\\Flash object as a string\n(string) flash();\n\n// or ... it's totally just for display, never do this in real life...\n\u003c?php\n// ... some code\n$flash = new Flash();\n$flash-\u003ewarning('It is totally just for display, never do this in real life...');\n// ... some other code\n?\u003e\n\u003c!-- ... some html --\u003e\n\u003cdiv class=\"flashes\"\u003e\n  \u003c?= $flash; ?\u003e\n\u003c/div\u003e\n\u003c!-- ... some other html --\u003e\n```\n\n## Templates\n\nUsing templates you can customize how flash messages will be rendered. \nPackage comes with a set of templates for most popular CSS frameworks:\n\n```php\nTemplates::BASE; // Same as Templates::BOOTSTRAP\nTemplates::BOOTSTRAP;   // https://getbootstrap.com\nTemplates::FOUNDATION;  // https://get.foundation\nTemplates::BULMA;       // https://bulma.io\nTemplates::MATERIALIZE; // https://materializecss.com\nTemplates::TAILWIND;    // https://tailwindcss.com\nTemplates::PRIMER;      // https://primer.style\nTemplates::UIKIT;       // https://getuikit.com\nTemplates::SEMANTIC;    // https://semantic-ui.com\nTemplates::SPECTRE;     // https://picturepan2.github.io/spectre\nTemplates::HALFMOON;    // https://www.gethalfmoon.com\n```\n\n### Shortcuts\n\nYou cah pass template name as a second argument to `display()` function:\n\n```php\nuse function Tamtamchik\\SimpleFlash\\flash;\n\nflash()-\u003esuccess('Success message!');\n...\n// rendering with Halfmoon template using Templates::HALFMOON as a shortcut\necho flash()-\u003edisplay('success', Templates::HALFMOON);\n```\n\nOr you can use descriptive display functions:\n\n```php\nuse function Tamtamchik\\SimpleFlash\\flash;\n\nflash()-\u003esuccess('Success message!');\n...\necho flash()-\u003edisplayBootstrap();\necho flash()-\u003edisplayFoundation();\necho flash()-\u003edisplayBulma();\necho flash()-\u003edisplayMaterialize();\necho flash()-\u003edisplayTailwind();\necho flash()-\u003edisplayPrimer();\necho flash()-\u003edisplayUiKit();\necho flash()-\u003edisplaySemantic();\necho flash()-\u003edisplaySpectre();\necho flash()-\u003edisplayHalfmoon();\n```\n\n### Factory\n\nPackage comes with a set of templates for most popular CSS frameworks:\n\nThis templates can be created using [TemplateFactory](src/TemplateFactory.php) that comes with package.\nAll templates have aliases defined in [Templates](src/Templates.php).\n\n```php\nuse Tamtamchik\\SimpleFlash\\Flash;\nuse Tamtamchik\\SimpleFlash\\TemplateFactory;\nuse Tamtamchik\\SimpleFlash\\Templates;\n\n// get template from factory, e.g. template for Foundation\n$template = TemplateFactory::create(Templates::FOUNDATION);\n\n// passing template via function\nflash('Info message using Foundation 6 template!', 'info', $template);\n\n// passing to constructor\n$flash = new Flash($template);\n\n// using setTemplate function\n$flash-\u003esetTemplate($template);\n```\n\n### Creating templates\n\nTemplate is basically any class that implements [TemplateInterface](src/TemplateInterface.php). But to make it easy\nyou can extend [BaseTemplate](src/BaseTemplate.php), it already contains most of the functions.\n\nDefining and using this sample class as template:\n\n```php\nuse Tamtamchik\\SimpleFlash\\BaseTemplate;\nuse Tamtamchik\\SimpleFlash\\TemplateInterface;\nuse function Tamtamchik\\SimpleFlash\\flash;\n\nclass CustomTemplate extends BaseTemplate implements TemplateInterface\n{\n    protected $prefix  = '\u003cli\u003e'; // every line prefix\n    protected $postfix = '\u003c/li\u003e'; // every line postfix\n    protected $wrapper = '\u003cul class=\"alert-%s\"\u003e%s\u003c/ul\u003e'; // wrapper over messages of same type\n\n    /**\n     * @param $messages - message text\n     * @param $type     - message type: success, info, warning, error\n     *\n     * @return string\n     */\n    public function wrapMessages($messages, $type)\n    {\n        return sprintf($this-\u003egetWrapper(), $type, $messages);\n    }\n}\n\nflash()\n    -\u003esetTemplate(new CustomTemplate)\n    -\u003eerror(['Invalid email!', 'Invalid username!'])\n    -\u003ewarning('Warning message.')\n    -\u003einfo('Info message.')\n    -\u003esuccess('Success message!')\n    -\u003edisplay();\n```\n\nWill output following:\n\n```html\n\u003cul class=\"alert-error\"\u003e\n    \u003cli\u003eInvalid email!\u003c/li\u003e\n    \u003cli\u003eInvalid username!\u003c/li\u003e\n\u003c/ul\u003e\n\u003cul class=\"alert-warning\"\u003e\n    \u003cli\u003eWarning message.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cul class=\"alert-info\"\u003e\n    \u003cli\u003eInfo message.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cul class=\"alert-success\"\u003e\n    \u003cli\u003eSuccess message!\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n## Interface\n\nPackage provides `TemplateInterface` for Simple Flash templates.\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer tests\n```\n\n## Examples\n\n``` bash\n$ composer examples\n```\nAnd then just visit [http://localhost:8000](http://localhost:8000)\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email \u003cyuri.tam.tkachenko@gmail.com\u003e instead of using the issue tracker.\n\n## Credits\n\n- [Yuri Tkachenko][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[![Buy Me A Coffee][ico-coffee]][link-coffee]\n\n[ico-version]: https://img.shields.io/packagist/v/tamtamchik/simple-flash.svg?style=flat-square\n[ico-license]: https://img.shields.io/packagist/l/tamtamchik/simple-flash.svg?style=flat-square\n[ico-scrutinizer-build]: https://img.shields.io/scrutinizer/build/g/tamtamchik/simple-flash.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/tamtamchik/simple-flash.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/tamtamchik/simple-flash.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/tamtamchik/simple-flash.svg?style=flat-square\n[ico-coffee]: https://img.shields.io/badge/Buy%20Me%20A-Coffee-%236F4E37.svg?style=flat-square\n[ico-insight]: https://insight.symfony.com/projects/a92cacf2-ba32-4f36-b040-5a9f1d7f8f25/small.svg\n[ico-php]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Ftamtamchik%2Fsimple-flash%2Fraw%2Fmaster%2Fcomposer.json\u0026query=%24.require.php\u0026style=flat-square\u0026label=PHP\n\n[link-packagist]: https://packagist.org/packages/tamtamchik/simple-flash\n[link-scrutinizer]: https://scrutinizer-ci.com/g/tamtamchik/simple-flash/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/tamtamchik/simple-flash\n[link-downloads]: https://packagist.org/packages/tamtamchik/simple-flash\n[link-author]: https://github.com/tamtamchik\n[link-contributors]: ../../contributors\n[link-coffee]: https://www.buymeacoffee.com/tamtamchik\n[link-insight]: https://insight.symfony.com/projects/a92cacf2-ba32-4f36-b040-5a9f1d7f8f25\n","funding_links":["https://www.buymeacoffee.com/tamtamchik"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamtamchik%2Fsimple-flash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamtamchik%2Fsimple-flash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamtamchik%2Fsimple-flash/lists"}