diff --git a/README.md b/README.md index 8e838cd..e9e273d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # PhpSlides -***PhpSlides*** is php framework mainly designed for already created foundation templates used in creating of `Router`, `Api` and `database management` 💫. +**_PhpSlides_** is php framework mainly designed for already created foundation templates used in creating of `Router`, `Api` and `database management` 💫. -Use ***PhpSlides*** in creating of Very based secured Router, Api & database, created inbuilt template database which accepts - `MySql` & `Sqlite` database 🔥✨ can also setup other database. +Use **_PhpSlides_** in creating of Very based secured Router, Api & database, created inbuilt template database which accepts - `MySql` & `Sqlite` database 🔥✨ can also setup other database. It has by default in preventing SQL injections, it prevents project from XXS attacks & CSRF 🔐. -It's a good practice for a beginner in Php to start with ***PhpSlides*** +It's a good practice for a beginner in Php to start with **_PhpSlides_** ## How PhpSlides works: -- With PhpSlides, all request coming from the server are redirecting to PhpSlides for verifing routing. +- With PhpSlides, all request coming from the server are redirecting to PhpSlides for verifing routing. And checks if request matches the registered routes, else it returns a 404 Not Found Page 📌. - No request can access any files or folders in a PhpSlides project unless specified in routing 📌. @@ -22,10 +22,9 @@ It's a good practice for a beginner in Php to start with ***PhpSlides*** - Read PhpSlides default codes and understand each codes function, codes are neat and readable 💯. - ## PhpSlides Examples & Explain -Firstly, we create our Slides Project by executing this command in your Terminal +Firstly, we create our Slides Project by executing this command in your Terminal if Composer is already installed. ```bash @@ -36,26 +35,29 @@ Where the `slide_project` is the project name you which to create & it's the pro And it's going to create the project with the specified name at the target directory where you install it If composer is not yet install. Install it by executing: + ```bash pkg install composer ``` + And we're all setted. We would open our project on vscode or PhpStorm or any other Php editors. -Let's start our project on browser, you would setup & start the Apache server in your Xampp or any other Php server. +Let's start our project on browser, you would setup & start the Apache server in your Xampp or any other Php server. If you're using phone, you may use AwebServer for Php server. And open the host in your browser, you would see a default template. ## Routing -There are different methods of Request Route. +There are different methods of Request Route. This Route methods are used receiving request from the client side + - GET Route - POST Route - PUT Route - UPDATE Route -- DELETE Route +- DELETE Route - VIEW Route _(almost the same as GET)_ - REDIRECT Route @@ -64,22 +66,22 @@ This Route methods are used receiving request from the client side Open the `routes/route.php` file in your editor. Open the `routes` folder, the the `route.php` file. By default you'll see a dashboard route been registered, you may remove it to start from scratch. -Let's create a simple blog slides as example. +Let's create a simple blog slides as example. So we would register our routes, we would need a `Login Page`, `Register`, `Profile`, and `Posts Page`. Let's register pur routes in the `route.php` file and write example: ```php (slides) ``` @@ -90,7 +92,7 @@ Firstly we imported our autoload file from the vendor directory so we can use al With `use PhpSlides\Route` we use it in importing our Route class to use. The `Route::config` function must be specified at the beginning of our codes. -It makes PhpSlides to configure our website Routes and makes it very secured +It makes PhpSlides to configure our website Routes and makes it very secured which allows to to have access in configuring the routing and the requested paths. The `Route::config` function takes 1 Boolean parameter which indicates whether to allow Logs request. @@ -100,7 +102,7 @@ And the `Route::view` function allows you to create a view route. The parameters passed to it, will be two, the first parameter specifies the route that should be requested to render the second parameter. -The second parameters render the files in the view directory which can be accessible with __::__ (___Double Colon___) and the file name. +The second parameters render the files in the view directory which can be accessible with **::** (**_Double Colon_**) and the file name. Any files we creates in the view directory must be in the format `fileName.view.php` which the `fileName` is the name of the view file and the `.view.php` is the file extension, so PhpSlides will notice that it's a view file. @@ -114,29 +116,29 @@ Then we can write a small example HTML code.

Login Page

