@@ -16,16 +16,6 @@ class ThemeService
1616 */
1717 protected array $ listeners = [];
1818
19- /**
20- * @var array<string, array<string, int>>
21- */
22- protected array $ beforeViews = [];
23-
24- /**
25- * @var array<string, array<string, int>>
26- */
27- protected array $ afterViews = [];
28-
2919 /**
3020 * Get the currently configured theme.
3121 * Returns an empty string if not configured.
@@ -92,31 +82,17 @@ public function registerCommand(Command $command): void
9282 public function readThemeActions (): void
9383 {
9484 $ themeActionsFile = theme_path ('functions.php ' );
85+ if (!$ themeActionsFile || !file_exists ($ themeActionsFile )) {
86+ return ;
87+ }
88+
9589 try {
9690 require $ themeActionsFile ;
9791 } catch (\Error $ exception ) {
9892 throw new ThemeException ("Failed loading theme functions file at \"{$ themeActionsFile }\" with error: {$ exception ->getMessage ()}" );
9993 }
10094 }
10195
102- /**
103- * Check if a logical theme is active.
104- */
105- public function logicalThemeIsActive (): bool
106- {
107- $ themeActionsFile = theme_path ('functions.php ' );
108- return $ themeActionsFile && file_exists ($ themeActionsFile );
109- }
110-
111- /**
112- * Register any extra paths for where we may expect views to be located
113- * with the provided FileViewFinder, to make custom views available for use.
114- */
115- public function registerViewPathsForTheme (FileViewFinder $ finder ): void
116- {
117- $ finder ->prependLocation (theme_path ());
118- }
119-
12096 /**
12197 * @see SocialDriverManager::addSocialDriver
12298 */
@@ -125,63 +101,4 @@ public function addSocialDriver(string $driverName, array $config, string $socia
125101 $ driverManager = app ()->make (SocialDriverManager::class);
126102 $ driverManager ->addSocialDriver ($ driverName , $ config , $ socialiteHandler , $ configureForRedirect );
127103 }
128-
129- /**
130- * Provide the response for a blade template view include.
131- */
132- public function handleViewInclude (string $ viewPath , array $ data = []): string
133- {
134- $ viewsContent = [
135- ...$ this ->renderViewSets ($ this ->beforeViews [$ viewPath ] ?? [], $ data ),
136- view ()->make ($ viewPath , $ data )->render (),
137- ...$ this ->renderViewSets ($ this ->afterViews [$ viewPath ] ?? [], $ data ),
138- ];
139-
140- return implode ("\n" , $ viewsContent );
141- }
142-
143- /**
144- * Register a custom view to be rendered before the given target view is included in the template system.
145- */
146- public function registerViewToRenderBefore (string $ targetView , string $ localView , int $ priority = 50 ): void
147- {
148- $ this ->registerAdjacentView ($ this ->beforeViews , $ targetView , $ localView , $ priority );
149- }
150-
151- /**
152- * Register a custom view to be rendered after the given target view is included in the template system.
153- */
154- public function registerViewToRenderAfter (string $ targetView , string $ localView , int $ priority = 50 ): void
155- {
156- $ this ->registerAdjacentView ($ this ->afterViews , $ targetView , $ localView , $ priority );
157- }
158-
159- protected function registerAdjacentView (array &$ location , string $ targetView , string $ localView , int $ priority = 50 ): void
160- {
161- $ viewPath = theme_path ($ localView . '.blade.php ' );
162- if (!file_exists ($ viewPath )) {
163- throw new ThemeException ("Expected registered view file at \"{$ viewPath }\" does not exist " );
164- }
165-
166- if (!isset ($ location [$ targetView ])) {
167- $ location [$ targetView ] = [];
168- }
169- $ location [$ targetView ][$ viewPath ] = $ priority ;
170- }
171-
172- /**
173- * @param array<string, int> $viewSet
174- * @return string[]
175- */
176- protected function renderViewSets (array $ viewSet , array $ data ): array
177- {
178- $ paths = array_keys ($ viewSet );
179- usort ($ paths , function (string $ a , string $ b ) use ($ viewSet ) {
180- return $ viewSet [$ a ] <=> $ viewSet [$ b ];
181- });
182-
183- return array_map (function (string $ viewPath ) use ($ data ) {
184- return view ()->file ($ viewPath , $ data )->render ();
185- }, $ paths );
186- }
187104}
0 commit comments