Skip to content

Commit 69991b6

Browse files
committed
dded functionality to inject custom builder class for handling conflicting packages.
1 parent e97c07e commit 69991b6

File tree

8 files changed

+74
-8
lines changed

8 files changed

+74
-8
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.10.2] - 2020-09-04
8+
### Added
9+
- functionality to inject custom builder class for handling conflicting packages.
10+
711
## [0.10.1] - 2020-08-02
812
### Fixed
913
- typos in test class.
@@ -307,7 +311,7 @@ Pushed changes intended for 0.5.1. Forgot to push changes to repo. 👀
307311

308312
## [0.3.3] - 10 Nov 2018
309313
### Fixed
310-
- typo in method `checkCooldownAndFlushAfterPersiting()` to
314+
- typo in method `checkCooldownAndFlushAfterPersiting()` to
311315
`checkCooldownAndFlushAfterPersisting()`; thanks @jacobzlogar!
312316

313317
## [0.3.2] - 3 Nov 2018

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,28 @@ The following are packages we have identified as incompatible:
6262
- [chelout/laravel-relationship-events](https://github.com/chelout/laravel-relationship-events)
6363
- [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder)
6464
- [dwightwatson/rememberable](https://github.com/dwightwatson/rememberable)
65-
- [kalnoy/nestedset](https://github.com/kalnoy/nestedset)
65+
- [kalnoy/nestedset](https://github.com/lazychaser/laravel-nestedset)
66+
67+
#### Override
68+
It may be possible to insert the custom querybuilder of the conflicting package
69+
into this package by adding the following to your AppServiceProvider, in this
70+
example we are implementing the NestedSet QueryBuilder:
71+
```php
72+
//...
73+
use GeneaLabs\LaravelModelCaching\ModelCaching;
74+
use Kalnoy\Nestedset\QueryBuilder;
75+
76+
class AppServiceProvider extends ServiceProvider
77+
{
78+
public function boot()
79+
{
80+
ModelCaching::useBuilder(QueryBuilder::class);
81+
//...
82+
}
83+
84+
//...
85+
}
86+
```
6687

6788
### Things That Don't Work Currently
6889
The following items currently do no work with this package:

phpcs.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
3+
<description>GeneaLabs coding standards.</description>
4+
5+
<rule ref="PSR1"></rule>
6+
<rule ref="PSR2"></rule>
7+
<rule ref="PSR12">
8+
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
9+
<exclude name="PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon"/>
10+
</rule>
11+
</ruleset>

src/CachedBuilder.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php namespace GeneaLabs\LaravelModelCaching;
22

3-
use GeneaLabs\LaravelModelCaching\Traits\BuilderCaching;
43
use GeneaLabs\LaravelModelCaching\Traits\Buildable;
4+
use GeneaLabs\LaravelModelCaching\Traits\BuilderCaching;
55
use GeneaLabs\LaravelModelCaching\Traits\Caching;
6-
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
76

87
class CachedBuilder extends EloquentBuilder
98
{

src/Helper.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace GeneaLabs\LaravelModelCaching;
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching;
24

35
use Illuminate\Container\Container;
46

src/ModelCaching.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
7+
class ModelCaching
8+
{
9+
protected static $builder = Builder::class;
10+
11+
public static function useEloquentBuilder(string $builder) : void
12+
{
13+
self::$builder = $builder;
14+
}
15+
16+
public static function builder()
17+
{
18+
return self::$builder;
19+
}
20+
}

src/Providers/Service.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<?php namespace GeneaLabs\LaravelModelCaching\Providers;
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching\Providers;
24

35
use GeneaLabs\LaravelModelCaching\Console\Commands\Clear;
46
use GeneaLabs\LaravelModelCaching\Console\Commands\Publish;
57
use GeneaLabs\LaravelModelCaching\Helper;
8+
use GeneaLabs\LaravelModelCaching\ModelCaching;
69
use Illuminate\Support\ServiceProvider;
710

811
class Service extends ServiceProvider
@@ -24,6 +27,13 @@ public function boot()
2427

2528
public function register()
2629
{
30+
if (! class_exists('GeneaLabs\LaravelModelCaching\EloquentBuilder')) {
31+
class_alias(
32+
ModelCaching::builder(),
33+
'GeneaLabs\LaravelModelCaching\EloquentBuilder'
34+
);
35+
}
36+
2737
$this->app->bind("model-cache", Helper::class);
2838
}
2939
}

src/Traits/ModelCaching.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
use GeneaLabs\LaravelModelCaching\CachedBelongsToMany;
44
use GeneaLabs\LaravelModelCaching\CachedBuilder;
5-
use Illuminate\Container\Container;
6-
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
5+
use GeneaLabs\LaravelModelCaching\EloquentBuilder;
76
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
98
use Illuminate\Support\Carbon;

0 commit comments

Comments
 (0)