2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
use App\Models\Note;
|
2019-10-27 16:29:15 +00:00
|
|
|
use App\Observers\NoteObserver;
|
2019-10-27 16:15:14 +00:00
|
|
|
use Codebird\Codebird;
|
2017-09-11 15:56:11 +01:00
|
|
|
use Illuminate\Http\Request;
|
2020-02-23 17:12:17 +00:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Illuminate\Support\Collection;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Laravel\Dusk\DuskServiceProvider;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2017-11-09 11:30:54 +00:00
|
|
|
Note::observe(NoteObserver::class);
|
2017-09-11 15:56:11 +01:00
|
|
|
|
|
|
|
// Request AS macro
|
2017-09-13 17:02:31 +00:00
|
|
|
Request::macro('wantsActivityStream', function () {
|
2019-02-01 18:49:35 +00:00
|
|
|
return Str::contains(mb_strtolower($this->header('Accept')), 'application/activity+json');
|
2017-09-11 15:56:11 +01:00
|
|
|
});
|
2017-09-16 11:39:36 +01:00
|
|
|
|
|
|
|
// configure Intervention/Image
|
|
|
|
$this->app->bind('Intervention\Image\ImageManager', function () {
|
|
|
|
return new \Intervention\Image\ImageManager(['driver' => config('image.driver')]);
|
|
|
|
});
|
2019-10-27 16:15:14 +00:00
|
|
|
|
|
|
|
// Bind the Codebird client
|
|
|
|
$this->app->bind('Codebird\Codebird', function () {
|
|
|
|
Codebird::setConsumerKey(
|
|
|
|
env('TWITTER_CONSUMER_KEY'),
|
|
|
|
env('TWITTER_CONSUMER_SECRET')
|
|
|
|
);
|
|
|
|
|
|
|
|
$cb = Codebird::getInstance();
|
|
|
|
|
|
|
|
$cb->setToken(
|
|
|
|
env('TWITTER_ACCESS_TOKEN'),
|
|
|
|
env('TWITTER_ACCESS_TOKEN_SECRET')
|
|
|
|
);
|
|
|
|
|
|
|
|
return $cb;
|
|
|
|
});
|
2020-02-23 17:12:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Paginate a standard Laravel Collection.
|
|
|
|
*
|
|
|
|
* @param int $perPage
|
|
|
|
* @param int $total
|
|
|
|
* @param int $page
|
|
|
|
* @param string $pageName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
|
|
|
|
$page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
|
|
|
|
|
|
|
|
return new LengthAwarePaginator(
|
|
|
|
$this->forPage($page, $perPage),
|
|
|
|
$total ?: $this->count(),
|
|
|
|
$perPage,
|
|
|
|
$page,
|
|
|
|
[
|
|
|
|
'path' => LengthAwarePaginator::resolveCurrentPath(),
|
|
|
|
'pageName' => $pageName,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
});
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2017-02-18 12:27:21 +00:00
|
|
|
if ($this->app->environment('local', 'testing')) {
|
|
|
|
$this->app->register(DuskServiceProvider::class);
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
}
|