Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 137f970

Browse files
committed
🔥 switched config to arrays
1 parent 3834e27 commit 137f970

4 files changed

Lines changed: 152 additions & 104 deletions

File tree

Config/aloe.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
// config for aloe CLI
3+
return [
4+
"paths" => [
5+
"controllers_path" => "/App/Controllers",
6+
"models_path" => "/App/Models",
7+
"migrations_path" => "/App/Database/Migrations",
8+
"seeds_path" => "/App/Database/Seeds",
9+
"factories_path" => "/App/Database/Factories",
10+
"helpers_path" => "/App/Helpers",
11+
"views_path" => "/App/Views",
12+
"config_path" => "/App/Config",
13+
"storage_path" => "/App/storage",
14+
"commands_path" => "/App/Console",
15+
"routes_path" => "/App/Routes",
16+
"lib_path" => "/Lib",
17+
]
18+
];

Config/functions.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,121 @@ function view(string $view, array $data = [], array $mergeData = [])
226226
return app()->blade->render($view, $data, $mergeData);
227227
}
228228
}
229+
230+
// App paths as callable methods
231+
232+
/**
233+
* Get all app paths
234+
*/
235+
function app_paths($path = null, bool $slash = false)
236+
{
237+
$paths = require __DIR__ . "/paths.php";
238+
$res = !$path ? $paths : $paths[$path] ?? "/";
239+
return $slash ? "/$res" : $res;
240+
}
241+
242+
/**
243+
* Views directory path
244+
*/
245+
function views_path($path = null, bool $slash = false)
246+
{
247+
return app_paths("views_path", $slash) . "/$path";
248+
}
249+
250+
/**
251+
* Config directory path
252+
*/
253+
function config_path($path = null)
254+
{
255+
return app_paths("config_path") . "/$path";
256+
}
257+
258+
/**
259+
* Storage directory path
260+
*/
261+
function storage_path($path = null, bool $slash = false)
262+
{
263+
return app_paths("storage_path", $slash) . "/$path";
264+
}
265+
266+
/**
267+
* Commands directory path
268+
*/
269+
function commands_path($path = null)
270+
{
271+
return app_paths("commands_path") . "/$path";
272+
}
273+
274+
/**
275+
* Controllers directory path
276+
*/
277+
function controllers_path($path = null)
278+
{
279+
return app_paths("controllers_path") . "/$path";
280+
}
281+
282+
/**
283+
* Models directory path
284+
*/
285+
function models_path($path = null)
286+
{
287+
return app_paths("models_path") . "/$path";
288+
}
289+
290+
/**
291+
* Migrations directory path
292+
*/
293+
function migrations_path($path = null, bool $slash = true)
294+
{
295+
return app_paths("migrations_path", $slash) . "/$path";
296+
}
297+
298+
/**
299+
* Seeds directory path
300+
*/
301+
function seeds_path($path = null)
302+
{
303+
return app_paths("seeds_path") . "/$path";
304+
}
305+
306+
/**
307+
* Factories directory path
308+
*/
309+
function factories_path($path = null)
310+
{
311+
return app_paths("factories_path") . "/$path";
312+
}
313+
314+
/**
315+
* Routes directory path
316+
*/
317+
function routes_path($path = null)
318+
{
319+
return "/App/Routes/$path";
320+
return app_paths("routes_path") . "/$path";
321+
}
322+
323+
/**
324+
* Helpers directory path
325+
*/
326+
function helpers_path($path = null)
327+
{
328+
return "/App/Helpers/$path";
329+
return app_paths("helpers_path") . "/$path";
330+
}
331+
332+
/**
333+
* Helpers directory path
334+
*/
335+
function lib_path($path = null)
336+
{
337+
return app_paths("lib_path") . "/$path";
338+
}
339+
340+
/**
341+
* Public directory path
342+
*/
343+
function public_path($path = null)
344+
{
345+
return app_paths("public_path") . "/$path";
346+
}

Config/paths.php

Lines changed: 15 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,17 @@
11
<?php
22

3-
/**
4-
* Views directory path
5-
*/
6-
function views_path($path = null, bool $slash = false)
7-
{
8-
return $slash ? "/App/Views/$path" : "App/Views/$path";
9-
}
10-
11-
/**
12-
* Config directory path
13-
*/
14-
function config_path($path = null)
15-
{
16-
return "/Config/$path";
17-
}
18-
19-
/**
20-
* Storage directory path
21-
*/
22-
function storage_path($path = null, bool $slash = false)
23-
{
24-
return $slash ? "/storage/$path" : "storage/$path";
25-
}
26-
27-
/**
28-
* Commands directory path
29-
*/
30-
function commands_path($path = null)
31-
{
32-
return "/App/Console/$path";
33-
}
34-
35-
/**
36-
* Controllers directory path
37-
*/
38-
function controllers_path($path = null)
39-
{
40-
return "/App/Controllers/$path";
41-
}
42-
43-
/**
44-
* Models directory path
45-
*/
46-
function models_path($path = null)
47-
{
48-
return "/App/Models/$path";
49-
}
50-
51-
/**
52-
* Migrations directory path
53-
*/
54-
function migrations_path($path = null, bool $slash = true)
55-
{
56-
return $slash ? "/App/Database/Migrations/$path" : "App/Database/Migrations/$path";
57-
}
58-
59-
/**
60-
* Seeds directory path
61-
*/
62-
function seeds_path($path = null)
63-
{
64-
return "/App/Database/Seeds/$path";
65-
}
66-
67-
/**
68-
* Factories directory path
69-
*/
70-
function factories_path($path = null)
71-
{
72-
return "/App/Database/Factories/$path";
73-
}
74-
75-
/**
76-
* Routes directory path
77-
*/
78-
function routes_path($path = null)
79-
{
80-
return "/App/Routes/$path";
81-
}
82-
83-
/**
84-
* Helpers directory path
85-
*/
86-
function helpers_path($path = null)
87-
{
88-
return "/App/Helpers/$path";
89-
}
90-
91-
/**
92-
* Helpers directory path
93-
*/
94-
function lib_path($path = null)
95-
{
96-
return "/Lib/$path";
97-
}
98-
99-
/**
100-
* Public directory path
101-
*/
102-
function public_path($path = null)
103-
{
104-
return "/public/$path";
105-
}
3+
return [
4+
"controllers_path" => "/App/Controllers",
5+
"models_path" => "/App/Models",
6+
"migrations_path" => "/App/Database/Migrations",
7+
"seeds_path" => "/App/Database/Seeds",
8+
"factories_path" => "/App/Database/Factories",
9+
"helpers_path" => "/App/Helpers",
10+
"views_path" => "/App/Views",
11+
"config_path" => "/App/Config",
12+
"storage_path" => "/App/storage",
13+
"commands_path" => "/App/Console",
14+
"routes_path" => "/App/Routes",
15+
"lib_path" => "/Lib",
16+
"public_path" => "/public",
17+
];

aloe renamed to leaf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require __DIR__ . "/Config/paths.php";
4848
| Initialise Aloe
4949
|--------------------------------------------------------------------------
5050
|
51-
| Initialise aloe cli
51+
| Initialise aloe cli and register default commands.
5252
|
5353
*/
5454
$console = new \Aloe\Console("Leaf API", "v2.0");

0 commit comments

Comments
 (0)