mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
add php-notify classes and rename namespaces
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
|
||||
# Path-based git attributes
|
||||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
|
||||
|
||||
# Ignore all test and documentation with "export-ignore".
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/.styleci.yml export-ignore
|
||||
/tests export-ignore
|
||||
/.editorconfig export-ignore
|
||||
@@ -0,0 +1,48 @@
|
||||
name: Running tests
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 * * * *'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: [ 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5, 5.4 ]
|
||||
dependency-version: [ prefer-lowest, prefer-stable ]
|
||||
|
||||
name: php ${{ matrix.php }} - ${{ matrix.dependency-version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.composer/cache/files
|
||||
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
|
||||
- name: Require phpunit 6 for php >= 7.0
|
||||
if: matrix.php >= 7.0
|
||||
run: COMPOSER_MEMORY_LIMIT=-1 composer require "phpunit/phpunit:6.*" --no-interaction --no-update
|
||||
|
||||
- name: Require phpunit 9 for php >= 7.3
|
||||
if: matrix.php >= 7.3
|
||||
run: COMPOSER_MEMORY_LIMIT=-1 composer require "phpunit/phpunit:9.*" --no-interaction --no-update
|
||||
|
||||
- name: Install dependencies
|
||||
run: COMPOSER_MEMORY_LIMIT=-1 composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/phpunit
|
||||
@@ -0,0 +1,5 @@
|
||||
.idea/
|
||||
vendor/
|
||||
composer.lock
|
||||
.phpunit.result.cache
|
||||
.phpcs-cache
|
||||
+625
@@ -0,0 +1,625 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
|
||||
>
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="parallel" value="80"/>
|
||||
<arg name="cache" value=".phpcs-cache"/>
|
||||
<arg name="colors"/>
|
||||
|
||||
<!-- Ignore warnings, show progress of the run and show sniff names -->
|
||||
<arg value="nps"/>
|
||||
|
||||
<!-- Directories to be checked -->
|
||||
<file>src</file>
|
||||
<file>tests</file>
|
||||
|
||||
<!-- Import PSR-12 coding standard (base) -->
|
||||
<rule ref="PSR12"/>
|
||||
|
||||
<!-- Force array element indentation with 4 spaces -->
|
||||
<rule ref="Generic.Arrays.ArrayIndent"/>
|
||||
|
||||
<!-- Forbid `[...]` -->
|
||||
<rule ref="Generic.Arrays.DisallowShortArraySyntax"/>
|
||||
|
||||
<!-- Forbid duplicate classes -->
|
||||
<rule ref="Generic.Classes.DuplicateClassName"/>
|
||||
|
||||
<!-- Forbid empty statements -->
|
||||
<rule ref="Generic.CodeAnalysis.EmptyStatement">
|
||||
<!-- But allow empty catch -->
|
||||
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid final methods in final classes -->
|
||||
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
|
||||
|
||||
<!-- Forbid useless empty method overrides -->
|
||||
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
|
||||
|
||||
<!-- Align corresponding assignment statement tokens -->
|
||||
<rule ref="Generic.Formatting.MultipleStatementAlignment">
|
||||
<properties>
|
||||
<property name="error" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Force whitespace after a type cast -->
|
||||
<rule ref="Generic.Formatting.SpaceAfterCast">
|
||||
<properties>
|
||||
<property name="spacing" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Force whitespace after `!` -->
|
||||
<!-- <rule ref="Generic.Formatting.SpaceAfterNot"/> -->
|
||||
|
||||
<!-- Forbid PHP 4 constructors -->
|
||||
<rule ref="Generic.NamingConventions.ConstructorName"/>
|
||||
|
||||
<!-- Forbid any content before opening tag -->
|
||||
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag"/>
|
||||
|
||||
<!-- Forbid deprecated functions -->
|
||||
<rule ref="Generic.PHP.DeprecatedFunctions"/>
|
||||
|
||||
<!-- Forbid alias functions, i.e. `sizeof()`, `delete()` -->
|
||||
<rule ref="Generic.PHP.ForbiddenFunctions">
|
||||
<properties>
|
||||
<property name="forbiddenFunctions" type="array">
|
||||
<element key="chop" value="rtrim"/>
|
||||
<element key="close" value="closedir"/>
|
||||
<element key="compact" value="null"/>
|
||||
<element key="delete" value="unset"/>
|
||||
<element key="doubleval" value="floatval"/>
|
||||
<element key="extract" value="null"/>
|
||||
<element key="fputs" value="fwrite"/>
|
||||
<element key="ini_alter" value="ini_set"/>
|
||||
<element key="is_double" value="is_float"/>
|
||||
<element key="is_integer" value="is_int"/>
|
||||
<element key="is_long" value="is_int"/>
|
||||
<element key="is_null" value="null"/>
|
||||
<element key="is_real" value="is_float"/>
|
||||
<element key="is_writeable" value="is_writable"/>
|
||||
<element key="join" value="implode"/>
|
||||
<element key="key_exists" value="array_key_exists"/>
|
||||
<element key="pos" value="current"/>
|
||||
<element key="settype" value="null"/>
|
||||
<element key="show_source" value="highlight_file"/>
|
||||
<element key="sizeof" value="count"/>
|
||||
<element key="strchr" value="strstr"/>
|
||||
<element key="user_error" value="trigger_error"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid useless inline string concatenation -->
|
||||
<rule ref="Generic.Strings.UnnecessaryStringConcat">
|
||||
<!-- But multiline is useful for readability -->
|
||||
<properties>
|
||||
<property name="allowMultiline" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid backtick operator -->
|
||||
<rule ref="Generic.PHP.BacktickOperator"/>
|
||||
|
||||
<!-- Force PHP 7 param and return types to be lowercased -->
|
||||
<rule ref="Generic.PHP.LowerCaseType"/>
|
||||
|
||||
<!-- Forbid `php_sapi_name()` function -->
|
||||
<rule ref="Generic.PHP.SAPIUsage"/>
|
||||
|
||||
<!-- Forbid comments starting with # -->
|
||||
<rule ref="PEAR.Commenting.InlineComment"/>
|
||||
|
||||
<!-- Disallow else if in favor of elseif -->
|
||||
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
|
||||
<type>error</type>
|
||||
</rule>
|
||||
|
||||
<!-- Require that single line arrays have the correct spacing: no space around brackets and one space after comma -->
|
||||
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
|
||||
|
||||
<!-- Require comma after last element in multi-line array -->
|
||||
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
|
||||
|
||||
<!-- Require presence of constant visibility -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility">
|
||||
<properties>
|
||||
<property name="fixable" value="true"/>
|
||||
</properties>
|
||||
</rule> -->
|
||||
|
||||
<!-- Forbid LSB for constants (static::FOO) -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
|
||||
|
||||
<!-- Forbid more than one constant declared per statement -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>
|
||||
|
||||
<!-- Forbid empty lines around type declarations -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
|
||||
<properties>
|
||||
<property name="linesCountAfterOpeningBrace" value="0"/>
|
||||
<property name="linesCountBeforeClosingBrace" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/> -->
|
||||
|
||||
<!-- Forbid uses of multiple traits separated by comma -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
|
||||
|
||||
<!-- Require no spaces before trait use, between trait uses and one space after trait uses -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing">
|
||||
<properties>
|
||||
<property name="linesCountAfterLastUse" value="1"/>
|
||||
<property name="linesCountAfterLastUseWhenLastInClass" value="0"/>
|
||||
<property name="linesCountBeforeFirstUse" value="0"/>
|
||||
<property name="linesCountBetweenUses" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid dead code -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
|
||||
|
||||
<!-- Forbid useless annotations - Git and LICENCE file provide more accurate information -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
|
||||
<properties>
|
||||
<property name="forbiddenAnnotations" type="array">
|
||||
<element value="@api"/>
|
||||
<element value="@author"/>
|
||||
<element value="@category"/>
|
||||
<element value="@copyright"/>
|
||||
<element value="@created"/>
|
||||
<element value="@license"/>
|
||||
<element value="@package"/>
|
||||
<element value="@since"/>
|
||||
<element value="@subpackage"/>
|
||||
<element value="@version"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid empty comments -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
|
||||
|
||||
<!-- Forbid useless comments -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenComments">
|
||||
<properties>
|
||||
<property name="forbiddenCommentPatterns" type="array">
|
||||
<element value="~^(?:(?!private|protected|static)\S+ )?(?:con|de)structor\.\z~i"/>
|
||||
<element value="~^Created by .+\.\z~i"/>
|
||||
<element value="~^(User|Date|Time): \S+\z~i"/>
|
||||
<element value="~^\S+ [gs]etter\.\z~i"/>
|
||||
<element value="~^(Class|Interface|Trait) \S+\z~i"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
|
||||
<properties>
|
||||
<property name="linesCountBeforeFirstContent" value="0"/>
|
||||
<property name="linesCountAfterLastContent" value="0"/>
|
||||
<property name="linesCountBetweenDescriptionAndAnnotations" value="1"/>
|
||||
<property name="linesCountBetweenAnnotationsGroups" value="1"/>
|
||||
<property name="annotationsGroups" type="array">
|
||||
<element value="
|
||||
@internal,
|
||||
@deprecated,
|
||||
"/>
|
||||
<element value="
|
||||
@link,
|
||||
@see,
|
||||
@uses,
|
||||
"/>
|
||||
<element value="@var"/>
|
||||
<element value="@ORM\"/>
|
||||
<element value="@param"/>
|
||||
<element value="@return"/>
|
||||
<element value="@throws"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Report invalid format of inline phpDocs with @var -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
|
||||
|
||||
<!-- Require comments with single line written as one-liners -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/> -->
|
||||
|
||||
<!-- Forbid assignments in conditions -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
|
||||
|
||||
<!-- Require consistent spacing for block structures -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing">
|
||||
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
|
||||
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeFirstControlStructure" />
|
||||
<properties>
|
||||
<property name="tokensToCheck" type="array">
|
||||
<element value="T_IF" />
|
||||
<element value="T_DO" />
|
||||
<element value="T_WHILE" />
|
||||
<element value="T_FOR" />
|
||||
<element value="T_FOREACH" />
|
||||
<element value="T_SWITCH" />
|
||||
<element value="T_TRY" />
|
||||
<element value="T_DEFAULT" />
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid fancy yoda conditions -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/> -->
|
||||
|
||||
<!-- Require usage of early exit -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
|
||||
|
||||
<!-- Require consistent spacing for jump statements -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing">
|
||||
<properties>
|
||||
<property name="linesCountBeforeWhenFirstInCaseOrDefault" value="0"/>
|
||||
<property name="linesCountAfterWhenLastInCaseOrDefault" value="1"/>
|
||||
<property name="linesCountAfterWhenLastInLastCaseOrDefault" value="0"/>
|
||||
<property name="tokensToCheck" type="array">
|
||||
<element value="T_RETURN" />
|
||||
<element value="T_THROW" />
|
||||
<element value="T_YIELD" />
|
||||
<element value="T_YIELD_FROM" />
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require language constructs without parentheses -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
|
||||
|
||||
<!-- Require usage of null coalesce operator equal operator when possible -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/> -->
|
||||
|
||||
<!-- Require usage of null coalesce operator when possible -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/> -->
|
||||
|
||||
<!-- Forbid usage of conditions when a simple return can be used -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
|
||||
|
||||
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
|
||||
|
||||
<!-- Forbid useless unreachable catch blocks -->
|
||||
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
|
||||
|
||||
<!-- Require using Throwable instead of Exception -->
|
||||
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
|
||||
|
||||
<!-- Ensure Arrow Functions declaration format -->
|
||||
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
|
||||
<properties>
|
||||
<property name="spacesCountAfterKeyword" value="1"/>
|
||||
<property name="spacesCountBeforeArrow" value="1"/>
|
||||
<property name="spacesCountAfterArrow" value="1"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require closures not referencing $this be static -->
|
||||
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
|
||||
|
||||
<!-- Forbid unused variables passed to closures via `use` -->
|
||||
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
|
||||
|
||||
<!-- Require presence of declare(strict_types=1) -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
|
||||
<properties>
|
||||
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
|
||||
<property name="spacesCountAroundEqualsSign" value="0"/>
|
||||
<property name="newlinesCountAfterDeclare" value="2"/>
|
||||
</properties>
|
||||
</rule> -->
|
||||
|
||||
<!-- Require consistent spacing for block structures -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
|
||||
|
||||
<!-- Forbid unused use statements -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
|
||||
<properties>
|
||||
<property name="searchAnnotations" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require use statements to be alphabetically sorted -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
|
||||
|
||||
<!-- Forbid fancy group uses -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
|
||||
|
||||
<!-- Forbid multiple use statements on same line -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
|
||||
|
||||
<!-- Require newlines around namespace declaration -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
|
||||
|
||||
<!-- Forbid using absolute class name references -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/> -->
|
||||
|
||||
<!-- Forbid superfluous leading backslash in use statements -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
|
||||
|
||||
<!-- Forbid useless uses of the same namespace -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
|
||||
|
||||
<!-- Require empty newlines before and after uses -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing">
|
||||
<properties>
|
||||
<property name="linesCountAfterLastUse" value="1"/>
|
||||
<property name="linesCountBeforeFirstUse" value="1"/>
|
||||
<property name="linesCountBetweenUseTypes" value="1"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid useless alias for classes, constants and functions -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
|
||||
|
||||
<!-- Forbid weak comparisons -->
|
||||
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
|
||||
|
||||
<!-- Forbid spacing before the negative operator `-` -->
|
||||
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing"/>
|
||||
|
||||
<!-- Require the usage of assignment operators, eg `+=`, `.=` when possible -->
|
||||
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
|
||||
|
||||
<!-- Require no spacing after spread operator -->
|
||||
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing"/>
|
||||
|
||||
<!-- Forbid `list(...)` syntax -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
|
||||
|
||||
<!-- Forbid use of longhand cast operators -->
|
||||
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
|
||||
|
||||
<!-- Forbid useless parentheses -->
|
||||
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
|
||||
|
||||
<!-- Forbid useless semicolon `;` -->
|
||||
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
|
||||
|
||||
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
|
||||
|
||||
<!-- Require the `null` type hint to be in the last position of annotations -->
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
|
||||
|
||||
<!-- Require ? when default value is null -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/> -->
|
||||
|
||||
<!-- Require one space between typehint and variable, require no space between nullability sign and typehint -->
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
|
||||
|
||||
<!-- Require space around colon in return types -->
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
|
||||
<properties>
|
||||
<property name="spacesCountBeforeColon" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid useless @var for constants -->
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
|
||||
|
||||
<!-- Forbid useless inherit doc comment -->
|
||||
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
|
||||
|
||||
<!-- Forbid duplicated variables assignments -->
|
||||
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
|
||||
|
||||
<!-- Forbid useless variables -->
|
||||
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
|
||||
|
||||
<!-- Forbid spaces around square brackets -->
|
||||
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
|
||||
|
||||
<!-- Forbid class being in a file with different name -->
|
||||
<rule ref="Squiz.Classes.ClassFileName"/>
|
||||
|
||||
<!-- Force `self::` for self-reference, force lower-case self, forbid spaces around `::` -->
|
||||
<rule ref="Squiz.Classes.SelfMemberReference"/>
|
||||
|
||||
<!-- Forbid global functions -->
|
||||
<rule ref="Squiz.Functions.GlobalFunction"/>
|
||||
|
||||
<!-- Force camelCase variables -->
|
||||
<rule ref="Squiz.NamingConventions.ValidVariableName">
|
||||
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
|
||||
</rule>
|
||||
|
||||
<!-- Force phpDoc alignment -->
|
||||
<rule ref="Squiz.Commenting.DocCommentAlignment">
|
||||
<!-- Allow extra spaces after star, i.e. for indented annotations -->
|
||||
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceAfterStar"/>
|
||||
</rule>
|
||||
|
||||
<!-- Force array declaration structure -->
|
||||
<rule ref="Squiz.Arrays.ArrayDeclaration">
|
||||
<!-- Disable arrow alignment -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>
|
||||
<!-- Uses indentation of only single space -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"/>
|
||||
<!-- Allow multiple values on a single line -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed"/>
|
||||
<!-- Disable alignment of braces -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"/>
|
||||
<!-- Disable alignment of values with opening brace -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"/>
|
||||
<!-- Checked by SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma -->
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"/>
|
||||
<exclude name="Squiz.Arrays.ArrayDeclaration.NoComma"/>
|
||||
</rule>
|
||||
|
||||
<!-- Force rules for function phpDoc -->
|
||||
<rule ref="Squiz.Commenting.FunctionComment">
|
||||
<!-- Allow `@throws` without description -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
|
||||
<!-- Does not work properly with PHP 7 / short-named types -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
|
||||
<!-- Does not support collections, i.e. `string[]` -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint"/>
|
||||
<!-- Forces incorrect types -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturn"/>
|
||||
<!-- Breaks with compound return types, i.e. `string|null` -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturnNotVoid"/>
|
||||
<!-- Breaks when all params are not documented -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
|
||||
<!-- Doc comment is not required for every method -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
|
||||
<!-- Do not require comments for `@param` -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/>
|
||||
<!-- Do not require `@param` for all parameters -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
|
||||
<!-- Do not require `@return` for void methods -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.MissingReturn"/>
|
||||
<!-- Comments don't have to be sentences -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullFullStop"/>
|
||||
<!-- Comments don't have to be sentences -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
|
||||
<!-- Breaks when all params are not documented -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
|
||||
<!-- Doesn't respect inheritance -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
|
||||
<!-- `@throws` lines can often be read as a sentence,
|
||||
i.e. `@throws RuntimeException if the file could not be written.` -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNotCapital"/>
|
||||
<!-- Doesn't work with self as typehint -->
|
||||
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid `AND` and `OR`, require `&&` and `||` -->
|
||||
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
|
||||
|
||||
<!-- Forbid `global` -->
|
||||
<rule ref="Squiz.PHP.GlobalKeyword"/>
|
||||
|
||||
<!-- Forbid functions inside functions -->
|
||||
<rule ref="Squiz.PHP.InnerFunctions"/>
|
||||
|
||||
<!-- Require PHP function calls in lowercase -->
|
||||
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
|
||||
|
||||
<!-- Forbid `$this` inside static function -->
|
||||
<rule ref="Squiz.Scope.StaticThisUsage"/>
|
||||
|
||||
<!-- Force whitespace before and after concatenation -->
|
||||
<!-- <rule ref="Squiz.Strings.ConcatenationSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="0"/>
|
||||
<property name="ignoreNewlines" value="true"/>
|
||||
</properties>
|
||||
</rule> -->
|
||||
|
||||
<!-- Forbid dead code -->
|
||||
<rule ref="Squiz.PHP.NonExecutableCode"/>
|
||||
|
||||
<!-- Forbid strings in `"` unless necessary -->
|
||||
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
|
||||
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
|
||||
<message>Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead</message>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid braces around string in `echo` -->
|
||||
<rule ref="Squiz.Strings.EchoedStrings"/>
|
||||
|
||||
<!-- Forbid spaces in type casts -->
|
||||
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
|
||||
|
||||
<!-- Forbid blank line after function opening brace -->
|
||||
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
|
||||
|
||||
<!-- Require 1 line before and after function, except at the top and bottom -->
|
||||
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="1" />
|
||||
<property name="spacingBeforeFirst" value="0"/>
|
||||
<property name="spacingAfterLast" value="0"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require there be no space between increment/decrement operator and its operand -->
|
||||
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
|
||||
|
||||
<!-- Require space after language constructs -->
|
||||
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
|
||||
|
||||
<!-- Require space around logical operators -->
|
||||
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
|
||||
|
||||
<!-- Forbid spaces around `->` operator -->
|
||||
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
|
||||
<properties>
|
||||
<property name="ignoreNewlines" value="true"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Forbid spaces before semicolon `;` -->
|
||||
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
|
||||
|
||||
<!-- Forbid superfluous whitespaces -->
|
||||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
|
||||
<properties>
|
||||
<!-- turned on by PSR2 -> turning back off -->
|
||||
<property name="ignoreBlankLines" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
|
||||
<!-- turned off by PSR2 -> turning back on -->
|
||||
<severity>5</severity>
|
||||
</rule>
|
||||
|
||||
<!-- Checks that class/trait/interface members are in the correct order. -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.ClassStructure"/>
|
||||
|
||||
<!-- Disallows use of continue without integer operand in switch because it emits a warning in PHP 7.3 and higher. -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
|
||||
|
||||
<!-- Enforces reasonable end bracket placement for multiline arrays. -->
|
||||
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
|
||||
|
||||
<!-- Checks that there is a certain number of blank lines between properties. -->
|
||||
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/>
|
||||
|
||||
<!-- Require consistent spacing for jump statements -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing">
|
||||
<properties>
|
||||
<property name="tokensToCheck" type="array">
|
||||
<element value="T_RETURN" />
|
||||
<element value="T_THROW" />
|
||||
<element value="T_YIELD" />
|
||||
<element value="T_YIELD_FROM" />
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Require consistent spacing for block structures -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing">
|
||||
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
|
||||
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeFirstControlStructure" />
|
||||
<properties>
|
||||
<property name="tokensToCheck" type="array">
|
||||
<element value="T_IF" />
|
||||
<element value="T_DO" />
|
||||
<element value="T_WHILE" />
|
||||
<element value="T_FOR" />
|
||||
<element value="T_FOREACH" />
|
||||
<element value="T_SWITCH" />
|
||||
<element value="T_TRY" />
|
||||
<element value="T_DEFAULT" />
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Requires new with parentheses. -->
|
||||
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
|
||||
|
||||
<!-- Disallows usage of array type hint syntax (eg. int[], bool[][]) in phpDocs in favour of generic type hint syntax (eg. array<int>, array<array<bool>>) -->
|
||||
<!-- <rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax" />-->
|
||||
</ruleset>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace PHPSTORM_META;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Flasher;
|
||||
use Flasher\Prime\Presenter\PresenterManager;
|
||||
use Flasher\Prime\Renderer\RendererManager;
|
||||
|
||||
override(Envelope::get(), type(0));
|
||||
|
||||
override(Flasher::make(''), map(['' => '@']));
|
||||
override(RendererManager::make(''), map(['' => '@']));
|
||||
override(PresenterManager::make(''), map(['' => '@']));
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime;
|
||||
|
||||
use Flasher\Prime\TestsNotification\Notification;
|
||||
use Flasher\Prime\TestsNotification\NotificationBuilder;
|
||||
use Flasher\Prime\TestsNotification\NotificationBuilderInterface;
|
||||
use Flasher\Prime\TestsNotification\NotificationInterface;
|
||||
|
||||
/**
|
||||
* @method NotificationBuilderInterface type($type, $message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface message($message)
|
||||
* @method NotificationBuilderInterface options($options)
|
||||
* @method NotificationBuilderInterface setOption($name, $value)
|
||||
* @method NotificationBuilderInterface unsetOption($name)
|
||||
* @method NotificationBuilderInterface success($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface error($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface info($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface warning($message = null, array $options = array())
|
||||
* @method NotificationInterface getNotification()
|
||||
*/
|
||||
abstract class AbstractFlasher implements NotifyFactoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new NotificationBuilder($this->createNotification());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Notification();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return get_class($this) === $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically call the default driver instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, array $parameters)
|
||||
{
|
||||
return call_user_func_array(array($this->createNotificationBuilder(), $method), $parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Config;
|
||||
|
||||
final class Config implements ConfigInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
$data = $this->config;
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (!isset($data[$segment])) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$data = $data[$segment];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Config;
|
||||
|
||||
interface ConfigInterface
|
||||
{
|
||||
/**
|
||||
* Returns an attribute.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default The default value if not found.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null);
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Notify;
|
||||
|
||||
use Flasher\Prime\TestsNotification\NotificationInterface;
|
||||
use Flasher\Prime\TestsStamp\StampInterface;
|
||||
|
||||
final class Envelope
|
||||
{
|
||||
/**
|
||||
* @var NotificationInterface
|
||||
*/
|
||||
private $notification;
|
||||
|
||||
/**
|
||||
* @var StampInterface[]
|
||||
*/
|
||||
private $stamps = array();
|
||||
|
||||
/**
|
||||
* @param Envelope|NotificationInterface $notification
|
||||
* @param StampInterface[] $stamps
|
||||
*/
|
||||
public function __construct($notification, $stamps = array())
|
||||
{
|
||||
$this->notification = $notification;
|
||||
$stamps = is_array($stamps) ? $stamps : array_slice(func_get_args(), 1);
|
||||
call_user_func_array(array($this, 'with'), $stamps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the notification is in an Envelope and adds the given stamps.
|
||||
*
|
||||
* @param NotificationInterface|Envelope $notification
|
||||
* @param StampInterface[] $stamps
|
||||
*
|
||||
* @return Envelope
|
||||
*/
|
||||
public static function wrap($notification, array $stamps = array())
|
||||
{
|
||||
$envelope = $notification instanceof self ? $notification : new self($notification);
|
||||
|
||||
return call_user_func_array(array($envelope, 'with'), $stamps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|StampInterface $stamps
|
||||
*
|
||||
* @return Envelope a new Envelope instance with additional stamp
|
||||
*/
|
||||
public function with($stamps = array())
|
||||
{
|
||||
$stamps = is_array($stamps) ? $stamps : func_get_args();
|
||||
|
||||
foreach ($stamps as $stamp) {
|
||||
$this->withStamp($stamp);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StampInterface $stamp
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withStamp(StampInterface $stamp)
|
||||
{
|
||||
$this->stamps[get_class($stamp)] = $stamp;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $stampFqcn
|
||||
*
|
||||
* @return StampInterface|null
|
||||
*/
|
||||
public function get($stampFqcn)
|
||||
{
|
||||
if (!isset($this->stamps[$stampFqcn])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->stamps[$stampFqcn];
|
||||
}
|
||||
|
||||
/**
|
||||
* All stamps by their class name
|
||||
*
|
||||
* @return StampInterface[]
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->stamps;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original notification contained in the envelope
|
||||
*
|
||||
* @return NotificationInterface
|
||||
*/
|
||||
public function getNotification()
|
||||
{
|
||||
return $this->notification;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter;
|
||||
|
||||
use Flasher\Prime\TestsFilter\Specification\LifeSpecification;
|
||||
use Flasher\Prime\TestsFilter\Specification\PrioritySpecification;
|
||||
|
||||
final class CriteriaBuilder
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\FilterBuilder
|
||||
*/
|
||||
private $filterBuilder;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $criteria;
|
||||
|
||||
public function __construct(FilterBuilder $filterBuilder, $criteria = array())
|
||||
{
|
||||
$this->filterBuilder = $filterBuilder;
|
||||
$this->criteria = $criteria;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
$this->buildPriority();
|
||||
$this->buildLife();
|
||||
$this->buildLimit();
|
||||
$this->buildOrder();
|
||||
|
||||
return $this->filterBuilder;
|
||||
}
|
||||
|
||||
public function buildPriority()
|
||||
{
|
||||
if (!isset($this->criteria['priority'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$priority = $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));
|
||||
}
|
||||
|
||||
public function buildLife()
|
||||
{
|
||||
if (!isset($this->criteria['life'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$life = $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 LifeSpecification($min, $max));
|
||||
}
|
||||
|
||||
public function buildLimit()
|
||||
{
|
||||
if (!isset($this->criteria['limit'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->filterBuilder->setMaxResults($this->criteria['limit']);
|
||||
}
|
||||
|
||||
public function buildOrder()
|
||||
{
|
||||
if (!isset($this->criteria['order_by'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$orderings = $this->criteria['order_by'];
|
||||
|
||||
if (!is_array($orderings)) {
|
||||
$orderings = array($orderings => FilterBuilder::ASC);
|
||||
}
|
||||
|
||||
$this->filterBuilder->orderBy($orderings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter;
|
||||
|
||||
final class DefaultFilter implements FilterInterface
|
||||
{
|
||||
private $filterBuilder;
|
||||
|
||||
public function __construct(FilterBuilder $filterBuilder)
|
||||
{
|
||||
$this->filterBuilder = $filterBuilder;
|
||||
}
|
||||
|
||||
public function filter($envelopes, $criteria = array())
|
||||
{
|
||||
return $this->filterBuilder->withCriteria($criteria)->filter($envelopes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsFilter\Specification\AndSpecification;
|
||||
use Flasher\Prime\TestsFilter\Specification\OrSpecification;
|
||||
use Flasher\Prime\TestsFilter\Specification\SpecificationInterface;
|
||||
use Flasher\Prime\TestsStamp\OrderableStampInterface;
|
||||
|
||||
final class FilterBuilder
|
||||
{
|
||||
const ASC = 'ASC';
|
||||
const DESC = 'DESC';
|
||||
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\Specification\SpecificationInterface
|
||||
*/
|
||||
private $specification;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private $orderings = array();
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxResults;
|
||||
|
||||
public function orderBy(array $orderings)
|
||||
{
|
||||
$this->orderings = array_map(
|
||||
static function ($ordering) {
|
||||
return strtoupper($ordering) === FilterBuilder::ASC ? FilterBuilder::ASC : FilterBuilder::DESC;
|
||||
},
|
||||
$orderings
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getOrderings()
|
||||
{
|
||||
return $this->orderings;
|
||||
}
|
||||
|
||||
public function withCriteria($criteria)
|
||||
{
|
||||
$criteriaBuilder = new CriteriaBuilder($this, $criteria);
|
||||
$criteriaBuilder->build();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filter(array $envelopes)
|
||||
{
|
||||
$specification = $this->getSpecification();
|
||||
|
||||
if (null !== $specification) {
|
||||
$envelopes = array_filter(
|
||||
$envelopes,
|
||||
static function (Envelope $envelope) use ($specification) {
|
||||
return $specification->isSatisfiedBy($envelope);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$orderings = $this->getOrderings();
|
||||
|
||||
if (null !== $orderings) {
|
||||
foreach ($orderings as $field => $ordering) {
|
||||
usort(
|
||||
$envelopes,
|
||||
static function (Envelope $a, Envelope $b) use ($field, $ordering) {
|
||||
if (FilterBuilder::ASC === $ordering) {
|
||||
list($a, $b) = array($b, $a);
|
||||
}
|
||||
|
||||
$stampA = $a->get($field);
|
||||
$stampB = $b->get($field);
|
||||
|
||||
if (!$stampA instanceof OrderableStampInterface) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $stampA->compare($stampB);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$length = $this->getMaxResults();
|
||||
|
||||
if (null !== $length) {
|
||||
$envelopes = array_slice($envelopes, 0, $length, true);
|
||||
}
|
||||
|
||||
return $envelopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Flasher\Prime\TestsFilter\Specification\SpecificationInterface
|
||||
*/
|
||||
public function getSpecification()
|
||||
{
|
||||
return $this->specification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getMaxResults()
|
||||
{
|
||||
return $this->maxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $maxResults
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxResults($maxResults)
|
||||
{
|
||||
$this->maxResults = $maxResults;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsFilter\Specification\SpecificationInterface $specification
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function andWhere(SpecificationInterface $specification)
|
||||
{
|
||||
if ($this->specification === null) {
|
||||
return $this->where($specification);
|
||||
}
|
||||
|
||||
$this->specification = new AndSpecification($this->specification, $specification);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsFilter\Specification\SpecificationInterface $specification
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function where(SpecificationInterface $specification)
|
||||
{
|
||||
$this->specification = $specification;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsFilter\Specification\SpecificationInterface $specification
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function orWhere(SpecificationInterface $specification)
|
||||
{
|
||||
if ($this->specification === null) {
|
||||
return $this->where($specification);
|
||||
}
|
||||
|
||||
$this->specification = new OrSpecification($this->specification, $specification);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter;
|
||||
|
||||
interface FilterInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter;
|
||||
|
||||
use Flasher\Prime\TestsManager\AbstractManager;
|
||||
|
||||
/**
|
||||
* @method \Flasher\Prime\TestsFilter\FilterInterface make($driver = null)
|
||||
*/
|
||||
final class FilterManager extends AbstractManager
|
||||
{
|
||||
protected function getDefaultDriver()
|
||||
{
|
||||
return $this->config->get('default_filter', 'default');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class AndSpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\Specification\SpecificationInterface[]
|
||||
*/
|
||||
private $specifications;
|
||||
|
||||
/**
|
||||
* @param array|mixed ...$specifications
|
||||
*/
|
||||
public function __construct($specifications = array())
|
||||
{
|
||||
$specifications = is_array($specifications) ? $specifications : func_get_args();
|
||||
|
||||
$this->specifications = $specifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
foreach ($this->specifications as $specification) {
|
||||
if (!$specification->isSatisfiedBy($envelope)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class LifeSpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $minLife;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxLife;
|
||||
|
||||
public function __construct($minLife, $maxLife = null)
|
||||
{
|
||||
$this->minLife = $minLife;
|
||||
$this->maxLife = $maxLife;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
$stamp = $envelope->get('Flasher\Prime\TestsStamp\ReplayStamp');
|
||||
|
||||
if (null === $stamp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $this->maxLife && $stamp->getLife() > $this->maxLife) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $stamp->getLife() >= $this->minLife;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class NotSpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\Specification\SpecificationInterface
|
||||
*/
|
||||
private $specification;
|
||||
|
||||
public function __construct(SpecificationInterface $specification)
|
||||
{
|
||||
$this->specification = $specification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
return !$this->specification->isSatisfiedBy($envelope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class OrSpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\Specification\SpecificationInterface[]
|
||||
*/
|
||||
private $specifications;
|
||||
|
||||
/**
|
||||
* @param array|mixed ...$specifications
|
||||
*/
|
||||
public function __construct($specifications = array())
|
||||
{
|
||||
$specifications = is_array($specifications) ? $specifications : func_get_args();
|
||||
|
||||
$this->specifications = $specifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
foreach ($this->specifications as $specification) {
|
||||
if ($specification->isSatisfiedBy($envelope)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class PrioritySpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $minPriority;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxPriority;
|
||||
|
||||
public function __construct($minPriority, $maxPriority = null)
|
||||
{
|
||||
$this->minPriority = $minPriority;
|
||||
$this->maxPriority = $maxPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
$stamp = $envelope->get('Flasher\Prime\TestsStamp\PriorityStamp');
|
||||
|
||||
if (null === $stamp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $this->maxPriority && $stamp->getPriority() > $this->maxPriority) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $stamp->getPriority() >= $this->minPriority;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
interface SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsFilter\Specification;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class TimeSpecification implements SpecificationInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $minTime;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxTime;
|
||||
|
||||
public function __construct($minTime, $maxTime = null)
|
||||
{
|
||||
$this->minTime = $minTime;
|
||||
$this->maxTime = $maxTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSatisfiedBy(Envelope $envelope)
|
||||
{
|
||||
$stamp = $envelope->get('Flasher\Prime\TestsStamp\CreatedAtStamp');
|
||||
|
||||
if (null === $stamp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $this->maxTime && $stamp->getCreatedAt() > $this->maxTime) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $stamp->getCreatedAt() >= $this->minTime;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\TestsNotification\NotificationBuilderInterface;
|
||||
use Flasher\Prime\TestsNotification\NotificationInterface;
|
||||
|
||||
/**
|
||||
* @method NotificationBuilderInterface type($type, $message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface message($message)
|
||||
* @method NotificationBuilderInterface options($options)
|
||||
* @method NotificationBuilderInterface setOption($name, $value)
|
||||
* @method NotificationBuilderInterface unsetOption($name)
|
||||
* @method NotificationBuilderInterface success($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface error($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface info($message = null, array $options = array())
|
||||
* @method NotificationBuilderInterface warning($message = null, array $options = array())
|
||||
* @method NotificationInterface getNotification()
|
||||
*/
|
||||
final class Flasher extends AbstractManager
|
||||
{
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->config->get('default');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime;
|
||||
|
||||
interface FlasherInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return NotifyFactoryInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($name = null, array $context = array());
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|NotifyFactoryInterface $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($driver);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsManager;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Notify\Config\ConfigInterface;
|
||||
|
||||
abstract class AbstractManager
|
||||
{
|
||||
/**
|
||||
* The array of created "drivers".
|
||||
*
|
||||
* @var array<object>
|
||||
*/
|
||||
protected $drivers = array();
|
||||
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @param ConfigInterface $config
|
||||
*/
|
||||
public function __construct(ConfigInterface $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($name = null, array $context = array())
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
if (is_array($name)) {
|
||||
$context = $name;
|
||||
$name = null;
|
||||
}
|
||||
|
||||
foreach ($this->drivers as $driver) {
|
||||
if ($driver->supports($name, $context)) {
|
||||
return $driver;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Driver [%s] not supported.', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param \Closure|object $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($driver)
|
||||
{
|
||||
$this->drivers[] = $driver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ConfigInterface
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically call the default driver instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, array $parameters)
|
||||
{
|
||||
return call_user_func_array(array($this->make(), $method), $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getDefaultDriver()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Manager;
|
||||
|
||||
interface ManagerInterface
|
||||
{
|
||||
/**
|
||||
* Get a driver instance.
|
||||
*
|
||||
* @param string|null $driver
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function make($driver = null);
|
||||
|
||||
/**
|
||||
* Register a custom driver creator.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param \Closure|object $driver
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDriver($alias, $driver);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\CreatedAtStamp;
|
||||
|
||||
final class AddCreatedAtStampMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, callable $next)
|
||||
{
|
||||
if (null === $envelope->get('Flasher\Prime\TestsStamp\CreatedAtStamp')) {
|
||||
$envelope->withStamp(new CreatedAtStamp());
|
||||
}
|
||||
|
||||
return $next($envelope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\PriorityStamp;
|
||||
|
||||
final class AddPriorityStampMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, callable $next)
|
||||
{
|
||||
if (null === $envelope->get('Flasher\Prime\TestsStamp\PriorityStamp')) {
|
||||
$envelope->withStamp(new PriorityStamp(0));
|
||||
}
|
||||
|
||||
return $next($envelope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\RenderedAtStamp;
|
||||
|
||||
final class AddRenderedAtStampMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, callable $next)
|
||||
{
|
||||
if (null === $envelope->get('Flasher\Prime\TestsStamp\RenderedAtStamp')) {
|
||||
$envelope->withStamp(new RenderedAtStamp());
|
||||
}
|
||||
|
||||
return $next($envelope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\ReplayStamp;
|
||||
|
||||
final class AddReplayStampMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, callable $next)
|
||||
{
|
||||
if (null === $envelope->get('Flasher\Prime\TestsStamp\ReplayStamp')) {
|
||||
$envelope->withStamp(new ReplayStamp(1));
|
||||
}
|
||||
|
||||
return $next($envelope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
interface MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Notify\Envelope
|
||||
*/
|
||||
public function handle(Envelope $envelope, callable $next);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsMiddleware;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
final class NotifyBus
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsMiddleware\MiddlewareInterface[]
|
||||
*/
|
||||
private $middlewares;
|
||||
|
||||
/**
|
||||
* Executes the given command and optionally returns a value
|
||||
*
|
||||
* @param \Notify\Envelope|\Flasher\Prime\TestsNotification\NotificationInterface $envelope
|
||||
* @param array $stamps
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatch($envelope, $stamps = array())
|
||||
{
|
||||
$envelope = Envelope::wrap($envelope, $stamps);
|
||||
|
||||
$middlewareChain = $this->createExecutionChain();
|
||||
|
||||
$middlewareChain($envelope);
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsMiddleware\MiddlewareInterface $middleware
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addMiddleware(MiddlewareInterface $middleware)
|
||||
{
|
||||
$this->middlewares[] = $middleware;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable
|
||||
*/
|
||||
private function createExecutionChain()
|
||||
{
|
||||
$lastCallable = static function () {
|
||||
// the final callable is a no-op
|
||||
};
|
||||
|
||||
$middlewares = $this->middlewares;
|
||||
|
||||
while ($middleware = array_pop($middlewares)) {
|
||||
$lastCallable = static function ($command) use ($middleware, $lastCallable) {
|
||||
return $middleware->handle($command, $lastCallable);
|
||||
};
|
||||
}
|
||||
|
||||
return $lastCallable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsNotification;
|
||||
|
||||
class Notification implements NotificationInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = self::TYPE_SUCCESS;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param string|null $type
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($message = null, $type = self::TYPE_SUCCESS, array $options = array())
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->type = $type;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOption($name, $default = null)
|
||||
{
|
||||
if (!isset($this->options[$name])) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function unsetOption($name)
|
||||
{
|
||||
unset($this->options[$name]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsNotification;
|
||||
|
||||
class NotificationBuilder implements NotificationBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsNotification\NotificationInterface
|
||||
*/
|
||||
protected $notification;
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsNotification\NotificationInterface|null $notification
|
||||
*/
|
||||
public function __construct(NotificationInterface $notification = null)
|
||||
{
|
||||
$this->notification = $notification ?: new Notification();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function type($type, $message = null, array $options = array())
|
||||
{
|
||||
$this->notification->setType($type);
|
||||
|
||||
if (null !== $message) {
|
||||
$this->message($message);
|
||||
}
|
||||
|
||||
if (array() !== $options) {
|
||||
$this->options($options, false);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function message($message)
|
||||
{
|
||||
$this->notification->setMessage($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function options($options, $merge = true)
|
||||
{
|
||||
if (true === $merge) {
|
||||
$options = array_merge($this->notification->getOptions(), $options);
|
||||
}
|
||||
|
||||
$this->notification->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function option($name, $value)
|
||||
{
|
||||
$this->notification->setOption($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getNotification()
|
||||
{
|
||||
return $this->notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function success($message = null, array $options = array())
|
||||
{
|
||||
return $this->type(NotificationInterface::TYPE_SUCCESS, $message, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function error($message = null, array $options = array())
|
||||
{
|
||||
return $this->type(NotificationInterface::TYPE_ERROR, $message, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function info($message = null, array $options = array())
|
||||
{
|
||||
return $this->type(NotificationInterface::TYPE_INFO, $message, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function warning($message = null, array $options = array())
|
||||
{
|
||||
return $this->type(NotificationInterface::TYPE_WARNING, $message, $options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsNotification;
|
||||
|
||||
interface NotificationBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string|null $message
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Flasher\Prime\TestsNotification\NotificationBuilder
|
||||
*/
|
||||
public function type($type, $message = null, array $options = array());
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @return \Flasher\Prime\TestsNotification\NotificationBuilder
|
||||
*/
|
||||
public function message($message);
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
* @param bool $merge
|
||||
*
|
||||
* @return \Flasher\Prime\TestsNotification\NotificationBuilder
|
||||
*/
|
||||
public function options($options, $merge = true);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Flasher\Prime\TestsNotification\NotificationBuilder
|
||||
*/
|
||||
public function option($name, $value);
|
||||
|
||||
/**
|
||||
* @return \Flasher\Prime\TestsNotification\NotificationInterface
|
||||
*/
|
||||
public function getNotification();
|
||||
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param array $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function success($message = null, array $options = array());
|
||||
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param array $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function error($message = null, array $options = array());
|
||||
|
||||
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param array $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function info($message = null, array $options = array());
|
||||
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param array $options
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function warning($message = null, array $options = array());
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsNotification;
|
||||
|
||||
interface NotificationInterface
|
||||
{
|
||||
const TYPE_SUCCESS = 'success';
|
||||
const TYPE_ERROR = 'error';
|
||||
const TYPE_INFO = 'info';
|
||||
const TYPE_WARNING = 'warning';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType();
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage();
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function setMessage($message);
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getOptions();
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function setOptions(array $options);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name, $default = null);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setOption($name, $value);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function unsetOption($name);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsPresenter;
|
||||
|
||||
use Notify\Config\ConfigInterface;
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsFilter\FilterManager;
|
||||
use Flasher\Prime\TestsRenderer\HasOptionsInterface;
|
||||
use Flasher\Prime\TestsRenderer\HasScriptsInterface;
|
||||
use Flasher\Prime\TestsRenderer\HasStylesInterface;
|
||||
use Flasher\Prime\TestsRenderer\RendererManager;
|
||||
use Flasher\Prime\TestsStorage\StorageInterface;
|
||||
|
||||
abstract class AbstractPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @var \Notify\Config\ConfigInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsStorage\StorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsFilter\FilterManager
|
||||
*/
|
||||
protected $filterManager;
|
||||
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsRenderer\RendererManager
|
||||
*/
|
||||
protected $rendererManager;
|
||||
|
||||
/**
|
||||
* AbstractPresenter constructor.
|
||||
*
|
||||
* @param \Notify\Config\ConfigInterface $config
|
||||
* @param \Flasher\Prime\TestsStorage\StorageInterface $storage
|
||||
* @param \Flasher\Prime\TestsFilter\FilterManager $filterManager
|
||||
* @param \Flasher\Prime\TestsRenderer\RendererManager $rendererManager
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigInterface $config,
|
||||
StorageInterface $storage,
|
||||
FilterManager $filterManager,
|
||||
RendererManager $rendererManager
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->storage = $storage;
|
||||
$this->filterManager = $filterManager;
|
||||
$this->rendererManager = $rendererManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return get_class($this) === $name;
|
||||
}
|
||||
|
||||
protected function getEnvelopes($filterName, $criteria = array())
|
||||
{
|
||||
$filter = $this->filterManager->make($filterName);
|
||||
$envelopes = $filter->filter($this->storage->get(), $criteria);
|
||||
|
||||
return array_filter(
|
||||
$envelopes,
|
||||
static function (Envelope $envelope) {
|
||||
$lifeStamp = $envelope->get('Flasher\Prime\TestsStamp\ReplayStamp');
|
||||
|
||||
return $lifeStamp->getLife() > 0;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Envelope[] $envelopes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getStyles($envelopes)
|
||||
{
|
||||
$files = $this->config->get('styles', array());
|
||||
$renderers = array();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$rendererStamp = $envelope->get('Flasher\Prime\TestsStamp\HandlerStamp');
|
||||
if (in_array($rendererStamp->getHandler(), $renderers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renderer = $this->rendererManager->make($rendererStamp->getHandler());
|
||||
if (!$renderer instanceof HasStylesInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$files = array_merge($files, $renderer->getStyles());
|
||||
$renderers[] = $rendererStamp->getHandler();
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_unique($files)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Envelope[] $envelopes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getScripts($envelopes)
|
||||
{
|
||||
$files = $this->config->get('scripts', array());
|
||||
$renderers = array();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$rendererStamp = $envelope->get('Flasher\Prime\TestsStamp\HandlerStamp');
|
||||
if (in_array($rendererStamp->getHandler(), $renderers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renderer = $this->rendererManager->make($rendererStamp->getHandler());
|
||||
if (!$renderer instanceof HasScriptsInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$files = array_merge($files, $renderer->getScripts());
|
||||
$renderers[] = $rendererStamp->getHandler();
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_unique($files)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Envelope[] $envelopes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getOptions($envelopes)
|
||||
{
|
||||
$options = array();
|
||||
$renderers = array();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$rendererStamp = $envelope->get('Flasher\Prime\TestsStamp\HandlerStamp');
|
||||
if (in_array($rendererStamp->getHandler(), $renderers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renderer = $this->rendererManager->make($rendererStamp->getHandler());
|
||||
if (!$renderer instanceof HasOptionsInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[] = $renderer->renderOptions();
|
||||
$renderers[] = $rendererStamp->getHandler();
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_unique($options)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsPresenter\Adapter;
|
||||
|
||||
use Flasher\Prime\TestsPresenter\AbstractPresenter;
|
||||
|
||||
final class HtmlPresenter extends AbstractPresenter
|
||||
{
|
||||
/**
|
||||
* @param string|array $criteria
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($criteria = null)
|
||||
{
|
||||
$filterName = 'default';
|
||||
|
||||
if (is_string($criteria)) {
|
||||
$filterName = $criteria;
|
||||
$criteria = array();
|
||||
}
|
||||
|
||||
$envelopes = $this->getEnvelopes($filterName, $criteria);
|
||||
|
||||
if (empty($envelopes)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$scripts = $this->renderScripts($envelopes);
|
||||
$styles = json_encode($this->getStyles($envelopes));
|
||||
$options = $this->renderOptions($envelopes);
|
||||
$notifications = $this->renderEnvelopes($envelopes);
|
||||
|
||||
$html = <<<HTML
|
||||
{$scripts}
|
||||
<script type="text/javascript">
|
||||
var renderPHPNotifyNotifications = function () {
|
||||
{$options}
|
||||
{$notifications}
|
||||
}
|
||||
|
||||
if ("undefined" !== typeof PHPNotify) {
|
||||
PHPNotify.addStyles({$styles}, renderPHPNotifyNotifications);
|
||||
} else {
|
||||
renderPHPNotifyNotifications();
|
||||
}
|
||||
</script>
|
||||
HTML;
|
||||
|
||||
$this->storage->flush($envelopes);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderEnvelopes($envelopes)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$rendererStamp = $envelope->get('Flasher\Prime\TestsStamp\HandlerStamp');
|
||||
$renderer = $this->rendererManager->make($rendererStamp->getHandler());
|
||||
|
||||
$html .= $renderer->render($envelope).PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderOptions($envelopes)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
foreach ($this->getOptions($envelopes) as $option) {
|
||||
$html .= $option.PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderScripts($envelopes)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
foreach ($this->getScripts($envelopes) as $file) {
|
||||
$html .= sprintf('<script src="%s"></script>', $file).PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsPresenter\Adapter;
|
||||
|
||||
use Flasher\Prime\TestsPresenter\AbstractPresenter;
|
||||
|
||||
final class JsonPresenter extends AbstractPresenter
|
||||
{
|
||||
/**
|
||||
* @param string|array $criteria
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function render($criteria = null)
|
||||
{
|
||||
$filterName = 'default';
|
||||
|
||||
if (is_string($criteria)) {
|
||||
$filterName = $criteria;
|
||||
$criteria = array();
|
||||
}
|
||||
|
||||
$envelopes = $this->getEnvelopes($filterName, $criteria);
|
||||
|
||||
if (empty($envelopes)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'scripts' => $this->getScripts($envelopes),
|
||||
'styles' => $this->getStyles($envelopes),
|
||||
'options' => $this->getOptions($envelopes),
|
||||
'notifications' => $this->renderEnvelopes($envelopes),
|
||||
);
|
||||
|
||||
$this->storage->flush($envelopes);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function renderEnvelopes($envelopes)
|
||||
{
|
||||
$notifications = array();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$rendererStamp = $envelope->get('Flasher\Prime\TestsStamp\HandlerStamp');
|
||||
$renderer = $this->rendererManager->make($rendererStamp->getHandler());
|
||||
|
||||
$notifications[] = array(
|
||||
'code' => $renderer->render($envelope),
|
||||
'adapter' => $rendererStamp->getHandler()
|
||||
);
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsPresenter;
|
||||
|
||||
interface PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param array $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($name = null, array $context = array());
|
||||
|
||||
/**
|
||||
* @param string $criteria
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($criteria = 'default');
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsPresenter;
|
||||
|
||||
use Flasher\Prime\TestsManager\AbstractManager;
|
||||
|
||||
/**
|
||||
* @method \Flasher\Prime\TestsPresenter\PresenterInterface make($name = null, array $context = array())
|
||||
*/
|
||||
final class PresenterManager extends AbstractManager
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<p align="center"><img width="600" alt="flasher" src="https://user-images.githubusercontent.com/10859693/100492861-fabfd800-3130-11eb-8c5e-242fff1706a9.png"></p>
|
||||
|
||||
<h1 align="center">Easy flash notifications for PHP, Laravel, Symfony, Lumen</h1>
|
||||
|
||||
<p align="center">:eyes: PHP Flasher library helps you to add flash notifications to your projects. This library was developed with the idea that you should be able to add flash notification to your application with ease and with few lines of code. No application-wide rewrites and no big investments upfront.</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/php-flasher/flasher">
|
||||
<img src="https://img.shields.io/badge/source-php--flasher/flasher-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/php-flasher/flasher/releases">
|
||||
<img src="https://img.shields.io/github/tag/php-flasher/flasher.svg">
|
||||
</a>
|
||||
<a href="https://github.com/php-flasher/flasher/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg">
|
||||
</a>
|
||||
<a href="https://packagist.org/packages/php-flasher/flasher">
|
||||
<img src="https://img.shields.io/packagist/dt/php-flasher/flasher.svg">
|
||||
</a>
|
||||
<a href="https://packagist.org/packages/php-flasher/flasher">
|
||||
<img src="https://img.shields.io/packagist/php-v/php-flasher/flasher.svg?style=flat-square">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## Introduction
|
||||
|
||||
PHP Flasher library helps you to add flash notifications to your 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 a variety of notification libraries : __toastr.js__, __sweet alert 2__, __pflasher__ and __notyf__
|
||||
and its highly extendable so you can add custom adapters.
|
||||
|
||||
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 response with Ajax or Websockets
|
||||
> * Limit the number of displayed notifications
|
||||
> * Show notifications from different adapters at the same time
|
||||
> * implementations for popular frameworks : Symfony and Laravel
|
||||
> * ...and more
|
||||
|
||||
|
||||
## Official Documentation
|
||||
|
||||
Documentation for Valet can be found on the [PHP Flasher website](https://php-flasher.github.io/).
|
||||
|
||||
## License
|
||||
|
||||
PHP Flasher is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsRenderer;
|
||||
|
||||
interface HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function renderOptions();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsRenderer;
|
||||
|
||||
interface HasScriptsInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getScripts();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsRenderer;
|
||||
|
||||
interface HasStylesInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStyles();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsRenderer;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
interface RendererInterface
|
||||
{
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(Envelope $envelope);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsRenderer;
|
||||
|
||||
use Flasher\Prime\TestsManager\AbstractManager;
|
||||
|
||||
/**
|
||||
* @method \Flasher\Prime\TestsRenderer\RendererInterface make($name = null, array $context = array())
|
||||
*/
|
||||
class RendererManager extends AbstractManager
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class CreatedAtStamp implements StampInterface, OrderableStampInterface
|
||||
{
|
||||
/**
|
||||
* @param \DateTime
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @param \DateTime|null $createdAt
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(\DateTime $createdAt = null)
|
||||
{
|
||||
$this->createdAt = $createdAt ?: new \DateTime('now', new \DateTimeZone('Africa/Casablanca'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsStamp\OrderableStampInterface $orderable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compare($orderable)
|
||||
{
|
||||
if (!$orderable instanceof CreatedAtStamp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->createdAt > $orderable->createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class HandlerStamp implements StampInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $handler;
|
||||
|
||||
/**
|
||||
* @param string $handler
|
||||
*/
|
||||
public function __construct($handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
interface OrderableStampInterface
|
||||
{
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsStamp\OrderableStampInterface $orderable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compare($orderable);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class PriorityStamp implements StampInterface, OrderableStampInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $priority;
|
||||
|
||||
/**
|
||||
* @param int $priority
|
||||
*/
|
||||
public function __construct($priority)
|
||||
{
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsStamp\OrderableStampInterface $orderable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compare($orderable)
|
||||
{
|
||||
if (!$orderable instanceof PriorityStamp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->priority > $orderable->priority;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class RenderedAtStamp implements StampInterface
|
||||
{
|
||||
/**
|
||||
* @param \DateTime
|
||||
*/
|
||||
private $renderedAt;
|
||||
|
||||
/**
|
||||
* @param \DateTime|null $renderedAt
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(\DateTime $renderedAt = null)
|
||||
{
|
||||
$this->renderedAt = $renderedAt ?: new \DateTime('now', new \DateTimeZone('Africa/Casablanca'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getRenderedAt()
|
||||
{
|
||||
return $this->renderedAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class ReplayStamp implements StampInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*/
|
||||
public function __construct($count)
|
||||
{
|
||||
$this->count = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
interface StampInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStamp;
|
||||
|
||||
final class UuidStamp implements StampInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $uuid;
|
||||
|
||||
/**
|
||||
* @param string|null $uuid
|
||||
*/
|
||||
public function __construct($uuid = null)
|
||||
{
|
||||
$this->uuid = $uuid ?: sprintf(
|
||||
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(16384, 20479),
|
||||
mt_rand(32768, 49151),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope|\Notify\Envelope[] $envelopes
|
||||
*
|
||||
* @return array<string, \Notify\Envelope>
|
||||
*/
|
||||
public static function indexWithUuid($envelopes)
|
||||
{
|
||||
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
||||
|
||||
$map = array();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$uuid = $envelope->get('Flasher\Prime\TestsStamp\UuidStamp')->getUuid();
|
||||
|
||||
$map[$uuid] = $envelope;
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUuid()
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStorage;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\UuidStamp;
|
||||
|
||||
final class ArrayStorage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* @var Envelope[]
|
||||
*/
|
||||
private $envelopes = array();
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->envelopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function add($envelopes)
|
||||
{
|
||||
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
if (null === $envelope->get('Flasher\Prime\TestsStamp\UuidStamp')) {
|
||||
$envelope->withStamp(new UuidStamp());
|
||||
}
|
||||
|
||||
$this->envelopes[] = $envelope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*/
|
||||
public function remove($envelopes)
|
||||
{
|
||||
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
||||
|
||||
$map = UuidStamp::indexWithUuid($envelopes);
|
||||
|
||||
$this->envelopes = array_filter(
|
||||
$this->envelopes,
|
||||
function (Envelope $envelope) use ($map) {
|
||||
$uuid = $envelope->get('Flasher\Prime\TestsStamp\UuidStamp')->getUuid();
|
||||
|
||||
return !isset($map[$uuid]);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->envelopes = array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStorage;
|
||||
|
||||
interface StorageInterface
|
||||
{
|
||||
/**
|
||||
* @return \Notify\Envelope[]
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope|\Notify\Envelope[] $envelopes
|
||||
*/
|
||||
public function add($envelopes);
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope|\Notify\Envelope[] $envelopes
|
||||
*/
|
||||
public function remove($envelopes);
|
||||
|
||||
/**
|
||||
* Remove all notifications from the storage
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStorage;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\ReplayStamp;
|
||||
|
||||
final class StorageManager implements StorageManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\TestsStorage\StorageInterface
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @param \Flasher\Prime\TestsStorage\StorageInterface $storage
|
||||
*/
|
||||
public function __construct(StorageInterface $storage)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function flush($envelopes)
|
||||
{
|
||||
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
|
||||
|
||||
$this->storage->remove($envelopes);
|
||||
|
||||
foreach ($envelopes as $envelope) {
|
||||
$replayStamp = $envelope->get('Flasher\Prime\TestsStamp\ReplayStamp');
|
||||
$replayCount = null === $replayStamp ? 0 : $replayStamp->getCount() - 1;
|
||||
|
||||
if (1 > $replayCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$envelope->with(new ReplayStamp($replayCount));
|
||||
$this->storage->add($envelope);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->storage->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function add(Envelope $envelope)
|
||||
{
|
||||
$this->storage->add($envelope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function remove($envelopes)
|
||||
{
|
||||
$this->storage->remove($envelopes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->storage->clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\TestsStorage;
|
||||
|
||||
use Notify\Envelope;
|
||||
|
||||
interface StorageManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*/
|
||||
public function flush($envelopes);
|
||||
|
||||
/**
|
||||
* @return \Notify\Envelope[]
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope $envelope
|
||||
*/
|
||||
public function add(Envelope $envelope);
|
||||
|
||||
/**
|
||||
* @param \Notify\Envelope[] $envelopes
|
||||
*/
|
||||
public function remove($envelopes);
|
||||
|
||||
/**
|
||||
* remove All notifications from storage
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Config;
|
||||
|
||||
use Notify\Config\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ConfigTest extends TestCase
|
||||
{
|
||||
public function testGet()
|
||||
{
|
||||
$config = new Config(
|
||||
array(
|
||||
'default' => 'notify',
|
||||
'drivers' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals('notify', $config->get('default'));
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
),
|
||||
$config->get('drivers.notify')
|
||||
);
|
||||
$this->assertEquals(array('styles.css'), $config->get('drivers.notify.styles'));
|
||||
$this->assertEquals(array(), $config->get('drivers.notify.options'));
|
||||
$this->assertEquals(null, $config->get('drivers.not_exists.options'));
|
||||
$this->assertEquals('now_it_exists', $config->get('drivers.not_exists.options', 'now_it_exists'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope;
|
||||
|
||||
use Notify\Envelope;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class EnvelopeTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = $this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock();
|
||||
|
||||
$envelope = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertSame(array(get_class($stamp) => $stamp), $envelope->all());
|
||||
}
|
||||
|
||||
public function testWith()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp1 = $this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock();
|
||||
$stamp2 = $this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock();
|
||||
|
||||
$envelope = new Envelope($notification);
|
||||
$envelope->with($stamp1, $stamp2);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertSame(array(get_class($stamp1) => $stamp1, get_class($stamp2) => $stamp2), $envelope->all());
|
||||
}
|
||||
|
||||
public function testWrap()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = $this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock();
|
||||
|
||||
$envelope = Envelope::wrap($notification, array($stamp));
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertSame(array(get_class($stamp) => $stamp), $envelope->all());
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamps = array(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
);
|
||||
|
||||
$envelope = new Envelope($notification, $stamps);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertSame(array(get_class($stamps[0]) => $stamps[3]), $envelope->all());
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$notification = $this->getMockBuilder('\Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamps = array(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsStamp\StampInterface')->getMock(),
|
||||
);
|
||||
|
||||
$envelope = new \Notify\Envelope($notification, $stamps);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
|
||||
$last = $envelope->get(get_class($stamps[0]));
|
||||
|
||||
$this->assertSame($stamps[2], $last);
|
||||
$this->assertSame($last, $envelope->get(get_class($stamps[0])));
|
||||
|
||||
$this->assertNull($envelope->get('NotFoundStamp'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope\Stamp;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\CreatedAtStamp;
|
||||
use Flasher\Prime\TestsStamp\ReplayStamp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CreatedAtStampTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = new CreatedAtStamp();
|
||||
|
||||
$envelop = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($stamp, $envelop->get('Flasher\Prime\TestsStamp\CreatedAtStamp'));
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsStamp\StampInterface', $stamp);
|
||||
}
|
||||
|
||||
public function testCompare()
|
||||
{
|
||||
$createdAt1 = new \Flasher\Prime\TestsStamp\CreatedAtStamp(new \DateTime('+2 h'));
|
||||
$createdAt2 = new \Flasher\Prime\TestsStamp\CreatedAtStamp(new \DateTime('+1 h'));
|
||||
|
||||
$this->assertFalse($createdAt1->compare($createdAt2));
|
||||
$this->assertSame(0, $createdAt1->compare(new ReplayStamp(1)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope\Stamp;
|
||||
|
||||
use Notify\Envelope;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LifeStampTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = new \Flasher\Prime\TestsStamp\ReplayStamp(5);
|
||||
|
||||
$envelop = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($stamp, $envelop->get('Flasher\Prime\TestsStamp\ReplayStamp'));
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsStamp\ReplayStamp', $stamp);
|
||||
$this->assertSame(5, $stamp->getCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope\Stamp;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsStamp\PriorityStamp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PriorityStampTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = new PriorityStamp(5);
|
||||
|
||||
$envelop = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($stamp, $envelop->get('Flasher\Prime\TestsStamp\PriorityStamp'));
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsStamp\StampInterface', $stamp);
|
||||
$this->assertSame(5, $stamp->getPriority());
|
||||
}
|
||||
|
||||
public function testCompare()
|
||||
{
|
||||
$stamp1 = new PriorityStamp(1);
|
||||
$stamp2 = new \Flasher\Prime\TestsStamp\PriorityStamp(2);
|
||||
|
||||
$this->assertFalse($stamp1->compare($stamp2));
|
||||
$this->assertSame(0, $stamp1->compare(new \Flasher\Prime\TestsStamp\ReplayStamp(1)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope\Stamp;
|
||||
|
||||
use Notify\Envelope;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class RendererStampTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = new \Flasher\Prime\TestsStamp\HandlerStamp('toastr');
|
||||
|
||||
$envelop = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($stamp, $envelop->get('Flasher\Prime\TestsStamp\HandlerStamp'));
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsStamp\HandlerStamp', $stamp);
|
||||
$this->assertSame('toastr', $stamp->getHandler());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Envelope\Stamp;
|
||||
|
||||
use Notify\Envelope;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class UuidStampTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock();
|
||||
$stamp = new \Flasher\Prime\TestsStamp\UuidStamp();
|
||||
|
||||
$envelop = new Envelope($notification, array($stamp));
|
||||
|
||||
$this->assertSame($stamp, $envelop->get('Flasher\Prime\TestsStamp\UuidStamp'));
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsStamp\UuidStamp', $stamp);
|
||||
$this->assertNotEmpty($stamp->getUuid());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Filter;
|
||||
|
||||
use Flasher\Prime\TestsFilter\CriteriaBuilder;
|
||||
use Flasher\Prime\TestsFilter\FilterBuilder;
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
|
||||
final class CriteriaBuilderTest extends TestCase
|
||||
{
|
||||
public function testCriteria()
|
||||
{
|
||||
$criteria = new CriteriaBuilder(
|
||||
new FilterBuilder(), array(
|
||||
'priority' => 1,
|
||||
'life' => 2,
|
||||
'limit' => 2,
|
||||
'order_by' => 'Flasher\Prime\TestsStamp\ReplayStamp',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsFilter\FilterBuilder', $criteria->build());
|
||||
$this->assertNotEmpty($criteria->build()->getSpecification());
|
||||
}
|
||||
|
||||
public function testWithoutPriority()
|
||||
{
|
||||
$criteria = new CriteriaBuilder(new FilterBuilder(), array());
|
||||
|
||||
$this->assertInstanceOf('Flasher\Prime\TestsFilter\FilterBuilder', $criteria->build());
|
||||
$this->assertEmpty($criteria->build()->getSpecification());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Filter;
|
||||
|
||||
use Notify\Config\Config;
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsMiddleware\AddCreatedAtStampMiddleware;
|
||||
use Flasher\Prime\TestsMiddleware\AddPriorityStampMiddleware;
|
||||
use Flasher\Prime\TestsStamp\PriorityStamp;
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
|
||||
final class DefaultFilterTest extends TestCase
|
||||
{
|
||||
public function testWithCriteria()
|
||||
{
|
||||
$notifications = array(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
);
|
||||
|
||||
$notifications[3] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(5))
|
||||
);
|
||||
|
||||
$notifications[4] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(-1))
|
||||
);
|
||||
|
||||
$notifications[5] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(1))
|
||||
);
|
||||
|
||||
$config = new Config(
|
||||
array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Filter;
|
||||
|
||||
use Notify\Config\Config;
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsFilter\FilterBuilder;
|
||||
use Flasher\Prime\TestsFilter\Specification\PrioritySpecification;
|
||||
use Flasher\Prime\TestsMiddleware\AddCreatedAtStampMiddleware;
|
||||
use Flasher\Prime\TestsMiddleware\AddPriorityStampMiddleware;
|
||||
use Flasher\Prime\TestsMiddleware\NotifyBus;
|
||||
use Flasher\Prime\TestsStamp\PriorityStamp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FilterManagerTest extends TestCase
|
||||
{
|
||||
public function testFilterWhere()
|
||||
{
|
||||
$notifications = array(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
);
|
||||
|
||||
$notifications[3] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(5))
|
||||
);
|
||||
|
||||
$notifications[4] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(-1))
|
||||
);
|
||||
|
||||
$notifications[5] = new Envelope(
|
||||
$this->getMockBuilder('Flasher\Prime\TestsNotification\NotificationInterface')->getMock(),
|
||||
array(new PriorityStamp(1))
|
||||
);
|
||||
|
||||
$config = new Config(
|
||||
array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$middleware = new NotifyBus($config);
|
||||
|
||||
$envelopes = array();
|
||||
foreach ($notifications as $notification) {
|
||||
$envelopes[] = $middleware->dispatch($notification);
|
||||
}
|
||||
|
||||
$builder = new FilterBuilder();
|
||||
|
||||
$envelopes = $builder
|
||||
->andWhere(new PrioritySpecification(1))
|
||||
->andWhere(new PrioritySpecification(1, 5))
|
||||
->orderBy(
|
||||
array(
|
||||
'Flasher\Prime\TestsStamp\PriorityStamp' => 'ASC'
|
||||
)
|
||||
)
|
||||
->setMaxResults(2)
|
||||
->filter($envelopes);
|
||||
|
||||
$this->assertNotEmpty($envelopes);
|
||||
|
||||
$builder = new FilterBuilder();
|
||||
|
||||
$envelopes = $builder
|
||||
->orWhere(new PrioritySpecification(1))
|
||||
->orWhere(new PrioritySpecification(1, 5))
|
||||
->orderBy(
|
||||
array(
|
||||
'Flasher\Prime\TestsStamp\PriorityStamp' => 'ASC',
|
||||
'Notify\Envelope\Stamp\NotExists' => 'ASC',
|
||||
)
|
||||
)
|
||||
->setMaxResults(2)
|
||||
->filter($envelopes);
|
||||
|
||||
$this->assertNotEmpty($envelopes);
|
||||
|
||||
$builder = new FilterBuilder();
|
||||
$builder->withCriteria(
|
||||
array(
|
||||
'priority' => '1'
|
||||
)
|
||||
);
|
||||
|
||||
$envelopes = $builder->filter($envelopes);
|
||||
$this->assertNotEmpty($envelopes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Manager;
|
||||
|
||||
use Notify\Notify;
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
|
||||
final class ManagerTest extends TestCase
|
||||
{
|
||||
public function testDefaultDriver()
|
||||
{
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$config->method('get')
|
||||
->with('default')
|
||||
->willReturn('default_notifier');
|
||||
|
||||
$manager = new Notify($config);
|
||||
$this->assertEquals('default_notifier', $manager->getDefaultDriver());
|
||||
}
|
||||
|
||||
public function testMakeDriver()
|
||||
{
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$config->method('get')
|
||||
->with('default')
|
||||
->willReturn('default_notifier');
|
||||
|
||||
$manager = new Notify($config);
|
||||
|
||||
$producer = $this->getMockBuilder('Notify\NotifyFactory')->getMock();
|
||||
$producer->method('supports')->willReturn(true);
|
||||
$manager->addDriver($producer);
|
||||
|
||||
$this->assertSame($producer, $manager->make('fake'));
|
||||
}
|
||||
|
||||
public function testDriverNotSupported()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException', 'Driver [test_driver] not supported.');
|
||||
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$config->method('get')
|
||||
->with('default')
|
||||
->willReturn('default_notifier');
|
||||
|
||||
$manager = new Notify($config);
|
||||
|
||||
$producer = $this->getMockBuilder('Notify\NotifyFactory')->getMock();
|
||||
$manager->addDriver($producer);
|
||||
|
||||
$manager->make('test_driver');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Middleware;
|
||||
|
||||
use Flasher\Prime\Config\Config;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Middleware\AddCreatedAtStampMiddleware;
|
||||
use Flasher\Prime\Middleware\AddPriorityStampMiddleware;
|
||||
use Flasher\Prime\Middleware\MiddlewareManager;
|
||||
use Flasher\Prime\Stamp\PriorityStamp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MiddlewareStackTest extends TestCase
|
||||
{
|
||||
public function testHandle()
|
||||
{
|
||||
$config = new Config(array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
));
|
||||
|
||||
$stack = new MiddlewareManager($config);
|
||||
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock();
|
||||
$envelope = new Envelope($notification);
|
||||
|
||||
$stack->handle($envelope);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertCount(3, $envelope->all());
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\PriorityStamp', $priorityStamp);
|
||||
// $this->assertEquals(0, $priorityStamp->getPriority());
|
||||
|
||||
$timeStamp = $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\CreatedAtStamp', $timeStamp);
|
||||
|
||||
$this->assertEquals(time(), $timeStamp->getCreatedAt()->getTimestamp());
|
||||
}
|
||||
|
||||
public function testHandleWithExistingStamps()
|
||||
{
|
||||
$config = new Config(array(
|
||||
'default' => 'notify',
|
||||
'adapters' => array(
|
||||
'notify' => array(
|
||||
'scripts' => array('script.js'),
|
||||
'styles' => array('styles.css'),
|
||||
'options' => array()
|
||||
)
|
||||
),
|
||||
'stamps_middlewares' => array(
|
||||
new AddPriorityStampMiddleware(),
|
||||
new AddCreatedAtStampMiddleware(),
|
||||
)
|
||||
));
|
||||
|
||||
$stack = new MiddlewareManager($config);
|
||||
|
||||
$notification = $this->getMockBuilder('Flasher\Prime\Notification\NotificationInterface')->getMock();
|
||||
$stamps = array(
|
||||
new PriorityStamp(1),
|
||||
);
|
||||
$envelope = new Envelope($notification, $stamps);
|
||||
|
||||
$stack->handle($envelope);
|
||||
|
||||
$this->assertSame($notification, $envelope->getNotification());
|
||||
$this->assertCount(3, $envelope->all());
|
||||
|
||||
$priorityStamp = $envelope->get('Flasher\Prime\Stamp\PriorityStamp');
|
||||
$this->assertInstanceOf('Flasher\Prime\Stamp\PriorityStamp', $priorityStamp);
|
||||
// $this->assertEquals(1, $priorityStamp->getPriority());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Notification;
|
||||
|
||||
use Flasher\Prime\TestsNotification\Notification;
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
|
||||
final class NotificationTest extends TestCase
|
||||
{
|
||||
public function testNotification()
|
||||
{
|
||||
$notification = new Notification('message', 'type', array('timer' => 5000));
|
||||
|
||||
$this->assertSame('type', $notification->getType());
|
||||
$this->assertSame('message', $notification->getMessage());
|
||||
$this->assertSame(array('timer' => 5000), $notification->getOptions());
|
||||
}
|
||||
|
||||
public function testAddOption()
|
||||
{
|
||||
$notification = new Notification('message', 'type', array('timer' => 5000));
|
||||
$notification->setOption('toast', true);
|
||||
|
||||
$this->assertSame(array('timer' => 5000, 'toast' => true), $notification->getOptions());
|
||||
|
||||
$notification->unsetOption('timer');
|
||||
|
||||
$this->assertSame(array('toast' => true), $notification->getOptions());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Producer;
|
||||
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
final class ProducerManagerTest extends TestCase
|
||||
{
|
||||
public function testExtendToAddMoreNotifiersFactory()
|
||||
{
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$manager = new \Notify\Notify($config);
|
||||
|
||||
$producer = $this->getMockBuilder('Notify\NotifyFactory')->getMock();
|
||||
$producer->method('supports')->willReturn(true);
|
||||
$manager->addDriver($producer);
|
||||
|
||||
$reflection = new ReflectionClass(get_class($manager));
|
||||
$extensions = $reflection->getProperty('drivers');
|
||||
$extensions->setAccessible(true);
|
||||
|
||||
$drivers = $extensions->getValue($manager);
|
||||
$this->assertCount(1, $drivers);
|
||||
|
||||
$producer1 = $manager->make('producer_1');
|
||||
$this->assertSame($producer, $producer1);
|
||||
}
|
||||
|
||||
public function testNullDriver()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException', 'Driver [] not supported.');
|
||||
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$config->method('get')->willReturn(null);
|
||||
|
||||
$manager = new \Notify\Notify($config);
|
||||
|
||||
$producer = $this->getMockBuilder('Notify\NotifyFactory')->getMock();
|
||||
$manager->addDriver($producer);
|
||||
|
||||
$this->assertSame($producer, $manager->make());
|
||||
}
|
||||
|
||||
public function testNotSupportedDriver()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException', 'Driver [not_supported] not supported.');
|
||||
|
||||
$config = $this->getMockBuilder('Notify\Config\ConfigInterface')->getMock();
|
||||
$manager = new \Notify\Notify($config);
|
||||
|
||||
$producer = $this->getMockBuilder('Notify\NotifyFactory')->getMock();
|
||||
$manager->addDriver($producer);
|
||||
|
||||
$this->assertSame($producer, $manager->make('not_supported'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Storage;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsNotification\Notification;
|
||||
use Flasher\Prime\TestsStamp\UuidStamp;
|
||||
use Flasher\Prime\TestsStorage\ArrayStorage;
|
||||
use Flasher\Prime\Tests\TestCase;
|
||||
|
||||
final class ArrayStorageTest extends TestCase
|
||||
{
|
||||
public function testAdd()
|
||||
{
|
||||
$storage = new ArrayStorage();
|
||||
$envelopes = array();
|
||||
|
||||
foreach (range(0, 4) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success', 'success message'));
|
||||
$storage->add($envelopes[$index]);
|
||||
}
|
||||
|
||||
$this->assertCount(5, $storage->all());
|
||||
}
|
||||
|
||||
public function testAddNotificationWithUuidStamp()
|
||||
{
|
||||
$storage = new ArrayStorage();
|
||||
$storage->add(new Envelope(new Notification('success')));
|
||||
|
||||
$envelopes = $storage->all();
|
||||
|
||||
$this->assertCount(1, $envelopes);
|
||||
|
||||
$uuid = $envelopes[0]->get('Flasher\Prime\TestsStamp\UuidStamp');
|
||||
$this->assertNotNull($uuid);
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$storage = new ArrayStorage();
|
||||
$envelopes = array();
|
||||
|
||||
foreach (range(0, 4) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success', 'success message'));
|
||||
$storage->add($envelopes[$index]);
|
||||
}
|
||||
|
||||
$storage->clear();
|
||||
|
||||
$this->assertSame(array(), $storage->all());
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$storage = new ArrayStorage();
|
||||
$envelopes = array();
|
||||
|
||||
foreach (range(0, 4) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success', 'success message'), new UuidStamp());
|
||||
$storage->add($envelopes[$index]);
|
||||
}
|
||||
|
||||
$storage->remove($envelopes[0], $envelopes[2]);
|
||||
|
||||
$actual = UuidStamp::indexWithUuid($storage->all());
|
||||
$expected = UuidStamp::indexWithUuid($envelopes[1], $envelopes[3], $envelopes[4]);
|
||||
|
||||
$this->assertSame(array(), array_diff_key($actual, $expected));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Storage;
|
||||
|
||||
use Notify\Envelope;
|
||||
use Flasher\Prime\TestsNotification\Notification;
|
||||
use Flasher\Prime\TestsStamp\ReplayStamp;
|
||||
use Flasher\Prime\TestsStamp\UuidStamp;
|
||||
use Flasher\Prime\TestsStorage\ArrayStorage;
|
||||
use Flasher\Prime\TestsStorage\StorageManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StorageManagerTest extends TestCase
|
||||
{
|
||||
public function testAll()
|
||||
{
|
||||
$storageManager = new StorageManager(new ArrayStorage());
|
||||
$envelopes = array();
|
||||
|
||||
foreach (range(0, 4) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success', 'success message'));
|
||||
$storageManager->add($envelopes[$index]);
|
||||
}
|
||||
|
||||
$this->assertCount(5, $storageManager->all());
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$storageManager = new StorageManager(new ArrayStorage());
|
||||
$envelopes = array();
|
||||
|
||||
foreach (range(0, 4) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success', 'success message'));
|
||||
$storageManager->add($envelopes[$index]);
|
||||
}
|
||||
|
||||
$storageManager->clear();
|
||||
|
||||
$this->assertSame(array(), $storageManager->all());
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$storageManager = new StorageManager(new ArrayStorage());
|
||||
$storageManager->add(new Envelope(new Notification('success')));
|
||||
|
||||
$envelopes = $storageManager->all();
|
||||
|
||||
$this->assertCount(1, $envelopes);
|
||||
|
||||
$uuid = $envelopes[0]->get('Flasher\Prime\TestsStamp\UuidStamp');
|
||||
$this->assertNotNull($uuid);
|
||||
}
|
||||
|
||||
public function testFlush()
|
||||
{
|
||||
$storageManager = new StorageManager(new ArrayStorage());
|
||||
|
||||
$envelope = new Envelope(
|
||||
new Notification('error message', 'error'),
|
||||
new ReplayStamp(2),
|
||||
new UuidStamp('fake-uuid')
|
||||
);
|
||||
$storageManager->add($envelope);
|
||||
|
||||
$envelopes = array();
|
||||
foreach (range(0, 2) as $index) {
|
||||
$envelopes[$index] = new Envelope(new Notification('success message', 'success'));
|
||||
$storageManager->add($envelopes[$index]);
|
||||
}
|
||||
$envelopes[] = $envelope;
|
||||
|
||||
$storageManager->flush($envelopes);
|
||||
|
||||
$this->assertSame(array('fake-uuid'), array_keys(UuidStamp::indexWithUuid($storageManager->all())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Stubs\Producer;
|
||||
|
||||
use Flasher\Prime\AbstractFlasher;
|
||||
|
||||
class FakeProducer extends AbstractFlasher
|
||||
{
|
||||
public function getRenderer()
|
||||
{
|
||||
return 'fake';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests\Stubs\Renderer;
|
||||
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasGlobalOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
class FakeRenderer implements RendererInterface, HasScriptsInterface, HasGlobalOptionsInterface, HasStylesInterface
|
||||
{
|
||||
public function renderOptions()
|
||||
{
|
||||
return 'fake.options = []';
|
||||
}
|
||||
|
||||
public function getScripts()
|
||||
{
|
||||
return array('jquery.min.js', 'fake.min.js');
|
||||
}
|
||||
|
||||
public function getStyles()
|
||||
{
|
||||
return array('fake.min.css');
|
||||
}
|
||||
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
return sprintf(
|
||||
"fake.%s('%s', '%s');",
|
||||
$envelope->getType(),
|
||||
$envelope->getMessage(),
|
||||
$envelope->getTitle()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Prime\Tests;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
} else {
|
||||
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function callMethod(&$object, $methodName, $parameters = array())
|
||||
{
|
||||
$reflection = new ReflectionClass(get_class($object));
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
$parameters = is_array($parameters) ? $parameters : array_slice(func_get_args(), 2);
|
||||
|
||||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "php-flasher/flasher",
|
||||
"description": "a flash notifications library for PHP",
|
||||
"keywords": [
|
||||
"notify",
|
||||
"flash",
|
||||
"php",
|
||||
"laravel",
|
||||
"symfony",
|
||||
"Lumen",
|
||||
"notifications",
|
||||
"messages",
|
||||
"alerts",
|
||||
"pnotify",
|
||||
"toastr "
|
||||
],
|
||||
"homepage": "https://github.com/php-flasher/flasher",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Younes Khoubza",
|
||||
"email": "younes.khoubza@gmail.com",
|
||||
"homepage": "https://github.com/yoeunes",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=4.8.36"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Flasher\\Prime\\": "",
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"helpers.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="true">
|
||||
<testsuites>
|
||||
<testsuite name="Flasher Test Suite">
|
||||
<directory>Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user