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

conedevelopment / root / 19758157679

28 Nov 2025 08:23AM UTC coverage: 76.162% (+0.05%) from 76.113%
19758157679

push

github

iamgergo
fix test

3393 of 4455 relevant lines covered (76.16%)

34.06 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Cone\Root;
6

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

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

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

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

70
        $this->app->alias(Root::class, 'root');
197✔
71

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

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

80
        $this->app->booted(static function (Application $app): void {
197✔
81
            $app->make(Root::class)->boot();
197✔
82
        });
197✔
83

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

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

98
        $this->registerViews();
197✔
99
        $this->registerRoutes();
197✔
100
        $this->registerExceptions();
197✔
101
        $this->registerAuth();
197✔
102
        $this->registerEvents();
197✔
103

104
        EncryptCookies::except(['__root_theme']);
197✔
105
    }
106

107
    /**
108
     * Register publishes.
109
     */
110
    protected function registerPublishes(): void
197✔
111
    {
112
        $this->publishes([
197✔
113
            __DIR__.'/../config/root.php' => $this->app->configPath('root.php'),
197✔
114
        ], 'root-config');
197✔
115

116
        $this->publishes([
197✔
117
            __DIR__.'/../public' => $this->app->publicPath('vendor/root'),
197✔
118
        ], 'root-compiled');
197✔
119

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

125
        $this->publishes([
197✔
126
            __DIR__.'/../resources/views' => $this->app->resourcePath('views/vendor/root'),
197✔
127
        ], 'root-views');
197✔
128

129
        $this->publishes([
197✔
130
            __DIR__.'/../stubs/RootServiceProvider.stub' => $this->app->basePath('app/Providers/RootServiceProvider.php'),
197✔
131
            __DIR__.'/../stubs/UserResource.stub' => $this->app->basePath('app/Root/Resources/UserResource.php'),
197✔
132
        ], 'root-stubs');
197✔
133
    }
134

135
    /**
136
     * Register the routes.
137
     */
138
    protected function registerRoutes(): void
197✔
139
    {
140
        $this->app['router']->middlewareGroup(
197✔
141
            'root', $this->app['config']->get('root.middleware', [])
197✔
142
        );
197✔
143

144
        $root = $this->app->make(Root::class);
197✔
145

146
        $this->app['router']->bind('resource', function (string $key) use ($root): Resource {
197✔
147
            try {
148
                return $root->resources->resolve($key);
7✔
149
            } catch (ResourceResolutionException) {
×
150
                throw new NotFoundHttpException;
×
151
            }
152
        });
197✔
153

154
        $this->app['router']->bind('resourceModel', fn (string $id, Route $route): Model => $id === 'create'
197✔
155
            ? $route->parameter('_resource')->getModelInstance()
×
156
            : $route->parameter('_resource')->resolveRouteBinding($this->app['request'], $id));
197✔
157

158
        $this->app['router']
197✔
159
            ->middleware(['web'])
197✔
160
            ->domain($root->getDomain())
197✔
161
            ->prefix($root->getPath())
197✔
162
            ->as('root.auth.')
197✔
163
            ->group(function (): void {
197✔
164
                $this->loadRoutesFrom(__DIR__.'/../routes/auth.php');
197✔
165
            });
197✔
166

167
        $root->routes(function (Router $router): void {
197✔
168
            $router->prefix('api')->as('api.')->group(function (): void {
197✔
169
                $this->loadRoutesFrom(__DIR__.'/../routes/api.php');
197✔
170
            });
197✔
171

172
            $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
197✔
173
        });
197✔
174

175
        RateLimiter::for('root.auth', static fn (Request $request): Limit => Limit::perMinute(6)->by($request->user()?->id ?: $request->ip()));
197✔
176
    }
177

178
    /**
179
     * Register commands.
180
     */
181
    protected function registerCommands(): void
197✔
182
    {
183
        AboutCommand::add('Root', fn (): array => ['Version' => Root::VERSION]);
197✔
184

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

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

207
        Blade::componentNamespace('Cone\\Root\\View\\Components', 'root');
197✔
208

209
        $this->app['view']->composer('root::*', function (View $view): void {
197✔
210
            $request = $this->app->make('request');
19✔
211

212
            $view->with([
19✔
213
                'alerts' => $request->session()->get('alerts', []),
19✔
214
                'user' => $request->user(),
19✔
215
            ]);
19✔
216
        });
197✔
217
    }
218

219
    /**
220
     * Register the custom exceptions.
221
     */
222
    protected function registerExceptions(): void
197✔
223
    {
224
        $exceptions = $this->app->make(ExceptionHandler::class);
197✔
225

226
        $exceptions->renderable(static fn (SaveFormDataException $exception): RedirectResponse => Redirect::back()
197✔
227
            ->withInput()
197✔
228
            ->with('alerts.form-save', Alert::error($exception->getMessage())));
197✔
229
    }
230

231
    /**
232
     * Register the auth features.
233
     */
234
    protected function registerAuth(): void
197✔
235
    {
236
        Gate::define('viewRoot', static fn (User $user): bool => Root::instance()->authorized($user));
197✔
237

238
        Gate::policy(Medium::getProxiedClass(), MediumPolicy::class);
197✔
239
    }
240

241
    /**
242
     * Register the events.
243
     */
244
    protected function registerEvents(): void
197✔
245
    {
246
        $this->app['events']->listen(VendorTagPublished::class, Listeners\FormatRootStubs::class);
197✔
247
    }
248
}
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

© 2025 Coveralls, Inc