44
55use Binaryk \LaravelRestify \Events \RestifyBeforeEach ;
66use Binaryk \LaravelRestify \Events \RestifyStarting ;
7+ use Binaryk \LaravelRestify \Http \Requests \RestifyRequest ;
78use Binaryk \LaravelRestify \Repositories \Repository ;
89use Binaryk \LaravelRestify \Traits \AuthorizesRequests ;
910use Illuminate \Database \Eloquent \Model ;
1516class Restify
1617{
1718 use AuthorizesRequests;
19+
1820 /**
1921 * The registered repository names.
2022 *
@@ -39,7 +41,7 @@ class Restify
3941 /**
4042 * Get the repository class name for a given key.
4143 *
42- * @param string $key
44+ * @param string $key
4345 * @return string
4446 */
4547 public static function repositoryForKey ($ key )
@@ -52,7 +54,7 @@ public static function repositoryForKey($key)
5254 /**
5355 * Get the repository class name for a given key.
5456 *
55- * @param string $model
57+ * @param string $model
5658 * @return string
5759 */
5860 public static function repositoryForModel ($ model )
@@ -69,7 +71,7 @@ public static function repositoryForModel($model)
6971 /**
7072 * Register the given repositories.
7173 *
72- * @param array $repositories
74+ * @param array $repositories
7375 * @return static
7476 */
7577 public static function repositories (array $ repositories )
@@ -84,7 +86,7 @@ public static function repositories(array $repositories)
8486 /**
8587 * Register all of the repository classes in the given directory.
8688 *
87- * @param string $directory
89+ * @param string $directory
8890 * @return void
8991 * @throws \ReflectionException
9092 */
@@ -114,7 +116,7 @@ public static function repositoriesFrom($directory)
114116 /**
115117 * Get the URI path prefix utilized by Restify.
116118 *
117- * @param null $plus
119+ * @param null $plus
118120 * @return string
119121 */
120122 public static function path ($ plus = null )
@@ -131,7 +133,7 @@ public static function path($plus = null)
131133 *
132134 * This listener is added in the RestifyApplicationServiceProvider
133135 *
134- * @param \Closure|string $callback
136+ * @param \Closure|string $callback
135137 * @return void
136138 */
137139 public static function starting ($ callback )
@@ -140,7 +142,7 @@ public static function starting($callback)
140142 }
141143
142144 /**
143- * @param \Closure|string $callback
145+ * @param \Closure|string $callback
144146 */
145147 public static function beforeEach ($ callback )
146148 {
@@ -150,10 +152,26 @@ public static function beforeEach($callback)
150152 /**
151153 * Set the callback used for intercepting any request exception.
152154 *
153- * @param \Closure|string $callback
155+ * @param \Closure|string $callback
154156 */
155157 public static function exceptionHandler ($ callback )
156158 {
157159 static ::$ renderCallback = $ callback ;
158160 }
161+
162+ public static function globallySearchableRepositories (RestifyRequest $ request )
163+ {
164+ return collect (static ::$ repositories )
165+ ->filter (fn ($ repository ) => $ repository ::authorizedToUseRepository ($ request ))
166+ ->filter (fn ($ repository ) => $ repository ::$ globallySearchable )
167+ ->sortBy (static ::sortResourcesWith ())
168+ ->all ();
169+ }
170+
171+ public static function sortResourcesWith ()
172+ {
173+ return function ($ resource ) {
174+ return $ resource ::label ();
175+ };
176+ }
159177}
0 commit comments