Skip to content

Commit 616f569

Browse files
committed
Changed event class to be optional
1 parent 83e32e1 commit 616f569

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/Models/BaseModel.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getIdField() : string
6565
/**
6666
* Expressive way to use the destroy method via dao repository
6767
*
68-
* @return \EdStevo\Dao\Repositories\BaseModel
68+
* @return \EdStevo\Dao\Models\BaseModel
6969
*/
7070
public function daoUpdate(array $data = []) : BaseModel
7171
{
@@ -77,7 +77,7 @@ public function daoUpdate(array $data = []) : BaseModel
7777
/**
7878
* Expressive way to use the destroy method via dao repository
7979
*
80-
* @return \EdStevo\Dao\Repositories\BaseModel
80+
* @return \EdStevo\Dao\Models\BaseModel
8181
*/
8282
public function daoIncrement(string $field = "", int $value = 1) : BaseModel
8383
{
@@ -127,7 +127,7 @@ public function daoGetRelationWhere(string $relation, array $constraints = []) :
127127
* @param string $relation
128128
* @param array $data
129129
*
130-
* @return \EdStevo\Dao\Repositories\BaseModel
130+
* @return \EdStevo\Dao\Models\BaseModel
131131
*/
132132
public function daoStoreRelation(string $relation, array $data = []) : BaseModel
133133
{
@@ -138,10 +138,10 @@ public function daoStoreRelation(string $relation, array $data = []) : BaseModel
138138
* Expressive way to use the update relation method with this model via the dao repository
139139
*
140140
* @param string $relationship
141-
* @param \EdStevo\Dao\Repositories\BaseModel $relation
141+
* @param \EdStevo\Dao\Models\BaseModel $relation
142142
* @param array $data
143143
*
144-
* @return \EdStevo\Dao\Repositories\BaseModel
144+
* @return \EdStevo\Dao\Models\BaseModel
145145
*/
146146
public function daoUpdateRelation(string $relationship, BaseModel $relation, array $data = []) : BaseModel
147147
{
@@ -152,7 +152,7 @@ public function daoUpdateRelation(string $relationship, BaseModel $relation, arr
152152
* Expressive way to use the update pivot method with this model via the dao repository
153153
*
154154
* @param string $relationship
155-
* @param \EdStevo\Dao\Repositories\BaseModel $relation
155+
* @param \EdStevo\Dao\Models\BaseModel $relation
156156
* @param array $data
157157
*
158158
* @return int
@@ -166,7 +166,7 @@ public function daoUpdatePivot(string $relationship, BaseModel $relation, array
166166
* Expressive way to use the destroy relation method with this model via the dao repository
167167
*
168168
* @param string $relationship
169-
* @param \EdStevo\Dao\Repositories\BaseModel $relation
169+
* @param \EdStevo\Dao\Models\BaseModel $relation
170170
*
171171
* @return bool
172172
*/
@@ -179,7 +179,7 @@ public function daoDestroyRelation(string $relationship, BaseModel $relation) :
179179
* Expressive way to use the attach method with this model via the dao repository
180180
*
181181
* @param string $relation
182-
* @param \EdStevo\Dao\Repositories\BaseModel $model
182+
* @param \EdStevo\Dao\Models\BaseModel $model
183183
* @param array $pivotData
184184
*/
185185
public function daoAttach(string $relation, Model $model, array $pivotData = [])
@@ -242,7 +242,7 @@ public function getRules() : array
242242
/**
243243
* Return the dao repository related to this model
244244
*
245-
* @return \EdStevo\Dao\Repositories\BaseModel
245+
* @return \EdStevo\Dao\Models\BaseModel
246246
*/
247247
public function getDaoRepository()
248248
{
@@ -252,7 +252,7 @@ public function getDaoRepository()
252252
/**
253253
* Flush this model's dao's cache
254254
*
255-
* @return \EdStevo\Dao\Repositories\BaseModel
255+
* @return \EdStevo\Dao\Models\BaseModel
256256
*/
257257
public function flushDaoCache() : BaseModel
258258
{
@@ -264,7 +264,7 @@ public function flushDaoCache() : BaseModel
264264
/**
265265
* Flush this model's dao's cache
266266
*
267-
* @return \EdStevo\Dao\Repositories\BaseModel
267+
* @return \EdStevo\Dao\Models\BaseModel
268268
*/
269269
public function flushModelCache() : BaseModel
270270
{
@@ -278,9 +278,10 @@ public function flushModelCache() : BaseModel
278278
*
279279
* @return string
280280
*/
281-
private function getModelName() : string
281+
public function getModelName() : string
282282
{
283-
return collect(explode('\\', get_class($this)))->last();
283+
$namespace = basename(get_class($this), ".php");
284+
return collect(explode('\\', $namespace))->last();
284285
}
285286

286287
/**

src/Repositories/DaoEventDispatcher.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public function fire()
149149
return;
150150

151151
$eventName = $this->getEventNamespace();
152-
broadcast(new $eventName($this->primaryModel, $this->relatedModel))->toOthers();
152+
153+
if(class_exists($eventName))
154+
{
155+
broadcast(new $eventName($this->primaryModel, $this->relatedModel))->toOthers();
156+
}
153157
}
154158

155159
/**
@@ -198,12 +202,12 @@ private function getEventsNamespace() : string
198202
*/
199203
private function getEventNamespace() : string
200204
{
201-
$modelName = $this->getClassName($this->primaryModel->getModel());
205+
$modelName = $this->getClassName($this->primaryModel->getModelName());
202206
$eventString = $this->getEventsNamespace() . $modelName;
203207

204208
if ($this->relatedModel)
205209
{
206-
$relatedName = $this->getClassName($this->relatedModel->getModel());
210+
$relatedName = $this->getClassName($this->relatedModel->getModelName());
207211
$eventString = $eventString . "\\" . $relatedName . "\\" . $relatedName;
208212
} else {
209213
$eventString = $eventString . "\\" . $modelName . "\\" . $modelName;

0 commit comments

Comments
 (0)