Skip to content

Commit 7fd3b4c

Browse files
committed
Initial commit
0 parents  commit 7fd3b4c

19 files changed

+1328
-0
lines changed

.editorconfig

Lines changed: 790 additions & 0 deletions
Large diffs are not rendered by default.

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/.php-cs-fixer.php export-ignore
6+
/phpunit.xml export-ignore

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: stayallive

.github/workflows/ci.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- develop
9+
- release/**
10+
11+
jobs:
12+
phpunit:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 15
15+
env:
16+
COMPOSER_NO_INTERACTION: 1
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php: [ "8.1" ]
22+
23+
name: phpunit (PHP:${{ matrix.php }})
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
coverage: none
34+
tools: composer:v2
35+
36+
- name: Install Composer dependencies
37+
run: composer install --no-interaction --prefer-dist --no-progress
38+
39+
- name: Run phpunit
40+
run: composer test:ci

.github/workflows/cs.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Code style
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- develop
9+
10+
jobs:
11+
php-cs-fixer:
12+
name: PHP-CS-Fixer
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.1'
22+
23+
- name: Install dependencies
24+
run: composer update --no-progress --no-interaction --prefer-dist
25+
26+
- name: Run script
27+
run: composer phpcs:ci

.github/workflows/release.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Create GitHub release
16+
uses: softprops/action-gh-release@v1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.lock
2+
/.idea
3+
/vendor
4+
/.php-cs-fixer.cache
5+
/.phpunit.result.cache

.php-cs-fixer.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests')
6+
->name('*.php')
7+
->ignoreDotFiles(true)
8+
->ignoreVCS(true);
9+
10+
$config = new PhpCsFixer\Config;
11+
12+
$config
13+
->setRules([
14+
'@Symfony' => true,
15+
16+
'yoda_style' => false,
17+
'phpdoc_order' => true,
18+
'new_with_braces' => false,
19+
'short_scalar_cast' => true,
20+
'phpdoc_to_comment' => false,
21+
'single_line_throw' => false,
22+
'single_blank_line_at_eof' => true,
23+
'no_superfluous_phpdoc_tags' => false,
24+
'linebreak_after_opening_tag' => true,
25+
'class_attributes_separation' => false,
26+
'not_operator_with_successor_space' => false,
27+
'single_trait_insert_per_statement' => false,
28+
'nullable_type_declaration_for_default_null_value' => true,
29+
30+
'concat_space' => [
31+
'spacing' => 'one',
32+
],
33+
'binary_operator_spaces' => [
34+
'operators' => [
35+
'|' => null,
36+
'=' => 'align_single_space',
37+
'=>' => 'align_single_space',
38+
],
39+
],
40+
'array_syntax' => [
41+
'syntax' => 'short',
42+
],
43+
'ordered_imports' => [
44+
'sort_algorithm' => 'length',
45+
],
46+
'cast_spaces' => [
47+
'space' => 'none',
48+
],
49+
'align_multiline_comment' => [
50+
'comment_type' => 'phpdocs_like',
51+
],
52+
'phpdoc_align' => [
53+
'align' => 'vertical',
54+
],
55+
'increment_style' => [
56+
'style' => 'post',
57+
],
58+
'phpdoc_no_alias_tag' => [
59+
'replacements' => [
60+
'type' => 'var',
61+
'link' => 'see',
62+
],
63+
],
64+
'no_extra_blank_lines' => [
65+
'tokens' => [],
66+
],
67+
])
68+
->setFinder($finder);
69+
70+
return $config;

LICENSE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2022 Alex Bouma
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Laravel Eloquent Observable
2+
3+
Register Eloquent model event listeners just-in-time directly from the model.
4+
5+
Using [Observers](https://laravel.com/docs/9.x/eloquent#observers) can introduce a (significant) overhead on the application since they are usually registered in a service
6+
provider which results in every model in your application with a observer is "booted" a startup of the application even though the model is never touched in the request. This
7+
package aims to reduce that overhead by connecting listeners just-in-time whenever the Eloquent model is booted (first used) in the request. The event callbacks are also
8+
defined on the model itself keeping the code cleaner, althought this is my preference of course and if you disagree this might not be the package for you.
9+
10+
## Installation
11+
12+
```bash
13+
composer require stayallive/laravel-eloquent-observable
14+
```
15+
16+
## Usage
17+
18+
Adding the `Observable` trait will ensure that the observable events are connected to the event handlers defined on the model.
19+
20+
```php
21+
<?php
22+
23+
namespace App\Models;
24+
25+
use Illuminate\Database\Eloquent\Model;
26+
use Stayallive\Laravel\Eloquent\Observable\Observable;
27+
28+
class SomeModel extends Model
29+
{
30+
use Observable;
31+
32+
// Event handlers are defined by `onEventName` where `EventName` is any valid Eloquent event (or custom event)
33+
// See a full list of Eloquent events: https://laravel.com/docs/9.x/eloquent#events
34+
public static function onSaving(self $model): void
35+
{
36+
// For example:
37+
$model->slug = str_slug($model->title);
38+
}
39+
}
40+
```
41+
42+
## Security Vulnerabilities
43+
44+
If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at `[email protected]`. All security vulnerabilities will be swiftly
45+
addressed.
46+
47+
## License
48+
49+
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)