Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
48.65% |
18 / 37 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AppServiceProvider | |
48.65% |
18 / 37 |
|
0.00% |
0 / 3 |
23.54 | |
0.00% |
0 / 1 |
| register | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
| boot | |
56.52% |
13 / 23 |
|
0.00% |
0 / 1 |
8.96 | |||
| hideTelescopeInProduction | |
11.11% |
1 / 9 |
|
0.00% |
0 / 1 |
4.81 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Providers; |
| 4 | |
| 5 | use App\Http\Models\Auth\User; |
| 6 | use App\Http\Models\Passport\AuthCode; |
| 7 | use App\Http\Models\Passport\Client; |
| 8 | use App\Http\Models\Passport\PersonalAccessClient; |
| 9 | use App\Http\Models\Passport\RefreshToken; |
| 10 | use App\Http\Models\Passport\Token; |
| 11 | use App\Http\Models\Subscription; |
| 12 | use App\Http\Models\SubscriptionItem; |
| 13 | use App\Http\Repositories\interfaces\ISavedPromptRepository; |
| 14 | use App\Http\Repositories\interfaces\ISubscriptionRepository; |
| 15 | use App\Http\Repositories\SavedPromptsRepository; |
| 16 | use App\Http\Repositories\SubscriptionRepository; |
| 17 | use App\Http\Resolvers\SocialUserResolver; |
| 18 | use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface; |
| 19 | use Illuminate\Foundation\AliasLoader; |
| 20 | use Illuminate\Http\Response; |
| 21 | use Illuminate\Support\Facades\App; |
| 22 | use Illuminate\Support\Facades\Gate; |
| 23 | use Illuminate\Support\Facades\URL; |
| 24 | use Illuminate\Support\ServiceProvider; |
| 25 | use Laravel\Cashier\Cashier; |
| 26 | use SimpleXMLElement; |
| 27 | use Stripe\Stripe; |
| 28 | |
| 29 | class AppServiceProvider extends ServiceProvider |
| 30 | { |
| 31 | public $bindings = [ |
| 32 | SocialUserResolverInterface::class => SocialUserResolver::class, |
| 33 | ]; |
| 34 | |
| 35 | /** |
| 36 | * Register any application services. |
| 37 | */ |
| 38 | public function register(): void |
| 39 | { |
| 40 | if (App::environment('local')) { |
| 41 | $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); |
| 42 | } |
| 43 | |
| 44 | Stripe::setApiKey(config('services.stripe.secret')); |
| 45 | |
| 46 | $this->app->bind(ISavedPromptRepository::class, SavedPromptsRepository::class); |
| 47 | $this->app->bind(ISubscriptionRepository::class, SubscriptionRepository::class); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Bootstrap any application services. |
| 52 | */ |
| 53 | public function boot(): void |
| 54 | { |
| 55 | if (config('app.env') === 'production') { |
| 56 | URL::forceScheme('https'); |
| 57 | } |
| 58 | |
| 59 | $this->hideTelescopeInProduction(); |
| 60 | $loader = AliasLoader::getInstance(); |
| 61 | |
| 62 | // Passport client extends Eloquent model by default, so we alias them. |
| 63 | $loader->alias('Laravel\Passport\AuthCode', AuthCode::class); |
| 64 | $loader->alias('Laravel\Passport\Client', Client::class); |
| 65 | $loader->alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class); |
| 66 | $loader->alias('Laravel\Passport\RefreshToken', RefreshToken::class); |
| 67 | $loader->alias('Laravel\Passport\Token', Token::class); |
| 68 | |
| 69 | $loader->alias('Laravel\Cashier\Subscription', Subscription::class); |
| 70 | $loader->alias('Laravel\Cashier\SubscriptionItem', SubscriptionItem::class); |
| 71 | |
| 72 | Cashier::useCustomerModel(User::class); |
| 73 | Response::macro('xml', function (array $vars, $status = 200, array $header = [], $xml = null) { |
| 74 | if (is_null($xml)) { |
| 75 | $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>'); |
| 76 | } |
| 77 | foreach ($vars as $key => $value) { |
| 78 | if (is_array($value)) { |
| 79 | Response::xml($value, $status, $header, $xml->addChild($key)); |
| 80 | } else { |
| 81 | $xml->addChild($key, $value); |
| 82 | } |
| 83 | } |
| 84 | if (empty($header)) { |
| 85 | $header['Content-Type'] = 'application/xml'; |
| 86 | } |
| 87 | |
| 88 | return Response::make($xml->asXML(), $status, $header); |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Prevent sensitive information from being exposed in production. |
| 94 | */ |
| 95 | private function hideTelescopeInProduction(): void |
| 96 | { |
| 97 | if (config('app.env') === 'production') { |
| 98 | Gate::define('viewTelescope', function ($user) { |
| 99 | return in_array($user->email, [ |
| 100 | 'jonatas@vengreso.com', |
| 101 | 'vivian@vengreso.com', |
| 102 | 'thales@vengreso.com', |
| 103 | 'jeff@vengreso.com', |
| 104 | ]); |
| 105 | }); |
| 106 | } |
| 107 | } |
| 108 | } |