Skip to content

Commit 0629f15

Browse files
author
Wazabii
committed
Improved examples
1 parent 446ee29 commit 0629f15

File tree

10 files changed

+97
-80
lines changed

10 files changed

+97
-80
lines changed

app/Http/Controllers/Examples/DynamicPages.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/Http/Controllers/Examples/Pages.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
class Pages extends BaseController
1111
{
12-
protected $url;
13-
protected $responder;
14-
protected $users;
12+
protected $provider;
1513

1614
public function __construct(Provider $provider)
1715
{
16+
$this->provider = $provider;
1817
}
1918

2019
/**
@@ -31,12 +30,26 @@ public function start(ResponseInterface $response, RequestInterface $request): R
3130
//$this->head()->getElement("title")->setValue("Welcome to my awesome app");
3231
//$this->head()->getElement("description")->attr("content", "Some text about my awesome app");
3332

34-
$this->view()->setPartial("breadcrumb", [
35-
"tagline" => getenv("APP_NAME"),
33+
34+
$this->provider->view()->setPartial("main.ingress", [
35+
"tagline" => "Ingress view partial",
3636
"name" => "Welcome to MaplePHP",
3737
"content" => "Get ready to build you first application."
3838
]);
3939

40+
$this->provider->view()->setPartial("main.text", [
41+
"tagline" => "Text view partial A",
42+
"name" => "Lorem ipsum dolor",
43+
"content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac."
44+
]);
45+
46+
$this->provider->view()->setPartial("main.text.textB", [
47+
"tagline" => "Text view partial B",
48+
"name" => "Lorem ipsum dolor",
49+
"content" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam id sapien dui. Nullam gravida bibendum finibus. Pellentesque a elementum augue. Aliquam malesuada et neque ac varius. Nam id eros eros. Ut ut mattis ex. Aliquam molestie tortor quis ultrices euismod. Quisque blandit pellentesque purus, in posuere ex mollis ac."
50+
]);
51+
52+
4053
// Auto clear cache on update and on a future pulish date!
4154
// withLastModified will only work with the middleware "LastModifiedHandler"
4255
// It will tho automatically be turned off IF session is open to make sure no important
@@ -54,7 +67,14 @@ public function start(ResponseInterface $response, RequestInterface $request): R
5467
*/
5568
public function about(ResponseInterface $response, RequestInterface $request): ResponseInterface
5669
{
57-
$this->view()->setPartial("breadcrumb", [
70+
71+
// $this->view() is the same as $this->provider when extending to the BaseController!;
72+
$this->view()->setPartial("main.ingress", [
73+
"tagline" => "Layered structure MVC framework",
74+
"name" => "MaplePHP"
75+
]);
76+
77+
$this->view()->setPartial("main.text", [
5878
"tagline" => "Layered structure MVC framework",
5979
"name" => "MaplePHP",
6080
"content" => "MaplePHP is a layered structure PHP framework that has been meticulously crafted to " .

app/Http/Controllers/Private/Pages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function logout(ResponseInterface $response, RequestInterface $request)
3939
*/
4040
public function profile(ResponseInterface $response, RequestInterface $request)
4141
{
42-
$this->view()->setPartial("breadcrumb", [
42+
$this->view()->setPartial("main.ingress", [
4343
"tagline" => getenv("APP_NAME"),
4444
"name" => "Welcome " . $this->user()->firstname,
4545
"content" => "Get ready to build you first application."

app/Http/Middlewares/HelloWorld.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Http\Middlewares;
4+
5+
use MaplePHP\Handler\Interfaces\MiddlewareInterface;
6+
use MaplePHP\Http\Interfaces\ResponseInterface;
7+
use MaplePHP\Http\Interfaces\RequestInterface;
8+
use MaplePHP\Foundation\Http\Provider;
9+
10+
class HelloWorld implements MiddlewareInterface
11+
{
12+
private $provider;
13+
14+
public function __construct(Provider $provider)
15+
{
16+
$this->provider = $provider;
17+
}
18+
19+
/**
20+
* Will load before the controllers
21+
* @param ResponseInterface $response
22+
* @param RequestInterface $request
23+
* @return ResponseInterface|void
24+
*/
25+
public function before(ResponseInterface $response, RequestInterface $request)
26+
{
27+
// Bind array data to the provider/container.
28+
$this->provider->set("helloWorld", [
29+
"tagline" => getenv("APP_NAME"),
30+
"name" => "Hello world",
31+
"content" => "The HelloWord middleware has taking over the ingress view."
32+
]);
33+
// You can now access the helloWorld data in your controller with "$this->provider->helloWorld()"
34+
}
35+
36+
/**
37+
* Custom Before middleware (Will load before the controllers)
38+
* @param ResponseInterface $response
39+
* @param RequestInterface $request
40+
* @return ResponseInterface|void
41+
*/
42+
public function yourCustomMethod(ResponseInterface $response, RequestInterface $request)
43+
{
44+
}
45+
46+
/**
47+
* Will load after the controllers
48+
* @param ResponseInterface $response
49+
* @param RequestInterface $request
50+
* @return ResponseInterface|void
51+
*/
52+
public function after(ResponseInterface $response, RequestInterface $request)
53+
{
54+
// This will take over the ingress view in at partial main location.
55+
$this->provider->view()->setPartial("main.ingress", $this->provider->helloWorld());
56+
}
57+
}

app/Libraries/Http

Submodule Http updated 1 file

app/Libraries/Output

resources/partials/ingress.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="article bg-secondary">
2+
<header class="wrapper max-w-screen-md align-center text-lg">
3+
<?php echo $obj->tagline("Dom")->create("h6")->attr("class", "title"); ?>
4+
<h1 class="title"><?php echo $obj->name; ?></h1>
5+
<p><?php echo $obj->content; ?></p>
6+
</header>
7+
</div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
<div class="article">
4-
<header class="wrapper max-w-screen-md align-center">
3+
<div class="article border-bottom">
4+
<section class="wrapper max-w-screen-md">
55
<?php echo $obj->tagline("Dom")->create("h6")->attr("class", "title"); ?>
66
<h1 class="title"><?php echo $obj->name; ?></h1>
77
<p><?php echo $obj->content; ?></p>
8-
</header>
8+
</section>
99
</div>

resources/views/main.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11

2-
3-
<!--{{partial:breadcrumb}}-->
4-
<?php echo $this->partial("breadcrumb")->get(); ?>
52
<?php echo $this->partial("main")->get(); ?>
63
<?php echo $this->partial("form")->get(); ?>
7-
<div id="waViewforms"></div>

0 commit comments

Comments
 (0)