-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit faef9b0
Showing
16 changed files
with
658 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
tests: | ||
name: PHP ${{ matrix.php }} - Silverstripe ${{ matrix.silverstripe }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['8.1'] | ||
silverstripe: ['4.13', '5.0'] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: mbstring, intl, pdo, mysql | ||
coverage: xdebug | ||
|
||
- name: Install dependencies | ||
run: | | ||
composer require --no-update silverstripe/framework:^${{ matrix.silverstripe }} | ||
composer install --no-interaction --no-progress | ||
- name: Run PHP CS Fixer | ||
run: vendor/bin/php-cs-fixer fix --dry-run --diff | ||
|
||
- name: Run PHPStan | ||
run: vendor/bin/phpstan analyse | ||
|
||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit --coverage-clover=coverage.xml | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/vendor/ | ||
.phpunit.result.cache | ||
.php-cs-cache | ||
.env | ||
.idea/ | ||
.vscode/ | ||
*.swp | ||
*.swo | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in([ | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests', | ||
]) | ||
->name('*.php') | ||
->ignoreDotFiles(true) | ||
->ignoreVCS(true); | ||
|
||
$config = new PhpCsFixer\Config(); | ||
|
||
return $config | ||
->setRules([ | ||
'@PSR12' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'ordered_imports' => ['sort_algorithm' => 'alpha'], | ||
'no_unused_imports' => true, | ||
'trailing_comma_in_multiline' => true, | ||
'phpdoc_align' => true, | ||
'phpdoc_order' => true, | ||
'phpdoc_separation' => true, | ||
'phpdoc_single_line_var_spacing' => true, | ||
'phpdoc_trim' => true, | ||
'phpdoc_var_without_name' => true, | ||
'return_type_declaration' => ['space_before' => 'none'], | ||
'single_quote' => true, | ||
'ternary_operator_spaces' => true, | ||
'unary_operator_spaces' => true, | ||
]) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Silverstripe Events Module | ||
|
||
This module provides PSR-14 Event Dispatcher integration for Silverstripe CMS with automatic event dispatching for DataObject CRUD operations and versioning actions. | ||
|
||
## Installation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
Name: events | ||
After: | ||
- '#coreservices' | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
ArchiPro\Silverstripe\EventDispatcher\Service\EventService: | ||
constructor: | ||
dispatcher: '%$Psr\EventDispatcher\EventDispatcherInterface' | ||
listenerProvider: '%$Psr\EventDispatcher\ListenerProviderInterface' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "archipro/silverstripe-event-dispatcher", | ||
"description": "PSR-14 Event Dispatcher integration for Silverstripe CMS", | ||
"type": "silverstripe-vendormodule", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^8.1", | ||
"silverstripe/framework": "^4.13 || ^5.0", | ||
"silverstripe/versioned": "^1.13 || ^2.0", | ||
"psr/event-dispatcher": "^1.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"squizlabs/php_codesniffer": "^3.0", | ||
"friendsofphp/php-cs-fixer": "^3.0", | ||
"phpstan/phpstan": "^1.10", | ||
"symbiote/silverstripe-phpstan": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ArchiPro\\Silverstripe\\EventDispatcher\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"ArchiPro\\Silverstripe\\EventDispatcher\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"lint": "php-cs-fixer fix --dry-run --diff", | ||
"lint-fix": "php-cs-fixer fix", | ||
"analyse": "phpstan analyse", | ||
"test": "phpunit" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"extra": { | ||
"expose": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
parameters: | ||
level: 8 | ||
paths: | ||
- src | ||
- tests | ||
excludePaths: | ||
- vendor/* | ||
silverstripe: | ||
checkUnusedViewVariables: false | ||
ignoreErrors: | ||
- '#Access to an undefined property .+::\$owner#' | ||
- '#Call to an undefined method .+::hasExtension\(\)#' | ||
includes: | ||
- vendor/symbiote/silverstripe-phpstan/phpstan.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace ArchiPro\Silverstripe\EventDispatcher\Event; | ||
|
||
use JsonSerializable; | ||
|
||
/** | ||
* Base class for all DataObject-related events. | ||
* | ||
* Provides common functionality for events that are triggered by DataObject operations. | ||
* All events are serializable to JSON for easy logging and external system integration. | ||
*/ | ||
abstract class AbstractDataObjectEvent implements JsonSerializable | ||
{ | ||
public function __construct( | ||
protected readonly int $objectID, | ||
protected readonly string $objectClass, | ||
protected readonly string $action, | ||
protected readonly array $changes = [] | ||
) {} | ||
|
||
public function getObjectID(): int | ||
{ | ||
return $this->objectID; | ||
} | ||
|
||
public function getObjectClass(): string | ||
{ | ||
return $this->objectClass; | ||
} | ||
|
||
public function getAction(): string | ||
{ | ||
return $this->action; | ||
} | ||
|
||
public function getChanges(): array | ||
{ | ||
return $this->changes; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'id' => $this->objectID, | ||
'class' => $this->objectClass, | ||
'action' => $this->action, | ||
'changes' => $this->changes, | ||
'timestamp' => time(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace ArchiPro\Silverstripe\EventDispatcher\Event; | ||
|
||
/** | ||
* Event class for DataObject deletion operations. | ||
* | ||
* This event is fired before a DataObject is permanently deleted from the database. | ||
* It allows listeners to perform cleanup or logging operations before the deletion occurs. | ||
*/ | ||
class DataObjectDeleteEvent extends AbstractDataObjectEvent | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace YourVendor\Events\Event; | ||
|
||
use SilverStripe\ORM\DataObject; | ||
|
||
class DataObjectEvent | ||
{ | ||
private DataObject $dataObject; | ||
private string $action; | ||
|
||
public function __construct(DataObject $dataObject, string $action) | ||
{ | ||
$this->dataObject = $dataObject; | ||
$this->action = $action; | ||
} | ||
|
||
public function getDataObject(): DataObject | ||
{ | ||
return $this->dataObject; | ||
} | ||
|
||
public function getAction(): string | ||
{ | ||
return $this->action; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace ArchiPro\Silverstripe\EventDispatcher\Event; | ||
|
||
/** | ||
* Event class for versioning-related actions on DataObjects. | ||
* | ||
* This event is fired when versioning actions occur, such as: | ||
* - Publishing | ||
* - Unpublishing | ||
* - Archiving | ||
* - Restoring | ||
*/ | ||
class DataObjectVersionEvent extends AbstractDataObjectEvent | ||
{ | ||
public function __construct( | ||
int $objectID, | ||
string $objectClass, | ||
string $action, | ||
private readonly ?int $version, | ||
array $changes = [] | ||
) { | ||
parent::__construct($objectID, $objectClass, $action, $changes); | ||
} | ||
|
||
public function getVersion(): ?int | ||
{ | ||
return $this->version; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return array_merge(parent::jsonSerialize(), [ | ||
'version' => $this->version, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace ArchiPro\Silverstripe\EventDispatcher\Event; | ||
|
||
/** | ||
* Event class for DataObject write operations. | ||
* | ||
* This event is fired when a DataObject is: | ||
* - Created (first write) | ||
* - Updated (subsequent writes) | ||
* | ||
* The event includes all changes made to the DataObject during the write operation. | ||
*/ | ||
class DataObjectWriteEvent extends AbstractDataObjectEvent | ||
{ | ||
} |
Oops, something went wrong.