PHP code example of accolon / izanagi

1. Go to this page and download the library: Download accolon/izanagi 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/ */

    

accolon / izanagi example snippets




namespace App\Models;

use Accolon\Izanagi\Attributes\Field;
use Accolon\Izanagi\Attributes\Table;
use Accolon\Izanagi\Types\FieldType;
use Accolon\Izanagi\Entity;

#[Table(name: "users")]
class User extends Entity
{
    #[Field(type: FieldType::Integer, primary: true, length: 11, autoIncrement: true)]
    public int $id;

    #[Field(type: FieldType::String, length: 30)]
    public string $name;

    #[Field(type: FieldType::String, length: 30)]
    public string $password;

    #[Field(type: FieldType::Boolean)]
    public bool $admin;
}



namespace App\Repositories;

use Accolon\Izanagi\Repository;
use App\Models\User;

class UserRepository extends Repository
{
    protected string $class = User::class;
}

// Basic Config

define("DB_CONFIG", [
    'name' => "izanagi",
    'user' => "root",
    'password' => 'pass'
]);

// Migrate

$manager = new Manager([
    User::class
]);

$manager->migrate();

$user = new User();
$user->name = 'Sla';
$user->password = 'd2k';
$user->admin = false;

$user->create();

$user->update(['admin' => true]);

$user->delete();

$repository = new UserRepository();

$repository->all(); // User[]
$repository->findAll([
    'name' => 'Sla'
]); // User[]

$repository->findOne(['name' => 'Sla']); // ?User
$repository->find(1); // ?User

$repository->exists(['name' => 'Sla']); // bool