• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / root / 13086943877

01 Feb 2025 08:35AM UTC coverage: 79.285% (+1.2%) from 78.037%
13086943877

push

github

web-flow
Merge pull request #234 from xHeaven/patch-1

Codebase health checkup

195 of 239 new or added lines in 45 files covered. (81.59%)

2 existing lines in 2 files now uncovered.

2572 of 3244 relevant lines covered (79.28%)

35.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.81
/src/RootServiceProvider.php
1
<?php
2

3
namespace Cone\Root;
4

5
use Cone\Root\Exceptions\ResourceResolutionException;
6
use Cone\Root\Exceptions\SaveFormDataException;
7
use Cone\Root\Models\Medium;
8
use Cone\Root\Models\User;
9
use Cone\Root\Policies\MediumPolicy;
10
use Cone\Root\Resources\Resource;
11
use Cone\Root\Support\Alert;
12
use Illuminate\Cache\RateLimiting\Limit;
13
use Illuminate\Contracts\Debug\ExceptionHandler;
14
use Illuminate\Contracts\Foundation\Application;
15
use Illuminate\Contracts\View\View;
16
use Illuminate\Cookie\Middleware\EncryptCookies;
17
use Illuminate\Database\Eloquent\Model;
18
use Illuminate\Foundation\Console\AboutCommand;
19
use Illuminate\Foundation\Events\VendorTagPublished;
20
use Illuminate\Http\RedirectResponse;
21
use Illuminate\Http\Request;
22
use Illuminate\Routing\Route;
23
use Illuminate\Routing\Router;
24
use Illuminate\Support\Facades\Blade;
25
use Illuminate\Support\Facades\Gate;
26
use Illuminate\Support\Facades\RateLimiter;
27
use Illuminate\Support\Facades\Redirect;
28
use Illuminate\Support\ServiceProvider;
29
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30

