Skip to content

Commit 5e78a4f

Browse files
committed
👽 configured leaf mvc with v2.5.0 changes
1 parent b76f56d commit 5e78a4f

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

App/Routes/index.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/**@var Leaf\App $app */
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Set up 404 handler
@@ -9,8 +11,6 @@
911
|
1012
*/
1113

12-
use function Leaf\Traits\auth;
13-
1414
$app->set404(function() {
1515
response()->headers->status(404);
1616
response()->page(views_path("errors/404.html", false));
@@ -27,6 +27,6 @@
2727
*/
2828
$app->setNamespace("\App\Controllers");
2929

30-
// New in Leaf v2.4.1.
31-
// You can assign a view directly
32-
$app->view("/", "index");
30+
$app->get("/", function () {
31+
echo view("index");
32+
});

Config/functions.php

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ function d()
3939
if (!function_exists('dbRow')) {
4040
/**
4141
* Return a db row by it's id
42-
*
42+
*
4343
* @param string $table The table to find row
4444
* @param string|int $row_id The row's id
4545
* @param string $columns The columns to get
46-
*
46+
*
4747
* @return array|null The database field
4848
*/
4949
function dbRow($table, $row_id, $columns = "*")
@@ -56,7 +56,7 @@ function dbRow($table, $row_id, $columns = "*")
5656
if (!function_exists('email')) {
5757
/**
5858
* Write and send an email
59-
*
59+
*
6060
* @param array $email The email block to write and send
6161
*/
6262
function email(array $email)
@@ -86,6 +86,16 @@ function fs()
8686
}
8787
}
8888

89+
if (!function_exists('flash')) {
90+
/**
91+
* Return Leaf's flash object
92+
*/
93+
function flash()
94+
{
95+
return \Leaf\Flash::class;
96+
}
97+
}
98+
8999
if (!function_exists('hasAuth')) {
90100
/**
91101
* Find out if there's an active sesion
@@ -99,9 +109,9 @@ function hasAuth()
99109
if (!function_exists('json')) {
100110
/**
101111
* json uses Leaf's now `json` method
102-
*
112+
*
103113
* json() packs in a bunch of functionality and customization into one method
104-
*
114+
*
105115
* @param array|string|object $data The data to output
106116
* @param int $code HTTP Status code for response, it's set in header
107117
* @param bool $showCode Show response code in response body?
@@ -116,7 +126,7 @@ function json($data, int $code = 200, bool $showCode = false, bool $useMessage =
116126
if (!function_exists('markup')) {
117127
/**
118128
* Output markup as response
119-
*
129+
*
120130
* @param string $data The markup to output
121131
* @param int $code The http status code
122132
*/
@@ -147,7 +157,7 @@ function render(string $view, array $data = [], array $mergeData = [])
147157
if (!function_exists('request')) {
148158
/**
149159
* Return request or request data
150-
*
160+
*
151161
* @param array|string $data — Get data from request
152162
*/
153163
function request($data = null)
@@ -160,7 +170,7 @@ function request($data = null)
160170
if (!function_exists('requestBody')) {
161171
/**
162172
* Get request body
163-
*
173+
*
164174
* @param bool $safeData — Sanitize output
165175
*/
166176
function requestBody($safeOutput = true)
@@ -172,7 +182,7 @@ function requestBody($safeOutput = true)
172182
if (!function_exists('requestData')) {
173183
/**
174184
* Get request data
175-
*
185+
*
176186
* @param string|array $param The item(s) to get from request
177187
* @param bool $safeData — Sanitize output
178188
*/
@@ -186,7 +196,7 @@ function requestData($param, $safeOutput = true, $assoc = false)
186196
if (!function_exists('response')) {
187197
/**
188198
* Return response or set response data
189-
*
199+
*
190200
* @param array|string $data — The JSON response to set
191201
*/
192202
function response($data = null)
@@ -211,7 +221,7 @@ function Route($methods, $pattern, $fn)
211221
if (!function_exists('session')) {
212222
/**
213223
* Get a session variable or the session object
214-
*
224+
*
215225
* @param string|null $key The variable to get
216226
*/
217227
function session($key = null)
@@ -237,7 +247,7 @@ function sessionUser()
237247
if (!function_exists('setHeader')) {
238248
/**
239249
* Set a response header
240-
*
250+
*
241251
* @param string|array $key The header key
242252
* @param string $value Header value
243253
* @param bool $replace Replace header if exists
@@ -271,7 +281,7 @@ function throwErr($error, int $code = 500, bool $useMessage = false)
271281
if (!function_exists('view')) {
272282
/**
273283
* Return a blade view
274-
*
284+
*
275285
* @param string $view The view to return
276286
* @param array $data Data to pass into app
277287
* @param array $mergeData
@@ -283,6 +293,17 @@ function view(string $view, array $data = [], array $mergeData = [])
283293
}
284294
}
285295

296+
// App
297+
298+
/**
299+
* Get app configuration
300+
*/
301+
function AppConfig($setting = null)
302+
{
303+
$config = require __DIR__ . "/app.php";
304+
return !$setting ? $config : $config[$setting];
305+
}
306+
286307
// Auth
287308

288309
/**
@@ -334,7 +355,7 @@ function config_path($path = null)
334355
}
335356

336357
/**
337-
* Storage directory path
358+
* Storage directory path
338359
*/
339360
function storage_path($path = null, bool $slash = false)
340361
{

Config/view.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| the usual LeafMVC view path has already been registered for you.
1212
|
1313
*/
14-
"views_path" => views_path(),
14+
"views_path" => views_path("", false),
1515

1616
/*
1717
|--------------------------------------------------------------------------
@@ -24,7 +24,7 @@
2424
|
2525
*/
2626
"cache_path" => storage_path('framework/views'),
27-
27+
2828
/*
2929
|--------------------------------------------------------------------------
3030
| Template Engine [EXPERIMENTAL]

0 commit comments

Comments
 (0)