diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/.github/workflows/laravel.yaml b/.github/workflows/laravel.yaml index 39facb99..e1a915fb 100644 --- a/.github/workflows/laravel.yaml +++ b/.github/workflows/laravel.yaml @@ -1,160 +1,49 @@ -name: Running tests +name: tests on: push: - pull_request: - schedule: - - cron: '* * * * *' jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: fail-fast: true matrix: - laravel: - - 8.* - - 7.* - - 6.* - - 5.8.* - - 5.7.* - - 5.6.* - - 5.5.* - - 5.4.* - - 5.3.* - - 5.2.* - - 5.1.* - - 5.0.* - - 4.2.* - - 4.1.* - - 4.0.* - os: - - ubuntu-latest - # - macos-latest - # - windows-latest + laravel: [ 9.*, 8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*, 5.5.*, 5.4.*, 5.3.*, 5.2.*, 5.1.*, 5.0.*, 4.2.*, 4.1.*, 4.0.* ] include: - - laravel: 8.* - testbench: 6.* - php: 7.3 - phpunit: 9.3.* + - { laravel: 9.*, testbench: 7.*, php: 8.0, phpunit: 9.5.* } + - { laravel: 8.*, testbench: 6.*, php: 7.3, phpunit: 9.3.* } + - { laravel: 7.*, testbench: 5.*, php: 7.3, phpunit: 8.4.* } + - { laravel: 6.*, testbench: 4.*, php: 7.2, phpunit: 8.3.* } + - { laravel: 5.8.*, testbench: 3.8.*, php: 7.1, phpunit: 7.5.* } + - { laravel: 5.7.*, testbench: 3.7.*, php: 7.1, phpunit: 7.0.* } + - { laravel: 5.6.*, testbench: 3.6.*, php: 7.1, phpunit: 7.0.* } + - { laravel: 5.5.*, testbench: 3.5.*, php: 7.0, phpunit: 6.0.* } + - { laravel: 5.4.*, testbench: 3.4.*, php: 5.6, phpunit: 5.7.* } + - { laravel: 5.3.*, testbench: 3.3.*, php: 5.6, phpunit: 4.8.* } + - { laravel: 5.2.*, testbench: 3.2.*, php: 5.5, phpunit: 4.8.* } + - { laravel: 5.1.*, testbench: 3.1.*, php: 5.5, phpunit: 4.8.* } + - { laravel: 5.0.*, testbench: 3.0.*, php: 5.4, phpunit: 4.8.* } + - { laravel: 4.2.*, testbench: 2.2.*, php: 5.4, phpunit: 4.8.* } + - { laravel: 4.1.*, testbench: 2.1.*, php: 5.4, phpunit: 4.8.* } + - { laravel: 4.0.*, testbench: 2.0.*, php: 5.4, phpunit: 4.8.* } - - laravel: 7.* - testbench: 5.* - php: 7.3 - phpunit: 8.4.* - - - laravel: 6.* - testbench: 4.* - php: 7.2 - phpunit: 8.3.* - - - laravel: 5.8.* - testbench: 3.8.* - php: 7.1 - phpunit: 7.5.* - - - laravel: 5.7.* - testbench: 3.7.* - php: 7.1 - phpunit: 7.0.* - - - laravel: 5.6.* - testbench: 3.6.* - php: 7.1 - phpunit: 7.0.* - - - laravel: 5.5.* - testbench: 3.5.* - php: 7.0 - phpunit: 6.0.* - - - laravel: 5.4.* - testbench: 3.4.* - php: 5.6 - phpunit: 5.7.* - - - laravel: 5.3.* - testbench: 3.3.* - php: 5.6 - phpunit: 4.8.* - - - laravel: 5.2.* - testbench: 3.2.* - php: 5.5 - phpunit: 4.8.* - - - laravel: 5.1.* - testbench: 3.1.* - php: 5.5 - phpunit: 4.8.* - - - laravel: 5.0.* - testbench: 3.0.* - php: 5.4 - phpunit: 4.8.* - - - laravel: 4.2.* - testbench: 2.2.* - php: 5.4 - phpunit: 4.8.* - - - laravel: 4.1.* - testbench: 2.1.* - php: 5.4 - phpunit: 4.8.* - - - laravel: 4.0.* - testbench: 2.0.* - php: 5.4 - phpunit: 4.8.* - - name: ${{ matrix.os }} - L${{ matrix.laravel }} - P${{ matrix.php }} + name: laravel[${{ matrix.laravel }}] php[${{ 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') }} + uses: actions/checkout@v2 - 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 }}" --no-interaction --no-update - composer update --prefer-dist --no-interaction --no-suggest + composer remove friendsofphp/php-cs-fixer laravel/laravel livewire/livewire phpstan/phpstan symfony/symfony orchestra/testbench phpunit/phpunit --dev + composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction - name: Execute tests run: vendor/bin/phpunit --configuration=phpunit-laravel.xml - - - name: Install Flasher Depencies - run: | - composer require "php-flasher/flasher:^0.9" - composer require "php-flasher/flasher-laravel:^0.9" - - composer require "php-flasher/flasher-cli:^0.9" - composer require "php-flasher/flasher-cli-laravel:^0.9" - - composer require "php-flasher/flasher-toastr:^0.9" - composer require "php-flasher/flasher-toastr-laravel:^0.9" - - composer require "php-flasher/flasher-noty:^0.9" - composer require "php-flasher/flasher-noty-laravel:^0.9" - - composer require "php-flasher/flasher-notyf:^0.9" - composer require "php-flasher/flasher-notyf-laravel:^0.9" - - composer require "php-flasher/flasher-sweet-alert:^0.9" - composer require "php-flasher/flasher-sweet-alert-laravel:^0.9" - - composer require "php-flasher/flasher-pnotify:^0.9" - composer require "php-flasher/flasher-pnotify-laravel:^0.9" diff --git a/.github/workflows/split_monorepo.yaml b/.github/workflows/split_monorepo.yaml new file mode 100644 index 00000000..06bbd3dd --- /dev/null +++ b/.github/workflows/split_monorepo.yaml @@ -0,0 +1,78 @@ +name: Split Monorepo + +on: + push: + branches: + - main + tags: + - '*' + +jobs: + split_monorepo: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: + - { path: 'src/Prime', repo: 'flasher' } + - { path: 'src/Laravel', repo: 'flasher-laravel' } + - { path: 'src/Symfony', repo: 'flasher-symfony' } + + - { path: 'src/Cli/Prime', repo: 'flasher-cli' } + - { path: 'src/Cli/Laravel', repo: 'flasher-cli-laravel' } + - { path: 'src/Cli/Symfony', repo: 'flasher-cli-symfony' } + + - { path: 'src/Noty/Prime', repo: 'flasher-noty' } + - { path: 'src/Noty/Laravel', repo: 'flasher-noty-laravel' } + - { path: 'src/Noty/Symfony', repo: 'flasher-noty-symfony' } + + - { path: 'src/Notyf/Prime', repo: 'flasher-notyf' } + - { path: 'src/Notyf/Laravel', repo: 'flasher-notyf-laravel' } + - { path: 'src/Notyf/Symfony', repo: 'flasher-notyf-symfony' } + + - { path: 'src/Pnotify/Prime', repo: 'flasher-pnotify' } + - { path: 'src/Pnotify/Laravel', repo: 'flasher-pnotify-laravel' } + - { path: 'src/Pnotify/Symfony', repo: 'flasher-pnotify-symfony' } + + - { path: 'src/SweetAlert/Prime', repo: 'flasher-sweetalert' } + - { path: 'src/SweetAlert/Laravel', repo: 'flasher-sweetalert-laravel' } + - { path: 'src/SweetAlert/Symfony', repo: 'flasher-sweetalert-symfony' } + + - { path: 'src/Toastr/Prime', repo: 'flasher-toastr' } + - { path: 'src/Toastr/Laravel', repo: 'flasher-toastr-laravel' } + - { path: 'src/Toastr/Symfony', repo: 'flasher-toastr-symfony' } + + - { path: 'packs/php-pack', repo: 'php-pack' } + - { path: 'packs/laravel-pack', repo: 'laravel-pack' } + - { path: 'packs/symfony-pack', repo: 'symfony-pack' } + + steps: + - uses: actions/checkout@v2 + + - if: "!startsWith(github.ref, 'refs/tags/')" + name: Monorepo Split of ${{ matrix.package }} + uses: symplify/github-action-monorepo-split@2.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + package-directory: '${{ matrix.package.path }}' + split-repository-organization: 'php-flasher' + split-repository-name: '${{ matrix.package.repo }}' + user-name: "Younes KHOUBZA" + user-email: "younes.khoubza@gmail.com" + branch: main + + - if: "startsWith(github.ref, 'refs/tags/')" + name: Monorepo Tagged Split of ${{ matrix.package }} + uses: symplify/github-action-monorepo-split@2.0 + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + with: + tag: ${GITHUB_REF#refs/tags/} + + package-directory: 'src/${{ matrix.package.path }}' + split-repository-organization: 'php-flasher' + split-repository-name: '${{ matrix.package.repo }}' + user-name: "Younes KHOUBZA" + user-email: "younes.khoubza@gmail.com" + branch: main diff --git a/.github/workflows/symfony.yaml b/.github/workflows/symfony.yaml index 5c833c92..4747c0d7 100644 --- a/.github/workflows/symfony.yaml +++ b/.github/workflows/symfony.yaml @@ -1,191 +1,59 @@ -name: Running tests +name: tests on: push: - pull_request: - schedule: - - cron: '* * * * *' jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: fail-fast: true matrix: - symfony: - - 5.4.* - - 5.3.* - - 5.2.* - - 5.1.* - - 5.0.* - - 4.4.* - - 4.3.* - - 4.2.* - - 4.1.* - - 4.0.* - - 3.4.* - - 3.3.* - - 3.2.* - - 3.1.* - - 3.0.* - - 2.8.* - - 2.7.* - - 2.6.* - - 2.5.* - - 2.4.* - - 2.3.* - - 2.2.* - - 2.1.* - - 2.0.* - os: - - ubuntu-latest - # - macos-latest - # - windows-latest + symfony: [ 6.0.*, 5.4.*, 5.3.*, 5.2.*, 5.1.*, 5.0.*, 4.4.*, 4.3.*, 4.2.*, 4.1.*, 4.0.*, 3.4.*, 3.3.*, 3.2.*, 3.1.*, 3.0.*, 2.8.*, 2.7.*, 2.6.*, 2.5.*, 2.4.*, 2.3.*, 2.2.*, 2.1.*, 2.0.* ] include: - - symfony: 5.4.* - php: 7.2 - phpunit: 8.3.* + - { symfony: 6.0.*, php: 8.0, phpunit: 9.5.* } + - { symfony: 5.4.*, php: 7.2, phpunit: 8.3.* } + - { symfony: 5.3.*, php: 7.2, phpunit: 8.3.* } + - { symfony: 5.2.*, php: 7.2, phpunit: 8.3.* } + - { symfony: 5.1.*, php: 7.2, phpunit: 8.3.* } + - { symfony: 5.0.*, php: 7.2, phpunit: 8.3.* } + - { symfony: 4.4.*, php: 7.1, phpunit: 7.0.* } + - { symfony: 4.3.*, php: 7.1, phpunit: 7.0.* } + - { symfony: 4.2.*, php: 7.1, phpunit: 7.0.* } + - { symfony: 4.1.*, php: 7.1, phpunit: 7.0.* } + - { symfony: 4.0.*, php: 7.1, phpunit: 7.0.* } + - { symfony: 3.4.*, php: 5.5, phpunit: 4.8.36 } + - { symfony: 3.3.*, php: 5.5, phpunit: 4.8.36 } + - { symfony: 3.2.*, php: 5.5, phpunit: 4.8.36 } + - { symfony: 3.1.*, php: 5.5, phpunit: 4.8.36 } + - { symfony: 3.0.*, php: 5.5, phpunit: 4.8.36 } + - { symfony: 2.8.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.7.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.6.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.5.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.4.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.3.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.2.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.1.*, php: 5.3, phpunit: 4.8.36 } + - { symfony: 2.0.*, php: 5.3, phpunit: 4.8.36 } - - symfony: 5.3.* - php: 7.2 - phpunit: 8.3.* - - - symfony: 5.2.* - php: 7.2 - phpunit: 8.3.* - - - symfony: 5.1.* - php: 7.2 - phpunit: 8.3.* - - - symfony: 5.0.* - php: 7.2 - phpunit: 8.3.* - - - symfony: 4.4.* - php: 7.1 - phpunit: 7.0.* - - - symfony: 4.3.* - php: 7.1 - phpunit: 7.0.* - - - symfony: 4.2.* - php: 7.1 - phpunit: 7.0.* - - - symfony: 4.1.* - php: 7.1 - phpunit: 7.0.* - - - symfony: 4.0.* - php: 7.1 - phpunit: 7.0.* - - - symfony: 3.4.* - php: 5.5 - phpunit: 4.8.36 - - - symfony: 3.3.* - php: 5.5 - phpunit: 4.8.36 - - - symfony: 3.2.* - php: 5.5 - phpunit: 4.8.36 - - - symfony: 3.1.* - php: 5.5 - phpunit: 4.8.36 - - - symfony: 3.0.* - php: 5.5 - phpunit: 4.8.36 - - - symfony: 2.8.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.7.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.6.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.5.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.4.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.3.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.2.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.1.* - php: 5.3 - phpunit: 4.8.36 - - - symfony: 2.0.* - php: 5.3 - phpunit: 4.8.36 - - name: ${{ matrix.os }} - S${{ matrix.symfony }} - P${{ matrix.php }} + name: symfony[${{ matrix.symfony }}] php[${{ matrix.php }}] steps: - name: Checkout code - uses: actions/checkout@v1 - - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache/files - key: dependencies-symfony-${{ matrix.symfony }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + uses: actions/checkout@v2 - 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 coverage: none - name: Install dependencies run: | - composer require "symfony/symfony:${{ matrix.symfony }}" "phpunit/phpunit:${{ matrix.phpunit }}" twig/twig --no-interaction --no-update + composer remove friendsofphp/php-cs-fixer laravel/laravel livewire/livewire phpstan/phpstan symfony/symfony orchestra/testbench phpunit/phpunit --dev composer config extra.symfony.require "${{ matrix.symfony }}" - composer update --prefer-dist --no-interaction --no-suggest + composer require "symfony/symfony:${{ matrix.symfony }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction - name: Execute tests run: vendor/bin/phpunit --configuration=phpunit-symfony.xml - - - name: Install Flasher Depencies - run: | - composer require "php-flasher/flasher:^0.9" - composer require "php-flasher/flasher-laravel:^0.9" - composer require "php-flasher/flasher-symfony:^0.9" - - composer require "php-flasher/flasher-cli:^0.9" - composer require "php-flasher/flasher-cli-symfony:^0.9" - - composer require "php-flasher/flasher-toastr:^0.9" - composer require "php-flasher/flasher-toastr-symfony:^0.9" - - composer require "php-flasher/flasher-noty:^0.9" - composer require "php-flasher/flasher-noty-symfony:^0.9" - - composer require "php-flasher/flasher-notyf:^0.9" - composer require "php-flasher/flasher-notyf-symfony:^0.9" - - composer require "php-flasher/flasher-sweet-alert:^0.9" - composer require "php-flasher/flasher-sweet-alert-symfony:^0.9" - - composer require "php-flasher/flasher-pnotify:^0.9" - composer require "php-flasher/flasher-pnotify-symfony:^0.9" diff --git a/.gitignore b/.gitignore index 89d72688..e609f21d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ vendor composer.lock .phpunit.result.cache .phpcs-cache +.php-cs-fixer.cache + +packs/**/composer.lock +packs/**/vendor/ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..cb2a8152 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,66 @@ + + */ + +if (!file_exists(__DIR__.'/src')) { + exit(0); +} + +$header = <<<'EOF' +This file is part of the PHPFlasher package. +(c) Younes KHOUBZA +EOF; + +$rules = array( + '@PSR12' => true, + '@PSR12:risky' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + '@PhpCsFixer' => true, + '@PhpCsFixer:risky' => true, + 'header_comment' => array('header' => $header), + 'array_syntax' => array('syntax' => 'long'), + 'ordered_imports' => array( + 'sort_algorithm' => 'alpha', + 'imports_order' => array('const', 'class', 'function'), + ), + 'no_extra_blank_lines' => array( + 'tokens' => array('case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw'), + ), + 'function_to_constant' => false, + 'visibility_required' => array('elements' => array('property', 'method')), + 'self_accessor' => false, + 'single_trait_insert_per_statement' => true, + 'linebreak_after_opening_tag' => true, + 'no_php4_constructor' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'phpdoc_order' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'phpdoc_line_span' => true, + 'php_unit_internal_class' => false, + 'php_unit_test_class_requires_covers' => false, + 'multiline_whitespace_before_semicolons' => false, + 'method_chaining_indentation' => false, + 'phpdoc_no_empty_return' => false, + 'phpdoc_types_order' => array('null_adjustment' => 'always_last'), + 'php_unit_test_case_static_method_calls' => array('call_type' => 'this'), + 'php_unit_strict' => false, + 'native_constant_invocation' => array('scope' => 'namespaced'), + 'phpdoc_return_self_reference' => true, +); + +$finder = new PhpCsFixer\Finder(); +$finder->in(__DIR__)->exclude(__DIR__.'/vendor'); + +$config = new PhpCsFixer\Config(); + +return $config->setFinder($finder) + ->setUsingCache(false) + ->setRiskyAllowed(true) + ->setRules($rules); diff --git a/.shared/.github/workflows/auto_closer.yaml b/.shared/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/.shared/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..567e05ca --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +include make/variables.mk +include make/help.mk +include make/composer.mk +include make/lint.mk diff --git a/README.md b/README.md index 5714d7d7..70048b42 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/bin/copy b/bin/copy new file mode 100755 index 00000000..b3b9d3a4 --- /dev/null +++ b/bin/copy @@ -0,0 +1,53 @@ +#!/usr/bin/env php +getPathname()) + : $dest .'/'. $file->getFilename(); + + if ($file->isDir()) { + system('rm -rf -- ' . escapeshellarg($dest)); + @mkdir(dirname($target), 0777, true); + continue; + } + + @mkdir(dirname($target), 0777, true); + @copy($file->getPathname(), $target); + } + } +} diff --git a/bin/release.sh b/bin/release.sh deleted file mode 100755 index 5efca36f..00000000 --- a/bin/release.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Make sure the release tag is provided. -if (( "$#" != 1 )) -then - echo "Tag has to be provided." - - exit 1 -fi - -RELEASE_BRANCH="main" -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -VERSION=$1 - -# Make sure current branch and release branch match. -if [[ "$RELEASE_BRANCH" != "$CURRENT_BRANCH" ]] -then - echo "Release branch ($RELEASE_BRANCH) does not match the current active branch ($CURRENT_BRANCH)." - - exit 1 -fi - -# Make sure the working directory is clear. -if [[ ! -z "$(git status --porcelain)" ]] -then - echo "Your working directory is dirty. Did you forget to commit your changes?" - - exit 1 -fi - -# Make sure latest changes are fetched first. -git fetch origin - -# Make sure that release branch is in sync with origin. -if [[ $(git rev-parse HEAD) != $(git rev-parse origin/$RELEASE_BRANCH) ]] -then - echo "Your branch is out of date with its upstream. Did you forget to pull or push any changes before releasing?" - - exit 1 -fi - -# Always prepend with "v" -if [[ $VERSION != v* ]] -then - VERSION="v$VERSION" -fi - -# Tag PHP Flasher -git tag "$VERSION" -git push origin --tags --force - -# Tag Repositories -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 \ - flasher-pnotify flasher-pnotify-laravel flasher-pnotify-symfony \ - flasher-noty flasher-noty-laravel flasher-noty-symfony \ - flasher-cli flasher-cli-laravel flasher-cli-symfony \ - laravel-pack livewire-pack php-pack symfony-pack -do - echo "" - echo "" - echo "Releasing $REMOTE"; - - TMP_DIR="/tmp/php-flasher" - REMOTE_URL="git@github.com:php-flasher/$REMOTE.git" - - rm -rf $TMP_DIR; - mkdir $TMP_DIR; - - ( - cd $TMP_DIR; - - git clone $REMOTE_URL . - git checkout "$RELEASE_BRANCH"; - - git tag "$VERSION" - git push origin --tags - ) -done diff --git a/bin/split.sh b/bin/split.sh deleted file mode 100755 index cd1d2c0c..00000000 --- a/bin/split.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x - -CURRENT_BRANCH="main" - -function split() -{ -# git merge --strategy recursive --strategy-option subtree="$1" "$2/$CURRENT_BRANCH" --allow-unrelated-histories -m "Merge remote-tracking branch '$2/$CURRENT_BRANCH'" - SHA1=$(./bin/splitsh-lite --prefix="$1") - git push $2 "$SHA1:refs/heads/$CURRENT_BRANCH" -f -} - -function remote() -{ - git remote add "$1" "$2" || true -} - -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 -remote toastr-symfony git@github.com:php-flasher/flasher-toastr-symfony.git - -remote notyf git@github.com:php-flasher/flasher-notyf.git -remote notyf-laravel git@github.com:php-flasher/flasher-notyf-laravel.git -remote notyf-symfony git@github.com:php-flasher/flasher-notyf-symfony.git - -remote sweet-alert git@github.com:php-flasher/flasher-sweet-alert.git -remote sweet-alert-laravel git@github.com:php-flasher/flasher-sweet-alert-laravel.git -remote sweet-alert-symfony git@github.com:php-flasher/flasher-sweet-alert-symfony.git - -remote pnotify git@github.com:php-flasher/flasher-pnotify.git -remote pnotify-laravel git@github.com:php-flasher/flasher-pnotify-laravel.git -remote pnotify-symfony git@github.com:php-flasher/flasher-pnotify-symfony.git - -remote noty git@github.com:php-flasher/flasher-noty.git -remote noty-laravel git@github.com:php-flasher/flasher-noty-laravel.git -remote noty-symfony git@github.com:php-flasher/flasher-noty-symfony.git - -remote cli git@github.com:php-flasher/flasher-cli.git -remote cli-laravel git@github.com:php-flasher/flasher-cli-laravel.git -remote cli-symfony git@github.com:php-flasher/flasher-cli-symfony.git - -remote laravel-pack git@github.com:php-flasher/laravel-pack.git -remote livewire-pack git@github.com:php-flasher/livewire-pack.git -remote php-pack git@github.com:php-flasher/php-pack.git -remote symfony-pack git@github.com:php-flasher/symfony-pack.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 -split 'src/Toastr/Symfony' toastr-symfony - -split 'src/Notyf/Prime' notyf -split 'src/Notyf/Laravel' notyf-laravel -split 'src/Notyf/Symfony' notyf-symfony - -split 'src/SweetAlert/Prime' sweet-alert -split 'src/SweetAlert/Laravel' sweet-alert-laravel -split 'src/SweetAlert/Symfony' sweet-alert-symfony - -split 'src/Pnotify/Prime' pnotify -split 'src/Pnotify/Laravel' pnotify-laravel -split 'src/Pnotify/Symfony' pnotify-symfony - -split 'src/Noty/Prime' noty -split 'src/Noty/Laravel' noty-laravel -split 'src/Noty/Symfony' noty-symfony - -split 'packs/laravel-pack' laravel-pack -split 'packs/livewire-pack' livewire-pack -split 'packs/php-pack' php-pack -split 'packs/symfony-pack' symfony-pack diff --git a/bin/splitsh-lite b/bin/splitsh-lite deleted file mode 100755 index ddefe95a..00000000 Binary files a/bin/splitsh-lite and /dev/null differ diff --git a/composer.json b/composer.json old mode 100755 new mode 100644 index 5ea3d43e..5db76790 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { "name": "php-flasher/php-flasher", - "description": "All flasher components in one place for easy maintenance with splitsh", + "description": "Repository for PHPFlasher development", "type": "project", "license": "MIT", "authors": [ { - "name": "KHOUBZA Younes", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -16,25 +16,102 @@ "ext-json": "*", "ext-mbstring": "*" }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8", + "laravel/laravel": "^9.1", + "livewire/livewire": "^2.10", + "orchestra/testbench": "^7.5", + "phpstan/phpstan": "^1.6", + "phpunit/phpunit": "^9.5", + "symfony/symfony": "^6.0" + }, "autoload": { - "psr-4": { - "Flasher\\": "src/" - }, "files": [ - "src/Prime/helpers.php", - "src/Laravel/helpers.php", - "src/Toastr/Laravel/Resources/functions/toastr.php", - "src/Noty/Laravel/Resources/functions/noty.php", - "src/Notyf/Laravel/Resources/functions/notyf.php", - "src/Pnotify/Laravel/Resources/functions/pnotify.php", - "src/SweetAlert/Laravel/Resources/functions/sweetAlert.php", - "src/Cli/Laravel/Resources/functions/cli.php" - ] + "src/Cli/Laravel/notify.php", + "src/Laravel/flasher.php", + "src/Noty/Laravel/noty.php", + "src/Notyf/Laravel/notyf.php", + "src/Pnotify/Laravel/pnotify.php", + "src/SweetAlert/Laravel/sweetalert.php", + "src/Toastr/Laravel/toastr.php" + ], + "psr-4": { + "Flasher\\": "src/", + "Flasher\\Cli\\Laravel\\": "src/Cli/Laravel/", + "Flasher\\Cli\\Prime\\": "src/Cli/Prime/", + "Flasher\\Cli\\Symfony\\": "src/Cli/Symfony/", + "Flasher\\Laravel\\": "src/Laravel/", + "Flasher\\Noty\\Laravel\\": "src/Noty/Laravel/", + "Flasher\\Noty\\Prime\\": "src/Noty/Prime/", + "Flasher\\Noty\\Symfony\\": "src/Noty/Symfony/", + "Flasher\\Notyf\\Laravel\\": "src/Notyf/Laravel/", + "Flasher\\Notyf\\Prime\\": "src/Notyf/Prime/", + "Flasher\\Notyf\\Symfony\\": "src/Notyf/Symfony/", + "Flasher\\Pnotify\\Laravel\\": "src/Pnotify/Laravel/", + "Flasher\\Pnotify\\Prime\\": "src/Pnotify/Prime/", + "Flasher\\Pnotify\\Symfony\\": "src/Pnotify/Symfony/", + "Flasher\\Prime\\": "src/Prime/", + "Flasher\\SweetAlert\\Laravel\\": "src/SweetAlert/Laravel/", + "Flasher\\SweetAlert\\Prime\\": "src/SweetAlert/Prime/", + "Flasher\\SweetAlert\\Symfony\\": "src/SweetAlert/Symfony/", + "Flasher\\Symfony\\": "src/Symfony/", + "Flasher\\Toastr\\Laravel\\": "src/Toastr/Laravel/", + "Flasher\\Toastr\\Prime\\": "src/Toastr/Prime/", + "Flasher\\Toastr\\Symfony\\": "src/Toastr/Symfony/" + } }, "autoload-dev": { "psr-4": { "Flasher\\Tests\\": "tests/" } }, - "minimum-stability": "dev" + "extra": { + "laravel": { + "providers": [ + "Flasher\\Cli\\Laravel\\FlasherCliServiceProvider", + "Flasher\\Toastr\\Laravel\\FlasherToastrServiceProvider", + "Flasher\\Laravel\\FlasherServiceProvider", + "Flasher\\Noty\\Laravel\\FlasherNotyServiceProvider", + "Flasher\\Pnotify\\Laravel\\FlasherPnotifyServiceProvider", + "Flasher\\Notyf\\Laravel\\FlasherNotyfServiceProvider", + "Flasher\\SweetAlert\\Laravel\\FlasherSweetAlertServiceProvider" + ], + "aliases": { + "Toastr": "Flasher\\Toastr\\Laravel\\Facade\\Toastr", + "Flasher": "Flasher\\Laravel\\Facade\\Flasher", + "Noty": "Flasher\\Laravel\\Facade\\Flasher", + "Pnotify": "Flasher\\Pnotify\\Laravel\\Facade\\Pnotify", + "Notyf": "Flasher\\Notyf\\Laravel\\Facade\\Notyf", + "SweetAlert": "Flasher\\SweetAlert\\Laravel\\Facade\\SweetAlert" + } + } + }, + "replace": { + "php-flasher/flasher": "self.version", + "php-flasher/flasher-cli": "self.version", + "php-flasher/flasher-cli-laravel": "self.version", + "php-flasher/flasher-cli-symfony": "self.version", + "php-flasher/flasher-laravel": "self.version", + "php-flasher/flasher-noty": "self.version", + "php-flasher/flasher-noty-laravel": "self.version", + "php-flasher/flasher-noty-symfony": "self.version", + "php-flasher/flasher-notyf": "self.version", + "php-flasher/flasher-notyf-laravel": "self.version", + "php-flasher/flasher-notyf-symfony": "self.version", + "php-flasher/flasher-pnotify": "self.version", + "php-flasher/flasher-pnotify-laravel": "self.version", + "php-flasher/flasher-pnotify-symfony": "self.version", + "php-flasher/flasher-sweetalert": "self.version", + "php-flasher/flasher-sweetalert-laravel": "self.version", + "php-flasher/flasher-sweetalert-symfony": "self.version", + "php-flasher/flasher-symfony": "self.version", + "php-flasher/flasher-toastr": "self.version", + "php-flasher/flasher-toastr-laravel": "self.version", + "php-flasher/flasher-toastr-symfony": "self.version" + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "stable", + "prefer-stable": true } diff --git a/make/composer.mk b/make/composer.mk new file mode 100644 index 00000000..2aa0b76c --- /dev/null +++ b/make/composer.mk @@ -0,0 +1,9 @@ +.PHONY: install update + +## 🧙‍ Installs the project dependencies and assets +install: composer.lock + $(COMPOSER) install $(COMPOSER_ARGS) + +## Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. +update: + $(COMPOSER) update --lock $(COMPOSER_ARGS) diff --git a/make/help.mk b/make/help.mk new file mode 100644 index 00000000..36f3c58e --- /dev/null +++ b/make/help.mk @@ -0,0 +1,27 @@ +.PHONY: help + +COLOR_RESET = \033[0m +COLOR_INFO = \033[32m +COLOR_COMMENT = \033[33m + +## Help +help: + @printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n" + @printf " make [target]\n\n" + @printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n" + @awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \ + helpMessage = match(lastLine, /^## (.*)/); \ + if (helpMessage) { \ + helpCommand = substr($$1, 0, index($$1, ":")); \ + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ + printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ + } \ + } \ + { lastLine = $$0 }' $(MAKEFILE_LIST) + +check_defined = \ + $(strip $(foreach 1,$1, \ + $(call __check_defined,$1,$(strip $(value 2))))) +__check_defined = \ + $(if $(value $1),, \ + $(error Undefined $1$(if $2, ($2)))) diff --git a/make/lint.mk b/make/lint.mk new file mode 100644 index 00000000..9c4fd691 --- /dev/null +++ b/make/lint.mk @@ -0,0 +1,11 @@ +.PHONY: lint fix + +## Run code style, linters +lint: + test `find ./src -iname "*.php" | xargs -n1 -P6 php -l | grep -Fv "No syntax errors" | wc -l` -eq 0 + $(PHP_CS_FIXER) fix --diff --dry-run -v + $(COMPOSER) validate --strict + +## Fix files with php-cs-fixer +fix: + $(PHP_CS_FIXER) fix --allow-risky=yes diff --git a/make/variables.mk b/make/variables.mk new file mode 100644 index 00000000..1feb946d --- /dev/null +++ b/make/variables.mk @@ -0,0 +1,12 @@ +# Executables +EXEC_PHP = php +COMPOSER = composer + +# Parameters +COMPOSER_ARGS ?= + +# Executables: vendors +PHP_CS_FIXER = ./vendor/bin/php-cs-fixer + +# Misc +.DEFAULT_GOAL = help diff --git a/monorepo-builder.php b/monorepo-builder.php new file mode 100644 index 00000000..bcb9c289 --- /dev/null +++ b/monorepo-builder.php @@ -0,0 +1,36 @@ + + */ + +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\AddTagToChangelogReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\PushNextDevReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\SetCurrentMutualDependenciesReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\SetNextMutualDependenciesReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\UpdateBranchAliasReleaseWorker; +use Symplify\MonorepoBuilder\Release\ReleaseWorker\UpdateReplaceReleaseWorker; +use Symplify\MonorepoBuilder\ValueObject\Option; + +return static function (ContainerConfigurator $containerConfigurator): void { + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::PACKAGE_DIRECTORIES, array( + __DIR__.'/src', + )); + + $services = $containerConfigurator->services(); + $services->set(UpdateReplaceReleaseWorker::class); + $services->set(SetCurrentMutualDependenciesReleaseWorker::class); + $services->set(AddTagToChangelogReleaseWorker::class); + $services->set(TagVersionReleaseWorker::class); + $services->set(PushTagReleaseWorker::class); + $services->set(SetNextMutualDependenciesReleaseWorker::class); + $services->set(UpdateBranchAliasReleaseWorker::class); + $services->set(PushNextDevReleaseWorker::class); +}; diff --git a/src/Livewire/.github/FUNDING.yml b/packs/laravel-pack/.github/FUNDING.yml similarity index 70% rename from src/Livewire/.github/FUNDING.yml rename to packs/laravel-pack/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Livewire/.github/FUNDING.yml +++ b/packs/laravel-pack/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/packs/laravel-pack/.github/workflows/auto_closer.yaml b/packs/laravel-pack/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/packs/laravel-pack/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Livewire/README.md b/packs/laravel-pack/README.md similarity index 74% rename from src/Livewire/README.md rename to packs/laravel-pack/README.md index 5714d7d7..70048b42 100644 --- a/src/Livewire/README.md +++ b/packs/laravel-pack/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/packs/laravel-pack/composer.json b/packs/laravel-pack/composer.json index e9b93141..807f5829 100644 --- a/packs/laravel-pack/composer.json +++ b/packs/laravel-pack/composer.json @@ -5,9 +5,9 @@ "license": "MIT", "authors": [ { - "name": "KHOUBZA Younes", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -16,7 +16,7 @@ "php-flasher/flasher-noty-laravel": "*", "php-flasher/flasher-notyf-laravel": "*", "php-flasher/flasher-pnotify-laravel": "*", - "php-flasher/flasher-sweet-alert-laravel": "*", + "php-flasher/flasher-sweetalert-laravel": "*", "php-flasher/flasher-toastr-laravel": "*" } } diff --git a/packs/livewire-pack/LICENSE b/packs/livewire-pack/LICENSE deleted file mode 100644 index 8d26d89b..00000000 --- a/packs/livewire-pack/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -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. diff --git a/packs/livewire-pack/composer.json b/packs/livewire-pack/composer.json deleted file mode 100644 index daa228ff..00000000 --- a/packs/livewire-pack/composer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "php-flasher/livewire-pack", - "description": "A pack for Livewire", - "type": "flasher-pack", - "license": "MIT", - "authors": [ - { - "name": "KHOUBZA Younes", - "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", - "role": "Developer" - } - ], - "require": { - "php-flasher/laravel-pack": "*", - "php-flasher/flasher-livewire": "*" - } -} diff --git a/packs/php-pack/.github/FUNDING.yml b/packs/php-pack/.github/FUNDING.yml new file mode 100644 index 00000000..7de85ae3 --- /dev/null +++ b/packs/php-pack/.github/FUNDING.yml @@ -0,0 +1,4 @@ +patreon: yoeunes +ko_fi: yoeunes +open_collective: php-flasher +custom: ['https://www.paypal.com/paypalme/yoeunes'] diff --git a/packs/php-pack/.github/workflows/auto_closer.yaml b/packs/php-pack/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/packs/php-pack/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/packs/php-pack/README.md b/packs/php-pack/README.md new file mode 100644 index 00000000..70048b42 --- /dev/null +++ b/packs/php-pack/README.md @@ -0,0 +1,67 @@ +

flasher

+ +

A powerful and flexible flash notifications system for PHP, Laravel, Symfony

+ +

+ :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. +

+ +

+ + + + + + + + + + + + + + + +

+ +# 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.io). + +### Contact + +PHP Flasher is being actively developed by yoeunes. 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). + +

Made with ❤️ by Younes KHOUBZA

diff --git a/packs/php-pack/composer.json b/packs/php-pack/composer.json index beb890be..a3341acc 100644 --- a/packs/php-pack/composer.json +++ b/packs/php-pack/composer.json @@ -5,9 +5,9 @@ "license": "MIT", "authors": [ { - "name": "KHOUBZA Younes", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -16,7 +16,7 @@ "php-flasher/flasher-noty": "*", "php-flasher/flasher-notyf": "*", "php-flasher/flasher-pnotify": "*", - "php-flasher/flasher-sweet-alert": "*", + "php-flasher/flasher-sweetalert": "*", "php-flasher/flasher-toastr": "*" } } diff --git a/packs/symfony-pack/.github/FUNDING.yml b/packs/symfony-pack/.github/FUNDING.yml new file mode 100644 index 00000000..7de85ae3 --- /dev/null +++ b/packs/symfony-pack/.github/FUNDING.yml @@ -0,0 +1,4 @@ +patreon: yoeunes +ko_fi: yoeunes +open_collective: php-flasher +custom: ['https://www.paypal.com/paypalme/yoeunes'] diff --git a/packs/symfony-pack/.github/workflows/auto_closer.yaml b/packs/symfony-pack/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/packs/symfony-pack/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/packs/symfony-pack/README.md b/packs/symfony-pack/README.md new file mode 100644 index 00000000..70048b42 --- /dev/null +++ b/packs/symfony-pack/README.md @@ -0,0 +1,67 @@ +

flasher

+ +

A powerful and flexible flash notifications system for PHP, Laravel, Symfony

+ +

+ :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. +

+ +

+ + + + + + + + + + + + + + + +

+ +# 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.io). + +### Contact + +PHP Flasher is being actively developed by yoeunes. 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). + +

Made with ❤️ by Younes KHOUBZA

diff --git a/packs/symfony-pack/composer.json b/packs/symfony-pack/composer.json index f7a13fce..ee932fc5 100644 --- a/packs/symfony-pack/composer.json +++ b/packs/symfony-pack/composer.json @@ -5,9 +5,9 @@ "license": "MIT", "authors": [ { - "name": "KHOUBZA Younes", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -16,7 +16,7 @@ "php-flasher/flasher-noty-symfony": "*", "php-flasher/flasher-notyf-symfony": "*", "php-flasher/flasher-pnotify-symfony": "*", - "php-flasher/flasher-sweet-alert-symfony": "*", + "php-flasher/flasher-sweetalert-symfony": "*", "php-flasher/flasher-toastr-symfony": "*" } } diff --git a/phpstan.neon b/phpstan.neon index 28c90543..f61f464a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,6 @@ parameters: + level: 9 paths: - - src/Prime - - src/Laravel - level: 8 - excludes_analyse: - - vendor/* + - src + excludePaths: + - src/Symfony/Bridge/ diff --git a/phpunit-laravel.xml b/phpunit-laravel.xml index f332bb05..e087e31a 100644 --- a/phpunit-laravel.xml +++ b/phpunit-laravel.xml @@ -1,36 +1,17 @@ - - - - src/ - - + - - tests/Prime - + tests/Prime tests/Laravel - - tests/Toastr/Laravel - - - tests/Notyf/Laravel - - - tests/SweetAlert/Laravel - - - tests/Pnotify/Laravel - - - tests/Noty/Laravel - diff --git a/phpunit-symfony.xml b/phpunit-symfony.xml index ba50bca5..c5a9cded 100644 --- a/phpunit-symfony.xml +++ b/phpunit-symfony.xml @@ -1,36 +1,16 @@ - - - - src/ - - + - - tests/Prime - + tests/Prime tests/Symfony - - tests/Toastr/Symfony - - - tests/Notyf/Symfony - - - tests/SweetAlert/Symfony - - - tests/Pnotify/Symfony - - - tests/Noty/Symfony - diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 320afbcd..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - src/ - - - - - tests - - - diff --git a/src/Cli/Laravel/.editorconfig b/src/Cli/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Cli/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Cli/Laravel/.gitattributes b/src/Cli/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Cli/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Cli/Laravel/.github/CONTRIBUTING.md b/src/Cli/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Cli/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Cli/Laravel/.github/FUNDING.yml b/src/Cli/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Cli/Laravel/.github/FUNDING.yml +++ b/src/Cli/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Cli/Laravel/.github/SECURITY.md b/src/Cli/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Cli/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Cli/Laravel/.github/dependabot.yml b/src/Cli/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Cli/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Cli/Laravel/.github/workflows/auto_closer.yaml b/src/Cli/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Cli/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Cli/Laravel/.github/workflows/close-pull-request.yml b/src/Cli/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Cli/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Cli/Laravel/.gitignore b/src/Cli/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Cli/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Cli/Laravel/.phpstorm.meta.php b/src/Cli/Laravel/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Cli/Laravel/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ - + */ + namespace Flasher\Cli\Laravel; -use Flasher\Cli\Laravel\ServiceProvider\ServiceProviderManager; +use Flasher\Cli\Prime\CliFactory; +use Flasher\Cli\Prime\EventListener\RenderListener; +use Flasher\Cli\Prime\Notify; +use Flasher\Cli\Prime\Presenter\CliPresenter; +use Flasher\Prime\EventDispatcher\EventDispatcherInterface; +use Flasher\Prime\FlasherInterface; +use Flasher\Prime\Response\ResponseManagerInterface; use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; final class FlasherCliServiceProvider extends ServiceProvider { + /** + * @return void + */ public function boot() { - $manager = new ServiceProviderManager($this); - $manager->boot(); + $this->processConfiguration(); + $this->registerRenderListener(); + $this->registerPresenter(); } /** - * Register the service provider. + * {@inheritdoc} */ public function register() { - $manager = new ServiceProviderManager($this); - $manager->register(); + $this->registerNotifierFactory(); + $this->registerNotifier(); } /** - * Get the services provided by the provider. - * - * @return string[] + * @return void */ - public function provides() + private function processConfiguration() { - return array( - 'flasher.cli', - ); + $name = 'flasher_cli'; + $config = $this->app['config']; // @phpstan-ignore-line + + $config->set($name, $config->get($name, array())); } /** - * @return Container + * @return void */ - public function getApplication() + private function registerNotifierFactory() { - return $this->app; + $this->app->singleton('flasher.cli', function (Container $app) { + return new CliFactory($app['flasher.storage_manager']); // @phpstan-ignore-line + }); + + $this->app->alias('flasher.cli', 'Flasher\Cli\Prime\CliFactory'); } - public function mergeConfigFrom($path, $key) + /** + * @return void + */ + private function registerNotifier() { - parent::mergeConfigFrom($path, $key); + $this->app->singleton('flasher.notify', function (Container $app) { + /** @phpstan-ignore-next-line */ + $title = $app['config']->get('flasher_cli.title', null); + $icons = $app['config']->get('flasher_cli.icons', array()); // @phpstan-ignore-line + + return new Notify($title, $icons); + }); + + $this->app->alias('flasher.notify', 'Flasher\Cli\Prime\Notify'); + $this->app->alias('flasher.notify', 'Flasher\Cli\Prime\NotifyInterface'); } - public function publishes(array $paths, $groups = null) + /** + * @return void + */ + private function registerRenderListener() { - parent::publishes($paths, $groups); + /** @var FlasherInterface $flasher */ + $flasher = $this->app['flasher']; + $this->app->extend('flasher.event_dispatcher', function (EventDispatcherInterface $dispatcher) use ($flasher) { + $dispatcher->addSubscriber(new RenderListener($flasher)); + + return $dispatcher; + }); + } + + /** + * @return void + */ + private function registerPresenter() + { + $this->app->extend('flasher.response_manager', function (ResponseManagerInterface $manager, Container $app) { + $manager->addPresenter(CliPresenter::NAME, new CliPresenter($app['flasher.notify'])); // @phpstan-ignore-line + + return $manager; + }); } } diff --git a/src/Cli/Laravel/README.md b/src/Cli/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Cli/Laravel/README.md +++ b/src/Cli/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Cli/Laravel/Resources/config/config.php b/src/Cli/Laravel/Resources/config/config.php deleted file mode 100644 index c905961d..00000000 --- a/src/Cli/Laravel/Resources/config/config.php +++ /dev/null @@ -1,110 +0,0 @@ - true, - - 'render_immediately' => true, - - 'title' => 'PHP Flasher', - - 'mute' => false, - - 'filter_criteria' => array(), - - 'icons' => array(), - - 'sounds' => array(), - - 'notifiers' => array( - 'growl_notify' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'growlnotify', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'kdialog_notifier' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'kdialog', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'notifu_notifier' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'notifu', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'notify_send' => array( - 'enabled' => true, - 'priority' => 2, - 'binary' => 'notify-send', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'zenity' => array( - 'enabled' => true, - 'priority' => 1, - 'binary' => 'zenity', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'snore_toast_notifier' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'snoretoast', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'terminal_notifier_notifier' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'terminal-notifier', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'toaster' => array( - 'enabled' => true, - 'priority' => 0, - 'binary' => 'toast', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - 'apple_script' => array( - 'enabled' => true, - 'priority' => 1, - 'binary' => 'osascript', - 'binary_paths' => array(), - 'title' => null, - 'mute' => true, - 'icons' => array(), - 'sounds' => array(), - ), - ), -); diff --git a/src/Cli/Laravel/Resources/functions/cli.php b/src/Cli/Laravel/Resources/functions/cli.php deleted file mode 100644 index 5d44cd0f..00000000 --- a/src/Cli/Laravel/Resources/functions/cli.php +++ /dev/null @@ -1,21 +0,0 @@ -with($stamps)->desktop($renderImmediately)->addFlash($type, $message, $options); - } -} diff --git a/src/Cli/Laravel/ServiceProvider/Providers/Laravel.php b/src/Cli/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index c5146e74..00000000 --- a/src/Cli/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,151 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherCliServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__.'/../../Resources/config/config.php') => config_path('flasher_cli.php'), - ), 'flasher-config'); - - $this->afterBoot(); - } - - public function afterBoot() - { - $this->app['flasher.response_manager']->addPresenter('cli', $this->app['flasher.presenter.cli']); - - $this->app['flasher.event_dispatcher']->addSubscriber(new RenderListener($this->app['flasher.cli'])); - - $this->app['flasher.event_dispatcher']->addSubscriber(new StampsListener( - $this->app['flasher.config']->getFrom('flasher_cli', 'render_all', false), - $this->app['flasher.config']->getFrom('flasher_cli', 'render_immediately', true) - )); - - NotificationBuilder::macro('desktop', function ($renderImmediately = true) { - return $this->withStamp(new DesktopStamp($renderImmediately)); - }); - } - - public function register(FlasherCliServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__.'/../../Resources/config/config.php'), 'flasher_cli'); - - $this->registerServices(); - } - - public function registerServices() - { - $this->app->singleton('flasher.cli', function (Container $app) { - return new CliNotificationFactory( - $app['flasher.storage_manager'], - $app['flasher.response_manager'], - $app['flasher.config']->getFrom('flasher_cli', 'filter_criteria', array()) - ); - }); - - $this->app->singleton('flasher.cli.growl_notify', function (Container $app) { - return new GrowlNotifyNotifier(Laravel::createConfigFor($app, 'growl_notify')); - }); - - $this->app->singleton('flasher.cli.kdialog_notifier', function (Container $app) { - return new KDialogNotifier(Laravel::createConfigFor($app, 'kdialog_notifier')); - }); - - $this->app->singleton('flasher.cli.notifu_notifier', function (Container $app) { - return new NotifuNotifier(Laravel::createConfigFor($app, 'notifu_notifier')); - }); - - $this->app->singleton('flasher.cli.notify_send', function (Container $app) { - return new NotifySendNotifier(Laravel::createConfigFor($app, 'notify_send')); - }); - - $this->app->singleton('flasher.cli.snore_toast_notifier', function (Container $app) { - return new SnoreToastNotifier(Laravel::createConfigFor($app, 'snore_toast_notifier')); - }); - - $this->app->singleton('flasher.cli.terminal_notifier_notifier', function (Container $app) { - return new TerminalNotifierNotifier(Laravel::createConfigFor($app, 'terminal_notifier_notifier')); - }); - - $this->app->singleton('flasher.cli.toaster', function (Container $app) { - return new ToasterNotifier(Laravel::createConfigFor($app, 'toaster')); - }); - - $this->app->singleton('flasher.cli.zenity', function (Container $app) { - return new ToasterNotifier(Laravel::createConfigFor($app, 'zenity')); - }); - - $this->app->singleton('flasher.cli.apple_script', function (Container $app) { - return new AppleScriptNotifier(Laravel::createConfigFor($app, 'apple_script')); - }); - - $this->app->singleton('flasher.presenter.cli', function (Container $app) { - $presenter = new CliPresenter(); - - $presenter->addNotifier($app['flasher.cli.growl_notify']); - $presenter->addNotifier($app['flasher.cli.kdialog_notifier']); - $presenter->addNotifier($app['flasher.cli.notifu_notifier']); - $presenter->addNotifier($app['flasher.cli.notify_send']); - $presenter->addNotifier($app['flasher.cli.snore_toast_notifier']); - $presenter->addNotifier($app['flasher.cli.terminal_notifier_notifier']); - $presenter->addNotifier($app['flasher.cli.toaster']); - $presenter->addNotifier($app['flasher.cli.zenity']); - $presenter->addNotifier($app['flasher.cli.apple_script']); - - return $presenter; - }); - - $this->app->alias('flasher.cli', 'Flasher\Cli\Prime\FlasherCli'); - $this->app->alias('Flasher\Cli\Prime\FlasherCli', 'Flasher\Cli\Prime\CliFlasherInterface'); - } - - private static function createConfigFor(Container $app, $notifier) - { - $options = $app['flasher.config']->getFrom('flasher_cli', 'notifiers.'.$notifier); - - $options['title'] = $app['flasher.config']->getFrom('flasher_cli', 'title'); - $options['mute'] = $app['flasher.config']->getFrom('flasher_cli', 'mute'); - $options['icons'] = array_replace_recursive($app['flasher.config']->getFrom('flasher_cli', 'icons'), $options['icons']); - $options['sounds'] = array_replace_recursive($app['flasher.config']->getFrom('flasher_cli', 'sounds'), $options['sounds']); - - return $options; - } -} diff --git a/src/Cli/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Cli/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 3caff568..00000000 --- a/src/Cli/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,30 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherCliServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-cli-laravel', - 'flasher_cli', - flasher_path(__DIR__ . '/../../Resources') - ); - - $this->afterBoot(); - } - - public function register(FlasherCliServiceProvider $provider) - { - $this->registerServices(); - } -} diff --git a/src/Cli/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Cli/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index 0e9e20dc..00000000 --- a/src/Cli/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Cli/Laravel/UPGRADING.md b/src/Cli/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Cli/Laravel/composer.json b/src/Cli/Laravel/composer.json index c932c0c7..2c18f680 100644 --- a/src/Cli/Laravel/composer.json +++ b/src/Cli/Laravel/composer.json @@ -2,42 +2,28 @@ "name": "php-flasher/flasher-cli-laravel", "description": "PHP Flasher Laravel adapter for Cli", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "cli ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "cli ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-cli": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-cli": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Cli\\Laravel\\": "" }, "files": [ - "Resources/functions/cli.php" + "notify.php" ] }, "extra": { @@ -50,6 +36,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Cli/Laravel/notify.php b/src/Cli/Laravel/notify.php new file mode 100644 index 00000000..ee080926 --- /dev/null +++ b/src/Cli/Laravel/notify.php @@ -0,0 +1,27 @@ + + */ + +if (!function_exists('notify')) { + /** + * @param Flasher\Cli\Prime\Notification|string|null $notification + * + * @return Flasher\Cli\Prime\Notify + */ + function notify($notification = null) + { + /** @var Flasher\Cli\Prime\Notify $notifier */ + $notifier = app('flasher.notify'); + + if (null === $notification || 0 === func_num_args()) { + return $notifier; + } + + $notifier->send($notification); + + return $notifier; + } +} diff --git a/src/Cli/Prime/.editorconfig b/src/Cli/Prime/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Cli/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Cli/Prime/.gitattributes b/src/Cli/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Cli/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Cli/Prime/.github/CONTRIBUTING.md b/src/Cli/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Cli/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Cli/Prime/.github/FUNDING.yml b/src/Cli/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Cli/Prime/.github/FUNDING.yml +++ b/src/Cli/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Cli/Prime/.github/SECURITY.md b/src/Cli/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Cli/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Cli/Prime/.github/dependabot.yml b/src/Cli/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Cli/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Cli/Prime/.github/workflows/auto_closer.yaml b/src/Cli/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Cli/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Cli/Prime/.github/workflows/close-pull-request.yml b/src/Cli/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Cli/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Cli/Prime/.gitignore b/src/Cli/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Cli/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Cli/Prime/.phpstorm.meta.php b/src/Cli/Prime/.phpstorm.meta.php index 7c3f0838..ef331a8a 100644 --- a/src/Cli/Prime/.phpstorm.meta.php +++ b/src/Cli/Prime/.phpstorm.meta.php @@ -3,9 +3,9 @@ namespace PHPSTORM_META; override(\Flasher\Prime\FlasherInterface::create(), map([ - 'cli' => \Flasher\Cli\Prime\CliNotificationFactory::class + 'cli' => \Flasher\Cli\Prime\CliFactory::class ])); override(\Flasher\Prime\FlasherInterface::using(), map([ - 'cli' => \Flasher\Cli\Prime\CliNotificationFactory::class + 'cli' => \Flasher\Cli\Prime\CliFactory::class ])); diff --git a/src/Cli/Prime/CHANGELOG.md b/src/Cli/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Cli/Prime/CODE_OF_CONDUCT.md b/src/Cli/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Cli/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Cli/Prime/CliNotificationBuilder.php b/src/Cli/Prime/CliBuilder.php similarity index 59% rename from src/Cli/Prime/CliNotificationBuilder.php rename to src/Cli/Prime/CliBuilder.php index 5c03e646..347e5e2b 100644 --- a/src/Cli/Prime/CliNotificationBuilder.php +++ b/src/Cli/Prime/CliBuilder.php @@ -1,20 +1,26 @@ + */ + namespace Flasher\Cli\Prime; use Flasher\Prime\Notification\NotificationBuilder; -final class CliNotificationBuilder extends NotificationBuilder +final class CliBuilder extends NotificationBuilder { /** * @param string $title * - * @return self + * @return static */ public function title($title) { + /** @var Notification $notification */ $notification = $this->envelope->getNotification(); - $notification->setTitle(addslashes($title)); + $notification->setTitle($title); return $this; } @@ -22,10 +28,11 @@ final class CliNotificationBuilder extends NotificationBuilder /** * @param string $icon * - * @return self + * @return static */ public function icon($icon) { + /** @var Notification $notification */ $notification = $this->envelope->getNotification(); $notification->setIcon($icon); diff --git a/src/Cli/Prime/CliFactory.php b/src/Cli/Prime/CliFactory.php new file mode 100644 index 00000000..443c40e7 --- /dev/null +++ b/src/Cli/Prime/CliFactory.php @@ -0,0 +1,18 @@ + + */ + +namespace Flasher\Cli\Prime; + +use Flasher\Prime\Factory\NotificationFactory; + +final class CliFactory extends NotificationFactory +{ + public function createNotificationBuilder() + { + return new CliBuilder($this->getStorageManager(), new Notification(), 'cli'); + } +} diff --git a/src/Cli/Prime/CliFlasherInterface.php b/src/Cli/Prime/CliFlasherInterface.php deleted file mode 100644 index 87ff9d4e..00000000 --- a/src/Cli/Prime/CliFlasherInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -title; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * @return string - */ - public function getIcon() - { - return $this->icon; - } - - /** - * @param string $icon - */ - public function setIcon($icon) - { - $this->icon = $icon; - } - - public function toArray() - { - return array_merge(parent::toArray(), array( - 'title' => $this->getTitle(), - 'icon' => $this->getIcon(), - )); - } -} diff --git a/src/Cli/Prime/CliNotificationFactory.php b/src/Cli/Prime/CliNotificationFactory.php deleted file mode 100644 index 486888b3..00000000 --- a/src/Cli/Prime/CliNotificationFactory.php +++ /dev/null @@ -1,38 +0,0 @@ -responseManager = $responseManager; - $this->filterCriteria = $filterCriteria; - } - - public function render(array $criteria = array(), $merge = true) - { - if ($merge) { - $criteria = $this->filterCriteria + $criteria; - } - - return $this->responseManager->render($criteria, 'cli'); - } - - public function createNotificationBuilder() - { - return new CliNotificationBuilder($this->getStorageManager(), new CliNotification(), 'cli'); - } -} diff --git a/src/Cli/Prime/EventListener/RenderListener.php b/src/Cli/Prime/EventListener/RenderListener.php index e616f30c..6d4648a2 100644 --- a/src/Cli/Prime/EventListener/RenderListener.php +++ b/src/Cli/Prime/EventListener/RenderListener.php @@ -1,43 +1,44 @@ + */ + namespace Flasher\Cli\Prime\EventListener; -use Flasher\Cli\Prime\CliFlasherInterface; -use Flasher\Cli\Prime\Stamp\DesktopStamp; -use Flasher\Prime\Envelope; +use Flasher\Cli\Prime\Presenter\CliPresenter; use Flasher\Prime\EventDispatcher\Event\PostPersistEvent; use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; +use Flasher\Prime\FlasherInterface; final class RenderListener implements EventSubscriberInterface { + /** + * @var FlasherInterface + */ private $flasher; - public function __construct(CliFlasherInterface $flasher) + public function __construct(FlasherInterface $flasher) { $this->flasher = $flasher; } /** - * @param PostPersistEvent $event + * @return void */ - public function __invoke($event) + public function __invoke(PostPersistEvent $event) { - if (PHP_SAPI !== 'cli') { + if ('cli' !== \PHP_SAPI) { return; } - $callback = function(Envelope $envelope) { - $stamp = $envelope->get('Flasher\Cli\Prime\Stamp\DesktopStamp'); - if (!$stamp instanceof DesktopStamp) { - return false; - } - - return $stamp->isRenderImmediately(); - }; - - $this->flasher->render(array('filter' => $callback)); + $this->flasher->render(array(), CliPresenter::NAME); } + /** + * {@inheritdoc} + */ public static function getSubscribedEvents() { return 'Flasher\Prime\EventDispatcher\Event\PostPersistEvent'; diff --git a/src/Cli/Prime/EventListener/StampsListener.php b/src/Cli/Prime/EventListener/StampsListener.php deleted file mode 100644 index dcd9dc13..00000000 --- a/src/Cli/Prime/EventListener/StampsListener.php +++ /dev/null @@ -1,48 +0,0 @@ -renderAll = $renderAll; - $this->renderImmediately = $renderImmediately; - } - - /** - * @param PersistEvent|UpdateEvent $event - */ - public function __invoke($event) - { - if (PHP_SAPI !== 'cli') { - return; - } - - foreach ($event->getEnvelopes() as $envelope) { - $this->attachStamps($envelope); - } - } - - public static function getSubscribedEvents() - { - return 'Flasher\Prime\EventDispatcher\Event\PersistEvent'; - } - - private function attachStamps(Envelope $envelope) - { - $stamp = $envelope->get('Flasher\Cli\Prime\Stamp\DesktopStamp'); - if (null === $stamp && true === $this->renderAll) { - $envelope->withStamp(new DesktopStamp($this->renderImmediately)); - } - } -} diff --git a/src/Cli/Prime/Notification.php b/src/Cli/Prime/Notification.php new file mode 100644 index 00000000..404f38d4 --- /dev/null +++ b/src/Cli/Prime/Notification.php @@ -0,0 +1,228 @@ + + */ + +namespace Flasher\Cli\Prime; + +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\Notification as BaseNotification; +use Flasher\Prime\Notification\NotificationInterface; + +final class Notification extends BaseNotification +{ + /** + * @var string|null + */ + private $title; + + /** + * @var string|null + */ + private $icon; + + /** + * @param string|null $message + * @param string|null $title + * @param string|null $icon + * @param string $type + * @param array $options + */ + public function __construct($message = null, $title = null, $icon = null, $type = self::INFO, array $options = array()) + { + $this->message = $message; + $this->title = $title; + $this->icon = $icon; + $this->type = $type; + $this->options = $options; + } + + /** + * @param Notification|string $notification + * + * @return static + */ + public static function wrap($notification) + { + if ($notification instanceof Notification) { + return $notification; + } + + return self::create($notification); + } + + /** + * @param string $message + * @param string|null $title + * @param string|null $icon + * @param string $type + * @param array $options + * + * @return static + */ + public static function create($message, $title = null, $icon = null, $type = self::INFO, array $options = array()) + { + return new self($message, $title, $icon, $type, $options); + } + + /** + * @param string $message + * @param string|null $title + * @param string|null $icon + * @param array $options + * + * @return static + */ + public static function error($message, $title = null, $icon = null, array $options = array()) + { + return self::create($message, $title, $icon, NotificationInterface::ERROR, $options); + } + + /** + * @param string $message + * @param string|null $title + * @param string|null $icon + * @param array $options + * + * @return static + */ + public static function info($message, $title = null, $icon = null, array $options = array()) + { + return self::create($message, $title, $icon, NotificationInterface::INFO, $options); + } + + /** + * @param string $message + * @param string|null $title + * @param string|null $icon + * @param array $options + * + * @return static + */ + public static function success($message, $title = null, $icon = null, array $options = array()) + { + return self::create($message, $title, $icon, NotificationInterface::SUCCESS, $options); + } + + /** + * @param string $message + * @param string|null $title + * @param string|null $icon + * @param array $options + * + * @return static + */ + public static function warning($message, $title = null, $icon = null, array $options = array()) + { + return self::create($message, $title, $icon, NotificationInterface::WARNING, $options); + } + + /** + * {@inheritdoc} + */ + public function getMessage() + { + $message = parent::getMessage(); + + if (\is_string($message)) { + $message = addslashes($message); + } + + return $message; + } + + /** + * {@inheritdoc} + */ + public function getOption($name, $default = null) + { + $option = parent::getOption($name, $default); + + if (\is_string($option)) { + $option = addslashes($option); + } + + return $option; + } + + /** + * @return string|null + */ + public function getTitle() + { + $title = $this->title; + + if (\is_string($title)) { + $title = addslashes($title); + } + + return $title; + } + + /** + * @param string|null $title + * + * @return static + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string|null + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @param string|null $icon + * + * @return static + */ + public function setIcon($icon) + { + $this->icon = $icon; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + return array_merge(parent::toArray(), array( + 'title' => $this->getTitle(), + 'icon' => $this->getIcon(), + )); + } + + /** + * @return static + */ + public static function fromEnvelope(Envelope $envelope) + { + $self = new self(); + + $self->setType($envelope->getType()); + $self->setMessage($envelope->getMessage()); + $self->setOptions($envelope->getOptions()); + + $notification = $envelope->getNotification(); + if (!$notification instanceof self) { + return $self; + } + + $self->setTitle($notification->getTitle()); + $self->setIcon($notification->getIcon()); + + return $self; + } +} diff --git a/src/Cli/Prime/Notifier/AbstractNotifier.php b/src/Cli/Prime/Notifier/AbstractNotifier.php deleted file mode 100644 index c80b66d9..00000000 --- a/src/Cli/Prime/Notifier/AbstractNotifier.php +++ /dev/null @@ -1,146 +0,0 @@ -configureOptions($options); - } - - public function render(array $envelopes) - { - foreach ($envelopes as $envelope) { - $this->renderEnvelope($envelope); - } - } - - abstract public function renderEnvelope(Envelope $envelope); - - public function isSupported() - { - return $this->options['is_supported']; - } - - public function getPriority() - { - return $this->options['priority']; - } - - public function getBinary() - { - return $this->options['binary']; - } - - public function getBinaryPaths() - { - return $this->options['binary_paths']; - } - - public function getProgram() - { - if (Program::exist($this->getBinary())) { - return $this->getBinary(); - } - - foreach ((array)$this->getBinaryPaths() as $path) { - $path = Path::realpath($path); - - if (file_exists($path)) { - return $path; - } - } - - return null; - } - - public function getTitle(Envelope $envelope) - { - $notification = $envelope->getNotification(); - - if (method_exists($notification, 'getTitle') && null !== $notification->getTitle()) { - return addslashes($notification->getTitle()); - } - - return addslashes($this->options['title']); - } - - public function isEnabled() - { - return $this->options['enabled']; - } - - /** - * @param Envelope $envelope - * - * @return string - */ - public function getIcon(Envelope $envelope) - { - $notification = $envelope->getNotification(); - if ($notification instanceof CliNotification && $notification->getIcon()) { - return Path::realpath($notification->getIcon()); - } - - $type = $envelope->getType(); - - if (isset($this->options['icons'][$type]) && file_exists($this->options['icons'][$type])) { - return Path::realpath($this->options['icons'][$type]); - } - - return Path::realpath(__DIR__.'/../Resources/icons/info.png'); - } - - public function playSound($type = null) - { - if ($this->options['mute']) { - return; - } - - \exec('paplay '.$this->getSound($type)); - } - - public function getSound($type) - { - if (isset($this->options['sounds'][$type]) && file_exists($this->options['sounds'][$type])) { - return Path::realpath($this->options['sounds'][$type]); - } - - return Path::realpath(__DIR__.'/../Resources/sounds/info.wav'); - } - - public function configureOptions(array $options) - { - $default = array( - 'enabled' => true, - 'priority' => 0, - 'binary' => null, - 'binary_paths' => array(), - 'title' => 'PHPFlasher', - 'icons' => array( - NotificationInterface::TYPE_SUCCESS => Path::realpath(__DIR__.'/../Resources/icons/success.png'), - NotificationInterface::TYPE_ERROR => Path::realpath(__DIR__.'/../Resources/icons/error.png'), - NotificationInterface::TYPE_INFO => Path::realpath(__DIR__.'/../Resources/icons/info.png'), - NotificationInterface::TYPE_WARNING => Path::realpath(__DIR__.'/../Resources/icons/warning.png'), - ), - 'mute' => false, - 'sounds' => array( - NotificationInterface::TYPE_SUCCESS => Path::realpath(__DIR__.'/../Resources/sounds/success.wav'), - NotificationInterface::TYPE_ERROR => Path::realpath(__DIR__.'/../Resources/sounds/error.wav'), - NotificationInterface::TYPE_INFO => Path::realpath(__DIR__.'/../Resources/sounds/info.wav'), - NotificationInterface::TYPE_WARNING => Path::realpath(__DIR__.'/../Resources/sounds/warning.wav'), - ), - ); - - $this->options = array_replace_recursive($default, $options); - } -} diff --git a/src/Cli/Prime/Notifier/AppleScriptBaseNotifier.php b/src/Cli/Prime/Notifier/AppleScriptBaseNotifier.php new file mode 100644 index 00000000..6411dccc --- /dev/null +++ b/src/Cli/Prime/Notifier/AppleScriptBaseNotifier.php @@ -0,0 +1,57 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class AppleScriptBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addArgument(sprintf('display notification "%s"', $notification->getMessage())) + ->addArgument(sprintf('with title "%s"', $notification->getTitle())); + + /** @var string $subtitle */ + $subtitle = $notification->getOption('subtitle'); + if ($subtitle) { + $cmd->addArgument(sprintf('subtitle "%s"', $subtitle)); + } + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + if (!$this->getProgram()) { + return false; + } + + return OS::isMacOS() && version_compare(OS::getMacOSVersion(), '10.9.0', '>='); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'osascript'; + } +} diff --git a/src/Cli/Prime/Notifier/AppleScriptNotifier.php b/src/Cli/Prime/Notifier/AppleScriptNotifier.php deleted file mode 100644 index b34c6f45..00000000 --- a/src/Cli/Prime/Notifier/AppleScriptNotifier.php +++ /dev/null @@ -1,51 +0,0 @@ -getProgram()); - - $cmd - ->addArgument(sprintf('display notification "%s"', $envelope->getMessage())) - ->addArgument(sprintf('with title "%s"', $this->getTitle($envelope))); - - $subtitle = $envelope->getOption('subtitle'); - if ($subtitle) { - $cmd->addArgument(sprintf('subtitle "%s"', $subtitle)); - } - - $sound = $envelope->getOption('sound'); - if ($sound) { - $cmd->addArgument(sprintf('sound name "%s"', $sound)); - } - - $cmd->run(); - } - - public function isSupported() - { - if (!$this->getProgram() || !$this->isEnabled()) { - return false; - } - - return OS::isMacOS() && version_compare(OS::getMacOSVersion(), '10.9.0', '>='); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'osascript', - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/BaseNotifier.php b/src/Cli/Prime/Notifier/BaseNotifier.php new file mode 100644 index 00000000..53eddf96 --- /dev/null +++ b/src/Cli/Prime/Notifier/BaseNotifier.php @@ -0,0 +1,111 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\NotifyInterface; +use Flasher\Cli\Prime\System\Path; +use Flasher\Cli\Prime\System\Program; +use Flasher\Prime\Notification\NotificationInterface; + +abstract class BaseNotifier implements NotifyInterface +{ + /** + * {@inheritdoc} + */ + public function isSupported() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } + + /** + * @return string|null + */ + public function getBinary() + { + return null; + } + + /** + * @return string|string[] + */ + public function getBinaryPaths() + { + return array(); + } + + /** + * @return string|null + */ + public function getProgram() + { + if (Program::exist($this->getBinary())) { + return $this->getBinary(); + } + + foreach ((array) $this->getBinaryPaths() as $path) { + $path = Path::realpath($path); + + if (file_exists($path)) { + return $path; + } + } + + return null; + } + + /** + * {@inheritdoc} + */ + public function success($message, $title = null, $options = array()) + { + $this->type(NotificationInterface::SUCCESS, $message, $title, $options); + } + + /** + * {@inheritdoc} + */ + public function info($message, $title = null, $options = array()) + { + $this->type(NotificationInterface::INFO, $message, $title, $options); + } + + /** + * {@inheritdoc} + */ + public function error($message, $title = null, $options = array()) + { + $this->type(NotificationInterface::ERROR, $message, $title, $options); + } + + /** + * {@inheritdoc} + */ + public function warning($message, $title = null, $options = array()) + { + $this->type(NotificationInterface::WARNING, $message, $title, $options); + } + + /** + * {@inheritdoc} + */ + public function type($type, $message, $title = null, $options = array()) + { + $notification = new Notification($message, $title, null, $type, $options); + + $this->send($notification); + } +} diff --git a/src/Cli/Prime/Notifier/GrowlNotifyBaseNotifier.php b/src/Cli/Prime/Notifier/GrowlNotifyBaseNotifier.php new file mode 100644 index 00000000..4a0434ef --- /dev/null +++ b/src/Cli/Prime/Notifier/GrowlNotifyBaseNotifier.php @@ -0,0 +1,48 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class GrowlNotifyBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('--message', $notification->getMessage()) + ->addOption('--title', $notification->getTitle()) + ->addOption('--image', $notification->getIcon()); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isMacOS() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'growlnotify'; + } +} diff --git a/src/Cli/Prime/Notifier/GrowlNotifyNotifier.php b/src/Cli/Prime/Notifier/GrowlNotifyNotifier.php deleted file mode 100644 index 73cce673..00000000 --- a/src/Cli/Prime/Notifier/GrowlNotifyNotifier.php +++ /dev/null @@ -1,38 +0,0 @@ -getProgram()); - - $cmd - ->addOption('--message', $envelope->getMessage()) - ->addOption('--title', $this->getTitle($envelope)) - ->addOption('--image', $this->getIcon($envelope)); - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isMacOS() && $this->getProgram(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'growlnotify', - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/KDialogBaseNotifier.php b/src/Cli/Prime/Notifier/KDialogBaseNotifier.php new file mode 100644 index 00000000..b5e9ba65 --- /dev/null +++ b/src/Cli/Prime/Notifier/KDialogBaseNotifier.php @@ -0,0 +1,48 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class KDialogBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('--passivepopup', $notification->getMessage()) + ->addOption('--title', $notification->getTitle()) + ->addArgument(5); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isUnix() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'kdialog'; + } +} diff --git a/src/Cli/Prime/Notifier/KDialogNotifier.php b/src/Cli/Prime/Notifier/KDialogNotifier.php deleted file mode 100644 index 072f9abc..00000000 --- a/src/Cli/Prime/Notifier/KDialogNotifier.php +++ /dev/null @@ -1,38 +0,0 @@ -getProgram()); - - $cmd - ->addOption('--passivepopup', $envelope->getMessage()) - ->addOption('--title', $this->getTitle($envelope)) - ->addArgument(5); - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isUnix() && $this->getProgram(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'kdialog', - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/NotifierInterface.php b/src/Cli/Prime/Notifier/NotifierInterface.php deleted file mode 100644 index c4cf1111..00000000 --- a/src/Cli/Prime/Notifier/NotifierInterface.php +++ /dev/null @@ -1,28 +0,0 @@ - + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; +use Flasher\Cli\Prime\System\Path; + +final class NotifuBaseNotifier extends BaseNotifier +{ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('/m', $notification->getMessage()) + ->addOption('/p', $notification->getTitle()) + ->addOption('/i', $notification->getIcon()); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isWindowsSeven() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'notifu'; + } + + /** + * {@inheritdoc} + */ + public function getBinaryPaths() + { + return Path::realpath(__DIR__.'/../Resources/bin/notifu/notifu.exe'); + } +} diff --git a/src/Cli/Prime/Notifier/NotifuNotifier.php b/src/Cli/Prime/Notifier/NotifuNotifier.php deleted file mode 100644 index bf98981c..00000000 --- a/src/Cli/Prime/Notifier/NotifuNotifier.php +++ /dev/null @@ -1,42 +0,0 @@ -getProgram()); - - $cmd - ->addOption('/m', $envelope->getMessage()) - ->addOption('/p', $this->getTitle($envelope)) - ->addOption('/i', $this->getIcon($envelope)); - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isWindowsSeven() && $this->getProgram(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'notifu', - 'binary_paths' => array( - Path::realpath(__DIR__.'/../Resources/bin/notifu/notifu.exe'), - ), - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/NotifySendBaseNotifier.php b/src/Cli/Prime/Notifier/NotifySendBaseNotifier.php new file mode 100644 index 00000000..9fbd24f4 --- /dev/null +++ b/src/Cli/Prime/Notifier/NotifySendBaseNotifier.php @@ -0,0 +1,51 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class NotifySendBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('--urgency', 'normal') + ->addOption('--app-name', 'notify') + ->addOption('--icon', $notification->getIcon()) + ->addOption('--expire-time', 1) + ->addArgument($notification->getTitle()) + ->addArgument($notification->getMessage()); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isUnix() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'notify-send'; + } +} diff --git a/src/Cli/Prime/Notifier/NotifySendNotifier.php b/src/Cli/Prime/Notifier/NotifySendNotifier.php deleted file mode 100644 index 6034e592..00000000 --- a/src/Cli/Prime/Notifier/NotifySendNotifier.php +++ /dev/null @@ -1,48 +0,0 @@ -getProgram()); - - $cmd - ->addOption('--urgency', 'normal') - ->addOption('--app-name', 'notify') - ->addOption('--icon', $this->getIcon($envelope)) - ->addOption('--expire-time', $this->getExpireTime()) - ->addArgument($this->getTitle($envelope)) - ->addArgument($envelope->getMessage()); - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isUnix() && $this->getProgram(); - } - - public function getExpireTime() - { - return (int)$this->options['expire_time']; - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'notify-send', - 'expire_time' => 1, - 'priority' => 2, - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/NullBaseNotifier.php b/src/Cli/Prime/Notifier/NullBaseNotifier.php new file mode 100644 index 00000000..ea93cbfe --- /dev/null +++ b/src/Cli/Prime/Notifier/NullBaseNotifier.php @@ -0,0 +1,34 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +final class NullBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return ''; + } +} diff --git a/src/Cli/Prime/Notifier/NullNotifier.php b/src/Cli/Prime/Notifier/NullNotifier.php deleted file mode 100644 index 74f26dc0..00000000 --- a/src/Cli/Prime/Notifier/NullNotifier.php +++ /dev/null @@ -1,17 +0,0 @@ - + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; +use Flasher\Cli\Prime\System\Path; + +final class SnoreToastBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('-m', $notification->getMessage()) + ->addOption('-t', $notification->getTitle()) + ->addOption('-p', $notification->getIcon()); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + if (!$this->getProgram()) { + return false; + } + + return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'snoretoast'; + } + + /** + * {@inheritdoc} + */ + public function getBinaryPaths() + { + return Path::realpath(__DIR__.'/../Resources/bin/snoreToast/snoretoast-x86.exe'); + } +} diff --git a/src/Cli/Prime/Notifier/SnoreToastNotifier.php b/src/Cli/Prime/Notifier/SnoreToastNotifier.php deleted file mode 100644 index b7f2707a..00000000 --- a/src/Cli/Prime/Notifier/SnoreToastNotifier.php +++ /dev/null @@ -1,46 +0,0 @@ -getProgram()); - - $cmd - ->addOption('-m', $envelope->getMessage()) - ->addOption('-t', $this->getTitle($envelope)) - ->addOption('-p', $this->getIcon($envelope)); - - $cmd->run(); - } - - public function isSupported() - { - if (!$this->getProgram() || !$this->isEnabled()) { - return false; - } - - return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'snoretoast', - 'binary_paths' => array( - Path::realpath(__DIR__.'/../Resources/bin/snoreToast/snoretoast-x86.exe'), - ), - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/TerminalNotifierBaseNotifier.php b/src/Cli/Prime/Notifier/TerminalNotifierBaseNotifier.php new file mode 100644 index 00000000..93224eca --- /dev/null +++ b/src/Cli/Prime/Notifier/TerminalNotifierBaseNotifier.php @@ -0,0 +1,57 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class TerminalNotifierBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('-message', $notification->getMessage()) + ->addOption('-title', $notification->getTitle()); + + if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) { + $cmd->addOption('-appIcon', $notification->getIcon()); + } + + /** @var string|null $url */ + $url = $notification->getOption('url'); + if ($url) { + $cmd->addOption('-open', $url); + } + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isMacOS() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'terminal-notifier'; + } +} diff --git a/src/Cli/Prime/Notifier/TerminalNotifierNotifier.php b/src/Cli/Prime/Notifier/TerminalNotifierNotifier.php deleted file mode 100644 index 3b7d0327..00000000 --- a/src/Cli/Prime/Notifier/TerminalNotifierNotifier.php +++ /dev/null @@ -1,46 +0,0 @@ -getProgram()); - - $cmd - ->addOption('-message', $envelope->getMessage()) - ->addOption('-title', $this->getTitle($envelope)); - - if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) { - $cmd->addOption('-appIcon', $this->getIcon($envelope)); - } - - $url = $envelope->getOption('url'); - if ($url) { - $cmd->addOption('-open', $url); - } - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isMacOS() && $this->getProgram(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'terminal-notifier', - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/ToasterBaseNotifier.php b/src/Cli/Prime/Notifier/ToasterBaseNotifier.php new file mode 100644 index 00000000..f9f6f2c8 --- /dev/null +++ b/src/Cli/Prime/Notifier/ToasterBaseNotifier.php @@ -0,0 +1,62 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; +use Flasher\Cli\Prime\System\Path; + +final class ToasterBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addOption('-t', $notification->getTitle()) + ->addOption('-m', $notification->getMessage()) + ->addOption('-p', $notification->getIcon()) + ->addArgument('-w'); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + if (!$this->getProgram()) { + return false; + } + + return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'toast'; + } + + /** + * {@inheritdoc} + */ + public function getBinaryPaths() + { + return Path::realpath(__DIR__.'/../Resources/bin/toaster/toast.exe'); + } +} diff --git a/src/Cli/Prime/Notifier/ToasterNotifier.php b/src/Cli/Prime/Notifier/ToasterNotifier.php deleted file mode 100644 index c40a53be..00000000 --- a/src/Cli/Prime/Notifier/ToasterNotifier.php +++ /dev/null @@ -1,47 +0,0 @@ -getProgram()); - - $cmd - ->addOption('-t', $this->getTitle($envelope)) - ->addOption('-m', $envelope->getMessage()) - ->addOption('-p', $this->getIcon($envelope)) - ->addArgument('-w');; - - $cmd->run(); - } - - public function isSupported() - { - if (!$this->getProgram() || !$this->isEnabled()) { - return false; - } - - return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'toast', - 'binary_paths' => array( - Path::realpath(__DIR__.'/../Resources/bin/toaster/toast.exe'), - ), - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notifier/ZenityBaseNotifier.php b/src/Cli/Prime/Notifier/ZenityBaseNotifier.php new file mode 100644 index 00000000..ca0f2de1 --- /dev/null +++ b/src/Cli/Prime/Notifier/ZenityBaseNotifier.php @@ -0,0 +1,48 @@ + + */ + +namespace Flasher\Cli\Prime\Notifier; + +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\System\Command; +use Flasher\Cli\Prime\System\OS; + +final class ZenityBaseNotifier extends BaseNotifier +{ + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = Notification::wrap($notification); + + $cmd = new Command($this->getProgram()); + + $cmd + ->addArgument('--notification') + ->addOption('--text', $notification->getTitle().'\n\n'.$notification->getMessage()) + ->addOption('--window-icon', $notification->getIcon()); + + $cmd->run(); + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + return OS::isUnix() && $this->getProgram(); + } + + /** + * {@inheritdoc} + */ + public function getBinary() + { + return 'zenity'; + } +} diff --git a/src/Cli/Prime/Notifier/ZenityNotifier.php b/src/Cli/Prime/Notifier/ZenityNotifier.php deleted file mode 100644 index c9289849..00000000 --- a/src/Cli/Prime/Notifier/ZenityNotifier.php +++ /dev/null @@ -1,40 +0,0 @@ -getProgram()); - - $cmd - ->addArgument('--notification') - ->addOption('--text', $this->getTitle($envelope).'\n\n'.$envelope->getMessage()) - ->addOption('--window-icon', $this->getIcon($envelope)); - - $cmd->run(); - } - - public function isSupported() - { - return $this->isEnabled() && OS::isUnix() && $this->getProgram(); - } - - public function configureOptions(array $options) - { - $default = array( - 'binary' => 'zenity', - 'expire_time' => 0, - 'priority' => 1, - ); - - $options = array_replace_recursive($default, $options); - - parent::configureOptions($options); - } -} diff --git a/src/Cli/Prime/Notify.php b/src/Cli/Prime/Notify.php new file mode 100644 index 00000000..b4047b9f --- /dev/null +++ b/src/Cli/Prime/Notify.php @@ -0,0 +1,231 @@ + + */ + +namespace Flasher\Cli\Prime; + +use Flasher\Cli\Prime\Notifier\BaseNotifier; +use Flasher\Cli\Prime\System\Path; +use Flasher\Prime\Notification\NotificationInterface; + +final class Notify extends BaseNotifier +{ + /** + * @var NotifyInterface|null + */ + private $notifier; + + /** + * @var NotifyInterface[] + */ + private $notifiers = array(); + + /** + * @var NotifyInterface[] + */ + private $sorted = array(); + + /** + * @var bool|null + */ + private $isSupported; + + /** + * @var string|null + */ + private $title; + + /** + * @var array{success?: string, error?: string, info?: string, warning?: string} + */ + private $icons = array(); + + /** + * @param string|null $title + * @param array{success?: string, error?: string, info?: string, warning?: string}|string $icons + */ + public function __construct($title = 'PHP Flasher', $icons = array()) + { + $this->title = $title; + $this->icons = $this->configureIcons($icons); + + $this->addNotifier(new Notifier\NotifySendBaseNotifier()); + $this->addNotifier(new Notifier\AppleScriptBaseNotifier()); + $this->addNotifier(new Notifier\GrowlNotifyBaseNotifier()); + $this->addNotifier(new Notifier\KDialogBaseNotifier()); + $this->addNotifier(new Notifier\NotifuBaseNotifier()); + $this->addNotifier(new Notifier\SnoreToastBaseNotifier()); + $this->addNotifier(new Notifier\TerminalNotifierBaseNotifier()); + $this->addNotifier(new Notifier\ToasterBaseNotifier()); + $this->addNotifier(new Notifier\ZenityBaseNotifier()); + } + + /** + * @param string|null $title + * @param array{success?: string, error?: string, info?: string, warning?: string}|string $icons + * + * @return static + */ + public static function create($title = null, $icons = array()) + { + return new self($title, $icons); + } + + /** + * {@inheritdoc} + */ + public function send($notification) + { + $notification = $this->configureNotification($notification); + + $notifier = $this->createNotifier(); + $notifier->send($notification); + } + + /** + * @return void + */ + public function addNotifier(NotifyInterface $notifier) + { + $this->notifiers[] = $notifier; + $this->reset(); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } + + /** + * {@inheritdoc} + */ + public function isSupported() + { + if (null !== $this->isSupported) { + return $this->isSupported; + } + + if ($this->notifier instanceof NotifyInterface) { + return true; + } + + foreach ($this->getNotifiers() as $notifier) { + if ($notifier->isSupported()) { + return $this->isSupported = true; + } + } + + return false; + } + + /** + * @return void + */ + private function reset() + { + $this->notifier = null; + $this->sorted = array(); + $this->isSupported = null; + } + + /** + * @return NotifyInterface[] + */ + private function getNotifiers() + { + if (array() !== $this->sorted) { + return $this->sorted; + } + + $this->sorted = $this->notifiers; + + usort($this->sorted, static function (NotifyInterface $a, NotifyInterface $b) { + $priorityA = $a->getPriority(); + $priorityB = $b->getPriority(); + + if ($priorityA === $priorityB) { + return 0; + } + + return $priorityA < $priorityB ? 1 : -1; + }); + + return $this->sorted; + } + + /** + * @return NotifyInterface + */ + private function createNotifier() + { + if ($this->notifier instanceof NotifyInterface) { + return $this->notifier; + } + + foreach ($this->getNotifiers() as $notifier) { + if ($notifier->isSupported()) { + return $this->notifier = $notifier; + } + } + + return new Notifier\NullBaseNotifier(); + } + + /** + * @param array{success?: string, error?: string, info?: string, warning?: string}|string $icons + * + * @return array<'default'|'error'|'info'|'success'|'warning', string> + */ + private function configureIcons($icons = array()) + { + $icons = $icons ?: array(); + + if (!\is_array($icons)) { + $icons = array( + NotificationInterface::SUCCESS => $icons, + NotificationInterface::ERROR => $icons, + NotificationInterface::INFO => $icons, + NotificationInterface::WARNING => $icons, + 'default' => $icons, + ); + } + + return array_merge(array( + NotificationInterface::SUCCESS => Path::realpath(__DIR__.'/Resources/icons/success.png'), + NotificationInterface::ERROR => Path::realpath(__DIR__.'/Resources/icons/error.png'), + NotificationInterface::INFO => Path::realpath(__DIR__.'/Resources/icons/info.png'), + NotificationInterface::WARNING => Path::realpath(__DIR__.'/Resources/icons/warning.png'), + 'default' => Path::realpath(__DIR__.'/Resources/icons/info.png'), + ), $icons); + } + + /** + * @param Notification|string $notification + * + * @return Notification + */ + private function configureNotification($notification) + { + $notification = Notification::wrap($notification); + + if (null === $notification->getTitle()) { + $notification->setTitle($this->title); + } + + if (null === $notification->getIcon() && isset($this->icons[$notification->getType()])) { + $notification->setIcon($this->icons[$notification->getType()]); // @phpstan-ignore-line + } + + if (null === $notification->getIcon()) { + $notification->setIcon($this->icons['default']); // @phpstan-ignore-line + } + + return $notification; + } +} diff --git a/src/Cli/Prime/NotifyInterface.php b/src/Cli/Prime/NotifyInterface.php new file mode 100644 index 00000000..994e0cbe --- /dev/null +++ b/src/Cli/Prime/NotifyInterface.php @@ -0,0 +1,74 @@ + + */ + +namespace Flasher\Cli\Prime; + +interface NotifyInterface +{ + /** + * @param Notification|string $notification + * + * @return void + */ + public function send($notification); + + /** + * @return int + */ + public function getPriority(); + + /** + * @return bool + */ + public function isSupported(); + + /** + * @param string $type + * @param string $message + * @param string|null $title + * @param array $options + * + * @return void + */ + public function type($type, $message, $title = null, $options = array()); + + /** + * @param string $message + * @param string|null $title + * @param array $options + * + * @return void + */ + public function warning($message, $title = null, $options = array()); + + /** + * @param string $message + * @param string|null $title + * @param array $options + * + * @return void + */ + public function info($message, $title = null, $options = array()); + + /** + * @param string $message + * @param string|null $title + * @param array $options + * + * @return void + */ + public function error($message, $title = null, $options = array()); + + /** + * @param string $message + * @param string|null $title + * @param array $options + * + * @return void + */ + public function success($message, $title = null, $options = array()); +} diff --git a/src/Cli/Prime/Presenter/CliPresenter.php b/src/Cli/Prime/Presenter/CliPresenter.php index f8e22097..5e064d59 100644 --- a/src/Cli/Prime/Presenter/CliPresenter.php +++ b/src/Cli/Prime/Presenter/CliPresenter.php @@ -1,73 +1,44 @@ + */ + namespace Flasher\Cli\Prime\Presenter; -use Flasher\Cli\Prime\Notifier\NotifierInterface; -use Flasher\Cli\Prime\Notifier\NullNotifier; +use Flasher\Cli\Prime\Notification; +use Flasher\Cli\Prime\Notify; +use Flasher\Cli\Prime\NotifyInterface; use Flasher\Prime\Response\Presenter\PresenterInterface; use Flasher\Prime\Response\Response; final class CliPresenter implements PresenterInterface { - /** - * @var NotifierInterface[] - */ - private $notifiers = array(); + const NAME = 'cli'; /** - * @var NotifierInterface[] + * @var NotifyInterface */ - private $sorted = array(); + private $notifier; + public function __construct(NotifyInterface $notifier = null) + { + $this->notifier = $notifier ?: new Notify(); + } + + /** + * {@inheritdoc} + */ public function render(Response $response) { - if (0 === count($response->getEnvelopes())) { + if ('cli' !== \PHP_SAPI || array() === $response->getEnvelopes()) { return; } - $notifier = $this->createNotifier(); - - $notifier->render($response->getEnvelopes()); - } - - public function addNotifier(NotifierInterface $notifier) - { - $this->notifiers[] = $notifier; - } - - public function getSortedNotifiers() - { - if (0 !== count($this->sorted)) { - return $this->sorted; + foreach ($response->getEnvelopes() as $envelope) { + $notification = Notification::fromEnvelope($envelope); + $this->notifier->send($notification); } - - $this->sorted = $this->notifiers; - - usort($this->sorted, static function (NotifierInterface $a, NotifierInterface $b) { - $priorityA = $a->getPriority(); - $priorityB = $b->getPriority(); - - if ($priorityA == $priorityB) { - return 0; - } - - return $priorityA < $priorityB ? 1 : -1; - }); - - return $this->sorted; - } - - /** - * @return NotifierInterface - */ - private function createNotifier() - { - foreach ($this->getSortedNotifiers() as $notifier) { - if ($notifier->isSupported()) { - return $notifier; - } - } - - return new NullNotifier(); } } diff --git a/src/Cli/Prime/README.md b/src/Cli/Prime/README.md index eacd0f2a..70048b42 100644 --- a/src/Cli/Prime/README.md +++ b/src/Cli/Prime/README.md @@ -24,17 +24,11 @@ - - - - - -

# Why use PHP Flasher ? -The PHP Flasher project supports many notification libraries : __tailwindcss__, __bootstrap__, __cli.js__, __sweet alert 2__, __pnotify__, __noty__, and __notyf__ +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 : @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Cli/Prime/Resources/bin/notifu/notifu.exe b/src/Cli/Prime/Resources/bin/notifu/notifu.exe index 33938d73..e69de29b 100644 Binary files a/src/Cli/Prime/Resources/bin/notifu/notifu.exe and b/src/Cli/Prime/Resources/bin/notifu/notifu.exe differ diff --git a/src/Cli/Prime/Resources/bin/snoreToast/snoretoast-x86.exe b/src/Cli/Prime/Resources/bin/snoreToast/snoretoast-x86.exe index 908afb95..e69de29b 100644 Binary files a/src/Cli/Prime/Resources/bin/snoreToast/snoretoast-x86.exe and b/src/Cli/Prime/Resources/bin/snoreToast/snoretoast-x86.exe differ diff --git a/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll b/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll index 4542663e..e69de29b 100644 Binary files a/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll and b/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.Shell.dll differ diff --git a/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.dll b/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.dll index ac869492..e69de29b 100644 Binary files a/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.dll and b/src/Cli/Prime/Resources/bin/toaster/Microsoft.WindowsAPICodePack.dll differ diff --git a/src/Cli/Prime/Resources/bin/toaster/toast.exe b/src/Cli/Prime/Resources/bin/toaster/toast.exe index 64af9c80..e69de29b 100644 Binary files a/src/Cli/Prime/Resources/bin/toaster/toast.exe and b/src/Cli/Prime/Resources/bin/toaster/toast.exe differ diff --git a/src/Cli/Prime/Resources/sounds/error.wav b/src/Cli/Prime/Resources/sounds/error.wav deleted file mode 100644 index c5a6e625..00000000 Binary files a/src/Cli/Prime/Resources/sounds/error.wav and /dev/null differ diff --git a/src/Cli/Prime/Resources/sounds/info.wav b/src/Cli/Prime/Resources/sounds/info.wav deleted file mode 100644 index 3a48e6b3..00000000 Binary files a/src/Cli/Prime/Resources/sounds/info.wav and /dev/null differ diff --git a/src/Cli/Prime/Resources/sounds/success.wav b/src/Cli/Prime/Resources/sounds/success.wav deleted file mode 100644 index 4d319d2d..00000000 Binary files a/src/Cli/Prime/Resources/sounds/success.wav and /dev/null differ diff --git a/src/Cli/Prime/Resources/sounds/warning.wav b/src/Cli/Prime/Resources/sounds/warning.wav deleted file mode 100644 index 5684ce95..00000000 Binary files a/src/Cli/Prime/Resources/sounds/warning.wav and /dev/null differ diff --git a/src/Cli/Prime/Stamp/DesktopStamp.php b/src/Cli/Prime/Stamp/DesktopStamp.php deleted file mode 100644 index 11a40bbe..00000000 --- a/src/Cli/Prime/Stamp/DesktopStamp.php +++ /dev/null @@ -1,24 +0,0 @@ -renderImmediately = $renderImmediately; - } - - /** - * @return bool - */ - public function isRenderImmediately() - { - return $this->renderImmediately; - } -} diff --git a/src/Cli/Prime/System/Command.php b/src/Cli/Prime/System/Command.php index 0bb32253..8fe7e472 100644 --- a/src/Cli/Prime/System/Command.php +++ b/src/Cli/Prime/System/Command.php @@ -1,38 +1,71 @@ + */ + namespace Flasher\Cli\Prime\System; -class Command +final class Command { + /** + * @var string|null + */ private $command; + + /** + * @var array + */ private $options = array(); + + /** + * @var array + */ private $arguments = array(); + /** + * @param string|null $command + */ public function __construct($command) { - $this->command = escapeshellcmd($command); + $this->command = null !== $command ? escapeshellcmd((string) $command) : null; } + /** + * @param string $name + * @param int|string|null $value + * + * @return static + */ public function addOption($name, $value = null) { - $this->options[$name] = escapeshellarg($value); + $this->options[$name] = null !== $value ? escapeshellarg((string) $value) : null; return $this; } + /** + * @param int|string|null $argument + * + * @return static + */ public function addArgument($argument) { - $this->arguments[] = escapeshellarg($argument); + $this->arguments[] = null !== $argument ? escapeshellarg((string) $argument) : $argument; return $this; } + /** + * @return void + */ public function run() { $command = $this->command.' '.$this->formatOptions().' '.$this->formatArguments(); if (OS::isWindows()) { - pclose(popen("start /B ".$command, "r")); + pclose(popen('start /B '.$command, 'r')); // @phpstan-ignore-line return; } @@ -40,11 +73,17 @@ class Command exec($command); } + /** + * @return string + */ private function formatArguments() { return implode(' ', $this->arguments); } + /** + * @return string + */ private function formatOptions() { $line = ''; diff --git a/src/Cli/Prime/System/OS.php b/src/Cli/Prime/System/OS.php index c83f33c4..b200d2e0 100644 --- a/src/Cli/Prime/System/OS.php +++ b/src/Cli/Prime/System/OS.php @@ -1,56 +1,88 @@ + */ + namespace Flasher\Cli\Prime\System; -class OS +final class OS { + /** + * @return string + */ public static function getName() { return php_uname('s'); } + /** + * @return string + */ public static function getRelease() { return php_uname('r'); } + /** + * @return bool + */ public static function isUnix() { - return in_array(self::getName(), array( + return \in_array(self::getName(), array( 'Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS', 'DragonFly', - )); + ), true); } + /** + * @return bool + */ public static function isWindows() { return 'WIN' === strtoupper(substr(self::getName(), 0, 3)); } + /** + * @return bool + */ public static function isWindowsSeven() { return self::isWindows() && '6.1' === self::getRelease(); } + /** + * @return bool + */ public static function isWindowsEightOrHigher() { return self::isWindows() && version_compare(self::getRelease(), '6.2', '>='); } + /** + * @return bool + */ public static function isWindowsSubsystemForLinux() { return self::isUnix() && false !== mb_strpos(strtolower(self::getName()), 'microsoft'); } + /** + * @return bool + */ public static function isMacOS() { return false !== strpos(self::getName(), 'Darwin'); } + /** + * @return string + */ public static function getMacOSVersion() { exec('sw_vers -productVersion', $output); diff --git a/src/Cli/Prime/System/Path.php b/src/Cli/Prime/System/Path.php index 77eb4ca7..ca1c5db4 100644 --- a/src/Cli/Prime/System/Path.php +++ b/src/Cli/Prime/System/Path.php @@ -1,11 +1,21 @@ + */ + namespace Flasher\Cli\Prime\System; -class Path +final class Path { + /** + * @param string $path + * + * @return string + */ public static function realpath($path) { - return realpath(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path)); + return (string) realpath(str_replace(array('/', '\\'), \DIRECTORY_SEPARATOR, $path)); } } diff --git a/src/Cli/Prime/System/Program.php b/src/Cli/Prime/System/Program.php index 311e0f65..4bf58011 100644 --- a/src/Cli/Prime/System/Program.php +++ b/src/Cli/Prime/System/Program.php @@ -1,19 +1,33 @@ -null"); - - return !empty($output); - } - - $output = shell_exec("command -v $program"); - - return !empty($output); - } -} + + */ + +namespace Flasher\Cli\Prime\System; + +final class Program +{ + /** + * @param string|null $program + * + * @return bool + */ + public static function exist($program) + { + if (null === $program) { + return false; + } + + if (OS::isWindows()) { + $output = shell_exec("where {$program} 2>null"); + + return !empty($output); + } + + $output = shell_exec("command -v {$program}"); + + return !empty($output); + } +} diff --git a/src/Cli/Prime/UPGRADING.md b/src/Cli/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Cli/Prime/composer.json b/src/Cli/Prime/composer.json index 94c0f94c..01e1967a 100644 --- a/src/Cli/Prime/composer.json +++ b/src/Cli/Prime/composer.json @@ -2,26 +2,13 @@ "name": "php-flasher/flasher-cli", "description": "PHP Flasher adapter for Cli Console Terminal", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "console", - "Cli", - "Terminal" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "console", "Cli", "Terminal"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -29,7 +16,7 @@ "require": { "php": ">=5.3", "ext-mbstring": "*", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { @@ -39,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Cli/Symfony/.editorconfig b/src/Cli/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Cli/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Cli/Symfony/.gitattributes b/src/Cli/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Cli/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Cli/Symfony/.github/CONTRIBUTING.md b/src/Cli/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Cli/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Cli/Symfony/.github/FUNDING.yml b/src/Cli/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Cli/Symfony/.github/FUNDING.yml +++ b/src/Cli/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Cli/Symfony/.github/SECURITY.md b/src/Cli/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Cli/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Cli/Symfony/.github/dependabot.yml b/src/Cli/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Cli/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Cli/Symfony/.github/workflows/auto_closer.yaml b/src/Cli/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Cli/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Cli/Symfony/.github/workflows/close-pull-request.yml b/src/Cli/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Cli/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Cli/Symfony/.gitignore b/src/Cli/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Cli/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Cli/Symfony/.phpstorm.meta.php b/src/Cli/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Cli/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ - + */ + namespace Flasher\Cli\Symfony\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -8,16 +13,19 @@ use Symfony\Component\DependencyInjection\Reference; final class NotifierCompilerPass implements CompilerPassInterface { + /** + * @return void + */ public function process(ContainerBuilder $container) { - if (!$container->has('flasher.presenter.cli')) { + if (!$container->has('flasher.cli_notifier')) { return; } - $presenter = $container->findDefinition('flasher.presenter.cli'); + $notifier = $container->findDefinition('flasher.cli_notifier'); foreach ($container->findTaggedServiceIds('flasher.cli_notifier') as $id => $tags) { - $presenter->addMethodCall('addNotifier', array(new Reference($id))); + $notifier->addMethodCall('addNotifier', array(new Reference($id))); } } } diff --git a/src/Cli/Symfony/DependencyInjection/Configuration.php b/src/Cli/Symfony/DependencyInjection/Configuration.php index bf6d948f..0d428321 100644 --- a/src/Cli/Symfony/DependencyInjection/Configuration.php +++ b/src/Cli/Symfony/DependencyInjection/Configuration.php @@ -1,8 +1,12 @@ + */ + namespace Flasher\Cli\Symfony\DependencyInjection; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -14,450 +18,25 @@ final class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $name = 'flasher_cli'; + $treeBuilder = new TreeBuilder($name); - $rootNode = $this->getRootNode($treeBuilder, $name); + + $rootNode = method_exists($treeBuilder, 'getRootNode') + ? $treeBuilder->getRootNode() + : $treeBuilder->root($name); // @phpstan-ignore-line $rootNode ->children() - ->booleanNode('render_all') - ->defaultValue(true) - ->end() - ->booleanNode('render_immediately') - ->defaultValue(true) - ->end() ->scalarNode('title') ->defaultValue('PHP Flasher') ->end() - ->booleanNode('mute') - ->defaultValue(true) - ->end() - ->arrayNode('filter_criteria') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() ->arrayNode('icons') ->prototype('variable')->end() ->defaultValue(array()) ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->append($this->addNotifiersConfig()) ->end() ; return $treeBuilder; } - - private function addNotifiersConfig() - { - $name = 'notifiers'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->fixXmlConfig('notifier') - ->children() - ->append($this->addGrowlNotifyNotifier()) - ->append($this->addKDialogNotifier()) - ->append($this->addNotifuNotifier()) - ->append($this->addNotifySendNotifier()) - ->append($this->addSnoreToastNotifier()) - ->append($this->addTerminalNotifierNotifier()) - ->append($this->addToasterNotifier()) - ->append($this->addZenityNotifier()) - ->append($this->addAppleScriptNotifier()) - ->end(); - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addGrowlNotifyNotifier() - { - $name = 'growl_notify'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('growlnotify')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addKDialogNotifier() - { - $name = 'kdialog_notifier'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('kdialog')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addNotifuNotifier() - { - $name = 'notifu_notifier'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('notifu')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addNotifySendNotifier() - { - $name = 'notify_send'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(2) - ->end() - ->scalarNode('binary')->defaultValue('notify-send')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addSnoreToastNotifier() - { - $name = 'snore_toast_notifier'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('snoretoast')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addTerminalNotifierNotifier() - { - $name = 'terminal_notifier_notifier'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('terminal-notifier')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addToasterNotifier() - { - $name = 'toaster'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(0) - ->end() - ->scalarNode('binary')->defaultValue('toast')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addZenityNotifier() - { - $name = 'zenity'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(1) - ->end() - ->scalarNode('binary')->defaultValue('zenity')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - /** - * @return ArrayNodeDefinition - */ - private function addAppleScriptNotifier() - { - $name = 'apple_script'; - $rootNode = $this->getRootNode(new TreeBuilder($name), $name); - - $rootNode - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(true)->end() - ->scalarNode('priority') - ->beforeNormalization() - ->always(function ($v) { return (int) $v; }) - ->end() - ->defaultValue(1) - ->end() - ->scalarNode('binary')->defaultValue('osascript')->end() - ->arrayNode('binary_paths') - ->beforeNormalization() - ->ifString() - ->then(function($v) { return array($v); }) - ->end() - ->prototype('scalar')->end() - ->end() - ->scalarNode('title')->defaultValue(null)->end() - ->booleanNode('mute')->defaultValue(true)->end() - ->arrayNode('icons') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('sounds') - ->prototype('variable')->end() - ->defaultValue(array()) - ->end() - ->end() - ; - - return $rootNode; - } - - private function getRootNode(TreeBuilder $treeBuilder, $name) - { - // BC layer for symfony/config 4.1 and older - if (\method_exists($treeBuilder, 'getRootNode')) { - return $treeBuilder->getRootNode(); - } - - return $treeBuilder->root($name); - } } diff --git a/src/Cli/Symfony/DependencyInjection/FlasherCliExtension.php b/src/Cli/Symfony/DependencyInjection/FlasherCliExtension.php index 5e819277..361a915d 100644 --- a/src/Cli/Symfony/DependencyInjection/FlasherCliExtension.php +++ b/src/Cli/Symfony/DependencyInjection/FlasherCliExtension.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Cli\Symfony\DependencyInjection; use Symfony\Component\Config\FileLocator; @@ -10,56 +15,29 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; final class FlasherCliExtension extends Extension { /** - * @throws \Exception + * @param array> $configs + * + * @return void */ public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); + $configs = $this->processConfiguration(new Configuration(), $configs); - $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.php'); - $container - ->findDefinition('flasher.event_listener.cli_stamps_listener') - ->replaceArgument(0, $config['render_all']) - ->replaceArgument(1, $config['render_immediately']); - - $container - ->findDefinition('flasher.cli') - ->replaceArgument(2, $config['filter_criteria']); - - $this->registerNotifiersConfiguration($container, $config); + $this->configureNotifier($configs, $container); } - private function registerNotifiersConfiguration(ContainerBuilder $container, array $config) + /** + * @param array> $configs + * + * @return void + */ + private function configureNotifier(array $configs, ContainerBuilder $container) { - $this->registerNotifier($container, $config, 'growl_notify'); - $this->registerNotifier($container, $config, 'kdialog_notifier'); - $this->registerNotifier($container, $config, 'notifu_notifier'); - $this->registerNotifier($container, $config, 'notify_send'); - $this->registerNotifier($container, $config, 'snore_toast_notifier'); - $this->registerNotifier($container, $config, 'terminal_notifier_notifier'); - $this->registerNotifier($container, $config, 'toaster'); - $this->registerNotifier($container, $config, 'apple_script'); - } - - private function registerNotifier(ContainerBuilder $container, array $config, $notifier) - { - $container - ->findDefinition("flasher.cli.$notifier") - ->replaceArgument(0, $this->createConfigFor($config, $notifier)); - } - - private function createConfigFor(array $config, $notifier) - { - $options = $config['notifiers'][$notifier]; - - $options['title'] = $config['title']; - $options['mute'] = $config['mute']; - $options['icons'] = array_replace_recursive($config['icons'], $options['icons']); - $options['sounds'] = array_replace_recursive($config['sounds'], $options['sounds']); - - return $options; + $notifier = $container->getDefinition('flasher.notify'); + $notifier->replaceArgument(0, $configs['title']); // @phpstan-ignore-line + $notifier->replaceArgument(1, $configs['icons']); // @phpstan-ignore-line } } diff --git a/src/Cli/Symfony/FlasherCliSymfonyBundle.php b/src/Cli/Symfony/FlasherCliSymfonyBundle.php index f37627f3..7ee4de2c 100644 --- a/src/Cli/Symfony/FlasherCliSymfonyBundle.php +++ b/src/Cli/Symfony/FlasherCliSymfonyBundle.php @@ -1,23 +1,19 @@ + */ + namespace Flasher\Cli\Symfony; -use Flasher\Cli\Prime\Stamp\DesktopStamp; use Flasher\Cli\Symfony\DependencyInjection\Compiler\NotifierCompilerPass; -use Flasher\Prime\Notification\NotificationBuilder; -use Flasher\Symfony\Bridge\FlasherBundle; use Flasher\Cli\Symfony\DependencyInjection\FlasherCliExtension; +use Flasher\Symfony\Bridge\FlasherBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; class FlasherCliSymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle { - public function boot() - { - NotificationBuilder::macro('desktop', function ($renderImmediately = true) { - return $this->withStamp(new DesktopStamp($renderImmediately)); - }); - } - protected function flasherBuild(ContainerBuilder $container) { $container->addCompilerPass(new NotifierCompilerPass()); diff --git a/src/Cli/Symfony/README.md b/src/Cli/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Cli/Symfony/README.md +++ b/src/Cli/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Cli/Symfony/Resources/config/services.php b/src/Cli/Symfony/Resources/config/services.php index d82da21d..a7a34164 100644 --- a/src/Cli/Symfony/Resources/config/services.php +++ b/src/Cli/Symfony/Resources/config/services.php @@ -1,85 +1,47 @@ + */ + +use Flasher\Cli\Prime\Presenter\CliPresenter; use Flasher\Symfony\Bridge\Bridge; +use Symfony\Component\DependencyInjection\ChildDefinition; +use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; -if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { - $definition = new ChildDefinition('flasher.notification_factory'); -} else { - $definition = new DefinitionDecorator('flasher.notification_factory'); +if (!isset($container)) { + return; } +/** @var ChildDefinition $definition */ +$definition = class_exists('Symfony\Component\DependencyInjection\ChildDefinition') + ? new ChildDefinition('flasher.notification_factory') + : new DefinitionDecorator('flasher.notification_factory'); // @phpstan-ignore-line + $definition - ->setClass('Flasher\Cli\Prime\CliNotificationFactory') - ->addArgument(new Reference('flasher.response_manager')) - ->addArgument(array()) + ->setClass('Flasher\Cli\Prime\CliFactory') ->addTag('flasher.factory', array('alias' => 'cli')); $container->setDefinition('flasher.cli', $definition); -$container - ->register('flasher.presenter.cli', 'Flasher\Cli\Prime\Presenter\CliPresenter') - ->addTag('flasher.presenter', array('alias' => 'cli')); +$container->register('flasher.notify', 'Flasher\Cli\Prime\Notify') + ->addArgument(null) + ->addArgument(array()); $container - ->register('flasher.event_listener.cli_stamps_listener', 'Flasher\Cli\Prime\EventListener\StampsListener') - ->addArgument(false) - ->addArgument(true) - ->addTag('flasher.event_subscriber'); + ->register('flasher.cli.presenter', 'Flasher\Cli\Prime\Presenter\CliPresenter') + ->addArgument(new Reference('flasher.notify')) + ->addTag('flasher.presenter', array('alias' => CliPresenter::NAME)); $container - ->register('flasher.event_listener.cli_render_listener', 'Flasher\Cli\Prime\EventListener\RenderListener') - ->addArgument(new Reference('flasher.cli')) + ->register('flasher.cli.render_listener', 'Flasher\Cli\Prime\EventListener\RenderListener') + ->addArgument(new Reference('flasher')) ->addTag('flasher.event_subscriber', array('priority' => -256)); -$container - ->register('flasher.cli.growl_notify', 'Flasher\Cli\Prime\Notifier\GrowlNotifyNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.kdialog_notifier', 'Flasher\Cli\Prime\Notifier\KDialogNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.notifu_notifier', 'Flasher\Cli\Prime\Notifier\NotifuNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.notify_send', 'Flasher\Cli\Prime\Notifier\NotifySendNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.snore_toast_notifier', 'Flasher\Cli\Prime\Notifier\SnoreToastNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.terminal_notifier_notifier', 'Flasher\Cli\Prime\Notifier\TerminalNotifierNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.toaster', 'Flasher\Cli\Prime\Notifier\ToasterNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.zenity', 'Flasher\Cli\Prime\Notifier\ZenityNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - -$container - ->register('flasher.cli.apple_script', 'Flasher\Cli\Prime\Notifier\AppleScriptNotifier') - ->addArgument(array()) - ->addTag('flasher.cli_notifier'); - if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Cli\Prime\CliNotificationFactory', 'flasher.cli'); - $container->setAlias('Flasher\Cli\Prime\CliFlasherInterface', 'Flasher\Cli\Prime\CliNotificationFactory'); + $container->setAlias('Flasher\Cli\Prime\CliFactory', 'flasher.cli'); + $container->setAlias('Flasher\Cli\Prime\Notify', 'flasher.notify'); + $container->setAlias('Flasher\Cli\Prime\NotifyInterface', 'flasher.notify'); } diff --git a/src/Cli/Symfony/UPGRADING.md b/src/Cli/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Cli/Symfony/composer.json b/src/Cli/Symfony/composer.json index 55d75a4c..28cfb86b 100644 --- a/src/Cli/Symfony/composer.json +++ b/src/Cli/Symfony/composer.json @@ -2,37 +2,21 @@ "name": "php-flasher/flasher-cli-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Cli Console Terminal", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "console", - "cli", - "terminal", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "console", "cli", "terminal", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-cli": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-cli": "^1.0" }, "autoload": { "psr-4": { @@ -42,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Laravel/.editorconfig b/src/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Laravel/.gitattributes b/src/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Laravel/.github/CONTRIBUTING.md b/src/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Laravel/.github/FUNDING.yml b/src/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Laravel/.github/FUNDING.yml +++ b/src/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Laravel/.github/SECURITY.md b/src/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Laravel/.github/dependabot.yml b/src/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Laravel/.github/workflows/auto_closer.yaml b/src/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Laravel/.github/workflows/close-pull-request.yml b/src/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Laravel/.gitignore b/src/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Laravel/.phpstorm.meta.php b/src/Laravel/.phpstorm.meta.php index 04d96382..a5c94f72 100644 --- a/src/Laravel/.phpstorm.meta.php +++ b/src/Laravel/.phpstorm.meta.php @@ -4,37 +4,14 @@ namespace PHPSTORM_META; $mapping = [ '' => '@', - - 'Flasher\Prime\Config\ConfigInterface' => \Flasher\Laravel\Config\Config::class, - 'Flasher\Prime\EventDispatcher\EventDispatcherInterface' => \Flasher\Prime\EventDispatcher\EventDispatcher::class, - 'Flasher\Prime\Factory\NotificationFactoryInterface' => \Flasher\Prime\Factory\NotificationFactory::class, - 'Flasher\Prime\Filter\FilterInterface' => \Flasher\Prime\Filter\Filter::class, 'Flasher\Prime\FlasherInterface' => \Flasher\Prime\Flasher::class, - 'Flasher\Prime\Response\ResponseManagerInterface' => \Flasher\Prime\Response\ResponseManager::class, - 'Flasher\Prime\Storage\StorageInterface' => \Flasher\Laravel\Storage\Storage::class, - 'Flasher\Prime\Storage\StorageManagerInterface' => \Flasher\Prime\Storage\StorageManager::class, - 'Flasher\Prime\Template\EngineInterface' => \Flasher\Laravel\Template\BladeEngine::class, - 'flasher' => \Flasher\Prime\Flasher::class, - 'flasher.config' => \Flasher\Laravel\Config\Config::class, - 'flasher.event_dispatcher' => \Flasher\Prime\EventDispatcher\EventDispatcher::class, - 'flasher.filter' => \Flasher\Prime\Filter\Filter::class, - 'flasher.notification_factory' => \Flasher\Prime\Factory\NotificationFactory::class, - 'flasher.template' => \Flasher\Prime\Factory\TemplateFactory::class, 'flasher.noty' => \Flasher\Noty\Prime\NotyFactory::class, 'flasher.notyf' => \Flasher\Notyf\Prime\NotyfFactory::class, 'flasher.pnotify' => \Flasher\Pnotify\Prime\PnotifyFactory::class, - 'flasher.resource_manager' => \Flasher\Prime\Response\Resource\ResourceManager::class, - 'flasher.response_manager' => \Flasher\Prime\Response\ResponseManager::class, - 'flasher.storage' => \Flasher\Laravel\Storage\Storage::class, - 'flasher.storage_manager' => \Flasher\Prime\Storage\StorageManager::class, - 'flasher.sweet_alert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class, - 'flasher.template_engine' => \Flasher\Laravel\Template\BladeEngine::class, + 'flasher.sweetalert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class, + 'flasher.template' => \Flasher\Prime\Factory\FlasherFactory::class, 'flasher.toastr' => \Flasher\Toastr\Prime\ToastrFactory::class, - - 'flasher.template.tailwindcss' => \Flasher\Prime\Factory\TemplateFactory::class, - 'flasher.template.tailwindcss_bg' => \Flasher\Prime\Factory\TemplateFactory::class, - 'flasher.template.boostrap' => \Flasher\Prime\Factory\TemplateFactory::class, ]; override(new \Illuminate\Contracts\Container\Container, map($mapping)); diff --git a/src/Laravel/CHANGELOG.md b/src/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Laravel/CODE_OF_CONDUCT.md b/src/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Laravel/Config/Config.php b/src/Laravel/Config/Config.php deleted file mode 100644 index 69cb8cd3..00000000 --- a/src/Laravel/Config/Config.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - $this->separator = $separator; - } - - public function get($key, $default = null) - { - return $this->getFrom('flasher', $key, $default); - } - - /** - * @param string $namespace - * @param string $key - * @param mixed $default - * - * @return mixed - */ - public function getFrom($namespace, $key, $default = null) - { - return $this->config->get($namespace . $this->separator . $key, $default); - } -} diff --git a/src/Laravel/Facade/Flasher.php b/src/Laravel/Facade/Flasher.php index 86dd9817..ea344cb6 100644 --- a/src/Laravel/Facade/Flasher.php +++ b/src/Laravel/Facade/Flasher.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Laravel\Facade; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationBuilder; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static NotificationBuilder addError(string $message, array $options = array()) * @method static NotificationBuilder addWarning(string $message, array $options = array()) * @method static NotificationBuilder addInfo(string $message, array $options = array()) - * @method static NotificationBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static NotificationBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static NotificationBuilder flash(StampInterface[] $stamps = array()) * @method static NotificationBuilder type(string $type, string $message = null, array $options = array()) * @method static NotificationBuilder message(string $message) diff --git a/src/Laravel/FlasherServiceProvider.php b/src/Laravel/FlasherServiceProvider.php index 463252dc..9dc00039 100644 --- a/src/Laravel/FlasherServiceProvider.php +++ b/src/Laravel/FlasherServiceProvider.php @@ -1,83 +1,239 @@ + */ + namespace Flasher\Laravel; -use Flasher\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Middleware\SessionMiddleware; +use Flasher\Laravel\Storage\SessionBag; +use Flasher\Laravel\Support\Laravel; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Laravel\Template\BladeTemplateEngine; +use Flasher\Prime\Config\Config; +use Flasher\Prime\EventDispatcher\EventDispatcher; +use Flasher\Prime\Flasher; +use Flasher\Prime\Plugin\FlasherPlugin; +use Flasher\Prime\Response\Resource\ResourceManager; +use Flasher\Prime\Response\ResponseManager; +use Flasher\Prime\Storage\StorageBag; +use Flasher\Prime\Storage\StorageManager; +use Illuminate\Foundation\Application; +use Illuminate\Support\Facades\Blade; +use Illuminate\View\Compilers\BladeCompiler; +use Livewire\Component; +use Livewire\LivewireManager; +use Livewire\Response; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ final class FlasherServiceProvider extends ServiceProvider { /** - * Bootstrap the application events. - * + * {@inheritdoc} + */ + public function afterBoot() + { + $this->registerBladeDirectives(); + $this->registerLivewire(); + } + + /** + * @{@inheritdoc} + */ + protected function createPlugin() + { + return new FlasherPlugin(); + } + + /** + * {@inheritdoc} + */ + protected function afterRegister() + { + $this->registerConfig(); + $this->registerFlasher(); + $this->registerResourceManager(); + $this->registerResponseManager(); + $this->registerStorageManager(); + $this->registerEventDispatcher(); + $this->registerSessionMiddleware(); + } + + /** * @return void */ - public function boot() + private function registerConfig() { - /** @var Container $app */ - $app = $this->app; - $manager = new ServiceProviderManager($this, $app); - $manager->boot(); + $this->app->singleton('flasher.config', function (Application $app) { + return new Config($app['config']->get('flasher')); // @phpstan-ignore-line + }); } /** - * Register the service provider. + * @return void */ - public function register() + private function registerFlasher() { - /** @var Container $app */ - $app = $this->app; - $manager = new ServiceProviderManager($this, $app); - $manager->register(); + $this->app->singleton('flasher', function (Application $app) { + return new Flasher($app['flasher.config']->get('default'), $app['flasher.response_manager'], $app['flasher.storage_manager']); // @phpstan-ignore-line + }); + $this->app->alias('flasher', 'Flasher\Prime\Flasher'); + $this->app->bind('Flasher\Prime\FlasherInterface', 'flasher'); } /** - * Get the services provided by the provider. + * @return void + */ + private function registerResourceManager() + { + $this->app->singleton('flasher.resource_manager', function (Application $app) { + return new ResourceManager($app['flasher.config'], new BladeTemplateEngine($app['view'])); // @phpstan-ignore-line + }); + } + + /** + * @return void + */ + private function registerResponseManager() + { + $this->app->singleton('flasher.response_manager', function (Application $app) { + return new ResponseManager($app['flasher.resource_manager'], $app['flasher.storage_manager'], $app['flasher.event_dispatcher']); // @phpstan-ignore-line + }); + } + + /** + * @return void + */ + private function registerStorageManager() + { + $this->app->singleton('flasher.storage_manager', function (Application $app) { + return new StorageManager(new StorageBag(new SessionBag($app['session'])), $app['flasher.event_dispatcher']); // @phpstan-ignore-line + }); + } + + /** + * @return void + */ + private function registerEventDispatcher() + { + $this->app->singleton('flasher.event_dispatcher', function () { + return new EventDispatcher(); + }); + } + + /** + * @return void + */ + private function registerSessionMiddleware() + { + $config = $this->app['flasher.config']; + if (true !== $config->get('flash_bag.enabled', false)) { + return; + } + + $mapping = $config->get('flash_bag.mapping', array()); + $this->app->singleton('Flasher\Laravel\Middleware\SessionMiddleware', function (Application $app) use ($mapping) { + return new SessionMiddleware($app['flasher'], $mapping); // @phpstan-ignore-line + }); + } + + /** + * @return void + */ + private function registerLivewire() + { + if (!$this->app->bound('livewire')) { + return; + } + + $livewire = $this->app->make('livewire'); + if (!$livewire instanceof LivewireManager) { + return; + } + + $livewire->listen('component.dehydrate', function (Component $component, Response $response) { + $data = app('flasher')->render(array(), 'array'); // @phpstan-ignore-line + + if (\count($data['envelopes']) > 0) { + $data['context']['livewire'] = array( + 'id' => $component->id, + 'name' => $response->fingerprint['name'], + ); + + $response->effects['dispatches'][] = array( + 'event' => 'flasher:render', + 'data' => $data, + ); + } + }); + } + + /** + * @return void * - * @return string[] + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function provides() + private function registerBladeDirectives() { - return array( - 'flasher', - ); - } + $startsWith = function ($haystack, $needle) { + return 0 === substr_compare($haystack, $needle, 0, \strlen($needle)); + }; - /** - * @return Container - */ - public function getApplication() - { - /** @var Container $app */ - $app = $this->app; + $endsWith = function ($haystack, $needle) { + return 0 === substr_compare($haystack, $needle, -\strlen($needle)); + }; - return $app; - } + if (Laravel::isVersion('5.1', '>=')) { + Blade::directive('flasher_render', function ($criteria = array()) use ($startsWith, $endsWith) { + if (!empty($criteria) && $startsWith($criteria, '(') && $endsWith($criteria, ')')) { + $criteria = substr($criteria, 1, -1); + } - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } + return "render({$criteria}); ?>"; + }); - /** - * @param string[] $paths - */ - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); - } + return; + } - public function loadTranslationsFrom($path, $namespace) - { - parent::loadTranslationsFrom($path, $namespace); - } + if (Laravel::isVersion('5.0', '>=')) { + Blade::extend(function ($view, BladeCompiler $compiler) use ($startsWith, $endsWith) { + if (!method_exists($compiler, 'createPlainMatcher')) { + return ''; + } - /** - * @param string $path - */ - public function loadViewsFrom($path, $namespace) - { - parent::loadViewsFrom($path, $namespace); + $pattern = $compiler->createPlainMatcher('flasher_render(.*)'); + $matches = array(); + + preg_match($pattern, $view, $matches); + + $value = $matches[2]; + + if (!empty($value) && $startsWith($value, '(') && $endsWith($value, ')')) { + $value = substr($value, 1, -1); + } + + return str_replace( + '%criteria%', + $value, + $matches[1]."render(%criteria%); ?>" + ); + }); + + return; + } + + Blade::extend(function ($view, BladeCompiler $compiler) { + if (!method_exists($compiler, 'createMatcher')) { + return ''; + } + + $pattern = $compiler->createMatcher('flasher_render'); + + return preg_replace($pattern, '$1render$2; ?>', $view); + }); } } diff --git a/src/Laravel/Middleware/SessionMiddleware.php b/src/Laravel/Middleware/SessionMiddleware.php old mode 100755 new mode 100644 index 9a395255..33b1bfce --- a/src/Laravel/Middleware/SessionMiddleware.php +++ b/src/Laravel/Middleware/SessionMiddleware.php @@ -1,36 +1,37 @@ + */ + namespace Flasher\Laravel\Middleware; use Closure; -use Flasher\Prime\Config\ConfigInterface; use Flasher\Prime\FlasherInterface; -use Flasher\Prime\Response\ResponseManagerInterface; +use Flasher\Prime\Response\Presenter\HtmlPresenter; use Illuminate\Http\Request; use Illuminate\Http\Response; final class SessionMiddleware { - /** - * @var ConfigInterface - */ - private $config; - /** * @var FlasherInterface */ private $flasher; /** - * @var ResponseManagerInterface + * @var array */ - private $renderer; + private $mapping; - public function __construct(ConfigInterface $config, FlasherInterface $flasher, ResponseManagerInterface $renderer) + /** + * @param array $mapping + */ + public function __construct(FlasherInterface $flasher, array $mapping = array()) { - $this->config = $config; $this->flasher = $flasher; - $this->renderer = $renderer; + $this->mapping = $this->flatMapping($mapping); } /** @@ -43,19 +44,26 @@ final class SessionMiddleware /** @var Response $response */ $response = $next($request); - if ($request->isXmlHttpRequest() || true !== $this->config->get('auto_create_from_session')) { + if ($request->isXmlHttpRequest() || !$request->hasSession()) { + return $response; + } + + $content = $response->getContent() ?: ''; + $insertPlaceHolder = HtmlPresenter::FLASHER_FLASH_BAG_PLACE_HOLDER; + $insertPosition = strripos($content, $insertPlaceHolder); + if (false === $insertPosition) { return $response; } $readyToRender = false; - - foreach ($this->typesMapping() as $alias => $type) { + foreach ($this->mapping as $alias => $type) { if (false === $request->session()->has($alias)) { continue; } - $this->flasher->addFlash($type, $request->session()->get($alias)); - + /** @var string $message */ + $message = $request->session()->get($alias); + $this->flasher->addFlash((string) $type, $message); $readyToRender = true; } @@ -63,40 +71,32 @@ final class SessionMiddleware return $response; } - $htmlResponse = $this->renderer->render(array(), 'html'); + $htmlResponse = $this->flasher->render(array(), 'html', array('envelopes_only' => true)); if (empty($htmlResponse)) { return $response; } - $content = $response->getContent(); - if (false === $content) { - return $response; - } - - $pos = (int) strripos($content, ''); - $content = substr($content, 0, $pos) . $htmlResponse . substr($content, $pos); + $content = substr($content, 0, $insertPosition).$htmlResponse.substr($content, $insertPosition + \strlen($insertPlaceHolder)); $response->setContent($content); return $response; } /** - * @return array + * @param array $mapping + * + * @return array */ - private function typesMapping() + private function flatMapping(array $mapping) { - $mapping = array(); + $flatMapping = array(); - foreach ($this->config->get('types_mapping', array()) as $type => $aliases) { - if (is_int($type) && is_string($aliases)) { - $type = $aliases; - } - - foreach ((array) $aliases as $alias) { - $mapping[$alias] = $type; + foreach ($mapping as $type => $aliases) { + foreach ($aliases as $alias) { + $flatMapping[$alias] = $type; } } - return $mapping; // @phpstan-ignore-line + return $flatMapping; } } diff --git a/src/Laravel/Observer/FlasherModelObserver.php b/src/Laravel/Observer/FlasherModelObserver.php deleted file mode 100644 index d7c0c624..00000000 --- a/src/Laravel/Observer/FlasherModelObserver.php +++ /dev/null @@ -1,116 +0,0 @@ -config = $config; - $this->flasher = $flasher; - $this->translator = $translator; - } - - /** - * Handle the Model "created" event. - * - * @return void - */ - public function created(Model $model) - { - $this->addFlash(__FUNCTION__, $model); - } - - /** - * Handle the Model "updated" event. - * - * @return void - */ - public function updated(Model $model) - { - $this->addFlash(__FUNCTION__, $model); - } - - /** - * Handle the Model "deleted" event. - * - * @return void - */ - public function deleted(Model $model) - { - $this->addFlash(__FUNCTION__, $model); - } - - /** - * Handle the Model "restored" event. - * - * @return void - */ - public function restored(Model $model) - { - $this->addFlash(__FUNCTION__, $model); - } - - /** - * Handle the Model "force deleted" event. - * - * @return void - */ - public function forceDeleted(Model $model) - { - $this->addFlash(__FUNCTION__, $model); - } - - /** - * @param string $method - * - * @return void - */ - private function addFlash($method, Model $model) - { - $excludes = $this->config->get('observer_events.exclude', array()); - if (in_array($method, $excludes, true)) { - return; - } - - if (isset($excludes[$method]) && in_array(get_class($model), $excludes[$method], true)) { - return; - } - - if ($this->translator->has(sprintf('flasher::messages.flashable.%s.%s', get_class($model), $method))) { - $message = $this->translator->get(sprintf('flasher::messages.flashable.%s.%s', get_class($model), $method)); - } else { - $message = $this->translator->get(sprintf('flasher::messages.flashable.default.%s', $method)); - $replace = strrchr(get_class($model), '\\'); - if (false !== $replace) { - $message = str_replace('{{ model }}', substr($replace, 1), $message); - } - } - - if (is_array($message)) { - return; - } - - $this->flasher->addSuccess($message); - } -} diff --git a/src/Laravel/README.md b/src/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Laravel/README.md +++ b/src/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Laravel/Resources/config/config.php b/src/Laravel/Resources/config/config.php deleted file mode 100644 index dac6d62e..00000000 --- a/src/Laravel/Resources/config/config.php +++ /dev/null @@ -1,49 +0,0 @@ - 'template', - - 'root_script' => 'https://cdn.jsdelivr.net/npm/@flasher/flasher@0.7.1/dist/flasher.min.js', - - 'template_factory' => array( - 'default' => 'tailwindcss', - 'templates' => array( - 'tailwindcss' => array( - 'view' => 'flasher::tailwindcss', - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'tailwindcss_bg' => array( - 'view' => 'flasher::tailwindcss_bg', - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'bootstrap' => array( - 'view' => 'flasher::bootstrap', - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css', - ), - ), - ), - ), - - 'auto_create_from_session' => true, - - 'types_mapping' => array( - 'success' => array('success'), - 'error' => array('error', 'danger'), - 'warning' => array('warning', 'alarm'), - 'info' => array('info', 'notice', 'alert'), - ), - - 'observer_events' => array( - 'exclude' => array( - 'forceDeleted', - 'restored', - ), - ), -); diff --git a/src/Laravel/Resources/lang/en/messages.php b/src/Laravel/Resources/lang/en/messages.php deleted file mode 100644 index ab9fb320..00000000 --- a/src/Laravel/Resources/lang/en/messages.php +++ /dev/null @@ -1,13 +0,0 @@ - array( - 'default' => array( - 'created' => '{{ model }} has been created.', - 'updated' => '{{ model }} has been updated.', - 'deleted' => '{{ model }} has been deleted.', - 'restored' => '{{ model }} has been restored.', - 'forceDeleted' => '{{ model }} has been deleted.', - ), - ), -); diff --git a/src/Laravel/Resources/views/bootstrap.blade.php b/src/Laravel/Resources/views/bootstrap.blade.php deleted file mode 100644 index 81e850d7..00000000 --- a/src/Laravel/Resources/views/bootstrap.blade.php +++ /dev/null @@ -1,64 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $alertClass = 'alert-success'; - $progressBackgroundColor = '#155724'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $alertClass = 'alert-danger'; - $progressBackgroundColor = '#721c24'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $alertClass = 'alert-warning'; - $progressBackgroundColor = '#856404'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $alertClass = 'alert-info'; - $progressBackgroundColor = '#0c5460'; - $icon = ''; - break; -} -?> - -
- - - - - - - - - - - - -
- -
-
diff --git a/src/Laravel/Resources/views/tailwindcss.blade.php b/src/Laravel/Resources/views/tailwindcss.blade.php deleted file mode 100644 index 6f28773a..00000000 --- a/src/Laravel/Resources/views/tailwindcss.blade.php +++ /dev/null @@ -1,68 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $textColor = 'text-green-600'; - $backgroundColor = 'bg-green-600'; - $progressBackgroundColor = 'bg-green-100'; - $borderColor = 'border-green-600'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $textColor = 'text-red-600'; - $backgroundColor = 'bg-red-600'; - $progressBackgroundColor = 'bg-red-100'; - $borderColor = 'border-red-600'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $textColor = 'text-yellow-600'; - $backgroundColor = 'bg-yellow-600'; - $progressBackgroundColor = 'bg-yellow-100'; - $borderColor = 'border-yellow-600'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $textColor = 'text-blue-600'; - $backgroundColor = 'bg-blue-600'; - $progressBackgroundColor = 'bg-blue-100'; - $borderColor = 'border-blue-600'; - $icon = ''; - break; -} -?> -
-
-
- {!! $icon !!} -
-
-

- {{ $notification->getTitle() ?: $title }} -

-

- {{ $notification->getMessage() }} -

-
-
-
- -
-
diff --git a/src/Laravel/Resources/views/tailwindcss_bg.blade.php b/src/Laravel/Resources/views/tailwindcss_bg.blade.php deleted file mode 100644 index 70b402e2..00000000 --- a/src/Laravel/Resources/views/tailwindcss_bg.blade.php +++ /dev/null @@ -1,69 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $textColor = 'text-green-700'; - $backgroundColor = 'bg-green-50'; - $progressBackgroundColor = 'bg-green-200'; - $borderColor = 'border-green-600'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $textColor = 'text-red-700'; - $backgroundColor = 'bg-red-50'; - $progressBackgroundColor = 'bg-red-200'; - $borderColor = 'border-red-600'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $textColor = 'text-yellow-700'; - $backgroundColor = 'bg-yellow-50'; - $progressBackgroundColor = 'bg-yellow-200'; - $borderColor = 'border-yellow-600'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $textColor = 'text-blue-700'; - $backgroundColor = 'bg-blue-50'; - $progressBackgroundColor = 'bg-blue-100'; - $borderColor = 'border-blue-600'; - $icon = ''; - break; -} -?> - -
-
-
- {!! $icon !!} -
-
-

- {{ $notification->getTitle() ?: $title }} -

-

- {{ $notification->getMessage() }} -

-
-
-
- -
-
diff --git a/src/Laravel/ServiceProvider/Providers/Laravel.php b/src/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100755 index bd598898..00000000 --- a/src/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,215 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherServiceProvider $provider) - { - $provider->loadTranslationsFrom(flasher_path(__DIR__ . '/../../Resources/lang'), 'flasher'); - $provider->loadViewsFrom(flasher_path(__DIR__ . '/../../Resources/views'), 'flasher'); - - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher.php'), - ), 'flasher-config'); - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/lang') => resource_path(flasher_path('lang/vendor/flasher')), - ), 'flasher-lang'); - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/views') => resource_path(flasher_path('views/vendor/flasher')), - ), 'flasher-views'); - - $this->registerBladeDirectives(); - $this->bootServices($this->app); - } - - /** - * @return void - */ - protected function bootServices(Container $app) - { - $templates = $app['flasher.config']->get('template_factory.templates', array()); - foreach ($templates as $template => $options) { - $app->bind('flasher.template.'.$template, function (Application $app) use ($template) { - $factory = new TemplateFactory($app['flasher.storage_manager']); - $factory->setHandler('template.' . $template); - - return $factory; - }); - } - - $app->extend('flasher', function (Flasher $flasher, Application $app) use ($templates) { - foreach ($templates as $template => $options) { - $flasher->addFactory('template.' . $template, $app['flasher.template.' . $template]); - } - - return $flasher; - }); - } - - public function register(FlasherServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher'); - - $this->app->singleton('flasher.config', function (Application $app) { - return new Config($app['config'], '.'); - }); - - $this->registerCommonServices(); - } - - /** - * @return void - */ - protected function registerCommonServices() - { - $this->app->singleton('flasher', function (Application $app) { - $flasher = new Flasher($app['flasher.config'], $app['flasher.response_manager']); - $flasher->addFactory('template', $app['flasher.template']); - - return $flasher; - }); - - $this->app->singleton('flasher.resource_manager', function (Application $app) { - $resourceManager = new ResourceManager($app['flasher.config'], $app['flasher.template_engine']); - - $templates = $app['flasher.config']->get('template_factory.templates', array()); - foreach ($templates as $template => $factory) { - if (isset($factory['scripts'])) { - $resourceManager->addScripts('template.' . $template, $factory['scripts']); - } - if (isset($factory['styles'])) { - $resourceManager->addStyles('template.' . $template, $factory['styles']); - } - if (isset($factory['options'])) { - $resourceManager->addOptions('template.' . $template, $factory['options']); - } - } - - return $resourceManager; - }); - - $this->app->singleton('flasher.response_manager', function (Application $app) { - $responseManager = new ResponseManager( - $app['flasher.storage_manager'], - $app['flasher.event_dispatcher'], - $app['flasher.resource_manager'] - ); - - $responseManager->addPresenter('html', new HtmlPresenter()); - $responseManager->addPresenter('array', new ArrayPresenter()); - - return $responseManager; - }); - - $this->app->singleton('flasher.storage', function (Application $app) { - return new Storage($app['session']); - }); - - $this->app->singleton('flasher.storage_manager', function (Application $app) { - return new StorageManager($app['flasher.storage'], $app['flasher.event_dispatcher']); - }); - - $this->app->singleton('flasher.filter', function (Application $app) { - return new Filter(); - }); - - $this->app->singleton('flasher.template_engine', function (Application $app) { - return new BladeEngine($app['view']); - }); - - $this->app->singleton('flasher.event_dispatcher', function (Application $app) { - $eventDispatcher = new EventDispatcher(); - - $eventDispatcher->addSubscriber(new FilterListener($app['flasher.filter'])); - $eventDispatcher->addSubscriber(new RemoveListener()); - $eventDispatcher->addSubscriber(new StampsListener()); - - return $eventDispatcher; - }); - - $this->app->singleton('flasher.template', function (Application $app) { - return new TemplateFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.config', 'Flasher\Laravel\Config\Config'); - $this->app->alias('flasher', 'Flasher\Prime\Flasher'); - $this->app->alias('flasher.response_manager', 'Flasher\Prime\Response\ResponseManager'); - $this->app->alias('flasher.event_dispatcher', 'Flasher\Prime\EventDispatcher\EventDispatcher'); - $this->app->alias('flasher.storage', 'Flasher\Laravel\Storage\Storage'); - $this->app->alias('flasher.storage_manager', 'Flasher\Laravel\Storage\StorageManager'); - $this->app->alias('flasher.filter', 'Flasher\Prime\Filter\Filter'); - $this->app->alias('flasher.template_engine', 'Flasher\Laravel\Template\BladeEngine'); - $this->app->alias('flasher.template', 'Flasher\Prime\Factory\TemplateFactory'); - - $this->app->alias('flasher.template', 'flasher.notification_factory'); - $this->app->alias('flasher.template', 'Flasher\Prime\Factory\NotificationFactory'); - - $this->app->bind('Flasher\Prime\Config\ConfigInterface', 'flasher.config'); - $this->app->bind('Flasher\Prime\FlasherInterface', 'flasher'); - $this->app->bind('Flasher\Prime\Storage\StorageManagerInterface', 'flasher.storage_manager'); - $this->app->bind('Flasher\Prime\Response\ResponseManagerInterface', 'flasher.response_manager'); - $this->app->bind('Flasher\Prime\Filter\FilterInterface', 'flasher.filter'); - $this->app->bind('Flasher\Prime\EventDispatcher\EventDispatcherInterface', 'flasher.event_dispatcher'); - $this->app->bind('Flasher\Prime\Storage\StorageInterface', 'flasher.storage'); - $this->app->bind('Flasher\Prime\Template\EngineInterface', 'flasher.template_engine'); - $this->app->bind('Flasher\Prime\Factory\NotificationFactoryInterface', 'flasher.template'); - } - - /** - * @return void - */ - protected function registerBladeDirectives() - { - $startsWith = function ($haystack, $needle) { - return substr_compare($haystack, $needle, 0, strlen($needle)) === 0; - }; - - $endsWith = function ($haystack, $needle) { - return substr_compare($haystack, $needle, -strlen($needle)) === 0; - }; - - Blade::directive('flasher_render', function ($criteria = array()) use ($startsWith, $endsWith) { - if (!empty($criteria) && $startsWith($criteria, '(') && $endsWith($criteria, ')')) { - $criteria = substr($criteria, 1, -1); - } - - return "render(${criteria}); ?>"; - }); - } -} diff --git a/src/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 618ee638..00000000 --- a/src/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,51 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherServiceProvider $provider) - { - // @phpstan-ignore-next-line - $provider->package('php-flasher/flasher-laravel', 'flasher', flasher_path(__DIR__ . '/../../Resources')); - - $this->registerBladeDirectives(); - $this->bootServices($this->app); - } - - public function register(FlasherServiceProvider $provider) - { - $this->app->singleton('flasher.config', function (Application $app) { - return new Config($app['config'], '::'); - }); - - $this->registerCommonServices(); - } - - /** - * @return void - */ - protected function registerBladeDirectives() - { - Blade::extend(function ($view, BladeCompiler $compiler) { - if (!method_exists($compiler, 'createMatcher')) { - return ''; - } - - $pattern = $compiler->createMatcher('flasher_render'); - - return preg_replace($pattern, '$1render$2; ?>', $view); - }); - } -} diff --git a/src/Laravel/ServiceProvider/Providers/Laravel50.php b/src/Laravel/ServiceProvider/Providers/Laravel50.php deleted file mode 100644 index 44898351..00000000 --- a/src/Laravel/ServiceProvider/Providers/Laravel50.php +++ /dev/null @@ -1,63 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '5.0'); - } - - public function boot(FlasherServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/lang') => base_path(flasher_path('resources/lang/vendor/flasher')), - )); - - $this->registerBladeDirectives(); - $this->bootServices($this->app); - } - - /** - * @return void - */ - protected function registerBladeDirectives() - { - $startsWith = function ($haystack, $needle) { - return substr_compare($haystack, $needle, 0, strlen($needle)) === 0; - }; - - $endsWith = function ($haystack, $needle) { - return substr_compare($haystack, $needle, -strlen($needle)) === 0; - }; - - Blade::extend(function ($view, BladeCompiler $compiler) use ($startsWith, $endsWith) { - if (!method_exists($compiler, 'createPlainMatcher')) { - return ''; - } - - $pattern = $compiler->createPlainMatcher('flasher_render(.*)'); - $matches = array(); - - preg_match($pattern, $view, $matches); - - $value = $matches[2]; - - if (!empty($value) && $startsWith($value, '(') && $endsWith($value, ')')) { - $value = substr($value, 1, -1); - } - - return str_replace( - '%criteria%', - $value, - $matches[1] . "render(%criteria%); ?>" - ); - }); - } -} diff --git a/src/Laravel/ServiceProvider/Providers/Laravel51.php b/src/Laravel/ServiceProvider/Providers/Laravel51.php deleted file mode 100644 index ee22ea1c..00000000 --- a/src/Laravel/ServiceProvider/Providers/Laravel51.php +++ /dev/null @@ -1,24 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '5.1'); - } - - public function boot(FlasherServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/lang') => base_path(flasher_path('resources/lang/vendor/flasher')), - )); - - $this->registerBladeDirectives(); - $this->bootServices($this->app); - } -} diff --git a/src/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index fcf11060..00000000 --- a/src/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,23 +0,0 @@ - $config - * - * @return void - */ - public static function process(ResourceManager $responseManager, $alias, $config = null) - { - if (null === $config) { - $config = $responseManager->getConfig()->get('adapters.' . $alias); - } - - $responseManager->addScripts($alias, self::getScripts($config)); - $responseManager->addStyles($alias, self::getStyles($config)); - $responseManager->addOptions($alias, self::getOptions($config)); - } - - /** - * @param array $config - * - * @return string[] - */ - private static function getScripts($config) - { - return isset($config['scripts']) ? $config['scripts'] : array(); - } - - /** - * @param array $config - * - * @return string[] - */ - private static function getStyles($config) - { - return isset($config['styles']) ? $config['styles'] : array(); - } - - /** - * @param array $config - * - * @return array - */ - private static function getOptions($config) - { - return isset($config['options']) ? $config['options'] : array(); - } -} diff --git a/src/Laravel/ServiceProvider/ServiceProviderManager.php b/src/Laravel/ServiceProvider/ServiceProviderManager.php deleted file mode 100644 index fa19362c..00000000 --- a/src/Laravel/ServiceProvider/ServiceProviderManager.php +++ /dev/null @@ -1,73 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - - $this->providers = array( - new Laravel4($app), - new Laravel50($app), - new Laravel51($app), - new Laravel($app), - ); - } - - /** - * @return void - */ - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - /** - * @return void - */ - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $provider) { - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Laravel/Storage/SessionBag.php b/src/Laravel/Storage/SessionBag.php new file mode 100644 index 00000000..d5c3fd3c --- /dev/null +++ b/src/Laravel/Storage/SessionBag.php @@ -0,0 +1,45 @@ + + */ + +namespace Flasher\Laravel\Storage; + +use Flasher\Prime\Storage\Bag\BagInterface; +use Illuminate\Session\Store; + +final class SessionBag implements BagInterface +{ + const ENVELOPES_NAMESPACE = 'flasher::envelopes'; + + /** + * @var Store + */ + private $session; + + /** + * @param Store $session + */ + public function __construct($session) + { + $this->session = $session; + } + + /** + * {@inheritdoc} + */ + public function get() + { + return $this->session->get(self::ENVELOPES_NAMESPACE, array()); // @phpstan-ignore-line + } + + /** + * {@inheritdoc} + */ + public function set(array $envelopes) + { + $this->session->put(self::ENVELOPES_NAMESPACE, $envelopes); + } +} diff --git a/src/Laravel/Storage/Storage.php b/src/Laravel/Storage/Storage.php deleted file mode 100644 index ba816206..00000000 --- a/src/Laravel/Storage/Storage.php +++ /dev/null @@ -1,89 +0,0 @@ -session = $session; - } - - public function all() - { - return $this->session->get(self::ENVELOPES_NAMESPACE, array()); - } - - public function add($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - - $this->session->put(self::ENVELOPES_NAMESPACE, array_merge($this->all(), $envelopes)); - } - - public function update($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $map = UuidStamp::indexByUuid($envelopes); - - $store = $this->all(); - foreach ($store as $index => $envelope) { - $uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp'); - - if (!$uuidStamp instanceof UuidStamp) { - continue; - } - - $uuid = $uuidStamp->getUuid(); - - if (!isset($map[$uuid])) { - continue; - } - - $store[$index] = $map[$uuid]; - } - - $this->session->put(self::ENVELOPES_NAMESPACE, $store); - } - - public function remove($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - - $map = UuidStamp::indexByUuid($envelopes); - - $store = array_filter($this->all(), function (Envelope $envelope) use ($map) { - $uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp'); - - if (!$uuidStamp instanceof UuidStamp) { - return false; - } - - $uuid = $uuidStamp->getUuid(); - - return !isset($map[$uuid]); - }); - - $this->session->put(self::ENVELOPES_NAMESPACE, $store); - } - - public function clear() - { - $this->session->put(self::ENVELOPES_NAMESPACE, array()); - } -} diff --git a/src/Laravel/Support/Laravel.php b/src/Laravel/Support/Laravel.php new file mode 100644 index 00000000..e766da8a --- /dev/null +++ b/src/Laravel/Support/Laravel.php @@ -0,0 +1,32 @@ + + */ + +namespace Flasher\Laravel\Support; + +use Illuminate\Foundation\Application; + +final class Laravel +{ + /** + * @param string $version + * @param string|null $operator + * + * @return bool + */ + public static function isVersion($version, $operator = null) + { + if (null !== $operator) { + return version_compare(Application::VERSION, $version, $operator); + } + + $parts = explode('.', $version); + ++$parts[\count($parts) - 1]; + $next = implode('.', $parts); + + return self::isVersion($version, '>=') && self::isVersion($next, '<'); + } +} diff --git a/src/Laravel/Support/ServiceProvider.php b/src/Laravel/Support/ServiceProvider.php new file mode 100644 index 00000000..b05ff321 --- /dev/null +++ b/src/Laravel/Support/ServiceProvider.php @@ -0,0 +1,121 @@ + + */ + +namespace Flasher\Laravel\Support; + +use Flasher\Prime\FlasherInterface; +use Flasher\Prime\Plugin\PluginInterface; +use Flasher\Prime\Response\Resource\ResourceManagerInterface; +use Illuminate\Container\Container; +use Illuminate\Support\ServiceProvider as BaseServiceProvider; + +abstract class ServiceProvider extends BaseServiceProvider +{ + /** + * @var PluginInterface|null + */ + protected $plugin; + + /** + * {@inheritdoc} + */ + public function register() + { + $this->plugin = $this->plugin ?: $this->createPlugin(); + + $this->processConfiguration(); + $this->afterRegister(); + } + + /** + * @return void + */ + public function boot() + { + $this->registerFactory(); + $this->afterBoot(); + } + + /** + * @return PluginInterface + */ + abstract protected function createPlugin(); + + /** + * @return void + */ + protected function processConfiguration() + { + if (null === $this->plugin) { + return; + } + + $name = $this->plugin->getName(); + $config = $this->app['config']; // @phpstan-ignore-line + + $config->set($name, $this->plugin->processConfiguration( + $config->get($name, array()) + )); + } + + /** + * @return void + */ + protected function afterRegister() + { + } + + /** + * @return void + */ + protected function afterBoot() + { + } + + /** + * @return void + */ + protected function registerFactory() + { + $plugin = $this->plugin; + if (null === $plugin) { + return; + } + + if (!class_exists($plugin->getFactory())) { + return; + } + + $this->app->singleton($plugin->getServiceID(), function (Container $app) use ($plugin) { + $factory = $plugin->getFactory(); + + return new $factory($app['flasher.storage_manager']); + }); + + $this->app->alias($plugin->getServiceID(), $plugin->getFactory()); + + $this->app->extend('flasher', function (FlasherInterface $flasher, Container $app) use ($plugin) { + $flasher->addFactory($plugin->getAlias(), $app[$plugin->getServiceID()]); // @phpstan-ignore-line + + return $flasher; + }); + + $config = $this->app['config']->get($this->plugin->getName(), array()); // @phpstan-ignore-line + $this->app->extend('flasher.resource_manager', function (ResourceManagerInterface $manager) use ($plugin, $config) { + $scripts = isset($config['scripts']) ? $config['scripts'] : array(); + $manager->addScripts($plugin->getAlias(), $scripts); + + $styles = isset($config['styles']) ? $config['styles'] : array(); + $manager->addStyles($plugin->getAlias(), $styles); + + $options = isset($config['options']) ? $config['options'] : array(); + $manager->addOptions($plugin->getAlias(), $options); + + return $manager; + }); + } +} diff --git a/src/Laravel/Template/BladeEngine.php b/src/Laravel/Template/BladeTemplateEngine.php similarity index 65% rename from src/Laravel/Template/BladeEngine.php rename to src/Laravel/Template/BladeTemplateEngine.php index 7a699cea..13066fb9 100644 --- a/src/Laravel/Template/BladeEngine.php +++ b/src/Laravel/Template/BladeTemplateEngine.php @@ -1,11 +1,16 @@ + */ + namespace Flasher\Laravel\Template; -use Flasher\Prime\Template\EngineInterface; +use Flasher\Prime\Template\TemplateEngineInterface; use Illuminate\View\Factory; -final class BladeEngine implements EngineInterface +final class BladeTemplateEngine implements TemplateEngineInterface { /** * @var Factory diff --git a/src/Laravel/UPGRADING.md b/src/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Laravel/composer.json b/src/Laravel/composer.json index eb326b45..d496b373 100644 --- a/src/Laravel/composer.json +++ b/src/Laravel/composer.json @@ -2,28 +2,13 @@ "name": "php-flasher/flasher-laravel", "description": "Laravel package integrating PHP Flasher into Laravel applications", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "flasher", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "flasher", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -31,14 +16,14 @@ "require": { "php": ">=5.3", "illuminate/support": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Laravel\\": "" }, "files": [ - "helpers.php" + "flasher.php" ] }, "extra": { @@ -54,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Laravel/flasher.php b/src/Laravel/flasher.php new file mode 100644 index 00000000..ddf739ed --- /dev/null +++ b/src/Laravel/flasher.php @@ -0,0 +1,47 @@ + + */ + +use Flasher\Prime\FlasherInterface; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Stamp\StampInterface; + +if (!function_exists('flash')) { + /** + * @param string $message + * @param string $type + * @param array $options + * @param StampInterface[] $stamps + * + * @return Envelope|FlasherInterface + */ + function flash($message = null, $type = 'success', array $options = array(), array $stamps = array()) + { + /** @var FlasherInterface $factory */ + $factory = app('flasher'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->with($stamps)->addFlash($type, $message, $options); + } +} + +if (!function_exists('flasher')) { + /** + * @param string $message + * @param string $type + * @param array $options + * @param StampInterface[] $stamps + * + * @return Envelope|FlasherInterface + */ + function flasher($message = null, $type = 'success', array $options = array(), array $stamps = array()) + { + return flash($message, $type, $options, $stamps); + } +} diff --git a/src/Laravel/helpers.php b/src/Laravel/helpers.php deleted file mode 100644 index 8fee9df5..00000000 --- a/src/Laravel/helpers.php +++ /dev/null @@ -1,40 +0,0 @@ - $options - * @param StampInterface[] $stamps - * - * @return FlasherInterface - */ - function flash($message = null, $type = 'success', array $options = array(), array $stamps = array()) - { - $flasher = app('flasher'); - - if (null === $message && 0 === func_num_args()) { - return $flasher; - } - - return $flasher->with($stamps)->addFlash($type, $message, $options); - } -} - -if (!function_exists('flasher')) { - /** - * @param string $message - * @param string $type - * @param array $options - * @param StampInterface[] $stamps - * - * @return FlasherInterface - */ - function flasher($message = null, $type = 'success', array $options = array(), array $stamps = array()) - { - return flash($message, $type, $options, $stamps); - } -} diff --git a/src/Livewire/.editorconfig b/src/Livewire/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Livewire/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Livewire/.gitattributes b/src/Livewire/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Livewire/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Livewire/.github/CONTRIBUTING.md b/src/Livewire/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Livewire/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Livewire/.github/SECURITY.md b/src/Livewire/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Livewire/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Livewire/.github/dependabot.yml b/src/Livewire/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Livewire/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Livewire/.github/workflows/close-pull-request.yml b/src/Livewire/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Livewire/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Livewire/.gitignore b/src/Livewire/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Livewire/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Livewire/CHANGELOG.md b/src/Livewire/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Livewire/CODE_OF_CONDUCT.md b/src/Livewire/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Livewire/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Livewire/FlasherLivewireServiceProvider.php b/src/Livewire/FlasherLivewireServiceProvider.php deleted file mode 100644 index 0d2e4885..00000000 --- a/src/Livewire/FlasherLivewireServiceProvider.php +++ /dev/null @@ -1,64 +0,0 @@ -withStamp(new LivewireStamp($context)); - }); - - Livewire::listen('component.dehydrate', function ($component, $response) { - $data = $this->app['flasher.response_manager']->render(array( - 'stamps' => LivewireStamp::class, - ), 'array'); - - if (count($data['envelopes']) > 0) { - $data['context']['livewire'] = $response->fingerprint; - $response->effects['dispatches'][] = [ - 'event' => 'flasher:render', - 'data' => $data, - ]; - } - }); - - Blade::directive('flasher_livewire_render', function () { - return "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', - ); - } -} diff --git a/src/Livewire/LICENSE b/src/Livewire/LICENSE deleted file mode 100644 index 8d26d89b..00000000 --- a/src/Livewire/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -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. diff --git a/src/Livewire/LivewireResponseManager.php b/src/Livewire/LivewireResponseManager.php deleted file mode 100644 index a75027d1..00000000 --- a/src/Livewire/LivewireResponseManager.php +++ /dev/null @@ -1,76 +0,0 @@ -config = $config; - } - - public function render(): string - { - $importScript = ''; - $rootScript = $this->config->get('root_script'); - if (!empty($rootScript)) { - $importScript = << - ${importScript} - - window.addEventListener('flasher:render', function (event) { - Flasher.getInstance().render(event.detail); - }); - - window.addEventListener('flasher:sweet_alert:promise', function (event) { - var envelope = event.detail.envelope; - var context = envelope.context; - - if (!context.livewire || !context.livewire.id) { - return; - } - - var detail = event.detail; - if (envelope.livewire_context) { - detail.context = envelope.livewire_context; - } - - var component = context.livewire.id; - - Livewire.components.emitSelf(component, 'sweetAlertEvent', detail); - - var promise = event.detail.promise; - if (promise.isConfirmed) { - Livewire.components.emitSelf(component, 'sweetAlertConfirmed', detail); - } - - if (promise.isDenied) { - Livewire.components.emitSelf(component, 'sweetAlertDenied', detail); - } - - if (promise.isDismissed) { - Livewire.components.emitSelf(component, 'sweetAlertDismissed', detail); - } - }, false); - -JAVASCRIPT; - } -} diff --git a/src/Livewire/LivewireStamp.php b/src/Livewire/LivewireStamp.php deleted file mode 100644 index 32101c08..00000000 --- a/src/Livewire/LivewireStamp.php +++ /dev/null @@ -1,30 +0,0 @@ -context = $context; - } - - public function getContext(): array - { - return $this->context; - } - - public function toArray() - { - return [ - 'livewire_context' => $this->getContext(), - ]; - } -} diff --git a/src/Livewire/UPGRADING.md b/src/Livewire/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Livewire/composer.json b/src/Livewire/composer.json deleted file mode 100644 index d9d5a6d7..00000000 --- a/src/Livewire/composer.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "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.9" - }, - "autoload": { - "psr-4": { - "Flasher\\Livewire\\": "" - } - }, - "extra": { - "laravel": { - "providers": [ - "Flasher\\Livewire\\FlasherLivewireServiceProvider" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev", - "prefer-stable": true -} diff --git a/src/Noty/Laravel/.editorconfig b/src/Noty/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Noty/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Noty/Laravel/.gitattributes b/src/Noty/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Noty/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Noty/Laravel/.github/CONTRIBUTING.md b/src/Noty/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Noty/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Noty/Laravel/.github/FUNDING.yml b/src/Noty/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Noty/Laravel/.github/FUNDING.yml +++ b/src/Noty/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Noty/Laravel/.github/SECURITY.md b/src/Noty/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Noty/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Noty/Laravel/.github/dependabot.yml b/src/Noty/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Noty/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Noty/Laravel/.github/workflows/auto_closer.yaml b/src/Noty/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Noty/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Noty/Laravel/.github/workflows/close-pull-request.yml b/src/Noty/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Noty/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Noty/Laravel/.gitignore b/src/Noty/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Noty/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Noty/Laravel/CHANGELOG.md b/src/Noty/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Noty/Laravel/CODE_OF_CONDUCT.md b/src/Noty/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Noty/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Noty/Laravel/Facade/Noty.php b/src/Noty/Laravel/Facade/Noty.php index f7d1cd42..20467c60 100644 --- a/src/Noty/Laravel/Facade/Noty.php +++ b/src/Noty/Laravel/Facade/Noty.php @@ -1,9 +1,14 @@ + */ + namespace Flasher\Noty\Laravel\Facade; use Flasher\Noty\Prime\NotyBuilder; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; use Illuminate\Support\Facades\Facade; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static NotyBuilder addError(string $message, array $options = array()) * @method static NotyBuilder addWarning(string $message, array $options = array()) * @method static NotyBuilder addInfo(string $message, array $options = array()) - * @method static NotyBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static NotyBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static NotyBuilder flash(StampInterface[] $stamps = array()) * @method static NotyBuilder type(string $type, string $message = null, array $options = array()) * @method static NotyBuilder message(string $message) @@ -32,14 +37,13 @@ use Illuminate\Support\Facades\Facade; * @method static NotyBuilder withStamp(StampInterface $stamp) * @method static NotyBuilder handler(string $handler) * @method static Envelope getEnvelope() - * * @method static NotyBuilder text(string $text) * @method static NotyBuilder alert(string $message = null, array $options = array()) * @method static NotyBuilder layout(string $layout) * @method static NotyBuilder theme(string $theme) - * @method static NotyBuilder timeout(int|bool $timeout) + * @method static NotyBuilder timeout(bool|int $timeout) * @method static NotyBuilder progressBar(bool $progressBar = false) - * @method static NotyBuilder closeWith(string|array $closeWith) + * @method static NotyBuilder closeWith(array|string $closeWith) * @method static NotyBuilder animation(string $animation, string $effect) * @method static NotyBuilder sounds(string $option, mixed $value) * @method static NotyBuilder docTitle(string $option, mixed $docTitle) diff --git a/src/Noty/Laravel/FlasherNotyServiceProvider.php b/src/Noty/Laravel/FlasherNotyServiceProvider.php index b8158c83..ea48ab86 100644 --- a/src/Noty/Laravel/FlasherNotyServiceProvider.php +++ b/src/Noty/Laravel/FlasherNotyServiceProvider.php @@ -1,55 +1,22 @@ + */ + namespace Flasher\Noty\Laravel; -use Flasher\Noty\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Noty\Prime\NotyPlugin; final class FlasherNotyServiceProvider extends ServiceProvider { - public function boot() - { - $manager = new ServiceProviderManager($this); - $manager->boot(); - } - /** - * Register the service provider. + * {@inheritDoc} */ - public function register() + protected function createPlugin() { - $manager = new ServiceProviderManager($this); - $manager->register(); - } - - /** - * Get the services provided by the provider. - * - * @return string[] - */ - public function provides() - { - return array( - 'flasher.noty', - ); - } - - /** - * @return Container - */ - public function getApplication() - { - return $this->app; - } - - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } - - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); + return new NotyPlugin(); } } diff --git a/src/Noty/Laravel/README.md b/src/Noty/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Noty/Laravel/README.md +++ b/src/Noty/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Noty/Laravel/Resources/config/config.php b/src/Noty/Laravel/Resources/config/config.php deleted file mode 100644 index 9dd622cc..00000000 --- a/src/Noty/Laravel/Resources/config/config.php +++ /dev/null @@ -1,11 +0,0 @@ - array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-noty@0.1.3/dist/flasher-noty.min.js', - ), - 'styles' => array(), - 'options' => array( - 'timeout' => 5000, - ), -); diff --git a/src/Noty/Laravel/Resources/functions/noty.php b/src/Noty/Laravel/Resources/functions/noty.php deleted file mode 100644 index 3b727333..00000000 --- a/src/Noty/Laravel/Resources/functions/noty.php +++ /dev/null @@ -1,21 +0,0 @@ -addFlash($type, $message, $options); - } -} diff --git a/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php b/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index 45f8d052..00000000 --- a/src/Noty/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,74 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherNotyServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_noty.php'), - ), 'flasher-config'); - } - - public function register(FlasherNotyServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_noty'); - $this->appendToFlasherConfig(); - - $this->registerServices(); - } - - protected function registerServices() - { - $this->app->singleton('flasher.noty', function (Container $app) { - return new NotyFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.noty', 'Flasher\Noty\Prime\NotyFactory'); - - $this->app->extend('flasher', function (Flasher $flasher, Container $app) { - $flasher->addFactory('noty', $app['flasher.noty']); - - return $flasher; - }); - - $this->app->extend('flasher.resource_manager', function (ResourceManager $resourceManager) { - ResourceManagerHelper::process($resourceManager, 'noty'); - - return $resourceManager; - }); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher.adapters.noty', array()); - - $notyConfig = $this->app['config']->get('flasher_noty', array()); - - $this->app['config']->set('flasher.adapters.noty', array_merge($notyConfig, $flasherConfig)); - } -} diff --git a/src/Noty/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Noty/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 2b937345..00000000 --- a/src/Noty/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,38 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherNotyServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-noty-laravel', - 'flasher_noty', - flasher_path(__DIR__ . '/../../Resources') - ); - $this->appendToFlasherConfig(); - } - - public function register(FlasherNotyServiceProvider $provider) - { - $this->registerServices(); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher::config.adapters.noty', array()); - - $notyConfig = $this->app['config']->get('flasher_noty::config', array()); - - $this->app['config']->set('flasher::config.adapters.noty', array_merge($notyConfig, $flasherConfig)); - } -} diff --git a/src/Noty/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Noty/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index 740dc308..00000000 --- a/src/Noty/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Noty/Laravel/UPGRADING.md b/src/Noty/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Noty/Laravel/composer.json b/src/Noty/Laravel/composer.json index b7337a33..e51b127a 100644 --- a/src/Noty/Laravel/composer.json +++ b/src/Noty/Laravel/composer.json @@ -2,48 +2,34 @@ "name": "php-flasher/flasher-noty-laravel", "type": "library", "description": "PHP Flasher Laravel adapter for Noty", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "noty ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "noty ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-noty": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-noty": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Noty\\Laravel\\": "" }, "files": [ - "Resources/functions/noty.php" + "noty.php" ] }, "extra": { "laravel": { "providers": [ - "Flasher\\Noty\\Laravel\\FlasherNotyServiceProvider" + "Flasher\\Noty\\Laravel\\FlasherNotyServiceProvider" ], "aliases": { "Noty": "Flasher\\Laravel\\Facade\\Flasher" @@ -53,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Noty/Laravel/noty.php b/src/Noty/Laravel/noty.php new file mode 100644 index 00000000..ee3cfa8f --- /dev/null +++ b/src/Noty/Laravel/noty.php @@ -0,0 +1,31 @@ + + */ + +use Flasher\Noty\Prime\NotyFactory; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\NotificationInterface; + +if (!function_exists('noty')) { + /** + * @param string $message + * @param string $type + * @param array $options + * + * @return Envelope|NotyFactory + */ + function noty($message = null, $type = NotificationInterface::SUCCESS, array $options = array()) + { + /** @var NotyFactory $factory */ + $factory = app('flasher.noty'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->addFlash($type, $message, $options); + } +} diff --git a/src/Noty/Prime/.editorconfig b/src/Noty/Prime/.editorconfig deleted file mode 100755 index cd8eb86e..00000000 --- a/src/Noty/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Noty/Prime/.gitattributes b/src/Noty/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Noty/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Noty/Prime/.github/CONTRIBUTING.md b/src/Noty/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Noty/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Noty/Prime/.github/FUNDING.yml b/src/Noty/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Noty/Prime/.github/FUNDING.yml +++ b/src/Noty/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Noty/Prime/.github/SECURITY.md b/src/Noty/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Noty/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Noty/Prime/.github/dependabot.yml b/src/Noty/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Noty/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Noty/Prime/.github/workflows/auto_closer.yaml b/src/Noty/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Noty/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Noty/Prime/.github/workflows/close-pull-request.yml b/src/Noty/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Noty/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Noty/Prime/.gitignore b/src/Noty/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Noty/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Noty/Prime/CHANGELOG.md b/src/Noty/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Noty/Prime/CODE_OF_CONDUCT.md b/src/Noty/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Noty/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Noty/Prime/Noty.php b/src/Noty/Prime/Noty.php deleted file mode 100644 index 65d9d871..00000000 --- a/src/Noty/Prime/Noty.php +++ /dev/null @@ -1,9 +0,0 @@ - + */ + namespace Flasher\Noty\Prime; use Flasher\Prime\Notification\NotificationBuilder; +/** + * @SuppressWarnings(PHPMD.TooManyMethods) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ final class NotyBuilder extends NotificationBuilder { /** @@ -11,7 +20,7 @@ final class NotyBuilder extends NotificationBuilder * * @param string $text * - * @return NotyBuilder + * @return static */ public function text($text) { @@ -19,9 +28,10 @@ final class NotyBuilder extends NotificationBuilder } /** - * @param string $message + * @param string $message + * @param array $options * - * @return NotyBuilder + * @return static */ public function alert($message = null, array $options = array()) { @@ -30,11 +40,11 @@ final class NotyBuilder extends NotificationBuilder /** * top, topLeft, topCenter, topRight, center, centerLeft, centerRight, bottom, bottomLeft, bottomCenter, bottomRight - * - ClassName generator uses this value → noty_layout__${layout} + * - ClassName generator uses this value → noty_layout__${layout}. * * @param string $layout * - * @return $this + * @return static */ public function layout($layout) { @@ -44,11 +54,11 @@ final class NotyBuilder extends NotificationBuilder } /** - * relax, mint, metroui - ClassName generator uses this value → noty_theme__${theme} + * relax, mint, metroui - ClassName generator uses this value → noty_theme__${theme}. * * @param string $theme * - * @return $this + * @return static */ public function theme($theme) { @@ -60,9 +70,9 @@ final class NotyBuilder extends NotificationBuilder /** * false, 1000, 3000, 3500, etc. Delay for closing event in milliseconds (ms). Set 'false' for sticky notifications. * - * @param int|bool $timeout + * @param bool|int $timeout * - * @return $this + * @return static */ public function timeout($timeout) { @@ -76,7 +86,7 @@ final class NotyBuilder extends NotificationBuilder * * @param bool $progressBar * - * @return $this + * @return static */ public function progressBar($progressBar = false) { @@ -86,11 +96,11 @@ final class NotyBuilder extends NotificationBuilder } /** - * click, button + * click, button. * - * @param string|array $closeWith + * @param array|string $closeWith * - * @return $this + * @return static */ public function closeWith($closeWith) { @@ -106,37 +116,37 @@ final class NotyBuilder extends NotificationBuilder * @param string $animation * @param string $effect * - * @return $this + * @return static */ public function animation($animation, $effect) { - $this->option('animation.' . $animation, $effect); + $this->option('animation.'.$animation, $effect); return $this; } /** * @param string $option - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function sounds($option, $value) { - $this->option('sounds.' . $option, $value); + $this->option('sounds.'.$option, $value); return $this; } /** * @param string $option - * @param mixed $docTitle + * @param mixed $docTitle * - * @return $this + * @return static */ public function docTitle($option, $docTitle) { - $this->option('docTitle' . $option, $docTitle); + $this->option('docTitle'.$option, $docTitle); return $this; } @@ -144,7 +154,7 @@ final class NotyBuilder extends NotificationBuilder /** * @param bool $modal * - * @return $this + * @return static */ public function modal($modal = true) { @@ -158,7 +168,10 @@ final class NotyBuilder extends NotificationBuilder * * @param bool|string $id * - * @return $this + * @return static + * + * @SuppressWarnings(PHPMD.ShortMethodName) + * @SuppressWarnings(PHPMD.ShortVariable) */ public function id($id) { @@ -172,7 +185,7 @@ final class NotyBuilder extends NotificationBuilder * * @param bool $force * - * @return $this + * @return static */ public function force($force = true) { @@ -184,7 +197,7 @@ final class NotyBuilder extends NotificationBuilder /** * @param string $queue * - * @return $this + * @return static */ public function queue($queue) { @@ -197,9 +210,9 @@ final class NotyBuilder extends NotificationBuilder * If true closes all visible notifications and shows itself. If string(queueName) closes all visible notification * on this queue and shows itself. * - * @param string|bool $killer + * @param bool|string $killer * - * @return $this + * @return static */ public function killer($killer) { @@ -211,9 +224,9 @@ final class NotyBuilder extends NotificationBuilder /** * Custom container selector string. Like '.my-custom-container'. Layout parameter will be ignored. * - * @param string|bool $container + * @param bool|string $container * - * @return $this + * @return static */ public function container($container) { @@ -225,9 +238,9 @@ final class NotyBuilder extends NotificationBuilder /** * An array of Noty.button, for creating confirmation dialogs. * - * @param array $buttons + * @param array $buttons * - * @return $this + * @return static */ public function buttons($buttons) { @@ -241,7 +254,7 @@ final class NotyBuilder extends NotificationBuilder * * @param bool $visibilityControl * - * @return $this + * @return static */ public function visibilityControl($visibilityControl) { diff --git a/src/Noty/Prime/NotyFactory.php b/src/Noty/Prime/NotyFactory.php index 36793c89..2525201b 100644 --- a/src/Noty/Prime/NotyFactory.php +++ b/src/Noty/Prime/NotyFactory.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Noty\Prime; use Flasher\Prime\Factory\NotificationFactory; +use Flasher\Prime\Notification\Notification; /** * @mixin NotyBuilder @@ -11,6 +17,6 @@ final class NotyFactory extends NotificationFactory { public function createNotificationBuilder() { - return new NotyBuilder($this->getStorageManager(), new Noty(), 'noty'); + return new NotyBuilder($this->getStorageManager(), new Notification(), 'noty'); } } diff --git a/src/Noty/Prime/NotyPlugin.php b/src/Noty/Prime/NotyPlugin.php new file mode 100644 index 00000000..9634f88d --- /dev/null +++ b/src/Noty/Prime/NotyPlugin.php @@ -0,0 +1,23 @@ + + */ + +namespace Flasher\Noty\Prime; + +use Flasher\Prime\Plugin\Plugin; + +class NotyPlugin extends Plugin +{ + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array( + 'https://cdn.jsdelivr.net/npm/@flasher/flasher-noty@1.0.7/dist/flasher-noty.min.js', + ); + } +} diff --git a/src/Noty/Prime/README.md b/src/Noty/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/Noty/Prime/README.md +++ b/src/Noty/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Noty/Prime/UPGRADING.md b/src/Noty/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Noty/Prime/composer.json b/src/Noty/Prime/composer.json index ee3990ad..7a63347f 100644 --- a/src/Noty/Prime/composer.json +++ b/src/Noty/Prime/composer.json @@ -2,31 +2,20 @@ "name": "php-flasher/flasher-noty", "description": "PHP Flasher adapter for Noty", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "noty " - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "noty "], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { @@ -36,6 +25,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Noty/Symfony/.editorconfig b/src/Noty/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Noty/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Noty/Symfony/.gitattributes b/src/Noty/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Noty/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Noty/Symfony/.github/CONTRIBUTING.md b/src/Noty/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Noty/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Noty/Symfony/.github/FUNDING.yml b/src/Noty/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Noty/Symfony/.github/FUNDING.yml +++ b/src/Noty/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Noty/Symfony/.github/SECURITY.md b/src/Noty/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Noty/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Noty/Symfony/.github/dependabot.yml b/src/Noty/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Noty/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Noty/Symfony/.github/workflows/auto_closer.yaml b/src/Noty/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Noty/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Noty/Symfony/.github/workflows/close-pull-request.yml b/src/Noty/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Noty/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Noty/Symfony/.gitignore b/src/Noty/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Noty/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Noty/Symfony/.phpstorm.meta.php b/src/Noty/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Noty/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ -getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher_noty'); - } - - $rootNode - ->children() - ->arrayNode('scripts') - ->prototype('scalar')->end() - ->defaultValue(array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-noty@0.1.3/dist/flasher-noty.min.js', - )) - ->end() - ->arrayNode('styles') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('options') - ->prototype('variable')->end() - ->ignoreExtraKeys(false) - ->defaultValue(array( - 'timeout' => 5000, - )) - ->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php b/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php deleted file mode 100644 index 9084bdef..00000000 --- a/src/Noty/Symfony/DependencyInjection/FlasherNotyExtension.php +++ /dev/null @@ -1,23 +0,0 @@ -load('services.php'); - } - - public function getConfigurationClass() - { - return new Configuration(); - } -} diff --git a/src/Noty/Symfony/FlasherNotySymfonyBundle.php b/src/Noty/Symfony/FlasherNotySymfonyBundle.php index 3a600ed6..e55ad46f 100644 --- a/src/Noty/Symfony/FlasherNotySymfonyBundle.php +++ b/src/Noty/Symfony/FlasherNotySymfonyBundle.php @@ -1,21 +1,22 @@ + */ + namespace Flasher\Noty\Symfony; -use Flasher\Noty\Symfony\DependencyInjection\FlasherNotyExtension; -use Flasher\Symfony\Bridge\FlasherBundle; -use Flasher\Symfony\DependencyInjection\Compiler\ResourceCompilerPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Flasher\Noty\Prime\NotyPlugin; +use Flasher\Symfony\Support\Bundle; -class FlasherNotySymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle +class FlasherNotySymfonyBundle extends Bundle // Symfony\Component\HttpKernel\Bundle\Bundle { - protected function flasherBuild(ContainerBuilder $container) + /** + * {@inheritDoc} + */ + protected function createPlugin() { - $container->addCompilerPass(new ResourceCompilerPass($this->getFlasherContainerExtension())); - } - - protected function getFlasherContainerExtension() - { - return new FlasherNotyExtension(); + return new NotyPlugin(); } } diff --git a/src/Noty/Symfony/README.md b/src/Noty/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Noty/Symfony/README.md +++ b/src/Noty/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Noty/Symfony/Resources/config/services.php b/src/Noty/Symfony/Resources/config/services.php deleted file mode 100644 index 1db9e5ba..00000000 --- a/src/Noty/Symfony/Resources/config/services.php +++ /dev/null @@ -1,21 +0,0 @@ -setClass('Flasher\Noty\Prime\NotyFactory') - ->addTag('flasher.factory', array('alias' => 'noty')); - -$container->setDefinition('flasher.noty', $definition); - -if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Noty\Prime\NotyFactory', 'flasher.noty'); -} diff --git a/src/Noty/Symfony/UPGRADING.md b/src/Noty/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Noty/Symfony/composer.json b/src/Noty/Symfony/composer.json index 2a674d97..6ec89d82 100644 --- a/src/Noty/Symfony/composer.json +++ b/src/Noty/Symfony/composer.json @@ -2,35 +2,21 @@ "name": "php-flasher/flasher-noty-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Noty", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "noty ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "noty ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-noty": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-noty": "^1.0" }, "autoload": { "psr-4": { @@ -40,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Notyf/Laravel/.editorconfig b/src/Notyf/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Notyf/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Notyf/Laravel/.gitattributes b/src/Notyf/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Notyf/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Notyf/Laravel/.github/CONTRIBUTING.md b/src/Notyf/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Notyf/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Notyf/Laravel/.github/FUNDING.yml b/src/Notyf/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Notyf/Laravel/.github/FUNDING.yml +++ b/src/Notyf/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Notyf/Laravel/.github/SECURITY.md b/src/Notyf/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Notyf/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Notyf/Laravel/.github/dependabot.yml b/src/Notyf/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Notyf/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Notyf/Laravel/.github/workflows/auto_closer.yaml b/src/Notyf/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Notyf/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Notyf/Laravel/.github/workflows/close-pull-request.yml b/src/Notyf/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Notyf/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Notyf/Laravel/.gitignore b/src/Notyf/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Notyf/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Notyf/Laravel/CHANGELOG.md b/src/Notyf/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Notyf/Laravel/CODE_OF_CONDUCT.md b/src/Notyf/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Notyf/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Notyf/Laravel/Facade/Notyf.php b/src/Notyf/Laravel/Facade/Notyf.php index 06b17cc5..496d6cdb 100644 --- a/src/Notyf/Laravel/Facade/Notyf.php +++ b/src/Notyf/Laravel/Facade/Notyf.php @@ -1,9 +1,14 @@ + */ + namespace Flasher\Notyf\Laravel\Facade; use Flasher\Notyf\Prime\NotyfBuilder; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; use Illuminate\Support\Facades\Facade; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static NotyfBuilder addError(string $message, array $options = array()) * @method static NotyfBuilder addWarning(string $message, array $options = array()) * @method static NotyfBuilder addInfo(string $message, array $options = array()) - * @method static NotyfBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static NotyfBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static NotyfBuilder flash(StampInterface[] $stamps = array()) * @method static NotyfBuilder type(string $type, string $message = null, array $options = array()) * @method static NotyfBuilder message(string $message) @@ -32,7 +37,6 @@ use Illuminate\Support\Facades\Facade; * @method static NotyfBuilder withStamp(StampInterface $stamp) * @method static NotyfBuilder handler(string $handler) * @method static Envelope getEnvelope() - * * @method static NotyfBuilder duration(int $duration) * @method static NotyfBuilder ripple(bool $ripple) * @method static NotyfBuilder position(string $position, string $value) diff --git a/src/Notyf/Laravel/FlasherNotyfServiceProvider.php b/src/Notyf/Laravel/FlasherNotyfServiceProvider.php index 570698b0..62a26404 100644 --- a/src/Notyf/Laravel/FlasherNotyfServiceProvider.php +++ b/src/Notyf/Laravel/FlasherNotyfServiceProvider.php @@ -1,55 +1,22 @@ + */ + namespace Flasher\Notyf\Laravel; -use Flasher\Notyf\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Notyf\Prime\NotyfPlugin; -class FlasherNotyfServiceProvider extends ServiceProvider +final class FlasherNotyfServiceProvider extends ServiceProvider { - public function boot() - { - $manager = new ServiceProviderManager($this); - $manager->boot(); - } - /** - * Register the service provider. + * {@inheritDoc} */ - public function register() + protected function createPlugin() { - $manager = new ServiceProviderManager($this); - $manager->register(); - } - - /** - * Get the services provided by the provider. - * - * @return string[] - */ - public function provides() - { - return array( - 'flasher.notyf', - ); - } - - /** - * @return Container - */ - public function getApplication() - { - return $this->app; - } - - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } - - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); + return new NotyfPlugin(); } } diff --git a/src/Notyf/Laravel/README.md b/src/Notyf/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Notyf/Laravel/README.md +++ b/src/Notyf/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Notyf/Laravel/Resources/config/config.php b/src/Notyf/Laravel/Resources/config/config.php deleted file mode 100644 index f250699d..00000000 --- a/src/Notyf/Laravel/Resources/config/config.php +++ /dev/null @@ -1,11 +0,0 @@ - array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-notyf@0.1.8/dist/flasher-notyf.min.js', - ), - 'styles' => array(), - 'options' => array( - 'duration' => 5000, - ), -); diff --git a/src/Notyf/Laravel/Resources/functions/notyf.php b/src/Notyf/Laravel/Resources/functions/notyf.php deleted file mode 100644 index bcd04bc1..00000000 --- a/src/Notyf/Laravel/Resources/functions/notyf.php +++ /dev/null @@ -1,21 +0,0 @@ -addFlash($type, $message, $options); - } -} diff --git a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index 11baddc1..00000000 --- a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,74 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherNotyfServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_notyf.php'), - ), 'flasher-config'); - } - - public function register(FlasherNotyfServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_notyf'); - $this->appendToFlasherConfig(); - - $this->registerServices(); - } - - public function registerServices() - { - $this->app->singleton('flasher.notyf', function (Container $app) { - return new NotyfFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.notyf', 'Flasher\Notyf\Prime\NotyfFactory'); - - $this->app->extend('flasher', function (Flasher $manager, Container $app) { - $manager->addFactory('notyf', $app['flasher.notyf']); - - return $manager; - }); - - $this->app->extend('flasher.resource_manager', function (ResourceManager $resourceManager) { - ResourceManagerHelper::process($resourceManager, 'notyf'); - - return $resourceManager; - }); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher.adapters.notyf', array()); - - $notyfConfig = $this->app['config']->get('flasher_notyf', array()); - - $this->app['config']->set('flasher.adapters.notyf', array_merge($notyfConfig, $flasherConfig)); - } -} diff --git a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Notyf/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 7c25cb74..00000000 --- a/src/Notyf/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,39 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherNotyfServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-notyf-laravel', - 'flasher_notyf', - flasher_path(__DIR__ . '/../../Resources') - ); - - $this->appendToFlasherConfig(); - } - - public function register(FlasherNotyfServiceProvider $provider) - { - $this->registerServices(); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher::config.adapters.notyf', array()); - - $notyfConfig = $this->app['config']->get('flasher_notyf::config', array()); - - $this->app['config']->set('flasher::config.adapters.notyf', array_merge($notyfConfig, $flasherConfig)); - } -} diff --git a/src/Notyf/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Notyf/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index 29c67d3b..00000000 --- a/src/Notyf/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Notyf/Laravel/UPGRADING.md b/src/Notyf/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Notyf/Laravel/composer.json b/src/Notyf/Laravel/composer.json index 0f07636f..1bd99dd5 100644 --- a/src/Notyf/Laravel/composer.json +++ b/src/Notyf/Laravel/composer.json @@ -2,43 +2,28 @@ "name": "php-flasher/flasher-notyf-laravel", "description": "PHP Flasher Laravel adapter for Notyf", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "notyf ", - "bundle", - "flex", - "toastr" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "notyf ", "bundle", "flex", "toastr"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-notyf": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-notyf": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Notyf\\Laravel\\": "" }, "files": [ - "Resources/functions/notyf.php" + "notyf.php" ] }, "extra": { @@ -54,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Notyf/Laravel/notyf.php b/src/Notyf/Laravel/notyf.php new file mode 100644 index 00000000..547a4665 --- /dev/null +++ b/src/Notyf/Laravel/notyf.php @@ -0,0 +1,31 @@ + + */ + +use Flasher\Notyf\Prime\NotyfFactory; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\NotificationInterface; + +if (!function_exists('notyf')) { + /** + * @param string $message + * @param string $type + * @param array $options + * + * @return Envelope|NotyfFactory + */ + function notyf($message = null, $type = NotificationInterface::SUCCESS, array $options = array()) + { + /** @var NotyfFactory $factory */ + $factory = app('flasher.notyf'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->addFlash($type, $message, $options); + } +} diff --git a/src/Notyf/Prime/.editorconfig b/src/Notyf/Prime/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Notyf/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Notyf/Prime/.gitattributes b/src/Notyf/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Notyf/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Notyf/Prime/.github/CONTRIBUTING.md b/src/Notyf/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Notyf/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Notyf/Prime/.github/FUNDING.yml b/src/Notyf/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Notyf/Prime/.github/FUNDING.yml +++ b/src/Notyf/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Notyf/Prime/.github/SECURITY.md b/src/Notyf/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Notyf/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Notyf/Prime/.github/dependabot.yml b/src/Notyf/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Notyf/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Notyf/Prime/.github/workflows/auto_closer.yaml b/src/Notyf/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Notyf/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Notyf/Prime/.github/workflows/close-pull-request.yml b/src/Notyf/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Notyf/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Notyf/Prime/.gitignore b/src/Notyf/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Notyf/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Notyf/Prime/CHANGELOG.md b/src/Notyf/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Notyf/Prime/CODE_OF_CONDUCT.md b/src/Notyf/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Notyf/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Notyf/Prime/Notyf.php b/src/Notyf/Prime/Notyf.php deleted file mode 100644 index 92d31c8a..00000000 --- a/src/Notyf/Prime/Notyf.php +++ /dev/null @@ -1,9 +0,0 @@ - + */ + namespace Flasher\Notyf\Prime; use Flasher\Prime\Notification\NotificationBuilder; @@ -11,7 +16,7 @@ final class NotyfBuilder extends NotificationBuilder * * @param int $duration * - * @return $this + * @return static */ public function duration($duration) { @@ -21,11 +26,11 @@ final class NotyfBuilder extends NotificationBuilder } /** - * Whether to show the notification with a ripple effect + * Whether to show the notification with a ripple effect. * * @param bool $ripple * - * @return $this + * @return static */ public function ripple($ripple) { @@ -35,17 +40,17 @@ final class NotyfBuilder extends NotificationBuilder } /** - * Viewport location where notifications are rendered + * Viewport location where notifications are rendered. * * @param string $position * @param string $value * - * @return $this + * @return static */ public function position($position, $value) { $option = $this->getEnvelope()->getOption('position', array()); - $option[$position] = $value; + $option[$position] = $value; // @phpstan-ignore-line $this->option('position', $option); @@ -53,11 +58,11 @@ final class NotyfBuilder extends NotificationBuilder } /** - * Whether to allow users to dismiss the notification with a button + * Whether to allow users to dismiss the notification with a button. * * @param bool $dismissible * - * @return $this + * @return static */ public function dismissible($dismissible) { diff --git a/src/Notyf/Prime/NotyfFactory.php b/src/Notyf/Prime/NotyfFactory.php index 8bc3fdef..23e8a71e 100644 --- a/src/Notyf/Prime/NotyfFactory.php +++ b/src/Notyf/Prime/NotyfFactory.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Notyf\Prime; use Flasher\Prime\Factory\NotificationFactory; +use Flasher\Prime\Notification\Notification; /** * @mixin NotyfBuilder @@ -11,6 +17,6 @@ final class NotyfFactory extends NotificationFactory { public function createNotificationBuilder() { - return new NotyfBuilder($this->getStorageManager(), new Notyf(), 'notyf'); + return new NotyfBuilder($this->getStorageManager(), new Notification(), 'notyf'); } } diff --git a/src/Notyf/Prime/NotyfPlugin.php b/src/Notyf/Prime/NotyfPlugin.php new file mode 100644 index 00000000..ff24d6a9 --- /dev/null +++ b/src/Notyf/Prime/NotyfPlugin.php @@ -0,0 +1,23 @@ + + */ + +namespace Flasher\Notyf\Prime; + +use Flasher\Prime\Plugin\Plugin; + +class NotyfPlugin extends Plugin +{ + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array( + 'https://cdn.jsdelivr.net/npm/@flasher/flasher-notyf@1.0.7/dist/flasher-notyf.min.js', + ); + } +} diff --git a/src/Notyf/Prime/README.md b/src/Notyf/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/Notyf/Prime/README.md +++ b/src/Notyf/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Notyf/Prime/UPGRADING.md b/src/Notyf/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Notyf/Prime/composer.json b/src/Notyf/Prime/composer.json index 07b7c893..ff4912e2 100644 --- a/src/Notyf/Prime/composer.json +++ b/src/Notyf/Prime/composer.json @@ -2,32 +2,20 @@ "name": "php-flasher/flasher-notyf", "description": "PHP Flasher adapter for Notyf", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "Sweet Alert", - "notyf" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "Sweet Alert", "notyf"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { @@ -37,6 +25,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Notyf/Symfony/.editorconfig b/src/Notyf/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Notyf/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Notyf/Symfony/.gitattributes b/src/Notyf/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Notyf/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Notyf/Symfony/.github/CONTRIBUTING.md b/src/Notyf/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Notyf/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Notyf/Symfony/.github/FUNDING.yml b/src/Notyf/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Notyf/Symfony/.github/FUNDING.yml +++ b/src/Notyf/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Notyf/Symfony/.github/SECURITY.md b/src/Notyf/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Notyf/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Notyf/Symfony/.github/dependabot.yml b/src/Notyf/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Notyf/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Notyf/Symfony/.github/workflows/auto_closer.yaml b/src/Notyf/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Notyf/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Notyf/Symfony/.github/workflows/close-pull-request.yml b/src/Notyf/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Notyf/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Notyf/Symfony/.gitignore b/src/Notyf/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Notyf/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Notyf/Symfony/.phpstorm.meta.php b/src/Notyf/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Notyf/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ -getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher_notyf'); - } - - $rootNode - ->children() - ->arrayNode('scripts') - ->prototype('scalar')->end() - ->defaultValue(array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-notyf@0.1.8/dist/flasher-notyf.min.js', - )) - ->end() - ->arrayNode('styles') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('options') - ->ignoreExtraKeys(false) - ->prototype('variable')->end() - ->defaultValue(array( - 'duration' => 5000, - )) - ->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php b/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php deleted file mode 100644 index 138039ab..00000000 --- a/src/Notyf/Symfony/DependencyInjection/FlasherNotyfExtension.php +++ /dev/null @@ -1,23 +0,0 @@ -load('services.php'); - } - - public function getConfigurationClass() - { - return new Configuration(); - } -} diff --git a/src/Notyf/Symfony/FlasherNotyfSymfonyBundle.php b/src/Notyf/Symfony/FlasherNotyfSymfonyBundle.php index 30683bf4..8106bf7e 100644 --- a/src/Notyf/Symfony/FlasherNotyfSymfonyBundle.php +++ b/src/Notyf/Symfony/FlasherNotyfSymfonyBundle.php @@ -1,21 +1,22 @@ + */ + namespace Flasher\Notyf\Symfony; -use Flasher\Notyf\Symfony\DependencyInjection\FlasherNotyfExtension; -use Flasher\Symfony\Bridge\FlasherBundle; -use Flasher\Symfony\DependencyInjection\Compiler\ResourceCompilerPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Flasher\Notyf\Prime\NotyfPlugin; +use Flasher\Symfony\Support\Bundle; -class FlasherNotyfSymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle +class FlasherNotyfSymfonyBundle extends Bundle // Symfony\Component\HttpKernel\Bundle\Bundle { - protected function flasherBuild(ContainerBuilder $container) + /** + * {@inheritDoc} + */ + protected function createPlugin() { - $container->addCompilerPass(new ResourceCompilerPass($this->getFlasherContainerExtension())); - } - - protected function getFlasherContainerExtension() - { - return new FlasherNotyfExtension(); + return new NotyfPlugin(); } } diff --git a/src/Notyf/Symfony/README.md b/src/Notyf/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Notyf/Symfony/README.md +++ b/src/Notyf/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Notyf/Symfony/Resources/config/services.php b/src/Notyf/Symfony/Resources/config/services.php deleted file mode 100644 index 49118712..00000000 --- a/src/Notyf/Symfony/Resources/config/services.php +++ /dev/null @@ -1,22 +0,0 @@ -setClass('Flasher\Notyf\Prime\NotyfFactory') - ->addTag('flasher.factory', array('alias' => 'notyf')); - -$container->setDefinition('flasher.notyf', $definition); - - -if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Notyf\Prime\NotyfFactory', 'flasher.notyf'); -} diff --git a/src/Notyf/Symfony/UPGRADING.md b/src/Notyf/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Notyf/Symfony/composer.json b/src/Notyf/Symfony/composer.json index 60b8f247..1a39a4ea 100644 --- a/src/Notyf/Symfony/composer.json +++ b/src/Notyf/Symfony/composer.json @@ -2,37 +2,21 @@ "name": "php-flasher/flasher-notyf-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Notyf", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "notyf ", - "toastr", - "bundle", - "flex", - "notyf" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "notyf ", "toastr", "bundle", "flex", "notyf"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-notyf": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-notyf": "^1.0" }, "autoload": { "psr-4": { @@ -42,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Pnotify/Laravel/.editorconfig b/src/Pnotify/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Pnotify/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Pnotify/Laravel/.gitattributes b/src/Pnotify/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Pnotify/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Pnotify/Laravel/.github/CONTRIBUTING.md b/src/Pnotify/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Pnotify/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Pnotify/Laravel/.github/FUNDING.yml b/src/Pnotify/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Pnotify/Laravel/.github/FUNDING.yml +++ b/src/Pnotify/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Pnotify/Laravel/.github/SECURITY.md b/src/Pnotify/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Pnotify/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Pnotify/Laravel/.github/dependabot.yml b/src/Pnotify/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Pnotify/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Pnotify/Laravel/.github/workflows/auto_closer.yaml b/src/Pnotify/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Pnotify/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Pnotify/Laravel/.github/workflows/close-pull-request.yml b/src/Pnotify/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Pnotify/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Pnotify/Laravel/.gitignore b/src/Pnotify/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Pnotify/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Pnotify/Laravel/CHANGELOG.md b/src/Pnotify/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Pnotify/Laravel/CODE_OF_CONDUCT.md b/src/Pnotify/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Pnotify/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Pnotify/Laravel/Facade/Pnotify.php b/src/Pnotify/Laravel/Facade/Pnotify.php index 16afa3a6..a9b9e5b6 100644 --- a/src/Pnotify/Laravel/Facade/Pnotify.php +++ b/src/Pnotify/Laravel/Facade/Pnotify.php @@ -1,9 +1,14 @@ + */ + namespace Flasher\Pnotify\Laravel\Facade; use Flasher\Pnotify\Prime\PnotifyBuilder; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; use Illuminate\Support\Facades\Facade; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static PnotifyBuilder addError(string $message, array $options = array()) * @method static PnotifyBuilder addWarning(string $message, array $options = array()) * @method static PnotifyBuilder addInfo(string $message, array $options = array()) - * @method static PnotifyBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static PnotifyBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static PnotifyBuilder flash(StampInterface[] $stamps = array()) * @method static PnotifyBuilder type(string $type, string $message = null, array $options = array()) * @method static PnotifyBuilder message(string $message) @@ -32,7 +37,6 @@ use Illuminate\Support\Facades\Facade; * @method static PnotifyBuilder withStamp(StampInterface $stamp) * @method static PnotifyBuilder handler(string $handler) * @method static Envelope getEnvelope() - * * @method static PnotifyBuilder title(bool|string $title) * @method static PnotifyBuilder titleEscape(bool $titleEscape = true) * @method static PnotifyBuilder text(string $text) diff --git a/src/Pnotify/Laravel/FlasherPnotifyServiceProvider.php b/src/Pnotify/Laravel/FlasherPnotifyServiceProvider.php index 13566d4e..1892e398 100644 --- a/src/Pnotify/Laravel/FlasherPnotifyServiceProvider.php +++ b/src/Pnotify/Laravel/FlasherPnotifyServiceProvider.php @@ -1,55 +1,22 @@ + */ + namespace Flasher\Pnotify\Laravel; -use Flasher\Pnotify\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Pnotify\Prime\PnotifyPlugin; final class FlasherPnotifyServiceProvider extends ServiceProvider { - public function boot() - { - $manager = new ServiceProviderManager($this); - $manager->boot(); - } - /** - * Register the service provider. + * {@inheritDoc} */ - public function register() + protected function createPlugin() { - $manager = new ServiceProviderManager($this); - $manager->register(); - } - - /** - * Get the services provided by the provider. - * - * @return string[] - */ - public function provides() - { - return array( - 'flasher.pnotify', - ); - } - - /** - * @return Container - */ - public function getApplication() - { - return $this->app; - } - - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } - - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); + return new PnotifyPlugin(); } } diff --git a/src/Pnotify/Laravel/README.md b/src/Pnotify/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Pnotify/Laravel/README.md +++ b/src/Pnotify/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Pnotify/Laravel/Resources/config/config.php b/src/Pnotify/Laravel/Resources/config/config.php deleted file mode 100644 index d57f7db2..00000000 --- a/src/Pnotify/Laravel/Resources/config/config.php +++ /dev/null @@ -1,12 +0,0 @@ - array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-pnotify@0.1.1/dist/flasher-pnotify.min.js', - ), - 'styles' => array(), - 'options' => array( - 'delay' => 1000, - ), -); diff --git a/src/Pnotify/Laravel/Resources/functions/pnotify.php b/src/Pnotify/Laravel/Resources/functions/pnotify.php deleted file mode 100644 index 120ddcc7..00000000 --- a/src/Pnotify/Laravel/Resources/functions/pnotify.php +++ /dev/null @@ -1,21 +0,0 @@ -addFlash($type, $message, $options); - } -} diff --git a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php b/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index 6934c19d..00000000 --- a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,74 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherPnotifyServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_pnotify.php'), - ), 'flasher-config'); - } - - public function register(FlasherPnotifyServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_pnotify'); - $this->appendToFlasherConfig(); - - $this->registerServices(); - } - - public function registerServices() - { - $this->app->singleton('flasher.pnotify', function (Container $app) { - return new PnotifyFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.pnotify', 'Flasher\Pnotify\Prime\PnotifyFactory'); - - $this->app->extend('flasher', function (Flasher $manager, Container $app) { - $manager->addFactory('pnotify', $app['flasher.pnotify']); - - return $manager; - }); - - $this->app->extend('flasher.resource_manager', function (ResourceManager $resourceManager) { - ResourceManagerHelper::process($resourceManager, 'pnotify'); - - return $resourceManager; - }); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher.adapters.pnotify', array()); - - $pnotifyConfig = $this->app['config']->get('flasher_pnotify', array()); - - $this->app['config']->set('flasher.adapters.pnotify', array_merge($pnotifyConfig, $flasherConfig)); - } -} diff --git a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 7ae1b337..00000000 --- a/src/Pnotify/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,39 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherPnotifyServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-pnotify-laravel', - 'flasher_pnotify', - flasher_path(__DIR__ . '/../../Resources') - ); - - $this->appendToFlasherConfig(); - } - - public function register(FlasherPnotifyServiceProvider $provider) - { - $this->registerServices(); - } - - protected function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher::config.adapters.pnotify', array()); - - $pnotifyConfig = $this->app['config']->get('flasher_pnotify::config', array()); - - $this->app['config']->set('flasher::config.adapters.pnotify', array_merge($pnotifyConfig, $flasherConfig)); - } -} diff --git a/src/Pnotify/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Pnotify/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index 752db25e..00000000 --- a/src/Pnotify/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Pnotify/Laravel/UPGRADING.md b/src/Pnotify/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Pnotify/Laravel/composer.json b/src/Pnotify/Laravel/composer.json index e5905234..b01bed04 100644 --- a/src/Pnotify/Laravel/composer.json +++ b/src/Pnotify/Laravel/composer.json @@ -2,42 +2,28 @@ "name": "php-flasher/flasher-pnotify-laravel", "description": "PHP Flasher Laravel adapter for Pnotify", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-pnotify": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-pnotify": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Pnotify\\Laravel\\": "" }, "files": [ - "Resources/functions/pnotify.php" + "pnotify.php" ] }, "extra": { @@ -53,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Pnotify/Laravel/pnotify.php b/src/Pnotify/Laravel/pnotify.php new file mode 100644 index 00000000..ffa08f8e --- /dev/null +++ b/src/Pnotify/Laravel/pnotify.php @@ -0,0 +1,31 @@ + + */ + +use Flasher\Pnotify\Prime\PnotifyFactory; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\NotificationInterface; + +if (!function_exists('pnotify')) { + /** + * @param string $message + * @param string $type + * @param array $options + * + * @return Envelope|PnotifyFactory + */ + function pnotify($message = null, $type = NotificationInterface::SUCCESS, array $options = array()) + { + /** @var PnotifyFactory $factory */ + $factory = app('flasher.pnotify'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->addFlash($type, $message, $options); + } +} diff --git a/src/Pnotify/Prime/.editorconfig b/src/Pnotify/Prime/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Pnotify/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Pnotify/Prime/.gitattributes b/src/Pnotify/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Pnotify/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Pnotify/Prime/.github/CONTRIBUTING.md b/src/Pnotify/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Pnotify/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Pnotify/Prime/.github/FUNDING.yml b/src/Pnotify/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Pnotify/Prime/.github/FUNDING.yml +++ b/src/Pnotify/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Pnotify/Prime/.github/SECURITY.md b/src/Pnotify/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Pnotify/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Pnotify/Prime/.github/dependabot.yml b/src/Pnotify/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Pnotify/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Pnotify/Prime/.github/workflows/auto_closer.yaml b/src/Pnotify/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Pnotify/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Pnotify/Prime/.github/workflows/close-pull-request.yml b/src/Pnotify/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Pnotify/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Pnotify/Prime/.gitignore b/src/Pnotify/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Pnotify/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Pnotify/Prime/CHANGELOG.md b/src/Pnotify/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Pnotify/Prime/CODE_OF_CONDUCT.md b/src/Pnotify/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Pnotify/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Pnotify/Prime/Pnotify.php b/src/Pnotify/Prime/Pnotify.php deleted file mode 100644 index 0cb405b2..00000000 --- a/src/Pnotify/Prime/Pnotify.php +++ /dev/null @@ -1,9 +0,0 @@ - + */ + namespace Flasher\Pnotify\Prime; use Flasher\Prime\Notification\NotificationBuilder; @@ -16,7 +21,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool|string $title * - * @return $this + * @return static */ public function title($title) { @@ -26,11 +31,11 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Whether to escape the content of the title. (Not allow HTML.) + * Whether to escape the content of the title. (Not allow HTML.). * * @param bool $titleEscape * - * @return $this + * @return static */ public function titleEscape($titleEscape = true) { @@ -44,7 +49,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param string $text * - * @return $this + * @return static */ public function text($text) { @@ -61,11 +66,11 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Whether to escape the content of the text. (Not allow HTML.) + * Whether to escape the content of the text. (Not allow HTML.). * * @param bool $textEscape * - * @return $this + * @return static */ public function textEscape($textEscape = true) { @@ -76,11 +81,11 @@ final class PnotifyBuilder extends NotificationBuilder /** * What styling classes to use. (Can be either "brighttheme", "bootstrap3", "fontawesome", or a custom style object. - * See the source in the end of pnotify.js for the properties in a style object.) + * See the source in the end of pnotify.js for the properties in a style object.). * * @param string $styling * - * @return $this + * @return static */ public function styling($styling) { @@ -90,11 +95,11 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Additional classes to be added to the notice. (For custom styling.) + * Additional classes to be added to the notice. (For custom styling.). * * @param string $addClass * - * @return $this + * @return static */ public function addClass($addClass) { @@ -108,7 +113,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param string $cornerClass * - * @return $this + * @return static */ public function cornerClass($cornerClass) { @@ -122,7 +127,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $autoDisplay * - * @return $this + * @return static */ public function autoDisplay($autoDisplay = true) { @@ -136,7 +141,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param int $width * - * @return $this + * @return static */ public function width($width) { @@ -150,7 +155,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param int $minHeight * - * @return $this + * @return static */ public function minHeight($minHeight) { @@ -165,7 +170,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $icon * - * @return $this + * @return static */ public function icon($icon = true) { @@ -180,7 +185,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param string $animation * - * @return $this + * @return static */ public function animation($animation) { @@ -194,7 +199,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param string $animateSpeed * - * @return $this + * @return static */ public function animateSpeed($animateSpeed) { @@ -208,7 +213,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $shadow * - * @return $this + * @return static */ public function shadow($shadow = true) { @@ -222,7 +227,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $hide * - * @return $this + * @return static */ public function hide($hide = true) { @@ -236,7 +241,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param int $timer * - * @return $this + * @return static */ public function timer($timer) { @@ -250,7 +255,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $mouseReset * - * @return $this + * @return static */ public function mouseReset($mouseReset = true) { @@ -264,7 +269,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $remove * - * @return $this + * @return static */ public function remove($remove = true) { @@ -278,7 +283,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $insertBrs * - * @return $this + * @return static */ public function insertBrs($insertBrs = true) { @@ -292,7 +297,7 @@ final class PnotifyBuilder extends NotificationBuilder * * @param bool $destroy * - * @return $this + * @return static */ public function destroy($destroy = true) { @@ -302,17 +307,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Desktop Module + * Desktop Module. * * @param string $desktop - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function desktop($desktop, $value) { $option = $this->getEnvelope()->getOption('desktop', array()); - $option[$desktop] = $value; + $option[$desktop] = $value; // @phpstan-ignore-line $this->option('desktop', $option); @@ -320,17 +325,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Buttons Module + * Buttons Module. * * @param string $buttons - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function buttons($buttons, $value) { $option = $this->getEnvelope()->getOption('buttons', array()); - $option[$buttons] = $value; + $option[$buttons] = $value; // @phpstan-ignore-line $this->option('buttons', $option); @@ -338,17 +343,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * NonBlock Module + * NonBlock Module. * * @param string $nonblock - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function nonblock($nonblock, $value) { $option = $this->getEnvelope()->getOption('nonblock', array()); - $option[$nonblock] = $value; + $option[$nonblock] = $value; // @phpstan-ignore-line $this->option('nonblock', $option); @@ -356,17 +361,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Mobile Module + * Mobile Module. * * @param string $mobile - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function mobile($mobile, $value) { $option = $this->getEnvelope()->getOption('mobile', array()); - $option[$mobile] = $value; + $option[$mobile] = $value; // @phpstan-ignore-line $this->option('mobile', $option); @@ -374,17 +379,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Animate Module + * Animate Module. * * @param string $animate - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function animate($animate, $value) { $option = $this->getEnvelope()->getOption('animate', array()); - $option[$animate] = $value; + $option[$animate] = $value; // @phpstan-ignore-line $this->option('animate', $option); @@ -392,17 +397,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * Confirm Module + * Confirm Module. * * @param string $confirm - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function confirm($confirm, $value) { $option = $this->getEnvelope()->getOption('confirm', array()); - $option[$confirm] = $value; + $option[$confirm] = $value; // @phpstan-ignore-line $this->option('confirm', $option); @@ -410,17 +415,17 @@ final class PnotifyBuilder extends NotificationBuilder } /** - * History Module + * History Module. * * @param string $history - * @param mixed $value + * @param mixed $value * - * @return $this + * @return static */ public function history($history, $value) { $option = $this->getEnvelope()->getOption('history', array()); - $option[$history] = $value; + $option[$history] = $value; // @phpstan-ignore-line $this->option('history', $option); diff --git a/src/Pnotify/Prime/PnotifyFactory.php b/src/Pnotify/Prime/PnotifyFactory.php index 5a70e2e5..f1158dcd 100644 --- a/src/Pnotify/Prime/PnotifyFactory.php +++ b/src/Pnotify/Prime/PnotifyFactory.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Pnotify\Prime; use Flasher\Prime\Factory\NotificationFactory; +use Flasher\Prime\Notification\Notification; /** * @mixin PnotifyBuilder @@ -11,6 +17,6 @@ final class PnotifyFactory extends NotificationFactory { public function createNotificationBuilder() { - return new PnotifyBuilder($this->getStorageManager(), new Pnotify(), 'pnotify'); + return new PnotifyBuilder($this->getStorageManager(), new Notification(), 'pnotify'); } } diff --git a/src/Pnotify/Prime/PnotifyPlugin.php b/src/Pnotify/Prime/PnotifyPlugin.php new file mode 100644 index 00000000..17be996b --- /dev/null +++ b/src/Pnotify/Prime/PnotifyPlugin.php @@ -0,0 +1,24 @@ + + */ + +namespace Flasher\Pnotify\Prime; + +use Flasher\Prime\Plugin\Plugin; + +class PnotifyPlugin extends Plugin +{ + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array( + 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', + 'https://cdn.jsdelivr.net/npm/@flasher/flasher-pnotify@1.0.7/dist/flasher-pnotify.min.js', + ); + } +} diff --git a/src/Pnotify/Prime/README.md b/src/Pnotify/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/Pnotify/Prime/README.md +++ b/src/Pnotify/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Pnotify/Prime/UPGRADING.md b/src/Pnotify/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Pnotify/Prime/composer.json b/src/Pnotify/Prime/composer.json index d009cd54..283e09ff 100644 --- a/src/Pnotify/Prime/composer.json +++ b/src/Pnotify/Prime/composer.json @@ -2,32 +2,20 @@ "name": "php-flasher/flasher-pnotify", "description": "PHP Flasher adapter for Pnotify", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr", - "sweet alert" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr", "sweet alert"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { @@ -37,6 +25,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Pnotify/Symfony/.editorconfig b/src/Pnotify/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Pnotify/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Pnotify/Symfony/.gitattributes b/src/Pnotify/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Pnotify/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Pnotify/Symfony/.github/CONTRIBUTING.md b/src/Pnotify/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Pnotify/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Pnotify/Symfony/.github/FUNDING.yml b/src/Pnotify/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Pnotify/Symfony/.github/FUNDING.yml +++ b/src/Pnotify/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Pnotify/Symfony/.github/SECURITY.md b/src/Pnotify/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Pnotify/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Pnotify/Symfony/.github/dependabot.yml b/src/Pnotify/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Pnotify/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Pnotify/Symfony/.github/workflows/auto_closer.yaml b/src/Pnotify/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Pnotify/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Pnotify/Symfony/.github/workflows/close-pull-request.yml b/src/Pnotify/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Pnotify/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Pnotify/Symfony/.gitignore b/src/Pnotify/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Pnotify/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Pnotify/Symfony/.phpstorm.meta.php b/src/Pnotify/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Pnotify/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ -getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher_pnotify'); - } - - $rootNode - ->children() - ->arrayNode('scripts') - ->prototype('scalar')->end() - ->defaultValue(array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-pnotify@0.1.1/dist/flasher-pnotify.min.js', - )) - ->end() - ->arrayNode('styles') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('options') - ->prototype('variable')->end() - ->ignoreExtraKeys(false) - ->defaultValue(array( - 'delay' => 1000, - )) - ->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php b/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php deleted file mode 100644 index aa062be3..00000000 --- a/src/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtension.php +++ /dev/null @@ -1,23 +0,0 @@ -load('services.php'); - } - - public function getConfigurationClass() - { - return new Configuration(); - } -} diff --git a/src/Pnotify/Symfony/FlasherPnotifySymfonyBundle.php b/src/Pnotify/Symfony/FlasherPnotifySymfonyBundle.php index ac168930..04c7d49f 100644 --- a/src/Pnotify/Symfony/FlasherPnotifySymfonyBundle.php +++ b/src/Pnotify/Symfony/FlasherPnotifySymfonyBundle.php @@ -1,21 +1,22 @@ + */ + namespace Flasher\Pnotify\Symfony; -use Flasher\Pnotify\Symfony\DependencyInjection\FlasherPnotifyExtension; -use Flasher\Symfony\Bridge\FlasherBundle; -use Flasher\Symfony\DependencyInjection\Compiler\ResourceCompilerPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Flasher\Pnotify\Prime\PnotifyPlugin; +use Flasher\Symfony\Support\Bundle; -class FlasherPnotifySymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle +class FlasherPnotifySymfonyBundle extends Bundle // Symfony\Component\HttpKernel\Bundle\Bundle { - protected function flasherBuild(ContainerBuilder $container) + /** + * {@inheritDoc} + */ + protected function createPlugin() { - $container->addCompilerPass(new ResourceCompilerPass($this->getFlasherContainerExtension())); - } - - protected function getFlasherContainerExtension() - { - return new FlasherPnotifyExtension(); + return new PnotifyPlugin(); } } diff --git a/src/Pnotify/Symfony/README.md b/src/Pnotify/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Pnotify/Symfony/README.md +++ b/src/Pnotify/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Pnotify/Symfony/Resources/config/services.php b/src/Pnotify/Symfony/Resources/config/services.php deleted file mode 100644 index c4a15fa3..00000000 --- a/src/Pnotify/Symfony/Resources/config/services.php +++ /dev/null @@ -1,21 +0,0 @@ -setClass('Flasher\Pnotify\Prime\PnotifyFactory') - ->addTag('flasher.factory', array('alias' => 'pnotify')); - -$container->setDefinition('flasher.pnotify', $definition); - -if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Pnotify\Prime\PnotifyFactory', 'flasher.pnotify'); -} diff --git a/src/Pnotify/Symfony/UPGRADING.md b/src/Pnotify/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Pnotify/Symfony/composer.json b/src/Pnotify/Symfony/composer.json index b1fbc2ad..4984e125 100644 --- a/src/Pnotify/Symfony/composer.json +++ b/src/Pnotify/Symfony/composer.json @@ -2,35 +2,21 @@ "name": "php-flasher/flasher-pnotify-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Pnotify", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "pnotify ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "pnotify ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-pnotify": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-pnotify": "^1.0" }, "autoload": { "psr-4": { @@ -40,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Prime/.editorconfig b/src/Prime/.editorconfig deleted file mode 100755 index cd8eb86e..00000000 --- a/src/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Prime/.gitattributes b/src/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Prime/.github/CONTRIBUTING.md b/src/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Prime/.github/FUNDING.yml b/src/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Prime/.github/FUNDING.yml +++ b/src/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Prime/.github/SECURITY.md b/src/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Prime/.github/dependabot.yml b/src/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Prime/.github/workflows/auto_closer.yaml b/src/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Prime/.github/workflows/close-pull-request.yml b/src/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Prime/.gitignore b/src/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Prime/.phpstorm.meta.php b/src/Prime/.phpstorm.meta.php index c0e31144..a6fe3d54 100644 --- a/src/Prime/.phpstorm.meta.php +++ b/src/Prime/.phpstorm.meta.php @@ -2,7 +2,9 @@ namespace PHPSTORM_META; -registerArgumentsSet('notificationTypes', NotificationInterface::TYPE_SUCCESS, NotificationInterface::TYPE_ERROR, NotificationInterface::TYPE_WARNING, NotificationInterface::TYPE_INFO); +use Flasher\Prime\Notification\NotificationInterface; + +registerArgumentsSet('notificationTypes', NotificationInterface::SUCCESS, NotificationInterface::ERROR, NotificationInterface::WARNING, NotificationInterface::INFO); override(Envelope::get(0), type(0)); @@ -14,16 +16,12 @@ expectedReturnValues(\Flasher\Prime\Notification\NotificationInterface::getType( override(\Flasher\Prime\FlasherInterface::create(), map([ '' => '@', - 'template' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.tailwindcss' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.tailwindcss_bg' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.bootstrap' => \Flasher\Prime\Factory\TemplateFactory::class, + 'flasher' => \Flasher\Prime\Factory\FlasherFactory::class, + 'theme.*' => \Flasher\Prime\Factory\FlasherFactory::class, ])); override(\Flasher\Prime\FlasherInterface::using(), map([ '' => '@', - 'template' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.tailwindcss' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.tailwindcss_bg' => \Flasher\Prime\Factory\TemplateFactory::class, - 'template.bootstrap' => \Flasher\Prime\Factory\TemplateFactory::class, + 'flasher' => \Flasher\Prime\Factory\FlasherFactory::class, + 'theme.*' => \Flasher\Prime\Factory\FlasherFactory::class, ])); diff --git a/src/Prime/CHANGELOG.md b/src/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Prime/CODE_OF_CONDUCT.md b/src/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Prime/Config/Config.php b/src/Prime/Config/Config.php index 7be853b8..3b05c2bf 100644 --- a/src/Prime/Config/Config.php +++ b/src/Prime/Config/Config.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Config; final class Config implements ConfigInterface @@ -12,21 +17,24 @@ final class Config implements ConfigInterface /** * @param array $config */ - public function __construct(array $config) + public function __construct(array $config = array()) { $this->config = $config; } + /** + * {@inheritdoc} + */ public function get($key, $default = null) { $data = $this->config; foreach (explode('.', $key) as $segment) { - if (!isset($data[$segment])) { + if (!isset($data[$segment])) { // @phpstan-ignore-line return $default; } - $data = $data[$segment]; + $data = $data[$segment]; // @phpstan-ignore-line } return $data; diff --git a/src/Prime/Config/ConfigInterface.php b/src/Prime/Config/ConfigInterface.php index a43f10f3..760aa0a7 100644 --- a/src/Prime/Config/ConfigInterface.php +++ b/src/Prime/Config/ConfigInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Config; interface ConfigInterface @@ -8,7 +13,7 @@ interface ConfigInterface * Returns an attribute. * * @param string $key - * @param mixed $default The default value if not found. + * @param mixed $default the default value if not found * * @return mixed */ diff --git a/src/Prime/EventDispatcher/Event/FilterEvent.php b/src/Prime/EventDispatcher/Event/FilterEvent.php index cd46a119..2d4bfc6b 100644 --- a/src/Prime/EventDispatcher/Event/FilterEvent.php +++ b/src/Prime/EventDispatcher/Event/FilterEvent.php @@ -1,29 +1,29 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Filter\Filter; +use Flasher\Prime\Notification\Envelope; final class FilterEvent { /** - * @var Envelope[] + * @var Filter */ - private $envelopes; + private $filter; /** - * @var array - */ - private $criteria; - - /** - * @param Envelope[] $envelopes + * @param Envelope[] $envelopes * @param array $criteria */ public function __construct(array $envelopes, array $criteria) { - $this->envelopes = $envelopes; - $this->criteria = $criteria; + $this->filter = new Filter($envelopes, $criteria); } /** @@ -31,34 +31,22 @@ final class FilterEvent */ public function getEnvelopes() { - return $this->envelopes; + return $this->filter->getResult(); + } + + /** + * @return Filter + */ + public function getFilter() + { + return $this->filter; } /** - * @param Envelope[] $envelopes - * * @return void */ - public function setEnvelopes(array $envelopes) + public function setFilter(Filter $filter) { - $this->envelopes = $envelopes; - } - - /** - * @return array - */ - public function getCriteria() - { - return $this->criteria; - } - - /** - * @param array $criteria - * - * @return void - */ - public function setCriteria(array $criteria) - { - $this->criteria = $criteria; + $this->filter = $filter; } } diff --git a/src/Prime/EventDispatcher/Event/PersistEvent.php b/src/Prime/EventDispatcher/Event/PersistEvent.php index 343e0a80..4322d9c2 100644 --- a/src/Prime/EventDispatcher/Event/PersistEvent.php +++ b/src/Prime/EventDispatcher/Event/PersistEvent.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class PersistEvent { diff --git a/src/Prime/EventDispatcher/Event/PostPersistEvent.php b/src/Prime/EventDispatcher/Event/PostPersistEvent.php index 8d5710bf..c9286b61 100644 --- a/src/Prime/EventDispatcher/Event/PostPersistEvent.php +++ b/src/Prime/EventDispatcher/Event/PostPersistEvent.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class PostPersistEvent { diff --git a/src/Prime/EventDispatcher/Event/PostRemoveEvent.php b/src/Prime/EventDispatcher/Event/PostRemoveEvent.php index 6ef56488..3f1f1b08 100644 --- a/src/Prime/EventDispatcher/Event/PostRemoveEvent.php +++ b/src/Prime/EventDispatcher/Event/PostRemoveEvent.php @@ -1,26 +1,31 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class PostRemoveEvent { /** * @var Envelope[] */ - private $envelopesToRemove = array(); + private $envelopesToRemove; /** * @var Envelope[] */ - private $envelopesToKeep = array(); + private $envelopesToKeep; /** * @param Envelope[] $envelopesToRemove * @param Envelope[] $envelopesToKeep */ - public function __construct(array $envelopesToRemove, array $envelopesToKeep) + public function __construct(array $envelopesToRemove = array(), array $envelopesToKeep = array()) { $this->envelopesToRemove = $envelopesToRemove; $this->envelopesToKeep = $envelopesToKeep; diff --git a/src/Prime/EventDispatcher/Event/PostUpdateEvent.php b/src/Prime/EventDispatcher/Event/PostUpdateEvent.php index 24c574cb..7186d579 100644 --- a/src/Prime/EventDispatcher/Event/PostUpdateEvent.php +++ b/src/Prime/EventDispatcher/Event/PostUpdateEvent.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class PostUpdateEvent { diff --git a/src/Prime/EventDispatcher/Event/RemoveEvent.php b/src/Prime/EventDispatcher/Event/RemoveEvent.php index 6ea28785..1235c87e 100644 --- a/src/Prime/EventDispatcher/Event/RemoveEvent.php +++ b/src/Prime/EventDispatcher/Event/RemoveEvent.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class RemoveEvent { diff --git a/src/Prime/EventDispatcher/Event/ResponseEvent.php b/src/Prime/EventDispatcher/Event/ResponseEvent.php index 03876c0e..802d4a4f 100644 --- a/src/Prime/EventDispatcher/Event/ResponseEvent.php +++ b/src/Prime/EventDispatcher/Event/ResponseEvent.php @@ -1,39 +1,57 @@ + */ -use Flasher\Prime\Envelope; +namespace Flasher\Prime\EventDispatcher\Event; final class ResponseEvent { /** - * @var Envelope[] + * @var mixed */ - private $envelopes; + private $response; /** - * @param Envelope[] $envelopes + * @var string */ - public function __construct(array $envelopes) + private $presenter; + + /** + * @param mixed $response + * @param string $presenter + */ + public function __construct($response, $presenter) { - $this->envelopes = $envelopes; + $this->response = $response; + $this->presenter = $presenter; } /** - * @return Envelope[] + * @return mixed */ - public function getEnvelopes() + public function getResponse() { - return $this->envelopes; + return $this->response; } /** - * @param Envelope[] $envelopes + * @param mixed $response * * @return void */ - public function setEnvelopes(array $envelopes) + public function setResponse($response) { - $this->envelopes = $envelopes; + $this->response = $response; + } + + /** + * @return string + */ + public function getPresenter() + { + return $this->presenter; } } diff --git a/src/Prime/EventDispatcher/Event/StoppableEventInterface.php b/src/Prime/EventDispatcher/Event/StoppableEventInterface.php index 7c3ef5f2..529b11e8 100644 --- a/src/Prime/EventDispatcher/Event/StoppableEventInterface.php +++ b/src/Prime/EventDispatcher/Event/StoppableEventInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; interface StoppableEventInterface diff --git a/src/Prime/EventDispatcher/Event/UpdateEvent.php b/src/Prime/EventDispatcher/Event/UpdateEvent.php index da491302..b9fa0a3b 100644 --- a/src/Prime/EventDispatcher/Event/UpdateEvent.php +++ b/src/Prime/EventDispatcher/Event/UpdateEvent.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\EventDispatcher\Event; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class UpdateEvent { diff --git a/src/Prime/EventDispatcher/EventDispatcher.php b/src/Prime/EventDispatcher/EventDispatcher.php index 86bc4d5b..33ba4a4a 100644 --- a/src/Prime/EventDispatcher/EventDispatcher.php +++ b/src/Prime/EventDispatcher/EventDispatcher.php @@ -1,103 +1,77 @@ + */ + namespace Flasher\Prime\EventDispatcher; use Flasher\Prime\EventDispatcher\Event\StoppableEventInterface; use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; +use Flasher\Prime\EventDispatcher\EventListener\RemoveListener; +use Flasher\Prime\EventDispatcher\EventListener\StampsListener; final class EventDispatcher implements EventDispatcherInterface { /** - * @var array + * @var array */ private $listeners = array(); - /** - * @var array - */ - private $sorted = array(); + public function __construct() + { + $this->addSubscriber(new RemoveListener()); + $this->addSubscriber(new StampsListener()); + } + /** + * {@inheritdoc} + */ public function dispatch($event) { - $listeners = $this->getListeners(get_class($event)); + $listeners = $this->getListeners(\get_class($event)); - $this->callListeners($listeners, $event); + $this->callListeners($listeners, $event); // @phpstan-ignore-line return $event; } + /** + * {@inheritdoc} + */ + public function addListener($eventName, $listener) + { + $this->listeners[$eventName][] = $listener; // @phpstan-ignore-line + } + + /** + * {@inheritdoc} + */ + public function addSubscriber(EventSubscriberInterface $subscriber) + { + foreach ((array) $subscriber->getSubscribedEvents() as $eventName) { + $this->addListener($eventName, array($subscriber, '__invoke')); // @phpstan-ignore-line + } + } + /** * @param string $eventName * - * @return EventSubscriberInterface[] + * @return array */ public function getListeners($eventName) { - if (empty($this->listeners[$eventName])) { - return array(); + if (\array_key_exists($eventName, $this->listeners)) { + return $this->listeners[$eventName]; // @phpstan-ignore-line } - if (!isset($this->sorted[$eventName])) { - $this->sortListeners($eventName); - } - - return $this->sorted[$eventName]; + return array(); } /** - * @param string $eventName - * @param EventSubscriberInterface|callable|mixed[] $listener - * @param int $priority - */ - public function addListener($eventName, $listener, $priority = 0) - { - $this->listeners[$eventName][$priority][] = $listener; - } - - public function addSubscriber(EventSubscriberInterface $subscriber) - { - foreach ((array) $subscriber->getSubscribedEvents() as $eventName => $params) { - if (is_int($eventName)) { - $eventName = $params; - $params = '__invoke'; - } - - if (is_string($params)) { - $this->addListener($eventName, array($subscriber, $params)); - } elseif (is_string($params[0])) { - $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0); - } else { - foreach ($params as $listener) { - $this->addListener( - $eventName, - array($subscriber, $listener[0]), - isset($listener[1]) ? $listener[1] : 0 - ); - } - } - } - } - - /** - * @param string $eventName - * - * @return void - */ - private function sortListeners($eventName) - { - krsort($this->listeners[$eventName]); - $this->sorted[$eventName] = array(); - - foreach ($this->listeners[$eventName] as $listeners) { - foreach ($listeners as $k => $listener) { - $this->sorted[$eventName][] = $listener; - } - } - } - - /** - * @param mixed[]|callable[] $listeners - * @param object $event + * @param callable[] $listeners + * @param object $event * * @return void */ @@ -107,7 +81,7 @@ final class EventDispatcher implements EventDispatcherInterface if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) { break; } - call_user_func($listener, $event, $this); + \call_user_func($listener, $event); } } } diff --git a/src/Prime/EventDispatcher/EventDispatcherInterface.php b/src/Prime/EventDispatcher/EventDispatcherInterface.php index cfef7ca4..3d9815d2 100644 --- a/src/Prime/EventDispatcher/EventDispatcherInterface.php +++ b/src/Prime/EventDispatcher/EventDispatcherInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\EventDispatcher; use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; @@ -16,11 +21,10 @@ interface EventDispatcherInterface /** * @param string $eventName * @param callable $listener - * @param int $priority * * @return void */ - public function addListener($eventName, $listener, $priority = 0); + public function addListener($eventName, $listener); /** * @return void diff --git a/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php b/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php index e9aace09..35e34c8d 100644 --- a/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php +++ b/src/Prime/EventDispatcher/EventListener/EventSubscriberInterface.php @@ -1,11 +1,16 @@ + */ + namespace Flasher\Prime\EventDispatcher\EventListener; interface EventSubscriberInterface { /** - * @return string|string[]|array|mixed[] + * @return string|string[] */ public static function getSubscribedEvents(); } diff --git a/src/Prime/EventDispatcher/EventListener/FilterListener.php b/src/Prime/EventDispatcher/EventListener/FilterListener.php deleted file mode 100644 index cb29bd01..00000000 --- a/src/Prime/EventDispatcher/EventListener/FilterListener.php +++ /dev/null @@ -1,41 +0,0 @@ -filter = $filter; - } - - /** - * @return void - */ - public function __invoke(FilterEvent $event) - { - $criteria = $event->getCriteria(); - $criteria['delay'] = 0; - $criteria['hops']['min'] = 1; - - $envelopes = $this->filter->filter($event->getEnvelopes(), $criteria); - - $event->setEnvelopes($envelopes); - } - - /** - * @return string - */ - public static function getSubscribedEvents() - { - return 'Flasher\Prime\EventDispatcher\Event\FilterEvent'; - } -} diff --git a/src/Prime/EventDispatcher/EventListener/RemoveListener.php b/src/Prime/EventDispatcher/EventListener/RemoveListener.php index 822825ea..e73a0291 100644 --- a/src/Prime/EventDispatcher/EventListener/RemoveListener.php +++ b/src/Prime/EventDispatcher/EventListener/RemoveListener.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\EventDispatcher\EventListener; use Flasher\Prime\EventDispatcher\Event\RemoveEvent; @@ -23,6 +28,7 @@ final class RemoveListener implements EventSubscriberInterface if (1 === $hopsStamp->getAmount()) { $envelopesToRemove[] = $envelope; + continue; } @@ -35,7 +41,7 @@ final class RemoveListener implements EventSubscriberInterface } /** - * @return string + * {@inheritdoc} */ public static function getSubscribedEvents() { diff --git a/src/Prime/EventDispatcher/EventListener/ResponseListener.php b/src/Prime/EventDispatcher/EventListener/ResponseListener.php deleted file mode 100644 index 9b6bf258..00000000 --- a/src/Prime/EventDispatcher/EventListener/ResponseListener.php +++ /dev/null @@ -1,41 +0,0 @@ -filter = $filter; - } - - /** - * @return void - */ - public function __invoke(FilterEvent $event) - { - $criteria = $event->getCriteria(); - $criteria['delay'] = 0; - $criteria['hops']['min'] = 1; - - $envelopes = $this->filter->filter($event->getEnvelopes(), $criteria); - - $event->setEnvelopes($envelopes); - } - - /** - * @return string - */ - public static function getSubscribedEvents() - { - return 'Flasher\Prime\EventDispatcher\Event\FilterEvent'; - } -} diff --git a/src/Prime/EventDispatcher/EventListener/StampsListener.php b/src/Prime/EventDispatcher/EventListener/StampsListener.php index 71849485..288166c6 100644 --- a/src/Prime/EventDispatcher/EventListener/StampsListener.php +++ b/src/Prime/EventDispatcher/EventListener/StampsListener.php @@ -1,10 +1,15 @@ + */ + namespace Flasher\Prime\EventDispatcher\EventListener; -use Flasher\Prime\Envelope; use Flasher\Prime\EventDispatcher\Event\PersistEvent; use Flasher\Prime\EventDispatcher\Event\UpdateEvent; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\CreatedAtStamp; use Flasher\Prime\Stamp\DelayStamp; use Flasher\Prime\Stamp\HopsStamp; @@ -26,7 +31,7 @@ final class StampsListener implements EventSubscriberInterface } /** - * @return string[] + * {@inheritdoc} */ public static function getSubscribedEvents() { @@ -46,7 +51,7 @@ final class StampsListener implements EventSubscriberInterface } if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) { - $envelope->withStamp(new UuidStamp()); + $envelope->withStamp(new UuidStamp(spl_object_hash($envelope))); } if (null === $envelope->get('Flasher\Prime\Stamp\DelayStamp')) { diff --git a/src/Prime/Factory/NotificationFactory.php b/src/Prime/Factory/NotificationFactory.php index febd3edb..370ba176 100644 --- a/src/Prime/Factory/NotificationFactory.php +++ b/src/Prime/Factory/NotificationFactory.php @@ -1,9 +1,15 @@ + */ + namespace Flasher\Prime\Factory; -use Flasher\Prime\Notification\Template; -use Flasher\Prime\Notification\TemplateBuilder; +use Flasher\Prime\Notification\Notification; +use Flasher\Prime\Notification\NotificationBuilder; +use Flasher\Prime\Storage\StorageManager; use Flasher\Prime\Storage\StorageManagerInterface; class NotificationFactory implements NotificationFactoryInterface @@ -13,15 +19,22 @@ class NotificationFactory implements NotificationFactoryInterface */ protected $storageManager; - public function __construct(StorageManagerInterface $storageManager) + /** + * @var string|null + */ + protected $handler; + + /** + * @param string|null $handler + */ + public function __construct(StorageManagerInterface $storageManager = null, $handler = null) { - $this->storageManager = $storageManager; + $this->storageManager = $storageManager ?: new StorageManager(); + $this->handler = $handler; } /** - * Dynamically call the default driver instance. - * - * @param string $method + * @param string $method * @param mixed[] $parameters * * @return mixed @@ -31,14 +44,15 @@ class NotificationFactory implements NotificationFactoryInterface /** @var callable $callback */ $callback = array($this->createNotificationBuilder(), $method); - return call_user_func_array($callback, $parameters); + return \call_user_func_array($callback, $parameters); } + /** + * {@inheritdoc} + */ public function createNotificationBuilder() { - @trigger_error('deprecated use TemplateFactory instead, it will be removed in v1.0.0', \E_USER_DEPRECATED); - - return new TemplateBuilder($this->getStorageManager(), new Template(), 'template'); + return new NotificationBuilder($this->getStorageManager(), new Notification(), $this->handler); } /** diff --git a/src/Prime/Factory/NotificationFactoryInterface.php b/src/Prime/Factory/NotificationFactoryInterface.php index 2100bca0..546b8003 100644 --- a/src/Prime/Factory/NotificationFactoryInterface.php +++ b/src/Prime/Factory/NotificationFactoryInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Factory; use Flasher\Prime\Notification\NotificationBuilderInterface; diff --git a/src/Prime/Factory/TemplateFactory.php b/src/Prime/Factory/TemplateFactory.php deleted file mode 100644 index 2e0acdfc..00000000 --- a/src/Prime/Factory/TemplateFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -getStorageManager(), - new Template(), - $this->getHandler() - ); - } - - /** - * @return string - */ - public function getHandler() - { - return $this->handler; - } - - /** - * @param string $handler - * - * @return void - */ - public function setHandler($handler) - { - $this->handler = $handler; - } -} diff --git a/src/Prime/Filter/CriteriaBuilder.php b/src/Prime/Filter/CriteriaBuilder.php index e6321d69..e2bbf5e0 100644 --- a/src/Prime/Filter/CriteriaBuilder.php +++ b/src/Prime/Filter/CriteriaBuilder.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Filter; use Flasher\Prime\Filter\Specification\CallbackSpecification; @@ -7,13 +12,24 @@ use Flasher\Prime\Filter\Specification\DelaySpecification; use Flasher\Prime\Filter\Specification\HopsSpecification; use Flasher\Prime\Filter\Specification\PrioritySpecification; use Flasher\Prime\Filter\Specification\StampsSpecification; +use Flasher\Prime\Stamp\StampInterface; final class CriteriaBuilder { /** - * @var FilterBuilder + * @var array> */ - private $filterBuilder; + public $aliases = array( + 'priority' => 'Flasher\Prime\Stamp\PriorityStamp', + 'created_at' => 'Flasher\Prime\Stamp\CreatedAtStamp', + 'delay' => 'Flasher\Prime\Stamp\DelayStamp', + 'hops' => 'Flasher\Prime\Stamp\HopsStamp', + ); + + /** + * @var Filter + */ + private $filter; /** * @var array @@ -23,14 +39,14 @@ final class CriteriaBuilder /** * @param array $criteria */ - public function __construct(FilterBuilder $filterBuilder, array $criteria) + public function __construct(Filter $filter, array $criteria) { - $this->filterBuilder = $filterBuilder; + $this->filter = $filter; $this->criteria = $criteria; } /** - * @return FilterBuilder + * @return void */ public function build() { @@ -38,12 +54,10 @@ final class CriteriaBuilder $this->buildHops(); $this->buildDelay(); $this->buildLife(); - $this->buildLimit(); $this->buildOrder(); + $this->buildLimit(); $this->buildStamps(); - $this->buildFilter(); - - return $this->filterBuilder; + $this->buildCallback(); } /** @@ -55,18 +69,9 @@ final class CriteriaBuilder return; } - $priority = $this->criteria['priority']; + $criteria = $this->extractMinMax($this->criteria['priority']); - if (!is_array($priority)) { - $priority = array( - 'min' => $priority, - ); - } - - $min = isset($priority['min']) ? $priority['min'] : null; - $max = isset($priority['max']) ? $priority['max'] : null; - - $this->filterBuilder->andWhere(new PrioritySpecification($min, $max)); + $this->filter->addSpecification(new PrioritySpecification($criteria['min'], $criteria['max'])); } /** @@ -78,18 +83,9 @@ final class CriteriaBuilder return; } - $hops = $this->criteria['hops']; + $criteria = $this->extractMinMax($this->criteria['hops']); - if (!is_array($hops)) { - $hops = array( - 'min' => $hops, - ); - } - - $min = isset($hops['min']) ? $hops['min'] : null; - $max = isset($hops['max']) ? $hops['max'] : null; - - $this->filterBuilder->andWhere(new HopsSpecification($min, $max)); + $this->filter->addSpecification(new HopsSpecification($criteria['min'], $criteria['max'])); } /** @@ -101,18 +97,9 @@ final class CriteriaBuilder return; } - $delay = $this->criteria['delay']; + $criteria = $this->extractMinMax($this->criteria['delay']); - if (!is_array($delay)) { - $delay = array( - 'min' => $delay, - ); - } - - $min = isset($delay['min']) ? $delay['min'] : null; - $max = isset($delay['max']) ? $delay['max'] : null; - - $this->filterBuilder->andWhere(new DelaySpecification($min, $max)); + $this->filter->addSpecification(new DelaySpecification($criteria['min'], $criteria['max'])); } /** @@ -124,30 +111,9 @@ final class CriteriaBuilder return; } - $life = $this->criteria['life']; + $criteria = $this->extractMinMax($this->criteria['life']); - if (!is_array($life)) { - $life = array( - 'min' => $life, - ); - } - - $min = isset($life['min']) ? $life['min'] : null; - $max = isset($life['max']) ? $life['max'] : null; - - $this->filterBuilder->andWhere(new HopsSpecification($min, $max)); - } - - /** - * @return void - */ - public function buildLimit() - { - if (!isset($this->criteria['limit'])) { - return; - } - - $this->filterBuilder->setMaxResults($this->criteria['limit']); + $this->filter->addSpecification(new HopsSpecification($criteria['min'], $criteria['max'])); } /** @@ -159,15 +125,42 @@ final class CriteriaBuilder return; } - $orderings = $this->criteria['order_by']; + $orderings = array(); - if (!is_array($orderings)) { - $orderings = array( - $orderings => FilterBuilder::ASC, - ); + /** + * @var int|string $field + * @var string $direction + */ + foreach ((array) $this->criteria['order_by'] as $field => $direction) { + if (\is_int($field)) { + $field = $direction; + $direction = Filter::ASC; + } + + $direction = Filter::ASC === strtoupper($direction) ? Filter::ASC : Filter::DESC; + + if (\array_key_exists($field, $this->aliases)) { + $field = $this->aliases[$field]; + } + + $orderings[$field] = $direction; } - $this->filterBuilder->orderBy($orderings); + $this->filter->orderBy($orderings); + } + + /** + * @return void + */ + public function buildLimit() + { + if (!isset($this->criteria['limit'])) { + return; + } + + /** @var int $limit */ + $limit = $this->criteria['limit']; + $this->filter->setMaxResults((int) $limit); } /** @@ -179,24 +172,56 @@ final class CriteriaBuilder return; } + /** @var string $strategy */ $strategy = isset($this->criteria['stamps_strategy']) ? $this->criteria['stamps_strategy'] : StampsSpecification::STRATEGY_OR; - $this->filterBuilder->andWhere(new StampsSpecification($this->criteria['stamps'], $strategy)); + /** @var array> $stamps */ + $stamps = (array) $this->criteria['stamps']; + + /** + * @var string $key + * @var class-string $value + */ + foreach ($stamps as $key => $value) { + if (\array_key_exists($value, $this->aliases)) { + $stamps[$key] = $this->aliases[$value]; + } + } + + $this->filter->addSpecification(new StampsSpecification($stamps, $strategy)); } /** * @return void */ - public function buildFilter() + public function buildCallback() { if (!isset($this->criteria['filter'])) { return; } + /** @var callable $callback */ foreach ((array) $this->criteria['filter'] as $callback) { - $this->filterBuilder->andWhere(new CallbackSpecification($this->filterBuilder, $callback)); + $this->filter->addSpecification(new CallbackSpecification($this->filter, $callback)); } } + + /** + * @param mixed $criteria + * + * @return array{min: int, max: int} + */ + private function extractMinMax($criteria) + { + if (!\is_array($criteria)) { + $criteria = array('min' => $criteria); + } + + $min = isset($criteria['min']) ? $criteria['min'] : null; + $max = isset($criteria['max']) ? $criteria['max'] : null; + + return array('min' => $min, 'max' => $max); + } } diff --git a/src/Prime/Filter/Filter.php b/src/Prime/Filter/Filter.php index c67845d7..7fe01bfd 100644 --- a/src/Prime/Filter/Filter.php +++ b/src/Prime/Filter/Filter.php @@ -1,14 +1,177 @@ + */ + namespace Flasher\Prime\Filter; -final class Filter implements FilterInterface -{ - public function filter(array $envelopes, array $criteria) - { - $filterBuilder = new FilterBuilder(); - $filterBuilder->withCriteria($criteria); +use Flasher\Prime\Filter\Specification\AndSpecification; +use Flasher\Prime\Filter\Specification\SpecificationInterface; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Stamp\OrderableStampInterface; +use Flasher\Prime\Stamp\StampInterface; - return $filterBuilder->filter($envelopes); +final class Filter +{ + const ASC = 'ASC'; + const DESC = 'DESC'; + + /** + * @var Envelope[] + */ + private $envelopes; + + /** + * @var array + */ + private $criteria; + + /** + * @var SpecificationInterface + */ + private $specification; + + /** + * @var array + */ + private $orderings = array(); + + /** + * @var int|null + */ + private $maxResults; + + /** + * @param Envelope[] $envelopes + * @param array $criteria + */ + public function __construct(array $envelopes, array $criteria) + { + $this->envelopes = $envelopes; + $this->criteria = $criteria; + } + + /** + * @return Envelope[] + */ + public function getResult() + { + $criteriaBuilder = new CriteriaBuilder($this, $this->criteria); + $criteriaBuilder->build(); + + $this->applySpecification(); + $this->applyOrdering(); + $this->applyLimit(); + + return $this->envelopes; + } + + /** + * @return Envelope[] + */ + public function getEnvelopes() + { + return $this->envelopes; + } + + /** + * @return array + */ + public function getCriteria() + { + return $this->criteria; + } + + /** + * @return void + */ + public function addSpecification(SpecificationInterface $specification) + { + $this->specification = null !== $this->specification + ? new AndSpecification($this->specification, $specification) + : $specification; + } + + /** + * @param array $orderings + * + * @return void + */ + public function orderBy(array $orderings) + { + $this->orderings = $orderings; + } + + /** + * @param int $maxResults + * + * @return void + */ + public function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * @return void + */ + private function applySpecification() + { + if (null === $this->specification) { + return; + } + + $specification = $this->specification; + $this->envelopes = array_filter($this->envelopes, function (Envelope $envelope) use ($specification) { + return $specification->isSatisfiedBy($envelope); + }); + } + + /** + * @return void + */ + private function applyOrdering() + { + if (null === $this->orderings) { + return; + } + + $orderings = $this->orderings; + usort($this->envelopes, function (Envelope $first, Envelope $second) use ($orderings) { + /** + * @var class-string $field + * @var string $ordering + */ + foreach ($orderings as $field => $ordering) { + $stampA = $first->get($field); + $stampB = $second->get($field); + + if (!$stampA instanceof OrderableStampInterface || !$stampB instanceof OrderableStampInterface) { + return 0; + } + + if (Filter::ASC === $ordering) { + return $stampA->compare($stampB); + } + + return $stampB->compare($stampA); + } + + return 0; + }); + } + + /** + * @return void + */ + private function applyLimit() + { + if (null === $this->maxResults) { + return; + } + + $this->envelopes = \array_slice($this->envelopes, 0, $this->maxResults, true); } } diff --git a/src/Prime/Filter/FilterBuilder.php b/src/Prime/Filter/FilterBuilder.php deleted file mode 100644 index 1c820079..00000000 --- a/src/Prime/Filter/FilterBuilder.php +++ /dev/null @@ -1,199 +0,0 @@ - - */ - private $orderings = array(); - - /** - * @var int|null - */ - private $maxResults; - - /** @var array */ - private static $stampsMap = array( - 'priority' => 'Flasher\Prime\Stamp\PriorityStamp', - 'created_at' => 'Flasher\Prime\Stamp\CreatedAtStamp', - 'delay' => 'Flasher\Prime\Stamp\DelayStamp', - 'hops' => 'Flasher\Prime\Stamp\HopsStamp', - ); - - /** - * @param Envelope[] $envelopes - * - * @return Envelope[] - */ - public function filter(array $envelopes) - { - $specification = $this->getSpecification(); - - if (null !== $specification) { - $envelopes = array_filter($envelopes, function (Envelope $envelope) use ($specification) { - return $specification->isSatisfiedBy($envelope); - }); - } - - $orderings = $this->getOrderings(); - - if (null !== $orderings) { - usort($envelopes, function (Envelope $a, Envelope $b) use ($orderings) { - /** - * @var class-string $field - * @var string $ordering - */ - foreach ($orderings as $field => $ordering) { - if (FilterBuilder::ASC !== $ordering) { - list($a, $b) = array($b, $a); - } - - // if (isset(FilterBuilder::$stampsMap[$field])) { - // return FilterBuilder::$stampsMap[$field]; - // } - - $stampA = $a->get($field); - $stampB = $b->get($field); - - if (!$stampA instanceof OrderableStampInterface) { - return -1; - } - - if (!$stampB instanceof OrderableStampInterface) { - return 1; - } - - return $stampA->compare($stampB); - } - - return 0; - }); - } - - $length = $this->getMaxResults(); - - if (null !== $length) { - $envelopes = array_slice($envelopes, 0, $length, true); - } - - return $envelopes; - } - - /** - * @param array $criteria - * - * @return self - */ - public function withCriteria(array $criteria) - { - $criteriaBuilder = new CriteriaBuilder($this, $criteria); - $criteriaBuilder->build(); - - return $this; - } - - /** - * @param array $orderings - * - * @return self - */ - public function orderBy(array $orderings) - { - $this->orderings = array_map(function ($ordering) { - return strtoupper($ordering) === FilterBuilder::ASC ? FilterBuilder::ASC : FilterBuilder::DESC; - }, $orderings); - - return $this; - } - - /** - * @return array - */ - public function getOrderings() - { - return $this->orderings; - } - - /** - * @return SpecificationInterface - */ - public function getSpecification() - { - return $this->specification; - } - - /** - * @return int|null - */ - public function getMaxResults() - { - return $this->maxResults; - } - - /** - * @param int $maxResults - * - * @return self - */ - public function setMaxResults($maxResults) - { - $this->maxResults = $maxResults; - - return $this; - } - - /** - * @return self - */ - public function andWhere(SpecificationInterface $specification) - { - if ($this->specification === null) { - return $this->where($specification); - } - - $this->specification = new AndSpecification($this->specification, $specification); - - return $this; - } - - /** - * @return self - */ - public function where(SpecificationInterface $specification) - { - $this->specification = $specification; - - return $this; - } - - /** - * @return self - */ - public function orWhere(SpecificationInterface $specification) - { - if ($this->specification === null) { - return $this->where($specification); - } - - $this->specification = new OrSpecification($this->specification, $specification); - - return $this; - } -} diff --git a/src/Prime/Filter/FilterInterface.php b/src/Prime/Filter/FilterInterface.php deleted file mode 100644 index fa8a6291..00000000 --- a/src/Prime/Filter/FilterInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - $criteria - * - * @return Envelope[] - */ - public function filter(array $envelopes, array $criteria); -} diff --git a/src/Prime/Filter/Specification/AndSpecification.php b/src/Prime/Filter/Specification/AndSpecification.php index ca53d28d..634214cb 100644 --- a/src/Prime/Filter/Specification/AndSpecification.php +++ b/src/Prime/Filter/Specification/AndSpecification.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class AndSpecification implements SpecificationInterface { @@ -16,11 +21,14 @@ final class AndSpecification implements SpecificationInterface */ public function __construct($specifications) { - $specifications = is_array($specifications) ? $specifications : func_get_args(); + $specifications = \is_array($specifications) ? $specifications : \func_get_args(); $this->specifications = $specifications; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { foreach ($this->specifications as $specification) { diff --git a/src/Prime/Filter/Specification/CallbackSpecification.php b/src/Prime/Filter/Specification/CallbackSpecification.php index 6de4c626..1dfeea8e 100644 --- a/src/Prime/Filter/Specification/CallbackSpecification.php +++ b/src/Prime/Filter/Specification/CallbackSpecification.php @@ -1,29 +1,41 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; -use Flasher\Prime\Filter\FilterBuilder; +use Flasher\Prime\Filter\Filter; +use Flasher\Prime\Notification\Envelope; final class CallbackSpecification implements SpecificationInterface { - /** @var FilterBuilder $filterBuilder */ - private $filterBuilder; + /** + * @var Filter + */ + private $filter; - /** @var callable $callback */ + /** + * @var callable + */ private $callback; /** * @param callable $callback */ - public function __construct(FilterBuilder $filterBuilder, $callback) + public function __construct(Filter $filterBuilder, $callback) { - $this->filterBuilder = $filterBuilder; + $this->filter = $filterBuilder; $this->callback = $callback; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { - return call_user_func($this->callback, $envelope, $this->filterBuilder); + return (bool) \call_user_func($this->callback, $envelope, $this->filter); } } diff --git a/src/Prime/Filter/Specification/DelaySpecification.php b/src/Prime/Filter/Specification/DelaySpecification.php index 3ffbe332..f258464c 100644 --- a/src/Prime/Filter/Specification/DelaySpecification.php +++ b/src/Prime/Filter/Specification/DelaySpecification.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Stamp\DelayStamp; final class DelaySpecification implements SpecificationInterface { @@ -26,11 +32,14 @@ final class DelaySpecification implements SpecificationInterface $this->maxDelay = $maxDelay; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { $stamp = $envelope->get('Flasher\Prime\Stamp\DelayStamp'); - if (null === $stamp) { + if (!$stamp instanceof DelayStamp) { return false; } diff --git a/src/Prime/Filter/Specification/HopsSpecification.php b/src/Prime/Filter/Specification/HopsSpecification.php index 3e84acc8..49593609 100644 --- a/src/Prime/Filter/Specification/HopsSpecification.php +++ b/src/Prime/Filter/Specification/HopsSpecification.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Stamp\HopsStamp; final class HopsSpecification implements SpecificationInterface { @@ -26,11 +32,14 @@ final class HopsSpecification implements SpecificationInterface $this->maxAmount = $maxAmount; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { $stamp = $envelope->get('Flasher\Prime\Stamp\HopsStamp'); - if (null === $stamp) { + if (!$stamp instanceof HopsStamp) { return false; } diff --git a/src/Prime/Filter/Specification/NotSpecification.php b/src/Prime/Filter/Specification/NotSpecification.php deleted file mode 100644 index 80e2deca..00000000 --- a/src/Prime/Filter/Specification/NotSpecification.php +++ /dev/null @@ -1,23 +0,0 @@ -specification = $specification; - } - - public function isSatisfiedBy(Envelope $envelope) - { - return !$this->specification->isSatisfiedBy($envelope); - } -} diff --git a/src/Prime/Filter/Specification/OrSpecification.php b/src/Prime/Filter/Specification/OrSpecification.php deleted file mode 100644 index 3aff92a1..00000000 --- a/src/Prime/Filter/Specification/OrSpecification.php +++ /dev/null @@ -1,34 +0,0 @@ -specifications = $specifications; - } - - public function isSatisfiedBy(Envelope $envelope) - { - foreach ($this->specifications as $specification) { - if ($specification->isSatisfiedBy($envelope)) { - return true; - } - } - - return false; - } -} diff --git a/src/Prime/Filter/Specification/PrioritySpecification.php b/src/Prime/Filter/Specification/PrioritySpecification.php index 5d8c065c..ffe202cf 100644 --- a/src/Prime/Filter/Specification/PrioritySpecification.php +++ b/src/Prime/Filter/Specification/PrioritySpecification.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Stamp\PriorityStamp; final class PrioritySpecification implements SpecificationInterface { @@ -26,11 +32,14 @@ final class PrioritySpecification implements SpecificationInterface $this->maxPriority = $maxPriority; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { $stamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp'); - if (null === $stamp) { + if (!$stamp instanceof PriorityStamp) { return false; } diff --git a/src/Prime/Filter/Specification/SpecificationInterface.php b/src/Prime/Filter/Specification/SpecificationInterface.php index 8ae261e5..6bbbf2ae 100644 --- a/src/Prime/Filter/Specification/SpecificationInterface.php +++ b/src/Prime/Filter/Specification/SpecificationInterface.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; interface SpecificationInterface { diff --git a/src/Prime/Filter/Specification/StampsSpecification.php b/src/Prime/Filter/Specification/StampsSpecification.php index 8497bcf3..f890074f 100644 --- a/src/Prime/Filter/Specification/StampsSpecification.php +++ b/src/Prime/Filter/Specification/StampsSpecification.php @@ -1,23 +1,32 @@ + */ + namespace Flasher\Prime\Filter\Specification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class StampsSpecification implements SpecificationInterface { const STRATEGY_AND = 'and'; const STRATEGY_OR = 'or'; - /** @var array|string[] */ + /** + * @var array|string[] + */ private $stamps; - /** @var string */ + /** + * @var string + */ private $strategy; /** * @param string|string[] $stamps - * @param string $strategy + * @param string $strategy */ public function __construct($stamps, $strategy) { @@ -25,14 +34,17 @@ final class StampsSpecification implements SpecificationInterface $this->strategy = $strategy; } + /** + * {@inheritdoc} + */ public function isSatisfiedBy(Envelope $envelope) { $diff = array_diff($this->stamps, array_keys($envelope->all())); if (self::STRATEGY_AND === $this->strategy) { - return 0 === count($diff); + return 0 === \count($diff); } - return count($diff) < count($this->stamps); + return \count($diff) < \count($this->stamps); } } diff --git a/src/Prime/Filter/Specification/TimeSpecification.php b/src/Prime/Filter/Specification/TimeSpecification.php deleted file mode 100644 index 2c4a633b..00000000 --- a/src/Prime/Filter/Specification/TimeSpecification.php +++ /dev/null @@ -1,40 +0,0 @@ -minTime = $minTime; - $this->maxTime = $maxTime; - } - - public function isSatisfiedBy(Envelope $envelope) - { - $stamp = $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp'); - - if (null === $stamp) { - return false; - } - - if (null !== $this->maxTime && $stamp->getCreatedAt() > $this->maxTime) { - return false; - } - - return $stamp->getCreatedAt() >= $this->minTime; - } -} diff --git a/src/Prime/Flasher.php b/src/Prime/Flasher.php index 922b51c5..0a5d8e53 100644 --- a/src/Prime/Flasher.php +++ b/src/Prime/Flasher.php @@ -1,11 +1,18 @@ + */ + namespace Flasher\Prime; -use Flasher\Prime\Config\ConfigInterface; +use Flasher\Prime\Factory\NotificationFactory; use Flasher\Prime\Factory\NotificationFactoryInterface; use Flasher\Prime\Notification\NotificationBuilderInterface; +use Flasher\Prime\Response\ResponseManager; use Flasher\Prime\Response\ResponseManagerInterface; +use Flasher\Prime\Storage\StorageManagerInterface; /** * @mixin NotificationBuilderInterface @@ -13,32 +20,42 @@ use Flasher\Prime\Response\ResponseManagerInterface; final class Flasher implements FlasherInterface { /** - * The array of created notification "factories". - * - * @template T or NotificationFactoryInterface - * - * @var array + * @var array */ private $factories = array(); /** - * @var ConfigInterface + * @var string|null */ - private $config; + private $defaultHandler; - /** @var ResponseManagerInterface */ + /** + * @var ResponseManagerInterface + */ private $responseManager; - public function __construct(ConfigInterface $config, ResponseManagerInterface $responseManager) - { - $this->config = $config; - $this->responseManager = $responseManager; + /** + * @var StorageManagerInterface|null + */ + private $storageManager; + + /** + * @param string $defaultHandler + */ + public function __construct( + $defaultHandler, + ResponseManagerInterface $responseManager = null, + StorageManagerInterface $storageManager = null + ) { + $this->defaultHandler = $defaultHandler ?: 'flasher'; + $this->responseManager = $responseManager ?: new ResponseManager(); + $this->storageManager = $storageManager; } /** * Dynamically call the default factory instance. * - * @param string $method + * @param string $method * @param mixed[] $parameters * * @return mixed @@ -48,42 +65,52 @@ final class Flasher implements FlasherInterface /** @var callable $callback */ $callback = array($this->create(), $method); - return call_user_func_array($callback, $parameters); + return \call_user_func_array($callback, $parameters); } + /** + * {@inheritdoc} + */ public function create($alias = null) { - $alias = $alias ?: $this->getDefaultFactory(); + $alias = trim($alias ?: $this->defaultHandler ?: ''); - if (!isset($this->factories[$alias])) { - throw new \InvalidArgumentException(sprintf('Factory [%s] not supported.', $alias)); + if (empty($alias)) { + throw new \InvalidArgumentException('Unable to resolve empty factory.'); } - return $this->factories[$alias]; + if (!isset($this->factories[$alias])) { + $this->addFactory($alias, new NotificationFactory($this->storageManager, $alias)); + } + + $factory = $this->factories[$alias]; + + return \is_callable($factory) ? $factory() : $factory; } + /** + * {@inheritdoc} + */ public function using($alias) { return $this->create($alias); } - public function addFactory($alias, NotificationFactoryInterface $factory) - { - $this->factories[$alias] = $factory; - - return $this; - } - + /** + * {@inheritdoc} + */ public function render(array $criteria = array(), $presenter = 'html', array $context = array()) { return $this->responseManager->render($criteria, $presenter, $context); } /** - * @return string|null + * {@inheritdoc} */ - private function getDefaultFactory() + public function addFactory($alias, $factory) { - return $this->config->get('default'); + $this->factories[$alias] = $factory; + + return $this; } } diff --git a/src/Prime/FlasherInterface.php b/src/Prime/FlasherInterface.php index 0c7a9a02..a126d34a 100644 --- a/src/Prime/FlasherInterface.php +++ b/src/Prime/FlasherInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime; use Flasher\Prime\Factory\NotificationFactoryInterface; @@ -15,9 +20,9 @@ interface FlasherInterface * * @param string|null $alias * - * @return NotificationFactoryInterface - * * @throws \InvalidArgumentException + * + * @return NotificationFactoryInterface */ public function create($alias = null); @@ -26,24 +31,25 @@ interface FlasherInterface * * @param string|null $alias * - * @return NotificationFactoryInterface - * * @throws \InvalidArgumentException + * + * @return NotificationFactoryInterface */ public function using($alias); /** * Register a custom driver creator. * - * @param string $alias + * @param string $alias + * @param callable|NotificationFactoryInterface $factory * - * @return $this + * @return static */ - public function addFactory($alias, NotificationFactoryInterface $factory); + public function addFactory($alias, $factory); /** * @param array $criteria - * @param string $presenter + * @param string $presenter * @param array $context * * @return mixed diff --git a/src/Prime/Envelope.php b/src/Prime/Notification/Envelope.php similarity index 55% rename from src/Prime/Envelope.php rename to src/Prime/Notification/Envelope.php index 24680872..a0b01666 100644 --- a/src/Prime/Envelope.php +++ b/src/Prime/Notification/Envelope.php @@ -1,8 +1,12 @@ + */ + +namespace Flasher\Prime\Notification; -use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\PresentableStampInterface; use Flasher\Prime\Stamp\StampInterface; @@ -14,43 +18,57 @@ final class Envelope implements NotificationInterface private $notification; /** - * @template T of StampInterface - * - * @var array + * @var array, StampInterface> */ private $stamps = array(); /** - * @param StampInterface[]|StampInterface $stamps + * @param StampInterface|StampInterface[] $stamps */ public function __construct(NotificationInterface $notification, $stamps = array()) { $this->notification = $notification; - $this->with(is_array($stamps) ? $stamps : array_slice(func_get_args(), 1)); + $this->with(\is_array($stamps) ? $stamps : \array_slice(\func_get_args(), 1)); + } + + /** + * Dynamically call methods on the notification. + * + * @param string $method + * @param mixed[] $parameters + * + * @return mixed + */ + public function __call($method, array $parameters) + { + /** @var callable $callback */ + $callback = array($this->getNotification(), $method); + + return \call_user_func_array($callback, $parameters); } /** * Makes sure the notification is in an Envelope and adds the given stamps. * - * @param StampInterface[]|StampInterface $stamps + * @param StampInterface|StampInterface[] $stamps * - * @return self + * @return static */ public static function wrap(NotificationInterface $notification, $stamps = array()) { $envelope = $notification instanceof self ? $notification : new self($notification); - return $envelope->with(is_array($stamps) ? $stamps : array_slice(func_get_args(), 1)); + return $envelope->with(\is_array($stamps) ? $stamps : \array_slice(\func_get_args(), 1)); } /** - * @param StampInterface[]|StampInterface $stamps + * @param StampInterface|StampInterface[] $stamps * - * @return self a new Envelope instance with additional stamp + * @return static */ public function with($stamps) { - $stamps = is_array($stamps) ? $stamps : func_get_args(); + $stamps = \is_array($stamps) ? $stamps : \func_get_args(); foreach ($stamps as $stamp) { $this->withStamp($stamp); @@ -60,23 +78,23 @@ final class Envelope implements NotificationInterface } /** - * @return $this + * @return static */ public function withStamp(StampInterface $stamp) { - $this->stamps[get_class($stamp)] = $stamp; + $this->stamps[\get_class($stamp)] = $stamp; return $this; } /** - * @param StampInterface[]|StampInterface $stamps + * @param StampInterface|StampInterface[] $stamps * - * @return self A new Envelope instance without any stamps of the given class + * @return static */ public function without($stamps) { - $stamps = is_array($stamps) ? $stamps : func_get_args(); + $stamps = \is_array($stamps) ? $stamps : \func_get_args(); foreach ($stamps as $stamp) { $this->withoutStamp($stamp); @@ -86,13 +104,13 @@ final class Envelope implements NotificationInterface } /** - * @param string|StampInterface $type + * @param class-string|StampInterface $type * - * @return self + * @return static */ public function withoutStamp($type) { - $type = $type instanceof StampInterface ? get_class($type) : $type; + $type = $type instanceof StampInterface ? \get_class($type) : $type; unset($this->stamps[$type]); @@ -100,11 +118,9 @@ final class Envelope implements NotificationInterface } /** - * @template T of StampInterface + * @param class-string $stampFqcn * - * @param class-string $stampFqcn - * - * @return T|null + * @return StampInterface|null */ public function get($stampFqcn) { @@ -112,14 +128,13 @@ final class Envelope implements NotificationInterface return null; } - // @phpstan-ignore-next-line return $this->stamps[$stampFqcn]; } /** - * All stamps by their class name + * All stamps by their class name. * - * @return StampInterface[] + * @return array, StampInterface> */ public function all() { @@ -127,7 +142,7 @@ final class Envelope implements NotificationInterface } /** - * The original notification contained in the envelope + * The original notification contained in the envelope. * * @return NotificationInterface */ @@ -136,51 +151,97 @@ final class Envelope implements NotificationInterface return $this->notification; } + /** + * {@inheritdoc} + */ public function getType() { return $this->notification->getType(); } + /** + * {@inheritdoc} + */ public function setType($type) { - $this->notification->setType($type); + return $this->notification->setType($type); // @phpstan-ignore-line } + /** + * {@inheritdoc} + */ public function getMessage() { return $this->notification->getMessage(); } + /** + * {@inheritdoc} + */ public function setMessage($message) { - $this->notification->setMessage($message); + return $this->notification->setMessage($message); // @phpstan-ignore-line } + /** + * {@inheritdoc} + */ + public function getTitle() + { + return $this->notification->getTitle(); + } + + /** + * {@inheritdoc} + */ + public function setTitle($title) + { + return $this->notification->setMessage($title); // @phpstan-ignore-line + } + + /** + * {@inheritdoc} + */ public function getOptions() { return $this->notification->getOptions(); } + /** + * {@inheritdoc} + */ public function setOptions(array $options) { - $this->notification->setOptions($options); + return $this->notification->setOptions($options); // @phpstan-ignore-line } + /** + * {@inheritdoc} + */ public function getOption($name, $default = null) { return $this->notification->getOption($name, $default); } + /** + * {@inheritdoc} + */ public function setOption($name, $value) { - $this->notification->setOption($name, $value); + return $this->notification->setOption($name, $value); // @phpstan-ignore-line } + /** + * {@inheritdoc} + */ public function unsetOption($name) { - $this->notification->unsetOption($name); + return $this->notification->unsetOption($name); // @phpstan-ignore-line } + /** + * {@inheritdoc} + */ public function toArray() { $array = array( @@ -195,20 +256,4 @@ final class Envelope implements NotificationInterface return $array; } - - /** - * Dynamically call methods on the notification - * - * @param string $method - * @param mixed[] $parameters - * - * @return mixed - */ - public function __call($method, array $parameters) - { - /** @var callable $callback */ - $callback = array($this->getNotification(), $method); - - return call_user_func_array($callback, $parameters); - } } diff --git a/src/Prime/Notification/Notification.php b/src/Prime/Notification/Notification.php index 1df2ce15..a58559ed 100644 --- a/src/Prime/Notification/Notification.php +++ b/src/Prime/Notification/Notification.php @@ -1,54 +1,109 @@ + */ + namespace Flasher\Prime\Notification; class Notification implements NotificationInterface { /** - * @var string + * @var string|null */ protected $message; /** * @var string */ - protected $type = self::TYPE_INFO; + protected $type = self::INFO; /** * @var array */ protected $options = array(); + /** + * @var string|null + */ + private $title; + + /** + * {@inheritdoc} + */ public function getType() { return $this->type; } + /** + * {@inheritdoc} + */ public function setType($type) { $this->type = $type; + + return $this; } + /** + * {@inheritdoc} + */ public function getMessage() { return $this->message; } + /** + * {@inheritdoc} + */ public function setMessage($message) { $this->message = $message; + + return $this; } + /** + * {@inheritdoc} + */ + public function getTitle() + { + return $this->title; + } + + /** + * {@inheritdoc} + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * {@inheritdoc} + */ public function getOptions() { return $this->options; } + /** + * {@inheritdoc} + */ public function setOptions(array $options) { $this->options = array_replace($this->options, $options); + + return $this; } + /** + * {@inheritdoc} + */ public function getOption($name, $default = null) { if (!isset($this->options[$name])) { @@ -58,21 +113,35 @@ class Notification implements NotificationInterface return $this->options[$name]; } + /** + * {@inheritdoc} + */ public function setOption($name, $value) { $this->options[$name] = $value; + + return $this; } + /** + * {@inheritdoc} + */ public function unsetOption($name) { unset($this->options[$name]); + + return $this; } + /** + * {@inheritdoc} + */ public function toArray() { return array( 'type' => $this->getType(), 'message' => $this->getMessage(), + 'title' => $this->getTitle(), 'options' => $this->getOptions(), ); } diff --git a/src/Prime/Notification/NotificationBuilder.php b/src/Prime/Notification/NotificationBuilder.php index be2845da..2714acbe 100644 --- a/src/Prime/Notification/NotificationBuilder.php +++ b/src/Prime/Notification/NotificationBuilder.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Notification; -use Flasher\Prime\Envelope; +use Flasher\Prime\Stamp\ContextStamp; use Flasher\Prime\Stamp\DelayStamp; use Flasher\Prime\Stamp\HandlerStamp; use Flasher\Prime\Stamp\HopsStamp; @@ -10,6 +15,9 @@ use Flasher\Prime\Stamp\PriorityStamp; use Flasher\Prime\Stamp\StampInterface; use Flasher\Prime\Storage\StorageManagerInterface; +/** + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ class NotificationBuilder implements NotificationBuilderInterface { /** @@ -22,65 +30,106 @@ class NotificationBuilder implements NotificationBuilderInterface */ protected $storageManager; - /** @var array */ + /** + * @var array + */ protected static $macros = array(); /** * @param string $handler */ - public function __construct(StorageManagerInterface $storageManager, NotificationInterface $notification, $handler) + public function __construct(StorageManagerInterface $storageManager, NotificationInterface $notification, $handler = null) { $this->storageManager = $storageManager; $this->envelope = Envelope::wrap($notification); - $this->handler($handler); + + if (null !== $handler) { + $this->handler($handler); + } } /** - * @param string $message + * @param string $method + * @param mixed[] $parameters * - * @return Envelope + * @return mixed + */ + public static function __callStatic($method, $parameters) + { + if (!static::hasMacro($method)) { + throw new \BadMethodCallException(sprintf('Method %s::%s does not exist.', \get_called_class(), $method)); + } + + $macro = static::$macros[$method]; + + if ($macro instanceof \Closure) { + /** @var callable $callback */ + $callback = \Closure::bind($macro, null, \get_called_class()); + + return \call_user_func_array($callback, $parameters); + } + + return \call_user_func_array($macro, $parameters); + } + + /** + * @param string $method + * @param mixed[] $parameters + * + * @return mixed + */ + public function __call($method, $parameters) + { + if (!static::hasMacro($method)) { + throw new \BadMethodCallException(sprintf('Method %s::%s does not exist.', \get_called_class(), $method)); + } + + $macro = static::$macros[$method]; + + if ($macro instanceof \Closure) { + /** @var callable $callback */ + $callback = $macro->bindTo($this, \get_called_class()); + + return \call_user_func_array($callback, $parameters); + } + + return \call_user_func_array($macro, $parameters); + } + + /** + * {@inheritdoc} */ public function addSuccess($message, array $options = array()) { - return $this->addFlash(NotificationInterface::TYPE_SUCCESS, $message, $options); + return $this->addFlash(NotificationInterface::SUCCESS, $message, $options); } /** - * @param string $message - * - * @return Envelope + * {@inheritdoc} */ public function addError($message, array $options = array()) { - return $this->addFlash(NotificationInterface::TYPE_ERROR, $message, $options); + return $this->addFlash(NotificationInterface::ERROR, $message, $options); } /** - * @param string $message - * - * @return Envelope + * {@inheritdoc} */ public function addWarning($message, array $options = array()) { - return $this->addFlash(NotificationInterface::TYPE_WARNING, $message, $options); + return $this->addFlash(NotificationInterface::WARNING, $message, $options); } /** - * @param string $message - * - * @return Envelope + * {@inheritdoc} */ public function addInfo($message, array $options = array()) { - return $this->addFlash(NotificationInterface::TYPE_INFO, $message, $options); + return $this->addFlash(NotificationInterface::INFO, $message, $options); } /** - * @param NotificationInterface|string $type - * @param string|null $message - * @param array $options - * - * @return Envelope + * {@inheritdoc} */ public function addFlash($type, $message = null, array $options = array()) { @@ -95,13 +144,11 @@ class NotificationBuilder implements NotificationBuilderInterface } /** - * @param StampInterface[] $stamps - * - * @return Envelope + * {@inheritdoc} */ public function flash(array $stamps = array()) { - if (!empty($stamps)) { + if (array() !== $stamps) { $this->with($stamps); } @@ -111,11 +158,7 @@ class NotificationBuilder implements NotificationBuilderInterface } /** - * @param string $type - * @param string|null $message - * @param array $options - * - * @return self + * {@inheritdoc} */ public function type($type, $message = null, array $options = array()) { @@ -133,9 +176,7 @@ class NotificationBuilder implements NotificationBuilderInterface } /** - * @param string $message - * - * @return self + * {@inheritdoc} */ public function message($message) { @@ -145,10 +186,17 @@ class NotificationBuilder implements NotificationBuilderInterface } /** - * @param array $options - * @param bool $merge - * - * @return self + * {@inheritdoc} + */ + public function title($title) + { + $this->envelope->setTitle($title); + + return $this; + } + + /** + * {@inheritdoc} */ public function options(array $options, $merge = true) { @@ -161,6 +209,9 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function option($name, $value) { $this->envelope->setOption($name, $value); @@ -168,26 +219,41 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function success($message = null, array $options = array()) { - return $this->type(NotificationInterface::TYPE_SUCCESS, $message, $options); + return $this->type(NotificationInterface::SUCCESS, $message, $options); } + /** + * {@inheritdoc} + */ public function error($message = null, array $options = array()) { - return $this->type(NotificationInterface::TYPE_ERROR, $message, $options); + return $this->type(NotificationInterface::ERROR, $message, $options); } + /** + * {@inheritdoc} + */ public function info($message = null, array $options = array()) { - return $this->type(NotificationInterface::TYPE_INFO, $message, $options); + return $this->type(NotificationInterface::INFO, $message, $options); } + /** + * {@inheritdoc} + */ public function warning($message = null, array $options = array()) { - return $this->type(NotificationInterface::TYPE_WARNING, $message, $options); + return $this->type(NotificationInterface::WARNING, $message, $options); } + /** + * {@inheritdoc} + */ public function priority($priority) { $this->envelope->withStamp(new PriorityStamp($priority)); @@ -195,6 +261,9 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function hops($amount) { $this->envelope->withStamp(new HopsStamp($amount)); @@ -202,6 +271,9 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function keep() { $hopsStamp = $this->envelope->get('Flasher\Prime\Stamp\HopsStamp'); @@ -212,6 +284,9 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function delay($delay) { $this->envelope->withStamp(new DelayStamp($delay)); @@ -219,18 +294,27 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function now() { return $this->delay(0); } - public function with(array $stamps = array()) + /** + * {@inheritdoc} + */ + public function with($stamps = array()) { $this->envelope->with($stamps); return $this; } + /** + * {@inheritdoc} + */ public function withStamp(StampInterface $stamp) { $this->envelope->withStamp($stamp); @@ -238,11 +322,17 @@ class NotificationBuilder implements NotificationBuilderInterface return $this; } + /** + * {@inheritdoc} + */ public function getEnvelope() { return $this->envelope; } + /** + * {@inheritdoc} + */ public function handler($handler) { $this->envelope->withStamp(new HandlerStamp($handler)); @@ -251,7 +341,17 @@ class NotificationBuilder implements NotificationBuilderInterface } /** - * @param string $name + * {@inheritdoc} + */ + public function context(array $context) + { + $this->envelope->withStamp(new ContextStamp($context)); + + return $this; + } + + /** + * @param string $name * @param callable $macro * * @return void @@ -263,7 +363,7 @@ class NotificationBuilder implements NotificationBuilderInterface /** * @param object $mixin - * @param bool $replace + * @param bool $replace * * @return void */ @@ -275,9 +375,12 @@ class NotificationBuilder implements NotificationBuilderInterface ); foreach ($methods as $method) { - if ($replace || ! static::hasMacro($method->name)) { + if ($replace || !static::hasMacro($method->name)) { $method->setAccessible(true); - static::macro($method->name, $method->invoke($mixin)); + + /** @var callable $callable */ + $callable = $method->invoke($mixin); + static::macro($method->name, $callable); } } } @@ -291,56 +394,4 @@ class NotificationBuilder implements NotificationBuilderInterface { return isset(static::$macros[$name]); } - - /** - * @param string $method - * @param mixed[] $parameters - * - * @return mixed - */ - public static function __callStatic($method, $parameters) - { - if (! static::hasMacro($method)) { - throw new \BadMethodCallException(sprintf( - 'Method %s::%s does not exist.', get_called_class(), $method - )); - } - - $macro = static::$macros[$method]; - - if ($macro instanceof \Closure) { - /** @var callable $callback */ - $callback = \Closure::bind($macro, null, get_called_class()); - - return call_user_func_array($callback, $parameters); - } - - return call_user_func_array($macro, $parameters); - } - - /** - * @param string $method - * @param mixed[] $parameters - * - * @return mixed - */ - public function __call($method, $parameters) - { - if (! static::hasMacro($method)) { - throw new \BadMethodCallException(sprintf( - 'Method %s::%s does not exist.', get_called_class(), $method - )); - } - - $macro = static::$macros[$method]; - - if ($macro instanceof \Closure) { - /** @var callable $callback */ - $callback = $macro->bindTo($this, get_called_class()); - - return call_user_func_array($callback, $parameters); - } - - return call_user_func_array($macro, $parameters); - } } diff --git a/src/Prime/Notification/NotificationBuilderInterface.php b/src/Prime/Notification/NotificationBuilderInterface.php index 2b0c59e1..29e9bdb8 100644 --- a/src/Prime/Notification/NotificationBuilderInterface.php +++ b/src/Prime/Notification/NotificationBuilderInterface.php @@ -1,19 +1,18 @@ + */ + namespace Flasher\Prime\Notification; -use Flasher\Prime\Envelope; use Flasher\Prime\Stamp\StampInterface; -/** - * @method $this livewire(array $context = array()) - * @method $this desktop(bool $renderImmediately = true) - * @method $this title(string $title) - */ interface NotificationBuilderInterface { /** - * @param string $message + * @param string $message * @param array $options * * @return Envelope @@ -21,7 +20,7 @@ interface NotificationBuilderInterface public function addSuccess($message, array $options = array()); /** - * @param string $message + * @param string $message * @param array $options * * @return Envelope @@ -29,7 +28,7 @@ interface NotificationBuilderInterface public function addError($message, array $options = array()); /** - * @param string $message + * @param string $message * @param array $options * * @return Envelope @@ -37,7 +36,7 @@ interface NotificationBuilderInterface public function addWarning($message, array $options = array()); /** - * @param string $message + * @param string $message * @param array $options * * @return Envelope @@ -45,35 +44,42 @@ interface NotificationBuilderInterface public function addInfo($message, array $options = array()); /** - * @param string|NotificationInterface $type - * @param string $message - * @param array $options + * @param NotificationInterface|string $type + * @param string|null $message + * @param array $options * - * @return Envelope|mixed + * @return Envelope */ public function addFlash($type, $message, array $options = array()); /** - * @param string $type - * @param string|null $message + * @param string $type + * @param string|null $message * @param array $options * - * @return self + * @return static */ public function type($type, $message = null, array $options = array()); /** * @param string $message * - * @return self + * @return static */ public function message($message); + /** + * @param string $title + * + * @return static + */ + public function title($title); + /** * @param array $options * @param bool $merge * - * @return self + * @return static */ public function options(array $options, $merge = true); @@ -81,89 +87,96 @@ interface NotificationBuilderInterface * @param string $name * @param mixed $value * - * @return self + * @return static */ public function option($name, $value); /** - * @param string|null $message + * @param string|null $message * @param array $options * - * @return self + * @return static */ public function success($message = null, array $options = array()); /** - * @param string|null $message + * @param string|null $message * @param array $options * - * @return self + * @return static */ public function error($message = null, array $options = array()); /** - * @param string|null $message + * @param string|null $message * @param array $options * - * @return self + * @return static */ public function info($message = null, array $options = array()); /** - * @param string|null $message + * @param string|null $message * @param array $options * - * @return self + * @return static */ public function warning($message = null, array $options = array()); /** * @param int $priority * - * @return self + * @return static */ public function priority($priority); /** - * @return self + * @return static */ public function keep(); /** * @param int $amount * - * @return self + * @return static */ public function hops($amount); /** * @param string $handler * - * @return self + * @return static */ public function handler($handler); /** - * @return self + * @param mixed[] $context + * + * @return static + */ + public function context(array $context); + + /** + * @return static */ public function withStamp(StampInterface $stamp); /** - * @param StampInterface[] $stamps + * @param StampInterface|StampInterface[] $stamps * - * @return self + * @return static */ - public function with(array $stamps = array()); + public function with($stamps = array()); /** - * @return self + * @return static */ public function now(); /** * @param int $delay * - * @return self + * @return static */ public function delay($delay); diff --git a/src/Prime/Notification/NotificationInterface.php b/src/Prime/Notification/NotificationInterface.php index acaab119..96e560dd 100644 --- a/src/Prime/Notification/NotificationInterface.php +++ b/src/Prime/Notification/NotificationInterface.php @@ -1,16 +1,18 @@ + */ + namespace Flasher\Prime\Notification; interface NotificationInterface { - const TYPE_SUCCESS = 'success'; - - const TYPE_ERROR = 'error'; - - const TYPE_INFO = 'info'; - - const TYPE_WARNING = 'warning'; + const SUCCESS = 'success'; + const ERROR = 'error'; + const INFO = 'info'; + const WARNING = 'warning'; /** * @return string @@ -20,22 +22,34 @@ interface NotificationInterface /** * @param string $type * - * @return void + * @return static */ public function setType($type); /** - * @return string + * @return string|null */ public function getMessage(); /** - * @param string $message + * @param string|null $message * - * @return void + * @return static */ public function setMessage($message); + /** + * @return string|null + */ + public function getTitle(); + + /** + * @param string|null $title + * + * @return static + */ + public function setTitle($title); + /** * @return array */ @@ -44,7 +58,7 @@ interface NotificationInterface /** * @param array $options * - * @return void + * @return static */ public function setOptions(array $options); @@ -60,14 +74,14 @@ interface NotificationInterface * @param string $name * @param mixed $value * - * @return mixed + * @return static */ public function setOption($name, $value); /** * @param string $name * - * @return void + * @return static */ public function unsetOption($name); diff --git a/src/Prime/Notification/Template.php b/src/Prime/Notification/Template.php deleted file mode 100644 index 3738b4f7..00000000 --- a/src/Prime/Notification/Template.php +++ /dev/null @@ -1,39 +0,0 @@ -title; - } - - /** - * @param string $title - * - * @return void - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * @return array - */ - public function toArray() - { - return array_merge(parent::toArray(), array( - 'title' => $this->getTitle(), - )); - } -} diff --git a/src/Prime/Notification/TemplateBuilder.php b/src/Prime/Notification/TemplateBuilder.php deleted file mode 100644 index 0ac10dc8..00000000 --- a/src/Prime/Notification/TemplateBuilder.php +++ /dev/null @@ -1,24 +0,0 @@ -envelope->getNotification(); - - if (!$notification instanceof Template) { - return $this; - } - - $notification->setTitle($title); - - return $this; - } -} diff --git a/src/Prime/Plugin/FlasherPlugin.php b/src/Prime/Plugin/FlasherPlugin.php new file mode 100644 index 00000000..5ccb58b7 --- /dev/null +++ b/src/Prime/Plugin/FlasherPlugin.php @@ -0,0 +1,116 @@ + + */ + +namespace Flasher\Prime\Plugin; + +class FlasherPlugin extends Plugin +{ + /** + * {@inheritdoc} + */ + public function getName() + { + return 'flasher'; + } + + /** + * {@inheritdoc} + */ + public function getServiceID() + { + return 'flasher'; + } + + /** + * @return string + */ + public function getDefault() + { + return 'flasher'; + } + + /** + * @return string + */ + public function getRootScript() + { + return 'https://cdn.jsdelivr.net/npm/@flasher/flasher@1.0.7/dist/flasher.min.js'; + } + + /** + * @return array + */ + public function getFlashBagMapping() + { + return array( + 'success' => array('success'), + 'error' => array('error', 'danger'), + 'warning' => array('warning', 'alarm'), + 'info' => array('info', 'notice', 'alert'), + ); + } + + /** + * {@inheritdoc} + */ + public function processConfiguration(array $options = array()) + { + if (\array_key_exists('flash_bag', $options)) { + $options['flash_bag'] = $this->normalizeFlashBagConfig($options['flash_bag']); + } + + return array_merge(array( + 'default' => $this->getDefault(), + 'root_script' => $this->getRootScript(), + 'flash_bag' => array( + 'enabled' => true, + 'mapping' => $this->getFlashBagMapping(), + ), + ), $options); + } + + /** + * @param mixed $config + * + * @return array + */ + public function normalizeFlashBagConfig($config) + { + if (null === $config || false === $config) { + return array('enabled' => false); + } + + if (!\is_array($config) || !\array_key_exists('mapping', $config) || !\is_array($config['mapping'])) { + return array('enabled' => true); + } + + $mapping = $config['mapping']; + + foreach ($mapping as $key => $values) { + if (!\is_string($key)) { + continue; + } + + if (!\is_array($values)) { + $mapping[$key] = array($values); + } + + foreach ($mapping[$key] as $index => $value) { + if (!\is_string($value)) { + unset($mapping[$key][$index]); + } + } + + $mapping[$key] = array_values($mapping[$key]); + } + + return array( + 'enabled' => true, + 'mapping' => $mapping, + ); + } +} diff --git a/src/Prime/Plugin/Plugin.php b/src/Prime/Plugin/Plugin.php new file mode 100644 index 00000000..c06d8fa6 --- /dev/null +++ b/src/Prime/Plugin/Plugin.php @@ -0,0 +1,86 @@ + + */ + +namespace Flasher\Prime\Plugin; + +abstract class Plugin implements PluginInterface +{ + /** + * {@inheritdoc} + */ + public function getAlias() + { + $alias = basename(str_replace('\\', '/', \get_class($this))); + + $alias = str_replace('Plugin', '', $alias); + + /** @var string $alias */ + $alias = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $alias); + + return strtolower($alias); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'flasher_'.$this->getAlias(); + } + + /** + * {@inheritdoc} + */ + public function getServiceID() + { + return 'flasher.'.$this->getAlias(); + } + + /** + * {@inheritdoc} + */ + public function getFactory() + { + return str_replace('Plugin', 'Factory', \get_class($this)); // @phpstan-ignore-line + } + + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array(); + } + + /** + * {@inheritdoc} + */ + public function getStyles() + { + return array(); + } + + /** + * {@inheritdoc} + */ + public function getOptions() + { + return array(); + } + + /** + * {@inheritdoc} + */ + public function processConfiguration(array $options = array()) + { + return array_merge(array( + 'scripts' => $this->getScripts(), + 'styles' => $this->getStyles(), + 'options' => $this->getOptions(), + ), $options); + } +} diff --git a/src/Prime/Plugin/PluginInterface.php b/src/Prime/Plugin/PluginInterface.php new file mode 100644 index 00000000..d32083c0 --- /dev/null +++ b/src/Prime/Plugin/PluginInterface.php @@ -0,0 +1,55 @@ + + */ + +namespace Flasher\Prime\Plugin; + +use Flasher\Prime\Factory\NotificationFactoryInterface; + +interface PluginInterface +{ + /** + * @return string + */ + public function getAlias(); + + /** + * @return string + */ + public function getName(); + + /** + * @return string + */ + public function getServiceID(); + + /** + * @return class-string + */ + public function getFactory(); + + /** + * @return string[] + */ + public function getScripts(); + + /** + * @return string[] + */ + public function getStyles(); + + /** + * @return array + */ + public function getOptions(); + + /** + * @param array $options + * + * @return array + */ + public function processConfiguration(array $options = array()); +} diff --git a/src/Prime/README.md b/src/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/Prime/README.md +++ b/src/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Prime/Response/Presenter/ArrayPresenter.php b/src/Prime/Response/Presenter/ArrayPresenter.php old mode 100755 new mode 100644 index 4dd91426..690b6f07 --- a/src/Prime/Response/Presenter/ArrayPresenter.php +++ b/src/Prime/Response/Presenter/ArrayPresenter.php @@ -1,11 +1,19 @@ + */ + namespace Flasher\Prime\Response\Presenter; use Flasher\Prime\Response\Response; final class ArrayPresenter implements PresenterInterface { + /** + * {@inheritdoc} + */ public function render(Response $response) { return $response->toArray(); diff --git a/src/Prime/Response/Presenter/HtmlPresenter.php b/src/Prime/Response/Presenter/HtmlPresenter.php old mode 100755 new mode 100644 index bafc6def..5399ef55 --- a/src/Prime/Response/Presenter/HtmlPresenter.php +++ b/src/Prime/Response/Presenter/HtmlPresenter.php @@ -1,52 +1,98 @@ + */ + namespace Flasher\Prime\Response\Presenter; use Flasher\Prime\Response\Response; final class HtmlPresenter implements PresenterInterface { + const FLASHER_FLASH_BAG_PLACE_HOLDER = 'FLASHER_FLASH_BAG_PLACE_HOLDER'; + + /** + * {@inheritdoc} + */ public function render(Response $response) { - if (0 === count($response->getEnvelopes())) { - return ''; + $options = json_encode($response->toArray(true)); + $context = $response->getContext(); + + if (isset($context['envelopes_only']) && true === $context['envelopes_only']) { + return $options; } - $options = json_encode($response->toArray()); - - $renderScript = "Flasher.getInstance().render(${options});"; - $rootScript = $response->getRootScript(); - if (empty($rootScript)) { - return << - document.addEventListener('DOMContentLoaded', function() { - ${renderScript} - }) - -JAVASCRIPT; - } - + $placeHolder = self::FLASHER_FLASH_BAG_PLACE_HOLDER; return << - flasherRender = function() { - ${renderScript} +(function() { + var rootScript = '{$rootScript}'; + var {$placeHolder} = {}; + var options = mergeOptions({$options}, {$placeHolder}); + + function mergeOptions(first, second) { + return { + context: merge(first.context || {}, second.context || {}), + envelopes: merge(first.envelopes || [], second.envelopes || []), + options: merge(first.options || {}, second.options || {}), + scripts: merge(first.scripts || [], second.scripts || []), + styles: merge(first.styles || [], second.styles || []), + }; } - if (!window.Flasher && !document.querySelector('script[src="${rootScript}"]')) { - var tag = document.createElement('script'); + function merge(first, second) { + if (Array.isArray(first) && Array.isArray(second)) { + return first.concat(second).filter(function(item, index, array) { + return array.indexOf(item) === index; + }); + } - tag.setAttribute('src', '${rootScript}'); - tag.setAttribute('type', 'text/javascript'); - tag.onload = flasherRender; + return Object.assign({}, first, second); + } + + function renderOptions(options) { + if(!window.hasOwnProperty('flasher')) { + console.error('Flasher is not loaded'); + return; + } + + window.flasher.render(options); + } + + function render(options) { + if ('loading' !== document.readyState) { + renderOptions(options); + + return; + } - document.body.appendChild(tag); - } else { document.addEventListener('DOMContentLoaded', function() { - flasherRender(); + renderOptions(options); }); } + + document.addEventListener('flasher:render', function (event) { + render(event.detail); + }); + + if (!rootScript || document.querySelector('script[src="' + rootScript + '"]')) { + render(options); + } else { + var tag = document.createElement('script'); + tag.setAttribute('src', rootScript); + tag.setAttribute('type', 'text/javascript'); + tag.onload = function () { + render(options); + }; + + document.head.appendChild(tag); + } +})(); JAVASCRIPT; } diff --git a/src/Prime/Response/Presenter/PresenterInterface.php b/src/Prime/Response/Presenter/PresenterInterface.php old mode 100755 new mode 100644 index 1ad05cf5..97515384 --- a/src/Prime/Response/Presenter/PresenterInterface.php +++ b/src/Prime/Response/Presenter/PresenterInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Response\Presenter; use Flasher\Prime\Response\Response; diff --git a/src/Prime/Response/Resource/ResourceManager.php b/src/Prime/Response/Resource/ResourceManager.php index 79303a54..15c39efb 100644 --- a/src/Prime/Response/Resource/ResourceManager.php +++ b/src/Prime/Response/Resource/ResourceManager.php @@ -1,13 +1,19 @@ + */ + namespace Flasher\Prime\Response\Resource; +use Flasher\Prime\Config\Config; use Flasher\Prime\Config\ConfigInterface; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Response\Response; use Flasher\Prime\Stamp\HandlerStamp; -use Flasher\Prime\Stamp\TemplateStamp; -use Flasher\Prime\Template\EngineInterface; +use Flasher\Prime\Stamp\ViewStamp; +use Flasher\Prime\Template\TemplateEngineInterface; final class ResourceManager implements ResourceManagerInterface { @@ -17,7 +23,7 @@ final class ResourceManager implements ResourceManagerInterface private $config; /** - * @var EngineInterface + * @var TemplateEngineInterface|null */ private $templateEngine; @@ -32,75 +38,61 @@ final class ResourceManager implements ResourceManagerInterface private $styles = array(); /** - * @var array + * @var array> */ private $options = array(); - public function __construct(ConfigInterface $config, EngineInterface $templateEngine) + public function __construct(ConfigInterface $config = null, TemplateEngineInterface $templateEngine = null) { - $this->config = $config; + $this->config = $config ?: new Config(); $this->templateEngine = $templateEngine; } - public function filterResponse(Response $response) + /** + * {@inheritdoc} + */ + public function buildResponse(Response $response) { + /** @var string $rootScript */ $rootScript = $this->config->get('root_script'); - if (null === $rootScript) { - $rootScripts = $this->config->get('root_scripts', array()); - $rootScript = reset($rootScripts); - } - $response->setRootScript($rootScript); $handlers = array(); - foreach ($response->getEnvelopes() as $envelope) { - $handlerStamp = $envelope->get('Flasher\Prime\Stamp\HandlerStamp'); - if (!$handlerStamp instanceof HandlerStamp) { + $handler = $this->resolveHandler($envelope); + if (null === $handler || \in_array($handler, $handlers, true)) { continue; } - - $handler = $handlerStamp->getHandler(); - - if (0 === strpos($handler, 'template')) { - $handler = $this->handleTemplateStamp($handler, $envelope); - } - - if (in_array($handler, $handlers, true)) { - continue; - } - $handlers[] = $handler; - if (isset($this->scripts[$handler])) { - $response->addScripts($this->scripts[$handler]); - } - - if (isset($this->styles[$handler])) { - $response->addStyles($this->styles[$handler]); - } - - if (isset($this->options[$handler])) { - $response->addOptions($handler, $this->options[$handler]); - } + $this->populateResponse($response, $handler); } return $response; } - public function addScripts($alias, array $scripts) + /** + * {@inheritdoc} + */ + public function addScripts($handler, array $scripts) { - $this->scripts[$alias] = $scripts; + $this->scripts[$handler] = $scripts; } - public function addStyles($alias, array $styles) + /** + * {@inheritdoc} + */ + public function addStyles($handler, array $styles) { - $this->styles[$alias] = $styles; + $this->styles[$handler] = $styles; } - public function addOptions($alias, array $options) + /** + * {@inheritdoc} + */ + public function addOptions($handler, array $options) { - $this->options[$alias] = $options; + $this->options[$handler] = $options; } /** @@ -112,35 +104,76 @@ final class ResourceManager implements ResourceManagerInterface } /** - * @param string $handler - * - * @return string + * @return string|null */ - private function handleTemplateStamp($handler, Envelope $envelope) + private function resolveHandler(Envelope $envelope) { - $view = $this->getTemplateAdapter($handler); - $template = $this->config->get('template_factory.templates.' . $view . '.view'); + $handlerStamp = $envelope->get('Flasher\Prime\Stamp\HandlerStamp'); + if (!$handlerStamp instanceof HandlerStamp) { + return null; + } - $compiled = $this->templateEngine->render($template, array( - 'envelope' => $envelope, - )); + $handler = $handlerStamp->getHandler(); + if ('flasher' !== $handler && 0 !== strpos($handler, 'theme.')) { + return $handler; + } - $envelope->withStamp(new TemplateStamp($compiled)); + $theme = $this->getTheme($handler); + if (null === $theme) { + return $handler; + } - return 'template.' . $view; + if (!isset($this->options[$handler])) { + /** @var array $options */ + $options = $this->config->get('themes.'.$theme.'.options', array()); + $this->addOptions($handler, $options); + } + + /** @var string|null $view */ + $view = $this->config->get('themes.'.$theme.'.view'); + if (null === $view || null === $this->templateEngine) { + return 'theme.'.$theme; + } + + $compiled = $this->templateEngine->render($view, array('envelope' => $envelope)); + $envelope->withStamp(new ViewStamp($compiled)); + + return 'theme.'.$theme; } /** * @param string $handler * - * @return string + * @return string|null */ - private function getTemplateAdapter($handler) + private function getTheme($handler) { - if (0 === strpos($handler, 'template.')) { - return substr($handler, strlen('template.')); + if (0 === strpos($handler, 'theme.')) { + return substr($handler, \strlen('theme.')); } - return $this->config->get('template_factory.default'); + $template = key((array) $this->config->get('themes')); + + return \is_string($template) ? $template : null; + } + + /** + * @param string $handler + * + * @return void + */ + private function populateResponse(Response $response, $handler) + { + if (isset($this->scripts[$handler])) { + $response->addScripts($this->scripts[$handler]); + } + + if (isset($this->styles[$handler])) { + $response->addStyles($this->styles[$handler]); + } + + if (isset($this->options[$handler])) { + $response->addOptions($handler, $this->options[$handler]); + } } } diff --git a/src/Prime/Response/Resource/ResourceManagerInterface.php b/src/Prime/Response/Resource/ResourceManagerInterface.php index 52d9776d..ba1fee3f 100644 --- a/src/Prime/Response/Resource/ResourceManagerInterface.php +++ b/src/Prime/Response/Resource/ResourceManagerInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Response\Resource; use Flasher\Prime\Response\Response; @@ -9,29 +14,29 @@ interface ResourceManagerInterface /** * @return Response */ - public function filterResponse(Response $response); + public function buildResponse(Response $response); /** - * @param string $alias + * @param string $handler * @param string[] $scripts * * @return void */ - public function addScripts($alias, array $scripts); + public function addScripts($handler, array $scripts); /** - * @param string $alias + * @param string $handler * @param string[] $styles * * @return void */ - public function addStyles($alias, array $styles); + public function addStyles($handler, array $styles); /** - * @param string $alias - * @param mixed[] $options + * @param string $handler + * @param array $options * * @return void */ - public function addOptions($alias, array $options); + public function addOptions($handler, array $options); } diff --git a/src/Prime/Response/Response.php b/src/Prime/Response/Response.php old mode 100755 new mode 100644 index 7066472e..cb33ec31 --- a/src/Prime/Response/Response.php +++ b/src/Prime/Response/Response.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Response; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class Response { @@ -11,7 +16,9 @@ final class Response */ private $envelopes; - /** @var string */ + /** + * @var string|null + */ private $rootScript; /** @@ -25,18 +32,18 @@ final class Response private $styles = array(); /** - * @var array + * @var array> */ private $options = array(); /** - * @var mixed[] + * @var array */ private $context; /** - * @param Envelope[] $envelopes - * @param mixed[] $context + * @param Envelope[] $envelopes + * @param array $context */ public function __construct(array $envelopes, array $context) { @@ -65,8 +72,8 @@ final class Response } /** - * @param string $alias - * @param mixed[] $options + * @param string $alias + * @param array $options * * @return void */ @@ -84,7 +91,7 @@ final class Response } /** - * @return string + * @return string|null */ public function getRootScript() { @@ -92,7 +99,7 @@ final class Response } /** - * @param string $rootScript + * @param string|null $rootScript * * @return void */ @@ -118,7 +125,7 @@ final class Response } /** - * @return array[] + * @return array> */ public function getOptions() { @@ -126,7 +133,7 @@ final class Response } /** - * @return mixed[] + * @return array */ public function getContext() { @@ -134,20 +141,27 @@ final class Response } /** + * @param mixed $filter + * * @return array */ - public function toArray() + public function toArray($filter = false) { - return array( - 'envelopes' => array_map( - function (Envelope $envelope) { - return $envelope->toArray(); - }, - $this->getEnvelopes() - ), + $envelopes = array_map(function (Envelope $envelope) { + return $envelope->toArray(); + }, $this->getEnvelopes()); + + $response = array( + 'envelopes' => $envelopes, 'scripts' => $this->getScripts(), 'styles' => $this->getStyles(), 'options' => $this->getOptions(), ); + + if (false === $filter) { + return $response; + } + + return array_filter($response); } } diff --git a/src/Prime/Response/ResponseManager.php b/src/Prime/Response/ResponseManager.php old mode 100755 new mode 100644 index 67fedb22..2be2c507 --- a/src/Prime/Response/ResponseManager.php +++ b/src/Prime/Response/ResponseManager.php @@ -1,21 +1,36 @@ + */ + namespace Flasher\Prime\Response; -use Flasher\Prime\Envelope; -use Flasher\Prime\EventDispatcher\Event\FilterEvent; +use Flasher\Prime\EventDispatcher\Event\ResponseEvent; +use Flasher\Prime\EventDispatcher\EventDispatcher; use Flasher\Prime\EventDispatcher\EventDispatcherInterface; +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Response\Presenter\ArrayPresenter; +use Flasher\Prime\Response\Presenter\HtmlPresenter; use Flasher\Prime\Response\Presenter\PresenterInterface; +use Flasher\Prime\Response\Resource\ResourceManager; use Flasher\Prime\Response\Resource\ResourceManagerInterface; +use Flasher\Prime\Storage\StorageManager; use Flasher\Prime\Storage\StorageManagerInterface; final class ResponseManager implements ResponseManagerInterface { /** - * @var PresenterInterface[] + * @var array */ private $presenters; + /** + * @var ResourceManagerInterface + */ + private $resourceManager; + /** * @var StorageManagerInterface */ @@ -26,32 +41,40 @@ final class ResponseManager implements ResponseManagerInterface */ private $eventDispatcher; - /** - * @var ResourceManagerInterface - */ - private $resourceManager; + public function __construct(ResourceManagerInterface $resourceManager = null, StorageManagerInterface $storageManager = null, EventDispatcherInterface $eventDispatcher = null) + { + $this->resourceManager = $resourceManager ?: new ResourceManager(); + $this->storageManager = $storageManager ?: new StorageManager(); + $this->eventDispatcher = $eventDispatcher ?: new EventDispatcher(); - public function __construct( - StorageManagerInterface $storageManager, - EventDispatcherInterface $eventDispatcher, - ResourceManagerInterface $resourceManager - ) { - $this->storageManager = $storageManager; - $this->eventDispatcher = $eventDispatcher; - $this->resourceManager = $resourceManager; + $this->addPresenter('html', new HtmlPresenter()); + $this->addPresenter('json', new ArrayPresenter()); + $this->addPresenter('array', new ArrayPresenter()); } + /** + * {@inheritdoc} + */ public function render(array $criteria = array(), $presenter = 'html', array $context = array()) { - $envelopes = $this->getEnvelopes($criteria); - + $envelopes = $this->storageManager->filter($criteria); $this->storageManager->remove($envelopes); - $response = $this->filterResponse($envelopes, $context); + $response = $this->createResponse($envelopes, $context); + $response = $this->createPresenter($presenter)->render($response); - $presenter = $this->createPresenter($presenter); + $event = new ResponseEvent($response, $presenter); + $this->eventDispatcher->dispatch($event); - return $presenter->render($response); + return $event->getResponse(); + } + + /** + * {@inheritdoc} + */ + public function addPresenter($alias, $presenter) + { + $this->presenters[$alias] = $presenter; } /** @@ -59,50 +82,27 @@ final class ResponseManager implements ResponseManagerInterface * * @return PresenterInterface */ - public function createPresenter($alias) + private function createPresenter($alias) { if (!isset($this->presenters[$alias])) { - throw new \InvalidArgumentException(sprintf('[%s] presenter not supported.', $alias)); + throw new \InvalidArgumentException(sprintf('Presenter [%s] not supported.', $alias)); } - return $this->presenters[$alias]; - } + $presenter = $this->presenters[$alias]; - /** - * @param string $alias - * - * @return void - */ - public function addPresenter($alias, PresenterInterface $presenter) - { - $this->presenters[$alias] = $presenter; + return \is_callable($presenter) ? $presenter() : $presenter; } /** * @param Envelope[] $envelopes - * @param mixed[] $context + * @param mixed[] $context * * @return Response */ - private function filterResponse($envelopes, $context) + private function createResponse($envelopes, $context) { $response = new Response($envelopes, $context); - return $this->resourceManager->filterResponse($response); - } - - /** - * @param mixed[] $criteria - * - * @return Envelope[] - */ - private function getEnvelopes(array $criteria) - { - $envelopes = $this->storageManager->all(); - - $event = new FilterEvent($envelopes, $criteria); - $this->eventDispatcher->dispatch($event); - - return $event->getEnvelopes(); + return $this->resourceManager->buildResponse($response); } } diff --git a/src/Prime/Response/ResponseManagerInterface.php b/src/Prime/Response/ResponseManagerInterface.php old mode 100755 new mode 100644 index 8a432b0d..1088ef0f --- a/src/Prime/Response/ResponseManagerInterface.php +++ b/src/Prime/Response/ResponseManagerInterface.php @@ -1,15 +1,30 @@ + */ + namespace Flasher\Prime\Response; +use Flasher\Prime\Response\Presenter\PresenterInterface; + interface ResponseManagerInterface { /** * @param mixed[] $criteria - * @param string $presenter + * @param string $presenter * @param mixed[] $context * * @return mixed */ public function render(array $criteria = array(), $presenter = 'html', array $context = array()); + + /** + * @param string $alias + * @param callable|PresenterInterface $presenter + * + * @return void + */ + public function addPresenter($alias, $presenter); } diff --git a/src/Prime/Stamp/ContextStamp.php b/src/Prime/Stamp/ContextStamp.php new file mode 100644 index 00000000..758d8db5 --- /dev/null +++ b/src/Prime/Stamp/ContextStamp.php @@ -0,0 +1,40 @@ + + */ + +namespace Flasher\Prime\Stamp; + +final class ContextStamp implements StampInterface, PresentableStampInterface +{ + /** + * @var mixed[] + */ + private $context; + + /** + * @param mixed[] $context + */ + public function __construct(array $context) + { + $this->context = $context; + } + + /** + * @return mixed[] + */ + public function getContext() + { + return $this->context; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + return array('context' => $this->getContext()); + } +} diff --git a/src/Prime/Stamp/CreatedAtStamp.php b/src/Prime/Stamp/CreatedAtStamp.php index 087b8567..da176395 100644 --- a/src/Prime/Stamp/CreatedAtStamp.php +++ b/src/Prime/Stamp/CreatedAtStamp.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; use DateTime; @@ -19,7 +24,7 @@ final class CreatedAtStamp implements StampInterface, OrderableStampInterface, P private $format; /** - * @param string|null $format + * @param string|null $format * * @throws Exception */ @@ -38,9 +43,7 @@ final class CreatedAtStamp implements StampInterface, OrderableStampInterface, P } /** - * @param mixed $orderable - * - * @return int + * {@inheritdoc} */ public function compare($orderable) { @@ -51,10 +54,13 @@ final class CreatedAtStamp implements StampInterface, OrderableStampInterface, P return $this->createdAt->getTimestamp() - $orderable->createdAt->getTimestamp(); } + /** + * {@inheritdoc} + */ public function toArray() { - return array( - 'created_at' => $this->getCreatedAt()->format($this->format), - ); + $createdAt = $this->getCreatedAt(); + + return array('created_at' => $createdAt->format($this->format)); } } diff --git a/src/Prime/Stamp/DelayStamp.php b/src/Prime/Stamp/DelayStamp.php index 6900afd1..11c6724b 100644 --- a/src/Prime/Stamp/DelayStamp.php +++ b/src/Prime/Stamp/DelayStamp.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; final class DelayStamp implements StampInterface diff --git a/src/Prime/Stamp/HandlerStamp.php b/src/Prime/Stamp/HandlerStamp.php index 227c2e9e..3b4d9960 100644 --- a/src/Prime/Stamp/HandlerStamp.php +++ b/src/Prime/Stamp/HandlerStamp.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; final class HandlerStamp implements StampInterface, PresentableStampInterface @@ -25,10 +30,11 @@ final class HandlerStamp implements StampInterface, PresentableStampInterface return $this->handler; } + /** + * {@inheritdoc} + */ public function toArray() { - return array( - 'handler' => $this->getHandler(), - ); + return array('handler' => $this->getHandler()); } } diff --git a/src/Prime/Stamp/HopsStamp.php b/src/Prime/Stamp/HopsStamp.php index c9caea2d..0627a1d8 100644 --- a/src/Prime/Stamp/HopsStamp.php +++ b/src/Prime/Stamp/HopsStamp.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; final class HopsStamp implements StampInterface diff --git a/src/Prime/Stamp/OrderableStampInterface.php b/src/Prime/Stamp/OrderableStampInterface.php index 9c53b6e4..4a707a56 100644 --- a/src/Prime/Stamp/OrderableStampInterface.php +++ b/src/Prime/Stamp/OrderableStampInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; interface OrderableStampInterface diff --git a/src/Prime/Stamp/PresentableStampInterface.php b/src/Prime/Stamp/PresentableStampInterface.php index 682a05b8..515f3186 100644 --- a/src/Prime/Stamp/PresentableStampInterface.php +++ b/src/Prime/Stamp/PresentableStampInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; interface PresentableStampInterface diff --git a/src/Prime/Stamp/PriorityStamp.php b/src/Prime/Stamp/PriorityStamp.php index 63117298..ad73670d 100644 --- a/src/Prime/Stamp/PriorityStamp.php +++ b/src/Prime/Stamp/PriorityStamp.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; final class PriorityStamp implements StampInterface, OrderableStampInterface, PresentableStampInterface @@ -26,9 +31,7 @@ final class PriorityStamp implements StampInterface, OrderableStampInterface, Pr } /** - * @param mixed $orderable - * - * @return int + * {@inheritdoc} */ public function compare($orderable) { @@ -39,10 +42,11 @@ final class PriorityStamp implements StampInterface, OrderableStampInterface, Pr return $this->priority - $orderable->priority; } + /** + * {@inheritdoc} + */ public function toArray() { - return array( - 'priority' => $this->getPriority(), - ); + return array('priority' => $this->getPriority()); } } diff --git a/src/Prime/Stamp/StampInterface.php b/src/Prime/Stamp/StampInterface.php index 1788bc60..1076caf3 100644 --- a/src/Prime/Stamp/StampInterface.php +++ b/src/Prime/Stamp/StampInterface.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Stamp; interface StampInterface diff --git a/src/Prime/Stamp/TemplateStamp.php b/src/Prime/Stamp/TemplateStamp.php deleted file mode 100644 index 04eed1d7..00000000 --- a/src/Prime/Stamp/TemplateStamp.php +++ /dev/null @@ -1,34 +0,0 @@ -template = $template; - } - - /** - * @return string - */ - public function getTemplate() - { - return $this->template; - } - - public function toArray() - { - return array( - 'template' => $this->getTemplate(), - ); - } -} diff --git a/src/Prime/Stamp/UuidStamp.php b/src/Prime/Stamp/UuidStamp.php index 51fc90b7..eb31ac07 100644 --- a/src/Prime/Stamp/UuidStamp.php +++ b/src/Prime/Stamp/UuidStamp.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; final class UuidStamp implements StampInterface, PresentableStampInterface { @@ -30,21 +35,21 @@ final class UuidStamp implements StampInterface, PresentableStampInterface } /** - * @param Envelope[]|Envelope ...$envelopes + * @param Envelope[]|Envelope... $envelopes * * @return array */ public static function indexByUuid($envelopes) { - /** @var Envelope[] $envelopes */ - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); $map = array(); foreach ($envelopes as $envelope) { $uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp'); if (!$uuidStamp instanceof UuidStamp) { - continue; + $uuidStamp = new UuidStamp(spl_object_hash($envelope)); + $envelope->withStamp($uuidStamp); } $uuid = $uuidStamp->getUuid(); @@ -62,10 +67,11 @@ final class UuidStamp implements StampInterface, PresentableStampInterface return $this->uuid; } + /** + * {@inheritdoc} + */ public function toArray() { - return array( - 'uuid' => $this->getUuid(), - ); + return array('uuid' => $this->getUuid()); } } diff --git a/src/Prime/Stamp/ViewStamp.php b/src/Prime/Stamp/ViewStamp.php new file mode 100644 index 00000000..d53323aa --- /dev/null +++ b/src/Prime/Stamp/ViewStamp.php @@ -0,0 +1,40 @@ + + */ + +namespace Flasher\Prime\Stamp; + +final class ViewStamp implements StampInterface, PresentableStampInterface +{ + /** + * @var string + */ + private $view; + + /** + * @param string $template + */ + public function __construct($template) + { + $this->view = $template; + } + + /** + * @return string + */ + public function getView() + { + return $this->view; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + return array('view' => $this->getView()); + } +} diff --git a/src/Prime/Storage/ArrayStorage.php b/src/Prime/Storage/ArrayStorage.php deleted file mode 100644 index 8de7b476..00000000 --- a/src/Prime/Storage/ArrayStorage.php +++ /dev/null @@ -1,67 +0,0 @@ -envelopes; - } - - public function add($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $this->envelopes = array_merge($this->envelopes, $envelopes); - } - - public function update($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $map = UuidStamp::indexByUuid($envelopes); - - foreach ($this->envelopes as $index => $envelope) { - $uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp'); - if (!$uuidStamp instanceof UuidStamp) { - continue; - } - - $uuid = $uuidStamp->getUuid(); - if (!isset($map[$uuid])) { - continue; - } - - $this->envelopes[$index] = $map[$uuid]; - } - } - - public function remove($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $map = UuidStamp::indexByUuid($envelopes); - - $this->envelopes = array_filter($this->envelopes, function (Envelope $envelope) use ($map) { - $uuidStamp = $envelope->get('Flasher\Prime\Stamp\UuidStamp'); - if (!$uuidStamp instanceof UuidStamp) { - return false; - } - - $uuid = $uuidStamp->getUuid(); - - return !isset($map[$uuid]); - }); - } - - public function clear() - { - $this->envelopes = array(); - } -} diff --git a/src/Prime/Storage/Bag/ArrayBag.php b/src/Prime/Storage/Bag/ArrayBag.php new file mode 100644 index 00000000..70e96608 --- /dev/null +++ b/src/Prime/Storage/Bag/ArrayBag.php @@ -0,0 +1,34 @@ + + */ + +namespace Flasher\Prime\Storage\Bag; + +use Flasher\Prime\Notification\Envelope; + +final class ArrayBag implements BagInterface +{ + /** + * @var Envelope[] + */ + private $envelopes = array(); + + /** + * {@inheritDoc} + */ + public function get() + { + return $this->envelopes; + } + + /** + * {@inheritDoc} + */ + public function set(array $envelopes) + { + $this->envelopes = $envelopes; + } +} diff --git a/src/Prime/Storage/Bag/BagInterface.php b/src/Prime/Storage/Bag/BagInterface.php new file mode 100644 index 00000000..50707e40 --- /dev/null +++ b/src/Prime/Storage/Bag/BagInterface.php @@ -0,0 +1,25 @@ + + */ + +namespace Flasher\Prime\Storage\Bag; + +use Flasher\Prime\Notification\Envelope; + +interface BagInterface +{ + /** + * @return array + */ + public function get(); + + /** + * @param array $envelopes + * + * @return void + */ + public function set(array $envelopes); +} diff --git a/src/Prime/Storage/Bag/StaticBag.php b/src/Prime/Storage/Bag/StaticBag.php new file mode 100644 index 00000000..14de24fb --- /dev/null +++ b/src/Prime/Storage/Bag/StaticBag.php @@ -0,0 +1,34 @@ + + */ + +namespace Flasher\Prime\Storage\Bag; + +use Flasher\Prime\Notification\Envelope; + +final class StaticBag implements BagInterface +{ + /** + * @var Envelope[] + */ + private static $envelopes = array(); + + /** + * {@inheritDoc} + */ + public function get() + { + return self::$envelopes; + } + + /** + * {@inheritDoc} + */ + public function set(array $envelopes) + { + self::$envelopes = $envelopes; + } +} diff --git a/src/Prime/Storage/StorageBag.php b/src/Prime/Storage/StorageBag.php new file mode 100644 index 00000000..749d74f3 --- /dev/null +++ b/src/Prime/Storage/StorageBag.php @@ -0,0 +1,74 @@ + + */ + +namespace Flasher\Prime\Storage; + +use Flasher\Prime\Stamp\UuidStamp; +use Flasher\Prime\Storage\Bag\ArrayBag; +use Flasher\Prime\Storage\Bag\BagInterface; + +final class StorageBag implements StorageInterface +{ + /** + * @var BagInterface + */ + private $bag; + + public function __construct(BagInterface $bag = null) + { + $this->bag = null !== $bag && 'cli' !== \PHP_SAPI ? $bag : new ArrayBag(); + } + + /** + * {@inheritdoc} + */ + public function all() + { + return $this->bag->get(); + } + + /** + * {@inheritdoc} + */ + public function add($envelopes) + { + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); + $envelopes = UuidStamp::indexByUuid($envelopes); + + $this->bag->set(array_merge($this->all(), $envelopes)); + } + + /** + * {@inheritdoc} + */ + public function update($envelopes) + { + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); + $envelopes = UuidStamp::indexByUuid($envelopes); + + $this->bag->set(array_merge($this->all(), $envelopes)); + } + + /** + * {@inheritdoc} + */ + public function remove($envelopes) + { + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); + $envelopes = UuidStamp::indexByUuid($envelopes); + + $this->bag->set(array_diff_key($this->all(), $envelopes)); + } + + /** + * {@inheritdoc} + */ + public function clear() + { + $this->bag->set(array()); + } +} diff --git a/src/Prime/Storage/StorageInterface.php b/src/Prime/Storage/StorageInterface.php index 914d056c..12d92c1c 100644 --- a/src/Prime/Storage/StorageInterface.php +++ b/src/Prime/Storage/StorageInterface.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Storage; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; interface StorageInterface { @@ -23,19 +28,19 @@ interface StorageInterface * * @return void */ - public function remove($envelopes); - - /** - * Remove all notifications from the storage - * - * @return void - */ - public function clear(); + public function update($envelopes); /** * @param Envelope|Envelope[] $envelopes * * @return void */ - public function update($envelopes); + public function remove($envelopes); + + /** + * Remove all notifications from the storage. + * + * @return void + */ + public function clear(); } diff --git a/src/Prime/Storage/StorageManager.php b/src/Prime/Storage/StorageManager.php index 88697018..877a18dc 100644 --- a/src/Prime/Storage/StorageManager.php +++ b/src/Prime/Storage/StorageManager.php @@ -1,13 +1,20 @@ + */ + namespace Flasher\Prime\Storage; +use Flasher\Prime\EventDispatcher\Event\FilterEvent; use Flasher\Prime\EventDispatcher\Event\PersistEvent; use Flasher\Prime\EventDispatcher\Event\PostPersistEvent; use Flasher\Prime\EventDispatcher\Event\PostRemoveEvent; use Flasher\Prime\EventDispatcher\Event\PostUpdateEvent; use Flasher\Prime\EventDispatcher\Event\RemoveEvent; use Flasher\Prime\EventDispatcher\Event\UpdateEvent; +use Flasher\Prime\EventDispatcher\EventDispatcher; use Flasher\Prime\EventDispatcher\EventDispatcherInterface; final class StorageManager implements StorageManagerInterface @@ -22,20 +29,41 @@ final class StorageManager implements StorageManagerInterface */ private $eventDispatcher; - public function __construct(StorageInterface $storage, EventDispatcherInterface $eventDispatcher) + public function __construct(StorageInterface $storage = null, EventDispatcherInterface $eventDispatcher = null) { - $this->storage = $storage; - $this->eventDispatcher = $eventDispatcher; + $this->storage = $storage ?: new StorageBag(); + $this->eventDispatcher = $eventDispatcher ?: new EventDispatcher(); } + /** + * {@inheritdoc} + */ public function all() { return $this->storage->all(); } + /** + * {@inheritdoc} + */ + public function filter(array $criteria = array()) + { + $criteria['delay'] = 0; + // @phpstan-ignore-next-line + $criteria['hops']['min'] = 1; + + $event = new FilterEvent($this->all(), $criteria); + $this->eventDispatcher->dispatch($event); + + return $event->getEnvelopes(); + } + + /** + * {@inheritdoc} + */ public function add($envelopes) { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); $event = new PersistEvent($envelopes); $this->eventDispatcher->dispatch($event); @@ -46,9 +74,12 @@ final class StorageManager implements StorageManagerInterface $this->eventDispatcher->dispatch($event); } + /** + * {@inheritdoc} + */ public function update($envelopes) { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); $event = new UpdateEvent($envelopes); $this->eventDispatcher->dispatch($event); @@ -59,9 +90,12 @@ final class StorageManager implements StorageManagerInterface $this->eventDispatcher->dispatch($event); } + /** + * {@inheritdoc} + */ public function remove($envelopes) { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); + $envelopes = \is_array($envelopes) ? $envelopes : \func_get_args(); $event = new RemoveEvent($envelopes); $this->eventDispatcher->dispatch($event); @@ -73,6 +107,9 @@ final class StorageManager implements StorageManagerInterface $this->eventDispatcher->dispatch($event); } + /** + * {@inheritdoc} + */ public function clear() { $this->storage->clear(); diff --git a/src/Prime/Storage/StorageManagerInterface.php b/src/Prime/Storage/StorageManagerInterface.php index 59328ca8..86c678a4 100644 --- a/src/Prime/Storage/StorageManagerInterface.php +++ b/src/Prime/Storage/StorageManagerInterface.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Prime\Storage; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; interface StorageManagerInterface { @@ -11,6 +16,13 @@ interface StorageManagerInterface */ public function all(); + /** + * @param mixed[] $criteria + * + * @return Envelope[] + */ + public function filter(array $criteria = array()); + /** * @param Envelope|Envelope[] $envelopes * @@ -33,7 +45,7 @@ interface StorageManagerInterface public function remove($envelopes); /** - * remove All notifications from storage + * remove All notifications from storage. * * @return void */ diff --git a/src/Prime/Template/Engine.php b/src/Prime/Template/Engine.php index 32cc3e9c..157d459a 100644 --- a/src/Prime/Template/Engine.php +++ b/src/Prime/Template/Engine.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Prime\Template; final class Engine implements EngineInterface @@ -11,7 +16,7 @@ final class Engine implements EngineInterface extract($context, \EXTR_SKIP); if (!file_exists($name)) { - $name = __DIR__ . '/views/' . $name; + $name = __DIR__.'/views/'.$name; if (!file_exists($name)) { throw new \Exception(sprintf('Cannot find template "%s"', $name)); diff --git a/src/Prime/Template/EngineInterface.php b/src/Prime/Template/EngineInterface.php index 8d749056..c8ae5640 100644 --- a/src/Prime/Template/EngineInterface.php +++ b/src/Prime/Template/EngineInterface.php @@ -1,11 +1,16 @@ + */ + namespace Flasher\Prime\Template; interface EngineInterface { /** - * @param string $name + * @param string $name * @param array $context * * @return string diff --git a/src/Prime/Template/PHPTemplateEngine.php b/src/Prime/Template/PHPTemplateEngine.php new file mode 100644 index 00000000..de8ace05 --- /dev/null +++ b/src/Prime/Template/PHPTemplateEngine.php @@ -0,0 +1,30 @@ + + */ + +namespace Flasher\Prime\Template; + +final class PHPTemplateEngine implements TemplateEngineInterface +{ + /** + * {@inheritdoc} + */ + public function render($name, array $context = array()) + { + ob_start(); + + extract($context, \EXTR_SKIP); + + include $name; + + $output = ob_get_clean(); + if (false === $output) { + return ''; + } + + return ltrim($output); + } +} diff --git a/src/Prime/Template/TemplateEngineInterface.php b/src/Prime/Template/TemplateEngineInterface.php new file mode 100644 index 00000000..f386f6b7 --- /dev/null +++ b/src/Prime/Template/TemplateEngineInterface.php @@ -0,0 +1,19 @@ + + */ + +namespace Flasher\Prime\Template; + +interface TemplateEngineInterface +{ + /** + * @param string $name + * @param array $context + * + * @return string + */ + public function render($name, array $context = array()); +} diff --git a/src/Prime/Template/views/bootstrap.php b/src/Prime/Template/views/bootstrap.php deleted file mode 100644 index 60f55144..00000000 --- a/src/Prime/Template/views/bootstrap.php +++ /dev/null @@ -1,64 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $alertClass = 'alert-success'; - $progressBackgroundColor = '#155724'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $alertClass = 'alert-danger'; - $progressBackgroundColor = '#721c24'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $alertClass = 'alert-warning'; - $progressBackgroundColor = '#856404'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $alertClass = 'alert-info'; - $progressBackgroundColor = '#0c5460'; - $icon = ''; - break; -} -?> - -
- - - - - - - - - - - - -
- -
-
diff --git a/src/Prime/Template/views/tailwindcss.php b/src/Prime/Template/views/tailwindcss.php deleted file mode 100644 index 180fdd43..00000000 --- a/src/Prime/Template/views/tailwindcss.php +++ /dev/null @@ -1,68 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $textColor = 'text-green-600'; - $backgroundColor = 'bg-green-600'; - $progressBackgroundColor = 'bg-green-100'; - $borderColor = 'border-green-600'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $textColor = 'text-red-600'; - $backgroundColor = 'bg-red-600'; - $progressBackgroundColor = 'bg-red-100'; - $borderColor = 'border-red-600'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $textColor = 'text-yellow-600'; - $backgroundColor = 'bg-yellow-600'; - $progressBackgroundColor = 'bg-yellow-100'; - $borderColor = 'border-yellow-600'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $textColor = 'text-blue-600'; - $backgroundColor = 'bg-blue-600'; - $progressBackgroundColor = 'bg-blue-100'; - $borderColor = 'border-blue-600'; - $icon = ''; - break; -} -?> -
-
-
- -
-
-

- getTitle() ?: $title ?> -

-

- getMessage() ?> -

-
-
-
- -
-
diff --git a/src/Prime/Template/views/tailwindcss_bg.php b/src/Prime/Template/views/tailwindcss_bg.php deleted file mode 100644 index 16690571..00000000 --- a/src/Prime/Template/views/tailwindcss_bg.php +++ /dev/null @@ -1,69 +0,0 @@ -getNotification(); -if (!$notification instanceof Template) { - return; -} - -switch ($notification->getType()) { - case 'success': - $title = 'Success'; - $textColor = 'text-green-700'; - $backgroundColor = 'bg-green-50'; - $progressBackgroundColor = 'bg-green-200'; - $borderColor = 'border-green-600'; - $icon = ''; - break; - case 'error': - $title = 'Error'; - $textColor = 'text-red-700'; - $backgroundColor = 'bg-red-50'; - $progressBackgroundColor = 'bg-red-200'; - $borderColor = 'border-red-600'; - $icon = ''; - break; - case 'warning': - $title = 'Warning'; - $textColor = 'text-yellow-700'; - $backgroundColor = 'bg-yellow-50'; - $progressBackgroundColor = 'bg-yellow-200'; - $borderColor = 'border-yellow-600'; - $icon = ''; - break; - case 'info': - default: - $title = 'Info'; - $textColor = 'text-blue-700'; - $backgroundColor = 'bg-blue-50'; - $progressBackgroundColor = 'bg-blue-100'; - $borderColor = 'border-blue-600'; - $icon = ''; - break; -} -?> - -
-
-
- -
-
-

- getTitle() ?: $title ?> -

-

- getMessage() ?> -

-
-
-
- -
-
diff --git a/src/Prime/UPGRADING.md b/src/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Prime/composer.json b/src/Prime/composer.json index ca11b2b5..589d46bd 100644 --- a/src/Prime/composer.json +++ b/src/Prime/composer.json @@ -1,30 +1,14 @@ { "name": "php-flasher/flasher", - "description": "A powerful and flexible flash notifications system for PHP", + "description": "A powerful and flexible flash notification system for PHP", "type": "library", - "keywords": [ - "flasher", - "toastr", - "notify", - "notyf", - "noty", - "pnotify", - "sweet alert", - "flash", - "notifications", - "php", - "laravel", - "symfony", - "Lumen", - "messages", - "alerts" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["flasher", "toastr", "notify", "notyf", "noty", "pnotify", "sweet alert", "flash", "notifications", "php", "laravel", "symfony", "Lumen", "messages", "alerts"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], @@ -35,14 +19,11 @@ "autoload": { "psr-4": { "Flasher\\Prime\\": "" - }, - "files": [ - "helpers.php" - ] + } }, "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Prime/helpers.php b/src/Prime/helpers.php deleted file mode 100644 index f9e5bf35..00000000 --- a/src/Prime/helpers.php +++ /dev/null @@ -1,15 +0,0 @@ -
Thanks!" diff --git a/src/SweetAlert/Laravel/.gitignore b/src/SweetAlert/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/SweetAlert/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/SweetAlert/Laravel/CHANGELOG.md b/src/SweetAlert/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/SweetAlert/Laravel/CODE_OF_CONDUCT.md b/src/SweetAlert/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/SweetAlert/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/SweetAlert/Laravel/Facade/SweetAlert.php b/src/SweetAlert/Laravel/Facade/SweetAlert.php index c357bdc2..dcce6876 100644 --- a/src/SweetAlert/Laravel/Facade/SweetAlert.php +++ b/src/SweetAlert/Laravel/Facade/SweetAlert.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\SweetAlert\Laravel\Facade; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; use Flasher\SweetAlert\Prime\SweetAlertBuilder; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static SweetAlertBuilder addError(string $message, array $options = array()) * @method static SweetAlertBuilder addWarning(string $message, array $options = array()) * @method static SweetAlertBuilder addInfo(string $message, array $options = array()) - * @method static SweetAlertBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static SweetAlertBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static SweetAlertBuilder flash(StampInterface[] $stamps = array()) * @method static SweetAlertBuilder type(string $type, string $message = null, array $options = array()) * @method static SweetAlertBuilder message(string $message) @@ -32,7 +37,6 @@ use Illuminate\Support\Facades\Facade; * @method static SweetAlertBuilder withStamp(StampInterface $stamp) * @method static SweetAlertBuilder handler(string $handler) * @method static Envelope getEnvelope() - * * @method static SweetAlertBuilder question(string $message = null, array $options = array()) * @method static SweetAlertBuilder title(string $title) * @method static SweetAlertBuilder titleText(string $titleText) @@ -107,6 +111,6 @@ class SweetAlert extends Facade { protected static function getFacadeAccessor() { - return 'flasher.sweet_alert'; + return 'flasher.sweetalert'; } } diff --git a/src/SweetAlert/Laravel/FlasherSweetAlertServiceProvider.php b/src/SweetAlert/Laravel/FlasherSweetAlertServiceProvider.php index ca747523..d804ec0a 100644 --- a/src/SweetAlert/Laravel/FlasherSweetAlertServiceProvider.php +++ b/src/SweetAlert/Laravel/FlasherSweetAlertServiceProvider.php @@ -1,55 +1,53 @@ + */ + namespace Flasher\SweetAlert\Laravel; -use Flasher\SweetAlert\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Prime\EventDispatcher\EventDispatcherInterface; +use Flasher\SweetAlert\Prime\SweetAlertPlugin; +use Livewire\LivewireManager; final class FlasherSweetAlertServiceProvider extends ServiceProvider { - public function boot() + /** + * {@inheritDoc} + */ + protected function createPlugin() { - $manager = new ServiceProviderManager($this); - $manager->boot(); + return new SweetAlertPlugin(); } /** - * Register the service provider. + * {@inheritDoc} */ - public function register() + protected function afterBoot() { - $manager = new ServiceProviderManager($this); - $manager->register(); + $this->registerLivewireListener(); } /** - * Get the services provided by the provider. - * - * @return string[] + * @return void */ - public function provides() + private function registerLivewireListener() { - return array( - 'flasher.sweet_alert', - ); - } + if (!$this->app->bound('livewire')) { + return; + } - /** - * @return Container - */ - public function getApplication() - { - return $this->app; - } + $livewire = $this->app->make('livewire'); + if (!$livewire instanceof LivewireManager) { + return; + } - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } + $this->app->extend('flasher.event_dispatcher', function (EventDispatcherInterface $dispatcher) { + $dispatcher->addSubscriber(new LivewireListener()); - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); + return $dispatcher; + }); } } diff --git a/src/SweetAlert/Laravel/LivewireListener.php b/src/SweetAlert/Laravel/LivewireListener.php new file mode 100644 index 00000000..d713ae51 --- /dev/null +++ b/src/SweetAlert/Laravel/LivewireListener.php @@ -0,0 +1,71 @@ + + */ + +namespace Flasher\SweetAlert\Laravel; + +use Flasher\Prime\EventDispatcher\Event\ResponseEvent; +use Flasher\Prime\EventDispatcher\EventListener\EventSubscriberInterface; + +final class LivewireListener implements EventSubscriberInterface +{ + /** + * @return void + */ + public function __invoke(ResponseEvent $event) + { + if ('html' !== $event->getPresenter()) { + return; + } + + $response = $event->getResponse() ?: ''; + if (!\is_string($response)) { + return; + } + + if (false === strripos($response, ' +JAVASCRIPT; + + $event->setResponse($response); + } + + public static function getSubscribedEvents() + { + return 'Flasher\Prime\EventDispatcher\Event\ResponseEvent'; + } +} diff --git a/src/SweetAlert/Laravel/README.md b/src/SweetAlert/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/SweetAlert/Laravel/README.md +++ b/src/SweetAlert/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/SweetAlert/Laravel/Resources/config/config.php b/src/SweetAlert/Laravel/Resources/config/config.php deleted file mode 100644 index 19d1056f..00000000 --- a/src/SweetAlert/Laravel/Resources/config/config.php +++ /dev/null @@ -1,13 +0,0 @@ - array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-sweet-alert@0.2.1/dist/flasher-sweet-alert.min.js', - ), - 'styles' => array(), - 'options' => array( - 'timer' => 5000, - 'timerProgressBar' => true, - ), -); diff --git a/src/SweetAlert/Laravel/Resources/functions/sweetAlert.php b/src/SweetAlert/Laravel/Resources/functions/sweetAlert.php deleted file mode 100644 index b0137db2..00000000 --- a/src/SweetAlert/Laravel/Resources/functions/sweetAlert.php +++ /dev/null @@ -1,21 +0,0 @@ -addFlash($type, $message, $options); - } -} diff --git a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php b/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index bf7e2a88..00000000 --- a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,74 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherSweetAlertServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_sweet_alert.php'), - ), 'flasher-config'); - } - - public function register(FlasherSweetAlertServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_sweet_alert'); - $this->appendToFlasherConfig(); - - $this->registerServices(); - } - - public function registerServices() - { - $this->app->singleton('flasher.sweet_alert', function (Container $app) { - return new SweetAlertFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.sweet_alert', 'Flasher\SweetAlert\Prime\SweetAlertFactory'); - - $this->app->extend('flasher', function (Flasher $manager, Container $app) { - $manager->addFactory('sweet_alert', $app['flasher.sweet_alert']); - - return $manager; - }); - - $this->app->extend('flasher.resource_manager', function (ResourceManager $resourceManager) { - ResourceManagerHelper::process($resourceManager, 'sweet_alert'); - - return $resourceManager; - }); - } - - public function appendToFlasherConfig() - { - $notifyConfig = $this->app['config']->get('flasher.adapters.sweet_alert', array()); - - $sweetAlertConfig = $this->app['config']->get('flasher_sweet_alert', array()); - - $this->app['config']->set('flasher.adapters.sweet_alert', array_merge($sweetAlertConfig, $notifyConfig)); - } -} diff --git a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel4.php b/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index 92a59800..00000000 --- a/src/SweetAlert/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,41 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherSweetAlertServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-sweet_alert-laravel', - 'flasher_sweet_alert', - flasher_path(__DIR__ . '/../../Resources') - ); - $this->appendToFlasherConfig(); - } - - public function register(FlasherSweetAlertServiceProvider $provider) - { - $this->registerServices(); - } - - public function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher::config.adapters.sweet_alert', array()); - - $sweetAlertConfig = $this->app['config']->get('flasher_sweet_alert::config', array()); - - $this->app['config']->set( - 'flasher::config.adapters.sweet_alert', - array_merge($sweetAlertConfig, $flasherConfig) - ); - } -} diff --git a/src/SweetAlert/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/SweetAlert/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index bb1998a4..00000000 --- a/src/SweetAlert/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/SweetAlert/Laravel/UPGRADING.md b/src/SweetAlert/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/SweetAlert/Laravel/composer.json b/src/SweetAlert/Laravel/composer.json index a28e53a1..beef7ccd 100644 --- a/src/SweetAlert/Laravel/composer.json +++ b/src/SweetAlert/Laravel/composer.json @@ -1,44 +1,29 @@ { - "name": "php-flasher/flasher-sweet-alert-laravel", + "name": "php-flasher/flasher-sweetalert-laravel", "description": "PHP Flasher Laravel adapter for Sweet Alert 2", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex", - "sweet alert" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex", "sweet alert"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-sweet-alert": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-sweetalert": "^1.0" }, "autoload": { "psr-4": { "Flasher\\SweetAlert\\Laravel\\": "" }, "files": [ - "Resources/functions/sweetAlert.php" + "sweetalert.php" ] }, "extra": { @@ -54,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/SweetAlert/Laravel/sweetalert.php b/src/SweetAlert/Laravel/sweetalert.php new file mode 100644 index 00000000..08b718db --- /dev/null +++ b/src/SweetAlert/Laravel/sweetalert.php @@ -0,0 +1,31 @@ + + */ + +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\NotificationInterface; +use Flasher\SweetAlert\Prime\SweetAlertFactory; + +if (!function_exists('sweetalert')) { + /** + * @param string $message + * @param string $type + * @param array $options + * + * @return Envelope|SweetAlertFactory + */ + function sweetalert($message = null, $type = NotificationInterface::SUCCESS, array $options = array()) + { + /** @var SweetAlertFactory $factory */ + $factory = app('flasher.sweetalert'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->addFlash($type, $message, $options); + } +} diff --git a/src/SweetAlert/Prime/.editorconfig b/src/SweetAlert/Prime/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/SweetAlert/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/SweetAlert/Prime/.gitattributes b/src/SweetAlert/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/SweetAlert/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/SweetAlert/Prime/.github/CONTRIBUTING.md b/src/SweetAlert/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/SweetAlert/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/SweetAlert/Prime/.github/FUNDING.yml b/src/SweetAlert/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/SweetAlert/Prime/.github/FUNDING.yml +++ b/src/SweetAlert/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/SweetAlert/Prime/.github/SECURITY.md b/src/SweetAlert/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/SweetAlert/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/SweetAlert/Prime/.github/dependabot.yml b/src/SweetAlert/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/SweetAlert/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/SweetAlert/Prime/.github/workflows/auto_closer.yaml b/src/SweetAlert/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/SweetAlert/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/SweetAlert/Prime/.github/workflows/close-pull-request.yml b/src/SweetAlert/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/SweetAlert/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/SweetAlert/Prime/.gitignore b/src/SweetAlert/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/SweetAlert/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/SweetAlert/Prime/.phpstorm.meta.php b/src/SweetAlert/Prime/.phpstorm.meta.php index eaf2e26d..bac67f31 100644 --- a/src/SweetAlert/Prime/.phpstorm.meta.php +++ b/src/SweetAlert/Prime/.phpstorm.meta.php @@ -12,9 +12,9 @@ expectedArguments(\Flasher\SweetAlert\Prime\SweetAlertBuilder::grow(), 0, 'row', expectedArguments(\Flasher\SweetAlert\Prime\SweetAlertBuilder::customClass(), 0, 'container', 'popup', 'header', 'title', 'closeButton', 'icon', 'image', 'content', 'input', 'inputLabel', 'validationMessage', 'actions', 'confirmButton', 'denyButton', 'cancelButton', 'loader', 'footer'); override(\Flasher\Prime\FlasherInterface::create(), map([ - 'sweet_alert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class + 'sweetalert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class ])); override(\Flasher\Prime\FlasherInterface::using(), map([ - 'sweet_alert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class + 'sweetalert' => \Flasher\SweetAlert\Prime\SweetAlertFactory::class ])); diff --git a/src/SweetAlert/Prime/CHANGELOG.md b/src/SweetAlert/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/SweetAlert/Prime/CODE_OF_CONDUCT.md b/src/SweetAlert/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/SweetAlert/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/SweetAlert/Prime/README.md b/src/SweetAlert/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/SweetAlert/Prime/README.md +++ b/src/SweetAlert/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/SweetAlert/Prime/SweetAlert.php b/src/SweetAlert/Prime/SweetAlert.php deleted file mode 100644 index d8c09ac5..00000000 --- a/src/SweetAlert/Prime/SweetAlert.php +++ /dev/null @@ -1,9 +0,0 @@ - + */ + namespace Flasher\SweetAlert\Prime; use Flasher\Prime\Notification\NotificationBuilder; +/** + * @SuppressWarnings(PHPMD.TooManyMethods) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + * @SuppressWarnings(PHPMD.ExcessiveClassLength) + * @SuppressWarnings(PHPMD.ExcessivePublicCount) + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + */ final class SweetAlertBuilder extends NotificationBuilder { public function type($type, $message = null, array $options = array()) @@ -14,9 +26,10 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Display a question typed alert message + * Display a question typed alert message. * - * @param string $message + * @param string $message + * @param array $options * * @return SweetAlertBuilder */ @@ -30,7 +43,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $title * - * @return $this + * @return static */ public function title($title) { @@ -44,7 +57,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $titleText * - * @return $this + * @return static */ public function titleText($titleText) { @@ -61,7 +74,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $html * - * @return $this + * @return static */ public function html($html) { @@ -75,7 +88,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $text * - * @return $this + * @return static */ public function text($text) { @@ -98,7 +111,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $icon * - * @return $this + * @return static */ public function icon($icon) { @@ -112,7 +125,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $iconColor * - * @return $this + * @return static */ public function iconColor($iconColor) { @@ -126,7 +139,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $iconHtml * - * @return $this + * @return static */ public function iconHtml($iconHtml) { @@ -136,17 +149,17 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * CSS classes for animations when showing a popup (fade in) + * CSS classes for animations when showing a popup (fade in). * * @param string $showClass * @param string $value * - * @return $this + * @return static */ public function showClass($showClass, $value) { $option = $this->getEnvelope()->getOption('showClass', array()); - $option[$showClass] = $value; + $option[$showClass] = $value; // @phpstan-ignore-line $this->option('showClass', $option); @@ -154,17 +167,17 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * CSS classes for animations when hiding a popup (fade out) + * CSS classes for animations when hiding a popup (fade out). * * @param string $hideClass * @param string $value * - * @return $this + * @return static */ public function hideClass($hideClass, $value) { $option = $this->getEnvelope()->getOption('hideClass', array()); - $option[$hideClass] = $value; + $option[$hideClass] = $value; // @phpstan-ignore-line $this->option('hideClass', $option); @@ -176,7 +189,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $footer * - * @return $this + * @return static */ public function footer($footer) { @@ -189,9 +202,9 @@ final class SweetAlertBuilder extends NotificationBuilder * Whether or not SweetAlert2 should show a full screen click-to-dismiss backdrop. Can be either a boolean or a * string which will be assigned to the CSS background property. * - * @param string|bool $backdrop + * @param bool|string $backdrop * - * @return $this + * @return static */ public function backdrop($backdrop = true) { @@ -208,7 +221,7 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $position * @param bool $showConfirmButton * - * @return $this + * @return static */ public function toast($toast = true, $position = 'top-end', $showConfirmButton = false) { @@ -228,7 +241,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $target * - * @return $this + * @return static */ public function target($target) { @@ -243,7 +256,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $input * - * @return $this + * @return static */ public function input($input) { @@ -257,7 +270,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $width * - * @return $this + * @return static */ public function width($width) { @@ -271,7 +284,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $padding * - * @return $this + * @return static */ public function padding($padding) { @@ -285,7 +298,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $background * - * @return $this + * @return static */ public function background($background) { @@ -300,7 +313,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $position * - * @return $this + * @return static */ public function position($position) { @@ -315,7 +328,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool|string $grow * - * @return $this + * @return static */ public function grow($grow) { @@ -325,17 +338,17 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * A custom CSS class for the popup + * A custom CSS class for the popup. * * @param string $customClass * @param string $value * - * @return $this + * @return static */ public function customClass($customClass, $value) { $option = $this->getEnvelope()->getOption('customClass', array()); - $option[$customClass] = $value; + $option[$customClass] = $value; // @phpstan-ignore-line $this->option('customClass', $option); @@ -347,7 +360,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param int $timer * - * @return $this + * @return static */ public function timer($timer) { @@ -362,7 +375,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $timerProgressBar * - * @return $this + * @return static */ public function timerProgressBar($timerProgressBar = true) { @@ -377,7 +390,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $heightAuto * - * @return $this + * @return static */ public function heightAuto($heightAuto = true) { @@ -392,7 +405,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool|string $allowOutsideClick * - * @return $this + * @return static */ public function allowOutsideClick($allowOutsideClick = true) { @@ -407,7 +420,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool|string $allowEscapeKey * - * @return $this + * @return static */ public function allowEscapeKey($allowEscapeKey = true) { @@ -422,7 +435,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool|string $allowEnterKey * - * @return $this + * @return static */ public function allowEnterKey($allowEnterKey = true) { @@ -434,13 +447,13 @@ final class SweetAlertBuilder extends NotificationBuilder /** * If set to false, SweetAlert2 will allow keydown events propagation to the document. * - * @param bool $stopKeydownPropagation + * @param bool $stop * - * @return $this + * @return static */ - public function stopKeydownPropagation($stopKeydownPropagation = true) + public function stopKeydownPropagation($stop = true) { - $this->option('stopKeydownPropagation', $stopKeydownPropagation); + $this->option('stopKeydownPropagation', $stop); return $this; } @@ -450,13 +463,13 @@ final class SweetAlertBuilder extends NotificationBuilder * false which means when a user hits Esc, both SweetAlert2 and Bootstrap modals will be closed. Set * keydownListenerCapture to true to fix that behavior. * - * @param bool $keydownListenerCapture + * @param bool $capture * - * @return $this + * @return static */ - public function keydownListenerCapture($keydownListenerCapture = true) + public function keydownListenerCapture($capture = true) { - $this->option('keydownListenerCapture', $keydownListenerCapture); + $this->option('keydownListenerCapture', $capture); return $this; } @@ -469,7 +482,9 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $confirmButtonColor * @param string $confirmButtonAriaLabel * - * @return $this + * @return static + * + * @SuppressWarnings(PHPMD.LongVariable) */ public function showConfirmButton( $showConfirmButton = true, @@ -497,12 +512,12 @@ final class SweetAlertBuilder extends NotificationBuilder /** * If set to true, a "Deny"-button will be shown. It can be useful when you want a popup with 3 buttons. * - * @param bool $showDenyButton + * @param bool $showDenyButton * @param string $denyButtonText * @param string $denyButtonColor * @param string $denyButtonAriaLabel * - * @return $this + * @return static */ public function showDenyButton( $showDenyButton = true, @@ -530,12 +545,14 @@ final class SweetAlertBuilder extends NotificationBuilder /** * If set to true, a "Cancel"-button will be shown, which the user can click on to dismiss the modal. * - * @param bool $showCancelButton + * @param bool $showCancelButton * @param string $cancelButtonText * @param string $cancelButtonColor * @param string $cancelButtonAriaLabel * - * @return $this + * @return static + * + * @SuppressWarnings(PHPMD.LongVariable) */ public function showCancelButton( $showCancelButton = true, @@ -567,7 +584,9 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $confirmButtonColor * @param string $confirmButtonAriaLabel * - * @return $this + * @return static + * + * @SuppressWarnings(PHPMD.LongVariable) */ public function confirmButtonText($confirmButtonText, $confirmButtonColor = null, $confirmButtonAriaLabel = null) { @@ -591,7 +610,7 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $denyButtonColor * @param string $denyButtonAriaLabel * - * @return $this + * @return static */ public function denyButtonText($denyButtonText, $denyButtonColor = null, $denyButtonAriaLabel = null) { @@ -615,7 +634,9 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $cancelButtonColor * @param string $cancelButtonAriaLabel * - * @return $this + * @return static + * + * @SuppressWarnings(PHPMD.LongVariable) */ public function cancelButtonText($cancelButtonText, $cancelButtonColor = null, $cancelButtonAriaLabel = null) { @@ -633,11 +654,11 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Use this to change the background color of the "Confirm"-button. The default color is #3085d6 + * Use this to change the background color of the "Confirm"-button. The default color is #3085d6. * * @param string $confirmButtonColor * - * @return $this + * @return static */ public function confirmButtonColor($confirmButtonColor) { @@ -647,11 +668,11 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Use this to change the background color of the "Deny"-button. The default color is #dd6b55 + * Use this to change the background color of the "Deny"-button. The default color is #dd6b55. * * @param string $denyButtonColor * - * @return $this + * @return static */ public function denyButtonColor($denyButtonColor) { @@ -661,11 +682,11 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Use this to change the background color of the "Cancel"-button. The default color is #aaa + * Use this to change the background color of the "Cancel"-button. The default color is #aaa. * * @param string $cancelButtonColor * - * @return $this + * @return static */ public function cancelButtonColor($cancelButtonColor) { @@ -677,13 +698,13 @@ final class SweetAlertBuilder extends NotificationBuilder /** * Use this to change the aria-label for the "Confirm"-button. * - * @param string $confirmButtonAriaLabel + * @param string $label * - * @return $this + * @return static */ - public function confirmButtonAriaLabel($confirmButtonAriaLabel) + public function confirmButtonAriaLabel($label) { - $this->option('confirmButtonAriaLabel', $confirmButtonAriaLabel); + $this->option('confirmButtonAriaLabel', $label); return $this; } @@ -693,7 +714,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $denyButtonAriaLabel * - * @return $this + * @return static */ public function denyButtonAriaLabel($denyButtonAriaLabel) { @@ -705,13 +726,13 @@ final class SweetAlertBuilder extends NotificationBuilder /** * Use this to change the aria-label for the "Cancel"-button. * - * @param string $cancelButtonAriaLabel + * @param string $label * - * @return $this + * @return static */ - public function cancelButtonAriaLabel($cancelButtonAriaLabel) + public function cancelButtonAriaLabel($label) { - $this->option('cancelButtonAriaLabel', $cancelButtonAriaLabel); + $this->option('cancelButtonAriaLabel', $label); return $this; } @@ -722,7 +743,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $buttonsStyling * - * @return $this + * @return static */ public function buttonsStyling($buttonsStyling = true) { @@ -736,7 +757,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $reverseButtons * - * @return $this + * @return static */ public function reverseButtons($reverseButtons = true) { @@ -750,7 +771,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $focusConfirm * - * @return $this + * @return static */ public function focusConfirm($focusConfirm = true) { @@ -764,7 +785,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $focusDeny * - * @return $this + * @return static */ public function focusDeny($focusDeny = true) { @@ -778,7 +799,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $focusCancel * - * @return $this + * @return static */ public function focusCancel($focusCancel = true) { @@ -792,7 +813,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $showCloseButton * - * @return $this + * @return static */ public function showCloseButton($showCloseButton = true) { @@ -806,7 +827,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $closeButtonHtml * - * @return $this + * @return static */ public function closeButtonHtml($closeButtonHtml) { @@ -820,7 +841,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $closeButtonAriaLabel * - * @return $this + * @return static */ public function closeButtonAriaLabel($closeButtonAriaLabel) { @@ -834,7 +855,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $loaderHtml * - * @return $this + * @return static */ public function loaderHtml($loaderHtml) { @@ -849,7 +870,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $showLoaderOnConfirm * - * @return $this + * @return static */ public function showLoaderOnConfirm($showLoaderOnConfirm = true) { @@ -859,11 +880,11 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Set to false to disable body padding adjustment when the page scrollbar gets hidden while the popup is shown + * Set to false to disable body padding adjustment when the page scrollbar gets hidden while the popup is shown. * * @param bool $scrollbarPadding * - * @return $this + * @return static */ public function scrollbarPadding($scrollbarPadding = true) { @@ -877,11 +898,11 @@ final class SweetAlertBuilder extends NotificationBuilder * Returned (or resolved) value can be: * - false to prevent a popup from closing * - anything else to pass that value as the result.value of Swal.fire() - * - undefined to keep the default result.value + * - undefined to keep the default result.value. * * @param bool|string $preConfirm * - * @return $this + * @return static */ public function preConfirm($preConfirm) { @@ -895,11 +916,11 @@ final class SweetAlertBuilder extends NotificationBuilder * Returned (or resolved) value can be: * - false to prevent a popup from closing * - anything else to pass that value as the result.value of Swal.fire() - * - undefined to keep the default result.value + * - undefined to keep the default result.value. * * @param string $preDeny * - * @return $this + * @return static */ public function preDeny($preDeny) { @@ -912,13 +933,13 @@ final class SweetAlertBuilder extends NotificationBuilder * If you want to return the input value as result.value when denying the popup, set to true. Otherwise, the denying * will set result.value to false. * - * @param bool $returnInputValueOnDeny + * @param bool $inputValue * - * @return $this + * @return static */ - public function returnInputValueOnDeny($returnInputValueOnDeny = true) + public function returnInputValueOnDeny($inputValue = true) { - $this->option('returnInputValueOnDeny', $returnInputValueOnDeny); + $this->option('returnInputValueOnDeny', $inputValue); return $this; } @@ -929,9 +950,9 @@ final class SweetAlertBuilder extends NotificationBuilder * @param string $imageUrl * @param int $imageWidth * @param int $imageHeight - * @param string $imageAlt + * @param string $imageAlt * - * @return $this + * @return static */ public function imageUrl($imageUrl, $imageWidth = null, $imageHeight = null, $imageAlt = null) { @@ -957,7 +978,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param int $imageWidth * - * @return $this + * @return static */ public function imageWidth($imageWidth) { @@ -971,7 +992,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param int $imageHeight * - * @return $this + * @return static */ public function imageHeight($imageHeight) { @@ -985,7 +1006,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $imageAlt * - * @return $this + * @return static */ public function imageAlt($imageAlt) { @@ -1002,7 +1023,7 @@ final class SweetAlertBuilder extends NotificationBuilder * @param int $imageHeight * @param string $imageAlt * - * @return $this + * @return static */ public function image($title, $text, $imageUrl, $imageWidth = 400, $imageHeight = 200, $imageAlt = null) { @@ -1022,7 +1043,7 @@ final class SweetAlertBuilder extends NotificationBuilder } /** - * Shortcut to add and flush an image + * Shortcut to add and flush an image. * * @param string $title * @param string $text @@ -1031,7 +1052,7 @@ final class SweetAlertBuilder extends NotificationBuilder * @param int $imageHeight * @param string $imageAlt * - * @return \Flasher\Prime\Envelope + * @return \Flasher\Prime\Notification\Envelope */ public function addImage($title, $text, $imageUrl, $imageWidth = 400, $imageHeight = 200, $imageAlt = null) { @@ -1045,7 +1066,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $inputLabel * - * @return $this + * @return static */ public function inputLabel($inputLabel) { @@ -1059,7 +1080,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $inputPlaceholder * - * @return $this + * @return static */ public function inputPlaceholder($inputPlaceholder) { @@ -1076,7 +1097,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $inputValue * - * @return $this + * @return static */ public function inputValue($inputValue) { @@ -1093,7 +1114,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $inputOptions * - * @return $this + * @return static */ public function inputOptions($inputOptions) { @@ -1108,7 +1129,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param bool $inputAutoTrim * - * @return $this + * @return static */ public function inputAutoTrim($inputAutoTrim = true) { @@ -1123,7 +1144,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $inputAttributes * - * @return $this + * @return static */ public function inputAttributes($inputAttributes) { @@ -1136,11 +1157,11 @@ final class SweetAlertBuilder extends NotificationBuilder * Validator for input field, may be async (Promise-returning) or sync. * Returned (or resolved) value can be: * - a falsy value (undefined, null, false) for indicating success - * - a string value (error message) for indicating failure + * - a string value (error message) for indicating failure. * * @param string $inputValidator * - * @return $this + * @return static */ public function inputValidator($inputValidator) { @@ -1154,7 +1175,7 @@ final class SweetAlertBuilder extends NotificationBuilder * * @param string $validationMessage * - * @return $this + * @return static */ public function validationMessage($validationMessage) { diff --git a/src/SweetAlert/Prime/SweetAlertFactory.php b/src/SweetAlert/Prime/SweetAlertFactory.php index a75cebf4..6af1525d 100644 --- a/src/SweetAlert/Prime/SweetAlertFactory.php +++ b/src/SweetAlert/Prime/SweetAlertFactory.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\SweetAlert\Prime; use Flasher\Prime\Factory\NotificationFactory; +use Flasher\Prime\Notification\Notification; /** * @mixin SweetAlertBuilder @@ -11,6 +17,6 @@ final class SweetAlertFactory extends NotificationFactory { public function createNotificationBuilder() { - return new SweetAlertBuilder($this->getStorageManager(), new SweetAlert(), 'sweet_alert'); + return new SweetAlertBuilder($this->getStorageManager(), new Notification(), 'sweetalert'); } } diff --git a/src/SweetAlert/Prime/SweetAlertPlugin.php b/src/SweetAlert/Prime/SweetAlertPlugin.php new file mode 100644 index 00000000..1b38dad1 --- /dev/null +++ b/src/SweetAlert/Prime/SweetAlertPlugin.php @@ -0,0 +1,29 @@ + + */ + +namespace Flasher\SweetAlert\Prime; + +use Flasher\Prime\Plugin\Plugin; + +class SweetAlertPlugin extends Plugin +{ + public function getAlias() + { + return 'sweetalert'; + } + + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array( + 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', + 'https://cdn.jsdelivr.net/npm/@flasher/flasher-sweetalert@1.0.7/dist/flasher-sweetalert.min.js', + ); + } +} diff --git a/src/SweetAlert/Prime/UPGRADING.md b/src/SweetAlert/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/SweetAlert/Prime/composer.json b/src/SweetAlert/Prime/composer.json index 5d3358bc..9a8a081d 100644 --- a/src/SweetAlert/Prime/composer.json +++ b/src/SweetAlert/Prime/composer.json @@ -1,52 +1,30 @@ { - "name": "php-flasher/flasher-sweet-alert", + "name": "php-flasher/flasher-sweetalert", "description": "PHP Flasher adapter for Sweet Alert 2", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "sweetAlert" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "sweetAlert"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { "Flasher\\SweetAlert\\Prime\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "autoload-dev": { - "psr-4": { - "Flasher\\SweetAlert\\Prime\\Tests\\": "Tests/" } }, "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/SweetAlert/Symfony/.editorconfig b/src/SweetAlert/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/SweetAlert/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/SweetAlert/Symfony/.gitattributes b/src/SweetAlert/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/SweetAlert/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/SweetAlert/Symfony/.github/CONTRIBUTING.md b/src/SweetAlert/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/SweetAlert/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/SweetAlert/Symfony/.github/FUNDING.yml b/src/SweetAlert/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/SweetAlert/Symfony/.github/FUNDING.yml +++ b/src/SweetAlert/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/SweetAlert/Symfony/.github/SECURITY.md b/src/SweetAlert/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/SweetAlert/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/SweetAlert/Symfony/.github/dependabot.yml b/src/SweetAlert/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/SweetAlert/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/SweetAlert/Symfony/.github/workflows/auto_closer.yaml b/src/SweetAlert/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/SweetAlert/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/SweetAlert/Symfony/.github/workflows/close-pull-request.yml b/src/SweetAlert/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/SweetAlert/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/SweetAlert/Symfony/.gitignore b/src/SweetAlert/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/SweetAlert/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/SweetAlert/Symfony/.phpstorm.meta.php b/src/SweetAlert/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/SweetAlert/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ -getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher_sweet_alert'); - } - - $rootNode - ->children() - ->arrayNode('scripts') - ->prototype('scalar')->end() - ->defaultValue(array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-sweet-alert@0.2.1/dist/flasher-sweet-alert.min.js', - )) - ->end() - ->arrayNode('styles') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('options') - ->ignoreExtraKeys(false) - ->prototype('variable')->end() - ->defaultValue(array( - 'timer' => 5000, - 'timerProgressBar' => true, - )) - ->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtension.php b/src/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtension.php deleted file mode 100644 index a0418f9d..00000000 --- a/src/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtension.php +++ /dev/null @@ -1,23 +0,0 @@ -load('services.php'); - } - - public function getConfigurationClass() - { - return new Configuration(); - } -} diff --git a/src/SweetAlert/Symfony/FlasherSweetAlertSymfonyBundle.php b/src/SweetAlert/Symfony/FlasherSweetAlertSymfonyBundle.php index ea3db3e9..8625b0c2 100644 --- a/src/SweetAlert/Symfony/FlasherSweetAlertSymfonyBundle.php +++ b/src/SweetAlert/Symfony/FlasherSweetAlertSymfonyBundle.php @@ -1,21 +1,22 @@ + */ + namespace Flasher\SweetAlert\Symfony; -use Flasher\SweetAlert\Symfony\DependencyInjection\FlasherSweetAlertExtension; -use Flasher\Symfony\Bridge\FlasherBundle; -use Flasher\Symfony\DependencyInjection\Compiler\ResourceCompilerPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Flasher\SweetAlert\Prime\SweetAlertPlugin; +use Flasher\Symfony\Support\Bundle; -class FlasherSweetAlertSymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle +class FlasherSweetAlertSymfonyBundle extends Bundle // Symfony\Component\HttpKernel\Bundle\Bundle { - protected function flasherBuild(ContainerBuilder $container) + /** + * {@inheritDoc} + */ + protected function createPlugin() { - $container->addCompilerPass(new ResourceCompilerPass($this->getFlasherContainerExtension())); - } - - protected function getFlasherContainerExtension() - { - return new FlasherSweetAlertExtension(); + return new SweetAlertPlugin(); } } diff --git a/src/SweetAlert/Symfony/README.md b/src/SweetAlert/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/SweetAlert/Symfony/README.md +++ b/src/SweetAlert/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/SweetAlert/Symfony/Resources/config/services.php b/src/SweetAlert/Symfony/Resources/config/services.php deleted file mode 100644 index b3044198..00000000 --- a/src/SweetAlert/Symfony/Resources/config/services.php +++ /dev/null @@ -1,21 +0,0 @@ -setClass('Flasher\SweetAlert\Prime\SweetAlertFactory') - ->addTag('flasher.factory', array('alias' => 'sweet_alert')); - -$container->setDefinition('flasher.sweet_alert', $definition); - -if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\SweetAlert\Prime\SweetAlertFactory', 'flasher.sweet_alert'); -} diff --git a/src/SweetAlert/Symfony/UPGRADING.md b/src/SweetAlert/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/SweetAlert/Symfony/composer.json b/src/SweetAlert/Symfony/composer.json index 7618fa16..3edfc541 100644 --- a/src/SweetAlert/Symfony/composer.json +++ b/src/SweetAlert/Symfony/composer.json @@ -1,37 +1,22 @@ { - "name": "php-flasher/flasher-sweet-alert-symfony", + "name": "php-flasher/flasher-sweetalert-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Sweet Alert 2", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "sweet-alert ", - "toastr", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "sweetalert ", "toastr", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-sweet-alert": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-sweetalert": "^1.0" }, "autoload": { "psr-4": { @@ -41,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Symfony/.editorconfig b/src/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Symfony/.gitattributes b/src/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Symfony/.github/CONTRIBUTING.md b/src/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Symfony/.github/FUNDING.yml b/src/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Symfony/.github/FUNDING.yml +++ b/src/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Symfony/.github/SECURITY.md b/src/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Symfony/.github/dependabot.yml b/src/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Symfony/.github/workflows/auto_closer.yaml b/src/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Symfony/.github/workflows/close-pull-request.yml b/src/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Symfony/.gitignore b/src/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Symfony/.phpstorm.meta.php b/src/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ - + */ + namespace Flasher\Symfony\Bridge; use Symfony\Component\HttpKernel\Kernel; @@ -15,6 +20,9 @@ final class Bridge } /** + * @param string $version + * @param string $operator + * * @return bool */ public static function versionCompare($version, $operator = '=') diff --git a/src/Symfony/Bridge/DependencyInjection/FlasherExtension.php b/src/Symfony/Bridge/DependencyInjection/FlasherExtension.php new file mode 100644 index 00000000..2eec4ad4 --- /dev/null +++ b/src/Symfony/Bridge/DependencyInjection/FlasherExtension.php @@ -0,0 +1,27 @@ + + */ + +namespace Flasher\Symfony\Bridge\DependencyInjection; + +use Flasher\Symfony\Bridge\Bridge; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +$class = Bridge::isLegacy() + ? 'Flasher\Symfony\Bridge\Legacy\DependencyInjection\FlasherExtension' + : 'Flasher\Symfony\Bridge\Typed\DependencyInjection\FlasherExtension'; + +class_alias($class, 'Flasher\Symfony\Bridge\DependencyInjection\FlasherExtension'); + +if (false) { /** @phpstan-ignore-line */ + abstract class FlasherExtension extends Extension + { + /** + * @return string + */ + abstract protected function getFlasherAlias(); + } +} diff --git a/src/Symfony/Bridge/FlasherBundle.php b/src/Symfony/Bridge/FlasherBundle.php index a8808c5b..64b47342 100644 --- a/src/Symfony/Bridge/FlasherBundle.php +++ b/src/Symfony/Bridge/FlasherBundle.php @@ -1,13 +1,34 @@ + */ + namespace Flasher\Symfony\Bridge; -if (Bridge::isLegacy()) { - class_alias('Flasher\Symfony\Bridge\Legacy\FlasherBundle', 'Flasher\Symfony\Bridge\FlasherBundle'); -} else { - class_alias('Flasher\Symfony\Bridge\Typed\FlasherBundle', 'Flasher\Symfony\Bridge\FlasherBundle'); -} +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -if (false) { - abstract class FlasherBundle {} +$class = Bridge::isLegacy() + ? 'Flasher\Symfony\Bridge\Legacy\FlasherBundle' + : 'Flasher\Symfony\Bridge\Typed\FlasherBundle'; + +class_alias($class, 'Flasher\Symfony\Bridge\FlasherBundle'); + +if (false) { /** @phpstan-ignore-line */ + abstract class FlasherBundle + { + /** + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + abstract protected function flasherBuild(ContainerBuilder $container); + + /** + * @return ?ExtensionInterface + */ + abstract protected function getFlasherContainerExtension(); + } } diff --git a/src/Symfony/Bridge/Legacy/DependencyInjection/FlasherExtension.php b/src/Symfony/Bridge/Legacy/DependencyInjection/FlasherExtension.php new file mode 100644 index 00000000..77ccd90a --- /dev/null +++ b/src/Symfony/Bridge/Legacy/DependencyInjection/FlasherExtension.php @@ -0,0 +1,26 @@ + + */ + +namespace Flasher\Symfony\Bridge\Legacy\DependencyInjection; + +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +abstract class FlasherExtension extends Extension +{ + /** + * {@inheritdoc} + */ + public function getAlias() + { + return $this->getFlasherAlias(); + } + + /** + * @return string + */ + abstract protected function getFlasherAlias(); +} diff --git a/src/Symfony/Bridge/Legacy/FlasherBundle.php b/src/Symfony/Bridge/Legacy/FlasherBundle.php index f008e4dc..c71c846b 100644 --- a/src/Symfony/Bridge/Legacy/FlasherBundle.php +++ b/src/Symfony/Bridge/Legacy/FlasherBundle.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Symfony\Bridge\Legacy; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -8,8 +13,26 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; abstract class FlasherBundle extends Bundle { + /** + * {@inheritdoc} + */ + public function build(ContainerBuilder $container) + { + $this->flasherBuild($container); + } + + /** + * {@inheritdoc} + */ + public function getContainerExtension() + { + return $this->getFlasherContainerExtension(); + } + /** * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function flasherBuild(ContainerBuilder $container) { @@ -19,14 +42,4 @@ abstract class FlasherBundle extends Bundle * @return ?ExtensionInterface */ abstract protected function getFlasherContainerExtension(); - - public function build(ContainerBuilder $container) - { - $this->flasherBuild($container); - } - - public function getContainerExtension() - { - return $this->getFlasherContainerExtension(); - } } diff --git a/src/Symfony/Bridge/Legacy/Twig/FlasherTwigExtension.php b/src/Symfony/Bridge/Legacy/Twig/FlasherTwigExtension.php index c55d41ba..e1bd20e1 100644 --- a/src/Symfony/Bridge/Legacy/Twig/FlasherTwigExtension.php +++ b/src/Symfony/Bridge/Legacy/Twig/FlasherTwigExtension.php @@ -1,18 +1,27 @@ + */ + namespace Flasher\Symfony\Bridge\Legacy\Twig; use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; abstract class FlasherTwigExtension extends AbstractExtension { /** - * @return array + * {@inheritdoc} */ - abstract protected function getFlasherFunctions(); - public function getFunctions() { return $this->getFlasherFunctions(); } + + /** + * @return TwigFunction[] + */ + abstract protected function getFlasherFunctions(); } diff --git a/src/Symfony/Bridge/Twig/FlasherTwigExtension.php b/src/Symfony/Bridge/Twig/FlasherTwigExtension.php index 3d50a187..7d3e6c0d 100644 --- a/src/Symfony/Bridge/Twig/FlasherTwigExtension.php +++ b/src/Symfony/Bridge/Twig/FlasherTwigExtension.php @@ -1,15 +1,27 @@ + */ + namespace Flasher\Symfony\Bridge\Twig; use Flasher\Symfony\Bridge\Bridge; +use Twig\TwigFunction; -if (Bridge::isLegacy()) { - class_alias('Flasher\Symfony\Bridge\Legacy\Twig\FlasherTwigExtension', 'Flasher\Symfony\Bridge\Twig\FlasherTwigExtension'); -} else { - class_alias('Flasher\Symfony\Bridge\Typed\Twig\FlasherTwigExtension', 'Flasher\Symfony\Bridge\Twig\FlasherTwigExtension'); -} +$class = Bridge::isLegacy() + ? 'Flasher\Symfony\Bridge\Legacy\Twig\FlasherTwigExtension' + : 'Flasher\Symfony\Bridge\Typed\Twig\FlasherTwigExtension'; -if (false) { - abstract class FlasherTwigExtension {} +class_alias($class, 'Flasher\Symfony\Bridge\Twig\FlasherTwigExtension'); + +if (false) { /** @phpstan-ignore-line */ + abstract class FlasherTwigExtension + { + /** + * @return TwigFunction[] + */ + abstract protected function getFlasherFunctions(); + } } diff --git a/src/Symfony/Bridge/Typed/DependencyInjection/FlasherExtension.php b/src/Symfony/Bridge/Typed/DependencyInjection/FlasherExtension.php new file mode 100644 index 00000000..d0fc1bba --- /dev/null +++ b/src/Symfony/Bridge/Typed/DependencyInjection/FlasherExtension.php @@ -0,0 +1,26 @@ + + */ + +namespace Flasher\Symfony\Bridge\Typed\DependencyInjection; + +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +abstract class FlasherExtension extends Extension +{ + /** + * {@inheritdoc} + */ + public function getAlias(): string + { + return $this->getFlasherAlias(); + } + + /** + * @return string + */ + abstract protected function getFlasherAlias(); +} diff --git a/src/Symfony/Bridge/Typed/FlasherBundle.php b/src/Symfony/Bridge/Typed/FlasherBundle.php index 5e4adcbe..cd768e4e 100644 --- a/src/Symfony/Bridge/Typed/FlasherBundle.php +++ b/src/Symfony/Bridge/Typed/FlasherBundle.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Symfony\Bridge\Typed; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -8,8 +13,26 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; abstract class FlasherBundle extends Bundle { + /** + * {@inheritdoc} + */ + public function build(ContainerBuilder $container) + { + $this->flasherBuild($container); + } + + /** + * {@inheritdoc} + */ + public function getContainerExtension(): ?ExtensionInterface + { + return $this->getFlasherContainerExtension(); + } + /** * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function flasherBuild(ContainerBuilder $container) { @@ -19,14 +42,4 @@ abstract class FlasherBundle extends Bundle * @return ?ExtensionInterface */ abstract protected function getFlasherContainerExtension(); - - public function build(ContainerBuilder $container) - { - $this->flasherBuild($container); - } - - public function getContainerExtension(): ?ExtensionInterface - { - return $this->getFlasherContainerExtension(); - } } diff --git a/src/Symfony/Bridge/Typed/Twig/FlasherTwigExtension.php b/src/Symfony/Bridge/Typed/Twig/FlasherTwigExtension.php index ea2c247d..a71547d6 100644 --- a/src/Symfony/Bridge/Typed/Twig/FlasherTwigExtension.php +++ b/src/Symfony/Bridge/Typed/Twig/FlasherTwigExtension.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Symfony\Bridge\Typed\Twig; use Twig\Extension\AbstractExtension; @@ -7,12 +12,15 @@ use Twig\Extension\AbstractExtension; abstract class FlasherTwigExtension extends AbstractExtension { /** - * @return array + * {@inheritdoc} */ - abstract protected function getFlasherFunctions(); - public function getFunctions(): array { return $this->getFlasherFunctions(); } + + /** + * @return array + */ + abstract protected function getFlasherFunctions(); } diff --git a/src/Symfony/CHANGELOG.md b/src/Symfony/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Symfony/CODE_OF_CONDUCT.md b/src/Symfony/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Symfony/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPass.php index 96715381..1efdfebc 100644 --- a/src/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPass.php @@ -1,25 +1,34 @@ + */ + namespace Flasher\Symfony\DependencyInjection\Compiler; -use Flasher\Prime\EventDispatcher\EventDispatcherInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; +/** + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ final class EventSubscriberCompilerPass implements CompilerPassInterface { + /** + * @return void + */ public function process(ContainerBuilder $container) { if (!$container->has('flasher.event_dispatcher')) { return; } - /** @var EventDispatcherInterface $flasherBus */ - $eventDispatcher = $container->findDefinition('flasher.event_dispatcher'); + $definition = $container->findDefinition('flasher.event_dispatcher'); foreach ($container->findTaggedServiceIds('flasher.event_subscriber') as $id => $tags) { - $eventDispatcher->addMethodCall('addSubscriber', array(new Reference($id))); + $definition->addMethodCall('addSubscriber', array(new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php index 748ecf0a..dd11d1c1 100644 --- a/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/FactoryCompilerPass.php @@ -1,26 +1,32 @@ + */ + namespace Flasher\Symfony\DependencyInjection\Compiler; -use Flasher\Prime\Flasher; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; final class FactoryCompilerPass implements CompilerPassInterface { + /** + * @return void + */ public function process(ContainerBuilder $container) { if (!$container->has('flasher')) { return; } - /** @var Flasher $manager */ - $manager = $container->findDefinition('flasher'); + $definition = $container->findDefinition('flasher'); foreach ($container->findTaggedServiceIds('flasher.factory') as $id => $tags) { foreach ($tags as $attributes) { - $manager->addMethodCall('addFactory', array($attributes['alias'], new Reference($id))); + $definition->addMethodCall('addFactory', array($attributes['alias'], new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php old mode 100755 new mode 100644 index d04d8bd4..915253bc --- a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php @@ -1,26 +1,32 @@ + */ + namespace Flasher\Symfony\DependencyInjection\Compiler; -use Flasher\Prime\Flasher; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; final class PresenterCompilerPass implements CompilerPassInterface { + /** + * @return void + */ public function process(ContainerBuilder $container) { if (!$container->has('flasher.response_manager')) { return; } - /** @var Flasher $manager */ - $manager = $container->findDefinition('flasher.response_manager'); + $definition = $container->findDefinition('flasher.response_manager'); foreach ($container->findTaggedServiceIds('flasher.presenter') as $id => $tags) { foreach ($tags as $attributes) { - $manager->addMethodCall('addPresenter', array($attributes['alias'], new Reference($id))); + $definition->addMethodCall('addPresenter', array($attributes['alias'], new Reference($id))); } } } diff --git a/src/Symfony/DependencyInjection/Compiler/ResourceCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/ResourceCompilerPass.php deleted file mode 100644 index c56d085e..00000000 --- a/src/Symfony/DependencyInjection/Compiler/ResourceCompilerPass.php +++ /dev/null @@ -1,75 +0,0 @@ -extension = $extension; - } - - public function process(ContainerBuilder $container) - { - $configs = $container->getExtensionConfig($this->extension->getAlias()); - $config = $this->processConfiguration($this->extension->getConfigurationClass(), $configs); - - $responseManager = $container->getDefinition('flasher.resource_manager'); - $responseManager->addMethodCall('addScripts', array($this->getHandlerAlias(), $this->getScripts($config))); - $responseManager->addMethodCall('addStyles', array($this->getHandlerAlias(), $this->getStyles($config))); - $responseManager->addMethodCall('addOptions', array($this->getHandlerAlias(), $this->getOptions($config))); - } - - protected function processConfiguration(ConfigurationInterface $configuration, array $configs) - { - $processor = new Processor(); - - return $processor->processConfiguration($configuration, $configs); - } - - /** - * @return string - */ - protected function getHandlerAlias() - { - return str_replace('flasher_', '', $this->extension->getAlias()); - } - - /** - * @param array $config - * - * @return array - */ - protected function getScripts($config) - { - return isset($config['scripts']) ? $config['scripts'] : array(); - } - - /** - * @param array $config - * - * @return array - */ - protected function getStyles($config) - { - return isset($config['styles']) ? $config['styles'] : array(); - } - - /** - * @param array $config - * - * @return array - */ - protected function getOptions($config) - { - return isset($config['options']) ? $config['options'] : array(); - } -} diff --git a/src/Symfony/DependencyInjection/Compiler/SessionCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/SessionCompilerPass.php deleted file mode 100644 index 47b8d6ad..00000000 --- a/src/Symfony/DependencyInjection/Compiler/SessionCompilerPass.php +++ /dev/null @@ -1,32 +0,0 @@ -has('flasher.storage')) { - return; - } - - $storage = $container->getDefinition('flasher.storage'); - - if (null !== $storage->getArgument(0)) { - return; - } - - if ($container->has('request_stack')) { - $storage->replaceArgument(0, new Reference('request_stack')); - return; - } - - if (null === $storage->getArgument(0) && $container->has('session')) { - $storage->replaceArgument(0, new Reference('session')); - } - } -} diff --git a/src/Symfony/DependencyInjection/Configuration.php b/src/Symfony/DependencyInjection/Configuration.php old mode 100755 new mode 100644 index e7e8df10..4fc63e0d --- a/src/Symfony/DependencyInjection/Configuration.php +++ b/src/Symfony/DependencyInjection/Configuration.php @@ -1,8 +1,14 @@ + */ + namespace Flasher\Symfony\DependencyInjection; -use Flasher\Symfony\Bridge\Bridge; +use Flasher\Prime\Plugin\FlasherPlugin; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -13,100 +19,68 @@ final class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder('flasher'); + $plugin = new FlasherPlugin(); - if (\method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher'); - } + $treeBuilder = new TreeBuilder($plugin->getName()); + + $rootNode = method_exists($treeBuilder, 'getRootNode') + ? $treeBuilder->getRootNode() + : $treeBuilder->root($plugin->getName()); // @phpstan-ignore-line $rootNode ->children() ->scalarNode('default') ->cannotBeEmpty() - ->defaultValue('template') + ->defaultValue($plugin->getDefault()) ->end() ->scalarNode('root_script') - ->defaultValue('https://cdn.jsdelivr.net/npm/@flasher/flasher@0.7.1/dist/flasher.min.js') + ->defaultValue($plugin->getRootScript()) ->end() - ->arrayNode('root_scripts') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('template_factory') - ->addDefaultsIfNotSet() + ->arrayNode('themes') + ->ignoreExtraKeys() + ->prototype('variable')->end() ->children() - ->scalarNode('default') + ->scalarNode('view') ->isRequired() ->cannotBeEmpty() - ->defaultValue('tailwindcss') - ->end() - ->arrayNode('templates') - ->ignoreExtraKeys() - ->prototype('variable')->end() - ->children() - ->scalarNode('view') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->arrayNode('styles')->end() - ->arrayNode('scripts')->end() - ->arrayNode('options')->end() - ->end() - ->defaultValue(array( - 'tailwindcss' => array( - 'view' => Configuration::getTemplate('tailwindcss.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'tailwindcss_bg' => array( - 'view' => Configuration::getTemplate('tailwindcss_bg.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'bootstrap' => array( - 'view' => Configuration::getTemplate('bootstrap.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css', - ), - ), - )) ->end() + ->arrayNode('styles')->end() + ->arrayNode('scripts')->end() + ->arrayNode('options')->end() ->end() ->end() - ->booleanNode('auto_create_from_session') - ->defaultValue(true) - ->end() - ->arrayNode('types_mapping') - ->prototype('variable')->end() - ->defaultValue(array( - 'success' => array('success'), - 'error' => array('error', 'danger'), - 'warning' => array('warning', 'alarm'), - 'info' => array('info', 'notice', 'alert'), - )) - ->end() ->end() ; + $this->addFlashBagSection($rootNode, $plugin); + return $treeBuilder; } /** - * @param $template string - * - * @return string + * @return void */ - public static function getTemplate($template) + private function addFlashBagSection(ArrayNodeDefinition $rootNode, FlasherPlugin $plugin) { - return Bridge::versionCompare('2.2', '<') - ? 'FlasherSymfonyBundle::' . $template - : '@FlasherSymfony/' . $template; + $rootNode + ->children() + ->arrayNode('flash_bag') + ->canBeUnset() + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->always(function ($v) use ($plugin) { + return $plugin->normalizeFlashBagConfig($v); + }) + ->end() + ->children() + ->booleanNode('enabled')->defaultTrue()->end() + ->arrayNode('mapping') + ->prototype('variable')->end() + ->defaultValue($plugin->getFlashBagMapping()) + ->end() + ->end() + ->end() + ->end() + ; } } diff --git a/src/Symfony/DependencyInjection/FlasherExtension.php b/src/Symfony/DependencyInjection/FlasherExtension.php index 1df9d64d..5be2377e 100644 --- a/src/Symfony/DependencyInjection/FlasherExtension.php +++ b/src/Symfony/DependencyInjection/FlasherExtension.php @@ -1,71 +1,63 @@ + */ + namespace Flasher\Symfony\DependencyInjection; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; final class FlasherExtension extends Extension { + /** + * @param array> $configs + * + * @return void + */ public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.php'); - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); + $configs = $this->processConfiguration(new Configuration(), $configs); - $this->registerFlasherConfiguration($config, $container); - $this->registerTemplateFactoriesConfigurations($config, $container); - $this->registerResourceManagerConfiguration($config, $container); - $this->registerServicesForAutoConfiguration($container); + $this->registerFlasherConfiguration($configs, $container); + $this->registerSessionListener($configs, $container, $loader); } - public function registerFlasherConfiguration(array $config, ContainerBuilder $container) + /** + * @param array> $configs + * + * @return void + */ + private function registerFlasherConfiguration(array $configs, ContainerBuilder $container) { - $configuration = $container->getDefinition('flasher.config'); - $configuration->replaceArgument(0, $config); + $config = $container->getDefinition('flasher.config'); + $config->replaceArgument(0, $configs); + + $flasher = $container->getDefinition('flasher'); + $flasher->replaceArgument(0, $configs['default']); // @phpstan-ignore-line } - public function registerTemplateFactoriesConfigurations(array $config, ContainerBuilder $container) + /** + * @param array{flash_bag?: array{enabled: bool, mapping: array}} $configs + * + * @return void + */ + private function registerSessionListener(array $configs, ContainerBuilder $container, Loader\PhpFileLoader $loader) { - foreach ($config['template_factory']['templates'] as $template => $options) { - $container - ->register('flasher.template.'.$template, 'Flasher\Prime\Factory\TemplateFactory') - ->addArgument(new Reference('flasher.storage_manager')) - ->addMethodCall('setHandler', array('template.'.$template)) - ->addTag('flasher.factory', array('alias' => 'template.'.$template)); - } - } - - public function registerResourceManagerConfiguration(array $config, ContainerBuilder $container) - { - $responseManager = $container->getDefinition('flasher.resource_manager'); - foreach ($config['template_factory']['templates'] as $template => $factory) { - if (isset($factory['scripts'])) { - $responseManager->addMethodCall('addScripts', array('template.' . $template, $factory['scripts'])); - } - if (isset($factory['styles'])) { - $responseManager->addMethodCall('addStyles', array('template.' . $template, $factory['styles'])); - } - if (isset($factory['options'])) { - $responseManager->addMethodCall('addOptions', array('template.' . $template, $factory['options'])); - } - } - } - - public function registerServicesForAutoConfiguration(ContainerBuilder $container) - { - if (!method_exists($container, 'registerForAutoconfiguration')) { + if (!isset($configs['flash_bag']['enabled']) || true !== $configs['flash_bag']['enabled']) { return; } - $container - ->registerForAutoconfiguration('Flasher\Prime\EventDispatcher\EventDispatcherInterface') - ->addTag('flasher.event_subscriber') - ; + $loader->load('session_listener.php'); + + $listener = $container->getDefinition('flasher.session_listener'); + $listener->replaceArgument(1, $configs['flash_bag']['mapping']); } } diff --git a/src/Symfony/DependencyInjection/FlasherExtensionInterface.php b/src/Symfony/DependencyInjection/FlasherExtensionInterface.php deleted file mode 100644 index a20dd062..00000000 --- a/src/Symfony/DependencyInjection/FlasherExtensionInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - + */ + namespace Flasher\Symfony\EventListener; -use Flasher\Prime\Config\ConfigInterface; use Flasher\Prime\FlasherInterface; -use Flasher\Prime\Response\ResponseManagerInterface; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Flasher\Prime\Response\Presenter\HtmlPresenter; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpKernel\Event\ResponseEvent; final class SessionListener { - /** - * @var ConfigInterface - */ - private $config; - /** * @var FlasherInterface */ private $flasher; /** - * @var ResponseManagerInterface + * @var array */ - private $responseManager; + private $mapping; - public function __construct( - ConfigInterface $config, - FlasherInterface $flasher, - ResponseManagerInterface $responseManager - ) { - $this->config = $config; + /** + * @param array $mapping + */ + public function __construct(FlasherInterface $flasher, array $mapping = array()) + { $this->flasher = $flasher; - $this->responseManager = $responseManager; + $this->mapping = $this->flatMapping($mapping); } /** - * @param ResponseEvent|FilterResponseEvent $event + * @param ResponseEvent $event + * + * @return void */ public function onKernelResponse($event) { $request = $event->getRequest(); - if (!$this->isMainRequest($event) - || $request->isXmlHttpRequest() - || true !== $this->config->get('auto_create_from_session')) { + if (!$this->isMainRequest($event) || $request->isXmlHttpRequest() || !$request->hasSession()) { return; } $response = $event->getResponse(); - - $mapping = $this->typesMapping(); - - $readyToRender = false; - - if (!$request->hasSession()) { + $content = $response->getContent() ?: ''; + $insertPlaceHolder = HtmlPresenter::FLASHER_FLASH_BAG_PLACE_HOLDER; + $insertPosition = strripos($content, $insertPlaceHolder); + if (false === $insertPosition) { return; } - foreach ($request->getSession()->getFlashBag()->all() as $type => $messages) { - if (!isset($mapping[$type])) { + $readyToRender = false; + + /** @var Session $session */ + $session = $request->getSession(); + foreach ($session->getFlashBag()->all() as $type => $messages) { + if (!isset($this->mapping[$type])) { continue; } foreach ($messages as $message) { - $this->flasher->addFlash($mapping[$type], $message); + $this->flasher->addFlash($this->mapping[$type], $message); + $readyToRender = true; } - - $readyToRender = true; } if (false === $readyToRender) { return; } - $htmlResponse = $this->responseManager->render(array(), 'html'); + $htmlResponse = $this->flasher->render(array(), 'html', array('envelopes_only' => true)); if (empty($htmlResponse)) { return; } - $content = $response->getContent(); - $pos = strripos($content, ''); - $content = substr($content, 0, $pos).$htmlResponse.substr($content, $pos); + $content = substr($content, 0, $insertPosition).$htmlResponse.substr($content, $insertPosition + \strlen($insertPlaceHolder)); $response->setContent($content); } /** - * @return array + * @param array $mapping + * + * @return array */ - private function typesMapping() + private function flatMapping(array $mapping) { - $mapping = array(); + $flatMapping = array(); - foreach ($this->config->get('types_mapping', array()) as $type => $aliases) { - if (is_int($type) && is_string($aliases)) { - $type = $aliases; - } - - foreach ((array) $aliases as $alias) { - $mapping[$alias] = $type; + foreach ($mapping as $type => $aliases) { + foreach ($aliases as $alias) { + $flatMapping[$alias] = $type; } } - return $mapping; + return $flatMapping; } /** - * @param ResponseEvent|FilterResponseEvent $event + * @param ResponseEvent $event + * + * @return bool */ private function isMainRequest($event) { - if (method_exists($event, 'isMasterRequest')) { - return $event->isMasterRequest(); - } - if (method_exists($event, 'isMainRequest')) { return $event->isMainRequest(); } + if (method_exists($event, 'isMasterRequest')) { // @phpstan-ignore-line + return $event->isMasterRequest(); + } + return 1 === $event->getRequestType(); } } diff --git a/src/Symfony/FlasherSymfonyBundle.php b/src/Symfony/FlasherSymfonyBundle.php index 8af59c50..3821c65e 100644 --- a/src/Symfony/FlasherSymfonyBundle.php +++ b/src/Symfony/FlasherSymfonyBundle.php @@ -1,25 +1,34 @@ + */ + namespace Flasher\Symfony; use Flasher\Symfony\Bridge\FlasherBundle; use Flasher\Symfony\DependencyInjection\Compiler\EventSubscriberCompilerPass; use Flasher\Symfony\DependencyInjection\Compiler\FactoryCompilerPass; use Flasher\Symfony\DependencyInjection\Compiler\PresenterCompilerPass; -use Flasher\Symfony\DependencyInjection\Compiler\SessionCompilerPass; use Flasher\Symfony\DependencyInjection\FlasherExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; class FlasherSymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle { + /** + * {@inheritdoc} + */ protected function flasherBuild(ContainerBuilder $container) { $container->addCompilerPass(new FactoryCompilerPass()); $container->addCompilerPass(new EventSubscriberCompilerPass()); $container->addCompilerPass(new PresenterCompilerPass()); - $container->addCompilerPass(new SessionCompilerPass()); } + /** + * {@inheritdoc} + */ protected function getFlasherContainerExtension() { return new FlasherExtension(); diff --git a/src/Symfony/README.md b/src/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Symfony/README.md +++ b/src/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Symfony/Resources/config/services.php b/src/Symfony/Resources/config/services.php index 8de7c45e..cb8bb876 100644 --- a/src/Symfony/Resources/config/services.php +++ b/src/Symfony/Resources/config/services.php @@ -1,103 +1,71 @@ + */ -$container - ->register('flasher.config', 'Flasher\Prime\Config\Config') +use Flasher\Symfony\Bridge\Bridge; +use Symfony\Component\DependencyInjection\Reference; + +if (!isset($container)) { + return; +} + +$container->register('flasher.config', 'Flasher\Prime\Config\Config') + ->setPublic(false) ->addArgument(array()); -$container - ->register('flasher.storage', 'Flasher\Symfony\Storage\Storage') - ->addArgument(null); +$storage = Bridge::versionCompare('5.3', '>=') + ? new Reference('request_stack') + : new Reference('session'); -$container - ->register('flasher.event_dispatcher', 'Flasher\Prime\EventDispatcher\EventDispatcher'); +$container->register('flasher.storage_bag', 'Flasher\Symfony\Storage\SessionBag') + ->setPublic(false) + ->addArgument($storage); -$container - ->register('flasher.storage_manager', 'Flasher\Prime\Storage\StorageManager') +$container->register('flasher.storage', 'Flasher\Prime\Storage\StorageBag') + ->setPublic(false) + ->addArgument(new Reference('flasher.storage_bag')); + +$container->register('flasher.event_dispatcher', 'Flasher\Prime\EventDispatcher\EventDispatcher') + ->setPublic(false); + +$container->register('flasher.storage_manager', 'Flasher\Prime\Storage\StorageManager') + ->setPublic(false) ->addArgument(new Reference('flasher.storage')) ->addArgument(new Reference('flasher.event_dispatcher')); -$container - ->register('flasher.template', 'Flasher\Prime\Factory\TemplateFactory') - ->addArgument( new Reference('flasher.storage_manager')) - ->addTag('flasher.factory', array('alias' => 'template')); - -$container - ->register('flasher.filter', 'Flasher\Prime\Filter\Filter'); - -$container - ->register('flasher.event_listener.filter_listener', 'Flasher\Prime\EventDispatcher\EventListener\FilterListener') - ->addArgument(new Reference('flasher.filter')) - ->addTag('flasher.event_subscriber'); - -$container - ->register('flasher.event_listener.post_flush_listener', 'Flasher\Prime\EventDispatcher\EventListener\RemoveListener') - ->addTag('flasher.event_subscriber'); - -$container - ->register('flasher.event_listener.stamps_listener', 'Flasher\Prime\EventDispatcher\EventListener\StampsListener') - ->addTag('flasher.event_subscriber'); - -$container - ->register('flasher.twig.extension', 'Flasher\Symfony\Twig\FlasherTwigExtension') - ->addArgument(new Reference('flasher.response_manager')) +$container->register('flasher.twig.extension', 'Flasher\Symfony\Twig\FlasherTwigExtension') + ->setPublic(false) + ->addArgument(new Reference('flasher')) ->addTag('twig.extension', array()); -$container - ->register('flasher.resource_manager', 'Flasher\Prime\Response\Resource\ResourceManager') +$container->register('flasher.template_engine', 'Flasher\Symfony\Template\TwigTemplateEngine') + ->setPublic(false) + ->addArgument(new Reference('twig')); + +$container->register('flasher.resource_manager', 'Flasher\Prime\Response\Resource\ResourceManager') + ->setPublic(false) ->addArgument(new Reference('flasher.config')) ->addArgument(new Reference('flasher.template_engine')); -$container - ->register('flasher.response_manager', 'Flasher\Prime\Response\ResponseManager') - ->addArgument(new Reference('flasher.storage_manager')) - ->addArgument(new Reference('flasher.event_dispatcher')) - ->addArgument(new Reference('flasher.resource_manager')); +$container->register('flasher.response_manager', 'Flasher\Prime\Response\ResponseManager') + ->setPublic(false) + ->addArgument(new Reference('flasher.resource_manager')) + ->addArgument(new Reference('flasher.storage_manager')); -$container - ->register('flasher.presenter.html', 'Flasher\Prime\Response\Presenter\HtmlPresenter') - ->addTag('flasher.presenter', array('alias' => 'html')); - -$container - ->register('flasher.presenter.array', 'Flasher\Prime\Response\Presenter\ArrayPresenter') - ->addTag('flasher.presenter', array('alias' => 'array')); - -$container - ->register('flasher.session_listener', 'Flasher\Symfony\EventListener\SessionListener') - ->addArgument(new Reference('flasher.config')) - ->addArgument(new Reference('flasher')) +$container->register('flasher', 'Flasher\Prime\Flasher') + ->setPublic(true) + ->addArgument(null) ->addArgument(new Reference('flasher.response_manager')) - ->addTag('kernel.event_listener', array('event' => 'kernel.response')); + ->addArgument(new Reference('flasher.storage_manager')); -$container - ->register('flasher.template_engine', 'Flasher\Symfony\Template\TwigEngine') - ->addArgument(new Reference('twig')); - -$container - ->register('flasher', 'Flasher\Prime\Flasher') - ->addArgument(new Reference('flasher.config')) - ->addArgument(new Reference('flasher.response_manager')); +$container->register('flasher.notification_factory', 'Flasher\Prime\Factory\NotificationFactory') + ->setPublic(false) + ->addArgument(new Reference('flasher.storage_manager')); if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Prime\Config\Config', 'flasher.config'); - $container->setAlias('Flasher\Prime\Config\ConfigInterface', 'flasher.config'); - $container->setAlias('Flasher\Prime\EventDispatcher\EventDispatcher', 'flasher.event_dispatcher'); - $container->setAlias('Flasher\Prime\EventDispatcher\EventDispatcherInterface', 'flasher.event_dispatcher'); - $container->setAlias('Flasher\Prime\Factory\TemplateFactory', 'flasher.template'); - $container->setAlias('Flasher\Prime\Factory\NotificationFactory', 'flasher.template'); - $container->setAlias('Flasher\Prime\Factory\NotificationFactoryInterface', 'flasher.template'); - $container->setAlias('flasher.notification_factory', 'flasher.template'); - $container->setAlias('Flasher\Prime\Filter\Filter', 'flasher.filter'); - $container->setAlias('Flasher\Prime\Filter\FilterInterface', 'flasher.filter'); $container->setAlias('Flasher\Prime\Flasher', 'flasher'); $container->setAlias('Flasher\Prime\FlasherInterface', 'flasher'); - $container->setAlias('Flasher\Prime\Response\ResponseManagerInterface', 'flasher.response_manager'); - $container->setAlias('Flasher\Prime\Storage\StorageInterface', 'flasher.storage'); - $container->setAlias('Flasher\Prime\Storage\StorageManager', 'flasher.storage_manager'); - $container->setAlias('Flasher\Prime\Storage\StorageManagerInterface', 'flasher.storage_manager'); - $container->setAlias('Flasher\Prime\Template\EngineInterface', 'flasher.template_engine'); - $container->setAlias('Flasher\Symfony\Storage\Storage', 'flasher.storage'); - $container->setAlias('Flasher\Symfony\Template\TwigEngine', 'flasher.template_engine'); } diff --git a/src/Symfony/Resources/config/session_listener.php b/src/Symfony/Resources/config/session_listener.php new file mode 100644 index 00000000..4cd684f8 --- /dev/null +++ b/src/Symfony/Resources/config/session_listener.php @@ -0,0 +1,18 @@ + + */ + +use Symfony\Component\DependencyInjection\Reference; + +if (!isset($container)) { + return; +} + +$container->register('flasher.session_listener', 'Flasher\Symfony\EventListener\SessionListener') + ->setPublic(false) + ->addArgument(new Reference('flasher')) + ->addArgument(array()) + ->addTag('kernel.event_listener', array('event' => 'kernel.response')); diff --git a/src/Symfony/Resources/views/bootstrap.html.twig b/src/Symfony/Resources/views/bootstrap.html.twig deleted file mode 100644 index fe4b48e0..00000000 --- a/src/Symfony/Resources/views/bootstrap.html.twig +++ /dev/null @@ -1,43 +0,0 @@ -{% if 'success' == envelope.type %} - {% set title = 'Success' %} - {% set alert_class = 'alert-success' %} - {% set progress_bg_color = '#155724' %} - {% set icon = '' %} -{% elseif 'error' == envelope.type %} - {% set title = 'Error' %} - {% set alert_class = 'alert-danger' %} - {% set progress_bg_color = '#721c24' %} - {% set icon = '' %} -{% elseif 'warning' == envelope.type %} - {% set title = 'Warning' %} - {% set alert_class = 'alert-warning' %} - {% set progress_bg_color = '#856404' %} - {% set icon = '' %} -{% else %} - {% set title = 'Info' %} - {% set alert_class = 'alert-info' %} - {% set progress_bg_color = '#0c5460' %} - {% set icon = '' %} -{% endif %} - -
- - - - - - - - - - - - -
- -
-
diff --git a/src/Symfony/Resources/views/tailwindcss.html.twig b/src/Symfony/Resources/views/tailwindcss.html.twig deleted file mode 100644 index 8d42b379..00000000 --- a/src/Symfony/Resources/views/tailwindcss.html.twig +++ /dev/null @@ -1,52 +0,0 @@ -{% if 'success' == envelope.type %} - {% set title = 'Success' %} - {% set text_color = 'text-green-600' %} - {% set ring_color = 'ring-green-300' %} - {% set background_color = 'bg-green-600' %} - {% set progress_background_color = 'bg-green-100' %} - {% set border_color = 'border-green-600' %} - {% set icon = '' %} -{% elseif 'error' == envelope.type %} - {% set title = 'Error' %} - {% set text_color = 'text-red-600' %} - {% set ring_color = 'ring-red-300' %} - {% set background_color = 'bg-red-600' %} - {% set progress_background_color = 'bg-red-100' %} - {% set border_color = 'border-red-600' %} - {% set icon = '' %} -{% elseif 'warning' == envelope.type %} - {% set title = 'Warning' %} - {% set text_color = 'text-yellow-600' %} - {% set ring_color = 'ring-yellow-300' %} - {% set background_color = 'bg-yellow-600' %} - {% set progress_background_color = 'bg-yellow-100' %} - {% set border_color = 'border-yellow-600' %} - {% set icon = '' %} -{% else %} - {% set title = 'Info' %} - {% set text_color = 'text-blue-600' %} - {% set ring_color = 'ring-blue-300' %} - {% set background_color = 'bg-blue-600' %} - {% set progress_background_color = 'bg-blue-100' %} - {% set border_color = 'border-blue-600' %} - {% set icon = '' %} -{% endif %} - -
-
-
- {{ icon | raw }} -
-
-

- {{ envelope.notification.title ?? title | trans }} -

-

- {{ envelope.message | trans }} -

-
-
-
- -
-
diff --git a/src/Symfony/Resources/views/tailwindcss_bg.html.twig b/src/Symfony/Resources/views/tailwindcss_bg.html.twig deleted file mode 100644 index e7c9f9f8..00000000 --- a/src/Symfony/Resources/views/tailwindcss_bg.html.twig +++ /dev/null @@ -1,48 +0,0 @@ -{% if 'success' == envelope.type %} - {% set title = 'Success' %} - {% set text_color = 'text-green-700' %} - {% set background_color = 'bg-green-50' %} - {% set progress_background_color = 'bg-green-200' %} - {% set border_color = 'border-green-600' %} - {% set icon = '' %} -{% elseif 'error' == envelope.type %} - {% set title = 'Error' %} - {% set text_color = 'text-red-700' %} - {% set background_color = 'bg-red-50' %} - {% set progress_background_color = 'bg-red-200' %} - {% set border_color = 'border-red-600' %} - {% set icon = '' %} -{% elseif 'warning' == envelope.type %} - {% set title = 'Warning' %} - {% set text_color = 'text-yellow-700' %} - {% set background_color = 'bg-yellow-50' %} - {% set progress_background_color = 'bg-yellow-200' %} - {% set border_color = 'border-yellow-600' %} - {% set icon = '' %} -{% else %} - {% set title = 'Info' %} - {% set text_color = 'text-blue-700' %} - {% set background_color = 'bg-blue-50' %} - {% set progress_background_color = 'bg-blue-200' %} - {% set border_color = 'border-blue-600' %} - {% set icon = '' %} -{% endif %} - -
-
-
- {{ icon | raw }} -
-
-

- {{ envelope.notification.title ?? title | trans }} -

-

- {{ envelope.message | trans }} -

-
-
-
- -
-
diff --git a/src/Symfony/Storage/SessionBag.php b/src/Symfony/Storage/SessionBag.php new file mode 100644 index 00000000..b0e73be2 --- /dev/null +++ b/src/Symfony/Storage/SessionBag.php @@ -0,0 +1,63 @@ + + */ + +namespace Flasher\Symfony\Storage; + +use Flasher\Prime\Storage\Bag\BagInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session as LegacySession; +use Symfony\Component\HttpFoundation\Session\SessionInterface; + +final class SessionBag implements BagInterface +{ + const ENVELOPES_NAMESPACE = 'flasher::envelopes'; + + /** + * @var RequestStack|SessionInterface + */ + private $session; + + /** + * @param RequestStack|SessionInterface $session + */ + public function __construct($session) + { + $this->session = $session; + } + + /** + * {@inheritdoc} + */ + public function get() + { + return $this->session()->get(self::ENVELOPES_NAMESPACE, array()); // @phpstan-ignore-line + } + + /** + * {@inheritdoc} + */ + public function set(array $envelopes) + { + $this->session()->set(self::ENVELOPES_NAMESPACE, $envelopes); + } + + /** + * @return SessionInterface + */ + private function session() + { + if ($this->session instanceof SessionInterface || $this->session instanceof LegacySession) { // @phpstan-ignore-line + return $this->session; // @phpstan-ignore-line + } + + if (method_exists($this->session, 'getSession')) { + return $this->session = $this->session->getSession(); + } + + return $this->session = $this->session->getCurrentRequest()->getSession(); // @phpstan-ignore-line + } +} diff --git a/src/Symfony/Storage/Storage.php b/src/Symfony/Storage/Storage.php deleted file mode 100644 index 37a6865d..00000000 --- a/src/Symfony/Storage/Storage.php +++ /dev/null @@ -1,96 +0,0 @@ -requestStack = $requestStack; - } - - public function all() - { - return $this->session()->get(self::ENVELOPES_NAMESPACE, array()); - } - - public function add($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - - $this->session()->set(self::ENVELOPES_NAMESPACE, array_merge($this->all(), $envelopes)); - } - - public function update($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $map = UuidStamp::indexByUuid($envelopes); - - $store = $this->all(); - foreach ($store as $index => $envelope) { - $uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid(); - - if (!isset($map[$uuid])) { - continue; - } - - $store[$index] = $map[$uuid]; - } - - $this->session()->set(self::ENVELOPES_NAMESPACE, $store); - } - - public function remove($envelopes) - { - $envelopes = is_array($envelopes) ? $envelopes : func_get_args(); - $map = UuidStamp::indexByUuid($envelopes); - - $store = array_filter($this->all(), function (Envelope $envelope) use ($map) { - $uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid(); - - return !isset($map[$uuid]); - }); - - $this->session()->set(self::ENVELOPES_NAMESPACE, $store); - } - - public function clear() - { - $this->session()->set(self::ENVELOPES_NAMESPACE, array()); - } - - /** - * @return SessionInterface - */ - private function session() - { - if ($this->requestStack instanceof SessionInterface || $this->requestStack instanceof LegacySession) { - return $this->requestStack; - } - - if (method_exists($this->requestStack, 'getSession')) { - return $this->requestStack->getSession(); - } - - $request = $this->requestStack->getCurrentRequest(); - - return $request->getSession(); - } -} diff --git a/src/Symfony/Support/Bundle.php b/src/Symfony/Support/Bundle.php new file mode 100644 index 00000000..46b2611a --- /dev/null +++ b/src/Symfony/Support/Bundle.php @@ -0,0 +1,24 @@ + + */ + +namespace Flasher\Symfony\Support; + +use Flasher\Prime\Plugin\PluginInterface; +use Flasher\Symfony\Bridge\FlasherBundle; + +abstract class Bundle extends FlasherBundle +{ + /** + * @return PluginInterface + */ + abstract protected function createPlugin(); + + protected function getFlasherContainerExtension() + { + return new Extension($this->createPlugin()); + } +} diff --git a/src/Symfony/Support/Configuration.php b/src/Symfony/Support/Configuration.php new file mode 100644 index 00000000..a16d6787 --- /dev/null +++ b/src/Symfony/Support/Configuration.php @@ -0,0 +1,54 @@ + + */ + +namespace Flasher\Symfony\Support; + +use Flasher\Prime\Plugin\PluginInterface; +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class Configuration implements ConfigurationInterface +{ + /** + * @var PluginInterface + */ + private $plugin; + + public function __construct(PluginInterface $plugin) + { + $this->plugin = $plugin; + } + + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder($this->plugin->getName()); + + $rootNode = method_exists($treeBuilder, 'getRootNode') + ? $treeBuilder->getRootNode() + : $treeBuilder->root($this->plugin->getName()); // @phpstan-ignore-line + + $rootNode + ->children() + ->arrayNode('scripts') + ->prototype('scalar')->end() + ->defaultValue($this->plugin->getScripts()) + ->end() + ->arrayNode('styles') + ->prototype('scalar')->end() + ->defaultValue($this->plugin->getStyles()) + ->end() + ->arrayNode('options') + ->prototype('variable')->end() + ->ignoreExtraKeys(false) + ->defaultValue($this->plugin->getOptions()) + ->end() + ->end() + ; + + return $treeBuilder; + } +} diff --git a/src/Symfony/Support/Extension.php b/src/Symfony/Support/Extension.php new file mode 100644 index 00000000..fe79e38b --- /dev/null +++ b/src/Symfony/Support/Extension.php @@ -0,0 +1,102 @@ + + */ + +namespace Flasher\Symfony\Support; + +use Flasher\Prime\Plugin\PluginInterface; +use Flasher\Symfony\Bridge\Bridge; +use Flasher\Symfony\Bridge\DependencyInjection\FlasherExtension; +use Symfony\Component\DependencyInjection\ChildDefinition; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\DefinitionDecorator; + +final class Extension extends FlasherExtension implements CompilerPassInterface +{ + /** + * @var PluginInterface + */ + private $plugin; + + public function __construct(PluginInterface $plugin) + { + $this->plugin = $plugin; + } + + /** + * {@inheritdoc} + * + * @param array> $configs + * + * @return void + */ + public function load(array $configs, ContainerBuilder $container) + { + /** @var ChildDefinition $definition */ + $definition = class_exists('Symfony\Component\DependencyInjection\ChildDefinition') + ? new ChildDefinition('flasher.notification_factory') + : new DefinitionDecorator('flasher.notification_factory'); // @phpstan-ignore-line + + $definition + ->setClass($this->plugin->getFactory()) + ->addTag('flasher.factory', array('alias' => $this->plugin->getAlias())); + + $identifier = $this->plugin->getServiceID(); + $container->setDefinition($identifier, $definition); + + if (Bridge::canLoadAliases()) { + $container->setAlias($this->plugin->getFactory(), $identifier); + } + } + + /** + * {@inheritdoc} + */ + public function getFlasherAlias() + { + return $this->plugin->getName(); + } + + /** + * {@inheritdoc} + * + * @return void + */ + public function process(ContainerBuilder $container) + { + $configs = $this->processConfiguration( + new Configuration($this->plugin), + $container->getExtensionConfig($this->plugin->getName()) + ); + + $this->processResourceConfiguration($configs, $container); + } + + /** + * @param array $configs + * + * @return void + */ + protected function processResourceConfiguration(array $configs, ContainerBuilder $container) + { + if (!$container->has('flasher.resource_manager')) { + return; + } + + $definition = $container->getDefinition('flasher.resource_manager'); + $handler = $this->plugin->getAlias(); + + $scripts = isset($configs['scripts']) ? $configs['scripts'] : array(); + $definition->addMethodCall('addScripts', array($handler, $scripts)); + + $styles = isset($configs['styles']) ? $configs['styles'] : array(); + $definition->addMethodCall('addStyles', array($handler, $styles)); + + $options = isset($configs['options']) ? $configs['options'] : array(); + $definition->addMethodCall('addOptions', array($handler, $options)); + } +} diff --git a/src/Symfony/Template/TwigEngine.php b/src/Symfony/Template/TwigTemplateEngine.php similarity index 61% rename from src/Symfony/Template/TwigEngine.php rename to src/Symfony/Template/TwigTemplateEngine.php index 2574e1b2..7500580a 100644 --- a/src/Symfony/Template/TwigEngine.php +++ b/src/Symfony/Template/TwigTemplateEngine.php @@ -1,11 +1,16 @@ + */ + namespace Flasher\Symfony\Template; -use Flasher\Prime\Template\EngineInterface; +use Flasher\Prime\Template\TemplateEngineInterface; use Twig\Environment; -final class TwigEngine implements EngineInterface +final class TwigTemplateEngine implements TemplateEngineInterface { /** * @var Environment diff --git a/src/Symfony/Twig/FlasherTwigExtension.php b/src/Symfony/Twig/FlasherTwigExtension.php old mode 100755 new mode 100644 index 3a0e1b81..5258155b --- a/src/Symfony/Twig/FlasherTwigExtension.php +++ b/src/Symfony/Twig/FlasherTwigExtension.php @@ -1,38 +1,47 @@ + */ + namespace Flasher\Symfony\Twig; -use Flasher\Prime\Response\ResponseManagerInterface; +use Flasher\Prime\FlasherInterface; +use Flasher\Symfony\Bridge\Twig\FlasherTwigExtension as BaseFlasherTwigExtension; use Twig\TwigFunction; -final class FlasherTwigExtension extends \Flasher\Symfony\Bridge\Twig\FlasherTwigExtension +final class FlasherTwigExtension extends BaseFlasherTwigExtension { /** - * @var ResponseManagerInterface + * @var FlasherInterface */ - private $responseManager; + private $flasher; - public function __construct(ResponseManagerInterface $responseManager) + public function __construct(FlasherInterface $flasher) { - $this->responseManager = $responseManager; + $this->flasher = $flasher; } + /** + * @return TwigFunction[] + */ public function getFlasherFunctions() { - $options = array( - 'is_safe' => array('html'), - ); + $options = array('is_safe' => array('html')); return array( - new TwigFunction('flasher_render', array($this, 'flasherRender'), $options), + new TwigFunction('flasher_render', array($this, 'render'), $options), ); } /** + * @param array $criteria + * * @return string */ - public function flasherRender(array $criteria = array()) + public function render(array $criteria = array()) { - return $this->responseManager->render($criteria); + return $this->flasher->render($criteria, 'html'); // @phpstan-ignore-line } } diff --git a/src/Symfony/UPGRADING.md b/src/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Symfony/composer.json b/src/Symfony/composer.json index 6d695cda..af35c59d 100644 --- a/src/Symfony/composer.json +++ b/src/Symfony/composer.json @@ -2,34 +2,20 @@ "name": "php-flasher/flasher-symfony", "type": "symfony-bundle", "description": "Symfony bundle integrating PHP Flasher into Symfony applications", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9", + "php-flasher/flasher": "^1.0", "symfony/config": "^2.0|^3.0|^4.0|^5.0|^6.0", "symfony/dependency-injection": "^2.0|^3.0|^4.0|^5.0|^6.0", "symfony/http-kernel": "^2.0|^3.0|^4.0|^5.0|^6.0", @@ -44,6 +30,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Toastr/Laravel/.editorconfig b/src/Toastr/Laravel/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Toastr/Laravel/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Toastr/Laravel/.gitattributes b/src/Toastr/Laravel/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Toastr/Laravel/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Toastr/Laravel/.github/CONTRIBUTING.md b/src/Toastr/Laravel/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Toastr/Laravel/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Toastr/Laravel/.github/FUNDING.yml b/src/Toastr/Laravel/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Toastr/Laravel/.github/FUNDING.yml +++ b/src/Toastr/Laravel/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Toastr/Laravel/.github/SECURITY.md b/src/Toastr/Laravel/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Toastr/Laravel/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Toastr/Laravel/.github/dependabot.yml b/src/Toastr/Laravel/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Toastr/Laravel/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Toastr/Laravel/.github/workflows/auto_closer.yaml b/src/Toastr/Laravel/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Toastr/Laravel/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Toastr/Laravel/.github/workflows/close-pull-request.yml b/src/Toastr/Laravel/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Toastr/Laravel/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Toastr/Laravel/.gitignore b/src/Toastr/Laravel/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Toastr/Laravel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Toastr/Laravel/CHANGELOG.md b/src/Toastr/Laravel/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Toastr/Laravel/CODE_OF_CONDUCT.md b/src/Toastr/Laravel/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Toastr/Laravel/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Toastr/Laravel/Facade/Toastr.php b/src/Toastr/Laravel/Facade/Toastr.php index d5f361ba..cc0ba9ad 100644 --- a/src/Toastr/Laravel/Facade/Toastr.php +++ b/src/Toastr/Laravel/Facade/Toastr.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Toastr\Laravel\Facade; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Stamp\StampInterface; use Flasher\Toastr\Prime\ToastrBuilder; @@ -13,7 +18,7 @@ use Illuminate\Support\Facades\Facade; * @method static ToastrBuilder addError(string $message, array $options = array()) * @method static ToastrBuilder addWarning(string $message, array $options = array()) * @method static ToastrBuilder addInfo(string $message, array $options = array()) - * @method static ToastrBuilder addFlash(string|NotificationInterface $type, string $message = null, array $options = array()) + * @method static ToastrBuilder addFlash(NotificationInterface|string $type, string $message = null, array $options = array()) * @method static ToastrBuilder flash(StampInterface[] $stamps = array()) * @method static ToastrBuilder type(string $type, string $message = null, array $options = array()) * @method static ToastrBuilder message(string $message) @@ -32,7 +37,6 @@ use Illuminate\Support\Facades\Facade; * @method static ToastrBuilder withStamp(StampInterface $stamp) * @method static ToastrBuilder handler(string $handler) * @method static Envelope getEnvelope() - * * @method static ToastrBuilder title(string $title) * @method static ToastrBuilder closeButton(bool $closeButton = true) * @method static ToastrBuilder closeClass(string $closeClass) diff --git a/src/Toastr/Laravel/FlasherToastrServiceProvider.php b/src/Toastr/Laravel/FlasherToastrServiceProvider.php index e9097dde..a3c0f115 100644 --- a/src/Toastr/Laravel/FlasherToastrServiceProvider.php +++ b/src/Toastr/Laravel/FlasherToastrServiceProvider.php @@ -1,55 +1,22 @@ + */ + namespace Flasher\Toastr\Laravel; -use Flasher\Toastr\Laravel\ServiceProvider\ServiceProviderManager; -use Illuminate\Container\Container; -use Illuminate\Support\ServiceProvider; +use Flasher\Laravel\Support\ServiceProvider; +use Flasher\Toastr\Prime\ToastrPlugin; final class FlasherToastrServiceProvider extends ServiceProvider { - public function boot() - { - $manager = new ServiceProviderManager($this); - $manager->boot(); - } - /** - * Register the service provider. + * {@inheritdoc} */ - public function register() + protected function createPlugin() { - $manager = new ServiceProviderManager($this); - $manager->register(); - } - - /** - * Get the services provided by the provider. - * - * @return string[] - */ - public function provides() - { - return array( - 'flasher.toastr', - ); - } - - /** - * @return Container - */ - public function getApplication() - { - return $this->app; - } - - public function mergeConfigFrom($path, $key) - { - parent::mergeConfigFrom($path, $key); - } - - public function publishes(array $paths, $groups = null) - { - parent::publishes($paths, $groups); + return new ToastrPlugin(); } } diff --git a/src/Toastr/Laravel/README.md b/src/Toastr/Laravel/README.md index 5714d7d7..70048b42 100644 --- a/src/Toastr/Laravel/README.md +++ b/src/Toastr/Laravel/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Toastr/Laravel/Resources/config/config.php b/src/Toastr/Laravel/Resources/config/config.php deleted file mode 100644 index 64674154..00000000 --- a/src/Toastr/Laravel/Resources/config/config.php +++ /dev/null @@ -1,13 +0,0 @@ - array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@0.1.3/dist/flasher-toastr.min.js', - ), - 'styles' => array(), - 'options' => array( - 'progressBar' => true, - 'timeOut' => 5000, - ), -); diff --git a/src/Toastr/Laravel/Resources/functions/toastr.php b/src/Toastr/Laravel/Resources/functions/toastr.php deleted file mode 100644 index c7d0496a..00000000 --- a/src/Toastr/Laravel/Resources/functions/toastr.php +++ /dev/null @@ -1,24 +0,0 @@ -title($title) - ->addFlash($type, $message, $options); - } -} diff --git a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php deleted file mode 100644 index 0a615ad0..00000000 --- a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel.php +++ /dev/null @@ -1,74 +0,0 @@ -app = $app; - } - - public function shouldBeUsed() - { - return $this->app instanceof Application; - } - - public function boot(FlasherToastrServiceProvider $provider) - { - $provider->publishes(array( - flasher_path(__DIR__ . '/../../Resources/config/config.php') => config_path('flasher_toastr.php'), - ), 'flasher-config'); - } - - public function register(FlasherToastrServiceProvider $provider) - { - $provider->mergeConfigFrom(flasher_path(__DIR__ . '/../../Resources/config/config.php'), 'flasher_toastr'); - $this->appendToFlasherConfig(); - - $this->registerServices(); - } - - public function registerServices() - { - $this->app->singleton('flasher.toastr', function (Container $app) { - return new ToastrFactory($app['flasher.storage_manager']); - }); - - $this->app->alias('flasher.toastr', 'Flasher\Toastr\Prime\ToastrFactory'); - - $this->app->extend('flasher', function (Flasher $flasher, Container $app) { - $flasher->addFactory('toastr', $app['flasher.toastr']); - - return $flasher; - }); - - $this->app->extend('flasher.resource_manager', function (ResourceManager $resourceManager) { - ResourceManagerHelper::process($resourceManager, 'toastr'); - - return $resourceManager; - }); - } - - public function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher.adapters.toastr', array()); - - $toastrConfig = $this->app['config']->get('flasher_toastr', array()); - - $this->app['config']->set('flasher.adapters.toastr', array_merge($toastrConfig, $flasherConfig)); - } -} diff --git a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel4.php b/src/Toastr/Laravel/ServiceProvider/Providers/Laravel4.php deleted file mode 100644 index f55bbed2..00000000 --- a/src/Toastr/Laravel/ServiceProvider/Providers/Laravel4.php +++ /dev/null @@ -1,38 +0,0 @@ -app instanceof Application && 0 === strpos(Application::VERSION, '4.'); - } - - public function boot(FlasherToastrServiceProvider $provider) - { - $provider->package( - 'php-flasher/flasher-toastr-laravel', - 'flasher_toastr', - flasher_path(__DIR__ . '/../../Resources') - ); - $this->appendToFlasherConfig(); - } - - public function register(FlasherToastrServiceProvider $provider) - { - $this->registerServices(); - } - - public function appendToFlasherConfig() - { - $flasherConfig = $this->app['config']->get('flasher::config.adapters.toastr', array()); - - $toastrConfig = $this->app['config']->get('flasher_toastr::config', array()); - - $this->app['config']->set('flasher::config.adapters.toastr', array_merge($toastrConfig, $flasherConfig)); - } -} diff --git a/src/Toastr/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php b/src/Toastr/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php deleted file mode 100644 index 3d4c6417..00000000 --- a/src/Toastr/Laravel/ServiceProvider/Providers/ServiceProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -notifyServiceProvider = $notifyServiceProvider; - } - - public function boot() - { - $provider = $this->resolveServiceProvider(); - $provider->boot($this->notifyServiceProvider); - } - - public function register() - { - $provider = $this->resolveServiceProvider(); - $provider->register($this->notifyServiceProvider); - } - - /** - * @return ServiceProviderInterface - */ - private function resolveServiceProvider() - { - if ($this->provider instanceof ServiceProviderInterface) { - return $this->provider; - } - - foreach ($this->providers as $providerClass) { - $provider = new $providerClass($this->notifyServiceProvider->getApplication()); - - if ($provider->shouldBeUsed()) { - return $this->provider = $provider; - } - } - - throw new \InvalidArgumentException('Service Provider not found.'); - } -} diff --git a/src/Toastr/Laravel/UPGRADING.md b/src/Toastr/Laravel/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Toastr/Laravel/composer.json b/src/Toastr/Laravel/composer.json index 58edb7d6..f3514599 100644 --- a/src/Toastr/Laravel/composer.json +++ b/src/Toastr/Laravel/composer.json @@ -2,42 +2,28 @@ "name": "php-flasher/flasher-toastr-laravel", "description": "PHP Flasher Laravel adapter for Toastr", "type": "library", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-laravel": "^0.9", - "php-flasher/flasher-toastr": "^0.9" + "php-flasher/flasher-laravel": "^1.0", + "php-flasher/flasher-toastr": "^1.0" }, "autoload": { "psr-4": { "Flasher\\Toastr\\Laravel\\": "" }, "files": [ - "Resources/functions/toastr.php" + "toastr.php" ] }, "extra": { @@ -53,6 +39,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Toastr/Laravel/toastr.php b/src/Toastr/Laravel/toastr.php new file mode 100644 index 00000000..7736eb1e --- /dev/null +++ b/src/Toastr/Laravel/toastr.php @@ -0,0 +1,32 @@ + + */ + +use Flasher\Prime\Notification\Envelope; +use Flasher\Prime\Notification\NotificationInterface; +use Flasher\Toastr\Prime\ToastrFactory; + +if (!function_exists('toastr')) { + /** + * @param string $message + * @param string $type + * @param string $title + * @param array $options + * + * @return Envelope|ToastrFactory + */ + function toastr($message = null, $type = NotificationInterface::SUCCESS, $title = '', array $options = array()) + { + /** @var ToastrFactory $factory */ + $factory = app('flasher.toastr'); + + if (0 === func_num_args()) { + return $factory; + } + + return $factory->title($title)->addFlash($type, $message, $options); + } +} diff --git a/src/Toastr/Prime/.editorconfig b/src/Toastr/Prime/.editorconfig deleted file mode 100755 index cd8eb86e..00000000 --- a/src/Toastr/Prime/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Toastr/Prime/.gitattributes b/src/Toastr/Prime/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Toastr/Prime/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Toastr/Prime/.github/CONTRIBUTING.md b/src/Toastr/Prime/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Toastr/Prime/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Toastr/Prime/.github/FUNDING.yml b/src/Toastr/Prime/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Toastr/Prime/.github/FUNDING.yml +++ b/src/Toastr/Prime/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Toastr/Prime/.github/SECURITY.md b/src/Toastr/Prime/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Toastr/Prime/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Toastr/Prime/.github/dependabot.yml b/src/Toastr/Prime/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Toastr/Prime/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Toastr/Prime/.github/workflows/auto_closer.yaml b/src/Toastr/Prime/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Toastr/Prime/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Toastr/Prime/.github/workflows/close-pull-request.yml b/src/Toastr/Prime/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Toastr/Prime/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Toastr/Prime/.gitignore b/src/Toastr/Prime/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Toastr/Prime/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Toastr/Prime/CHANGELOG.md b/src/Toastr/Prime/CHANGELOG.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Toastr/Prime/CODE_OF_CONDUCT.md b/src/Toastr/Prime/CODE_OF_CONDUCT.md deleted file mode 100644 index ec367cc6..00000000 --- a/src/Toastr/Prime/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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 diff --git a/src/Toastr/Prime/README.md b/src/Toastr/Prime/README.md index 5714d7d7..70048b42 100644 --- a/src/Toastr/Prime/README.md +++ b/src/Toastr/Prime/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Toastr/Prime/Toastr.php b/src/Toastr/Prime/Toastr.php deleted file mode 100644 index 7ebaf0fb..00000000 --- a/src/Toastr/Prime/Toastr.php +++ /dev/null @@ -1,36 +0,0 @@ -title; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - public function toArray() - { - return array_merge(parent::toArray(), array( - 'title' => $this->getTitle(), - )); - } -} diff --git a/src/Toastr/Prime/ToastrBuilder.php b/src/Toastr/Prime/ToastrBuilder.php index 85976a92..fe177691 100644 --- a/src/Toastr/Prime/ToastrBuilder.php +++ b/src/Toastr/Prime/ToastrBuilder.php @@ -1,30 +1,26 @@ + */ + namespace Flasher\Toastr\Prime; use Flasher\Prime\Notification\NotificationBuilder; +/** + * @SuppressWarnings(PHPMD.TooManyMethods) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ final class ToastrBuilder extends NotificationBuilder { /** - * @param string $title - * - * @return self - */ - public function title($title) - { - $notification = $this->envelope->getNotification(); - $notification->setTitle($title); - - return $this; - } - - /** - * Enable a close button + * Enable a close button. * * @param bool $closeButton * - * @return $this + * @return static */ public function closeButton($closeButton = true) { @@ -36,7 +32,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $closeClass * - * @return $this + * @return static */ public function closeClass($closeClass) { @@ -48,7 +44,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param int $closeDuration * - * @return $this + * @return static */ public function closeDuration($closeDuration) { @@ -60,7 +56,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $closeEasing * - * @return $this + * @return static */ public function closeEasing($closeEasing) { @@ -74,7 +70,7 @@ final class ToastrBuilder extends NotificationBuilder * * @param string $closeHtml * - * @return $this + * @return static */ public function closeHtml($closeHtml) { @@ -86,7 +82,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $closeMethod * - * @return $this + * @return static */ public function closeMethod($closeMethod) { @@ -98,7 +94,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param bool $closeOnHover * - * @return $this + * @return static */ public function closeOnHover($closeOnHover = true) { @@ -110,7 +106,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $containerId * - * @return $this + * @return static */ public function containerId($containerId) { @@ -122,7 +118,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param bool $debug * - * @return $this + * @return static */ public function debug($debug = true) { @@ -132,11 +128,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * In case you want to escape HTML characters in title and message + * In case you want to escape HTML characters in title and message. * * @param bool $escapeHtml * - * @return $this + * @return static */ public function escapeHtml($escapeHtml = true) { @@ -146,11 +142,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * How long the toast will display after a user hovers over it + * How long the toast will display after a user hovers over it. * * @param int $extendedTimeOut * - * @return $this + * @return static */ public function extendedTimeOut($extendedTimeOut) { @@ -160,11 +156,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Specifies the time during which the pop-up closes in ms + * Specifies the time during which the pop-up closes in ms. * * @param int $hideDuration * - * @return $this + * @return static */ public function hideDuration($hideDuration) { @@ -174,11 +170,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Indicates the entry transition of the pop-up + * Indicates the entry transition of the pop-up. * * @param string $hideEasing * - * @return $this + * @return static */ public function hideEasing($hideEasing) { @@ -188,11 +184,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Indicates the opening animation of the pop-up + * Indicates the opening animation of the pop-up. * * @param string $hideMethod * - * @return $this + * @return static */ public function hideMethod($hideMethod) { @@ -204,7 +200,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $iconClass * - * @return $this + * @return static */ public function iconClass($iconClass) { @@ -216,7 +212,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $messageClass * - * @return $this + * @return static */ public function messageClass($messageClass) { @@ -226,11 +222,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Show newest toast at bottom (top is default) + * Show newest toast at bottom (top is default). * * @param bool $newestOnTop * - * @return $this + * @return static */ public function newestOnTop($newestOnTop = true) { @@ -242,7 +238,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $onHidden * - * @return $this + * @return static */ public function onHidden($onHidden) { @@ -254,7 +250,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $onShown * - * @return $this + * @return static */ public function onShown($onShown) { @@ -266,7 +262,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $positionClass * - * @return $this + * @return static */ public function positionClass($positionClass) { @@ -281,7 +277,7 @@ final class ToastrBuilder extends NotificationBuilder * * @param bool $preventDuplicates * - * @return $this + * @return static */ public function preventDuplicates($preventDuplicates = true) { @@ -295,7 +291,7 @@ final class ToastrBuilder extends NotificationBuilder * * @param bool $progressBar * - * @return $this + * @return static */ public function progressBar($progressBar = true) { @@ -307,7 +303,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $progressClass * - * @return $this + * @return static */ public function progressClass($progressClass) { @@ -321,7 +317,7 @@ final class ToastrBuilder extends NotificationBuilder * * @param bool $rtl * - * @return $this + * @return static */ public function rtl($rtl = true) { @@ -331,11 +327,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Specifies the time during which the pop-up opens in ms + * Specifies the time during which the pop-up opens in ms. * * @param int $showDuration * - * @return $this + * @return static */ public function showDuration($showDuration) { @@ -345,11 +341,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Indicates the entry transition of the pop-up + * Indicates the entry transition of the pop-up. * * @param string $showEasing * - * @return $this + * @return static */ public function showEasing($showEasing) { @@ -359,11 +355,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Indicates the opening animation of the pop-up + * Indicates the opening animation of the pop-up. * * @param string $showMethod * - * @return $this + * @return static */ public function showMethod($showMethod) { @@ -373,11 +369,11 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Forces the user to validate the pop-up before closing + * Forces the user to validate the pop-up before closing. * * @param bool $tapToDismiss * - * @return $this + * @return static */ public function tapToDismiss($tapToDismiss = true) { @@ -389,7 +385,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $target * - * @return $this + * @return static */ public function target($target) { @@ -399,12 +395,12 @@ final class ToastrBuilder extends NotificationBuilder } /** - * How long the toast will display without user interaction + * How long the toast will display without user interaction. * - * @param int $timeOut + * @param int $timeOut * @param int $extendedTimeOut * - * @return $this + * @return static */ public function timeOut($timeOut, $extendedTimeOut = null) { @@ -420,7 +416,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $titleClass * - * @return $this + * @return static */ public function titleClass($titleClass) { @@ -432,7 +428,7 @@ final class ToastrBuilder extends NotificationBuilder /** * @param string $toastClass * - * @return $this + * @return static */ public function toastClass($toastClass) { @@ -442,9 +438,9 @@ final class ToastrBuilder extends NotificationBuilder } /** - * Prevent from Auto Hiding + * Prevent from Auto Hiding. * - * @return $this + * @return static */ public function persistent() { diff --git a/src/Toastr/Prime/ToastrFactory.php b/src/Toastr/Prime/ToastrFactory.php index ee17e7ec..2838e93f 100644 --- a/src/Toastr/Prime/ToastrFactory.php +++ b/src/Toastr/Prime/ToastrFactory.php @@ -1,16 +1,25 @@ + */ + namespace Flasher\Toastr\Prime; use Flasher\Prime\Factory\NotificationFactory; +use Flasher\Prime\Notification\Notification; /** * @mixin ToastrBuilder */ final class ToastrFactory extends NotificationFactory { + /** + * {@inheritdoc} + */ public function createNotificationBuilder() { - return new ToastrBuilder($this->getStorageManager(), new Toastr(), 'toastr'); + return new ToastrBuilder($this->getStorageManager(), new Notification(), 'toastr'); } } diff --git a/src/Toastr/Prime/ToastrPlugin.php b/src/Toastr/Prime/ToastrPlugin.php new file mode 100644 index 00000000..c4813f7c --- /dev/null +++ b/src/Toastr/Prime/ToastrPlugin.php @@ -0,0 +1,24 @@ + + */ + +namespace Flasher\Toastr\Prime; + +use Flasher\Prime\Plugin\Plugin; + +class ToastrPlugin extends Plugin +{ + /** + * {@inheritdoc} + */ + public function getScripts() + { + return array( + 'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js', + 'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@1.0.7/dist/flasher-toastr.min.js', + ); + } +} diff --git a/src/Toastr/Prime/UPGRADING.md b/src/Toastr/Prime/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Toastr/Prime/composer.json b/src/Toastr/Prime/composer.json index e185ab88..e1ae1e0d 100644 --- a/src/Toastr/Prime/composer.json +++ b/src/Toastr/Prime/composer.json @@ -2,31 +2,20 @@ "name": "php-flasher/flasher-toastr", "description": "PHP Flasher adapter for Toastr", "type": "library", - "keywords": [ - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr " - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr "], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher": "^0.9" + "php-flasher/flasher": "^1.0" }, "autoload": { "psr-4": { @@ -36,6 +25,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Toastr/Symfony/.editorconfig b/src/Toastr/Symfony/.editorconfig deleted file mode 100644 index cd8eb86e..00000000 --- a/src/Toastr/Symfony/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -; 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 diff --git a/src/Toastr/Symfony/.gitattributes b/src/Toastr/Symfony/.gitattributes deleted file mode 100644 index 3383d44b..00000000 --- a/src/Toastr/Symfony/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ - -# 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 diff --git a/src/Toastr/Symfony/.github/CONTRIBUTING.md b/src/Toastr/Symfony/.github/CONTRIBUTING.md deleted file mode 100644 index b4ae1c4a..00000000 --- a/src/Toastr/Symfony/.github/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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**! diff --git a/src/Toastr/Symfony/.github/FUNDING.yml b/src/Toastr/Symfony/.github/FUNDING.yml index 5e454f27..7de85ae3 100644 --- a/src/Toastr/Symfony/.github/FUNDING.yml +++ b/src/Toastr/Symfony/.github/FUNDING.yml @@ -1,5 +1,3 @@ -# These are supported funding model platforms - patreon: yoeunes ko_fi: yoeunes open_collective: php-flasher diff --git a/src/Toastr/Symfony/.github/SECURITY.md b/src/Toastr/Symfony/.github/SECURITY.md deleted file mode 100644 index d9b55dde..00000000 --- a/src/Toastr/Symfony/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -If you discover any security related issues, please email younes.khoubza@gmail.com instead of using the issue tracker. diff --git a/src/Toastr/Symfony/.github/dependabot.yml b/src/Toastr/Symfony/.github/dependabot.yml deleted file mode 100644 index c630ffa6..00000000 --- a/src/Toastr/Symfony/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 diff --git a/src/Toastr/Symfony/.github/workflows/auto_closer.yaml b/src/Toastr/Symfony/.github/workflows/auto_closer.yaml new file mode 100644 index 00000000..f807ac59 --- /dev/null +++ b/src/Toastr/Symfony/.github/workflows/auto_closer.yaml @@ -0,0 +1,22 @@ +name: Auto Closer PR + +on: + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Hi, thank you for your contribution. + + Unfortunately, this repository is read-only. It's a split from our main monorepo repository. + + We'd like to kindly ask you to move the contribution there - https://github.com/php-flasher/php-flasher. + + We'll check it, review it and give you feed back right way. + + Thank you. diff --git a/src/Toastr/Symfony/.github/workflows/close-pull-request.yml b/src/Toastr/Symfony/.github/workflows/close-pull-request.yml deleted file mode 100644 index ed229fac..00000000 --- a/src/Toastr/Symfony/.github/workflows/close-pull-request.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Close Pull Request - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: "Thank you for your pull request. However, you have submitted this PR on a read-only sub split of `php-flasher/php-flasher`. Please submit your PR on the https://github.com/php-flasher/php-flasher repository.

Thanks!" diff --git a/src/Toastr/Symfony/.gitignore b/src/Toastr/Symfony/.gitignore deleted file mode 100644 index 89d72688..00000000 --- a/src/Toastr/Symfony/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -vendor -composer.lock -.phpunit.result.cache -.phpcs-cache diff --git a/src/Toastr/Symfony/.phpstorm.meta.php b/src/Toastr/Symfony/.phpstorm.meta.php deleted file mode 100644 index 55dcbfa4..00000000 --- a/src/Toastr/Symfony/.phpstorm.meta.php +++ /dev/null @@ -1,3 +0,0 @@ -getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('flasher_toastr'); - } - - $rootNode - ->children() - ->arrayNode('scripts') - ->prototype('scalar')->end() - ->defaultValue(array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@0.1.3/dist/flasher-toastr.min.js', - )) - ->end() - ->arrayNode('styles') - ->prototype('scalar')->end() - ->defaultValue(array()) - ->end() - ->arrayNode('options') - ->prototype('variable')->end() - ->ignoreExtraKeys(false) - ->defaultValue(array( - 'progressBar' => true, - 'timeOut' => 5000, - )) - ->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php b/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php deleted file mode 100644 index 357305d2..00000000 --- a/src/Toastr/Symfony/DependencyInjection/FlasherToastrExtension.php +++ /dev/null @@ -1,23 +0,0 @@ -load('services.php'); - } - - public function getConfigurationClass() - { - return new Configuration(); - } -} diff --git a/src/Toastr/Symfony/FlasherToastrSymfonyBundle.php b/src/Toastr/Symfony/FlasherToastrSymfonyBundle.php index 00e4ee24..5437903d 100644 --- a/src/Toastr/Symfony/FlasherToastrSymfonyBundle.php +++ b/src/Toastr/Symfony/FlasherToastrSymfonyBundle.php @@ -1,21 +1,22 @@ + */ + namespace Flasher\Toastr\Symfony; -use Flasher\Symfony\DependencyInjection\Compiler\ResourceCompilerPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Flasher\Symfony\Bridge\FlasherBundle; -use Flasher\Toastr\Symfony\DependencyInjection\FlasherToastrExtension; +use Flasher\Symfony\Support\Bundle; +use Flasher\Toastr\Prime\ToastrPlugin; -class FlasherToastrSymfonyBundle extends FlasherBundle // Symfony\Component\HttpKernel\Bundle\Bundle +final class FlasherToastrSymfonyBundle extends Bundle // Symfony\Component\HttpKernel\Bundle\Bundle { - protected function flasherBuild(ContainerBuilder $container) + /** + * {@inheritdoc} + */ + protected function createPlugin() { - $container->addCompilerPass(new ResourceCompilerPass($this->getFlasherContainerExtension())); - } - - protected function getFlasherContainerExtension() - { - return new FlasherToastrExtension(); + return new ToastrPlugin(); } } diff --git a/src/Toastr/Symfony/README.md b/src/Toastr/Symfony/README.md index 5714d7d7..70048b42 100644 --- a/src/Toastr/Symfony/README.md +++ b/src/Toastr/Symfony/README.md @@ -24,12 +24,6 @@ - - - - - -

# Why use PHP Flasher ? @@ -53,21 +47,7 @@ This library is designed, so you can take full control when creating you notific ## 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! 🙏 - - - Backers - - - - Sponsors - +Documentation for PHP Flasher can be found on the [PHP Flasher website](https://php-flasher.io). ### Contact diff --git a/src/Toastr/Symfony/Resources/config/services.php b/src/Toastr/Symfony/Resources/config/services.php deleted file mode 100644 index c667a6ed..00000000 --- a/src/Toastr/Symfony/Resources/config/services.php +++ /dev/null @@ -1,21 +0,0 @@ -setClass('Flasher\Toastr\Prime\ToastrFactory') - ->addTag('flasher.factory', array('alias' => 'toastr')); - -$container->setDefinition('flasher.toastr', $definition); - -if (Bridge::canLoadAliases()) { - $container->setAlias('Flasher\Toastr\Prime\ToastrFactory', 'flasher.toastr'); -} diff --git a/src/Toastr/Symfony/UPGRADING.md b/src/Toastr/Symfony/UPGRADING.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Toastr/Symfony/composer.json b/src/Toastr/Symfony/composer.json index 9ac9cc51..ecffc314 100644 --- a/src/Toastr/Symfony/composer.json +++ b/src/Toastr/Symfony/composer.json @@ -2,35 +2,21 @@ "name": "php-flasher/flasher-toastr-symfony", "type": "symfony-bundle", "description": "PHP Flasher Symfony adapter for Toastr", - "keywords": [ - "yoeunes", - "notify", - "php", - "laravel", - "symfony", - "Lumen", - "notifications", - "messages", - "alerts", - "pnotify", - "toastr ", - "bundle", - "flex" - ], - "homepage": "https://php-flasher.github.io/", + "keywords": ["yoeunes", "notify", "php", "laravel", "symfony", "Lumen", "notifications", "messages", "alerts", "pnotify", "toastr ", "bundle", "flex"], + "homepage": "https://php-flasher.io", "authors": [ { - "name": "Younes Khoubza", + "name": "Younes KHOUBZA", "email": "younes.khoubza@gmail.com", - "homepage": "https://github.com/yoeunes", + "homepage": "https://www.linkedin.com/in/younes-khoubza", "role": "Developer" } ], "license": "MIT", "require": { "php": ">=5.3", - "php-flasher/flasher-symfony": "^0.9", - "php-flasher/flasher-toastr": "^0.9" + "php-flasher/flasher-symfony": "^1.0", + "php-flasher/flasher-toastr": "^1.0" }, "autoload": { "psr-4": { @@ -40,6 +26,6 @@ "config": { "sort-packages": true }, - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true } diff --git a/tests/Laravel/Config/ConfigTest.php b/tests/Laravel/Config/ConfigTest.php deleted file mode 100644 index 9639752c..00000000 --- a/tests/Laravel/Config/ConfigTest.php +++ /dev/null @@ -1,23 +0,0 @@ -isLaravel4() ? '::' : '.'; - $config = new Config($this->app->make('config'), $separator); - - $this->assertEquals('template', $config->get('default')); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/Laravel/FlasherServiceProviderTest.php b/tests/Laravel/FlasherServiceProviderTest.php deleted file mode 100644 index 10b2cd72..00000000 --- a/tests/Laravel/FlasherServiceProviderTest.php +++ /dev/null @@ -1,45 +0,0 @@ -assertInstanceOf('Flasher\Laravel\Config\Config', $this->app->make('flasher.config')); - $this->assertInstanceOf('Flasher\Prime\Flasher', $this->app->make('flasher')); - $this->assertInstanceOf('Flasher\Prime\Response\ResponseManager', $this->app->make('flasher.response_manager')); - $this->assertInstanceOf( - 'Flasher\Prime\Response\Resource\ResourceManager', - $this->app->make('flasher.resource_manager') - ); - $this->assertInstanceOf('Flasher\Laravel\Storage\Storage', $this->app->make('flasher.storage')); - $this->assertInstanceOf('Flasher\Prime\Storage\StorageManager', $this->app->make('flasher.storage_manager')); - $this->assertInstanceOf( - 'Flasher\Prime\EventDispatcher\EventDispatcher', - $this->app->make('flasher.event_dispatcher') - ); - $this->assertInstanceOf('Flasher\Prime\Filter\Filter', $this->app->make('flasher.filter')); - } - - public function testBladeDirective() - { - /** @var BladeCompiler $blade */ - $blade = $this->app->make('view')->getEngineResolver()->resolve('blade')->getCompiler(); - - $this->assertEquals( - "render(); ?>", - $blade->compileString('@flasher_render()') - ); - $this->assertEquals( - "render(array()); ?>", - $blade->compileString('@flasher_render(array())') - ); - $this->assertEquals( - "render(array(\"priority\" => array(\"min\" => 4, \"max\" => 5))); ?>", - $blade->compileString('@flasher_render(array("priority" => array("min" => 4, "max" => 5)))') - ); - } -} diff --git a/tests/Laravel/ServiceProviderTest.php b/tests/Laravel/ServiceProviderTest.php new file mode 100644 index 00000000..accddec0 --- /dev/null +++ b/tests/Laravel/ServiceProviderTest.php @@ -0,0 +1,47 @@ + + */ + +namespace Flasher\Tests\Laravel; + +class ServiceProviderTest extends TestCase +{ + public function testContainerContainServices() + { + $this->assertTrue($this->app->bound('flasher')); + $this->assertTrue($this->app->bound('flasher.noty')); + $this->assertTrue($this->app->bound('flasher.notyf')); + $this->assertTrue($this->app->bound('flasher.pnotify')); + $this->assertTrue($this->app->bound('flasher.sweetalert')); + $this->assertTrue($this->app->bound('flasher.toastr')); + + $this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $this->app->make('flasher.noty')); + $this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $this->app->make('flasher.notyf')); + $this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $this->app->make('flasher.pnotify')); + $this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $this->app->make('flasher.sweetalert')); + $this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $this->app->make('flasher.toastr')); + } + + public function testFlasherCanCreateServicesFromAlias() + { + $flasher = $this->app->make('flasher'); + + $adapter = $flasher->create('noty'); + $this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $adapter); + + $adapter = $flasher->create('notyf'); + $this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $adapter); + + $adapter = $flasher->create('pnotify'); + $this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $adapter); + + $adapter = $flasher->create('sweetalert'); + $this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $adapter); + + $adapter = $flasher->create('toastr'); + $this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $adapter); + } +} diff --git a/tests/Laravel/Storage/StorageTest.php b/tests/Laravel/StorageTest.php similarity index 65% rename from tests/Laravel/Storage/StorageTest.php rename to tests/Laravel/StorageTest.php index 2a95ef1b..d816aa63 100644 --- a/tests/Laravel/Storage/StorageTest.php +++ b/tests/Laravel/StorageTest.php @@ -1,46 +1,51 @@ + */ -use Flasher\Laravel\Storage\Storage; -use Flasher\Tests\Laravel\TestCase; -use Flasher\Prime\Envelope; +namespace Flasher\Tests\Laravel; + +use Flasher\Laravel\Storage\SessionBag; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\Notification; use Flasher\Prime\Stamp\PriorityStamp; use Flasher\Prime\Stamp\UuidStamp; +use Flasher\Prime\Storage\StorageBag; final class StorageTest extends TestCase { public function testInitialState() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $this->assertEquals(array(), $storage->all()); } public function testAddEnvelope() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelope = new Envelope(new Notification()); $storage->add($envelope); - $this->assertEquals(array($envelope), $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelope), $storage->all()); } public function testAddMultipleEnvelopes() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification()), new Envelope(new Notification()), ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); } public function testUpdateEnvelopes() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification(), array( new UuidStamp(), @@ -51,12 +56,12 @@ final class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $envelopes[1]->withStamp(new PriorityStamp(1)); $storage->update($envelopes[1]); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $this->assertInstanceOf( 'Flasher\Prime\Stamp\PriorityStamp', $envelopes[1]->get('Flasher\Prime\Stamp\PriorityStamp') @@ -65,7 +70,7 @@ final class StorageTest extends TestCase public function testRemoveEnvelopes() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification(), array( new UuidStamp(), @@ -76,15 +81,15 @@ final class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->remove($envelopes[1]); - $this->assertEquals(array($envelopes[0]), $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes[0]), $storage->all()); } public function testRemoveMultipleEnvelopes() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification(), array( new UuidStamp(), @@ -95,7 +100,7 @@ final class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->remove($envelopes); $this->assertEquals(array(), $storage->all()); @@ -103,7 +108,7 @@ final class StorageTest extends TestCase public function testClearAllEnvelopes() { - $storage = new Storage($this->app->make('session')); + $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification(), array( new UuidStamp(), @@ -114,9 +119,14 @@ final class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->clear(); $this->assertEquals(array(), $storage->all()); } + + private function getStorage() + { + return new StorageBag(new SessionBag($this->app->make('session'))); + } } diff --git a/tests/Laravel/TestCase.php b/tests/Laravel/TestCase.php index e9fdb11c..88faeb87 100644 --- a/tests/Laravel/TestCase.php +++ b/tests/Laravel/TestCase.php @@ -1,12 +1,67 @@ + */ + namespace Flasher\Tests\Laravel; +use Illuminate\Config\Repository as Config; +use Illuminate\Foundation\AliasLoader; use Illuminate\Foundation\Application; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Facade; use Orchestra\Testbench\TestCase as Orchestra; class TestCase extends Orchestra { + public function createApplication() + { + if (0 !== strpos(Application::VERSION, '4.0')) { + return parent::createApplication(); + } + + $app = new Application(); + + $app->detectEnvironment(array( + 'local' => array('your-machine-name'), + )); + + $app->bindInstallPaths($this->getApplicationPaths()); + + $app['env'] = 'testing'; + + $app->instance('app', $app); + + Facade::clearResolvedInstances(); + Facade::setFacadeApplication($app); + + $config = new Config($app->getConfigLoader(), $app['env']); + $app->instance('config', $config); + $app->startExceptionHandling(); + + if ($app->runningInConsole()) { + $app->setRequestForConsoleEnvironment(); + } + + date_default_timezone_set($this->getApplicationTimezone()); + + $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); + AliasLoader::getInstance($aliases)->register(); + + Request::enableHttpMethodParameterOverride(); + + $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); + $app->getProviderRepository()->load($app, $providers); + + $this->getEnvironmentSetUp($app); + + $app->boot(); + + return $app; + } + /** * @param $app * @@ -16,6 +71,11 @@ class TestCase extends Orchestra { return array( 'Flasher\Laravel\FlasherServiceProvider', + 'Flasher\Noty\Laravel\FlasherNotyServiceProvider', + 'Flasher\Notyf\Laravel\FlasherNotyfServiceProvider', + 'Flasher\Pnotify\Laravel\FlasherPnotifyServiceProvider', + 'Flasher\SweetAlert\Laravel\FlasherSweetAlertServiceProvider', + 'Flasher\Toastr\Laravel\FlasherToastrServiceProvider', ); } @@ -24,6 +84,14 @@ class TestCase extends Orchestra */ protected function getEnvironmentSetUp($app) { + $separator = $this->isLaravel4() ? '::config' : ''; + $app['config']->set('session.driver', 'array'); + $app['config']->set('session'.$separator.'.driver', 'array'); + } + + private function isLaravel4() + { + return 0 === strpos(Application::VERSION, '4.'); } } diff --git a/tests/Noty/Laravel/FlasherNotyServiceProviderTest.php b/tests/Noty/Laravel/FlasherNotyServiceProviderTest.php deleted file mode 100644 index 2c86ecff..00000000 --- a/tests/Noty/Laravel/FlasherNotyServiceProviderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue($this->app->bound('flasher.noty')); - $this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $this->app->make('flasher.noty')); - } - - public function testNotifyFactoryIsAddedToExtensionsArray() - { - $flasher = $this->app->make('flasher'); - $adapter = $flasher->create('noty'); - - $this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $adapter); - } -} diff --git a/tests/Noty/Laravel/TestCase.php b/tests/Noty/Laravel/TestCase.php deleted file mode 100644 index 95e86b7b..00000000 --- a/tests/Noty/Laravel/TestCase.php +++ /dev/null @@ -1,87 +0,0 @@ -detectEnvironment(array( - 'local' => array('your-machine-name'), - )); - - $app->bindInstallPaths($this->getApplicationPaths()); - - $app['env'] = 'testing'; - - $app->instance('app', $app); - - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $config = new Config($app->getConfigLoader(), $app['env']); - $app->instance('config', $config); - $app->startExceptionHandling(); - - if ($app->runningInConsole()) { - $app->setRequestForConsoleEnvironment(); - } - - date_default_timezone_set($this->getApplicationTimezone()); - - $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); - AliasLoader::getInstance($aliases)->register(); - - Request::enableHttpMethodParameterOverride(); - - $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); - $app->getProviderRepository()->load($app, $providers); - - $this->getEnvironmentSetUp($app); - - $app->boot(); - - return $app; - } - - /** - * @param Application $app - * - * @return array - */ - protected function getPackageProviders($app = null) - { - return array( - 'Flasher\Laravel\FlasherServiceProvider', - 'Flasher\Noty\Laravel\FlasherNotyServiceProvider', - ); - } - - /** - * @param Application $app - */ - protected function getEnvironmentSetUp($app) - { - $separator = $this->isLaravel4() ? '::config' : ''; - - $app['config']->set('session' . $separator . '.driver', 'array'); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/Noty/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Noty/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 0c96f8ca..00000000 --- a/tests/Noty/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,41 +0,0 @@ -process(array()); - - $expected = array( - 'scripts' => array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-noty@0.1.3/dist/flasher-noty.min.js', - ), - 'styles' => array(), - 'options' => array( - 'timeout' => 5000, - ), - ); - - $this->assertEquals($expected, $config); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/Noty/Symfony/DependencyInjection/FlasherNotyExtensionTest.php b/tests/Noty/Symfony/DependencyInjection/FlasherNotyExtensionTest.php deleted file mode 100644 index 52be7f42..00000000 --- a/tests/Noty/Symfony/DependencyInjection/FlasherNotyExtensionTest.php +++ /dev/null @@ -1,67 +0,0 @@ -getContainer(); - - $this->assertTrue($container->has('flasher.noty')); - } - - public function testCreateInstanceOfNotyAdapter() - { - $container = $this->getContainer(); - - $flasher = $container->getDefinition('flasher'); - $calls = $flasher->getMethodCalls(); - - $this->assertCount(5, $calls); - - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('template', $calls[0][1][0]); - $this->assertEquals('flasher.template', (string) $calls[0][1][1]); - - $this->assertEquals('addFactory', $calls[4][0]); - $this->assertEquals('noty', $calls[4][1][0]); - $this->assertEquals('flasher.noty', (string) $calls[4][1][1]); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $container->registerExtension(new FlasherExtension()); - $flasherBundle = new FlasherSymfonyBundle(); - $flasherBundle->build($container); - - $container->registerExtension(new FlasherNotyExtension()); - $adapterBundle = new FlasherNotySymfonyBundle(); - $adapterBundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_noty', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Notyf/Laravel/FlasherNotyfServiceProviderTest.php b/tests/Notyf/Laravel/FlasherNotyfServiceProviderTest.php deleted file mode 100644 index da49c849..00000000 --- a/tests/Notyf/Laravel/FlasherNotyfServiceProviderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue($this->app->bound('flasher.notyf')); - $this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $this->app->make('flasher.notyf')); - } - - public function testNotifyFactoryIsAddedToExtensionsArray() - { - $flasher = $this->app->make('flasher'); - $adapter = $flasher->create('notyf'); - - $this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $adapter); - } -} diff --git a/tests/Notyf/Laravel/TestCase.php b/tests/Notyf/Laravel/TestCase.php deleted file mode 100644 index 15f3ce51..00000000 --- a/tests/Notyf/Laravel/TestCase.php +++ /dev/null @@ -1,87 +0,0 @@ -detectEnvironment(array( - 'local' => array('your-machine-name'), - )); - - $app->bindInstallPaths($this->getApplicationPaths()); - - $app['env'] = 'testing'; - - $app->instance('app', $app); - - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $config = new Config($app->getConfigLoader(), $app['env']); - $app->instance('config', $config); - $app->startExceptionHandling(); - - if ($app->runningInConsole()) { - $app->setRequestForConsoleEnvironment(); - } - - date_default_timezone_set($this->getApplicationTimezone()); - - $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); - AliasLoader::getInstance($aliases)->register(); - - Request::enableHttpMethodParameterOverride(); - - $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); - $app->getProviderRepository()->load($app, $providers); - - $this->getEnvironmentSetUp($app); - - $app->boot(); - - return $app; - } - - /** - * @param Application $app - * - * @return array - */ - protected function getPackageProviders($app = null) - { - return array( - 'Flasher\Laravel\FlasherServiceProvider', - 'Flasher\Notyf\Laravel\FlasherNotyfServiceProvider', - ); - } - - /** - * @param Application $app - */ - protected function getEnvironmentSetUp($app) - { - $separator = $this->isLaravel4() ? '::config' : ''; - - $app['config']->set('session' . $separator . '.driver', 'array'); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/Notyf/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Notyf/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 82588ba7..00000000 --- a/tests/Notyf/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,41 +0,0 @@ -process(array()); - - $expected = array( - 'scripts' => array( - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-notyf@0.1.8/dist/flasher-notyf.min.js', - ), - 'styles' => array(), - 'options' => array( - 'duration' => 5000, - ), - ); - - $this->assertEquals($expected, $config); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/Notyf/Symfony/DependencyInjection/FlasherNotyfExtensionTest.php b/tests/Notyf/Symfony/DependencyInjection/FlasherNotyfExtensionTest.php deleted file mode 100644 index b1083a60..00000000 --- a/tests/Notyf/Symfony/DependencyInjection/FlasherNotyfExtensionTest.php +++ /dev/null @@ -1,67 +0,0 @@ -getContainer(); - - $this->assertTrue($container->has('flasher.notyf')); - } - - public function testCreateInstanceOfNotyfAdapter() - { - $container = $this->getContainer(); - - $flasher = $container->getDefinition('flasher'); - $calls = $flasher->getMethodCalls(); - - $this->assertCount(5, $calls); - - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('template', $calls[0][1][0]); - $this->assertEquals('flasher.template', (string) $calls[0][1][1]); - - $this->assertEquals('addFactory', $calls[4][0]); - $this->assertEquals('notyf', $calls[4][1][0]); - $this->assertEquals('flasher.notyf', (string) $calls[4][1][1]); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $container->registerExtension(new FlasherExtension()); - $flasherBundle = new FlasherSymfonyBundle(); - $flasherBundle->build($container); - - $container->registerExtension(new FlasherNotyfExtension()); - $adapterBundle = new FlasherNotyfSymfonyBundle(); - $adapterBundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_notyf', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Pnotify/Laravel/FlasherPnotifyServiceProviderTest.php b/tests/Pnotify/Laravel/FlasherPnotifyServiceProviderTest.php deleted file mode 100644 index e36f4356..00000000 --- a/tests/Pnotify/Laravel/FlasherPnotifyServiceProviderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue($this->app->bound('flasher.pnotify')); - $this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $this->app->make('flasher.pnotify')); - } - - public function testNotifyFactoryIsAddedToExtensionsArray() - { - $flasher = $this->app->make('flasher'); - $adapter = $flasher->create('pnotify'); - - $this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $adapter); - } -} diff --git a/tests/Pnotify/Laravel/TestCase.php b/tests/Pnotify/Laravel/TestCase.php deleted file mode 100644 index 8aecc2be..00000000 --- a/tests/Pnotify/Laravel/TestCase.php +++ /dev/null @@ -1,87 +0,0 @@ -detectEnvironment(array( - 'local' => array('your-machine-name'), - )); - - $app->bindInstallPaths($this->getApplicationPaths()); - - $app['env'] = 'testing'; - - $app->instance('app', $app); - - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $config = new Config($app->getConfigLoader(), $app['env']); - $app->instance('config', $config); - $app->startExceptionHandling(); - - if ($app->runningInConsole()) { - $app->setRequestForConsoleEnvironment(); - } - - date_default_timezone_set($this->getApplicationTimezone()); - - $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); - AliasLoader::getInstance($aliases)->register(); - - Request::enableHttpMethodParameterOverride(); - - $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); - $app->getProviderRepository()->load($app, $providers); - - $this->getEnvironmentSetUp($app); - - $app->boot(); - - return $app; - } - - /** - * @param Application $app - * - * @return array - */ - protected function getPackageProviders($app = null) - { - return array( - 'Flasher\Laravel\FlasherServiceProvider', - 'Flasher\Pnotify\Laravel\FlasherPnotifyServiceProvider', - ); - } - - /** - * @param Application $app - */ - protected function getEnvironmentSetUp($app) - { - $separator = $this->isLaravel4() ? '::config' : ''; - - $app['config']->set('session' . $separator . '.driver', 'array'); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/Pnotify/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Pnotify/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 961fe19a..00000000 --- a/tests/Pnotify/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,42 +0,0 @@ -process(array()); - - $expected = array( - 'scripts' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-pnotify@0.1.1/dist/flasher-pnotify.min.js', - ), - 'styles' => array(), - 'options' => array( - 'delay' => 1000, - ), - ); - - $this->assertEquals($expected, $config); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtensionTest.php b/tests/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtensionTest.php deleted file mode 100644 index d15bf299..00000000 --- a/tests/Pnotify/Symfony/DependencyInjection/FlasherPnotifyExtensionTest.php +++ /dev/null @@ -1,67 +0,0 @@ -getContainer(); - - $this->assertTrue($container->has('flasher.pnotify')); - } - - public function testCreateInstanceOfPnotifyAdapter() - { - $container = $this->getContainer(); - - $flasher = $container->getDefinition('flasher'); - $calls = $flasher->getMethodCalls(); - - $this->assertCount(5, $calls); - - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('template', $calls[0][1][0]); - $this->assertEquals('flasher.template', (string) $calls[0][1][1]); - - $this->assertEquals('addFactory', $calls[4][0]); - $this->assertEquals('pnotify', $calls[4][1][0]); - $this->assertEquals('flasher.pnotify', (string) $calls[4][1][1]); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $container->registerExtension(new FlasherExtension()); - $flasherBundle = new FlasherSymfonyBundle(); - $flasherBundle->build($container); - - $container->registerExtension(new FlasherPnotifyExtension()); - $adapterBundle = new FlasherPnotifySymfonyBundle(); - $adapterBundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_pnotify', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Prime/Config/ConfigTest.php b/tests/Prime/Config/ConfigTest.php index 35defcc1..487801ce 100644 --- a/tests/Prime/Config/ConfigTest.php +++ b/tests/Prime/Config/ConfigTest.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Tests\Prime\Config; use Flasher\Prime\Config\Config; @@ -33,7 +38,7 @@ final class ConfigTest extends TestCase ); $this->assertEquals(array('styles.css'), $config->get('drivers.toastr.styles')); $this->assertEquals(array(), $config->get('drivers.toastr.options')); - $this->assertEquals(null, $config->get('drivers.not_exists.options')); + $this->assertNull($config->get('drivers.not_exists.options')); $this->assertEquals('now_it_exists', $config->get('drivers.not_exists.options', 'now_it_exists')); } } diff --git a/tests/Prime/Envelope/EnvelopeTest.php b/tests/Prime/Envelope/EnvelopeTest.php index 62ae96cc..fed8626f 100644 --- a/tests/Prime/Envelope/EnvelopeTest.php +++ b/tests/Prime/Envelope/EnvelopeTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use PHPUnit\Framework\TestCase; final class EnvelopeTest extends TestCase @@ -16,7 +21,7 @@ final class EnvelopeTest extends TestCase $this->assertEquals($notification, $envelope->getNotification()); $this->assertEquals(array( - get_class($stamp) => $stamp, + \get_class($stamp) => $stamp, ), $envelope->all()); } @@ -31,8 +36,8 @@ final class EnvelopeTest extends TestCase $this->assertEquals($notification, $envelope->getNotification()); $this->assertEquals(array( - get_class($stamp1) => $stamp1, - get_class($stamp2) => $stamp2, + \get_class($stamp1) => $stamp1, + \get_class($stamp2) => $stamp2, ), $envelope->all()); } @@ -45,7 +50,7 @@ final class EnvelopeTest extends TestCase $this->assertEquals($notification, $envelope->getNotification()); $this->assertEquals(array( - get_class($stamp) => $stamp, + \get_class($stamp) => $stamp, ), $envelope->all()); } @@ -63,7 +68,7 @@ final class EnvelopeTest extends TestCase $this->assertEquals($notification, $envelope->getNotification()); $this->assertEquals(array( - get_class($stamps[0]) => $stamps[3], + \get_class($stamps[0]) => $stamps[3], ), $envelope->all()); } @@ -80,10 +85,10 @@ final class EnvelopeTest extends TestCase $this->assertEquals($notification, $envelope->getNotification()); - $last = $envelope->get(get_class($stamps[0])); + $last = $envelope->get(\get_class($stamps[0])); $this->assertEquals($stamps[2], $last); - $this->assertEquals($last, $envelope->get(get_class($stamps[0]))); + $this->assertEquals($last, $envelope->get(\get_class($stamps[0]))); $this->assertNull($envelope->get('NotFoundStamp')); } diff --git a/tests/Prime/Envelope/Stamp/CreatedAtStampTest.php b/tests/Prime/Envelope/Stamp/CreatedAtStampTest.php index c822bb72..7b41fb99 100644 --- a/tests/Prime/Envelope/Stamp/CreatedAtStampTest.php +++ b/tests/Prime/Envelope/Stamp/CreatedAtStampTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\CreatedAtStamp; use Flasher\Prime\Stamp\HopsStamp; use PHPUnit\Framework\TestCase; diff --git a/tests/Prime/Envelope/Stamp/HandlerStampTest.php b/tests/Prime/Envelope/Stamp/HandlerStampTest.php index 359ae40a..f167a378 100644 --- a/tests/Prime/Envelope/Stamp/HandlerStampTest.php +++ b/tests/Prime/Envelope/Stamp/HandlerStampTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HandlerStamp; use PHPUnit\Framework\TestCase; diff --git a/tests/Prime/Envelope/Stamp/HopsStampTest.php b/tests/Prime/Envelope/Stamp/HopsStampTest.php index 151a56ac..cef86010 100644 --- a/tests/Prime/Envelope/Stamp/HopsStampTest.php +++ b/tests/Prime/Envelope/Stamp/HopsStampTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HopsStamp; use PHPUnit\Framework\TestCase; diff --git a/tests/Prime/Envelope/Stamp/PriorityStampTest.php b/tests/Prime/Envelope/Stamp/PriorityStampTest.php index d09b5956..f075aeba 100644 --- a/tests/Prime/Envelope/Stamp/PriorityStampTest.php +++ b/tests/Prime/Envelope/Stamp/PriorityStampTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\HopsStamp; use Flasher\Prime\Stamp\PriorityStamp; use PHPUnit\Framework\TestCase; diff --git a/tests/Prime/Envelope/Stamp/UuidStampTest.php b/tests/Prime/Envelope/Stamp/UuidStampTest.php index d3caeabd..feae92f9 100644 --- a/tests/Prime/Envelope/Stamp/UuidStampTest.php +++ b/tests/Prime/Envelope/Stamp/UuidStampTest.php @@ -1,8 +1,13 @@ + */ + namespace Flasher\Tests\Prime\Envelope\Stamp; -use Flasher\Prime\Envelope; +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Stamp\UuidStamp; use PHPUnit\Framework\TestCase; diff --git a/tests/Prime/EventDispatcher/EventDispatcherTest.php b/tests/Prime/EventDispatcher/EventDispatcherTest.php index 61c33ac0..8e5028ee 100644 --- a/tests/Prime/EventDispatcher/EventDispatcherTest.php +++ b/tests/Prime/EventDispatcher/EventDispatcherTest.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Tests\Prime\EventDispatcher; use Flasher\Prime\EventDispatcher\Event\StoppableEventInterface; @@ -9,7 +14,7 @@ use Flasher\Tests\Prime\TestCase; class EventDispatcherTest extends TestCase { - /* Some pseudo events */ + // Some pseudo events const preFoo = 'pre.foo'; const postFoo = 'post.foo'; @@ -35,30 +40,6 @@ class EventDispatcherTest extends TestCase $this->assertCount(1, $dispatcher->getListeners(self::postFoo)); } - public function testGetListenersSortsByPriority() - { - $dispatcher = new EventDispatcher(); - - $listener1 = new TestEventListener(); - $listener2 = new TestEventListener(); - $listener3 = new TestEventListener(); - $listener1->name = '1'; - $listener2->name = '2'; - $listener3->name = '3'; - - $dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10); - $dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10); - $dispatcher->addListener('pre.foo', array($listener3, 'preFoo')); - - $expected = array( - array($listener2, 'preFoo'), - array($listener3, 'preFoo'), - array($listener1, 'preFoo'), - ); - - $this->assertEquals($expected, $dispatcher->getListeners('pre.foo')); - } - public function testDispatch() { $dispatcher = new EventDispatcher(); @@ -110,29 +91,6 @@ class EventDispatcherTest extends TestCase $this->assertTrue($listener->postFooInvoked); $this->assertFalse($otherListener->postFooInvoked); } - - public function testDispatchByPriority() - { - $dispatcher = new EventDispatcher(); - - $event = new Event(); - - $invoked = array(); - $listener1 = function () use (&$invoked) { - $invoked[] = '1'; - }; - $listener2 = function () use (&$invoked) { - $invoked[] = '2'; - }; - $listener3 = function () use (&$invoked) { - $invoked[] = '3'; - }; - $dispatcher->addListener('Flasher\Tests\Prime\EventDispatcher\Event', $listener1, -10); - $dispatcher->addListener('Flasher\Tests\Prime\EventDispatcher\Event', $listener2); - $dispatcher->addListener('Flasher\Tests\Prime\EventDispatcher\Event', $listener3, 10); - $dispatcher->dispatch($event); - $this->assertEquals(array('3', '2', '1'), $invoked); - } } class Event implements StoppableEventInterface diff --git a/tests/Prime/Filter/CriteriaBuilderTest.php b/tests/Prime/Filter/CriteriaBuilderTest.php deleted file mode 100644 index f985cc08..00000000 --- a/tests/Prime/Filter/CriteriaBuilderTest.php +++ /dev/null @@ -1,31 +0,0 @@ - 1, - 'life' => 2, - 'limit' => 2, - 'order_by' => 'Flasher\Prime\Stamp\HopsStamp', - )); - - $this->assertInstanceOf('Flasher\Prime\Filter\FilterBuilder', $criteria->build()); - $this->assertNotEmpty($criteria->build()->getSpecification()); - } - - public function testWithoutPriority() - { - $criteria = new CriteriaBuilder(new FilterBuilder(), array()); - - $this->assertInstanceOf('Flasher\Prime\Filter\FilterBuilder', $criteria->build()); - $this->assertEmpty($criteria->build()->getSpecification()); - } -} diff --git a/tests/Prime/Filter/FilterBuilderTest.php b/tests/Prime/Filter/FilterBuilderTest.php deleted file mode 100644 index 60eb9003..00000000 --- a/tests/Prime/Filter/FilterBuilderTest.php +++ /dev/null @@ -1,92 +0,0 @@ -filter($envelopes); - $expected = $envelopes; - - $this->assertEquals($expected, $filtered); - } - - public function testMaxResults() - { - $envelopes = array( - new Envelope(new Notification()), - new Envelope(new Notification()), - new Envelope(new Notification()), - ); - - $builder = new FilterBuilder(); - $builder->setMaxResults(2); - - $filtered = $builder->filter($envelopes); - $expected = array_slice($envelopes, 0, 2); - - $this->assertEquals($expected, $filtered); - } - - public function testOrderingByPriority() - { - $envelopes = array( - 0 => new Envelope(new Notification(), array( - new PriorityStamp(5), - new CreatedAtStamp(), - )), - 1 => new Envelope(new Notification(), array( - new PriorityStamp(4), - )), - 2 => new Envelope(new Notification(), array( - new PriorityStamp(-2), - )), - 3 => new Envelope(new Notification(), array( - new CreatedAtStamp(), - )), - 4 => new Envelope(new Notification(), array( - new PriorityStamp(7), - )), - 5 => new Envelope(new Notification(), array( - new PriorityStamp(6), - )), - 6 => new Envelope(new Notification(), array( - new PriorityStamp(-1), - )), - ); - - $builder = new FilterBuilder(); - $builder->orderBy(array( - 'Flasher\Prime\Stamp\PriorityStamp' => FilterBuilder::ASC, - )); - - $filtered = $builder->filter($envelopes); - $expected = array( - $envelopes[3], - $envelopes[2], - $envelopes[6], - $envelopes[1], - $envelopes[0], - $envelopes[5], - $envelopes[4], - ); - - $this->assertEquals($expected, $filtered); - } -} diff --git a/tests/Prime/Storage/ArrayStorageTest.php b/tests/Prime/Storage/ArrayStorageTest.php deleted file mode 100644 index 57d33293..00000000 --- a/tests/Prime/Storage/ArrayStorageTest.php +++ /dev/null @@ -1,71 +0,0 @@ -add($envelopes[$index]); - } - - $this->assertCount(5, $storage->all()); - } - - public function testAddNotificationWithUuidStamp() - { - $storage = new ArrayStorage(); - $storage->add(new Envelope(new Notification())); - - $envelopes = $storage->all(); - - $this->assertCount(1, $envelopes); - - $uuid = $envelopes[0]->get('Flasher\Prime\Stamp\UuidStamp'); - $this->assertNull($uuid); - } - - public function testClear() - { - $storage = new ArrayStorage(); - $envelopes = array(); - - foreach (range(0, 4) as $index) { - $envelopes[$index] = new Envelope(new Notification()); - $storage->add($envelopes[$index]); - } - - $storage->clear(); - - $this->assertEquals(array(), $storage->all()); - } - - public function testRemove() - { - $storage = new ArrayStorage(); - $envelopes = array(); - - foreach (range(0, 4) as $index) { - $envelopes[$index] = new Envelope(new Notification(), new UuidStamp()); - $storage->add($envelopes[$index]); - } - - $storage->remove($envelopes[0], $envelopes[2]); - - $actual = UuidStamp::indexByUuid($storage->all()); - $expected = UuidStamp::indexByUuid($envelopes[1], $envelopes[3], $envelopes[4]); - - $this->assertEquals(array(), array_diff_key($actual, $expected)); - } -} diff --git a/tests/Prime/Storage/StorageManagerTest.php b/tests/Prime/Storage/StorageManagerTest.php deleted file mode 100644 index e0e91bdb..00000000 --- a/tests/Prime/Storage/StorageManagerTest.php +++ /dev/null @@ -1,54 +0,0 @@ -add($envelopes[$index]); - } - - $this->assertCount(5, $storageManager->all()); - } - - public function testClear() - { - $storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher()); - $envelopes = array(); - - foreach (range(0, 4) as $index) { - $envelopes[$index] = new Envelope(new Notification()); - $storageManager->add($envelopes[$index]); - } - - $storageManager->clear(); - - $this->assertEquals(array(), $storageManager->all()); - } - - public function testAdd() - { - $storageManager = new StorageManager(new ArrayStorage(), new EventDispatcher()); - $storageManager->add(new Envelope(new Notification())); - - $envelopes = $storageManager->all(); - - $this->assertCount(1, $envelopes); - - $uuid = $envelopes[0]->get('Flasher\Prime\Stamp\UuidStamp'); - $this->assertNull($uuid); - } -} diff --git a/tests/Prime/TestCase.php b/tests/Prime/TestCase.php index 8e837857..3e6f5245 100644 --- a/tests/Prime/TestCase.php +++ b/tests/Prime/TestCase.php @@ -1,5 +1,10 @@ + */ + namespace Flasher\Tests\Prime; use ReflectionClass; @@ -19,21 +24,21 @@ class TestCase extends \PHPUnit\Framework\TestCase /** * Call protected/private method of a class. * - * @param object $object Instantiated object that we will run method on. - * @param string $methodName Method name to call. - * @param array|mixed $parameters array of parameters to pass into method. - * - * @return mixed method return + * @param object $object instantiated object that we will run method on + * @param string $methodName method name to call + * @param array|mixed $parameters array of parameters to pass into method * * @throws \ReflectionException + * + * @return mixed method return */ protected function callMethod(&$object, $methodName, $parameters = array()) { - $reflection = new ReflectionClass(get_class($object)); + $reflection = new ReflectionClass(\get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); - $parameters = is_array($parameters) ? $parameters : array_slice(func_get_args(), 2); + $parameters = \is_array($parameters) ? $parameters : \array_slice(\func_get_args(), 2); return $method->invokeArgs($object, $parameters); } diff --git a/tests/SweetAlert/Laravel/FlasherSweetAlertServiceProviderTest.php b/tests/SweetAlert/Laravel/FlasherSweetAlertServiceProviderTest.php deleted file mode 100644 index ca14f64f..00000000 --- a/tests/SweetAlert/Laravel/FlasherSweetAlertServiceProviderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue($this->app->bound('flasher.sweet_alert')); - $this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $this->app->make('flasher.sweet_alert')); - } - - public function testNotifyFactoryIsAddedToExtensionsArray() - { - $flasher = $this->app->make('flasher'); - $adapter = $flasher->create('sweet_alert'); - - $this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $adapter); - } -} diff --git a/tests/SweetAlert/Laravel/TestCase.php b/tests/SweetAlert/Laravel/TestCase.php deleted file mode 100644 index 0356d552..00000000 --- a/tests/SweetAlert/Laravel/TestCase.php +++ /dev/null @@ -1,87 +0,0 @@ -detectEnvironment(array( - 'local' => array('your-machine-name'), - )); - - $app->bindInstallPaths($this->getApplicationPaths()); - - $app['env'] = 'testing'; - - $app->instance('app', $app); - - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $config = new Config($app->getConfigLoader(), $app['env']); - $app->instance('config', $config); - $app->startExceptionHandling(); - - if ($app->runningInConsole()) { - $app->setRequestForConsoleEnvironment(); - } - - date_default_timezone_set($this->getApplicationTimezone()); - - $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); - AliasLoader::getInstance($aliases)->register(); - - Request::enableHttpMethodParameterOverride(); - - $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); - $app->getProviderRepository()->load($app, $providers); - - $this->getEnvironmentSetUp($app); - - $app->boot(); - - return $app; - } - - /** - * @param Application $app - * - * @return array - */ - protected function getPackageProviders($app = null) - { - return array( - 'Flasher\Laravel\FlasherServiceProvider', - 'Flasher\SweetAlert\Laravel\FlasherSweetAlertServiceProvider', - ); - } - - /** - * @param Application $app - */ - protected function getEnvironmentSetUp($app) - { - $separator = $this->isLaravel4() ? '::config' : ''; - - $app['config']->set('session' . $separator . '.driver', 'array'); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/SweetAlert/Symfony/DependencyInjection/ConfigurationTest.php b/tests/SweetAlert/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index ad5a8a31..00000000 --- a/tests/SweetAlert/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,43 +0,0 @@ -process(array()); - - $expected = array( - 'scripts' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-sweet-alert@0.2.1/dist/flasher-sweet-alert.min.js', - ), - 'styles' => array(), - 'options' => array( - 'timer' => 5000, - 'timerProgressBar' => true, - ), - ); - - $this->assertEquals($expected, $config); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtensionTest.php b/tests/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtensionTest.php deleted file mode 100644 index 5ed872c5..00000000 --- a/tests/SweetAlert/Symfony/DependencyInjection/FlasherSweetAlertExtensionTest.php +++ /dev/null @@ -1,67 +0,0 @@ -getContainer(); - - $this->assertTrue($container->has('flasher.sweet_alert')); - } - - public function testCreateInstanceOfSweetAlertAdapter() - { - $container = $this->getContainer(); - - $flasher = $container->getDefinition('flasher'); - $calls = $flasher->getMethodCalls(); - - $this->assertCount(5, $calls); - - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('template', $calls[0][1][0]); - $this->assertEquals('flasher.template', (string) $calls[0][1][1]); - - $this->assertEquals('addFactory', $calls[4][0]); - $this->assertEquals('sweet_alert', $calls[4][1][0]); - $this->assertEquals('flasher.sweet_alert', (string) $calls[4][1][1]); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $container->registerExtension(new FlasherExtension()); - $flasherBundle = new FlasherSymfonyBundle(); - $flasherBundle->build($container); - - $container->registerExtension(new FlasherSweetAlertExtension()); - $adapterBundle = new FlasherSweetAlertSymfonyBundle(); - $adapterBundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_sweet_alert', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php b/tests/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php deleted file mode 100644 index 8abe02a9..00000000 --- a/tests/Symfony/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php +++ /dev/null @@ -1,63 +0,0 @@ -getContainer(); - - $this->assertTrue($container->hasDefinition('test_subscriber')); - - $flasher = $container->getDefinition('test_subscriber'); - $this->assertTrue($flasher->hasTag('flasher.event_subscriber')); - - $manager = $container->getDefinition('flasher.event_dispatcher'); - $calls = $manager->getMethodCalls(); - - $this->assertCount(4, $calls); - - $this->assertEquals('addSubscriber', $calls[0][0]); - $this->assertEquals('test_subscriber', $calls[0][1][0]); - - $this->assertEquals('addSubscriber', $calls[1][0]); - $this->assertEquals('flasher.event_listener.filter_listener', $calls[1][1][0]); - - $this->assertEquals('addSubscriber', $calls[2][0]); - $this->assertEquals('flasher.event_listener.post_flush_listener', $calls[2][1][0]); - - $this->assertEquals('addSubscriber', $calls[3][0]); - $this->assertEquals('flasher.event_listener.stamps_listener', $calls[3][1][0]); - } - - private function getContainer() - { - $container = new ContainerBuilder(); - - $flasher = new Definition('test_subscriber'); - $flasher->addTag('flasher.event_subscriber'); - $container->setDefinition('test_subscriber', $flasher); - - $extension = new FlasherExtension(); - $container->registerExtension($extension); - - $bundle = new FlasherSymfonyBundle(); - $bundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - $container->loadFromExtension('flasher', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Symfony/DependencyInjection/Compiler/FactoryCompilerPassTest.php b/tests/Symfony/DependencyInjection/Compiler/FactoryCompilerPassTest.php deleted file mode 100644 index d7d33ce7..00000000 --- a/tests/Symfony/DependencyInjection/Compiler/FactoryCompilerPassTest.php +++ /dev/null @@ -1,55 +0,0 @@ -getContainer(); - - $this->assertTrue($container->hasDefinition('test_flasher')); - - $flasher = $container->getDefinition('test_flasher'); - $this->assertTrue($flasher->hasTag('flasher.factory')); - - $manager = $container->getDefinition('flasher'); - $calls = $manager->getMethodCalls(); - - $this->assertCount(5, $calls); - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('test_flasher', $calls[0][1][0]); - } - - private function getContainer() - { - $container = new ContainerBuilder(); - - $flasher = new Definition('test_flasher'); - $flasher->addTag('flasher.factory', array( - 'alias' => 'test_flasher', - )); - $container->setDefinition('test_flasher', $flasher); - - $extension = new FlasherExtension(); - $container->registerExtension($extension); - - $bundle = new FlasherSymfonyBundle(); - $bundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - $container->loadFromExtension('flasher', array()); - $container->compile(); - - return $container; - } -} diff --git a/tests/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index b34515a5..00000000 --- a/tests/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,92 +0,0 @@ -process(array()); - - $expected = array( - 'default' => 'template', - 'root_script' => 'https://cdn.jsdelivr.net/npm/@flasher/flasher@0.7.1/dist/flasher.min.js', - 'root_scripts' => array(), - 'template_factory' => array( - 'default' => 'tailwindcss', - 'templates' => array( - 'tailwindcss' => array( - 'view' => Configuration::getTemplate('tailwindcss.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'tailwindcss_bg' => array( - 'view' => Configuration::getTemplate('tailwindcss_bg.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/base.min.css', - 'https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.11/utilities.css', - ), - ), - 'bootstrap' => array( - 'view' => Configuration::getTemplate('bootstrap.html.twig'), - 'styles' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css', - ), - ), - ), - ), - 'auto_create_from_session' => true, - 'types_mapping' => array( - 'success' => array( - 'success', - ), - 'error' => array( - 'error', - 'danger', - ), - 'warning' => array( - 'warning', - 'alarm', - ), - 'info' => array( - 'info', - 'notice', - 'alert', - ), - ), - ); - - $this->assertEquals($expected, $config); - } - - public function testEmptyDefault() - { - $this->setExpectedException( - '\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', - 'The path "flasher.default" cannot contain an empty value, but got "".' - ); - $this->process(array(array( - 'default' => '', - ))); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/Symfony/DependencyInjection/FlasherExtensionTest.php b/tests/Symfony/DependencyInjection/FlasherExtensionTest.php deleted file mode 100644 index 61ed4d23..00000000 --- a/tests/Symfony/DependencyInjection/FlasherExtensionTest.php +++ /dev/null @@ -1,45 +0,0 @@ -getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->compile(); - - $this->assertTrue($container->has('flasher')); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $extension = new FlasherExtension(); - $container->registerExtension($extension); - - $bundle = new FlasherSymfonyBundle(); - $bundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->compile(); - - return $container; - } -} diff --git a/tests/Symfony/FlasherExtensionTest.php b/tests/Symfony/FlasherExtensionTest.php new file mode 100644 index 00000000..810aa4af --- /dev/null +++ b/tests/Symfony/FlasherExtensionTest.php @@ -0,0 +1,91 @@ + + */ + +namespace Flasher\Tests\Symfony; + +use Flasher\Noty\Prime\NotyPlugin; +use Flasher\Noty\Symfony\FlasherNotySymfonyBundle; +use Flasher\Notyf\Prime\NotyfPlugin; +use Flasher\Notyf\Symfony\FlasherNotyfSymfonyBundle; +use Flasher\Pnotify\Prime\PnotifyPlugin; +use Flasher\Pnotify\Symfony\FlasherPnotifySymfonyBundle; +use Flasher\SweetAlert\Prime\SweetAlertPlugin; +use Flasher\SweetAlert\Symfony\FlasherSweetAlertSymfonyBundle; +use Flasher\Symfony\DependencyInjection\FlasherExtension; +use Flasher\Symfony\FlasherSymfonyBundle; +use Flasher\Symfony\Support\Extension; +use Flasher\Tests\Prime\TestCase; +use Flasher\Toastr\Prime\ToastrPlugin; +use Flasher\Toastr\Symfony\FlasherToastrSymfonyBundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class FlasherExtensionTest extends TestCase +{ + public function testContainerContainFlasherServices() + { + $container = $this->getContainer(); + + $this->assertTrue($container->has('flasher')); + $this->assertTrue($container->has('flasher.noty')); + $this->assertTrue($container->has('flasher.notyf')); + $this->assertTrue($container->has('flasher.pnotify')); + $this->assertTrue($container->has('flasher.sweetalert')); + $this->assertTrue($container->has('flasher.toastr')); + } + + private function getContainer() + { + $container = new ContainerBuilder(); + $container->registerExtension(new FlasherExtension()); + + $plugins = array( + new NotyPlugin(), + new NotyfPlugin(), + new PnotifyPlugin(), + new SweetAlertPlugin(), + new ToastrPlugin(), + ); + + foreach ($plugins as $plugin) { + $container->registerExtension(new Extension($plugin)); + } + + $bundles = array( + new FlasherSymfonyBundle(), + new FlasherNotySymfonyBundle(), + new FlasherNotyfSymfonyBundle(), + new FlasherPnotifySymfonyBundle(), + new FlasherSweetAlertSymfonyBundle(), + new FlasherToastrSymfonyBundle(), + ); + + foreach ($bundles as $bundle) { + $bundle->build($container); + } + + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); + + $extensions = array( + 'flasher', + 'flasher_noty', + 'flasher_notyf', + 'flasher_pnotify', + 'flasher_sweetalert', + 'flasher_toastr', + ); + + foreach ($extensions as $extension) { + $container->loadFromExtension($extension, array()); + } + + $container->compile(); + + return $container; + } +} diff --git a/tests/Symfony/Storage/StorageTest.php b/tests/Symfony/StorageTest.php similarity index 74% rename from tests/Symfony/Storage/StorageTest.php rename to tests/Symfony/StorageTest.php index afbe94c7..a84f21a4 100644 --- a/tests/Symfony/Storage/StorageTest.php +++ b/tests/Symfony/StorageTest.php @@ -1,12 +1,18 @@ + */ -use Flasher\Prime\Envelope; +namespace Flasher\Tests\Symfony; + +use Flasher\Prime\Notification\Envelope; use Flasher\Prime\Notification\Notification; use Flasher\Prime\Stamp\PriorityStamp; use Flasher\Prime\Stamp\UuidStamp; -use Flasher\Symfony\Storage\Storage; +use Flasher\Prime\Storage\StorageBag; +use Flasher\Symfony\Storage\SessionBag; use Flasher\Tests\Prime\TestCase; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -22,23 +28,27 @@ class StorageTest extends TestCase public function testAddEnvelope() { - $storage = $this->getStorage(); + $uuid = new UuidStamp(); $envelope = new Envelope(new Notification()); + $envelope->withStamp($uuid); + + $storage = $this->getStorage(); $storage->add($envelope); - $this->assertEquals(array($envelope), $storage->all()); + $this->assertEquals(array($uuid->getUuid() => $envelope), $storage->all()); } public function testAddMultipleEnvelopes() { - $storage = $this->getStorage(); $envelopes = array( new Envelope(new Notification()), new Envelope(new Notification()), ); + $storage = $this->getStorage(); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); } public function testUpdateEnvelopes() @@ -54,12 +64,12 @@ class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $envelopes[1]->withStamp(new PriorityStamp(1)); $storage->update($envelopes[1]); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $this->assertInstanceOf( 'Flasher\Prime\Stamp\PriorityStamp', $envelopes[1]->get('Flasher\Prime\Stamp\PriorityStamp') @@ -79,10 +89,10 @@ class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->remove($envelopes[1]); - $this->assertEquals(array($envelopes[0]), $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid(array($envelopes[0])), $storage->all()); } public function testRemoveMultipleEnvelopes() @@ -98,7 +108,7 @@ class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->remove($envelopes); $this->assertEquals(array(), $storage->all()); @@ -117,7 +127,7 @@ class StorageTest extends TestCase ); $storage->add($envelopes); - $this->assertEquals($envelopes, $storage->all()); + $this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all()); $storage->clear(); $this->assertEquals(array(), $storage->all()); @@ -127,8 +137,8 @@ class StorageTest extends TestCase { $session = class_exists('Symfony\Component\HttpFoundation\Session\Session') ? new Session(new MockArraySessionStorage()) - : new \Symfony\Component\HttpFoundation\Session(new ArraySessionStorage()); + : new \Symfony\Component\HttpFoundation\Session(new ArraySessionStorage()); // @phpstan-ignore-line - return new Storage($session); + return new StorageBag(new SessionBag($session)); } } diff --git a/tests/Symfony/Twig/FlasherTwigExtensionTest.php b/tests/Symfony/Twig/FlasherTwigExtensionTest.php deleted file mode 100644 index 7ed1764c..00000000 --- a/tests/Symfony/Twig/FlasherTwigExtensionTest.php +++ /dev/null @@ -1,38 +0,0 @@ -toastr.success('success title')"; - - $responseManager = $this->getMockBuilder('Flasher\Prime\Response\ResponseManagerInterface')->getMock(); - $responseManager->method('render')->willReturn($expected); - - $this->assertEquals($expected, $this->render('{{ flasher_render() }}', $responseManager)); - } - - private function render($template, ResponseManagerInterface $renderer) - { - $twig = new Environment(new ArrayLoader(array( - 'template' => $template, - )), array( - 'debug' => true, - 'cache' => false, - 'autoescape' => 'html', - 'optimizations' => 0, - )); - - $twig->addExtension(new FlasherTwigExtension($renderer)); - - return $twig->render('template'); - } -} diff --git a/tests/Toastr/Laravel/FlasherToastrServiceProviderTest.php b/tests/Toastr/Laravel/FlasherToastrServiceProviderTest.php deleted file mode 100644 index c8a6aa99..00000000 --- a/tests/Toastr/Laravel/FlasherToastrServiceProviderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue($this->app->bound('flasher.toastr')); - $this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $this->app->make('flasher.toastr')); - } - - public function testNotifyFactoryIsAddedToExtensionsArray() - { - $flasher = $this->app->make('flasher'); - $adapter = $flasher->create('toastr'); - - $this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $adapter); - } -} diff --git a/tests/Toastr/Laravel/TestCase.php b/tests/Toastr/Laravel/TestCase.php deleted file mode 100644 index 62bbeb68..00000000 --- a/tests/Toastr/Laravel/TestCase.php +++ /dev/null @@ -1,87 +0,0 @@ -detectEnvironment(array( - 'local' => array('your-machine-name'), - )); - - $app->bindInstallPaths($this->getApplicationPaths()); - - $app['env'] = 'testing'; - - $app->instance('app', $app); - - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $config = new Config($app->getConfigLoader(), $app['env']); - $app->instance('config', $config); - $app->startExceptionHandling(); - - if ($app->runningInConsole()) { - $app->setRequestForConsoleEnvironment(); - } - - date_default_timezone_set($this->getApplicationTimezone()); - - $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases()); - AliasLoader::getInstance($aliases)->register(); - - Request::enableHttpMethodParameterOverride(); - - $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders()); - $app->getProviderRepository()->load($app, $providers); - - $this->getEnvironmentSetUp($app); - - $app->boot(); - - return $app; - } - - /** - * @param Application $app - * - * @return array - */ - protected function getPackageProviders($app = null) - { - return array( - 'Flasher\Laravel\FlasherServiceProvider', - 'Flasher\Toastr\Laravel\FlasherToastrServiceProvider', - ); - } - - /** - * @param Application $app - */ - protected function getEnvironmentSetUp($app) - { - $separator = $this->isLaravel4() ? '::config' : ''; - - $app['config']->set('session' . $separator . '.driver', 'array'); - } - - private function isLaravel4() - { - return 0 === strpos(Application::VERSION, '4.'); - } -} diff --git a/tests/Toastr/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Toastr/Symfony/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 78473057..00000000 --- a/tests/Toastr/Symfony/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,43 +0,0 @@ -process(array()); - - $expected = array( - 'scripts' => array( - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', - 'https://cdn.jsdelivr.net/npm/@flasher/flasher-toastr@0.1.3/dist/flasher-toastr.min.js', - ), - 'styles' => array(), - 'options' => array( - 'progressBar' => true, - 'timeOut' => 5000, - ), - ); - - $this->assertEquals($expected, $config); - } - - /** - * Processes an array of configurations and returns a compiled version. - * - * @param array $configs An array of raw configurations - * - * @return array A normalized array - */ - private function process($configs) - { - $processor = new Processor(); - - return $processor->processConfiguration(new Configuration(), $configs); - } -} diff --git a/tests/Toastr/Symfony/DependencyInjection/FlasherToastrExtensionTest.php b/tests/Toastr/Symfony/DependencyInjection/FlasherToastrExtensionTest.php deleted file mode 100644 index fcf7e7a2..00000000 --- a/tests/Toastr/Symfony/DependencyInjection/FlasherToastrExtensionTest.php +++ /dev/null @@ -1,72 +0,0 @@ -getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_toastr', array()); - $container->compile(); - - $this->assertTrue($container->has('flasher.toastr')); - } - - public function testCreateInstanceOfToastrAdapter() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher'); - $container->loadFromExtension('flasher_toastr'); - $container->compile(); - - $flasher = $container->getDefinition('flasher'); - $calls = $flasher->getMethodCalls(); - - $this->assertCount(5, $calls); - $this->assertEquals('addFactory', $calls[0][0]); - $this->assertEquals('template', $calls[0][1][0]); - $this->assertEquals('flasher.template', (string) $calls[0][1][1]); - - $this->assertEquals('addFactory', $calls[4][0]); - $this->assertEquals('toastr', $calls[4][1][0]); - $this->assertEquals('flasher.toastr', (string) $calls[4][1][1]); - } - - private function getRawContainer() - { - $container = new ContainerBuilder(); - - $container->registerExtension(new FlasherExtension()); - $flasherBundle = new FlasherSymfonyBundle(); - $flasherBundle->build($container); - - $container->registerExtension(new FlasherToastrExtension()); - $adapterBundle = new FlasherToastrSymfonyBundle(); - $adapterBundle->build($container); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->getCompilerPassConfig()->setAfterRemovingPasses(array()); - - return $container; - } - - private function getContainer() - { - $container = $this->getRawContainer(); - $container->loadFromExtension('flasher', array()); - $container->loadFromExtension('flasher_toastr', array()); - $container->compile(); - - return $container; - } -}