add livewire 2 support

This commit is contained in:
Khoubza Younes
2021-08-29 19:21:14 +01:00
parent b4566ce527
commit 1e94cb64a5
23 changed files with 562 additions and 1 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ git tag "$VERSION"
git push origin --tags --force
# Tag Repositories
for REMOTE in flasher flasher-laravel flasher-symfony \
for REMOTE in flasher flasher-laravel flasher-symfony flasher-livewire \
flasher-toastr flasher-toastr-laravel flasher-toastr-symfony \
flasher-notyf flasher-notyf-laravel flasher-notyf-symfony \
flasher-sweet-alert flasher-sweet-alert-laravel flasher-sweet-alert-symfony \
+2
View File
@@ -22,6 +22,7 @@ git pull origin $CURRENT_BRANCH
remote flasher git@github.com:php-flasher/flasher.git
remote laravel git@github.com:php-flasher/flasher-laravel.git
remote symfony git@github.com:php-flasher/flasher-symfony.git
remote livewire git@github.com:php-flasher/flasher-livewire.git
remote toastr git@github.com:php-flasher/flasher-toastr.git
remote toastr-laravel git@github.com:php-flasher/flasher-toastr-laravel.git
@@ -46,6 +47,7 @@ remote noty-symfony git@github.com:php-flasher/flasher-noty-symfony.git
split 'src/Prime' flasher
split 'src/Laravel' laravel
split 'src/Symfony' symfony
split 'src/Livewire' livewire
split 'src/Toastr/Prime' toastr
split 'src/Toastr/Laravel' toastr-laravel
+1
View File
@@ -11,6 +11,7 @@ function remote()
remote flasher git@github.com:php-flasher/flasher.git
remote laravel git@github.com:php-flasher/flasher-laravel.git
remote symfony git@github.com:php-flasher/flasher-symfony.git
remote livewire git@github.com:php-flasher/flasher-livewire.git
remote toastr git@github.com:php-flasher/flasher-toastr.git
remote toastr-laravel git@github.com:php-flasher/flasher-toastr-laravel.git
+15
View File
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
+13
View File
@@ -0,0 +1,13 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
+55
View File
@@ -0,0 +1,55 @@
# Contributing
Contributions are **welcome** and will be fully **credited**.
Please read and understand the contribution guide before creating an issue or pull request.
## Etiquette
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
## Viability
When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.
## Procedure
Before filing an issue:
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.
Before submitting a pull request:
- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
## Requirements
If the project maintainer has any additional requirements, you will find them listed here.
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
**Happy coding**!
+6
View File
@@ -0,0 +1,6 @@
# These are supported funding model platforms
patreon: yoeunes
ko_fi: yoeunes
open_collective: php-flasher
custom: ['https://www.paypal.com/paypalme/yoeunes']
+3
View File
@@ -0,0 +1,3 @@
# Security Policy
If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker.
+7
View File
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
+55
View File
@@ -0,0 +1,55 @@
name: Running tests
on:
push:
pull_request:
schedule:
- cron: '* * * * *'
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
laravel: [8.*, 7.*]
os:
- ubuntu-latest
include:
- laravel: 8.*
testbench: 6.*
php: 7.3
phpunit: 9.3.*
- laravel: 7.*
testbench: 5.*
php: 7.3
phpunit: 8.4.*
name: ${{ matrix.os }} - L${{ matrix.laravel }} - P${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
ini-values: memory_limit=-1
coverage: none
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "orchestra/testbench:${{ matrix.testbench }}" monolog/monolog --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
+5
View File
@@ -0,0 +1,5 @@
.idea
vendor
composer.lock
.phpunit.result.cache
.phpcs-cache
View File
+76
View File
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at younes.khoubza@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Flasher\Livewire;
use Flasher\Prime\Notification\NotificationBuilder;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
final class FlasherLivewireServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*/
public function boot()
{
NotificationBuilder::macro('livewire', function () {
return $this->withStamp(new LivewireStamp());
});
Livewire::listen('component.dehydrate', function ($component, $response) {
$data = $this->app['flasher.response_manager']->render(array(
'stamps' => LivewireStamp::class,
), 'array');
if (count($data['envelopes']) > 0) {
$response->effects['dispatches'][] = [
'event' => 'flasher:render',
'data' => $data,
];
}
});
Blade::directive('flasher_livewire_render', function () {
return "<?php echo app('flasher.livewire_response_manager')->render(); ?>";
});
}
/**
* Register the service provider.
*/
public function register()
{
$this->app->singleton('flasher.livewire_response_manager', function (Application $app) {
return new LivewireResponseManager($app['flasher.config']);
});
}
/**
* Get the services provided by the provider.
*
* @return string[]
*/
public function provides()
{
return array(
'flasher.livewire_response_manager',
);
}
}
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 PHP Flasher
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+45
View File
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Flasher\Livewire;
use Flasher\Prime\Config\ConfigInterface;
final class LivewireResponseManager
{
private $config;
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
public function render(): string
{
$importScript = '';
$rootScript = $this->config->get('root_script');
if (!empty($rootScript)) {
$importScript = <<<JAVASCRIPT
if (!window.Flasher && !document.querySelector('script[src="${rootScript}"]')) {
var tag = document.createElement('script');
tag.setAttribute('src', '${rootScript}');
tag.setAttribute('type', 'text/javascript');
document.body.appendChild(tag);
}
JAVASCRIPT;
}
return <<<JAVASCRIPT
<script type="text/javascript">
${importScript}
window.addEventListener('flasher:render', function (event) {
Flasher.getInstance().render(event.detail);
});
</script>
JAVASCRIPT;
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Flasher\Livewire;
use Flasher\Prime\Stamp\StampInterface;
class LivewireStamp implements StampInterface
{
}
+87
View File
@@ -0,0 +1,87 @@
<p align="center"><img width="600" alt="flasher" src="https://user-images.githubusercontent.com/10859693/102468596-03317180-4052-11eb-9df3-44dc6235b238.png"></p>
<h1 align="center">A powerful and flexible flash notifications system for PHP, Laravel, Symfony</h1>
<p align="center">
:eyes: PHP Flasher helps you to add flash notifications to your PHP projects.
This library was developed with the idea that you should be able to add flash notification to your application with ease and with few lines of code.
No application-wide rewrites and no big investments upfront.
</p>
<p align="center">
<a href="https://github.com/php-flasher/flasher">
<img src="https://img.shields.io/badge/source-php--flasher/flasher-blue.svg?style=flat-square">
</a>
<a href="https://github.com/php-flasher/flasher/releases">
<img src="https://img.shields.io/github/tag/php-flasher/flasher.svg">
</a>
<a href="https://github.com/php-flasher/flasher/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg">
</a>
<a href="https://packagist.org/packages/php-flasher/flasher">
<img src="https://img.shields.io/packagist/dt/php-flasher/flasher.svg">
</a>
<a href="https://packagist.org/packages/php-flasher/flasher">
<img src="https://img.shields.io/packagist/php-v/php-flasher/flasher.svg?style=flat-square">
</a>
<a href="https://opencollective.com/php-flasher">
<img src="https://opencollective.com/php-flasher/tiers/backer/badge.svg?label=backer&color=brightgreen" />
</a>
<a href="https://opencollective.com/php-flasher">
<img src="https://opencollective.com/php-flasher/tiers/sponsor/badge.svg?label=sponsor&color=brightgreen" />
</a>
</p>
# Why use PHP Flasher ?
The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __toastr.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__
and its highly extendable so you can add your custom notifications.
This library is designed, so you can take full control when creating you notifications :
> * Display multiple notifications
> * Sort and filter notifications
> * Render notification from JSON object
> * Limit the number of displayed notifications
> * Show notifications from different libraries at the same time
> * Framework angostic with integration for : Symfony and Laravel
> * Support templates
> * Easy migration from similar libraries.
> * Very flexible so you can add you own adapters
> * ...and more
## Official Documentation
Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.github.io/).
## Backers && Sponsors
Support this project by becoming a sponsor. Your name will show up in the Contribute page of all PHP Flasher installations as well as here with a link to your website!
Thank you to all our backers and sponsors! 🙏
<a href="https://opencollective.com/php-flasher#backers" target="_blank">
<img src="https://opencollective.com/php-flasher/backers.svg?width=890" title="Backers" alt="Backers">
</a>
<a href="https://opencollective.com/php-flasher#sponsors" target="_blank">
<img src="https://opencollective.com/php-flasher/sponsors.svg?width=890" title="Sponsors" alt="Sponsors">
</a>
### Contact
PHP Flasher is being actively developed by <a href="https://github.com/yoeunes">yoeunes</a>. You can reach out with questions, bug reports, or feature requests
on any of the following:
- [Github Issues](https://github.com/php-flasher/flasher/issues)
- [Github](https://github.com/yoeunes)
- [Twitter](https://twitter.com/yoeunes)
- [Linkedin](https://www.linkedin.com/in/younes-khoubza/)
- [Email me directly](mailto:younes.khoubza@gmail.com)
## License
PHP Flasher is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
<p align="center"> <b>Made with ❤️ by <a href="https://www.linkedin.com/in/younes-khoubza/">Younes KHOUBZA</a> <b> </p>
View File
View File
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace {
exit("This file should not be included, only analyzed by your IDE");
}
namespace Flasher\Prime\Notification {
interface NotificationBuilderInterface
{
public function livewire(): self;
}
}
+62
View File
@@ -0,0 +1,62 @@
{
"name": "php-flasher/flasher-livewire",
"description": "Laravel package integrating PHP Flasher into Livewire applications",
"type": "library",
"keywords": [
"yoeunes",
"notify",
"flasher",
"php",
"laravel",
"symfony",
"Lumen",
"notifications",
"messages",
"alerts",
"pnotify",
"toastr ",
"bundle",
"flex",
"livewire"
],
"homepage": "https://php-flasher.github.io/",
"authors": [
{
"name": "Younes Khoubza",
"email": "younes.khoubza@gmail.com",
"homepage": "https://github.com/yoeunes",
"role": "Developer"
}
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"livewire/livewire": "^2.0",
"php-flasher/flasher-laravel": "^0.4.14"
},
"autoload": {
"psr-4": {
"Flasher\\Livewire\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"autoload-dev": {
"psr-4": {
"Flasher\\Livewire\\Tests\\": "Tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Flasher\\Livewire\\FlasherLivewireServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Flasher Test Suite">
<directory>Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
</whitelist>
</filter>
</phpunit>