-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend.php
115 lines (95 loc) · 4.29 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Flamarkt\Library;
use ClarkWinkelmann\Mithril2Html\Extend\FrontendNoConflict;
use ClarkWinkelmann\Scout\Extend\Scout;
use Flamarkt\Core\Api\Controller as CoreController;
use Flamarkt\Core\Api\Serializer\BasicProductSerializer;
use Flamarkt\Core\Api\Serializer\ProductSerializer;
use Flamarkt\Core\Extend\Mail;
use Flamarkt\Core\Notification\AbstractOrderUpdateBlueprint;
use Flamarkt\Core\Product\Event\Saving;
use Flamarkt\Core\Product\Product;
use Flarum\Extend;
$extenders = [
(new Extend\Frontend('backoffice'))
->js(__DIR__ . '/js/dist/backoffice.js')
->route('/files', 'files.index')
->route('/files/{id:[0-9a-f-]+|new}', 'files.show'),
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/resources/less/forum.less'),
(new FrontendNoConflict('mithril2html'))
->js(__DIR__ . '/js/dist/mithril2html.js'),
new Extend\Locales(__DIR__ . '/resources/locale'),
(new Extend\Routes('api'))
->get('/flamarkt/files', 'flamarkt.files.index', Api\Controller\FileIndexController::class)
->post('/flamarkt/files', 'flamarkt.files.store', Api\Controller\FileStoreController::class)
->get('/flamarkt/files/{id:[0-9a-f-]+}', 'flamarkt.files.show', Api\Controller\FileShowController::class)
->patch('/flamarkt/files/{id:[0-9a-f-]+}', 'flamarkt.files.update', Api\Controller\FileUpdateController::class)
->delete('/flamarkt/files/{id:[0-9a-f-]+}', 'flamarkt.files.delete', Api\Controller\FileDeleteController::class),
(new Extend\Model(Product::class))
->belongsToMany('files', File::class, 'flamarkt_file_product')
->belongsTo('thumbnail', File::class, 'thumbnail_id'),
(new Extend\Event())
->listen(Saving::class, Listeners\SaveProduct::class),
(new Extend\ApiSerializer(BasicProductSerializer::class))
->hasOne('thumbnail', Api\Serializer\FileSerializer::class),
(new Extend\ApiSerializer(ProductSerializer::class))
->attributes(ProductAttributes::class)
->hasMany('files', Api\Serializer\FileSerializer::class),
(new Extend\ApiController(CoreController\ProductIndexController::class))
->addInclude('thumbnail'),
(new Extend\ApiController(CoreController\ProductShowController::class))
->addInclude('thumbnail'),
(new Extend\ApiController(CoreController\ProductStoreController::class))
->addInclude('thumbnail'),
(new Extend\ApiController(CoreController\ProductUpdateController::class))
->addInclude('thumbnail'),
(new Extend\ApiController(CoreController\OrderShowController::class))
->addInclude('lines.product.thumbnail'),
(new Extend\Filter(FileFilterer::class))
->addFilter(Filter\MimeFilter::class),
(new Extend\SimpleFlarumSearch(FileSearcher::class))
->addGambit(Filter\MimeFilter::class)
->setFullTextGambit(Filter\FullTextGambit::class),
(new Extend\ServiceProvider())
->register(ImageServiceProvider::class),
(new Extend\Console())
->command(Console\RefreshConversions::class),
(new Extend\ModelVisibility(File::class))
->scope(Scope\View::class),
(new Extend\Filter(FileFilterer::class))
->addFilter(Filter\MimeFilter::class),
(new Mail())
->css(function ($blueprint) {
if ($blueprint instanceof AbstractOrderUpdateBlueprint) {
return <<<CSS
.FlamarktThumbnail {
width: 75px;
}
CSS;
}
}),
];
if (class_exists(Scout::class)) {
$extenders[] = (new Scout(File::class))
->listenSaved(File\Event\Created::class, function (File\Event\Created $event) {
return $event->file;
})
->listenSaved(File\Event\DescriptionChanged::class, function (File\Event\DescriptionChanged $event) {
return $event->file;
})
->listenSaved(File\Event\TitleChanged::class, function (File\Event\TitleChanged $event) {
return $event->file;
})
->listenDeleted(File\Event\Deleted::class, function (File\Event\Deleted $event) {
return $event->file;
})
->attributes(function (File $file): array {
return [
'title' => $file->title,
'description' => $file->description,
];
});
}
return $extenders;