1. Go to this page and download the library: Download machinjiri/framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
machinjiri / framework example snippets
// routes/web.php
use Mlangeni\Machinjiri\Core\Routing\Router;
Router::get('/', function() {
return 'Welcome to Machinjiri!';
});
Router::get('/hello/{name}', function($name) {
return "Hello, {$name}!";
}, 'greeting');
// app/Controllers/HomeController.php
namespace Mlangeni\Machinjiri\App\Controllers;
class HomeController
{
public function index()
{
return view('home', ['title' => 'Home Page']);
}
}
// In your controller
public function login($req, $res)
{
$credentials = $req->only(['email', 'password']);
if (auth()->attempt($credentials)) {
return $res->redirect('/dashboard');
}
return view('auth.login', ['error' => 'Invalid credentials']);
}
public function logout($req, $res)
{
auth()->logout();
return $res->redirect('/');
}
use Mlangeni\Machinjiri\Core\Authentication\OAuth;
$oauth = new OAuth($config);
$token = $oauth->getAccessToken($code);
$user = $oauth->getUserInfo($token);
use Mlangeni\Machinjiri\Core\Forms\Password;
// Hash password
$hashed = Password::hash('secret123');
// Verify password
if (Password::verify('secret123', $hashed)) {
// Password is correct
}
// Automatically handled in forms
<form method="POST" action="/users">
<input type="hidden" name="_token" value="<%= csrf_token() %>">
<!-- form fields -->
</form>
use Mlangeni\Machinjiri\Core\Security\Encryption\Cipher;
$encrypter = new Cipher($key);
$encrypted = $encrypter->encrypt($data);
$decrypted = $encrypter->decrypt($encrypted);
use Mlangeni\Machinjiri\Core\Forms\FormValidator;
public function store($req, $res)
{
$validator = new FormValidator($req->all());
$validator->validate([
'name' => '=> $validator->errors()]);
}
// Create user
User::create($validator->validated());
}
$validator = new FormValidator($data);
$validator->validate([
'age' => [
'e < 18) {
$fail('Must be 18 or older');
}
},
],
]);
// app/Jobs/SendWelcomeEmail.php
namespace Mlangeni\Machinjiri\App\Jobs;
use Mlangeni\Machinjiri\Core\Artisans\Contracts\JobInterface;
class SendWelcomeEmail implements JobInterface
{
public $data;
public function __construct($userId)
{
$this->data = ['user_id' => $userId];
}
public function handle()
{
$user = User::find($this->data['user_id']);
Mail::to($user->email)->send(new WelcomeEmail($user));
}
}
// In a controller or callback
dispatch(new SendWelcomeEmail($user->id));
// Or queue for later
dispatch(new SendWelcomeEmail($user->id))->onQueue('default');
use Mlangeni\Machinjiri\Components\Alert;
use Mlangeni\Machinjiri\Components\Button;
use Mlangeni\Machinjiri\Components\Card;
use Mlangeni\Machinjiri\Components\Form;
use Mlangeni\Machinjiri\Components\Input;
use Mlangeni\Machinjiri\Components\Modal;
use Mlangeni\Machinjiri\Components\Nav;
use Mlangeni\Machinjiri\Components\ProgressBar;
// Alert component
$alert = new Alert('Success!', 'success');
echo $alert->render();
// Button component
$button = new Button('Click Me', 'btn-primary');
echo $button->render();
// Form component
$form = new Form('POST', '/submit');
$form->addField('email', 'email');
$form->addField('password', 'password');
echo $form->render();
// Input component
$input = new Input('email', '[email protected]');
echo $input->render();
// Card component
$card = new Card('Title', 'Content');
echo $card->render();