@@ -46,9 +46,9 @@ public function handle()
4646 }
4747
4848 $ this ->setAppNamespace ();
49-
49+
5050 $ this ->configureUserModel ();
51-
51+
5252 $ this ->createAiRoutesFile ();
5353
5454 $ this ->info ('Restify setup successfully. ' );
@@ -148,30 +148,32 @@ protected function setAppNamespaceOn($file, $namespace)
148148 protected function configureUserModel ()
149149 {
150150 $ this ->comment ('Searching for User models in your application... ' );
151-
151+
152152 $ userModels = $ this ->findUserModels ();
153-
153+
154154 if (empty ($ userModels )) {
155155 $ this ->warn ('No User models found in App namespace. Using default \\App \\Models \\User. ' );
156+
156157 return ;
157158 }
158-
159+
159160 if (count ($ userModels ) === 1 ) {
160161 $ selectedModel = $ userModels [0 ];
161162 if ($ this ->confirm ("Found User model: {$ selectedModel }. Use this as your authentication model? " , true )) {
162163 $ this ->updateUserModelConfig ($ selectedModel );
163164 $ this ->info ("Updated restify config to use: {$ selectedModel }" );
164165 }
166+
165167 return ;
166168 }
167-
169+
168170 $ this ->info ('Multiple User models found: ' );
169171 foreach ($ userModels as $ index => $ model ) {
170172 $ this ->line (" [ {$ index }] {$ model }" );
171173 }
172-
174+
173175 $ choice = $ this ->ask ('Please select the User model to use (enter the number) ' , '0 ' );
174-
176+
175177 if (isset ($ userModels [$ choice ])) {
176178 $ selectedModel = $ userModels [$ choice ];
177179 $ this ->updateUserModelConfig ($ selectedModel );
@@ -191,24 +193,24 @@ protected function findUserModels()
191193 $ appPath = app_path ();
192194 $ namespace = $ this ->laravel ->getNamespace ();
193195 $ userModels = [];
194-
196+
195197 $ iterator = new \RecursiveIteratorIterator (
196198 new \RecursiveDirectoryIterator ($ appPath , \RecursiveDirectoryIterator::SKIP_DOTS ),
197199 \RecursiveIteratorIterator::SELF_FIRST
198200 );
199-
201+
200202 foreach ($ iterator as $ file ) {
201203 if ($ file ->isFile () && $ file ->getExtension () === 'php ' ) {
202- $ relativePath = str_replace ($ appPath . DIRECTORY_SEPARATOR , '' , $ file ->getPathname ());
204+ $ relativePath = str_replace ($ appPath. DIRECTORY_SEPARATOR , '' , $ file ->getPathname ());
203205 $ className = str_replace (['/ ' , '.php ' ], ['\\' , '' ], $ relativePath );
204- $ fqcn = $ namespace . $ className ;
205-
206+ $ fqcn = $ namespace. $ className ;
207+
206208 if ($ this ->isUserModel ($ file ->getPathname (), $ className )) {
207209 $ userModels [] = $ fqcn ;
208210 }
209211 }
210212 }
211-
213+
212214 return $ userModels ;
213215 }
214216
@@ -224,9 +226,9 @@ protected function isUserModel($filePath, $className)
224226 if (! str_contains (strtolower ($ className ), 'user ' )) {
225227 return false ;
226228 }
227-
229+
228230 $ content = file_get_contents ($ filePath );
229-
231+
230232 return str_contains ($ content , 'extends Authenticatable ' ) ||
231233 str_contains ($ content , 'use Authenticatable ' ) ||
232234 str_contains ($ content , 'implements AuthenticatableContract ' ) ||
@@ -242,20 +244,21 @@ protected function isUserModel($filePath, $className)
242244 protected function updateUserModelConfig ($ userModel )
243245 {
244246 $ configPath = config_path ('restify.php ' );
245-
247+
246248 if (! file_exists ($ configPath )) {
247249 $ this ->warn ('restify.php config file not found. ' );
250+
248251 return ;
249252 }
250-
253+
251254 $ content = file_get_contents ($ configPath );
252255 $ escapedUserModel = addslashes ($ userModel );
253-
256+
254257 $ pattern = "/'user_model'\s*=>\s*[' \"].*?[' \"]/ " ;
255258 $ replacement = "'user_model' => \"{$ escapedUserModel }\"" ;
256-
259+
257260 $ newContent = preg_replace ($ pattern , $ replacement , $ content );
258-
261+
259262 if ($ newContent !== $ content ) {
260263 file_put_contents ($ configPath , $ newContent );
261264 } else {
@@ -271,19 +274,20 @@ protected function updateUserModelConfig($userModel)
271274 protected function createAiRoutesFile ()
272275 {
273276 $ routesPath = base_path ('routes ' );
274- $ aiRoutesFile = $ routesPath . '/ai.php ' ;
275-
277+ $ aiRoutesFile = $ routesPath. '/ai.php ' ;
278+
276279 if (file_exists ($ aiRoutesFile )) {
277280 $ this ->line ('AI routes file already exists. ' );
281+
278282 return ;
279283 }
280-
284+
281285 app (Filesystem::class)->ensureDirectoryExists ($ routesPath );
282-
286+
283287 $ content = "<?php \n\nuse Binaryk \\LaravelRestify \\MCP \\RestifyServer; \nuse Laravel \\Mcp \\Server \\Facades \\Mcp; \n\n// Restify MCP Server - provides AI agents access to your Restify repositories \n// Mcp::web('restify', RestifyServer::class) \n// ->middleware(['auth:sanctum']); // Available at /mcp/restify \n\n// Mcp::local('restify', RestifyServer::class); // Start with ./artisan mcp:start restify \n\n// Example custom servers: \n// Mcp::web('demo', \\App \\Mcp \\Servers \\PublicServer::class); // Available at /mcp/demo \n// Mcp::local('demo', \\App \\Mcp \\Servers \\LocalServer::class); // Start with ./artisan mcp:start demo \n" ;
284-
288+
285289 file_put_contents ($ aiRoutesFile , $ content );
286-
290+
287291 $ this ->info ('Created routes/ai.php file for MCP server configuration. ' );
288292 }
289293}
0 commit comments