PHP code example of yurigabriel / myframework

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

    

yurigabriel / myframework example snippets


$data = $this->userRepository
    ->select(['u.id', 'u.username', 'p.name'])
    ->innerJoin('profile p', 'p.user_id', '=', 'u.id')
    ->where(function($w) {
        $w->and('u.active', '=', 1)
          ->and('u.username', '!=', 'guest')
          ->or('u.role', '=', 'admin');
    })
    ->orderByDESC('u.created_at')
    ->limit(50)
    ->run();

$this->userRepository
    ->insert(['username' => 'jdoe', 'email' => '[email protected]', 'password' => 'hash'])
    ->run();

$this->userRepository
    ->update(['username' => "'newname'", 'email' => "'[email protected]'"])
    ->where(function($w) {
        $w->and('id', '=', 10);
    })
    ->run();

$this->userRepository
    ->delete(['id' => 10])
    ->run();


namespace App\Model;

use Framework\Libs\Annotations\DataBase\Collumn;
use Framework\Libs\Annotations\DataBase\Model;
use Framework\Libs\Annotations\DataBase\PrimaryKey;

#[Model("product")]
class Product {
    #[PrimaryKey]
    #[Collumn]
    public $id;

    #[Collumn]
    public $name;

    #[Collumn]
    public $price;
}


namespace App\Repository;

use App\Model\Product;
use Framework\Libs\DataBase\Repository;

class ProductRepository extends Repository {
    public function __construct() {
        parent::__construct(Product::class);
    }
}


namespace App\Controller;

use App\Repository\ProductRepository;
use Framework\Libs\Annotations\Controller;
use Framework\Libs\Annotations\Instantiate;
use Framework\Libs\Annotations\Mapping;
use Framework\Libs\Engine\Render;

#[Controller]
class ProductController {
    #[Instantiate]
    public ProductRepository $repo;

    #[Mapping('/products')]
    public function index() {
        $data = $this->repo->select(['*'])->run();
        Render::render('products/index');
    }
}


namespace App\Middleware;

use Framework\Libs\Annotations\Middleware;
use Framework\Libs\Http\Interceptable;

#[Middleware]
class AdminOnly implements Interceptable {
    public function rule(): bool {
        // checar autorização
        return isset($_SESSION['user']) && $_SESSION['user']['role'] === 'admin';
    }
}
bash
php command run