31
class RootServiceProvider extends ServiceProvider
32
{
33
    /**
34
     * All of the container bindings that should be registered.
35
     *
36
     * @var array
37
     */
38
    public $bindings = [
39
        Interfaces\Breadcrumbs\Registry::class => Breadcrumbs\Registry::class,
40
        Interfaces\Models\AuthCode::class => Models\AuthCode::class,
41
        Interfaces\Models\Medium::class => Models\Medium::class,
42
        Interfaces\Models\Meta::class => Models\Meta::class,
43
        Interfaces\Models\Notification::class => Models\Notification::class,
44
        Interfaces\Models\Setting::class => Models\Setting::class,
45
        Interfaces\Models\Translation::class => Models\Translation::class,
46
        Interfaces\Models\User::class => Models\User::class,
47
        Interfaces\Navigation\Registry::class => Navigation\Registry::class,
48
        Interfaces\Settings\Registry::class => Settings\Registry::class,
49
        Interfaces\Settings\Repository::class => Settings\Repository::class,
50
    ];
51

52
    /**
53
     * All of the container singletons that should be registered.
54
     *
55
     * @var array
56
     */
57
    public $singletons = [
58
        Interfaces\Conversion\Manager::class => Conversion\Manager::class,
59
    ];
60

61
    /**
62
     * Register any application services.
63
     */
64
    public function register(): void
65
    {
66
        $this->app->singleton(Root::class, static fn (Application $app): Root => new Root($app));
198✔
67

68
        $this->app->alias(Root::class, 'root');
198✔
69

70
        if (! $this->app->configurationIsCached()) {
198✔
71
            $this->mergeConfigFrom(__DIR__.'/../config/root.php', 'root');
198✔
72
        }
73

74
        $this->app->afterResolving(EncryptCookies::class, static function (EncryptCookies $middleware): void {
198✔
75
            $middleware->disableFor('__root_theme');
42✔
76
        });
198✔
77

78
        $this->app->booted(static function (Application $app): void {
198✔
79
            $app->make(Root::class)->boot();
198✔
80
        });
198✔
81

82
        $this->app['request']->macro('isTurboFrameRequest', fn (): bool => $this->hasHeader('Turbo-Frame'));
198✔
83
    }
84

85
    /**
86
     * Bootstrap any application services.
87
     */
88
    public function boot(): void
89
    {
90
        if ($this->app->runningInConsole()) {
198✔
91
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
198✔
92
            $this->registerCommands();
198✔
93
            $this->registerPublishes();
198✔
94
        }
95

96
        $this->registerViews();
198✔
97
        $this->registerRoutes();
198✔
98
        $this->registerExceptions();
198✔
99
        $this->registerAuth();
198✔
100
        $this->registerEvents();
198✔
101
    }
102

103
    /**
104
     * Register publishes.
105
     */
106
    protected function registerPublishes(): void
107
    {
108
        $this->publishes([
198✔
109
            __DIR__.'/../config/root.php' => $this->app->configPath('root.php'),
198✔
110
        ], 'root-config');
198✔
111

112
        $this->publishes([
198✔
113
            __DIR__.'/../public' => $this->app->publicPath('vendor/root'),
198✔
114
        ], 'root-compiled');
198✔
115

116
        $this->publishes([
198✔
117
            __DIR__.'/../resources/js' => $this->app->resourcePath('js/vendor/root'),
198✔
118
            __DIR__.'/../resources/sass' => $this->app->resourcePath('sass/vendor/root'),
198✔
119
        ], 'root-vendor');
198✔
120

121
        $this->publishes([
198✔
122
            __DIR__.'/../resources/views' => $this->app->resourcePath('views/vendor/root'),
198✔
123
        ], 'root-views');
198✔
124

125
        $this->publishes([
198✔
126
            __DIR__.'/../stubs/RootServiceProvider.stub' => $this->app->basePath('app/Providers/RootServiceProvider.php'),
198✔
127
            __DIR__.'/../stubs/UserResource.stub' => $this->app->basePath('app/Root/Resources/UserResource.php'),
198✔
128
        ], 'root-stubs');
198✔
129
    }
130

131
    /**
132
     * Register the routes.
133
     */
134
    protected function registerRoutes(): void
135
    {
136
        $this->app['router']->middlewareGroup(
198✔
137
            'root', $this->app['config']->get('root.middleware', [])
198✔
138
        );
198✔
139

140
        $root = $this->app->make(Root::class);
198✔
141

142
        $this->app['router']->bind('resource', function (string $key) use ($root): Resource {
198✔
143
            try {
144
                return $root->resources->resolve($key);
7✔
NEW
145
            } catch (ResourceResolutionException) {
×
146
                throw new NotFoundHttpException;
×
147
            }
148
        });
198✔
149

150
        $this->app['router']->bind('resourceModel', fn (string $id, Route $route): Model => $id === 'create'
198✔
NEW
151
            ? $route->parameter('_resource')->getModelInstance()
×
152
            : $route->parameter('_resource')->resolveRouteBinding($this->app['request'], $id));
198✔
153

154
        $this->app['router']
198✔
155
            ->middleware(['web'])
198✔
156
            ->domain($root->getDomain())
198✔
157
            ->prefix($root->getPath())
198✔
158
            ->as('root.auth.')
198✔
159
            ->group(function (): void {
198✔
160
                $this->loadRoutesFrom(__DIR__.'/../routes/auth.php');
198✔
161
            });
198✔
162

163
        $root->routes(function (Router $router): void {
198✔
164
            $router->prefix('api')->as('api.')->group(function (): void {
198✔
165
                $this->loadRoutesFrom(__DIR__.'/../routes/api.php');
198✔
166
            });
198✔
167

168
            $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
198✔
169
        });
198✔
170

171
        RateLimiter::for('root.auth', static fn (Request $request): Limit => Limit::perMinute(6)->by($request->user()?->id ?: $request->ip()));
198✔
172
    }
173

174
    /**
175
     * Register commands.
176
     */
177
    protected function registerCommands(): void
178
    {
179
        AboutCommand::add('Root', fn (): array => ['Version' => Root::VERSION]);
198✔
180

181
        $this->commands([
198✔
182
            Console\Commands\ActionMake::class,
198✔
183
            Console\Commands\ClearChunks::class,
198✔
184
            Console\Commands\ClearMedia::class,
198✔
185
            Console\Commands\FieldMake::class,
198✔
186
            Console\Commands\FilterMake::class,
198✔
187
            Console\Commands\Install::class,
198✔
188
            Console\Commands\Publish::class,
198✔
189
            Console\Commands\ResourceMake::class,
198✔
190
            Console\Commands\TrendMake::class,
198✔
191
            Console\Commands\ValueMake::class,
198✔
192
            Console\Commands\WidgetMake::class,
198✔
193
        ]);
198✔
194
    }
195

196
    /**
197
     * Register the views.
198
     */
199
    protected function registerViews(): void
200
    {
201
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'root');
198✔
202

203
        Blade::componentNamespace('Cone\\Root\\View\\Components', 'root');
198✔
204

205
        $this->app['view']->composer('root::*', function (View $view): void {
198✔
206
            $request = $this->app->make('request');
19✔
207

208
            $view->with([
19✔
209
                'alerts' => $request->session()->get('alerts', []),
19✔
210
                'user' => $request->user(),
19✔
211
            ]);
19✔
212
        });
198✔
213
    }
214

215
    /**
216
     * Register the custom exceptions.
217
     */
218
    protected function registerExceptions(): void
219
    {
220
        $exceptions = $this->app->make(ExceptionHandler::class);
198✔
221

222
        $exceptions->renderable(static fn (SaveFormDataException $exception): RedirectResponse => Redirect::back()
198✔
223
            ->withInput()
198✔
224
            ->with('alerts.form-save', Alert::error($exception->getMessage())));
198✔
225
    }
226

227
    /**
228
     * Register the auth features.
229
     */
230
    protected function registerAuth(): void
231
    {
232
        Gate::define('viewRoot', static fn (User $user): bool => Root::instance()->authorized($user));
198✔
233

234
        Gate::policy(Medium::getProxiedClass(), MediumPolicy::class);
198✔
235
    }
236

237
    /**
238
     * Register the events.
239
     */
240
    protected function registerEvents(): void
241
    {
242
        $this->app['events']->listen(VendorTagPublished::class, Listeners\FormatRootStubs::class);
198✔
243
    }
244
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc