Skip to content

A simple minimal set of functions provide you the ability to build API & web application with no setup time

Notifications You must be signed in to change notification settings

ayushmankoley/php-weekend

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP-Weekend

A simple minimal set of functions provide you the ability to build API & web application with no setup time

Table of Contents

Features

  • Routing with dynamic routes
  • Templating
  • Method for accessing request data
  • Method for sending json data
  • Customizable
  • No design restriction build your API in anyway you want
  • Zero configuration

Installation

Install PHP-Weekend

composer require erdum/php-weekend

Usage

After installing the package your project directory will have the following

ls
  • composer.json
  • composer.lock
  • vendor

Create an index.php file

<?php

require(__DIR__ . '/vendor/autoload.php');

use PhpWeekend\Router;
use PhpWeekend\App;

Router::get('/', function() {
    App::send_json(['data' => 'Hello, World!']);
});

/*
Router also have
post
put
patch
delete
any
*/

You can get request data submitted in any format with a single function

  • query Parameters
  • form-data
  • multipart/form-data
  • application/json
<?php

require(__DIR__ . '/vendor/autoload.php');

use PhpWeekend\Router;
use PhpWeekend\App;

Router::post('/', function() {
    $request_payload = App::get_request();

    App::send_json(['data' => $request_payload], 201);
});

You can also build dynamic routes

<?php

require(__DIR__ . '/vendor/autoload.php');

use PhpWeekend\Router;
use PhpWeekend\App;

Router::get('/user/$name', function($name) {
    App::send_json(['data' => $name]);
});

You can also use templates create a directory called templates in your project root

mkdir templates

inside your templates directory you can build your templates like home.php

<h1><?= $data ?></h1>
<h2><?= $foo ?></h2>

<?php if ($age > 18): ?>
    Hello
<?php else: ?>
    whatsapp
<?php endif; ?>

now you can render home.php template from your index file

<?php

require(__DIR__ . '/vendor/autoload.php');

use PhpWeekend\Router;
use PhpWeekend\App;

Router::get('/', function() {
    App::send_template('home', [
        'data' => 'Hello, World!',
        'foo' => 'bar',
        'age' => 18
    ]);
});

App also provides you the csrf functionality

<form>
    <input type="name" name="user-name">
    <input type="email" name="user-email">
    <?= set_csrf() ?>
</form>

now verify the csrf token in the handler

<?php

require(__DIR__ . '/vendor/autoload.php');

use PhpWeekend\Router;
use PhpWeekend\App;

Router::get('/', function() {

    if (App::is_csrf_valid()) {
        // CSRF token validated
    }
});

Feedback

If you have any feedback, please reach out to us at erdumadnan@gmail.com

Contributors

License

MIT License

About

A simple minimal set of functions provide you the ability to build API & web application with no setup time

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%