Simple is a project that brings together a set of packets to work with PHP quickly and minimally. Less is more!
To start using the simple one you can use the command:
$ composer create-project phpzm/simplesor make a copy of the repository white master
$ git clone https://github.com/phpzm/simples.git < dir >
$ cd < dir >
$ rm .git
$ composer installBy now you have already downloaded a basic architecture, and you need to set up some details to go out using happy basic features for a PHP website or system.
The two settings that are made available as the base we will mention below are directed to the same URL: http://localhost:8080 Before starting any of the server modes, make a copy of the .env example file that is available with the project
$ composer run env:initCreates a copy of the example file that is made available together with the project
$ composer run docker:initNext you can use the command that is used to running the containers or using
$ composer run docker:serve --timeout=0To use the development server that comes with PHP use the commands below
$ composer run php:serve --timeout=0 Everything went well, when accessing the URL http://localhost:8080 you will already see our default presentation page
Okay, the URL that should work is ok, but let's make an overview of what happened for her to run.
In this folder you will find the only entry point for requests that your application will have. When opening the index.php file that has inside it we find the first interaction with the simple files. In addition to the PHP file, there are also files we usually call assets . They are the images, style files, and features used to improve the visualization of application resources. This folder will be used to leave exposed documents that can be accessed by anyone.
This directory contains a PHP file list that are used to configure application behaviors. While taking a look at these files you will see that there is a function called env being used to define some properties. This function recovers the values that are defined in the .env .
Finally we arrived where the party happens. Simples comes with the right settings to use this directory to consult the documents you will create. As you can do a lot, we divide everything into parts.
It houses the documents related to the composition of resources indirectly. It is initially configured with 3 directories (email, locales, view), but you can grow it comfortable. You can see in the config/app.php file a configuration instruction similar to that below. Based on the example, we can use Helper config('app.resources.root') that the app/resources value will be returned and this is how simple locates the features it uses.
[config/app.php]
<?php
( . . . )
' resources ' => [
' root ' => ' app/resources ' ,
]
(...) We will see more about this part of the views and their use of the template section.
This is a suggested path for using routes. It is described in config/route.php where you can enter a file array that will be initialized to compose the application routes.
[config/route.php]
<?php
( . . . )
' files ' => [
' app/routes/index.php '
]
(...) Therefore, when an HTTP request is sent to public/index.php it will start searching for routes in the app/routes/index.php file. Later, in the route creation section, we will see how to create routes in an organized way using the simple.
This folder is directly related to the Composer autoloader through the configuration on composer.json
[composer.json]
(...)
"autoload": {
"psr-4": {
"App\": "app/src/"
}
}
(...)
That is, the standard namepace you will use is the App and the file should be within the folder described above. Obviously you can modify this. Note that using the PSR-4 convention when you create a document with proper namespace you can use it transparently. We will go into more detail about this in the structural composition section.
As a way to indicate an initial path we suggest this folder called storage at the root of the project to maintain documents that cannot be open to public access.
The vendor folder is automatically created by the Composer . It has the dependencies your project will use and file load settings. It is by default configured in the .gitignore file to be ignored by Git
The configuration of which the first route (or which the first routes) will be called is default within app/config/route.php .
Application resource access settings can be made in the route files. Commands can be written directly on the file of the file (where a $ router variable will be available for scope reasons) or using the return of closures that receive the $ router as a parameter.
Simple routes
return function ( $ router ) {
$ router -> on ( ' GET ' , ' / ' , function () {
return ' Hello World! ' ;
});
}Dynamic routes
return function ( $ router ) {
$ router -> get ( ' /:controller/:method ' , function ( $ controller , $ method ) {
return ' Hello World! ' ;
});
}Rota groups
return function ( $ router ) {
// lista com arquivos de rota
$ router -> group ( ' GET ' , ' /site ' , [ ' more/files/routes.php ' , ' more/files/site.php ' ]);
// pasta que contém arquivos de rotas
$ router -> group ( ' * ' , ' /api ' , ' api/routes ' );
}Routes with interaction with controller
return function ( $ router ) {
$ router -> post ( ' /client/save ' , ' NamespaceClientController@save ' );
$ router -> resource ( ' client ' , ' NamespaceClientController ' );
} A $router->resource will create:
| Verb | Path | Action | Route Name |
|---|---|---|---|
| Get | /route | index | Route.index |
| Get | /route/create | Create | Route.create |
| Get | /route/{id} | show | Route.show |
| Get | /route/{id}/edit | edit | Route.edit |
| Post | /route | stere | Route.store |
| Put/patch | /route/{id} | update | ROUTE.UPDATE |
| Delete | /route/{id} | destroy | ROUTE.DESTROY |