Skip to content

Commit 91e4b11

Browse files
committed
✨ added support for functional mode
1 parent f383655 commit 91e4b11

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"autoload": {
2424
"psr-4": {
2525
"Leaf\\": "src"
26-
}
26+
},
27+
"files": [
28+
"src/functions.php"
29+
]
2730
},
2831
"minimum-stability": "stable",
2932
"require": {

src/functions.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
if (!function_exists('session')) {
4+
/**
5+
* Return session data/object or set session data
6+
*
7+
* @param string|null $key — The session data to set/get
8+
* @param mixed $key — The data to set
9+
*/
10+
function session($key = null, $value = null)
11+
{
12+
if (!$key && !$value) {
13+
return new \Leaf\Http\Session();
14+
}
15+
16+
if (!$value && ($key && is_string($key))) {
17+
return \Leaf\Http\Session::get($key);
18+
}
19+
20+
if (!$value && ($key && is_array($key))) {
21+
return \Leaf\Http\Session::set($key);
22+
}
23+
24+
return \Leaf\Http\Session::set($key, $value);
25+
}
26+
}
27+
28+
if (!function_exists('flash')) {
29+
/**
30+
* Return flash data/object or set flash data
31+
*
32+
* @param string|null $key — The flash data to set/get
33+
* @param mixed $key — The data to set
34+
*/
35+
function flash($key = null, $value = null)
36+
{
37+
if (!$key && !$value) {
38+
return new \Leaf\Flash();
39+
}
40+
41+
if (!$value && is_string($key)) {
42+
return \Leaf\Flash::display($key);
43+
}
44+
45+
return \Leaf\Flash::set($key, $value);
46+
}
47+
}

0 commit comments

Comments
 (0)