Skip to content

Commit 8217a7e

Browse files
author
Wazabii
committed
Documentation
1 parent 80ed4b2 commit 8217a7e

File tree

1 file changed

+6
-238
lines changed

1 file changed

+6
-238
lines changed

README.md

Lines changed: 6 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11

2-
3-
4-
5-
6-
72
# MaplePHP - Layered structure MVC PHP framework
83

94
**MaplePHP is a layered structure MVC PHP framework** that very user-friendly and does not compromise on performance or scalability. By leveraging a modular architecture and with full PSR support, the framework allows for easy customization and flexibility, enabling developers to pick and choose the specific components they need to build their applications.
105

6+
## Visit the full guide
7+
[Click here for full guide](https://maplephp.wazabii.se/)
8+
119
- [Why Choose MaplePHP?](#why-choose-maplephp)
1210
- [Installation](#installation)
1311
- [Quick guide](#quick-guide)
@@ -37,240 +35,10 @@ Updates to MaplePHP are delivered through minor and patch versions, ensuring smo
3735

3836

3937
## Much more to be done
40-
In recent developments, MaplePHP has reached a significant milestone with the release of **version 2.0.0+**. This signifies the conclusion of its beta phase, marking the completion of every structural change. While substantial progress has been achieved, there is still much on the horizon. Ongoing tasks include **rigorous quality testing **and** comprehensive documentation updates**, all aimed at ensuring an even more user-friendly experience for developers.
41-
42-
## Install the MaplePHP
43-
Install the framework:
44-
```
45-
composer create-project maplephp/maplephp myApp
46-
```
47-
48-
## Install a JavaScript template engine?
49-
*MaplePHP comes with some pre-installed npm packages, including Stratox.js, a template engine. However, it is recommended to execute the command below to ensure you have the latest package and that every new JavaScript component is installed:*
50-
```
51-
npm install
52-
```
53-
This will install [Stratox.js](https://www.npmjs.com/package/stratox) a JavaScript template engine tailored for MaplePHP. [Read the documentation here](https://wazabii.se/stratoxjs/).
54-
55-
It is **not required**, and you can, for example, manually replace all content in "resources/js/main.js" and modify "package.json" with your own libraries that you are comfortable with. However, I have included it so that all the examples work.
56-
57-
## Updating MaplePHP
58-
Starting from version 2.0.0 and beyond, updating MaplePHP to the latest version is as simple as running the command below.
59-
```
60-
composer update
61-
```
62-
63-
## Install the app
64-
From you apps root directory (where the file **cli** exists) execute the following command and follow the instructions:
65-
```
66-
php cli config install --type=app
67-
```
68-
*Every value that comes with a default value can be skipped.*
69-
70-
The app is installed... You can change ever value by either enter the install command again or by opening the **.env** file and manually change it.
71-
72-
Access your application/site in the browser by navigating to the **"public/"** directory to observe it in action.
73-
74-
75-
## Quick guide
76-
**Getting started in just 4 steps.** I am working on a more comprehensive guide in gitbook and will publish it as soon as possible.
77-
78-
1. Adding Controller
79-
2. Add Controller to router
80-
3. Add services to provider
81-
5. Dispatch output
82-
83-
### 1. Adding controller
84-
Add a controller file in the Controllers directory or you can just duplicate one of the working examples from "app/Http/Controllers/Examples/".
85-
86-
```php
87-
<?php
88-
namespace Http\Controllers;
89-
90-
use MaplePHP\Http\Interfaces\ResponseInterface;
91-
use MaplePHP\Http\Interfaces\RequestInterface;
92-
use MaplePHP\Foundation\Http\Provider;
93-
use Http\Controllers\BaseController;
94-
95-
class Pages extends BaseController
96-
{
97-
public function __construct(Provider $provider)
98-
{
99-
}
100-
101-
public function start(ResponseInterface $response, RequestInterface $request): ResponseInterface
102-
{
103-
// Your code here -->
104-
return $response;
105-
}
106-
}
107-
```
108-
*More comprehensive guide will come on controllers*
109-
110-
### 2. Add Controller to router
111-
Add you Controller to router **(app/Http/Routes/web.php)** by specifing a method type (GET, POST, PUT, DELETE), full namespace path to your class and specify method if you want, else maple will try to access the __invoke method.
112-
```php
113-
$routes->group(function ($routes) {
114-
// Will handle all HTTP request errors
115-
$routes->map("*", '[/{any:.*}]', ['Http\Controllers\HttpRequestError', "handleError"]);
116-
117-
// Your routes here
118-
$routes->get("/", ['Http\Controllers\Pages', "start"]);
119-
$routes->get("/{page:contact}", ['Http\Controllers\Pages', "contact"]);
120-
$routes->post("/{page:contact}", ['Http\Controllers\Pages', "submitContactForm"]);
121-
122-
}, [
123-
// Add middlewares
124-
MaplePHP\Foundation\Cache\Middleware\LastModified::class,
125-
MaplePHP\Foundation\Nav\Middleware\Navigation::class,
126-
MaplePHP\Foundation\Dom\Middleware\Meta::class
127-
]);
128-
```
129-
*More comprehensive guide will come on router and middlewares*
130-
131-
### 3. Add services to provider
132-
Utilize the Dependency Injector for seamless and efficient connection and access to services in controllers and services in services, and so on. It effortlessly resolves dependencies, preventing the creation of duplicate instances.
133-
1. Add them to ”configs/providers.php” services here should be accessible by the whole application.
134-
```php
135-
return [
136-
'providers' => [
137-
'services' => [
138-
'logger' => '\MaplePHP\Foundation\Log\StreamLogger',
139-
'lang' => '\MaplePHP\Foundation\Http\Lang',
140-
'responder' => '\MaplePHP\Foundation\Http\Responder',
141-
'cookies' => '\MaplePHP\Foundation\Http\Cookie'
142-
]
143-
]
144-
];
145-
// To access a service above, e.g."logger" in your controller
146-
// then just output:
147-
//var_dump($this->logger());
148-
/*
149-
* Event handler - Example:
150-
* Add to service provider and event handler
151-
* Event handler will trigger every time "emergency, alert or critical" is triggered
152-
* When they are triggered the service "MyMailService" will be triggered
153-
* Resulting in that the log message will also be emailed
154-
155-
'logger' => [
156-
"handlers" => [
157-
'\MaplePHP\Foundation\Log\StreamLogger' => ["emergency", "alert", "critical"],
158-
],
159-
"events" => [
160-
'\MyCustomService\MyMailService'
161-
]
162-
]
163-
164-
*/
165-
```
166-
2. Access services directly in your Controller and through your **constructor**.
167-
```php
168-
public function __construct(Provider $provider, StreamLogger $streamLogger)
169-
{
170-
$this->logger = $streamLogger;
171-
}
172-
```
173-
3. Initiate the service directly with the Container/provider.
174-
```php
175-
public function __construct(Provider $provider, StreamLogger $streamLogger)
176-
{
177-
$provider->set("logger", StreamLogger::class);
178-
//var_dump($this->logger()); // Access the logger
179-
}
180-
```
181-
*What is great is that if StreamLogger has it own services and those services has their own services and so on, the dependency injector will resolve it all for you, and also without creating duplicate instances!*
182-
183-
*More comprehensive guide will come on provider, services and event handler*
184-
185-
### 4. Dispatch output
186-
Use built in template library or add your own either way output the content with PSR ResponseInterface.
187-
```php
188-
<?php
189-
190-
namespace Http\Controllers;
191-
192-
use MaplePHP\Http\Interfaces\ResponseInterface;
193-
use MaplePHP\Http\Interfaces\RequestInterface;
194-
use MaplePHP\Foundation\Http\Provider;
195-
use Http\Controllers\BaseController;
196-
197-
class Pages extends BaseController
198-
{
199-
// Use the built in template engine
200-
public function start(ResponseInterface $response, RequestInterface $request): ResponseInterface
201-
{
202-
$this->view()->setPartial("ingress", [
203-
"tagline" => "My Awesome App",
204-
"name" => "Welcome to MaplePHP",
205-
"content" => "Get ready to build you first application."
206-
]);
207-
208-
$this->view()->setPartial("content", [
209-
"name" => "A second breadcrumb",
210-
"content" => "A second breadcrumb/ingress attached to the main partial."
211-
]);
212-
213-
return $response;
214-
}
215-
216-
// Or attach you own to the stream
217-
public function about(ResponseInterface $response, RequestInterface $request): ResponseInterface
218-
{
219-
$response->getBody()->write("Hello world");
220-
return $response;
221-
}
222-
}
223-
```
224-
*More comprehensive guide will come on the built in template engine and how to implement third-apart template engine*
225-
226-
**And thats it.. Easy right?**
227-
228-
There is of course **many** more functions, but with that you can start building your site or app either with MaplePHP libraries or third-party libraries that you are used to work with.
229-
230-
## Other installations
231-
232-
### Install database
233-
Execute the following command and follow the instructions:
234-
```
235-
php cli config install --type=mysql
236-
```
237-
The database is now installed and ready.
238-
239-
**IF you do not want to use table prefix, you can manually remove "MYSQL_PREFIX" or add a empty string from .env**
240-
241-
### Install mail
242-
Execute the following command and follow the instructions. I do recommended using a SMTP but is not required:
243-
```
244-
php cli config install --type=mail
245-
```
246-
Mail has now been installed.
247-
248-
### Install Auth and login form
249-
250-
#### Install the database:
251-
In the correct order!
252-
```
253-
php cli migrate create --table=organizations
254-
```
255-
```
256-
php cli migrate create --table=users
257-
```
258-
```
259-
php cli migrate create --table=login
260-
```
261-
```
262-
php cli migrate create --table=usersToken
263-
```
264-
#### Add organization
265-
```
266-
php cli database insertOrg
267-
```
268-
#### Add user
269-
```
270-
php cli database insertUser
271-
```
272-
*Now you can use the login form (take a look at the router file app/Http/Routes/web.php) and you will see that login controller is already prepared.*
38+
While substantial progress has been achieved, there is still much on the horizon. Ongoing tasks include **rigorous quality testing and comprehensive documentation updates**, all aimed at ensuring an even more user-friendly experience for developers.
27339

40+
### For the full guide:
41+
[Click here](https://maplephp.wazabii.se/)
27442

27543
## Library guides
27644
The guide is not complete. There is much more to come.

0 commit comments

Comments
 (0)