- + - + ``` -### GET Route Method +### GET Route Method -Example of GET Route method +Example of GET Route method ```php (slides) ``` @@ -147,7 +149,7 @@ But in GET route, the 2nd parameters which is used as a callback function takes Since it returns it directly to the client side. With GET routes, request method of the particular url to receive must be a GET request, so as all routes methods. -___GET Route with Closure Function method___ +**_GET Route with Closure Function method_** ```php (slides) Route::get("/login", function() { @@ -159,7 +161,7 @@ It returns the Login view page, we can return any php values to the browser. All routes methods has second parameters as callback function which takes function methods or any other methods. -___GET Route method with url Parameters with Closures___ +**_GET Route method with url Parameters with Closures_** ```php (slides) Route::get("/posts/{id}", function(int $id) { @@ -170,34 +172,34 @@ ___GET Route method with url Parameters with Closures___ This above example register a new GET route with /posts request which receive GET request with a function closure parameters of ID. If the request was /posts/2 then it'll return "Posts ID = 2" it gets the ID value and send it to the client side/browser. -## POST Route Method +## POST Route Method -Example of POST Route method +Example of POST Route method ```php (slides) ``` -It calls the POST method, it indicates that the POST route function can only be executed if the REQUEST_METHOD is a POST request. +It calls the POST method, it indicates that the POST route function can only be executed if the REQUEST_METHOD is a POST request. And can be used in like submitting form data. -The second parameters is empty, can return a JSON format, -because POST method is normally used in sending a POST request that returns data in a JSON formats, 2nd parameters can contain any formats for a callback function +The second parameters is empty, can return a JSON format, +because POST method is normally used in sending a POST request that returns data in a JSON formats, 2nd parameters can contain any formats for a callback function That's how the rest Route method is. -## PUT Route Method +## PUT Route Method -Example of PUT Route method +Example of PUT Route method ```php (slides) Route::put("/user", ()); @@ -205,9 +207,9 @@ Example of PUT Route method PUT method is just like a POST request, in adding informations or data to a specific file or database. -## UPDATE Route Method +## UPDATE Route Method -Example of UPDATE Route method +Example of UPDATE Route method ```php (slides) Route::update("/user/{id}", ()); @@ -215,9 +217,9 @@ Example of UPDATE Route method UPDATE method is normally used in updating information like in database. -### DELETE Route Method +### DELETE Route Method -Example of DELETE Route method +Example of DELETE Route method ```php (slides) Route::delete("/user/{id}", ()); @@ -225,7 +227,7 @@ Example of DELETE Route method DELETE method is normally used likely in deleting informations in the database. -### ANY Route Method +### ANY Route Method Example of ANY Route method @@ -238,17 +240,17 @@ Can be either POST, GET, PUT, UPDATE or DELETE, depending on the requested route ## Create NotFound Errors Route -Example of NotFound Route method +Example of NotFound Route method ```php (slides) Route::any("*", Route::view("::errors::404")); ``` In this above NotFound example, we created an ANY Route -and make the first parameter to be `*` +and make the first parameter to be `*` which indicates to return whenever there's no routes matches the requested URL. -The NotFound route should be at the ending of the registered routes, +The NotFound route should be at the ending of the registered routes, so it can be executed when all above routes are mismatched. And in the second parameter, we navigates to `view` folder @@ -259,10 +261,10 @@ then create a page called `404.view.php` You can creates a multiple routes url that'll render a page or a function. -Create multiple URLs with array and list of URLs in it. +Create multiple URLs with array and list of URLs in it. Can use any route methods. -___NOTE:___ You cannot use multiple URLs when using routes parameters with {} curly braces +**_NOTE:_** You cannot use multiple URLs when using routes parameters with {} curly braces ```php (slides) Route::view(["/", "/index", "/dashboard"], "::dashboard"); @@ -288,26 +290,27 @@ Let's navigates to the created file and write some codes in it. ```php (slides) Get User with ID = {$id}"; } } - + ?> ``` In this example above, we created a file called `UserController.php` in the `/Controller` folder. And we created a namespace for the class controller that'll be used in calling the class. -We created the class called `UserController` and extends it to the `Controller` class, +We created the class called `UserController` and extends it to the `Controller` class, which allows you to access some protected functions. Make sure after every created class components which has a namespace you should run this below command for autoloading of each classes. + ```bash composer slides-refresh ``` @@ -315,26 +318,26 @@ Make sure after every created class components which has a namespace you should The final keywords in the class describes that the class should be final and cannot be extended to another class, you may remove it if the class should be extended. -And we create our public function called __invoke which gets the closure parameter in route, -that'll be used to get the url params and returns value for the callback function. +And we create our public function called \_\_invoke which gets the closure parameter in route, +that'll be used to get the url params and returns value for the callback function. So it gets the closure $id parameters, and describes it as an integer using the `int` before the param name. Let's register the user routes and make it to be GET route, can make it any type of route request depending on the usage. ```php (slides) ``` -In this above example, we already created a class called `UserController`, +In this above example, we already created a class called `UserController`, And we created a GET route method which has a URL parameter of `id`. Then we render the `UserController` class, which the `id` parameter has been sent to the `UserController` class with the `__invoke` function. @@ -356,7 +359,7 @@ In our class controller, we can also create multiple methods for different Route } } - ?> + ?> ``` In the `UserController` we created another method called `User()` which takes one parameter as `$id` for the `id` URL request parameter. @@ -387,7 +390,7 @@ Example below for creating multiple URL parameters: }); ``` -It has two URL parameters called `id` and `post_id` for user id and post id, then we gets the URL parameters in the closure function parameter. +It has two URL parameters called `id` and `post_id` for user id and post id, then we gets the URL parameters in the closure function parameter. Same thing as route controller method. But make sure the function closure parameters variable cannot be the same else it might turns conflict, but the URL parameters may be the same. @@ -403,32 +406,33 @@ By default if they open any urls to any path of the page, the web will be blank And the configurations in PhpSlides makes it easy in allowing you to configure the part a user can view, to make a very secured website..As they can only view any files in the public folder, but cannot view the folders there apart from Routing. -___Example of Configuration in PhpSlides__ +**\_Example of Configuration in PhpSlides** Open the `phpslides.config.json` at the root directory of your project. ```json - { - "charset": "UTF-8" - } +{ + "charset": "UTF-8" +} ``` This above example specifies the charsets to be used in returning all files and routing pages to the brower. But can change it at anytime with PHP code, if you want some part to be changed. ```json - { - "public": { - "/": [ "*" ] - } - } +{ + "public": { + "/": ["*"] + } +} ``` We added a `public` key in the json file, which specifies that inside the `public` directory, the files and nested files in folders it can access -We added the `/` key which specifies the root of the `public` directory. So we added it has `*` _(Asterisk)_. Which specifies to access all files in the root of the `public` directory. And we can specify any type of extensions they can access, even though the file exist and they try to access the file that the extension are not available in the cconfiguration, it'll return a `Not Found page`. They can write multiple extesnsions in the array. And can also write `image` whereby they can access all images, `video` or `audio`. +We added the `/` key which specifies the root of the `public` directory. So we added it has `*` _(Asterisk)_. Which specifies to access all files in the root of the `public` directory. And we can specify any type of extensions they can access, even though the file exist and they try to access the file that the extension are not available in the cconfiguration, it'll return a `Not Found page`. They can write multiple extesnsions in the array. And can also write `image` whereby they can access all images, `video` or `audio`. + ```json - "/": [ "image", "audio", "video" ] + "/": [ "image", "audio", "video" ] ``` On each nested folders inside the `public` directory will be specified as an array of extensions in the config file. @@ -453,15 +457,12 @@ So this example is explained: In the `public` directory we have `assets` and `images` folder. so in the `assets` folder we have 1 image, 1 PDF file and 1 `vendor` folder which contain `bootstrap.min.js`. So if we want to configure it:: ```json - { - "public": { - "assets": [ - "jpg", - "js" - ], - "images": [ "image", "video" ] - } - } +{ + "public": { + "assets": ["jpg", "js"], + "images": ["image", "video"] + } +} ``` In this example we only created configurations for the `assets` and `images` directory, so all files and folders in the `assets` directory will use the extensions added in the `assets` directory which specifies that in this example, the `js` extension specified will be allowed also in the `vendor` folder, or we add the `vendor` key to the json file. @@ -472,15 +473,16 @@ For the `images` directory we specified that it can only access the any files th ### View Public Files in Web -To view all files that are in `public` directory with files in nested folders. You woudn't add the `public` folder before getting files, it'll return `Not Found page`. So like the above example, to access the file in the `assets` folder. We would follow the url: `http://localhost:8000/assets/image.jpg` and not `http://localhost:8000/public/assets/image.jpg`. +To view all files that are in `public` directory with files in nested folders. You woudn't add the `public` folder before getting files, it'll return `Not Found page`. So like the above example, to access the file in the `assets` folder. We would follow the url: `http://localhost:8000/assets/image.jpg` and not `http://localhost:8000/public/assets/image.jpg`. And if files are in the root directory of the project, it would be accessed directly after the host url: `http://localhost:8000/image.jpg`. - # Version 1.1.0 + In this version, slides provides way in dealing with view page 🔥 Create your view template file in the `views` directory, in this format `fileName` + `.view.php` extension. which is `fileName.view.php` PhpSlides created some special view syntax. + - @view - ::view - ::root @@ -494,9 +496,9 @@ Lets get this started.. - + Page Title @@ -507,11 +509,11 @@ Lets get this started.. ``` -In a view template page where we writes HTML codes, PHP tag should not starts the file, -instead write the php tag and codes inside the `` tag or any other places apart from the starting, +In a view template page where we writes HTML codes, PHP tag should not starts the file, +instead write the php tag and codes inside the `` tag or any other places apart from the starting, should always start HTML documents with the `` tag and not `` tag in the view template is short php tag used in writing short php codes. +The `` tag in the view template is short php tag used in writing short php codes. like using if statement, or echoing data to the html page. Example codes: ```php (slides) @@ -521,7 +523,7 @@ like using if statement, or echoing data to the html page. Example codes:

Hello Guest

- +

@@ -532,10 +534,10 @@ This example is explained as: in the body element we check if a user returns tru Else it'll return and `h1` element with text Hello Guest In the `

` tag we wrote php codes which uses the `@view` keyword to return the string/value to the `

` element. -__::view & ::root__ +**::view & ::root** The `::view` is just a word written only in the view template files which return the root location after the server name in the project starting from the `/`. Usually used to link public files. -And the `::root` is returning the root location of your project and not has the `::view`, `::root` is used in php in including any files of the project, +And the `::root` is returning the root location of your project and not has the `::view`, `::root` is used in php in including any files of the project, but `::view` can just access only what the browser/client side can acces, but cannot access any files in project when not in `public` directory. Now let's imagine we have images we would access in the public directory and extra php file we would need to include in the view page. @@ -543,7 +545,7 @@ Now let's imagine we have images we would access in the public directory and ext ```php (slides) - +

Icon
@@ -552,35 +554,35 @@ Now let's imagine we have images we would access in the public directory and ext In this case the root of the project is indicated as `::root` and inside the project we created a folder called `components` and new file called `extraFile.php` for any php codes to include in the view page. -The `::view` is the root location of the server host, so let's imagine the host url as `http://localhost:8000/` so it's indicated as `::view` and normally in slides, +The `::view` is the root location of the server host, so let's imagine the host url as `http://localhost:8000/` so it's indicated as `::view` and normally in slides, all files and folders in `public` directory are extended in the root of the url as `::view/` and not `::view/public` So the url as `::view/assets/icon.png` in the `public` directory, created a `assets` folder and `icon.png` image. -__SLIDES INCLUDE__ +## SLIDES_INCLUDE Slides provides way for you to include another view template file to a view page, and not only a php files. -__2 ways of including view page__ +**2 ways of including view page** - Using the `` html tag - Using the `slides_include` php function -With the `` html tag, you can include other php/view page to the current view page. +With the `` html tag, you can include other php/view page to the current view page. Which allows you to write slides view template in other files to include. And can also include any other php file located anywhere in the project. ```html - - - - + + + + ``` So in the first tag we included a php file located at the `components` directory. And the second tag we included a view template file located in the `views` directory. And can only use the `` tag in a view template page. -__slides_include__ +**slides_include** This function provides a way for you to include view files in any php file & not only on the view template page. @@ -589,7 +591,6 @@ This function provides a way for you to include view files in any php file & not ``` - # Version 1.2.0 ## API @@ -602,7 +603,7 @@ Register your new API route in the `routes/api.php` file ```php (slides) @@ -632,27 +633,27 @@ And create another route `"/api/users/{id}"` also a POST method which would show So in the first Api we didn't provide a second parameter for the method to use which by default is `__invoke` method. And in the second we use the `@user` which declears the `user` method of the same controller class. The `@` target the method name of the controller class. -Let's first create our controller class in the `Controller/Api` directory. Let's name it `UserController`. +Let's first create our controller class in the `Controller/Api` directory. Let's name it `UserController`. In our controller names, it is must the `Controller` to end a file, which describes a controller file. ```php (slides) 'We have gotten all users id successful']; return json_encode($response); } - + function user(int $id) { $response = ['data' => 'The particular user id = $id']; return json_encode($response); } } - + ?> ``` @@ -662,21 +663,19 @@ Not yet done.. We need to register each API routes url for controller class in t ```php (slides) UserController::class, '/api/users/{id}' => UserController::class ]; - + ?> ``` - We returned the register API routes now API is ready to be consumed ❤️💯. +**_HURRAY as you enjoy using PhpSlides!!!_** -***HURRAY as you enjoy using PhpSlides!!!*** - -***More functions are coming in the next versions*** \ No newline at end of file +**_More functions are coming in the next versions_** diff --git a/composer.json b/composer.json index df05f44..679db4b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "dconco/php_slides", "description": "PhpSlides a light fast framework for letting you create a secured Routing in php and secured API, which prevents SQL injections, and from XSS attack & CSRF.", "homepage": "https://github.com/dconco/php_slides", - "version": "1.2.1", + "version": "v1.2.1-alpha", "type": "project", "keywords": [ "php", @@ -43,6 +43,6 @@ "allow-contrib": false } }, - "minimum-stability": "stable", + "minimum-stability": "alpha", "prefer-stable": true } \ No newline at end of file