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 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);
// app/Providers/LdapServiceProvider.php
namespace App\Providers;
use Mlangeni\Machinjiri\Core\Components\LDAP\Manager as LdapManager;
use Mlangeni\Machinjiri\Core\Container;
use Mlangeni\Machinjiri\Core\Providers\ServiceProvider;
class LdapServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('ldap.manager', function (Container $app) {
return new LdapManager([
'default' => 'directory',
'connections' => [
'directory' => [
'hosts' => [env('LDAP_HOST', 'ldap.example.com')],
'port' => (int) env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=example,dc=com'),
'username' => env('LDAP_BIND_DN'),
'password' => env('LDAP_BIND_PASSWORD'),
'use_tls' => (bool) env('LDAP_USE_TLS', true),
],
],
]);
});
}
}
use Mlangeni\Machinjiri\Core\Components\LDAP\Manager as LdapManager;
public function directoryUsers(LdapManager $ldap): array
{
return $ldap->connection()->query()
->where('objectClass', '=', 'inetOrgPerson')
->where('mail', 'contains', '@example.com')
->select(['uid', 'cn', 'mail'])
->sizeLimit(100)
->get();
}
foreach (directoryUsers(resolve('ldap.manager')) as $entry) {
echo $entry->getAttribute('cn');
echo $entry->getAttribute('mail');
echo $entry->getDn();
}
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 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');