1. Go to this page and download the library: Download busarm/armie 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/ */
....
$app = new App($config);
$app->get('/user/{id}')->view(UserPage::class);
$app->run()->send();
....
$app = new App($config);
// Using Custom Route Class - Single
$app->router->addRoute(MyRoute::get('/user/{id}')->to(UserController::class, 'get'));
// Using Custom Route Class - List
$app->router->addRoutes([
MyRoute::get('/user/{id}')->to(UserController::class, 'get'),
MyRoute::post('/user')->to(UserController::class, 'create'),
MyRoute::put('/user/{id}')->to(UserController::class, 'update'),
MyRoute::delete('/user/{id}')->to(UserController::class, 'delete'),
]);
$app->run()->send();
class CustomProvider implements ProviderInterface
{
/**
* @inheritDoc
*/
public function process(App $app): void
{
// Perform custom action....
}
}
...
$app = new App($config);
$app->addProvider(new CustomProvider());
...
class AuthenticateMiddleware implements MiddlewareInterface
{
public function process(RequestInterface|RouteInterface $request, RequestHandlerInterface $handler): ResponseInterface {
// Perform custom action....
// Or forward to next request handler
return $handler->handle($request);
}
}
# Attach global middleware
....
$app = new App($config);
$app->addMiddleware(new AuthenticateMiddleware())
....
# Attach middleware to specific route
....
$app->put('/user/{id}')->to(UserController::class, 'update')->middlewares([
new AuthenticateMiddleware()
]);
$app->router->addRoute(
Route::put('/user/{id}')->to(UserController::class, 'update')->middlewares([
new AuthenticateMiddleware()
])
);
....
....
$app = new App($config);
$app->addBinding(CacheInterface::class, RedisCache::class)
....
// Manually
$cache = app()->make(CacheInterface::class)
// Automatically
class UserController
{
public function __construct(private CacheInterface $cache)
{
}
}
# In Controller (or anywhere you wish to load view)
// Using app instance
app()->loader->view('login', ['username' => $uname, 'password' => $pass]);
// Using helpers
view('login', ['username' => $uname, 'password' => $pass]);
# In-line rendering
class LoginPage extends View
{
public function __construct(protected LoginPageDto|BaseDto|array|null $data = null, protected $headers = array())
{
}
public function render()
{
$header = new HeaderComponent;
return <<<HTML
<html>
<body>
<div>{$header}</div>
<div>Username: {$this->get("username")}</div>
</body>
</html>
HTML;
}
}
# Component rendering
class LoginPage extends View
{
public function __construct(protected LoginPageDto|BaseDto|array|null $data = null, protected $headers = array())
{
}
public function render()
{
return $this->
class ProductModel extends Model
{
/**
* @inheritDoc
*/
public function getFields(): array
{
return [
new Field('id', DataType::INT),
new Field('name', DataType::STRING),
new Field('type', DataType::STRING),
new Field('qty', DataType::INT),
new Field('categoryId', DataType::INT),
new Field('createdAt', DataType::DATETIME),
new Field('updatedAt', DataType::DATETIME),
new Field('deletedAt', DataType::DATETIME)
];
}
/**
* @inheritDoc
*/
public function getRelations(): array
{
return [
new OneToOne('category', $this, new Reference(CategoryTestModel::class, ['categoryId' => 'id']))
];
}
/**
* @inheritDoc
*/
public function getTableName(): string
{
return 'products';
}
/**
* @inheritDoc
*/
public function getKeyName(): ?string
{
return 'id';
}
/**
* @inheritDoc
*/
public function getCreatedDateName(): ?string
{
return 'createdAt';
}
/**
* @inheritDoc
*/
public function getUpdatedDateName(): ?string
{
return 'updatedAt';
}
/**
* @inheritDoc
*/
public function getSoftDeleteDateName(): ?string
{
return 'deletedAt';
}
}
...
$model = ProductModel::findById(1);
// Or
$model = (new ProductModel)->find(1);
...
$model = ProductModel::getAll();
// Or
$model = (new ProductModel)->all();
class ProductRepository extends Repository
{
public function __construct()
{
parent::__construct(new ProductModel);
}
}
// Or - Use Generic Repository
$productRepo = new Repository(new ProductModel)
...
$productRepo = new ProductRepository();
$result = $productRepo->paginate(1, 3);
sh
# Windows
php start.php
# Unix (Linux or Mac) [Recommended]
php start.php start
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.