-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
33 changed files
with
271 additions
and
367 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,108 @@ | ||
# Nextras ORM Events | ||
|
||
## Content | ||
|
||
- [Config](#config) | ||
- [Entity](#entity) | ||
- [Service](#service) | ||
- [Real example](#real-example) | ||
|
||
## Usage | ||
|
||
### Config | ||
|
||
```yaml | ||
extensions: | ||
orm.events: Contributte\Nextras\Orm\Events\DI\NextrasOrmEventsExtension | ||
``` | ||
```yaml | ||
services: | ||
- App\Model\BeforePersistListener | ||
``` | ||
### Entity | ||
Just add annotation `@<Before/Update>` to your entity. | ||
|
||
```php | ||
/** | ||
* @BeforeInsert(App\Model\BeforeInsertListener) | ||
* @BeforePersist(App\Model\BeforePersistListener) | ||
* @BeforeRemove(App\Model\BeforeRemoveListener) | ||
* @BeforeUpdate(App\Model\BeforeUpdateListener) | ||
* @AfterInsert(App\Model\AfterInsertListener) | ||
* @AfterPersist(App\Model\AfterPersistListener) | ||
* @AfterRemove(App\Model\AfterRemoveListener) | ||
* @AfterUpdate(App\Model\AfterUpdateListener) | ||
* @Lifecycle(App\Model\LifecycleListener) | ||
*/ | ||
class Foo extends Entity | ||
{ | ||
} | ||
``` | ||
|
||
### Service | ||
|
||
```php | ||
namespace App\Model; | ||
use Contributte\Nextras\Orm\Events\Listeners\BeforePersistListener; | ||
use Nextras\Orm\Entity\IEntity; | ||
final class BeforePersistListener implements BeforePersistListener | ||
{ | ||
public function onBeforePersist(IEntity $entity): void | ||
{ | ||
// ... | ||
} | ||
} | ||
``` | ||
|
||
### Real example | ||
|
||
```yaml | ||
service: | ||
- App\Model\FooBeforeInsertListener | ||
``` | ||
|
||
```php | ||
/** | ||
* @BeforeInsert(App\Model\FooBeforeInsertListener) | ||
*/ | ||
class Foo extends Entity | ||
{ | ||
} | ||
``` | ||
|
||
```php | ||
// Generated container.. | ||
/** | ||
* @return FooRepository | ||
*/ | ||
public function createServiceOrm__repositories__foo() | ||
{ | ||
$service = new FooRepository( | ||
$this->getService('orm.mappers.foo'), | ||
$this->getService('orm.dependencyProvider') | ||
); | ||
$service->setModel($this->getService('orm.model')); | ||
// ===== attaching events (provided by extension ===== | ||
$service->onBeforeInsert[] = [ | ||
$this->getService('App\Model\FooBeforeInsertListener'), | ||
'onBeforeInsert', | ||
]; | ||
// ===== attaching events ============================ | ||
return $service; | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,26 +1,20 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# Top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# JS / PHP | ||
[*.{js,php,phpt}] | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
indent_style = tab | ||
indent_size = 4 | ||
indent_size = tab | ||
tab_width = 4 | ||
|
||
# NEON | ||
[*.neon] | ||
charset = utf-8 | ||
indent_style = tab | ||
[*.md] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Composer, NPM, Travis, BitbucketPipelines | ||
[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}] | ||
[{composer.json,package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
indent_size = 2 |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# IDEA | ||
# IDE | ||
/.idea | ||
|
||
# Composer | ||
/composer.lock | ||
/vendor | ||
/composer.lock | ||
|
||
# Tests | ||
/temp/ | ||
/tests/*.log | ||
/tests/tmp | ||
/tests/coverage.html | ||
/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
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
Oops, something went wrong.