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
c660d3b7
Unverified
Commit
c660d3b7
authored
Sep 20, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a folder repository
parent
18aed5a7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
0 deletions
+88
-0
MediaServiceProvider.php
Modules/Media/Providers/MediaServiceProvider.php
+5
-0
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+18
-0
FolderRepository.php
Modules/Media/Repositories/FolderRepository.php
+9
-0
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+56
-0
No files found.
Modules/Media/Providers/MediaServiceProvider.php
View file @
c660d3b7
...
...
@@ -19,7 +19,9 @@ use Modules\Media\Events\Handlers\RegisterMediaSidebar;
use
Modules\Media\Events\Handlers\RemovePolymorphicLink
;
use
Modules\Media\Image\ThumbnailManager
;
use
Modules\Media\Repositories\Eloquent\EloquentFileRepository
;
use
Modules\Media\Repositories\Eloquent\EloquentFolderRepository
;
use
Modules\Media\Repositories\FileRepository
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Tag\Repositories\TagManager
;
class
MediaServiceProvider
extends
ServiceProvider
...
...
@@ -90,6 +92,9 @@ class MediaServiceProvider extends ServiceProvider
$this
->
app
->
bind
(
FileRepository
::
class
,
function
()
{
return
new
EloquentFileRepository
(
new
File
());
});
$this
->
app
->
bind
(
FolderRepository
::
class
,
function
()
{
return
new
EloquentFolderRepository
(
new
File
());
});
}
/**
...
...
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
0 → 100644
View file @
c660d3b7
<?php
namespace
Modules\Media\Repositories\Eloquent
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Media\Repositories\FolderRepository
;
class
EloquentFolderRepository
extends
EloquentBaseRepository
implements
FolderRepository
{
public
function
create
(
$data
)
{
return
$this
->
model
->
create
([
'filename'
=>
array_get
(
$data
,
'name'
),
'path'
=>
str_slug
(
array_get
(
$data
,
'name'
)),
'is_folder'
=>
true
,
]);
}
}
Modules/Media/Repositories/FolderRepository.php
0 → 100644
View file @
c660d3b7
<?php
namespace
Modules\Media\Repositories
;
use
Modules\Core\Repositories\BaseRepository
;
interface
FolderRepository
extends
BaseRepository
{
}
Modules/Media/Tests/EloquentFolderRepositoryTest.php
0 → 100644
View file @
c660d3b7
<?php
namespace
Modules\Media\Tests
;
use
Modules\Media\Repositories\Eloquent\EloquentFolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
use
PHPUnit\Framework\TestCase
;
final
class
EloquentFolderRepositoryTest
extends
MediaTestCase
{
/**
* @var FolderRepository
*/
private
$folder
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
resetDatabase
();
$this
->
folder
=
app
(
FolderRepository
::
class
);
}
/** @test */
public
function
it_can_create_a_folder
()
{
$folder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
$this
->
assertCount
(
1
,
$this
->
folder
->
all
());
$this
->
assertEquals
(
'My Folder'
,
$folder
->
filename
);
$this
->
assertEquals
(
'my-folder'
,
$folder
->
path
->
getRelativeUrl
());
$this
->
assertTrue
(
$folder
->
is_folder
);
}
private
function
resetDatabase
()
{
// Makes sure the migrations table is created
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
]);
// We empty all tables
$this
->
artisan
(
'migrate:reset'
,
[
'--database'
=>
'sqlite'
,
]);
// Migrate
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
]);
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
'--path'
=>
'Modules/Tag/Database/Migrations'
,
]);
}
}
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