Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
e2f783e3
Unverified
Commit
e2f783e3
authored
Sep 21, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trigger an event when a folder was created
parent
071db56d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-1
FolderWasCreated.php
Modules/Media/Events/FolderWasCreated.php
+23
-0
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+6
-1
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+14
-0
No files found.
Modules/Media/Events/FolderWasCreated.php
0 → 100644
View file @
e2f783e3
<?php
namespace
Modules\Media\Events
;
use
Modules\Media\Entities\File
;
class
FolderWasCreated
{
/**
* @var File
*/
public
$folder
;
/**
* @var array
*/
public
$data
;
public
function
__construct
(
File
$folder
,
array
$data
)
{
$this
->
folder
=
$folder
;
$this
->
data
=
$data
;
}
}
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
View file @
e2f783e3
...
...
@@ -3,17 +3,22 @@
namespace
Modules\Media\Repositories\Eloquent
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Repositories\FolderRepository
;
class
EloquentFolderRepository
extends
EloquentBaseRepository
implements
FolderRepository
{
public
function
create
(
$data
)
{
return
$this
->
model
->
create
([
$folder
=
$this
->
model
->
create
([
'filename'
=>
array_get
(
$data
,
'name'
),
'path'
=>
config
(
'asgard.media.config.files-path'
)
.
str_slug
(
array_get
(
$data
,
'name'
)),
'is_folder'
=>
true
,
'folder_id'
=>
array_get
(
$data
,
'parent_id'
),
]);
event
(
new
FolderWasCreated
(
$folder
,
$data
));
return
$folder
;
}
}
Modules/Media/Tests/EloquentFolderRepositoryTest.php
View file @
e2f783e3
...
...
@@ -2,6 +2,8 @@
namespace
Modules\Media\Tests
;
use
Illuminate\Support\Facades\Event
;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Repositories\Eloquent\EloquentFolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
use
PHPUnit\Framework\TestCase
;
...
...
@@ -36,6 +38,18 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
$this
->
assertEquals
(
0
,
$folder
->
folder_id
);
}
/** @test */
public
function
it_triggers_event_on_created_folder
()
{
Event
::
fake
();
$folder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
Event
::
assertDispatched
(
FolderWasCreated
::
class
,
function
(
$e
)
use
(
$folder
)
{
return
$e
->
folder
->
id
===
$folder
->
id
;
});
}
private
function
resetDatabase
()
{
// Makes sure the migrations table is created
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment