Skip to content

w3labkr/php-with-bladeone

Repository files navigation

php-with-bladeone

This is a starter project using the php mvp pattern without a framework. As it is a starter project, it was implemented in pure php and no css or javascript was used.

The default page is shown below.

  • register, welcome, withdrawal, farewell
  • login, logout, remember me
  • forgot password, forgot username, reset password
  • overview, profile, account, security.

Table of Contents

Environment

  • php: 8.1
  • mysql: 8.0

Directory Structure

.
└── application/
    ├── app/
    │   ├── Controllers/
    │   ├── Helpers/
    │   ├── Interfaces/
    │   ├── Middlewares/
    │   ├── Models/
    │   └── ThirdParty/
    ├── config/
    ├── data/
    │   └── sql/
    ├── database/
    │   ├── factories/
    │   └── seeders/
    ├── public/
    │   └── assets/
    │       ├── css/
    │       ├── images/
    │       └── js/
    ├── resources/
    │   ├── language/
    │   └── views/
    │       ├── includes/
    │       ├── layouts/
    │       └── pages/
    ├── routes/
    ├── schedulers/
    ├── storage/
    │   ├── app/
    │   ├── framework/
    │   │   ├── cache/
    │   │   ├── sessions/
    │   │   ├── testing/
    │   │   └── views/
    │   └── logs/
    ├── tests/
    ├── vendor/
    └── server.php

Installation

You can see more details on the page below.

Recommended Packages

You can see more details on the page below.

Useful Commands

You can see more details on the page below.

Functions

Facker

Generates fake data

$faker = new \App\Models\UserFaker();
$faker->createTable()->factory(10);

Router

The router automatically loads files under the routes directory.

  • The web.php file does not apply.
  • File names starting with an underscore are not applied.

Session

Sessions support dot notation.

// $_SESSION['a']['b']['c'] = 'value';
session()->set('a.b.c', 'value');
// $_SESSION['a']['b']['c']
session()->get('a.b.c');
// unset($_SESSION['a']['b']['c'])
session()->del('a.b.c');
// isset($_SESSION['a']['b']['c'])
session()->exists('a.b.c');
// !isset($_SESSION['a']['b']['c'])
session()->noexists('a.b.c');

Cookie

Set non-strict mode

  • expires: 0
  • path: /
  • domain: ''
  • secure: false
  • httponly: false
  • samesite: null
cookie()->set('key', 'value');
cookie()->set('key', 'value', [
    'expires' => 0,
    'path' => '/',
    'domain' => '',
    'secure' => false,
    'httponly' => false,
    'samesite' => null,
]);
cookie()->get('key');
cookie()->exists('key');
cookie()->noexists('key');

Set strict mode

  • expires: 0
  • path: /
  • domain: $_SERVER['SERVER_NAME']
  • secure: true
  • httponly: true
  • samesite: 'Strict'
cookie('Strict')->set('key', 'value');
cookie()->set('key', 'value', [
    'expires' => 0,
    'path' => '/',
    'domain' => $_SERVER['SERVER_NAME'],
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Strict', // None || Lax || Strict
]);
cookie('Strict')->del('key');

Supports the strtotime() function when the expires value is a string time.

cookie()->set('key', 'value', [
    'expires' => 'now',
    'expires' => '+1 seconds',
    'expires' => '+1 hours',
    'expires' => '+1 days',
    'expires' => '+1 week',
    'expires' => '+1 months',
    'expires' => '+1 years',
    'expires' => '+1 years +2 months +3 days +4 hours',
    'expires' => '2001-01-01 +1 months',
    'expires' => '2001-01-01 000000 +1 months',
]);
cookie('Strict')->del('key');

Dot Notation

Dot notation access to PHP arrays

// $array['a'] = 'a';
dot()->set('a', 'a');
// $array['a'];
dot()->get('a');
// unset($array['a']);
dot()->del('a');
// isset($array['a']);
dot()->exists('a');
// !isset($array['a']);
dot()->noexists('a');

String

Replace string with new characters for privacy.

substr_replace_offset('foobar', '*'); // ******
substr_replace_offset('foobar', '*', 1); // f*****
substr_replace_offset('foobar', '*', 0, 1); // *****r
substr_replace_offset('foobar', '*', 1, 1); // f****r
safety($_POST);
// htmlspecialchars(stripslashes(trim($_POST)));

UUID

Generates random tokens. The byte length can be modified as a parameter.

generate_token(16);
// 5cb43bbe36e79532f776fca4b74e84ee

Convert randomly generated tokens to UUID4 format.

uuid4();
// 011d0956-24d9-0da2-9cf4-68032a05723c

Convert UUID in binary format to UUID4 format.

bin2uuid4(' íðs u£¼¸N B¬   ');
// 20c3adc3-b073-2075-c2a3-c2bcc2b84e20

CSRF Token

By default, CSRF validation applies to all forms where the method is POST. You can modify it in middleware CSRF.php.

<input type="hidden" name="_token" value="{{ csrf_token() }}" />
function get()
{
    $csrf_token = csrf_token();

    echo $this->view('pages.page', compact('csrf_token'));
}

Mailer

Usage is same as PHPMailer library.

$mailer = mailer()->smtp();

$mailer->setFrom('[email protected]', 'Mailer');
$mailer->addAddress('[email protected]');

$mailer->isHTML(true);
$mailer->Subject = 'Here is the subject';

$mailer->Body = "This is the HTML message body <b>in bold!</b>";
$mailer->send();

License

MIT LICENSE

Releases

No releases published

Packages

No packages published

Languages